| 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; |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 46 | import com.android.internal.policy.impl.PhoneWindowManager; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 47 | import com.android.internal.view.IInputContext; |
| 48 | import com.android.internal.view.IInputMethodClient; |
| 49 | import com.android.internal.view.IInputMethodManager; |
| Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 50 | import com.android.internal.view.WindowManagerPolicyThread; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 51 | import com.android.server.am.BatteryStatsService; |
| 52 | |
| 53 | import android.Manifest; |
| 54 | import android.app.ActivityManagerNative; |
| 55 | import android.app.IActivityManager; |
| Jim Miller | d6b5705 | 2010-06-07 17:52:42 -0700 | [diff] [blame] | 56 | import android.app.admin.DevicePolicyManager; |
| Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 57 | import android.content.BroadcastReceiver; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 58 | import android.content.Context; |
| Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 59 | import android.content.Intent; |
| 60 | import android.content.IntentFilter; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 61 | import android.content.pm.ActivityInfo; |
| 62 | import android.content.pm.PackageManager; |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 63 | import android.content.res.CompatibilityInfo; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 64 | import android.content.res.Configuration; |
| 65 | import android.graphics.Matrix; |
| 66 | import android.graphics.PixelFormat; |
| 67 | import android.graphics.Rect; |
| 68 | import android.graphics.Region; |
| 69 | import android.os.BatteryStats; |
| 70 | import android.os.Binder; |
| Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 71 | import android.os.Bundle; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 72 | import android.os.Debug; |
| 73 | import android.os.Handler; |
| 74 | import android.os.IBinder; |
| Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 75 | import android.os.LatencyTimer; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 76 | import android.os.LocalPowerManager; |
| 77 | import android.os.Looper; |
| 78 | import android.os.Message; |
| 79 | import android.os.Parcel; |
| 80 | import android.os.ParcelFileDescriptor; |
| 81 | import android.os.Power; |
| 82 | import android.os.PowerManager; |
| 83 | import android.os.Process; |
| 84 | import android.os.RemoteException; |
| 85 | import android.os.ServiceManager; |
| 86 | import android.os.SystemClock; |
| 87 | import android.os.SystemProperties; |
| 88 | import android.os.TokenWatcher; |
| 89 | import android.provider.Settings; |
| Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 90 | import android.util.DisplayMetrics; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 91 | import android.util.EventLog; |
| Jim Miller | d6b5705 | 2010-06-07 17:52:42 -0700 | [diff] [blame] | 92 | import android.util.Log; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 93 | import android.util.Slog; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 94 | import android.util.SparseIntArray; |
| 95 | import android.view.Display; |
| 96 | import android.view.Gravity; |
| Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 97 | import android.view.HapticFeedbackConstants; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 98 | import android.view.IApplicationToken; |
| 99 | import android.view.IOnKeyguardExitResult; |
| 100 | import android.view.IRotationWatcher; |
| 101 | import android.view.IWindow; |
| 102 | import android.view.IWindowManager; |
| 103 | import android.view.IWindowSession; |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 104 | import android.view.InputChannel; |
| 105 | import android.view.InputQueue; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 106 | import android.view.KeyEvent; |
| 107 | import android.view.MotionEvent; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 108 | import android.view.Surface; |
| 109 | import android.view.SurfaceSession; |
| 110 | import android.view.View; |
| Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 111 | import android.view.ViewConfiguration; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 112 | import android.view.ViewTreeObserver; |
| 113 | import android.view.WindowManager; |
| 114 | import android.view.WindowManagerImpl; |
| 115 | import android.view.WindowManagerPolicy; |
| 116 | import android.view.WindowManager.LayoutParams; |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 117 | import android.view.animation.AccelerateInterpolator; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 118 | import android.view.animation.Animation; |
| 119 | import android.view.animation.AnimationUtils; |
| 120 | import android.view.animation.Transformation; |
| 121 | |
| 122 | import java.io.BufferedWriter; |
| 123 | import java.io.File; |
| 124 | import java.io.FileDescriptor; |
| 125 | import java.io.IOException; |
| 126 | import java.io.OutputStream; |
| 127 | import java.io.OutputStreamWriter; |
| 128 | import java.io.PrintWriter; |
| 129 | import java.io.StringWriter; |
| 130 | import java.net.Socket; |
| 131 | import java.util.ArrayList; |
| 132 | import java.util.HashMap; |
| 133 | import java.util.HashSet; |
| 134 | import java.util.Iterator; |
| 135 | import java.util.List; |
| 136 | |
| 137 | /** {@hide} */ |
| Dianne Hackborn | ddca3ee | 2009-07-23 19:01:31 -0700 | [diff] [blame] | 138 | public class WindowManagerService extends IWindowManager.Stub |
| Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 139 | implements Watchdog.Monitor { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 140 | static final String TAG = "WindowManager"; |
| 141 | static final boolean DEBUG = false; |
| 142 | static final boolean DEBUG_FOCUS = false; |
| 143 | static final boolean DEBUG_ANIM = false; |
| Dianne Hackborn | 9b52a21 | 2009-12-11 14:51:35 -0800 | [diff] [blame] | 144 | static final boolean DEBUG_LAYOUT = false; |
| Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 145 | static final boolean DEBUG_RESIZE = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 146 | static final boolean DEBUG_LAYERS = false; |
| 147 | static final boolean DEBUG_INPUT = false; |
| 148 | static final boolean DEBUG_INPUT_METHOD = false; |
| 149 | static final boolean DEBUG_VISIBILITY = false; |
| Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 150 | static final boolean DEBUG_WINDOW_MOVEMENT = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 151 | static final boolean DEBUG_ORIENTATION = false; |
| Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 152 | static final boolean DEBUG_CONFIGURATION = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 153 | static final boolean DEBUG_APP_TRANSITIONS = false; |
| 154 | static final boolean DEBUG_STARTING_WINDOW = false; |
| 155 | static final boolean DEBUG_REORDER = false; |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 156 | static final boolean DEBUG_WALLPAPER = false; |
| Dianne Hackborn | ce73c1e | 2010-04-12 23:11:38 -0700 | [diff] [blame] | 157 | static final boolean DEBUG_FREEZE = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 158 | static final boolean SHOW_TRANSACTIONS = false; |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 159 | static final boolean HIDE_STACK_CRAWLS = true; |
| Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 160 | static final boolean MEASURE_LATENCY = false; |
| 161 | static private LatencyTimer lt; |
| 162 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 163 | static final boolean PROFILE_ORIENTATION = false; |
| 164 | static final boolean BLUR = true; |
| Dave Bort | cfe6524 | 2009-04-09 14:51:04 -0700 | [diff] [blame] | 165 | static final boolean localLOGV = DEBUG; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 166 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 167 | /** How much to multiply the policy's type layer, to reserve room |
| 168 | * for multiple windows of the same type and Z-ordering adjustment |
| 169 | * with TYPE_LAYER_OFFSET. */ |
| 170 | static final int TYPE_LAYER_MULTIPLIER = 10000; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 171 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 172 | /** Offset from TYPE_LAYER_MULTIPLIER for moving a group of windows above |
| 173 | * or below others in the same layer. */ |
| 174 | static final int TYPE_LAYER_OFFSET = 1000; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 175 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 176 | /** How much to increment the layer for each window, to reserve room |
| 177 | * for effect surfaces between them. |
| 178 | */ |
| 179 | static final int WINDOW_LAYER_MULTIPLIER = 5; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 180 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 181 | /** The maximum length we will accept for a loaded animation duration: |
| 182 | * this is 10 seconds. |
| 183 | */ |
| 184 | static final int MAX_ANIMATION_DURATION = 10*1000; |
| 185 | |
| 186 | /** Amount of time (in milliseconds) to animate the dim surface from one |
| 187 | * value to another, when no window animation is driving it. |
| 188 | */ |
| 189 | static final int DEFAULT_DIM_DURATION = 200; |
| 190 | |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 191 | /** Amount of time (in milliseconds) to animate the fade-in-out transition for |
| 192 | * compatible windows. |
| 193 | */ |
| 194 | static final int DEFAULT_FADE_IN_OUT_DURATION = 400; |
| 195 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 196 | /** Adjustment to time to perform a dim, to make it more dramatic. |
| 197 | */ |
| 198 | static final int DIM_DURATION_MULTIPLIER = 6; |
| Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 199 | |
| 200 | // Maximum number of milliseconds to wait for input event injection. |
| 201 | // FIXME is this value reasonable? |
| 202 | private static final int INJECTION_TIMEOUT_MILLIS = 30 * 1000; |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 203 | |
| 204 | // Default input dispatching timeout in nanoseconds. |
| 205 | private static final long DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS = 5000 * 1000000L; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 206 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 207 | static final int UPDATE_FOCUS_NORMAL = 0; |
| 208 | static final int UPDATE_FOCUS_WILL_ASSIGN_LAYERS = 1; |
| 209 | static final int UPDATE_FOCUS_PLACING_SURFACES = 2; |
| 210 | static final int UPDATE_FOCUS_WILL_PLACE_SURFACES = 3; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 211 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 212 | private static final String SYSTEM_SECURE = "ro.secure"; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 213 | private static final String SYSTEM_DEBUGGABLE = "ro.debuggable"; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 214 | |
| 215 | /** |
| 216 | * Condition waited on by {@link #reenableKeyguard} to know the call to |
| 217 | * the window policy has finished. |
| Mike Lockwood | 983ee09 | 2009-11-22 01:42:24 -0500 | [diff] [blame] | 218 | * This is set to true only if mKeyguardTokenWatcher.acquired() has |
| 219 | * actually disabled the keyguard. |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 220 | */ |
| Mike Lockwood | 983ee09 | 2009-11-22 01:42:24 -0500 | [diff] [blame] | 221 | private boolean mKeyguardDisabled = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 222 | |
| Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 223 | private static final int ALLOW_DISABLE_YES = 1; |
| 224 | private static final int ALLOW_DISABLE_NO = 0; |
| 225 | private static final int ALLOW_DISABLE_UNKNOWN = -1; // check with DevicePolicyManager |
| 226 | private int mAllowDisableKeyguard = ALLOW_DISABLE_UNKNOWN; // sync'd by mKeyguardTokenWatcher |
| 227 | |
| Mike Lockwood | 983ee09 | 2009-11-22 01:42:24 -0500 | [diff] [blame] | 228 | final TokenWatcher mKeyguardTokenWatcher = new TokenWatcher( |
| 229 | new Handler(), "WindowManagerService.mKeyguardTokenWatcher") { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 230 | public void acquired() { |
| Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 231 | if (shouldAllowDisableKeyguard()) { |
| 232 | mPolicy.enableKeyguard(false); |
| 233 | mKeyguardDisabled = true; |
| 234 | } else { |
| 235 | Log.v(TAG, "Not disabling keyguard since device policy is enforced"); |
| 236 | } |
| 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 | |
| Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 247 | final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() { |
| 248 | @Override |
| 249 | public void onReceive(Context context, Intent intent) { |
| 250 | mPolicy.enableKeyguard(true); |
| 251 | synchronized(mKeyguardTokenWatcher) { |
| 252 | // lazily evaluate this next time we're asked to disable keyguard |
| 253 | mAllowDisableKeyguard = ALLOW_DISABLE_UNKNOWN; |
| 254 | mKeyguardDisabled = false; |
| 255 | } |
| 256 | } |
| 257 | }; |
| 258 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 259 | final Context mContext; |
| 260 | |
| 261 | final boolean mHaveInputMethods; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 262 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 263 | final boolean mLimitedAlphaCompositing; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 264 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 265 | final WindowManagerPolicy mPolicy = PolicyManager.makeNewWindowManager(); |
| 266 | |
| 267 | final IActivityManager mActivityManager; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 268 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 269 | final IBatteryStats mBatteryStats; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 270 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 271 | /** |
| 272 | * All currently active sessions with clients. |
| 273 | */ |
| 274 | final HashSet<Session> mSessions = new HashSet<Session>(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 275 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 276 | /** |
| 277 | * Mapping from an IWindow IBinder to the server's Window object. |
| 278 | * This is also used as the lock for all of our state. |
| 279 | */ |
| 280 | final HashMap<IBinder, WindowState> mWindowMap = new HashMap<IBinder, WindowState>(); |
| 281 | |
| 282 | /** |
| 283 | * Mapping from a token IBinder to a WindowToken object. |
| 284 | */ |
| 285 | final HashMap<IBinder, WindowToken> mTokenMap = |
| 286 | new HashMap<IBinder, WindowToken>(); |
| 287 | |
| 288 | /** |
| 289 | * The same tokens as mTokenMap, stored in a list for efficient iteration |
| 290 | * over them. |
| 291 | */ |
| 292 | final ArrayList<WindowToken> mTokenList = new ArrayList<WindowToken>(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 293 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 294 | /** |
| 295 | * Window tokens that are in the process of exiting, but still |
| 296 | * on screen for animations. |
| 297 | */ |
| 298 | final ArrayList<WindowToken> mExitingTokens = new ArrayList<WindowToken>(); |
| 299 | |
| 300 | /** |
| 301 | * Z-ordered (bottom-most first) list of all application tokens, for |
| 302 | * controlling the ordering of windows in different applications. This |
| 303 | * contains WindowToken objects. |
| 304 | */ |
| 305 | final ArrayList<AppWindowToken> mAppTokens = new ArrayList<AppWindowToken>(); |
| 306 | |
| 307 | /** |
| 308 | * Application tokens that are in the process of exiting, but still |
| 309 | * on screen for animations. |
| 310 | */ |
| 311 | final ArrayList<AppWindowToken> mExitingAppTokens = new ArrayList<AppWindowToken>(); |
| 312 | |
| 313 | /** |
| 314 | * List of window tokens that have finished starting their application, |
| 315 | * and now need to have the policy remove their windows. |
| 316 | */ |
| 317 | final ArrayList<AppWindowToken> mFinishedStarting = new ArrayList<AppWindowToken>(); |
| 318 | |
| 319 | /** |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 320 | * This was the app token that was used to retrieve the last enter |
| 321 | * animation. It will be used for the next exit animation. |
| 322 | */ |
| 323 | AppWindowToken mLastEnterAnimToken; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 324 | |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 325 | /** |
| 326 | * These were the layout params used to retrieve the last enter animation. |
| 327 | * They will be used for the next exit animation. |
| 328 | */ |
| 329 | LayoutParams mLastEnterAnimParams; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 330 | |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 331 | /** |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 332 | * Z-ordered (bottom-most first) list of all Window objects. |
| 333 | */ |
| 334 | final ArrayList mWindows = new ArrayList(); |
| 335 | |
| 336 | /** |
| 337 | * Windows that are being resized. Used so we can tell the client about |
| 338 | * the resize after closing the transaction in which we resized the |
| 339 | * underlying surface. |
| 340 | */ |
| 341 | final ArrayList<WindowState> mResizingWindows = new ArrayList<WindowState>(); |
| 342 | |
| 343 | /** |
| 344 | * Windows whose animations have ended and now must be removed. |
| 345 | */ |
| 346 | final ArrayList<WindowState> mPendingRemove = new ArrayList<WindowState>(); |
| 347 | |
| 348 | /** |
| 349 | * Windows whose surface should be destroyed. |
| 350 | */ |
| 351 | final ArrayList<WindowState> mDestroySurface = new ArrayList<WindowState>(); |
| 352 | |
| 353 | /** |
| 354 | * Windows that have lost input focus and are waiting for the new |
| 355 | * focus window to be displayed before they are told about this. |
| 356 | */ |
| 357 | ArrayList<WindowState> mLosingFocus = new ArrayList<WindowState>(); |
| 358 | |
| 359 | /** |
| 360 | * This is set when we have run out of memory, and will either be an empty |
| 361 | * list or contain windows that need to be force removed. |
| 362 | */ |
| 363 | ArrayList<WindowState> mForceRemoves; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 364 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 365 | IInputMethodManager mInputMethodManager; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 366 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 367 | SurfaceSession mFxSession; |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 368 | private DimAnimator mDimAnimator = null; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 369 | Surface mBlurSurface; |
| 370 | boolean mBlurShown; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 371 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 372 | int mTransactionSequence = 0; |
| 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 | final float[] mTmpFloats = new float[9]; |
| 375 | |
| 376 | boolean mSafeMode; |
| 377 | boolean mDisplayEnabled = false; |
| 378 | boolean mSystemBooted = false; |
| Christopher Tate | b696aee | 2010-04-02 19:08:30 -0700 | [diff] [blame] | 379 | int mInitialDisplayWidth = 0; |
| 380 | int mInitialDisplayHeight = 0; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 381 | int mRotation = 0; |
| 382 | int mRequestedRotation = 0; |
| 383 | int mForcedAppOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
| Dianne Hackborn | 321ae68 | 2009-03-27 16:16:03 -0700 | [diff] [blame] | 384 | int mLastRotationFlags; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 385 | ArrayList<IRotationWatcher> mRotationWatchers |
| 386 | = new ArrayList<IRotationWatcher>(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 387 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 388 | boolean mLayoutNeeded = true; |
| 389 | boolean mAnimationPending = false; |
| 390 | boolean mDisplayFrozen = false; |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 391 | boolean mWaitingForConfig = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 392 | boolean mWindowsFreezingScreen = false; |
| 393 | long mFreezeGcPending = 0; |
| 394 | int mAppsFreezingScreen = 0; |
| 395 | |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 396 | int mLayoutSeq = 0; |
| 397 | |
| Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 398 | // State while inside of layoutAndPlaceSurfacesLocked(). |
| 399 | boolean mFocusMayChange; |
| 400 | |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 401 | Configuration mCurConfiguration = new Configuration(); |
| 402 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 403 | // This is held as long as we have the screen frozen, to give us time to |
| 404 | // perform a rotation animation when turning off shows the lock screen which |
| 405 | // changes the orientation. |
| 406 | PowerManager.WakeLock mScreenFrozenLock; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 407 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 408 | // State management of app transitions. When we are preparing for a |
| 409 | // transition, mNextAppTransition will be the kind of transition to |
| 410 | // perform or TRANSIT_NONE if we are not waiting. If we are waiting, |
| 411 | // mOpeningApps and mClosingApps are the lists of tokens that will be |
| 412 | // made visible or hidden at the next transition. |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 413 | int mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 414 | String mNextAppTransitionPackage; |
| 415 | int mNextAppTransitionEnter; |
| 416 | int mNextAppTransitionExit; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 417 | boolean mAppTransitionReady = false; |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 418 | boolean mAppTransitionRunning = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 419 | boolean mAppTransitionTimeout = false; |
| 420 | boolean mStartingIconInTransition = false; |
| 421 | boolean mSkipAppTransitionAnimation = false; |
| 422 | final ArrayList<AppWindowToken> mOpeningApps = new ArrayList<AppWindowToken>(); |
| 423 | final ArrayList<AppWindowToken> mClosingApps = new ArrayList<AppWindowToken>(); |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 424 | final ArrayList<AppWindowToken> mToTopApps = new ArrayList<AppWindowToken>(); |
| 425 | final ArrayList<AppWindowToken> mToBottomApps = new ArrayList<AppWindowToken>(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 426 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 427 | Display mDisplay; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 428 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 429 | H mH = new H(); |
| 430 | |
| 431 | WindowState mCurrentFocus = null; |
| 432 | WindowState mLastFocus = null; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 433 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 434 | // This just indicates the window the input method is on top of, not |
| 435 | // necessarily the window its input is going to. |
| 436 | WindowState mInputMethodTarget = null; |
| 437 | WindowState mUpcomingInputMethodTarget = null; |
| 438 | boolean mInputMethodTargetWaitingAnim; |
| 439 | int mInputMethodAnimLayerAdjustment; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 440 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 441 | WindowState mInputMethodWindow = null; |
| 442 | final ArrayList<WindowState> mInputMethodDialogs = new ArrayList<WindowState>(); |
| 443 | |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 444 | final ArrayList<WindowToken> mWallpaperTokens = new ArrayList<WindowToken>(); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 445 | |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 446 | // If non-null, this is the currently visible window that is associated |
| 447 | // with the wallpaper. |
| 448 | WindowState mWallpaperTarget = null; |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 449 | // If non-null, we are in the middle of animating from one wallpaper target |
| 450 | // to another, and this is the lower one in Z-order. |
| 451 | WindowState mLowerWallpaperTarget = null; |
| 452 | // If non-null, we are in the middle of animating from one wallpaper target |
| 453 | // to another, and this is the higher one in Z-order. |
| 454 | WindowState mUpperWallpaperTarget = null; |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 455 | int mWallpaperAnimLayerAdjustment; |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 456 | float mLastWallpaperX = -1; |
| 457 | float mLastWallpaperY = -1; |
| Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 458 | float mLastWallpaperXStep = -1; |
| 459 | float mLastWallpaperYStep = -1; |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 460 | // This is set when we are waiting for a wallpaper to tell us it is done |
| 461 | // changing its scroll position. |
| 462 | WindowState mWaitingOnWallpaper; |
| 463 | // The last time we had a timeout when waiting for a wallpaper. |
| 464 | long mLastWallpaperTimeoutTime; |
| 465 | // We give a wallpaper up to 150ms to finish scrolling. |
| 466 | static final long WALLPAPER_TIMEOUT = 150; |
| 467 | // Time we wait after a timeout before trying to wait again. |
| 468 | static final long WALLPAPER_TIMEOUT_RECOVERY = 10000; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 469 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 470 | AppWindowToken mFocusedApp = null; |
| 471 | |
| 472 | PowerManagerService mPowerManager; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 473 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 474 | float mWindowAnimationScale = 1.0f; |
| 475 | float mTransitionAnimationScale = 1.0f; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 476 | |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 477 | final InputManager mInputManager; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 478 | |
| 479 | // Who is holding the screen on. |
| 480 | Session mHoldingScreenOn; |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 481 | PowerManager.WakeLock mHoldingScreenWakeLock; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 482 | |
| Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 483 | boolean mTurnOnScreen; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 484 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 485 | /** |
| 486 | * Whether the UI is currently running in touch mode (not showing |
| 487 | * navigational focus because the user is directly pressing the screen). |
| 488 | */ |
| 489 | boolean mInTouchMode = false; |
| 490 | |
| 491 | private ViewServer mViewServer; |
| 492 | |
| Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 493 | final Configuration mTempConfiguration = new Configuration(); |
| Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 494 | int mScreenLayout = Configuration.SCREENLAYOUT_SIZE_UNDEFINED; |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 495 | |
| 496 | // The frame use to limit the size of the app running in compatibility mode. |
| 497 | Rect mCompatibleScreenFrame = new Rect(); |
| 498 | // The surface used to fill the outer rim of the app running in compatibility mode. |
| 499 | Surface mBackgroundFillerSurface = null; |
| 500 | boolean mBackgroundFillerShown = false; |
| 501 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 502 | public static WindowManagerService main(Context context, |
| 503 | PowerManagerService pm, boolean haveInputMethods) { |
| 504 | WMThread thr = new WMThread(context, pm, haveInputMethods); |
| 505 | thr.start(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 506 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 507 | synchronized (thr) { |
| 508 | while (thr.mService == null) { |
| 509 | try { |
| 510 | thr.wait(); |
| 511 | } catch (InterruptedException e) { |
| 512 | } |
| 513 | } |
| 514 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 515 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 516 | return thr.mService; |
| 517 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 518 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 519 | static class WMThread extends Thread { |
| 520 | WindowManagerService mService; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 521 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 522 | private final Context mContext; |
| 523 | private final PowerManagerService mPM; |
| 524 | private final boolean mHaveInputMethods; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 525 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 526 | public WMThread(Context context, PowerManagerService pm, |
| 527 | boolean haveInputMethods) { |
| 528 | super("WindowManager"); |
| 529 | mContext = context; |
| 530 | mPM = pm; |
| 531 | mHaveInputMethods = haveInputMethods; |
| 532 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 533 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 534 | public void run() { |
| 535 | Looper.prepare(); |
| 536 | WindowManagerService s = new WindowManagerService(mContext, mPM, |
| 537 | mHaveInputMethods); |
| 538 | android.os.Process.setThreadPriority( |
| 539 | android.os.Process.THREAD_PRIORITY_DISPLAY); |
| Christopher Tate | 160edb3 | 2010-06-30 17:46:30 -0700 | [diff] [blame] | 540 | android.os.Process.setCanSelfBackground(false); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 541 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 542 | synchronized (this) { |
| 543 | mService = s; |
| 544 | notifyAll(); |
| 545 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 546 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 547 | Looper.loop(); |
| 548 | } |
| 549 | } |
| 550 | |
| 551 | static class PolicyThread extends Thread { |
| 552 | private final WindowManagerPolicy mPolicy; |
| 553 | private final WindowManagerService mService; |
| 554 | private final Context mContext; |
| 555 | private final PowerManagerService mPM; |
| 556 | boolean mRunning = false; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 557 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 558 | public PolicyThread(WindowManagerPolicy policy, |
| 559 | WindowManagerService service, Context context, |
| 560 | PowerManagerService pm) { |
| 561 | super("WindowManagerPolicy"); |
| 562 | mPolicy = policy; |
| 563 | mService = service; |
| 564 | mContext = context; |
| 565 | mPM = pm; |
| 566 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 567 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 568 | public void run() { |
| 569 | Looper.prepare(); |
| Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 570 | WindowManagerPolicyThread.set(this, Looper.myLooper()); |
| 571 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 572 | //Looper.myLooper().setMessageLogging(new LogPrinter( |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 573 | // Log.VERBOSE, "WindowManagerPolicy", Log.LOG_ID_SYSTEM)); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 574 | android.os.Process.setThreadPriority( |
| 575 | android.os.Process.THREAD_PRIORITY_FOREGROUND); |
| Christopher Tate | 160edb3 | 2010-06-30 17:46:30 -0700 | [diff] [blame] | 576 | android.os.Process.setCanSelfBackground(false); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 577 | mPolicy.init(mContext, mService, mPM); |
| 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 | synchronized (this) { |
| 580 | mRunning = true; |
| 581 | notifyAll(); |
| 582 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 583 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 584 | Looper.loop(); |
| 585 | } |
| 586 | } |
| 587 | |
| 588 | private WindowManagerService(Context context, PowerManagerService pm, |
| 589 | boolean haveInputMethods) { |
| Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 590 | if (MEASURE_LATENCY) { |
| 591 | lt = new LatencyTimer(100, 1000); |
| 592 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 593 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 594 | mContext = context; |
| 595 | mHaveInputMethods = haveInputMethods; |
| 596 | mLimitedAlphaCompositing = context.getResources().getBoolean( |
| 597 | com.android.internal.R.bool.config_sf_limitedAlpha); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 598 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 599 | mPowerManager = pm; |
| 600 | mPowerManager.setPolicy(mPolicy); |
| 601 | PowerManager pmc = (PowerManager)context.getSystemService(Context.POWER_SERVICE); |
| 602 | mScreenFrozenLock = pmc.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, |
| 603 | "SCREEN_FROZEN"); |
| 604 | mScreenFrozenLock.setReferenceCounted(false); |
| 605 | |
| 606 | mActivityManager = ActivityManagerNative.getDefault(); |
| 607 | mBatteryStats = BatteryStatsService.getService(); |
| 608 | |
| 609 | // Get persisted window scale setting |
| 610 | mWindowAnimationScale = Settings.System.getFloat(context.getContentResolver(), |
| 611 | Settings.System.WINDOW_ANIMATION_SCALE, mWindowAnimationScale); |
| 612 | mTransitionAnimationScale = Settings.System.getFloat(context.getContentResolver(), |
| 613 | Settings.System.TRANSITION_ANIMATION_SCALE, mTransitionAnimationScale); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 614 | |
| Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 615 | // Track changes to DevicePolicyManager state so we can enable/disable keyguard. |
| 616 | IntentFilter filter = new IntentFilter(); |
| 617 | filter.addAction(DevicePolicyManager.ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED); |
| 618 | mContext.registerReceiver(mBroadcastReceiver, filter); |
| 619 | |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 620 | mHoldingScreenWakeLock = pmc.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK, |
| 621 | "KEEP_SCREEN_ON_FLAG"); |
| 622 | mHoldingScreenWakeLock.setReferenceCounted(false); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 623 | |
| Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 624 | mInputManager = new InputManager(context, this, pmc, mPowerManager); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 625 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 626 | PolicyThread thr = new PolicyThread(mPolicy, this, context, pm); |
| 627 | thr.start(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 628 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 629 | synchronized (thr) { |
| 630 | while (!thr.mRunning) { |
| 631 | try { |
| 632 | thr.wait(); |
| 633 | } catch (InterruptedException e) { |
| 634 | } |
| 635 | } |
| 636 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 637 | |
| Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 638 | mInputManager.start(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 639 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 640 | // Add ourself to the Watchdog monitors. |
| 641 | Watchdog.getInstance().addMonitor(this); |
| 642 | } |
| 643 | |
| 644 | @Override |
| 645 | public boolean onTransact(int code, Parcel data, Parcel reply, int flags) |
| 646 | throws RemoteException { |
| 647 | try { |
| 648 | return super.onTransact(code, data, reply, flags); |
| 649 | } catch (RuntimeException e) { |
| 650 | // The window manager only throws security exceptions, so let's |
| 651 | // log all others. |
| 652 | if (!(e instanceof SecurityException)) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 653 | Slog.e(TAG, "Window Manager Crash", e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 654 | } |
| 655 | throw e; |
| 656 | } |
| 657 | } |
| 658 | |
| 659 | private void placeWindowAfter(Object pos, WindowState window) { |
| 660 | final int i = mWindows.indexOf(pos); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 661 | if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 662 | TAG, "Adding window " + window + " at " |
| 663 | + (i+1) + " of " + mWindows.size() + " (after " + pos + ")"); |
| 664 | mWindows.add(i+1, window); |
| 665 | } |
| 666 | |
| 667 | private void placeWindowBefore(Object pos, WindowState window) { |
| 668 | final int i = mWindows.indexOf(pos); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 669 | if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 670 | TAG, "Adding window " + window + " at " |
| 671 | + i + " of " + mWindows.size() + " (before " + pos + ")"); |
| 672 | mWindows.add(i, window); |
| 673 | } |
| 674 | |
| 675 | //This method finds out the index of a window that has the same app token as |
| 676 | //win. used for z ordering the windows in mWindows |
| 677 | private int findIdxBasedOnAppTokens(WindowState win) { |
| 678 | //use a local variable to cache mWindows |
| 679 | ArrayList localmWindows = mWindows; |
| 680 | int jmax = localmWindows.size(); |
| 681 | if(jmax == 0) { |
| 682 | return -1; |
| 683 | } |
| 684 | for(int j = (jmax-1); j >= 0; j--) { |
| 685 | WindowState wentry = (WindowState)localmWindows.get(j); |
| 686 | if(wentry.mAppToken == win.mAppToken) { |
| 687 | return j; |
| 688 | } |
| 689 | } |
| 690 | return -1; |
| 691 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 692 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 693 | private void addWindowToListInOrderLocked(WindowState win, boolean addToToken) { |
| 694 | final IWindow client = win.mClient; |
| 695 | final WindowToken token = win.mToken; |
| 696 | final ArrayList localmWindows = mWindows; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 697 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 698 | final int N = localmWindows.size(); |
| 699 | final WindowState attached = win.mAttachedWindow; |
| 700 | int i; |
| 701 | if (attached == null) { |
| 702 | int tokenWindowsPos = token.windows.size(); |
| 703 | if (token.appWindowToken != null) { |
| 704 | int index = tokenWindowsPos-1; |
| 705 | if (index >= 0) { |
| 706 | // If this application has existing windows, we |
| 707 | // simply place the new window on top of them... but |
| 708 | // keep the starting window on top. |
| 709 | if (win.mAttrs.type == TYPE_BASE_APPLICATION) { |
| 710 | // Base windows go behind everything else. |
| 711 | placeWindowBefore(token.windows.get(0), win); |
| 712 | tokenWindowsPos = 0; |
| 713 | } else { |
| 714 | AppWindowToken atoken = win.mAppToken; |
| 715 | if (atoken != null && |
| 716 | token.windows.get(index) == atoken.startingWindow) { |
| 717 | placeWindowBefore(token.windows.get(index), win); |
| 718 | tokenWindowsPos--; |
| 719 | } else { |
| 720 | int newIdx = findIdxBasedOnAppTokens(win); |
| 721 | if(newIdx != -1) { |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 722 | //there is a window above this one associated with the same |
| 723 | //apptoken note that the window could be a floating window |
| 724 | //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] | 725 | //windows associated with this token. |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 726 | if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v( |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 727 | TAG, "Adding window " + win + " at " |
| 728 | + (newIdx+1) + " of " + N); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 729 | localmWindows.add(newIdx+1, win); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 730 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 731 | } |
| 732 | } |
| 733 | } else { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 734 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 735 | TAG, "Figuring out where to add app window " |
| 736 | + client.asBinder() + " (token=" + token + ")"); |
| 737 | // Figure out where the window should go, based on the |
| 738 | // order of applications. |
| 739 | final int NA = mAppTokens.size(); |
| 740 | Object pos = null; |
| 741 | for (i=NA-1; i>=0; i--) { |
| 742 | AppWindowToken t = mAppTokens.get(i); |
| 743 | if (t == token) { |
| 744 | i--; |
| 745 | break; |
| 746 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 747 | |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 748 | // We haven't reached the token yet; if this token |
| 749 | // is not going to the bottom and has windows, we can |
| 750 | // use it as an anchor for when we do reach the token. |
| 751 | if (!t.sendingToBottom && t.windows.size() > 0) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 752 | pos = t.windows.get(0); |
| 753 | } |
| 754 | } |
| 755 | // We now know the index into the apps. If we found |
| 756 | // an app window above, that gives us the position; else |
| 757 | // we need to look some more. |
| 758 | if (pos != null) { |
| 759 | // Move behind any windows attached to this one. |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 760 | WindowToken atoken = |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 761 | mTokenMap.get(((WindowState)pos).mClient.asBinder()); |
| 762 | if (atoken != null) { |
| 763 | final int NC = atoken.windows.size(); |
| 764 | if (NC > 0) { |
| 765 | WindowState bottom = atoken.windows.get(0); |
| 766 | if (bottom.mSubLayer < 0) { |
| 767 | pos = bottom; |
| 768 | } |
| 769 | } |
| 770 | } |
| 771 | placeWindowBefore(pos, win); |
| 772 | } else { |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 773 | // Continue looking down until we find the first |
| 774 | // token that has windows. |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 775 | while (i >= 0) { |
| 776 | AppWindowToken t = mAppTokens.get(i); |
| 777 | final int NW = t.windows.size(); |
| 778 | if (NW > 0) { |
| 779 | pos = t.windows.get(NW-1); |
| 780 | break; |
| 781 | } |
| 782 | i--; |
| 783 | } |
| 784 | if (pos != null) { |
| 785 | // Move in front of any windows attached to this |
| 786 | // one. |
| 787 | WindowToken atoken = |
| 788 | mTokenMap.get(((WindowState)pos).mClient.asBinder()); |
| 789 | if (atoken != null) { |
| 790 | final int NC = atoken.windows.size(); |
| 791 | if (NC > 0) { |
| 792 | WindowState top = atoken.windows.get(NC-1); |
| 793 | if (top.mSubLayer >= 0) { |
| 794 | pos = top; |
| 795 | } |
| 796 | } |
| 797 | } |
| 798 | placeWindowAfter(pos, win); |
| 799 | } else { |
| 800 | // Just search for the start of this layer. |
| 801 | final int myLayer = win.mBaseLayer; |
| 802 | for (i=0; i<N; i++) { |
| 803 | WindowState w = (WindowState)localmWindows.get(i); |
| 804 | if (w.mBaseLayer > myLayer) { |
| 805 | break; |
| 806 | } |
| 807 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 808 | if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v( |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 809 | TAG, "Adding window " + win + " at " |
| 810 | + i + " of " + N); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 811 | localmWindows.add(i, win); |
| 812 | } |
| 813 | } |
| 814 | } |
| 815 | } else { |
| 816 | // Figure out where window should go, based on layer. |
| 817 | final int myLayer = win.mBaseLayer; |
| 818 | for (i=N-1; i>=0; i--) { |
| 819 | if (((WindowState)localmWindows.get(i)).mBaseLayer <= myLayer) { |
| 820 | i++; |
| 821 | break; |
| 822 | } |
| 823 | } |
| 824 | if (i < 0) i = 0; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 825 | if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v( |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 826 | TAG, "Adding window " + win + " at " |
| 827 | + i + " of " + N); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 828 | localmWindows.add(i, win); |
| 829 | } |
| 830 | if (addToToken) { |
| 831 | token.windows.add(tokenWindowsPos, win); |
| 832 | } |
| 833 | |
| 834 | } else { |
| 835 | // Figure out this window's ordering relative to the window |
| 836 | // it is attached to. |
| 837 | final int NA = token.windows.size(); |
| 838 | final int sublayer = win.mSubLayer; |
| 839 | int largestSublayer = Integer.MIN_VALUE; |
| 840 | WindowState windowWithLargestSublayer = null; |
| 841 | for (i=0; i<NA; i++) { |
| 842 | WindowState w = token.windows.get(i); |
| 843 | final int wSublayer = w.mSubLayer; |
| 844 | if (wSublayer >= largestSublayer) { |
| 845 | largestSublayer = wSublayer; |
| 846 | windowWithLargestSublayer = w; |
| 847 | } |
| 848 | if (sublayer < 0) { |
| 849 | // For negative sublayers, we go below all windows |
| 850 | // in the same sublayer. |
| 851 | if (wSublayer >= sublayer) { |
| 852 | if (addToToken) { |
| 853 | token.windows.add(i, win); |
| 854 | } |
| 855 | placeWindowBefore( |
| 856 | wSublayer >= 0 ? attached : w, win); |
| 857 | break; |
| 858 | } |
| 859 | } else { |
| 860 | // For positive sublayers, we go above all windows |
| 861 | // in the same sublayer. |
| 862 | if (wSublayer > sublayer) { |
| 863 | if (addToToken) { |
| 864 | token.windows.add(i, win); |
| 865 | } |
| 866 | placeWindowBefore(w, win); |
| 867 | break; |
| 868 | } |
| 869 | } |
| 870 | } |
| 871 | if (i >= NA) { |
| 872 | if (addToToken) { |
| 873 | token.windows.add(win); |
| 874 | } |
| 875 | if (sublayer < 0) { |
| 876 | placeWindowBefore(attached, win); |
| 877 | } else { |
| 878 | placeWindowAfter(largestSublayer >= 0 |
| 879 | ? windowWithLargestSublayer |
| 880 | : attached, |
| 881 | win); |
| 882 | } |
| 883 | } |
| 884 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 885 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 886 | if (win.mAppToken != null && addToToken) { |
| 887 | win.mAppToken.allAppWindows.add(win); |
| 888 | } |
| 889 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 890 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 891 | static boolean canBeImeTarget(WindowState w) { |
| 892 | final int fl = w.mAttrs.flags |
| 893 | & (FLAG_NOT_FOCUSABLE|FLAG_ALT_FOCUSABLE_IM); |
| 894 | if (fl == 0 || fl == (FLAG_NOT_FOCUSABLE|FLAG_ALT_FOCUSABLE_IM)) { |
| 895 | return w.isVisibleOrAdding(); |
| 896 | } |
| 897 | return false; |
| 898 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 899 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 900 | int findDesiredInputMethodWindowIndexLocked(boolean willMove) { |
| 901 | final ArrayList localmWindows = mWindows; |
| 902 | final int N = localmWindows.size(); |
| 903 | WindowState w = null; |
| 904 | int i = N; |
| 905 | while (i > 0) { |
| 906 | i--; |
| 907 | w = (WindowState)localmWindows.get(i); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 908 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 909 | //Slog.i(TAG, "Checking window @" + i + " " + w + " fl=0x" |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 910 | // + Integer.toHexString(w.mAttrs.flags)); |
| 911 | if (canBeImeTarget(w)) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 912 | //Slog.i(TAG, "Putting input method here!"); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 913 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 914 | // Yet more tricksyness! If this window is a "starting" |
| 915 | // window, we do actually want to be on top of it, but |
| 916 | // it is not -really- where input will go. So if the caller |
| 917 | // is not actually looking to move the IME, look down below |
| 918 | // for a real window to target... |
| 919 | if (!willMove |
| 920 | && w.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING |
| 921 | && i > 0) { |
| 922 | WindowState wb = (WindowState)localmWindows.get(i-1); |
| 923 | if (wb.mAppToken == w.mAppToken && canBeImeTarget(wb)) { |
| 924 | i--; |
| 925 | w = wb; |
| 926 | } |
| 927 | } |
| 928 | break; |
| 929 | } |
| 930 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 931 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 932 | mUpcomingInputMethodTarget = w; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 933 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 934 | if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Desired input method target=" |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 935 | + w + " willMove=" + willMove); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 936 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 937 | if (willMove && w != null) { |
| 938 | final WindowState curTarget = mInputMethodTarget; |
| 939 | if (curTarget != null && curTarget.mAppToken != null) { |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 940 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 941 | // Now some fun for dealing with window animations that |
| 942 | // modify the Z order. We need to look at all windows below |
| 943 | // the current target that are in this app, finding the highest |
| 944 | // visible one in layering. |
| 945 | AppWindowToken token = curTarget.mAppToken; |
| 946 | WindowState highestTarget = null; |
| 947 | int highestPos = 0; |
| 948 | if (token.animating || token.animation != null) { |
| 949 | int pos = 0; |
| 950 | pos = localmWindows.indexOf(curTarget); |
| 951 | while (pos >= 0) { |
| 952 | WindowState win = (WindowState)localmWindows.get(pos); |
| 953 | if (win.mAppToken != token) { |
| 954 | break; |
| 955 | } |
| 956 | if (!win.mRemoved) { |
| 957 | if (highestTarget == null || win.mAnimLayer > |
| 958 | highestTarget.mAnimLayer) { |
| 959 | highestTarget = win; |
| 960 | highestPos = pos; |
| 961 | } |
| 962 | } |
| 963 | pos--; |
| 964 | } |
| 965 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 966 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 967 | if (highestTarget != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 968 | if (DEBUG_INPUT_METHOD) Slog.v(TAG, "mNextAppTransition=" |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 969 | + mNextAppTransition + " " + highestTarget |
| 970 | + " animating=" + highestTarget.isAnimating() |
| 971 | + " layer=" + highestTarget.mAnimLayer |
| 972 | + " new layer=" + w.mAnimLayer); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 973 | |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 974 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 975 | // If we are currently setting up for an animation, |
| 976 | // hold everything until we can find out what will happen. |
| 977 | mInputMethodTargetWaitingAnim = true; |
| 978 | mInputMethodTarget = highestTarget; |
| 979 | return highestPos + 1; |
| 980 | } else if (highestTarget.isAnimating() && |
| 981 | highestTarget.mAnimLayer > w.mAnimLayer) { |
| 982 | // If the window we are currently targeting is involved |
| 983 | // with an animation, and it is on top of the next target |
| 984 | // we will be over, then hold off on moving until |
| 985 | // that is done. |
| 986 | mInputMethodTarget = highestTarget; |
| 987 | return highestPos + 1; |
| 988 | } |
| 989 | } |
| 990 | } |
| 991 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 992 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 993 | //Slog.i(TAG, "Placing input method @" + (i+1)); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 994 | if (w != null) { |
| 995 | if (willMove) { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 996 | if (DEBUG_INPUT_METHOD) { |
| 997 | RuntimeException e = null; |
| 998 | if (!HIDE_STACK_CRAWLS) { |
| 999 | e = new RuntimeException(); |
| 1000 | e.fillInStackTrace(); |
| 1001 | } |
| 1002 | Slog.w(TAG, "Moving IM target from " |
| 1003 | + mInputMethodTarget + " to " + w, e); |
| 1004 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1005 | mInputMethodTarget = w; |
| 1006 | if (w.mAppToken != null) { |
| 1007 | setInputMethodAnimLayerAdjustment(w.mAppToken.animLayerAdjustment); |
| 1008 | } else { |
| 1009 | setInputMethodAnimLayerAdjustment(0); |
| 1010 | } |
| 1011 | } |
| 1012 | return i+1; |
| 1013 | } |
| 1014 | if (willMove) { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 1015 | if (DEBUG_INPUT_METHOD) { |
| 1016 | RuntimeException e = null; |
| 1017 | if (!HIDE_STACK_CRAWLS) { |
| 1018 | e = new RuntimeException(); |
| 1019 | e.fillInStackTrace(); |
| 1020 | } |
| 1021 | Slog.w(TAG, "Moving IM target from " |
| 1022 | + mInputMethodTarget + " to null", e); |
| 1023 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1024 | mInputMethodTarget = null; |
| 1025 | setInputMethodAnimLayerAdjustment(0); |
| 1026 | } |
| 1027 | return -1; |
| 1028 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1029 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1030 | void addInputMethodWindowToListLocked(WindowState win) { |
| 1031 | int pos = findDesiredInputMethodWindowIndexLocked(true); |
| 1032 | if (pos >= 0) { |
| 1033 | win.mTargetAppToken = mInputMethodTarget.mAppToken; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1034 | if (DEBUG_WINDOW_MOVEMENT) Slog.v( |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 1035 | TAG, "Adding input method window " + win + " at " + pos); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1036 | mWindows.add(pos, win); |
| 1037 | moveInputMethodDialogsLocked(pos+1); |
| 1038 | return; |
| 1039 | } |
| 1040 | win.mTargetAppToken = null; |
| 1041 | addWindowToListInOrderLocked(win, true); |
| 1042 | moveInputMethodDialogsLocked(pos); |
| 1043 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1044 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1045 | void setInputMethodAnimLayerAdjustment(int adj) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1046 | if (DEBUG_LAYERS) Slog.v(TAG, "Setting im layer adj to " + adj); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1047 | mInputMethodAnimLayerAdjustment = adj; |
| 1048 | WindowState imw = mInputMethodWindow; |
| 1049 | if (imw != null) { |
| 1050 | imw.mAnimLayer = imw.mLayer + adj; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1051 | if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + imw |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1052 | + " anim layer: " + imw.mAnimLayer); |
| 1053 | int wi = imw.mChildWindows.size(); |
| 1054 | while (wi > 0) { |
| 1055 | wi--; |
| 1056 | WindowState cw = (WindowState)imw.mChildWindows.get(wi); |
| 1057 | cw.mAnimLayer = cw.mLayer + adj; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1058 | if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + cw |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1059 | + " anim layer: " + cw.mAnimLayer); |
| 1060 | } |
| 1061 | } |
| 1062 | int di = mInputMethodDialogs.size(); |
| 1063 | while (di > 0) { |
| 1064 | di --; |
| 1065 | imw = mInputMethodDialogs.get(di); |
| 1066 | imw.mAnimLayer = imw.mLayer + adj; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1067 | if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + imw |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1068 | + " anim layer: " + imw.mAnimLayer); |
| 1069 | } |
| 1070 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1071 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1072 | private int tmpRemoveWindowLocked(int interestingPos, WindowState win) { |
| 1073 | int wpos = mWindows.indexOf(win); |
| 1074 | if (wpos >= 0) { |
| 1075 | if (wpos < interestingPos) interestingPos--; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1076 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Temp removing at " + wpos + ": " + win); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1077 | mWindows.remove(wpos); |
| 1078 | int NC = win.mChildWindows.size(); |
| 1079 | while (NC > 0) { |
| 1080 | NC--; |
| 1081 | WindowState cw = (WindowState)win.mChildWindows.get(NC); |
| 1082 | int cpos = mWindows.indexOf(cw); |
| 1083 | if (cpos >= 0) { |
| 1084 | if (cpos < interestingPos) interestingPos--; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1085 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Temp removing child at " |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 1086 | + cpos + ": " + cw); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1087 | mWindows.remove(cpos); |
| 1088 | } |
| 1089 | } |
| 1090 | } |
| 1091 | return interestingPos; |
| 1092 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1093 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1094 | private void reAddWindowToListInOrderLocked(WindowState win) { |
| 1095 | addWindowToListInOrderLocked(win, false); |
| 1096 | // This is a hack to get all of the child windows added as well |
| 1097 | // at the right position. Child windows should be rare and |
| 1098 | // this case should be rare, so it shouldn't be that big a deal. |
| 1099 | int wpos = mWindows.indexOf(win); |
| 1100 | if (wpos >= 0) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1101 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "ReAdd removing from " + wpos |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 1102 | + ": " + win); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1103 | mWindows.remove(wpos); |
| 1104 | reAddWindowLocked(wpos, win); |
| 1105 | } |
| 1106 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1107 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1108 | void logWindowList(String prefix) { |
| 1109 | int N = mWindows.size(); |
| 1110 | while (N > 0) { |
| 1111 | N--; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1112 | Slog.v(TAG, prefix + "#" + N + ": " + mWindows.get(N)); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1113 | } |
| 1114 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1115 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1116 | void moveInputMethodDialogsLocked(int pos) { |
| 1117 | ArrayList<WindowState> dialogs = mInputMethodDialogs; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1118 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1119 | final int N = dialogs.size(); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1120 | if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Removing " + N + " dialogs w/pos=" + pos); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1121 | for (int i=0; i<N; i++) { |
| 1122 | pos = tmpRemoveWindowLocked(pos, dialogs.get(i)); |
| 1123 | } |
| 1124 | if (DEBUG_INPUT_METHOD) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1125 | Slog.v(TAG, "Window list w/pos=" + pos); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1126 | logWindowList(" "); |
| 1127 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1128 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1129 | if (pos >= 0) { |
| 1130 | final AppWindowToken targetAppToken = mInputMethodTarget.mAppToken; |
| 1131 | if (pos < mWindows.size()) { |
| 1132 | WindowState wp = (WindowState)mWindows.get(pos); |
| 1133 | if (wp == mInputMethodWindow) { |
| 1134 | pos++; |
| 1135 | } |
| 1136 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1137 | if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Adding " + N + " dialogs at pos=" + pos); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1138 | for (int i=0; i<N; i++) { |
| 1139 | WindowState win = dialogs.get(i); |
| 1140 | win.mTargetAppToken = targetAppToken; |
| 1141 | pos = reAddWindowLocked(pos, win); |
| 1142 | } |
| 1143 | if (DEBUG_INPUT_METHOD) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1144 | Slog.v(TAG, "Final window list:"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1145 | logWindowList(" "); |
| 1146 | } |
| 1147 | return; |
| 1148 | } |
| 1149 | for (int i=0; i<N; i++) { |
| 1150 | WindowState win = dialogs.get(i); |
| 1151 | win.mTargetAppToken = null; |
| 1152 | reAddWindowToListInOrderLocked(win); |
| 1153 | if (DEBUG_INPUT_METHOD) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1154 | Slog.v(TAG, "No IM target, final list:"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1155 | logWindowList(" "); |
| 1156 | } |
| 1157 | } |
| 1158 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1159 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1160 | boolean moveInputMethodWindowsIfNeededLocked(boolean needAssignLayers) { |
| 1161 | final WindowState imWin = mInputMethodWindow; |
| 1162 | final int DN = mInputMethodDialogs.size(); |
| 1163 | if (imWin == null && DN == 0) { |
| 1164 | return false; |
| 1165 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1166 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1167 | int imPos = findDesiredInputMethodWindowIndexLocked(true); |
| 1168 | if (imPos >= 0) { |
| 1169 | // In this case, the input method windows are to be placed |
| 1170 | // immediately above the window they are targeting. |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1171 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1172 | // First check to see if the input method windows are already |
| 1173 | // located here, and contiguous. |
| 1174 | final int N = mWindows.size(); |
| 1175 | WindowState firstImWin = imPos < N |
| 1176 | ? (WindowState)mWindows.get(imPos) : null; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1177 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1178 | // Figure out the actual input method window that should be |
| 1179 | // at the bottom of their stack. |
| 1180 | WindowState baseImWin = imWin != null |
| 1181 | ? imWin : mInputMethodDialogs.get(0); |
| 1182 | if (baseImWin.mChildWindows.size() > 0) { |
| 1183 | WindowState cw = (WindowState)baseImWin.mChildWindows.get(0); |
| 1184 | if (cw.mSubLayer < 0) baseImWin = cw; |
| 1185 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1186 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1187 | if (firstImWin == baseImWin) { |
| 1188 | // The windows haven't moved... but are they still contiguous? |
| 1189 | // First find the top IM window. |
| 1190 | int pos = imPos+1; |
| 1191 | while (pos < N) { |
| 1192 | if (!((WindowState)mWindows.get(pos)).mIsImWindow) { |
| 1193 | break; |
| 1194 | } |
| 1195 | pos++; |
| 1196 | } |
| 1197 | pos++; |
| 1198 | // Now there should be no more input method windows above. |
| 1199 | while (pos < N) { |
| 1200 | if (((WindowState)mWindows.get(pos)).mIsImWindow) { |
| 1201 | break; |
| 1202 | } |
| 1203 | pos++; |
| 1204 | } |
| 1205 | if (pos >= N) { |
| 1206 | // All is good! |
| 1207 | return false; |
| 1208 | } |
| 1209 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1210 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1211 | if (imWin != null) { |
| 1212 | if (DEBUG_INPUT_METHOD) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1213 | Slog.v(TAG, "Moving IM from " + imPos); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1214 | logWindowList(" "); |
| 1215 | } |
| 1216 | imPos = tmpRemoveWindowLocked(imPos, imWin); |
| 1217 | if (DEBUG_INPUT_METHOD) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1218 | Slog.v(TAG, "List after moving with new pos " + imPos + ":"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1219 | logWindowList(" "); |
| 1220 | } |
| 1221 | imWin.mTargetAppToken = mInputMethodTarget.mAppToken; |
| 1222 | reAddWindowLocked(imPos, imWin); |
| 1223 | if (DEBUG_INPUT_METHOD) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1224 | Slog.v(TAG, "List after moving IM to " + imPos + ":"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1225 | logWindowList(" "); |
| 1226 | } |
| 1227 | if (DN > 0) moveInputMethodDialogsLocked(imPos+1); |
| 1228 | } else { |
| 1229 | moveInputMethodDialogsLocked(imPos); |
| 1230 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1231 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1232 | } else { |
| 1233 | // In this case, the input method windows go in a fixed layer, |
| 1234 | // because they aren't currently associated with a focus window. |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1235 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1236 | if (imWin != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1237 | if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Moving IM from " + imPos); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1238 | tmpRemoveWindowLocked(0, imWin); |
| 1239 | imWin.mTargetAppToken = null; |
| 1240 | reAddWindowToListInOrderLocked(imWin); |
| 1241 | if (DEBUG_INPUT_METHOD) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1242 | Slog.v(TAG, "List with no IM target:"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1243 | logWindowList(" "); |
| 1244 | } |
| 1245 | if (DN > 0) moveInputMethodDialogsLocked(-1);; |
| 1246 | } else { |
| 1247 | moveInputMethodDialogsLocked(-1);; |
| 1248 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1249 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1250 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1251 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1252 | if (needAssignLayers) { |
| 1253 | assignLayersLocked(); |
| 1254 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1255 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1256 | return true; |
| 1257 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1258 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1259 | void adjustInputMethodDialogsLocked() { |
| 1260 | moveInputMethodDialogsLocked(findDesiredInputMethodWindowIndexLocked(true)); |
| 1261 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1262 | |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 1263 | final boolean isWallpaperVisible(WindowState wallpaperTarget) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1264 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper vis: target obscured=" |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 1265 | + (wallpaperTarget != null ? Boolean.toString(wallpaperTarget.mObscured) : "??") |
| 1266 | + " anim=" + ((wallpaperTarget != null && wallpaperTarget.mAppToken != null) |
| 1267 | ? wallpaperTarget.mAppToken.animation : null) |
| 1268 | + " upper=" + mUpperWallpaperTarget |
| 1269 | + " lower=" + mLowerWallpaperTarget); |
| 1270 | return (wallpaperTarget != null |
| 1271 | && (!wallpaperTarget.mObscured || (wallpaperTarget.mAppToken != null |
| 1272 | && wallpaperTarget.mAppToken.animation != null))) |
| 1273 | || mUpperWallpaperTarget != null |
| 1274 | || mLowerWallpaperTarget != null; |
| 1275 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1276 | |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 1277 | static final int ADJUST_WALLPAPER_LAYERS_CHANGED = 1<<1; |
| 1278 | static final int ADJUST_WALLPAPER_VISIBILITY_CHANGED = 1<<2; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1279 | |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 1280 | int adjustWallpaperWindowsLocked() { |
| 1281 | int changed = 0; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1282 | |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1283 | final int dw = mDisplay.getWidth(); |
| 1284 | final int dh = mDisplay.getHeight(); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1285 | |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1286 | // First find top-most window that has asked to be on top of the |
| 1287 | // wallpaper; all wallpapers go behind it. |
| 1288 | final ArrayList localmWindows = mWindows; |
| 1289 | int N = localmWindows.size(); |
| 1290 | WindowState w = null; |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1291 | WindowState foundW = null; |
| 1292 | int foundI = 0; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1293 | WindowState topCurW = null; |
| 1294 | int topCurI = 0; |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1295 | int i = N; |
| 1296 | while (i > 0) { |
| 1297 | i--; |
| 1298 | w = (WindowState)localmWindows.get(i); |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1299 | if ((w.mAttrs.type == WindowManager.LayoutParams.TYPE_WALLPAPER)) { |
| 1300 | if (topCurW == null) { |
| 1301 | topCurW = w; |
| 1302 | topCurI = i; |
| 1303 | } |
| 1304 | continue; |
| 1305 | } |
| 1306 | topCurW = null; |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1307 | if (w.mAppToken != null) { |
| 1308 | // If this window's app token is hidden and not animating, |
| 1309 | // it is of no interest to us. |
| 1310 | if (w.mAppToken.hidden && w.mAppToken.animation == null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1311 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1312 | "Skipping hidden or animating token: " + w); |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1313 | topCurW = null; |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1314 | continue; |
| 1315 | } |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1316 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1317 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Win " + w + ": readyfordisplay=" |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1318 | + w.isReadyForDisplay() + " drawpending=" + w.mDrawPending |
| 1319 | + " commitdrawpending=" + w.mCommitDrawPending); |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1320 | if ((w.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0 && w.isReadyForDisplay() |
| Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 1321 | && (mWallpaperTarget == w |
| 1322 | || (!w.mDrawPending && !w.mCommitDrawPending))) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1323 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1324 | "Found wallpaper activity: #" + i + "=" + w); |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1325 | foundW = w; |
| 1326 | foundI = i; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1327 | if (w == mWallpaperTarget && ((w.mAppToken != null |
| 1328 | && w.mAppToken.animation != null) |
| 1329 | || w.mAnimation != null)) { |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1330 | // The current wallpaper target is animating, so we'll |
| 1331 | // look behind it for another possible target and figure |
| 1332 | // out what is going on below. |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1333 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Win " + w |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1334 | + ": token animating, looking behind."); |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1335 | continue; |
| 1336 | } |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1337 | break; |
| 1338 | } |
| 1339 | } |
| 1340 | |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 1341 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1342 | // If we are currently waiting for an app transition, and either |
| 1343 | // the current target or the next target are involved with it, |
| 1344 | // then hold off on doing anything with the wallpaper. |
| 1345 | // Note that we are checking here for just whether the target |
| 1346 | // is part of an app token... which is potentially overly aggressive |
| 1347 | // (the app token may not be involved in the transition), but good |
| 1348 | // enough (we'll just wait until whatever transition is pending |
| 1349 | // executes). |
| 1350 | if (mWallpaperTarget != null && mWallpaperTarget.mAppToken != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1351 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1352 | "Wallpaper not changing: waiting for app anim in current target"); |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 1353 | return 0; |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1354 | } |
| 1355 | if (foundW != null && foundW.mAppToken != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1356 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1357 | "Wallpaper not changing: waiting for app anim in found target"); |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 1358 | return 0; |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1359 | } |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1360 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1361 | |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1362 | if (mWallpaperTarget != foundW) { |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1363 | if (DEBUG_WALLPAPER) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1364 | Slog.v(TAG, "New wallpaper target: " + foundW |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1365 | + " oldTarget: " + mWallpaperTarget); |
| 1366 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1367 | |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1368 | mLowerWallpaperTarget = null; |
| 1369 | mUpperWallpaperTarget = null; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1370 | |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1371 | WindowState oldW = mWallpaperTarget; |
| 1372 | mWallpaperTarget = foundW; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1373 | |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1374 | // Now what is happening... if the current and new targets are |
| 1375 | // animating, then we are in our super special mode! |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1376 | if (foundW != null && oldW != null) { |
| 1377 | boolean oldAnim = oldW.mAnimation != null |
| 1378 | || (oldW.mAppToken != null && oldW.mAppToken.animation != null); |
| 1379 | boolean foundAnim = foundW.mAnimation != null |
| 1380 | || (foundW.mAppToken != null && foundW.mAppToken.animation != null); |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1381 | if (DEBUG_WALLPAPER) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1382 | Slog.v(TAG, "New animation: " + foundAnim |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1383 | + " old animation: " + oldAnim); |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1384 | } |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1385 | if (foundAnim && oldAnim) { |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1386 | int oldI = localmWindows.indexOf(oldW); |
| 1387 | if (DEBUG_WALLPAPER) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1388 | Slog.v(TAG, "New i: " + foundI + " old i: " + oldI); |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1389 | } |
| 1390 | if (oldI >= 0) { |
| 1391 | if (DEBUG_WALLPAPER) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1392 | Slog.v(TAG, "Animating wallpapers: old#" + oldI |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1393 | + "=" + oldW + "; new#" + foundI |
| 1394 | + "=" + foundW); |
| 1395 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1396 | |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1397 | // Set the new target correctly. |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1398 | if (foundW.mAppToken != null && foundW.mAppToken.hiddenRequested) { |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1399 | if (DEBUG_WALLPAPER) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1400 | Slog.v(TAG, "Old wallpaper still the target."); |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1401 | } |
| 1402 | mWallpaperTarget = oldW; |
| 1403 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1404 | |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1405 | // Now set the upper and lower wallpaper targets |
| 1406 | // correctly, and make sure that we are positioning |
| 1407 | // the wallpaper below the lower. |
| 1408 | if (foundI > oldI) { |
| 1409 | // The new target is on top of the old one. |
| 1410 | if (DEBUG_WALLPAPER) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1411 | Slog.v(TAG, "Found target above old target."); |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1412 | } |
| 1413 | mUpperWallpaperTarget = foundW; |
| 1414 | mLowerWallpaperTarget = oldW; |
| 1415 | foundW = oldW; |
| 1416 | foundI = oldI; |
| 1417 | } else { |
| 1418 | // The new target is below the old one. |
| 1419 | if (DEBUG_WALLPAPER) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1420 | Slog.v(TAG, "Found target below old target."); |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1421 | } |
| 1422 | mUpperWallpaperTarget = oldW; |
| 1423 | mLowerWallpaperTarget = foundW; |
| 1424 | } |
| 1425 | } |
| 1426 | } |
| 1427 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1428 | |
| Dianne Hackborn | 6b1cb35 | 2009-09-28 18:27:26 -0700 | [diff] [blame] | 1429 | } else if (mLowerWallpaperTarget != null) { |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1430 | // Is it time to stop animating? |
| Dianne Hackborn | 6b1cb35 | 2009-09-28 18:27:26 -0700 | [diff] [blame] | 1431 | boolean lowerAnimating = mLowerWallpaperTarget.mAnimation != null |
| 1432 | || (mLowerWallpaperTarget.mAppToken != null |
| 1433 | && mLowerWallpaperTarget.mAppToken.animation != null); |
| 1434 | boolean upperAnimating = mUpperWallpaperTarget.mAnimation != null |
| 1435 | || (mUpperWallpaperTarget.mAppToken != null |
| 1436 | && mUpperWallpaperTarget.mAppToken.animation != null); |
| 1437 | if (!lowerAnimating || !upperAnimating) { |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1438 | if (DEBUG_WALLPAPER) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1439 | Slog.v(TAG, "No longer animating wallpaper targets!"); |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1440 | } |
| 1441 | mLowerWallpaperTarget = null; |
| 1442 | mUpperWallpaperTarget = null; |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1443 | } |
| 1444 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1445 | |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1446 | boolean visible = foundW != null; |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 1447 | if (visible) { |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1448 | // The window is visible to the compositor... but is it visible |
| 1449 | // to the user? That is what the wallpaper cares about. |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 1450 | visible = isWallpaperVisible(foundW); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1451 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper visibility: " + visible); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1452 | |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1453 | // If the wallpaper target is animating, we may need to copy |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1454 | // its layer adjustment. Only do this if we are not transfering |
| 1455 | // between two wallpaper targets. |
| 1456 | mWallpaperAnimLayerAdjustment = |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1457 | (mLowerWallpaperTarget == null && foundW.mAppToken != null) |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1458 | ? foundW.mAppToken.animLayerAdjustment : 0; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1459 | |
| Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 1460 | final int maxLayer = mPolicy.getMaxWallpaperLayer() |
| 1461 | * TYPE_LAYER_MULTIPLIER |
| 1462 | + TYPE_LAYER_OFFSET; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1463 | |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1464 | // Now w is the window we are supposed to be behind... but we |
| 1465 | // 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] | 1466 | // AND any starting window associated with it, AND below the |
| 1467 | // maximum layer the policy allows for wallpapers. |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1468 | while (foundI > 0) { |
| 1469 | WindowState wb = (WindowState)localmWindows.get(foundI-1); |
| Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 1470 | if (wb.mBaseLayer < maxLayer && |
| 1471 | wb.mAttachedWindow != foundW && |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1472 | (wb.mAttrs.type != TYPE_APPLICATION_STARTING || |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1473 | wb.mToken != foundW.mToken)) { |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1474 | // This window is not related to the previous one in any |
| 1475 | // interesting way, so stop here. |
| 1476 | break; |
| 1477 | } |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1478 | foundW = wb; |
| 1479 | foundI--; |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1480 | } |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 1481 | } else { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1482 | if (DEBUG_WALLPAPER) Slog.v(TAG, "No wallpaper target"); |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1483 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1484 | |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1485 | if (foundW == null && topCurW != null) { |
| 1486 | // There is no wallpaper target, so it goes at the bottom. |
| 1487 | // We will assume it is the same place as last time, if known. |
| 1488 | foundW = topCurW; |
| 1489 | foundI = topCurI+1; |
| 1490 | } else { |
| 1491 | // Okay i is the position immediately above the wallpaper. Look at |
| 1492 | // what is below it for later. |
| 1493 | foundW = foundI > 0 ? (WindowState)localmWindows.get(foundI-1) : null; |
| 1494 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1495 | |
| Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 1496 | if (visible) { |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1497 | if (mWallpaperTarget.mWallpaperX >= 0) { |
| 1498 | mLastWallpaperX = mWallpaperTarget.mWallpaperX; |
| Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 1499 | mLastWallpaperXStep = mWallpaperTarget.mWallpaperXStep; |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1500 | } |
| 1501 | if (mWallpaperTarget.mWallpaperY >= 0) { |
| 1502 | mLastWallpaperY = mWallpaperTarget.mWallpaperY; |
| Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 1503 | mLastWallpaperYStep = mWallpaperTarget.mWallpaperYStep; |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1504 | } |
| Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 1505 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1506 | |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1507 | // Start stepping backwards from here, ensuring that our wallpaper windows |
| 1508 | // are correctly placed. |
| 1509 | int curTokenIndex = mWallpaperTokens.size(); |
| 1510 | while (curTokenIndex > 0) { |
| 1511 | curTokenIndex--; |
| 1512 | WindowToken token = mWallpaperTokens.get(curTokenIndex); |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 1513 | if (token.hidden == visible) { |
| 1514 | changed |= ADJUST_WALLPAPER_VISIBILITY_CHANGED; |
| 1515 | token.hidden = !visible; |
| 1516 | // Need to do a layout to ensure the wallpaper now has the |
| 1517 | // correct size. |
| 1518 | mLayoutNeeded = true; |
| 1519 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1520 | |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1521 | int curWallpaperIndex = token.windows.size(); |
| 1522 | while (curWallpaperIndex > 0) { |
| 1523 | curWallpaperIndex--; |
| 1524 | WindowState wallpaper = token.windows.get(curWallpaperIndex); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1525 | |
| Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 1526 | if (visible) { |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1527 | updateWallpaperOffsetLocked(wallpaper, dw, dh, false); |
| Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 1528 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1529 | |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 1530 | // First, make sure the client has the current visibility |
| 1531 | // state. |
| 1532 | if (wallpaper.mWallpaperVisible != visible) { |
| 1533 | wallpaper.mWallpaperVisible = visible; |
| 1534 | try { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1535 | if (DEBUG_VISIBILITY || DEBUG_WALLPAPER) Slog.v(TAG, |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 1536 | "Setting visibility of wallpaper " + wallpaper |
| 1537 | + ": " + visible); |
| 1538 | wallpaper.mClient.dispatchAppVisibility(visible); |
| 1539 | } catch (RemoteException e) { |
| 1540 | } |
| 1541 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1542 | |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 1543 | wallpaper.mAnimLayer = wallpaper.mLayer + mWallpaperAnimLayerAdjustment; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1544 | if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper win " |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1545 | + wallpaper + " anim layer: " + wallpaper.mAnimLayer); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1546 | |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1547 | // First, if this window is at the current index, then all |
| 1548 | // is well. |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1549 | if (wallpaper == foundW) { |
| 1550 | foundI--; |
| 1551 | foundW = foundI > 0 |
| 1552 | ? (WindowState)localmWindows.get(foundI-1) : null; |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1553 | continue; |
| 1554 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1555 | |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1556 | // The window didn't match... the current wallpaper window, |
| 1557 | // wherever it is, is in the wrong place, so make sure it is |
| 1558 | // not in the list. |
| 1559 | int oldIndex = localmWindows.indexOf(wallpaper); |
| 1560 | if (oldIndex >= 0) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1561 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Wallpaper removing at " |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 1562 | + oldIndex + ": " + wallpaper); |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1563 | localmWindows.remove(oldIndex); |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1564 | if (oldIndex < foundI) { |
| 1565 | foundI--; |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1566 | } |
| 1567 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1568 | |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1569 | // Now stick it in. |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1570 | if (DEBUG_WALLPAPER || DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 1571 | "Moving wallpaper " + wallpaper |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1572 | + " from " + oldIndex + " to " + foundI); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1573 | |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1574 | localmWindows.add(foundI, wallpaper); |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 1575 | changed |= ADJUST_WALLPAPER_LAYERS_CHANGED; |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1576 | } |
| 1577 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1578 | |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1579 | return changed; |
| 1580 | } |
| 1581 | |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 1582 | void setWallpaperAnimLayerAdjustmentLocked(int adj) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1583 | if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG, |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1584 | "Setting wallpaper layer adj to " + adj); |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 1585 | mWallpaperAnimLayerAdjustment = adj; |
| 1586 | int curTokenIndex = mWallpaperTokens.size(); |
| 1587 | while (curTokenIndex > 0) { |
| 1588 | curTokenIndex--; |
| 1589 | WindowToken token = mWallpaperTokens.get(curTokenIndex); |
| 1590 | int curWallpaperIndex = token.windows.size(); |
| 1591 | while (curWallpaperIndex > 0) { |
| 1592 | curWallpaperIndex--; |
| 1593 | WindowState wallpaper = token.windows.get(curWallpaperIndex); |
| 1594 | wallpaper.mAnimLayer = wallpaper.mLayer + adj; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1595 | if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper win " |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1596 | + wallpaper + " anim layer: " + wallpaper.mAnimLayer); |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 1597 | } |
| 1598 | } |
| 1599 | } |
| 1600 | |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1601 | boolean updateWallpaperOffsetLocked(WindowState wallpaperWin, int dw, int dh, |
| 1602 | boolean sync) { |
| Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 1603 | boolean changed = false; |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1604 | boolean rawChanged = false; |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1605 | float wpx = mLastWallpaperX >= 0 ? mLastWallpaperX : 0.5f; |
| Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 1606 | float wpxs = mLastWallpaperXStep >= 0 ? mLastWallpaperXStep : -1.0f; |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1607 | int availw = wallpaperWin.mFrame.right-wallpaperWin.mFrame.left-dw; |
| 1608 | int offset = availw > 0 ? -(int)(availw*wpx+.5f) : 0; |
| 1609 | changed = wallpaperWin.mXOffset != offset; |
| 1610 | if (changed) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1611 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Update wallpaper " |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1612 | + wallpaperWin + " x: " + offset); |
| 1613 | wallpaperWin.mXOffset = offset; |
| 1614 | } |
| Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 1615 | if (wallpaperWin.mWallpaperX != wpx || wallpaperWin.mWallpaperXStep != wpxs) { |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1616 | wallpaperWin.mWallpaperX = wpx; |
| Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 1617 | wallpaperWin.mWallpaperXStep = wpxs; |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1618 | rawChanged = true; |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 1619 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1620 | |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1621 | float wpy = mLastWallpaperY >= 0 ? mLastWallpaperY : 0.5f; |
| Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 1622 | float wpys = mLastWallpaperYStep >= 0 ? mLastWallpaperYStep : -1.0f; |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1623 | int availh = wallpaperWin.mFrame.bottom-wallpaperWin.mFrame.top-dh; |
| 1624 | offset = availh > 0 ? -(int)(availh*wpy+.5f) : 0; |
| 1625 | if (wallpaperWin.mYOffset != offset) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1626 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Update wallpaper " |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1627 | + wallpaperWin + " y: " + offset); |
| 1628 | changed = true; |
| 1629 | wallpaperWin.mYOffset = offset; |
| 1630 | } |
| Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 1631 | if (wallpaperWin.mWallpaperY != wpy || wallpaperWin.mWallpaperYStep != wpys) { |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1632 | wallpaperWin.mWallpaperY = wpy; |
| Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 1633 | wallpaperWin.mWallpaperYStep = wpys; |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1634 | rawChanged = true; |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 1635 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1636 | |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1637 | if (rawChanged) { |
| Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 1638 | try { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1639 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Report new wp offset " |
| Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 1640 | + wallpaperWin + " x=" + wallpaperWin.mWallpaperX |
| 1641 | + " y=" + wallpaperWin.mWallpaperY); |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1642 | if (sync) { |
| Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 1643 | mWaitingOnWallpaper = wallpaperWin; |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1644 | } |
| Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 1645 | wallpaperWin.mClient.dispatchWallpaperOffsets( |
| Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 1646 | wallpaperWin.mWallpaperX, wallpaperWin.mWallpaperY, |
| 1647 | wallpaperWin.mWallpaperXStep, wallpaperWin.mWallpaperYStep, sync); |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1648 | if (sync) { |
| Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 1649 | if (mWaitingOnWallpaper != null) { |
| 1650 | long start = SystemClock.uptimeMillis(); |
| 1651 | if ((mLastWallpaperTimeoutTime+WALLPAPER_TIMEOUT_RECOVERY) |
| 1652 | < start) { |
| 1653 | try { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1654 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
| Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 1655 | "Waiting for offset complete..."); |
| 1656 | mWindowMap.wait(WALLPAPER_TIMEOUT); |
| 1657 | } catch (InterruptedException e) { |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1658 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1659 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Offset complete!"); |
| Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 1660 | if ((start+WALLPAPER_TIMEOUT) |
| 1661 | < SystemClock.uptimeMillis()) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1662 | Slog.i(TAG, "Timeout waiting for wallpaper to offset: " |
| Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 1663 | + wallpaperWin); |
| 1664 | mLastWallpaperTimeoutTime = start; |
| 1665 | } |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1666 | } |
| Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 1667 | mWaitingOnWallpaper = null; |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1668 | } |
| 1669 | } |
| Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 1670 | } catch (RemoteException e) { |
| 1671 | } |
| 1672 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1673 | |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 1674 | return changed; |
| 1675 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1676 | |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1677 | void wallpaperOffsetsComplete(IBinder window) { |
| Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 1678 | synchronized (mWindowMap) { |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1679 | if (mWaitingOnWallpaper != null && |
| 1680 | mWaitingOnWallpaper.mClient.asBinder() == window) { |
| 1681 | mWaitingOnWallpaper = null; |
| Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 1682 | mWindowMap.notifyAll(); |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1683 | } |
| 1684 | } |
| 1685 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1686 | |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1687 | boolean updateWallpaperOffsetLocked(WindowState changingTarget, boolean sync) { |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 1688 | final int dw = mDisplay.getWidth(); |
| 1689 | final int dh = mDisplay.getHeight(); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1690 | |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 1691 | boolean changed = false; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1692 | |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 1693 | WindowState target = mWallpaperTarget; |
| 1694 | if (target != null) { |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1695 | if (target.mWallpaperX >= 0) { |
| 1696 | mLastWallpaperX = target.mWallpaperX; |
| 1697 | } else if (changingTarget.mWallpaperX >= 0) { |
| 1698 | mLastWallpaperX = changingTarget.mWallpaperX; |
| 1699 | } |
| 1700 | if (target.mWallpaperY >= 0) { |
| 1701 | mLastWallpaperY = target.mWallpaperY; |
| 1702 | } else if (changingTarget.mWallpaperY >= 0) { |
| 1703 | mLastWallpaperY = changingTarget.mWallpaperY; |
| 1704 | } |
| 1705 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1706 | |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1707 | int curTokenIndex = mWallpaperTokens.size(); |
| 1708 | while (curTokenIndex > 0) { |
| 1709 | curTokenIndex--; |
| 1710 | WindowToken token = mWallpaperTokens.get(curTokenIndex); |
| 1711 | int curWallpaperIndex = token.windows.size(); |
| 1712 | while (curWallpaperIndex > 0) { |
| 1713 | curWallpaperIndex--; |
| 1714 | WindowState wallpaper = token.windows.get(curWallpaperIndex); |
| 1715 | if (updateWallpaperOffsetLocked(wallpaper, dw, dh, sync)) { |
| 1716 | wallpaper.computeShownFrameLocked(); |
| 1717 | changed = true; |
| 1718 | // We only want to be synchronous with one wallpaper. |
| 1719 | sync = false; |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 1720 | } |
| 1721 | } |
| 1722 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1723 | |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 1724 | return changed; |
| 1725 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1726 | |
| Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 1727 | void updateWallpaperVisibilityLocked() { |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 1728 | final boolean visible = isWallpaperVisible(mWallpaperTarget); |
| Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 1729 | final int dw = mDisplay.getWidth(); |
| 1730 | final int dh = mDisplay.getHeight(); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1731 | |
| Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 1732 | int curTokenIndex = mWallpaperTokens.size(); |
| 1733 | while (curTokenIndex > 0) { |
| 1734 | curTokenIndex--; |
| 1735 | WindowToken token = mWallpaperTokens.get(curTokenIndex); |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 1736 | if (token.hidden == visible) { |
| 1737 | token.hidden = !visible; |
| 1738 | // Need to do a layout to ensure the wallpaper now has the |
| 1739 | // correct size. |
| 1740 | mLayoutNeeded = true; |
| 1741 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1742 | |
| Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 1743 | int curWallpaperIndex = token.windows.size(); |
| 1744 | while (curWallpaperIndex > 0) { |
| 1745 | curWallpaperIndex--; |
| 1746 | WindowState wallpaper = token.windows.get(curWallpaperIndex); |
| 1747 | if (visible) { |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1748 | updateWallpaperOffsetLocked(wallpaper, dw, dh, false); |
| Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 1749 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1750 | |
| Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 1751 | if (wallpaper.mWallpaperVisible != visible) { |
| 1752 | wallpaper.mWallpaperVisible = visible; |
| 1753 | try { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1754 | if (DEBUG_VISIBILITY || DEBUG_WALLPAPER) Slog.v(TAG, |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 1755 | "Updating visibility of wallpaper " + wallpaper |
| Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 1756 | + ": " + visible); |
| 1757 | wallpaper.mClient.dispatchAppVisibility(visible); |
| 1758 | } catch (RemoteException e) { |
| 1759 | } |
| 1760 | } |
| 1761 | } |
| 1762 | } |
| 1763 | } |
| Dianne Hackborn | 90d2db3 | 2010-02-11 22:19:06 -0800 | [diff] [blame] | 1764 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1765 | public int addWindow(Session session, IWindow client, |
| 1766 | WindowManager.LayoutParams attrs, int viewVisibility, |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1767 | Rect outContentInsets, InputChannel outInputChannel) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1768 | int res = mPolicy.checkAddPermission(attrs); |
| 1769 | if (res != WindowManagerImpl.ADD_OKAY) { |
| 1770 | return res; |
| 1771 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1772 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1773 | boolean reportNewConfig = false; |
| 1774 | WindowState attachedWindow = null; |
| 1775 | WindowState win = null; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1776 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1777 | synchronized(mWindowMap) { |
| 1778 | // Instantiating a Display requires talking with the simulator, |
| 1779 | // so don't do it until we know the system is mostly up and |
| 1780 | // running. |
| 1781 | if (mDisplay == null) { |
| 1782 | WindowManager wm = (WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE); |
| 1783 | mDisplay = wm.getDefaultDisplay(); |
| Christopher Tate | b696aee | 2010-04-02 19:08:30 -0700 | [diff] [blame] | 1784 | mInitialDisplayWidth = mDisplay.getWidth(); |
| 1785 | mInitialDisplayHeight = mDisplay.getHeight(); |
| Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 1786 | mInputManager.setDisplaySize(0, mInitialDisplayWidth, mInitialDisplayHeight); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1787 | reportNewConfig = true; |
| 1788 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1789 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1790 | if (mWindowMap.containsKey(client.asBinder())) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1791 | Slog.w(TAG, "Window " + client + " is already added"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1792 | return WindowManagerImpl.ADD_DUPLICATE_ADD; |
| 1793 | } |
| 1794 | |
| 1795 | if (attrs.type >= FIRST_SUB_WINDOW && attrs.type <= LAST_SUB_WINDOW) { |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 1796 | attachedWindow = windowForClientLocked(null, attrs.token, false); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1797 | if (attachedWindow == null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1798 | Slog.w(TAG, "Attempted to add window with token that is not a window: " |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1799 | + attrs.token + ". Aborting."); |
| 1800 | return WindowManagerImpl.ADD_BAD_SUBWINDOW_TOKEN; |
| 1801 | } |
| 1802 | if (attachedWindow.mAttrs.type >= FIRST_SUB_WINDOW |
| 1803 | && attachedWindow.mAttrs.type <= LAST_SUB_WINDOW) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1804 | Slog.w(TAG, "Attempted to add window with token that is a sub-window: " |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1805 | + attrs.token + ". Aborting."); |
| 1806 | return WindowManagerImpl.ADD_BAD_SUBWINDOW_TOKEN; |
| 1807 | } |
| 1808 | } |
| 1809 | |
| 1810 | boolean addToken = false; |
| 1811 | WindowToken token = mTokenMap.get(attrs.token); |
| 1812 | if (token == null) { |
| 1813 | if (attrs.type >= FIRST_APPLICATION_WINDOW |
| 1814 | && attrs.type <= LAST_APPLICATION_WINDOW) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1815 | Slog.w(TAG, "Attempted to add application window with unknown token " |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1816 | + attrs.token + ". Aborting."); |
| 1817 | return WindowManagerImpl.ADD_BAD_APP_TOKEN; |
| 1818 | } |
| 1819 | if (attrs.type == TYPE_INPUT_METHOD) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1820 | Slog.w(TAG, "Attempted to add input method window with unknown token " |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1821 | + attrs.token + ". Aborting."); |
| 1822 | return WindowManagerImpl.ADD_BAD_APP_TOKEN; |
| 1823 | } |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1824 | if (attrs.type == TYPE_WALLPAPER) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1825 | Slog.w(TAG, "Attempted to add wallpaper window with unknown token " |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1826 | + attrs.token + ". Aborting."); |
| 1827 | return WindowManagerImpl.ADD_BAD_APP_TOKEN; |
| 1828 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1829 | token = new WindowToken(attrs.token, -1, false); |
| 1830 | addToken = true; |
| 1831 | } else if (attrs.type >= FIRST_APPLICATION_WINDOW |
| 1832 | && attrs.type <= LAST_APPLICATION_WINDOW) { |
| 1833 | AppWindowToken atoken = token.appWindowToken; |
| 1834 | if (atoken == null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1835 | Slog.w(TAG, "Attempted to add window with non-application token " |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1836 | + token + ". Aborting."); |
| 1837 | return WindowManagerImpl.ADD_NOT_APP_TOKEN; |
| 1838 | } else if (atoken.removed) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1839 | Slog.w(TAG, "Attempted to add window with exiting application token " |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1840 | + token + ". Aborting."); |
| 1841 | return WindowManagerImpl.ADD_APP_EXITING; |
| 1842 | } |
| 1843 | if (attrs.type == TYPE_APPLICATION_STARTING && atoken.firstWindowDrawn) { |
| 1844 | // No need for this guy! |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1845 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1846 | TAG, "**** NO NEED TO START: " + attrs.getTitle()); |
| 1847 | return WindowManagerImpl.ADD_STARTING_NOT_NEEDED; |
| 1848 | } |
| 1849 | } else if (attrs.type == TYPE_INPUT_METHOD) { |
| 1850 | if (token.windowType != TYPE_INPUT_METHOD) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1851 | Slog.w(TAG, "Attempted to add input method window with bad token " |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1852 | + attrs.token + ". Aborting."); |
| 1853 | return WindowManagerImpl.ADD_BAD_APP_TOKEN; |
| 1854 | } |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1855 | } else if (attrs.type == TYPE_WALLPAPER) { |
| 1856 | if (token.windowType != TYPE_WALLPAPER) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1857 | Slog.w(TAG, "Attempted to add wallpaper window with bad token " |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1858 | + attrs.token + ". Aborting."); |
| 1859 | return WindowManagerImpl.ADD_BAD_APP_TOKEN; |
| 1860 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1861 | } |
| 1862 | |
| 1863 | win = new WindowState(session, client, token, |
| 1864 | attachedWindow, attrs, viewVisibility); |
| 1865 | if (win.mDeathRecipient == null) { |
| 1866 | // Client has apparently died, so there is no reason to |
| 1867 | // continue. |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1868 | Slog.w(TAG, "Adding window client " + client.asBinder() |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1869 | + " that is dead, aborting."); |
| 1870 | return WindowManagerImpl.ADD_APP_EXITING; |
| 1871 | } |
| 1872 | |
| 1873 | mPolicy.adjustWindowParamsLw(win.mAttrs); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1874 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1875 | res = mPolicy.prepareAddWindowLw(win, attrs); |
| 1876 | if (res != WindowManagerImpl.ADD_OKAY) { |
| 1877 | return res; |
| 1878 | } |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1879 | |
| Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 1880 | if (outInputChannel != null) { |
| 1881 | String name = win.makeInputChannelName(); |
| 1882 | InputChannel[] inputChannels = InputChannel.openInputChannelPair(name); |
| 1883 | win.mInputChannel = inputChannels[0]; |
| 1884 | inputChannels[1].transferToBinderOutParameter(outInputChannel); |
| 1885 | |
| 1886 | mInputManager.registerInputChannel(win.mInputChannel); |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1887 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1888 | |
| 1889 | // From now on, no exceptions or errors allowed! |
| 1890 | |
| 1891 | res = WindowManagerImpl.ADD_OKAY; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1892 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1893 | final long origId = Binder.clearCallingIdentity(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1894 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1895 | if (addToken) { |
| 1896 | mTokenMap.put(attrs.token, token); |
| 1897 | mTokenList.add(token); |
| 1898 | } |
| 1899 | win.attach(); |
| 1900 | mWindowMap.put(client.asBinder(), win); |
| 1901 | |
| 1902 | if (attrs.type == TYPE_APPLICATION_STARTING && |
| 1903 | token.appWindowToken != null) { |
| 1904 | token.appWindowToken.startingWindow = win; |
| 1905 | } |
| 1906 | |
| 1907 | boolean imMayMove = true; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1908 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1909 | if (attrs.type == TYPE_INPUT_METHOD) { |
| 1910 | mInputMethodWindow = win; |
| 1911 | addInputMethodWindowToListLocked(win); |
| 1912 | imMayMove = false; |
| 1913 | } else if (attrs.type == TYPE_INPUT_METHOD_DIALOG) { |
| 1914 | mInputMethodDialogs.add(win); |
| 1915 | addWindowToListInOrderLocked(win, true); |
| 1916 | adjustInputMethodDialogsLocked(); |
| 1917 | imMayMove = false; |
| 1918 | } else { |
| 1919 | addWindowToListInOrderLocked(win, true); |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1920 | if (attrs.type == TYPE_WALLPAPER) { |
| 1921 | mLastWallpaperTimeoutTime = 0; |
| 1922 | adjustWallpaperWindowsLocked(); |
| 1923 | } else if ((attrs.flags&FLAG_SHOW_WALLPAPER) != 0) { |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1924 | adjustWallpaperWindowsLocked(); |
| 1925 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1926 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1927 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1928 | win.mEnterAnimationPending = true; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1929 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1930 | mPolicy.getContentInsetHintLw(attrs, outContentInsets); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1931 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1932 | if (mInTouchMode) { |
| 1933 | res |= WindowManagerImpl.ADD_FLAG_IN_TOUCH_MODE; |
| 1934 | } |
| 1935 | if (win == null || win.mAppToken == null || !win.mAppToken.clientHidden) { |
| 1936 | res |= WindowManagerImpl.ADD_FLAG_APP_VISIBLE; |
| 1937 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1938 | |
| The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 1939 | boolean focusChanged = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1940 | if (win.canReceiveKeys()) { |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 1941 | focusChanged = updateFocusedWindowLocked(UPDATE_FOCUS_WILL_ASSIGN_LAYERS); |
| 1942 | if (focusChanged) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1943 | imMayMove = false; |
| 1944 | } |
| 1945 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1946 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1947 | if (imMayMove) { |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1948 | moveInputMethodWindowsIfNeededLocked(false); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1949 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1950 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1951 | assignLayersLocked(); |
| 1952 | // Don't do layout here, the window must call |
| 1953 | // relayout to be displayed, so we'll do it there. |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1954 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1955 | //dump(); |
| 1956 | |
| The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 1957 | if (focusChanged) { |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 1958 | finishUpdateFocusedWindowAfterAssignLayersLocked(); |
| The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 1959 | } |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 1960 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1961 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1962 | TAG, "New client " + client.asBinder() |
| 1963 | + ": window=" + win); |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 1964 | |
| 1965 | if (win.isVisibleOrAdding() && updateOrientationFromAppTokensLocked()) { |
| 1966 | reportNewConfig = true; |
| 1967 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1968 | } |
| 1969 | |
| 1970 | // sendNewConfiguration() checks caller permissions so we must call it with |
| 1971 | // privilege. updateOrientationFromAppTokens() clears and resets the caller |
| 1972 | // identity anyway, so it's safe to just clear & restore around this whole |
| 1973 | // block. |
| 1974 | final long origId = Binder.clearCallingIdentity(); |
| 1975 | if (reportNewConfig) { |
| 1976 | sendNewConfiguration(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1977 | } |
| 1978 | Binder.restoreCallingIdentity(origId); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1979 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1980 | return res; |
| 1981 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1982 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1983 | public void removeWindow(Session session, IWindow client) { |
| 1984 | synchronized(mWindowMap) { |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 1985 | WindowState win = windowForClientLocked(session, client, false); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1986 | if (win == null) { |
| 1987 | return; |
| 1988 | } |
| 1989 | removeWindowLocked(session, win); |
| 1990 | } |
| 1991 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1992 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1993 | public void removeWindowLocked(Session session, WindowState win) { |
| 1994 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1995 | if (localLOGV || DEBUG_FOCUS) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1996 | TAG, "Remove " + win + " client=" |
| 1997 | + Integer.toHexString(System.identityHashCode( |
| 1998 | win.mClient.asBinder())) |
| 1999 | + ", surface=" + win.mSurface); |
| 2000 | |
| 2001 | final long origId = Binder.clearCallingIdentity(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2002 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2003 | if (DEBUG_APP_TRANSITIONS) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2004 | TAG, "Remove " + win + ": mSurface=" + win.mSurface |
| 2005 | + " mExiting=" + win.mExiting |
| 2006 | + " isAnimating=" + win.isAnimating() |
| 2007 | + " app-animation=" |
| 2008 | + (win.mAppToken != null ? win.mAppToken.animation : null) |
| 2009 | + " inPendingTransaction=" |
| 2010 | + (win.mAppToken != null ? win.mAppToken.inPendingTransaction : false) |
| 2011 | + " mDisplayFrozen=" + mDisplayFrozen); |
| 2012 | // Visibility of the removed window. Will be used later to update orientation later on. |
| 2013 | boolean wasVisible = false; |
| 2014 | // First, see if we need to run an animation. If we do, we have |
| 2015 | // to hold off on removing the window until the animation is done. |
| 2016 | // If the display is frozen, just remove immediately, since the |
| 2017 | // animation wouldn't be seen. |
| Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 2018 | if (win.mSurface != null && !mDisplayFrozen && mPolicy.isScreenOn()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2019 | // If we are not currently running the exit animation, we |
| 2020 | // need to see about starting one. |
| 2021 | if (wasVisible=win.isWinVisibleLw()) { |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2022 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2023 | int transit = WindowManagerPolicy.TRANSIT_EXIT; |
| 2024 | if (win.getAttrs().type == TYPE_APPLICATION_STARTING) { |
| 2025 | transit = WindowManagerPolicy.TRANSIT_PREVIEW_DONE; |
| 2026 | } |
| 2027 | // Try starting an animation. |
| 2028 | if (applyAnimationLocked(win, transit, false)) { |
| 2029 | win.mExiting = true; |
| 2030 | } |
| 2031 | } |
| 2032 | if (win.mExiting || win.isAnimating()) { |
| 2033 | // The exit animation is running... wait for it! |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2034 | //Slog.i(TAG, "*** Running exit animation..."); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2035 | win.mExiting = true; |
| 2036 | win.mRemoveOnExit = true; |
| 2037 | mLayoutNeeded = true; |
| 2038 | updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES); |
| 2039 | performLayoutAndPlaceSurfacesLocked(); |
| 2040 | if (win.mAppToken != null) { |
| 2041 | win.mAppToken.updateReportedVisibilityLocked(); |
| 2042 | } |
| 2043 | //dump(); |
| 2044 | Binder.restoreCallingIdentity(origId); |
| 2045 | return; |
| 2046 | } |
| 2047 | } |
| 2048 | |
| 2049 | removeWindowInnerLocked(session, win); |
| 2050 | // Removing a visible window will effect the computed orientation |
| 2051 | // So just update orientation if needed. |
| The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 2052 | if (wasVisible && computeForcedAppOrientationLocked() |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2053 | != mForcedAppOrientation |
| 2054 | && updateOrientationFromAppTokensLocked()) { |
| 2055 | mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2056 | } |
| 2057 | updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL); |
| 2058 | Binder.restoreCallingIdentity(origId); |
| 2059 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2060 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2061 | private void removeWindowInnerLocked(Session session, WindowState win) { |
| Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 2062 | mInputMonitor.windowIsBeingRemovedLw(win); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2063 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2064 | win.mRemoved = true; |
| 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 | if (mInputMethodTarget == win) { |
| 2067 | moveInputMethodWindowsIfNeededLocked(false); |
| 2068 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2069 | |
| Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 2070 | if (false) { |
| 2071 | RuntimeException e = new RuntimeException("here"); |
| 2072 | e.fillInStackTrace(); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2073 | Slog.w(TAG, "Removing window " + win, e); |
| Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 2074 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2075 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2076 | mPolicy.removeWindowLw(win); |
| 2077 | win.removeLocked(); |
| 2078 | |
| 2079 | mWindowMap.remove(win.mClient.asBinder()); |
| 2080 | mWindows.remove(win); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2081 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Final remove of window: " + win); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2082 | |
| 2083 | if (mInputMethodWindow == win) { |
| 2084 | mInputMethodWindow = null; |
| 2085 | } else if (win.mAttrs.type == TYPE_INPUT_METHOD_DIALOG) { |
| 2086 | mInputMethodDialogs.remove(win); |
| 2087 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2088 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2089 | final WindowToken token = win.mToken; |
| 2090 | final AppWindowToken atoken = win.mAppToken; |
| 2091 | token.windows.remove(win); |
| 2092 | if (atoken != null) { |
| 2093 | atoken.allAppWindows.remove(win); |
| 2094 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2095 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2096 | TAG, "**** Removing window " + win + ": count=" |
| 2097 | + token.windows.size()); |
| 2098 | if (token.windows.size() == 0) { |
| 2099 | if (!token.explicit) { |
| 2100 | mTokenMap.remove(token.token); |
| 2101 | mTokenList.remove(token); |
| 2102 | } else if (atoken != null) { |
| 2103 | atoken.firstWindowDrawn = false; |
| 2104 | } |
| 2105 | } |
| 2106 | |
| 2107 | if (atoken != null) { |
| 2108 | if (atoken.startingWindow == win) { |
| 2109 | atoken.startingWindow = null; |
| 2110 | } else if (atoken.allAppWindows.size() == 0 && atoken.startingData != null) { |
| 2111 | // If this is the last window and we had requested a starting |
| 2112 | // transition window, well there is no point now. |
| 2113 | atoken.startingData = null; |
| 2114 | } else if (atoken.allAppWindows.size() == 1 && atoken.startingView != null) { |
| 2115 | // If this is the last window except for a starting transition |
| 2116 | // window, we need to get rid of the starting transition. |
| 2117 | if (DEBUG_STARTING_WINDOW) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2118 | Slog.v(TAG, "Schedule remove starting " + token |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2119 | + ": no more real windows"); |
| 2120 | } |
| 2121 | Message m = mH.obtainMessage(H.REMOVE_STARTING, atoken); |
| 2122 | mH.sendMessage(m); |
| 2123 | } |
| 2124 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2125 | |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 2126 | if (win.mAttrs.type == TYPE_WALLPAPER) { |
| 2127 | mLastWallpaperTimeoutTime = 0; |
| 2128 | adjustWallpaperWindowsLocked(); |
| 2129 | } else if ((win.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0) { |
| Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 2130 | adjustWallpaperWindowsLocked(); |
| 2131 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2132 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2133 | if (!mInLayout) { |
| 2134 | assignLayersLocked(); |
| 2135 | mLayoutNeeded = true; |
| 2136 | performLayoutAndPlaceSurfacesLocked(); |
| 2137 | if (win.mAppToken != null) { |
| 2138 | win.mAppToken.updateReportedVisibilityLocked(); |
| 2139 | } |
| 2140 | } |
| 2141 | } |
| 2142 | |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 2143 | private static void logSurface(WindowState w, String msg, RuntimeException where) { |
| 2144 | String str = " SURFACE " + Integer.toHexString(w.hashCode()) |
| 2145 | + ": " + msg + " / " + w.mAttrs.getTitle(); |
| 2146 | if (where != null) { |
| 2147 | Slog.i(TAG, str, where); |
| 2148 | } else { |
| 2149 | Slog.i(TAG, str); |
| 2150 | } |
| 2151 | } |
| 2152 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2153 | private void setTransparentRegionWindow(Session session, IWindow client, Region region) { |
| 2154 | long origId = Binder.clearCallingIdentity(); |
| 2155 | try { |
| 2156 | synchronized (mWindowMap) { |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2157 | WindowState w = windowForClientLocked(session, client, false); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2158 | if ((w != null) && (w.mSurface != null)) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2159 | if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2160 | Surface.openTransaction(); |
| 2161 | try { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 2162 | if (SHOW_TRANSACTIONS) logSurface(w, |
| 2163 | "transparentRegionHint=" + region, null); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2164 | w.mSurface.setTransparentRegionHint(region); |
| 2165 | } finally { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2166 | if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2167 | Surface.closeTransaction(); |
| 2168 | } |
| 2169 | } |
| 2170 | } |
| 2171 | } finally { |
| 2172 | Binder.restoreCallingIdentity(origId); |
| 2173 | } |
| 2174 | } |
| 2175 | |
| 2176 | void setInsetsWindow(Session session, IWindow client, |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2177 | int touchableInsets, Rect contentInsets, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2178 | Rect visibleInsets) { |
| 2179 | long origId = Binder.clearCallingIdentity(); |
| 2180 | try { |
| 2181 | synchronized (mWindowMap) { |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2182 | WindowState w = windowForClientLocked(session, client, false); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2183 | if (w != null) { |
| 2184 | w.mGivenInsetsPending = false; |
| 2185 | w.mGivenContentInsets.set(contentInsets); |
| 2186 | w.mGivenVisibleInsets.set(visibleInsets); |
| 2187 | w.mTouchableInsets = touchableInsets; |
| 2188 | mLayoutNeeded = true; |
| 2189 | performLayoutAndPlaceSurfacesLocked(); |
| 2190 | } |
| 2191 | } |
| 2192 | } finally { |
| 2193 | Binder.restoreCallingIdentity(origId); |
| 2194 | } |
| 2195 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2196 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2197 | public void getWindowDisplayFrame(Session session, IWindow client, |
| 2198 | Rect outDisplayFrame) { |
| 2199 | synchronized(mWindowMap) { |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2200 | WindowState win = windowForClientLocked(session, client, false); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2201 | if (win == null) { |
| 2202 | outDisplayFrame.setEmpty(); |
| 2203 | return; |
| 2204 | } |
| 2205 | outDisplayFrame.set(win.mDisplayFrame); |
| 2206 | } |
| 2207 | } |
| 2208 | |
| Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 2209 | public void setWindowWallpaperPositionLocked(WindowState window, float x, float y, |
| 2210 | float xStep, float yStep) { |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 2211 | if (window.mWallpaperX != x || window.mWallpaperY != y) { |
| 2212 | window.mWallpaperX = x; |
| 2213 | window.mWallpaperY = y; |
| Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 2214 | window.mWallpaperXStep = xStep; |
| 2215 | window.mWallpaperYStep = yStep; |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 2216 | if (updateWallpaperOffsetLocked(window, true)) { |
| 2217 | performLayoutAndPlaceSurfacesLocked(); |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 2218 | } |
| 2219 | } |
| 2220 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2221 | |
| Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 2222 | void wallpaperCommandComplete(IBinder window, Bundle result) { |
| 2223 | synchronized (mWindowMap) { |
| 2224 | if (mWaitingOnWallpaper != null && |
| 2225 | mWaitingOnWallpaper.mClient.asBinder() == window) { |
| 2226 | mWaitingOnWallpaper = null; |
| 2227 | mWindowMap.notifyAll(); |
| 2228 | } |
| 2229 | } |
| 2230 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2231 | |
| Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 2232 | public Bundle sendWindowWallpaperCommandLocked(WindowState window, |
| 2233 | String action, int x, int y, int z, Bundle extras, boolean sync) { |
| 2234 | if (window == mWallpaperTarget || window == mLowerWallpaperTarget |
| 2235 | || window == mUpperWallpaperTarget) { |
| 2236 | boolean doWait = sync; |
| 2237 | int curTokenIndex = mWallpaperTokens.size(); |
| 2238 | while (curTokenIndex > 0) { |
| 2239 | curTokenIndex--; |
| 2240 | WindowToken token = mWallpaperTokens.get(curTokenIndex); |
| 2241 | int curWallpaperIndex = token.windows.size(); |
| 2242 | while (curWallpaperIndex > 0) { |
| 2243 | curWallpaperIndex--; |
| 2244 | WindowState wallpaper = token.windows.get(curWallpaperIndex); |
| 2245 | try { |
| 2246 | wallpaper.mClient.dispatchWallpaperCommand(action, |
| 2247 | x, y, z, extras, sync); |
| 2248 | // We only want to be synchronous with one wallpaper. |
| 2249 | sync = false; |
| 2250 | } catch (RemoteException e) { |
| 2251 | } |
| 2252 | } |
| 2253 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2254 | |
| Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 2255 | if (doWait) { |
| 2256 | // XXX Need to wait for result. |
| 2257 | } |
| 2258 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2259 | |
| Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 2260 | return null; |
| 2261 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2262 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2263 | public int relayoutWindow(Session session, IWindow client, |
| 2264 | WindowManager.LayoutParams attrs, int requestedWidth, |
| 2265 | int requestedHeight, int viewVisibility, boolean insetsPending, |
| 2266 | Rect outFrame, Rect outContentInsets, Rect outVisibleInsets, |
| Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 2267 | Configuration outConfig, Surface outSurface) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2268 | boolean displayed = false; |
| 2269 | boolean inTouchMode; |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2270 | boolean configChanged; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2271 | long origId = Binder.clearCallingIdentity(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2272 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2273 | synchronized(mWindowMap) { |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2274 | WindowState win = windowForClientLocked(session, client, false); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2275 | if (win == null) { |
| 2276 | return 0; |
| 2277 | } |
| 2278 | win.mRequestedWidth = requestedWidth; |
| 2279 | win.mRequestedHeight = requestedHeight; |
| 2280 | |
| 2281 | if (attrs != null) { |
| 2282 | mPolicy.adjustWindowParamsLw(attrs); |
| 2283 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2284 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2285 | int attrChanges = 0; |
| 2286 | int flagChanges = 0; |
| 2287 | if (attrs != null) { |
| 2288 | flagChanges = win.mAttrs.flags ^= attrs.flags; |
| 2289 | attrChanges = win.mAttrs.copyFrom(attrs); |
| 2290 | } |
| 2291 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2292 | if (DEBUG_LAYOUT) Slog.v(TAG, "Relayout " + win + ": " + win.mAttrs); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2293 | |
| 2294 | if ((attrChanges & WindowManager.LayoutParams.ALPHA_CHANGED) != 0) { |
| 2295 | win.mAlpha = attrs.alpha; |
| 2296 | } |
| 2297 | |
| 2298 | final boolean scaledWindow = |
| 2299 | ((win.mAttrs.flags & WindowManager.LayoutParams.FLAG_SCALED) != 0); |
| 2300 | |
| 2301 | if (scaledWindow) { |
| 2302 | // requested{Width|Height} Surface's physical size |
| 2303 | // attrs.{width|height} Size on screen |
| 2304 | win.mHScale = (attrs.width != requestedWidth) ? |
| 2305 | (attrs.width / (float)requestedWidth) : 1.0f; |
| 2306 | win.mVScale = (attrs.height != requestedHeight) ? |
| 2307 | (attrs.height / (float)requestedHeight) : 1.0f; |
| Dianne Hackborn | 9b52a21 | 2009-12-11 14:51:35 -0800 | [diff] [blame] | 2308 | } else { |
| 2309 | win.mHScale = win.mVScale = 1; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 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; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 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 | } |
| Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 2340 | if (displayed) { |
| 2341 | if (win.mSurface != null && !win.mDrawPending |
| 2342 | && !win.mCommitDrawPending && !mDisplayFrozen |
| 2343 | && mPolicy.isScreenOn()) { |
| 2344 | applyEnterAnimationLocked(win); |
| 2345 | } |
| 2346 | if ((win.mAttrs.flags |
| 2347 | & WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON) != 0) { |
| 2348 | if (DEBUG_VISIBILITY) Slog.v(TAG, |
| 2349 | "Relayout window turning screen on: " + win); |
| 2350 | win.mTurnOnScreen = true; |
| 2351 | } |
| 2352 | int diff = 0; |
| 2353 | if (win.mConfiguration != mCurConfiguration |
| 2354 | && (win.mConfiguration == null |
| 2355 | || (diff=mCurConfiguration.diff(win.mConfiguration)) != 0)) { |
| 2356 | win.mConfiguration = mCurConfiguration; |
| 2357 | if (DEBUG_CONFIGURATION) { |
| 2358 | Slog.i(TAG, "Window " + win + " visible with new config: " |
| 2359 | + win.mConfiguration + " / 0x" |
| 2360 | + Integer.toHexString(diff)); |
| 2361 | } |
| 2362 | outConfig.setTo(mCurConfiguration); |
| 2363 | } |
| Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 2364 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2365 | if ((attrChanges&WindowManager.LayoutParams.FORMAT_CHANGED) != 0) { |
| 2366 | // To change the format, we need to re-build the surface. |
| 2367 | win.destroySurfaceLocked(); |
| 2368 | displayed = true; |
| 2369 | } |
| 2370 | try { |
| 2371 | Surface surface = win.createSurfaceLocked(); |
| 2372 | if (surface != null) { |
| 2373 | outSurface.copyFrom(surface); |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2374 | win.mReportDestroySurface = false; |
| 2375 | win.mSurfacePendingDestroy = false; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2376 | if (SHOW_TRANSACTIONS) Slog.i(TAG, |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 2377 | " OUT SURFACE " + outSurface + ": copied"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2378 | } else { |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 2379 | // For some reason there isn't a surface. Clear the |
| 2380 | // caller's object so they see the same state. |
| 2381 | outSurface.release(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2382 | } |
| 2383 | } catch (Exception e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2384 | Slog.w(TAG, "Exception thrown when creating surface for client " |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 2385 | + client + " (" + win.mAttrs.getTitle() + ")", |
| 2386 | e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2387 | Binder.restoreCallingIdentity(origId); |
| 2388 | return 0; |
| 2389 | } |
| 2390 | if (displayed) { |
| 2391 | focusMayChange = true; |
| 2392 | } |
| 2393 | if (win.mAttrs.type == TYPE_INPUT_METHOD |
| 2394 | && mInputMethodWindow == null) { |
| 2395 | mInputMethodWindow = win; |
| 2396 | imMayMove = true; |
| 2397 | } |
| Dianne Hackborn | 558947c | 2009-12-18 16:02:50 -0800 | [diff] [blame] | 2398 | if (win.mAttrs.type == TYPE_BASE_APPLICATION |
| 2399 | && win.mAppToken != null |
| 2400 | && win.mAppToken.startingWindow != null) { |
| 2401 | // Special handling of starting window over the base |
| 2402 | // window of the app: propagate lock screen flags to it, |
| 2403 | // to provide the correct semantics while starting. |
| 2404 | final int mask = |
| 2405 | WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED |
| Mike Lockwood | ef73162 | 2010-01-27 17:51:34 -0500 | [diff] [blame] | 2406 | | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD |
| 2407 | | WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON; |
| Dianne Hackborn | 558947c | 2009-12-18 16:02:50 -0800 | [diff] [blame] | 2408 | WindowManager.LayoutParams sa = win.mAppToken.startingWindow.mAttrs; |
| 2409 | sa.flags = (sa.flags&~mask) | (win.mAttrs.flags&mask); |
| 2410 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2411 | } else { |
| 2412 | win.mEnterAnimationPending = false; |
| 2413 | if (win.mSurface != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2414 | if (DEBUG_VISIBILITY) Slog.i(TAG, "Relayout invis " + win |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2415 | + ": mExiting=" + win.mExiting |
| 2416 | + " mSurfacePendingDestroy=" + win.mSurfacePendingDestroy); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2417 | // If we are not currently running the exit animation, we |
| 2418 | // need to see about starting one. |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2419 | if (!win.mExiting || win.mSurfacePendingDestroy) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2420 | // Try starting an animation; if there isn't one, we |
| 2421 | // can destroy the surface right away. |
| 2422 | int transit = WindowManagerPolicy.TRANSIT_EXIT; |
| 2423 | if (win.getAttrs().type == TYPE_APPLICATION_STARTING) { |
| 2424 | transit = WindowManagerPolicy.TRANSIT_PREVIEW_DONE; |
| 2425 | } |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2426 | if (!win.mSurfacePendingDestroy && win.isWinVisibleLw() && |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2427 | applyAnimationLocked(win, transit, false)) { |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2428 | focusMayChange = true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2429 | win.mExiting = true; |
| Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 2430 | mInputMonitor.windowIsBecomingInvisibleLw(win); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2431 | } else if (win.isAnimating()) { |
| 2432 | // Currently in a hide animation... turn this into |
| 2433 | // an exit. |
| 2434 | win.mExiting = true; |
| Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 2435 | } else if (win == mWallpaperTarget) { |
| 2436 | // If the wallpaper is currently behind this |
| 2437 | // window, we need to change both of them inside |
| 2438 | // of a transaction to avoid artifacts. |
| 2439 | win.mExiting = true; |
| 2440 | win.mAnimating = true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2441 | } else { |
| 2442 | if (mInputMethodWindow == win) { |
| 2443 | mInputMethodWindow = null; |
| 2444 | } |
| 2445 | win.destroySurfaceLocked(); |
| 2446 | } |
| 2447 | } |
| 2448 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2449 | |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2450 | if (win.mSurface == null || (win.getAttrs().flags |
| 2451 | & WindowManager.LayoutParams.FLAG_KEEP_SURFACE_WHILE_ANIMATING) == 0 |
| 2452 | || win.mSurfacePendingDestroy) { |
| 2453 | // We are being called from a local process, which |
| 2454 | // means outSurface holds its current surface. Ensure the |
| 2455 | // surface object is cleared, but we don't want it actually |
| 2456 | // destroyed at this point. |
| 2457 | win.mSurfacePendingDestroy = false; |
| 2458 | outSurface.release(); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2459 | if (DEBUG_VISIBILITY) Slog.i(TAG, "Releasing surface in: " + win); |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2460 | } else if (win.mSurface != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2461 | if (DEBUG_VISIBILITY) Slog.i(TAG, |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2462 | "Keeping surface, will report destroy: " + win); |
| 2463 | win.mReportDestroySurface = true; |
| 2464 | outSurface.copyFrom(win.mSurface); |
| 2465 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2466 | } |
| 2467 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2468 | if (focusMayChange) { |
| 2469 | //System.out.println("Focus may change: " + win.mAttrs.getTitle()); |
| 2470 | if (updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES)) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2471 | imMayMove = false; |
| 2472 | } |
| 2473 | //System.out.println("Relayout " + win + ": focus=" + mCurrentFocus); |
| 2474 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2475 | |
| The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 2476 | // updateFocusedWindowLocked() already assigned layers so we only need to |
| 2477 | // reassign them at this point if the IM window state gets shuffled |
| 2478 | boolean assignLayers = false; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2479 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2480 | if (imMayMove) { |
| Dianne Hackborn | 8abd5f0 | 2009-11-20 18:09:03 -0800 | [diff] [blame] | 2481 | if (moveInputMethodWindowsIfNeededLocked(false) || displayed) { |
| 2482 | // Little hack here -- we -should- be able to rely on the |
| 2483 | // function to return true if the IME has moved and needs |
| 2484 | // its layer recomputed. However, if the IME was hidden |
| 2485 | // and isn't actually moved in the list, its layer may be |
| 2486 | // 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] | 2487 | assignLayers = true; |
| 2488 | } |
| 2489 | } |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2490 | if (wallpaperMayMove) { |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 2491 | if ((adjustWallpaperWindowsLocked()&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) { |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2492 | assignLayers = true; |
| 2493 | } |
| 2494 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2495 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2496 | mLayoutNeeded = true; |
| 2497 | win.mGivenInsetsPending = insetsPending; |
| 2498 | if (assignLayers) { |
| 2499 | assignLayersLocked(); |
| 2500 | } |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2501 | configChanged = updateOrientationFromAppTokensLocked(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2502 | performLayoutAndPlaceSurfacesLocked(); |
| Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 2503 | if (displayed && win.mIsWallpaper) { |
| 2504 | updateWallpaperOffsetLocked(win, mDisplay.getWidth(), |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 2505 | mDisplay.getHeight(), false); |
| Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 2506 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2507 | if (win.mAppToken != null) { |
| 2508 | win.mAppToken.updateReportedVisibilityLocked(); |
| 2509 | } |
| 2510 | outFrame.set(win.mFrame); |
| 2511 | outContentInsets.set(win.mContentInsets); |
| 2512 | outVisibleInsets.set(win.mVisibleInsets); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2513 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2514 | TAG, "Relayout given client " + client.asBinder() |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2515 | + ", requestedWidth=" + requestedWidth |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2516 | + ", requestedHeight=" + requestedHeight |
| 2517 | + ", viewVisibility=" + viewVisibility |
| 2518 | + "\nRelayout returning frame=" + outFrame |
| 2519 | + ", surface=" + outSurface); |
| 2520 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2521 | if (localLOGV || DEBUG_FOCUS) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2522 | TAG, "Relayout of " + win + ": focusMayChange=" + focusMayChange); |
| 2523 | |
| 2524 | inTouchMode = mInTouchMode; |
| 2525 | } |
| 2526 | |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2527 | if (configChanged) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2528 | sendNewConfiguration(); |
| 2529 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2530 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2531 | Binder.restoreCallingIdentity(origId); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2532 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2533 | return (inTouchMode ? WindowManagerImpl.RELAYOUT_IN_TOUCH_MODE : 0) |
| 2534 | | (displayed ? WindowManagerImpl.RELAYOUT_FIRST_TIME : 0); |
| 2535 | } |
| 2536 | |
| 2537 | public void finishDrawingWindow(Session session, IWindow client) { |
| 2538 | final long origId = Binder.clearCallingIdentity(); |
| 2539 | synchronized(mWindowMap) { |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2540 | WindowState win = windowForClientLocked(session, client, false); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2541 | if (win != null && win.finishDrawingLocked()) { |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 2542 | if ((win.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0) { |
| 2543 | adjustWallpaperWindowsLocked(); |
| 2544 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2545 | mLayoutNeeded = true; |
| 2546 | performLayoutAndPlaceSurfacesLocked(); |
| 2547 | } |
| 2548 | } |
| 2549 | Binder.restoreCallingIdentity(origId); |
| 2550 | } |
| 2551 | |
| 2552 | private AttributeCache.Entry getCachedAnimations(WindowManager.LayoutParams lp) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2553 | if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: params package=" |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2554 | + (lp != null ? lp.packageName : null) |
| 2555 | + " resId=0x" + (lp != null ? Integer.toHexString(lp.windowAnimations) : null)); |
| 2556 | if (lp != null && lp.windowAnimations != 0) { |
| 2557 | // If this is a system resource, don't try to load it from the |
| 2558 | // application resources. It is nice to avoid loading application |
| 2559 | // resources if we can. |
| 2560 | String packageName = lp.packageName != null ? lp.packageName : "android"; |
| 2561 | int resId = lp.windowAnimations; |
| 2562 | if ((resId&0xFF000000) == 0x01000000) { |
| 2563 | packageName = "android"; |
| 2564 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2565 | if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: picked package=" |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2566 | + packageName); |
| 2567 | return AttributeCache.instance().get(packageName, resId, |
| 2568 | com.android.internal.R.styleable.WindowAnimation); |
| 2569 | } |
| 2570 | return null; |
| 2571 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2572 | |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2573 | private AttributeCache.Entry getCachedAnimations(String packageName, int resId) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2574 | if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: params package=" |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2575 | + packageName + " resId=0x" + Integer.toHexString(resId)); |
| 2576 | if (packageName != null) { |
| 2577 | if ((resId&0xFF000000) == 0x01000000) { |
| 2578 | packageName = "android"; |
| 2579 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2580 | if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: picked package=" |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2581 | + packageName); |
| 2582 | return AttributeCache.instance().get(packageName, resId, |
| 2583 | com.android.internal.R.styleable.WindowAnimation); |
| 2584 | } |
| 2585 | return null; |
| 2586 | } |
| 2587 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2588 | private void applyEnterAnimationLocked(WindowState win) { |
| 2589 | int transit = WindowManagerPolicy.TRANSIT_SHOW; |
| 2590 | if (win.mEnterAnimationPending) { |
| 2591 | win.mEnterAnimationPending = false; |
| 2592 | transit = WindowManagerPolicy.TRANSIT_ENTER; |
| 2593 | } |
| 2594 | |
| 2595 | applyAnimationLocked(win, transit, true); |
| 2596 | } |
| 2597 | |
| 2598 | private boolean applyAnimationLocked(WindowState win, |
| 2599 | int transit, boolean isEntrance) { |
| 2600 | if (win.mLocalAnimating && win.mAnimationIsEntrance == isEntrance) { |
| 2601 | // If we are trying to apply an animation, but already running |
| 2602 | // an animation of the same type, then just leave that one alone. |
| 2603 | return true; |
| 2604 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2605 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2606 | // Only apply an animation if the display isn't frozen. If it is |
| 2607 | // frozen, there is no reason to animate and it can cause strange |
| 2608 | // artifacts when we unfreeze the display if some different animation |
| 2609 | // is running. |
| Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 2610 | if (!mDisplayFrozen && mPolicy.isScreenOn()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2611 | int anim = mPolicy.selectAnimationLw(win, transit); |
| 2612 | int attr = -1; |
| 2613 | Animation a = null; |
| 2614 | if (anim != 0) { |
| 2615 | a = AnimationUtils.loadAnimation(mContext, anim); |
| 2616 | } else { |
| 2617 | switch (transit) { |
| 2618 | case WindowManagerPolicy.TRANSIT_ENTER: |
| 2619 | attr = com.android.internal.R.styleable.WindowAnimation_windowEnterAnimation; |
| 2620 | break; |
| 2621 | case WindowManagerPolicy.TRANSIT_EXIT: |
| 2622 | attr = com.android.internal.R.styleable.WindowAnimation_windowExitAnimation; |
| 2623 | break; |
| 2624 | case WindowManagerPolicy.TRANSIT_SHOW: |
| 2625 | attr = com.android.internal.R.styleable.WindowAnimation_windowShowAnimation; |
| 2626 | break; |
| 2627 | case WindowManagerPolicy.TRANSIT_HIDE: |
| 2628 | attr = com.android.internal.R.styleable.WindowAnimation_windowHideAnimation; |
| 2629 | break; |
| 2630 | } |
| 2631 | if (attr >= 0) { |
| 2632 | a = loadAnimation(win.mAttrs, attr); |
| 2633 | } |
| 2634 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2635 | if (DEBUG_ANIM) Slog.v(TAG, "applyAnimation: win=" + win |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2636 | + " anim=" + anim + " attr=0x" + Integer.toHexString(attr) |
| 2637 | + " mAnimation=" + win.mAnimation |
| 2638 | + " isEntrance=" + isEntrance); |
| 2639 | if (a != null) { |
| 2640 | if (DEBUG_ANIM) { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 2641 | RuntimeException e = null; |
| 2642 | if (!HIDE_STACK_CRAWLS) { |
| 2643 | e = new RuntimeException(); |
| 2644 | e.fillInStackTrace(); |
| 2645 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2646 | Slog.v(TAG, "Loaded animation " + a + " for " + win, e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2647 | } |
| 2648 | win.setAnimation(a); |
| 2649 | win.mAnimationIsEntrance = isEntrance; |
| 2650 | } |
| 2651 | } else { |
| 2652 | win.clearAnimation(); |
| 2653 | } |
| 2654 | |
| 2655 | return win.mAnimation != null; |
| 2656 | } |
| 2657 | |
| 2658 | private Animation loadAnimation(WindowManager.LayoutParams lp, int animAttr) { |
| 2659 | int anim = 0; |
| 2660 | Context context = mContext; |
| 2661 | if (animAttr >= 0) { |
| 2662 | AttributeCache.Entry ent = getCachedAnimations(lp); |
| 2663 | if (ent != null) { |
| 2664 | context = ent.context; |
| 2665 | anim = ent.array.getResourceId(animAttr, 0); |
| 2666 | } |
| 2667 | } |
| 2668 | if (anim != 0) { |
| 2669 | return AnimationUtils.loadAnimation(context, anim); |
| 2670 | } |
| 2671 | return null; |
| 2672 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2673 | |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2674 | private Animation loadAnimation(String packageName, int resId) { |
| 2675 | int anim = 0; |
| 2676 | Context context = mContext; |
| 2677 | if (resId >= 0) { |
| 2678 | AttributeCache.Entry ent = getCachedAnimations(packageName, resId); |
| 2679 | if (ent != null) { |
| 2680 | context = ent.context; |
| 2681 | anim = resId; |
| 2682 | } |
| 2683 | } |
| 2684 | if (anim != 0) { |
| 2685 | return AnimationUtils.loadAnimation(context, anim); |
| 2686 | } |
| 2687 | return null; |
| 2688 | } |
| 2689 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2690 | private boolean applyAnimationLocked(AppWindowToken wtoken, |
| 2691 | WindowManager.LayoutParams lp, int transit, boolean enter) { |
| 2692 | // Only apply an animation if the display isn't frozen. If it is |
| 2693 | // frozen, there is no reason to animate and it can cause strange |
| 2694 | // artifacts when we unfreeze the display if some different animation |
| 2695 | // is running. |
| Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 2696 | if (!mDisplayFrozen && mPolicy.isScreenOn()) { |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 2697 | Animation a; |
| Mitsuru Oshima | d2967e2 | 2009-07-20 14:01:43 -0700 | [diff] [blame] | 2698 | if (lp != null && (lp.flags & FLAG_COMPATIBLE_WINDOW) != 0) { |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 2699 | a = new FadeInOutAnimation(enter); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2700 | if (DEBUG_ANIM) Slog.v(TAG, |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 2701 | "applying FadeInOutAnimation for a window in compatibility mode"); |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2702 | } else if (mNextAppTransitionPackage != null) { |
| 2703 | a = loadAnimation(mNextAppTransitionPackage, enter ? |
| 2704 | mNextAppTransitionEnter : mNextAppTransitionExit); |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 2705 | } else { |
| 2706 | int animAttr = 0; |
| 2707 | switch (transit) { |
| 2708 | case WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN: |
| 2709 | animAttr = enter |
| 2710 | ? com.android.internal.R.styleable.WindowAnimation_activityOpenEnterAnimation |
| 2711 | : com.android.internal.R.styleable.WindowAnimation_activityOpenExitAnimation; |
| 2712 | break; |
| 2713 | case WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE: |
| 2714 | animAttr = enter |
| 2715 | ? com.android.internal.R.styleable.WindowAnimation_activityCloseEnterAnimation |
| 2716 | : com.android.internal.R.styleable.WindowAnimation_activityCloseExitAnimation; |
| 2717 | break; |
| 2718 | case WindowManagerPolicy.TRANSIT_TASK_OPEN: |
| 2719 | animAttr = enter |
| 2720 | ? com.android.internal.R.styleable.WindowAnimation_taskOpenEnterAnimation |
| 2721 | : com.android.internal.R.styleable.WindowAnimation_taskOpenExitAnimation; |
| 2722 | break; |
| 2723 | case WindowManagerPolicy.TRANSIT_TASK_CLOSE: |
| 2724 | animAttr = enter |
| 2725 | ? com.android.internal.R.styleable.WindowAnimation_taskCloseEnterAnimation |
| 2726 | : com.android.internal.R.styleable.WindowAnimation_taskCloseExitAnimation; |
| 2727 | break; |
| 2728 | case WindowManagerPolicy.TRANSIT_TASK_TO_FRONT: |
| 2729 | animAttr = enter |
| 2730 | ? com.android.internal.R.styleable.WindowAnimation_taskToFrontEnterAnimation |
| 2731 | : com.android.internal.R.styleable.WindowAnimation_taskToFrontExitAnimation; |
| 2732 | break; |
| 2733 | case WindowManagerPolicy.TRANSIT_TASK_TO_BACK: |
| 2734 | animAttr = enter |
| Mitsuru Oshima | 5a2b91d | 2009-07-16 16:30:02 -0700 | [diff] [blame] | 2735 | ? com.android.internal.R.styleable.WindowAnimation_taskToBackEnterAnimation |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 2736 | : com.android.internal.R.styleable.WindowAnimation_taskToBackExitAnimation; |
| 2737 | break; |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 2738 | case WindowManagerPolicy.TRANSIT_WALLPAPER_OPEN: |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 2739 | animAttr = enter |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 2740 | ? com.android.internal.R.styleable.WindowAnimation_wallpaperOpenEnterAnimation |
| 2741 | : com.android.internal.R.styleable.WindowAnimation_wallpaperOpenExitAnimation; |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 2742 | break; |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 2743 | case WindowManagerPolicy.TRANSIT_WALLPAPER_CLOSE: |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 2744 | animAttr = enter |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 2745 | ? com.android.internal.R.styleable.WindowAnimation_wallpaperCloseEnterAnimation |
| 2746 | : com.android.internal.R.styleable.WindowAnimation_wallpaperCloseExitAnimation; |
| 2747 | break; |
| 2748 | case WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_OPEN: |
| 2749 | animAttr = enter |
| 2750 | ? com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenEnterAnimation |
| 2751 | : com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenExitAnimation; |
| 2752 | break; |
| 2753 | case WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_CLOSE: |
| 2754 | animAttr = enter |
| 2755 | ? com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseEnterAnimation |
| 2756 | : com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseExitAnimation; |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 2757 | break; |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 2758 | } |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 2759 | a = animAttr != 0 ? loadAnimation(lp, animAttr) : null; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2760 | if (DEBUG_ANIM) Slog.v(TAG, "applyAnimation: wtoken=" + wtoken |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 2761 | + " anim=" + a |
| 2762 | + " animAttr=0x" + Integer.toHexString(animAttr) |
| 2763 | + " transit=" + transit); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2764 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2765 | if (a != null) { |
| 2766 | if (DEBUG_ANIM) { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 2767 | RuntimeException e = null; |
| 2768 | if (!HIDE_STACK_CRAWLS) { |
| 2769 | e = new RuntimeException(); |
| 2770 | e.fillInStackTrace(); |
| 2771 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2772 | Slog.v(TAG, "Loaded animation " + a + " for " + wtoken, e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2773 | } |
| 2774 | wtoken.setAnimation(a); |
| 2775 | } |
| 2776 | } else { |
| 2777 | wtoken.clearAnimation(); |
| 2778 | } |
| 2779 | |
| 2780 | return wtoken.animation != null; |
| 2781 | } |
| 2782 | |
| 2783 | // ------------------------------------------------------------- |
| 2784 | // Application Window Tokens |
| 2785 | // ------------------------------------------------------------- |
| 2786 | |
| 2787 | public void validateAppTokens(List tokens) { |
| 2788 | int v = tokens.size()-1; |
| 2789 | int m = mAppTokens.size()-1; |
| 2790 | while (v >= 0 && m >= 0) { |
| 2791 | AppWindowToken wtoken = mAppTokens.get(m); |
| 2792 | if (wtoken.removed) { |
| 2793 | m--; |
| 2794 | continue; |
| 2795 | } |
| 2796 | if (tokens.get(v) != wtoken.token) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2797 | Slog.w(TAG, "Tokens out of sync: external is " + tokens.get(v) |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2798 | + " @ " + v + ", internal is " + wtoken.token + " @ " + m); |
| 2799 | } |
| 2800 | v--; |
| 2801 | m--; |
| 2802 | } |
| 2803 | while (v >= 0) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2804 | Slog.w(TAG, "External token not found: " + tokens.get(v) + " @ " + v); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2805 | v--; |
| 2806 | } |
| 2807 | while (m >= 0) { |
| 2808 | AppWindowToken wtoken = mAppTokens.get(m); |
| 2809 | if (!wtoken.removed) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2810 | Slog.w(TAG, "Invalid internal token: " + wtoken.token + " @ " + m); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2811 | } |
| 2812 | m--; |
| 2813 | } |
| 2814 | } |
| 2815 | |
| 2816 | boolean checkCallingPermission(String permission, String func) { |
| 2817 | // Quick check: if the calling permission is me, it's all okay. |
| 2818 | if (Binder.getCallingPid() == Process.myPid()) { |
| 2819 | return true; |
| 2820 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2821 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2822 | if (mContext.checkCallingPermission(permission) |
| 2823 | == PackageManager.PERMISSION_GRANTED) { |
| 2824 | return true; |
| 2825 | } |
| 2826 | String msg = "Permission Denial: " + func + " from pid=" |
| 2827 | + Binder.getCallingPid() |
| 2828 | + ", uid=" + Binder.getCallingUid() |
| 2829 | + " requires " + permission; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2830 | Slog.w(TAG, msg); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2831 | return false; |
| 2832 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2833 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2834 | AppWindowToken findAppWindowToken(IBinder token) { |
| 2835 | WindowToken wtoken = mTokenMap.get(token); |
| 2836 | if (wtoken == null) { |
| 2837 | return null; |
| 2838 | } |
| 2839 | return wtoken.appWindowToken; |
| 2840 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2841 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2842 | public void addWindowToken(IBinder token, int type) { |
| 2843 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 2844 | "addWindowToken()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 2845 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2846 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2847 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2848 | synchronized(mWindowMap) { |
| 2849 | WindowToken wtoken = mTokenMap.get(token); |
| 2850 | if (wtoken != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2851 | Slog.w(TAG, "Attempted to add existing input method token: " + token); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2852 | return; |
| 2853 | } |
| 2854 | wtoken = new WindowToken(token, type, true); |
| 2855 | mTokenMap.put(token, wtoken); |
| 2856 | mTokenList.add(wtoken); |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2857 | if (type == TYPE_WALLPAPER) { |
| 2858 | mWallpaperTokens.add(wtoken); |
| 2859 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2860 | } |
| 2861 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2862 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2863 | public void removeWindowToken(IBinder token) { |
| 2864 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 2865 | "removeWindowToken()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 2866 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2867 | } |
| 2868 | |
| 2869 | final long origId = Binder.clearCallingIdentity(); |
| 2870 | synchronized(mWindowMap) { |
| 2871 | WindowToken wtoken = mTokenMap.remove(token); |
| 2872 | mTokenList.remove(wtoken); |
| 2873 | if (wtoken != null) { |
| 2874 | boolean delayed = false; |
| 2875 | if (!wtoken.hidden) { |
| 2876 | wtoken.hidden = true; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2877 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2878 | final int N = wtoken.windows.size(); |
| 2879 | boolean changed = false; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2880 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2881 | for (int i=0; i<N; i++) { |
| 2882 | WindowState win = wtoken.windows.get(i); |
| 2883 | |
| 2884 | if (win.isAnimating()) { |
| 2885 | delayed = true; |
| 2886 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2887 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2888 | if (win.isVisibleNow()) { |
| 2889 | applyAnimationLocked(win, |
| 2890 | WindowManagerPolicy.TRANSIT_EXIT, false); |
| Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 2891 | mInputMonitor.windowIsBeingRemovedLw(win); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2892 | changed = true; |
| 2893 | } |
| 2894 | } |
| 2895 | |
| 2896 | if (changed) { |
| 2897 | mLayoutNeeded = true; |
| 2898 | performLayoutAndPlaceSurfacesLocked(); |
| 2899 | updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL); |
| 2900 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2901 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2902 | if (delayed) { |
| 2903 | mExitingTokens.add(wtoken); |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2904 | } else if (wtoken.windowType == TYPE_WALLPAPER) { |
| 2905 | mWallpaperTokens.remove(wtoken); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2906 | } |
| 2907 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2908 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2909 | } else { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2910 | Slog.w(TAG, "Attempted to remove non-existing token: " + token); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2911 | } |
| 2912 | } |
| 2913 | Binder.restoreCallingIdentity(origId); |
| 2914 | } |
| 2915 | |
| 2916 | public void addAppToken(int addPos, IApplicationToken token, |
| 2917 | int groupId, int requestedOrientation, boolean fullscreen) { |
| 2918 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 2919 | "addAppToken()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 2920 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2921 | } |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 2922 | |
| 2923 | // Get the dispatching timeout here while we are not holding any locks so that it |
| 2924 | // can be cached by the AppWindowToken. The timeout value is used later by the |
| 2925 | // input dispatcher in code that does hold locks. If we did not cache the value |
| 2926 | // here we would run the chance of introducing a deadlock between the window manager |
| 2927 | // (which holds locks while updating the input dispatcher state) and the activity manager |
| 2928 | // (which holds locks while querying the application token). |
| 2929 | long inputDispatchingTimeoutNanos; |
| 2930 | try { |
| 2931 | inputDispatchingTimeoutNanos = token.getKeyDispatchingTimeout() * 1000000L; |
| 2932 | } catch (RemoteException ex) { |
| 2933 | Slog.w(TAG, "Could not get dispatching timeout.", ex); |
| 2934 | inputDispatchingTimeoutNanos = DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS; |
| 2935 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2936 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2937 | synchronized(mWindowMap) { |
| 2938 | AppWindowToken wtoken = findAppWindowToken(token.asBinder()); |
| 2939 | if (wtoken != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2940 | Slog.w(TAG, "Attempted to add existing app token: " + token); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2941 | return; |
| 2942 | } |
| 2943 | wtoken = new AppWindowToken(token); |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 2944 | wtoken.inputDispatchingTimeoutNanos = inputDispatchingTimeoutNanos; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2945 | wtoken.groupId = groupId; |
| 2946 | wtoken.appFullscreen = fullscreen; |
| 2947 | wtoken.requestedOrientation = requestedOrientation; |
| 2948 | mAppTokens.add(addPos, wtoken); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2949 | if (localLOGV) Slog.v(TAG, "Adding new app token: " + wtoken); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2950 | mTokenMap.put(token.asBinder(), wtoken); |
| 2951 | mTokenList.add(wtoken); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2952 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2953 | // Application tokens start out hidden. |
| 2954 | wtoken.hidden = true; |
| 2955 | wtoken.hiddenRequested = true; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2956 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2957 | //dump(); |
| 2958 | } |
| 2959 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2960 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2961 | public void setAppGroupId(IBinder token, int groupId) { |
| 2962 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 2963 | "setAppStartingIcon()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 2964 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2965 | } |
| 2966 | |
| 2967 | synchronized(mWindowMap) { |
| 2968 | AppWindowToken wtoken = findAppWindowToken(token); |
| 2969 | if (wtoken == null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2970 | Slog.w(TAG, "Attempted to set group id of non-existing app token: " + token); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2971 | return; |
| 2972 | } |
| 2973 | wtoken.groupId = groupId; |
| 2974 | } |
| 2975 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2976 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2977 | public int getOrientationFromWindowsLocked() { |
| 2978 | int pos = mWindows.size() - 1; |
| 2979 | while (pos >= 0) { |
| 2980 | WindowState wtoken = (WindowState) mWindows.get(pos); |
| 2981 | pos--; |
| 2982 | if (wtoken.mAppToken != null) { |
| 2983 | // We hit an application window. so the orientation will be determined by the |
| 2984 | // app window. No point in continuing further. |
| 2985 | return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
| 2986 | } |
| Christopher Tate | b696aee | 2010-04-02 19:08:30 -0700 | [diff] [blame] | 2987 | if (!wtoken.isVisibleLw() || !wtoken.mPolicyVisibilityAfterAnim) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2988 | continue; |
| 2989 | } |
| 2990 | int req = wtoken.mAttrs.screenOrientation; |
| 2991 | if((req == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) || |
| 2992 | (req == ActivityInfo.SCREEN_ORIENTATION_BEHIND)){ |
| 2993 | continue; |
| 2994 | } else { |
| 2995 | return req; |
| 2996 | } |
| 2997 | } |
| 2998 | return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
| 2999 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3000 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3001 | public int getOrientationFromAppTokensLocked() { |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3002 | int pos = mAppTokens.size() - 1; |
| 3003 | int curGroup = 0; |
| 3004 | int lastOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
| 3005 | boolean findingBehind = false; |
| 3006 | boolean haveGroup = false; |
| 3007 | boolean lastFullscreen = false; |
| 3008 | while (pos >= 0) { |
| 3009 | AppWindowToken wtoken = mAppTokens.get(pos); |
| 3010 | pos--; |
| 3011 | // if we're about to tear down this window and not seek for |
| 3012 | // the behind activity, don't use it for orientation |
| 3013 | if (!findingBehind |
| 3014 | && (!wtoken.hidden && wtoken.hiddenRequested)) { |
| 3015 | continue; |
| 3016 | } |
| 3017 | |
| 3018 | if (!haveGroup) { |
| 3019 | // We ignore any hidden applications on the top. |
| 3020 | if (wtoken.hiddenRequested || wtoken.willBeHidden) { |
| The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3021 | continue; |
| 3022 | } |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3023 | haveGroup = true; |
| 3024 | curGroup = wtoken.groupId; |
| 3025 | lastOrientation = wtoken.requestedOrientation; |
| 3026 | } else if (curGroup != wtoken.groupId) { |
| 3027 | // If we have hit a new application group, and the bottom |
| 3028 | // of the previous group didn't explicitly say to use |
| 3029 | // the orientation behind it, and the last app was |
| 3030 | // full screen, then we'll stick with the |
| 3031 | // user's orientation. |
| 3032 | if (lastOrientation != ActivityInfo.SCREEN_ORIENTATION_BEHIND |
| 3033 | && lastFullscreen) { |
| 3034 | return lastOrientation; |
| 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 | } |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3037 | int or = wtoken.requestedOrientation; |
| 3038 | // If this application is fullscreen, and didn't explicitly say |
| 3039 | // to use the orientation behind it, then just take whatever |
| 3040 | // orientation it has and ignores whatever is under it. |
| 3041 | lastFullscreen = wtoken.appFullscreen; |
| 3042 | if (lastFullscreen |
| 3043 | && or != ActivityInfo.SCREEN_ORIENTATION_BEHIND) { |
| 3044 | return or; |
| 3045 | } |
| 3046 | // If this application has requested an explicit orientation, |
| 3047 | // then use it. |
| 3048 | if (or == ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE || |
| 3049 | or == ActivityInfo.SCREEN_ORIENTATION_PORTRAIT || |
| 3050 | or == ActivityInfo.SCREEN_ORIENTATION_SENSOR || |
| 3051 | or == ActivityInfo.SCREEN_ORIENTATION_NOSENSOR || |
| 3052 | or == ActivityInfo.SCREEN_ORIENTATION_USER) { |
| 3053 | return or; |
| 3054 | } |
| 3055 | findingBehind |= (or == ActivityInfo.SCREEN_ORIENTATION_BEHIND); |
| 3056 | } |
| 3057 | return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3058 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3059 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3060 | public Configuration updateOrientationFromAppTokens( |
| The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3061 | Configuration currentConfig, IBinder freezeThisOneIfNeeded) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3062 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3063 | "updateOrientationFromAppTokens()")) { |
| 3064 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| 3065 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3066 | |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3067 | Configuration config = null; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3068 | long ident = Binder.clearCallingIdentity(); |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3069 | |
| 3070 | synchronized(mWindowMap) { |
| 3071 | if (updateOrientationFromAppTokensLocked()) { |
| 3072 | if (freezeThisOneIfNeeded != null) { |
| 3073 | AppWindowToken wtoken = findAppWindowToken( |
| 3074 | freezeThisOneIfNeeded); |
| 3075 | if (wtoken != null) { |
| 3076 | startAppFreezingScreenLocked(wtoken, |
| 3077 | ActivityInfo.CONFIG_ORIENTATION); |
| 3078 | } |
| 3079 | } |
| 3080 | config = computeNewConfigurationLocked(); |
| 3081 | |
| 3082 | } else if (currentConfig != null) { |
| 3083 | // No obvious action we need to take, but if our current |
| 3084 | // state mismatches the activity maanager's, update it |
| 3085 | mTempConfiguration.setToDefaults(); |
| 3086 | if (computeNewConfigurationLocked(mTempConfiguration)) { |
| 3087 | if (currentConfig.diff(mTempConfiguration) != 0) { |
| 3088 | mWaitingForConfig = true; |
| 3089 | mLayoutNeeded = true; |
| 3090 | startFreezingDisplayLocked(); |
| 3091 | config = new Configuration(mTempConfiguration); |
| 3092 | } |
| 3093 | } |
| 3094 | } |
| 3095 | } |
| 3096 | |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3097 | Binder.restoreCallingIdentity(ident); |
| 3098 | return config; |
| 3099 | } |
| 3100 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3101 | /* |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3102 | * Determine the new desired orientation of the display, returning |
| 3103 | * a non-null new Configuration if it has changed from the current |
| 3104 | * orientation. IF TRUE IS RETURNED SOMEONE MUST CALL |
| 3105 | * setNewConfiguration() TO TELL THE WINDOW MANAGER IT CAN UNFREEZE THE |
| 3106 | * SCREEN. This will typically be done for you if you call |
| 3107 | * sendNewConfiguration(). |
| 3108 | * |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3109 | * The orientation is computed from non-application windows first. If none of |
| 3110 | * the non-application windows specify orientation, the orientation is computed from |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3111 | * application tokens. |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3112 | * @see android.view.IWindowManager#updateOrientationFromAppTokens( |
| 3113 | * android.os.IBinder) |
| 3114 | */ |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3115 | boolean updateOrientationFromAppTokensLocked() { |
| Christopher Tate | b696aee | 2010-04-02 19:08:30 -0700 | [diff] [blame] | 3116 | if (mDisplayFrozen) { |
| 3117 | // If the display is frozen, some activities may be in the middle |
| 3118 | // of restarting, and thus have removed their old window. If the |
| 3119 | // window has the flag to hide the lock screen, then the lock screen |
| 3120 | // can re-appear and inflict its own orientation on us. Keep the |
| 3121 | // orientation stable until this all settles down. |
| 3122 | return false; |
| 3123 | } |
| 3124 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3125 | boolean changed = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3126 | long ident = Binder.clearCallingIdentity(); |
| 3127 | try { |
| The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 3128 | int req = computeForcedAppOrientationLocked(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3129 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3130 | if (req != mForcedAppOrientation) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3131 | mForcedAppOrientation = req; |
| 3132 | //send a message to Policy indicating orientation change to take |
| 3133 | //action like disabling/enabling sensors etc., |
| The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 3134 | mPolicy.setCurrentOrientationLw(req); |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3135 | if (setRotationUncheckedLocked(WindowManagerPolicy.USE_LAST_ROTATION, |
| 3136 | mLastRotationFlags | Surface.FLAGS_ORIENTATION_ANIMATION_DISABLE)) { |
| 3137 | changed = true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3138 | } |
| 3139 | } |
| The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3140 | |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3141 | return changed; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3142 | } finally { |
| 3143 | Binder.restoreCallingIdentity(ident); |
| 3144 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3145 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3146 | |
| The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 3147 | int computeForcedAppOrientationLocked() { |
| 3148 | int req = getOrientationFromWindowsLocked(); |
| 3149 | if (req == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) { |
| 3150 | req = getOrientationFromAppTokensLocked(); |
| 3151 | } |
| 3152 | return req; |
| 3153 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3154 | |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3155 | public void setNewConfiguration(Configuration config) { |
| 3156 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3157 | "setNewConfiguration()")) { |
| 3158 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| 3159 | } |
| 3160 | |
| 3161 | synchronized(mWindowMap) { |
| 3162 | mCurConfiguration = new Configuration(config); |
| 3163 | mWaitingForConfig = false; |
| 3164 | performLayoutAndPlaceSurfacesLocked(); |
| 3165 | } |
| 3166 | } |
| 3167 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3168 | public void setAppOrientation(IApplicationToken token, int requestedOrientation) { |
| 3169 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3170 | "setAppOrientation()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3171 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3172 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3173 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3174 | synchronized(mWindowMap) { |
| 3175 | AppWindowToken wtoken = findAppWindowToken(token.asBinder()); |
| 3176 | if (wtoken == null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3177 | Slog.w(TAG, "Attempted to set orientation of non-existing app token: " + token); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3178 | return; |
| 3179 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3180 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3181 | wtoken.requestedOrientation = requestedOrientation; |
| 3182 | } |
| 3183 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3184 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3185 | public int getAppOrientation(IApplicationToken token) { |
| 3186 | synchronized(mWindowMap) { |
| 3187 | AppWindowToken wtoken = findAppWindowToken(token.asBinder()); |
| 3188 | if (wtoken == null) { |
| 3189 | return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
| 3190 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3191 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3192 | return wtoken.requestedOrientation; |
| 3193 | } |
| 3194 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3195 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3196 | public void setFocusedApp(IBinder token, boolean moveFocusNow) { |
| 3197 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3198 | "setFocusedApp()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3199 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3200 | } |
| 3201 | |
| 3202 | synchronized(mWindowMap) { |
| 3203 | boolean changed = false; |
| 3204 | if (token == null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3205 | if (DEBUG_FOCUS) Slog.v(TAG, "Clearing focused app, was " + mFocusedApp); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3206 | changed = mFocusedApp != null; |
| 3207 | mFocusedApp = null; |
| Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 3208 | if (changed) { |
| 3209 | mInputMonitor.setFocusedAppLw(null); |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 3210 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3211 | } else { |
| 3212 | AppWindowToken newFocus = findAppWindowToken(token); |
| 3213 | if (newFocus == null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3214 | Slog.w(TAG, "Attempted to set focus to non-existing app token: " + token); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3215 | return; |
| 3216 | } |
| 3217 | changed = mFocusedApp != newFocus; |
| 3218 | mFocusedApp = newFocus; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3219 | if (DEBUG_FOCUS) Slog.v(TAG, "Set focused app to: " + mFocusedApp); |
| Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 3220 | if (changed) { |
| 3221 | mInputMonitor.setFocusedAppLw(newFocus); |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 3222 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3223 | } |
| 3224 | |
| 3225 | if (moveFocusNow && changed) { |
| 3226 | final long origId = Binder.clearCallingIdentity(); |
| 3227 | updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL); |
| 3228 | Binder.restoreCallingIdentity(origId); |
| 3229 | } |
| 3230 | } |
| 3231 | } |
| 3232 | |
| 3233 | public void prepareAppTransition(int transit) { |
| 3234 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3235 | "prepareAppTransition()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3236 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3237 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3238 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3239 | synchronized(mWindowMap) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3240 | if (DEBUG_APP_TRANSITIONS) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3241 | TAG, "Prepare app transition: transit=" + transit |
| 3242 | + " mNextAppTransition=" + mNextAppTransition); |
| Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 3243 | if (!mDisplayFrozen && mPolicy.isScreenOn()) { |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 3244 | if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET |
| 3245 | || mNextAppTransition == WindowManagerPolicy.TRANSIT_NONE) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3246 | mNextAppTransition = transit; |
| Dianne Hackborn | d7cd29d | 2009-07-01 11:22:45 -0700 | [diff] [blame] | 3247 | } else if (transit == WindowManagerPolicy.TRANSIT_TASK_OPEN |
| 3248 | && mNextAppTransition == WindowManagerPolicy.TRANSIT_TASK_CLOSE) { |
| 3249 | // Opening a new task always supersedes a close for the anim. |
| 3250 | mNextAppTransition = transit; |
| 3251 | } else if (transit == WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN |
| 3252 | && mNextAppTransition == WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE) { |
| 3253 | // Opening a new activity always supersedes a close for the anim. |
| 3254 | mNextAppTransition = transit; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3255 | } |
| 3256 | mAppTransitionReady = false; |
| 3257 | mAppTransitionTimeout = false; |
| 3258 | mStartingIconInTransition = false; |
| 3259 | mSkipAppTransitionAnimation = false; |
| 3260 | mH.removeMessages(H.APP_TRANSITION_TIMEOUT); |
| 3261 | mH.sendMessageDelayed(mH.obtainMessage(H.APP_TRANSITION_TIMEOUT), |
| 3262 | 5000); |
| 3263 | } |
| 3264 | } |
| 3265 | } |
| 3266 | |
| 3267 | public int getPendingAppTransition() { |
| 3268 | return mNextAppTransition; |
| 3269 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3270 | |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 3271 | public void overridePendingAppTransition(String packageName, |
| 3272 | int enterAnim, int exitAnim) { |
| Dianne Hackborn | 8b571a8 | 2009-09-25 16:09:43 -0700 | [diff] [blame] | 3273 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 3274 | mNextAppTransitionPackage = packageName; |
| 3275 | mNextAppTransitionEnter = enterAnim; |
| 3276 | mNextAppTransitionExit = exitAnim; |
| 3277 | } |
| 3278 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3279 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3280 | public void executeAppTransition() { |
| 3281 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3282 | "executeAppTransition()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3283 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3284 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3285 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3286 | synchronized(mWindowMap) { |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 3287 | if (DEBUG_APP_TRANSITIONS) { |
| 3288 | RuntimeException e = new RuntimeException("here"); |
| 3289 | e.fillInStackTrace(); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3290 | Slog.w(TAG, "Execute app transition: mNextAppTransition=" |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 3291 | + mNextAppTransition, e); |
| 3292 | } |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 3293 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3294 | mAppTransitionReady = true; |
| 3295 | final long origId = Binder.clearCallingIdentity(); |
| 3296 | performLayoutAndPlaceSurfacesLocked(); |
| 3297 | Binder.restoreCallingIdentity(origId); |
| 3298 | } |
| 3299 | } |
| 3300 | } |
| 3301 | |
| 3302 | public void setAppStartingWindow(IBinder token, String pkg, |
| 3303 | int theme, CharSequence nonLocalizedLabel, int labelRes, int icon, |
| 3304 | IBinder transferFrom, boolean createIfNeeded) { |
| 3305 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3306 | "setAppStartingIcon()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3307 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3308 | } |
| 3309 | |
| 3310 | synchronized(mWindowMap) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3311 | if (DEBUG_STARTING_WINDOW) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3312 | TAG, "setAppStartingIcon: token=" + token + " pkg=" + pkg |
| 3313 | + " transferFrom=" + transferFrom); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3314 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3315 | AppWindowToken wtoken = findAppWindowToken(token); |
| 3316 | if (wtoken == null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3317 | Slog.w(TAG, "Attempted to set icon of non-existing app token: " + token); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3318 | return; |
| 3319 | } |
| 3320 | |
| 3321 | // If the display is frozen, we won't do anything until the |
| 3322 | // actual window is displayed so there is no reason to put in |
| 3323 | // the starting window. |
| Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 3324 | if (mDisplayFrozen || !mPolicy.isScreenOn()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3325 | return; |
| 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 | if (wtoken.startingData != null) { |
| 3329 | return; |
| 3330 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3331 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3332 | if (transferFrom != null) { |
| 3333 | AppWindowToken ttoken = findAppWindowToken(transferFrom); |
| 3334 | if (ttoken != null) { |
| 3335 | WindowState startingWindow = ttoken.startingWindow; |
| 3336 | if (startingWindow != null) { |
| 3337 | if (mStartingIconInTransition) { |
| 3338 | // In this case, the starting icon has already |
| 3339 | // been displayed, so start letting windows get |
| 3340 | // shown immediately without any more transitions. |
| 3341 | mSkipAppTransitionAnimation = true; |
| 3342 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3343 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3344 | "Moving existing starting from " + ttoken |
| 3345 | + " to " + wtoken); |
| 3346 | final long origId = Binder.clearCallingIdentity(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3347 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3348 | // Transfer the starting window over to the new |
| 3349 | // token. |
| 3350 | wtoken.startingData = ttoken.startingData; |
| 3351 | wtoken.startingView = ttoken.startingView; |
| 3352 | wtoken.startingWindow = startingWindow; |
| 3353 | ttoken.startingData = null; |
| 3354 | ttoken.startingView = null; |
| 3355 | ttoken.startingWindow = null; |
| 3356 | ttoken.startingMoved = true; |
| 3357 | startingWindow.mToken = wtoken; |
| Dianne Hackborn | ef49c57 | 2009-03-24 19:27:32 -0700 | [diff] [blame] | 3358 | startingWindow.mRootToken = wtoken; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3359 | startingWindow.mAppToken = wtoken; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3360 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 3361 | "Removing starting window: " + startingWindow); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3362 | mWindows.remove(startingWindow); |
| 3363 | ttoken.windows.remove(startingWindow); |
| 3364 | ttoken.allAppWindows.remove(startingWindow); |
| 3365 | addWindowToListInOrderLocked(startingWindow, true); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3366 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3367 | // Propagate other interesting state between the |
| 3368 | // tokens. If the old token is displayed, we should |
| 3369 | // immediately force the new one to be displayed. If |
| 3370 | // it is animating, we need to move that animation to |
| 3371 | // the new one. |
| 3372 | if (ttoken.allDrawn) { |
| 3373 | wtoken.allDrawn = true; |
| 3374 | } |
| 3375 | if (ttoken.firstWindowDrawn) { |
| 3376 | wtoken.firstWindowDrawn = true; |
| 3377 | } |
| 3378 | if (!ttoken.hidden) { |
| 3379 | wtoken.hidden = false; |
| 3380 | wtoken.hiddenRequested = false; |
| 3381 | wtoken.willBeHidden = false; |
| 3382 | } |
| 3383 | if (wtoken.clientHidden != ttoken.clientHidden) { |
| 3384 | wtoken.clientHidden = ttoken.clientHidden; |
| 3385 | wtoken.sendAppVisibilityToClients(); |
| 3386 | } |
| 3387 | if (ttoken.animation != null) { |
| 3388 | wtoken.animation = ttoken.animation; |
| 3389 | wtoken.animating = ttoken.animating; |
| 3390 | wtoken.animLayerAdjustment = ttoken.animLayerAdjustment; |
| 3391 | ttoken.animation = null; |
| 3392 | ttoken.animLayerAdjustment = 0; |
| 3393 | wtoken.updateLayers(); |
| 3394 | ttoken.updateLayers(); |
| 3395 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3396 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3397 | updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3398 | mLayoutNeeded = true; |
| 3399 | performLayoutAndPlaceSurfacesLocked(); |
| 3400 | Binder.restoreCallingIdentity(origId); |
| 3401 | return; |
| 3402 | } else if (ttoken.startingData != null) { |
| 3403 | // The previous app was getting ready to show a |
| 3404 | // starting window, but hasn't yet done so. Steal it! |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3405 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3406 | "Moving pending starting from " + ttoken |
| 3407 | + " to " + wtoken); |
| 3408 | wtoken.startingData = ttoken.startingData; |
| 3409 | ttoken.startingData = null; |
| 3410 | ttoken.startingMoved = true; |
| 3411 | Message m = mH.obtainMessage(H.ADD_STARTING, wtoken); |
| 3412 | // Note: we really want to do sendMessageAtFrontOfQueue() because we |
| 3413 | // want to process the message ASAP, before any other queued |
| 3414 | // messages. |
| 3415 | mH.sendMessageAtFrontOfQueue(m); |
| 3416 | return; |
| 3417 | } |
| 3418 | } |
| 3419 | } |
| 3420 | |
| 3421 | // There is no existing starting window, and the caller doesn't |
| 3422 | // want us to create one, so that's it! |
| 3423 | if (!createIfNeeded) { |
| 3424 | return; |
| 3425 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3426 | |
| Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 3427 | // If this is a translucent or wallpaper window, then don't |
| 3428 | // show a starting window -- the current effect (a full-screen |
| 3429 | // opaque starting window that fades away to the real contents |
| 3430 | // when it is ready) does not work for this. |
| 3431 | if (theme != 0) { |
| 3432 | AttributeCache.Entry ent = AttributeCache.instance().get(pkg, theme, |
| 3433 | com.android.internal.R.styleable.Window); |
| 3434 | if (ent.array.getBoolean( |
| 3435 | com.android.internal.R.styleable.Window_windowIsTranslucent, false)) { |
| 3436 | return; |
| 3437 | } |
| 3438 | if (ent.array.getBoolean( |
| Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 3439 | com.android.internal.R.styleable.Window_windowIsFloating, false)) { |
| 3440 | return; |
| 3441 | } |
| 3442 | if (ent.array.getBoolean( |
| Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 3443 | com.android.internal.R.styleable.Window_windowShowWallpaper, false)) { |
| 3444 | return; |
| 3445 | } |
| 3446 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3447 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3448 | mStartingIconInTransition = true; |
| 3449 | wtoken.startingData = new StartingData( |
| 3450 | pkg, theme, nonLocalizedLabel, |
| 3451 | labelRes, icon); |
| 3452 | Message m = mH.obtainMessage(H.ADD_STARTING, wtoken); |
| 3453 | // Note: we really want to do sendMessageAtFrontOfQueue() because we |
| 3454 | // want to process the message ASAP, before any other queued |
| 3455 | // messages. |
| 3456 | mH.sendMessageAtFrontOfQueue(m); |
| 3457 | } |
| 3458 | } |
| 3459 | |
| 3460 | public void setAppWillBeHidden(IBinder token) { |
| 3461 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3462 | "setAppWillBeHidden()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3463 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3464 | } |
| 3465 | |
| 3466 | AppWindowToken wtoken; |
| 3467 | |
| 3468 | synchronized(mWindowMap) { |
| 3469 | wtoken = findAppWindowToken(token); |
| 3470 | if (wtoken == null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3471 | Slog.w(TAG, "Attempted to set will be hidden of non-existing app token: " + token); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3472 | return; |
| 3473 | } |
| 3474 | wtoken.willBeHidden = true; |
| 3475 | } |
| 3476 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3477 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3478 | boolean setTokenVisibilityLocked(AppWindowToken wtoken, WindowManager.LayoutParams lp, |
| 3479 | boolean visible, int transit, boolean performLayout) { |
| 3480 | boolean delayed = false; |
| 3481 | |
| 3482 | if (wtoken.clientHidden == visible) { |
| 3483 | wtoken.clientHidden = !visible; |
| 3484 | wtoken.sendAppVisibilityToClients(); |
| 3485 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3486 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3487 | wtoken.willBeHidden = false; |
| 3488 | if (wtoken.hidden == visible) { |
| 3489 | final int N = wtoken.allAppWindows.size(); |
| 3490 | boolean changed = false; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3491 | if (DEBUG_APP_TRANSITIONS) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3492 | TAG, "Changing app " + wtoken + " hidden=" + wtoken.hidden |
| 3493 | + " performLayout=" + performLayout); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3494 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3495 | boolean runningAppAnimation = false; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3496 | |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 3497 | if (transit != WindowManagerPolicy.TRANSIT_UNSET) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3498 | if (wtoken.animation == sDummyAnimation) { |
| 3499 | wtoken.animation = null; |
| 3500 | } |
| 3501 | applyAnimationLocked(wtoken, lp, transit, visible); |
| 3502 | changed = true; |
| 3503 | if (wtoken.animation != null) { |
| 3504 | delayed = runningAppAnimation = true; |
| 3505 | } |
| 3506 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3507 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3508 | for (int i=0; i<N; i++) { |
| 3509 | WindowState win = wtoken.allAppWindows.get(i); |
| 3510 | if (win == wtoken.startingWindow) { |
| 3511 | continue; |
| 3512 | } |
| 3513 | |
| 3514 | if (win.isAnimating()) { |
| 3515 | delayed = true; |
| 3516 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3517 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3518 | //Slog.i(TAG, "Window " + win + ": vis=" + win.isVisible()); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3519 | //win.dump(" "); |
| 3520 | if (visible) { |
| 3521 | if (!win.isVisibleNow()) { |
| 3522 | if (!runningAppAnimation) { |
| 3523 | applyAnimationLocked(win, |
| 3524 | WindowManagerPolicy.TRANSIT_ENTER, true); |
| 3525 | } |
| 3526 | changed = true; |
| 3527 | } |
| 3528 | } else if (win.isVisibleNow()) { |
| 3529 | if (!runningAppAnimation) { |
| 3530 | applyAnimationLocked(win, |
| 3531 | WindowManagerPolicy.TRANSIT_EXIT, false); |
| 3532 | } |
| Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 3533 | mInputMonitor.windowIsBecomingInvisibleLw(win); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3534 | changed = true; |
| 3535 | } |
| 3536 | } |
| 3537 | |
| 3538 | wtoken.hidden = wtoken.hiddenRequested = !visible; |
| 3539 | if (!visible) { |
| 3540 | unsetAppFreezingScreenLocked(wtoken, true, true); |
| 3541 | } else { |
| 3542 | // If we are being set visible, and the starting window is |
| 3543 | // not yet displayed, then make sure it doesn't get displayed. |
| 3544 | WindowState swin = wtoken.startingWindow; |
| 3545 | if (swin != null && (swin.mDrawPending |
| 3546 | || swin.mCommitDrawPending)) { |
| 3547 | swin.mPolicyVisibility = false; |
| 3548 | swin.mPolicyVisibilityAfterAnim = false; |
| 3549 | } |
| 3550 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3551 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3552 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "setTokenVisibilityLocked: " + wtoken |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3553 | + ": hidden=" + wtoken.hidden + " hiddenRequested=" |
| 3554 | + wtoken.hiddenRequested); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3555 | |
| Dianne Hackborn | 9b52a21 | 2009-12-11 14:51:35 -0800 | [diff] [blame] | 3556 | if (changed) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3557 | mLayoutNeeded = true; |
| Dianne Hackborn | 9b52a21 | 2009-12-11 14:51:35 -0800 | [diff] [blame] | 3558 | if (performLayout) { |
| 3559 | updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES); |
| 3560 | performLayoutAndPlaceSurfacesLocked(); |
| 3561 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3562 | } |
| 3563 | } |
| 3564 | |
| 3565 | if (wtoken.animation != null) { |
| 3566 | delayed = true; |
| 3567 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3568 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3569 | return delayed; |
| 3570 | } |
| 3571 | |
| 3572 | public void setAppVisibility(IBinder token, boolean visible) { |
| 3573 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3574 | "setAppVisibility()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3575 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3576 | } |
| 3577 | |
| 3578 | AppWindowToken wtoken; |
| 3579 | |
| 3580 | synchronized(mWindowMap) { |
| 3581 | wtoken = findAppWindowToken(token); |
| 3582 | if (wtoken == null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3583 | Slog.w(TAG, "Attempted to set visibility of non-existing app token: " + token); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3584 | return; |
| 3585 | } |
| 3586 | |
| 3587 | if (DEBUG_APP_TRANSITIONS || DEBUG_ORIENTATION) { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 3588 | RuntimeException e = null; |
| 3589 | if (!HIDE_STACK_CRAWLS) { |
| 3590 | e = new RuntimeException(); |
| 3591 | e.fillInStackTrace(); |
| 3592 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3593 | Slog.v(TAG, "setAppVisibility(" + token + ", " + visible |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3594 | + "): mNextAppTransition=" + mNextAppTransition |
| 3595 | + " hidden=" + wtoken.hidden |
| 3596 | + " hiddenRequested=" + wtoken.hiddenRequested, e); |
| 3597 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3598 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3599 | // If we are preparing an app transition, then delay changing |
| 3600 | // the visibility of this token until we execute that transition. |
| Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 3601 | if (!mDisplayFrozen && mPolicy.isScreenOn() |
| 3602 | && mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3603 | // Already in requested state, don't do anything more. |
| 3604 | if (wtoken.hiddenRequested != visible) { |
| 3605 | return; |
| 3606 | } |
| 3607 | wtoken.hiddenRequested = !visible; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3608 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3609 | if (DEBUG_APP_TRANSITIONS) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3610 | TAG, "Setting dummy animation on: " + wtoken); |
| 3611 | wtoken.setDummyAnimation(); |
| 3612 | mOpeningApps.remove(wtoken); |
| 3613 | mClosingApps.remove(wtoken); |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 3614 | wtoken.waitingToShow = wtoken.waitingToHide = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3615 | wtoken.inPendingTransaction = true; |
| 3616 | if (visible) { |
| 3617 | mOpeningApps.add(wtoken); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3618 | wtoken.startingDisplayed = false; |
| 3619 | wtoken.startingMoved = false; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3620 | |
| Dianne Hackborn | 195f6a0 | 2009-11-24 11:26:00 -0800 | [diff] [blame] | 3621 | // If the token is currently hidden (should be the |
| 3622 | // common case), then we need to set up to wait for |
| 3623 | // its windows to be ready. |
| 3624 | if (wtoken.hidden) { |
| 3625 | wtoken.allDrawn = false; |
| 3626 | wtoken.waitingToShow = true; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3627 | |
| Dianne Hackborn | 195f6a0 | 2009-11-24 11:26:00 -0800 | [diff] [blame] | 3628 | if (wtoken.clientHidden) { |
| 3629 | // In the case where we are making an app visible |
| 3630 | // but holding off for a transition, we still need |
| 3631 | // to tell the client to make its windows visible so |
| 3632 | // they get drawn. Otherwise, we will wait on |
| 3633 | // performing the transition until all windows have |
| 3634 | // been drawn, they never will be, and we are sad. |
| 3635 | wtoken.clientHidden = false; |
| 3636 | wtoken.sendAppVisibilityToClients(); |
| 3637 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3638 | } |
| 3639 | } else { |
| 3640 | mClosingApps.add(wtoken); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3641 | |
| Dianne Hackborn | 195f6a0 | 2009-11-24 11:26:00 -0800 | [diff] [blame] | 3642 | // If the token is currently visible (should be the |
| 3643 | // common case), then set up to wait for it to be hidden. |
| 3644 | if (!wtoken.hidden) { |
| 3645 | wtoken.waitingToHide = true; |
| 3646 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3647 | } |
| 3648 | return; |
| 3649 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3650 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3651 | final long origId = Binder.clearCallingIdentity(); |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 3652 | setTokenVisibilityLocked(wtoken, null, visible, WindowManagerPolicy.TRANSIT_UNSET, true); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3653 | wtoken.updateReportedVisibilityLocked(); |
| 3654 | Binder.restoreCallingIdentity(origId); |
| 3655 | } |
| 3656 | } |
| 3657 | |
| 3658 | void unsetAppFreezingScreenLocked(AppWindowToken wtoken, |
| 3659 | boolean unfreezeSurfaceNow, boolean force) { |
| 3660 | if (wtoken.freezingScreen) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3661 | if (DEBUG_ORIENTATION) Slog.v(TAG, "Clear freezing of " + wtoken |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3662 | + " force=" + force); |
| 3663 | final int N = wtoken.allAppWindows.size(); |
| 3664 | boolean unfrozeWindows = false; |
| 3665 | for (int i=0; i<N; i++) { |
| 3666 | WindowState w = wtoken.allAppWindows.get(i); |
| 3667 | if (w.mAppFreezing) { |
| 3668 | w.mAppFreezing = false; |
| 3669 | if (w.mSurface != null && !w.mOrientationChanging) { |
| 3670 | w.mOrientationChanging = true; |
| 3671 | } |
| 3672 | unfrozeWindows = true; |
| 3673 | } |
| 3674 | } |
| 3675 | if (force || unfrozeWindows) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3676 | if (DEBUG_ORIENTATION) Slog.v(TAG, "No longer freezing: " + wtoken); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3677 | wtoken.freezingScreen = false; |
| 3678 | mAppsFreezingScreen--; |
| 3679 | } |
| 3680 | if (unfreezeSurfaceNow) { |
| 3681 | if (unfrozeWindows) { |
| 3682 | mLayoutNeeded = true; |
| 3683 | performLayoutAndPlaceSurfacesLocked(); |
| 3684 | } |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3685 | stopFreezingDisplayLocked(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3686 | } |
| 3687 | } |
| 3688 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3689 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3690 | public void startAppFreezingScreenLocked(AppWindowToken wtoken, |
| 3691 | int configChanges) { |
| 3692 | if (DEBUG_ORIENTATION) { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 3693 | RuntimeException e = null; |
| 3694 | if (!HIDE_STACK_CRAWLS) { |
| 3695 | e = new RuntimeException(); |
| 3696 | e.fillInStackTrace(); |
| 3697 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3698 | Slog.i(TAG, "Set freezing of " + wtoken.appToken |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3699 | + ": hidden=" + wtoken.hidden + " freezing=" |
| 3700 | + wtoken.freezingScreen, e); |
| 3701 | } |
| 3702 | if (!wtoken.hiddenRequested) { |
| 3703 | if (!wtoken.freezingScreen) { |
| 3704 | wtoken.freezingScreen = true; |
| 3705 | mAppsFreezingScreen++; |
| 3706 | if (mAppsFreezingScreen == 1) { |
| 3707 | startFreezingDisplayLocked(); |
| 3708 | mH.removeMessages(H.APP_FREEZE_TIMEOUT); |
| 3709 | mH.sendMessageDelayed(mH.obtainMessage(H.APP_FREEZE_TIMEOUT), |
| 3710 | 5000); |
| 3711 | } |
| 3712 | } |
| 3713 | final int N = wtoken.allAppWindows.size(); |
| 3714 | for (int i=0; i<N; i++) { |
| 3715 | WindowState w = wtoken.allAppWindows.get(i); |
| 3716 | w.mAppFreezing = true; |
| 3717 | } |
| 3718 | } |
| 3719 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3720 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3721 | public void startAppFreezingScreen(IBinder token, int configChanges) { |
| 3722 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3723 | "setAppFreezingScreen()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3724 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3725 | } |
| 3726 | |
| 3727 | synchronized(mWindowMap) { |
| Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 3728 | if (configChanges == 0 && !mDisplayFrozen && mPolicy.isScreenOn()) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3729 | if (DEBUG_ORIENTATION) Slog.v(TAG, "Skipping set freeze of " + token); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3730 | return; |
| 3731 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3732 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3733 | AppWindowToken wtoken = findAppWindowToken(token); |
| 3734 | if (wtoken == null || wtoken.appToken == null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3735 | Slog.w(TAG, "Attempted to freeze screen with non-existing app token: " + wtoken); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3736 | return; |
| 3737 | } |
| 3738 | final long origId = Binder.clearCallingIdentity(); |
| 3739 | startAppFreezingScreenLocked(wtoken, configChanges); |
| 3740 | Binder.restoreCallingIdentity(origId); |
| 3741 | } |
| 3742 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3743 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3744 | public void stopAppFreezingScreen(IBinder token, boolean force) { |
| 3745 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3746 | "setAppFreezingScreen()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3747 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3748 | } |
| 3749 | |
| 3750 | synchronized(mWindowMap) { |
| 3751 | AppWindowToken wtoken = findAppWindowToken(token); |
| 3752 | if (wtoken == null || wtoken.appToken == null) { |
| 3753 | return; |
| 3754 | } |
| 3755 | final long origId = Binder.clearCallingIdentity(); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3756 | if (DEBUG_ORIENTATION) Slog.v(TAG, "Clear freezing of " + token |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3757 | + ": hidden=" + wtoken.hidden + " freezing=" + wtoken.freezingScreen); |
| 3758 | unsetAppFreezingScreenLocked(wtoken, true, force); |
| 3759 | Binder.restoreCallingIdentity(origId); |
| 3760 | } |
| 3761 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3762 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3763 | public void removeAppToken(IBinder token) { |
| 3764 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3765 | "removeAppToken()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3766 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3767 | } |
| 3768 | |
| 3769 | AppWindowToken wtoken = null; |
| 3770 | AppWindowToken startingToken = null; |
| 3771 | boolean delayed = false; |
| 3772 | |
| 3773 | final long origId = Binder.clearCallingIdentity(); |
| 3774 | synchronized(mWindowMap) { |
| 3775 | WindowToken basewtoken = mTokenMap.remove(token); |
| 3776 | mTokenList.remove(basewtoken); |
| 3777 | if (basewtoken != null && (wtoken=basewtoken.appWindowToken) != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3778 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "Removing app token: " + wtoken); |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 3779 | delayed = setTokenVisibilityLocked(wtoken, null, false, WindowManagerPolicy.TRANSIT_UNSET, true); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3780 | wtoken.inPendingTransaction = false; |
| 3781 | mOpeningApps.remove(wtoken); |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 3782 | wtoken.waitingToShow = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3783 | if (mClosingApps.contains(wtoken)) { |
| 3784 | delayed = true; |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 3785 | } else if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3786 | mClosingApps.add(wtoken); |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 3787 | wtoken.waitingToHide = true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3788 | delayed = true; |
| 3789 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3790 | if (DEBUG_APP_TRANSITIONS) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3791 | TAG, "Removing app " + wtoken + " delayed=" + delayed |
| 3792 | + " animation=" + wtoken.animation |
| 3793 | + " animating=" + wtoken.animating); |
| 3794 | if (delayed) { |
| 3795 | // set the token aside because it has an active animation to be finished |
| 3796 | mExitingAppTokens.add(wtoken); |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 3797 | } else { |
| 3798 | // Make sure there is no animation running on this token, |
| 3799 | // so any windows associated with it will be removed as |
| 3800 | // soon as their animations are complete |
| 3801 | wtoken.animation = null; |
| 3802 | wtoken.animating = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3803 | } |
| 3804 | mAppTokens.remove(wtoken); |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 3805 | if (mLastEnterAnimToken == wtoken) { |
| 3806 | mLastEnterAnimToken = null; |
| 3807 | mLastEnterAnimParams = null; |
| 3808 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3809 | wtoken.removed = true; |
| 3810 | if (wtoken.startingData != null) { |
| 3811 | startingToken = wtoken; |
| 3812 | } |
| 3813 | unsetAppFreezingScreenLocked(wtoken, true, true); |
| 3814 | if (mFocusedApp == wtoken) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3815 | if (DEBUG_FOCUS) Slog.v(TAG, "Removing focused app token:" + wtoken); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3816 | mFocusedApp = null; |
| 3817 | updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL); |
| Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 3818 | mInputMonitor.setFocusedAppLw(null); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3819 | } |
| 3820 | } else { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3821 | Slog.w(TAG, "Attempted to remove non-existing app token: " + token); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3822 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3823 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3824 | if (!delayed && wtoken != null) { |
| 3825 | wtoken.updateReportedVisibilityLocked(); |
| 3826 | } |
| 3827 | } |
| 3828 | Binder.restoreCallingIdentity(origId); |
| 3829 | |
| 3830 | if (startingToken != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3831 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Schedule remove starting " |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3832 | + startingToken + ": app token removed"); |
| 3833 | Message m = mH.obtainMessage(H.REMOVE_STARTING, startingToken); |
| 3834 | mH.sendMessage(m); |
| 3835 | } |
| 3836 | } |
| 3837 | |
| 3838 | private boolean tmpRemoveAppWindowsLocked(WindowToken token) { |
| 3839 | final int NW = token.windows.size(); |
| 3840 | for (int i=0; i<NW; i++) { |
| 3841 | WindowState win = token.windows.get(i); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3842 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Tmp removing app window " + win); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3843 | mWindows.remove(win); |
| 3844 | int j = win.mChildWindows.size(); |
| 3845 | while (j > 0) { |
| 3846 | j--; |
| Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 3847 | WindowState cwin = (WindowState)win.mChildWindows.get(j); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3848 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, |
| Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 3849 | "Tmp removing child window " + cwin); |
| 3850 | mWindows.remove(cwin); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3851 | } |
| 3852 | } |
| 3853 | return NW > 0; |
| 3854 | } |
| 3855 | |
| 3856 | void dumpAppTokensLocked() { |
| 3857 | for (int i=mAppTokens.size()-1; i>=0; i--) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3858 | Slog.v(TAG, " #" + i + ": " + mAppTokens.get(i).token); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3859 | } |
| 3860 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3861 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3862 | void dumpWindowsLocked() { |
| 3863 | for (int i=mWindows.size()-1; i>=0; i--) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3864 | Slog.v(TAG, " #" + i + ": " + mWindows.get(i)); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3865 | } |
| 3866 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3867 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3868 | private int findWindowOffsetLocked(int tokenPos) { |
| 3869 | final int NW = mWindows.size(); |
| 3870 | |
| 3871 | if (tokenPos >= mAppTokens.size()) { |
| 3872 | int i = NW; |
| 3873 | while (i > 0) { |
| 3874 | i--; |
| 3875 | WindowState win = (WindowState)mWindows.get(i); |
| 3876 | if (win.getAppToken() != null) { |
| 3877 | return i+1; |
| 3878 | } |
| 3879 | } |
| 3880 | } |
| 3881 | |
| 3882 | while (tokenPos > 0) { |
| 3883 | // Find the first app token below the new position that has |
| 3884 | // a window displayed. |
| 3885 | final AppWindowToken wtoken = mAppTokens.get(tokenPos-1); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3886 | if (DEBUG_REORDER) Slog.v(TAG, "Looking for lower windows @ " |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3887 | + tokenPos + " -- " + wtoken.token); |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 3888 | if (wtoken.sendingToBottom) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3889 | if (DEBUG_REORDER) Slog.v(TAG, |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 3890 | "Skipping token -- currently sending to bottom"); |
| 3891 | tokenPos--; |
| 3892 | continue; |
| 3893 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3894 | int i = wtoken.windows.size(); |
| 3895 | while (i > 0) { |
| 3896 | i--; |
| 3897 | WindowState win = wtoken.windows.get(i); |
| 3898 | int j = win.mChildWindows.size(); |
| 3899 | while (j > 0) { |
| 3900 | j--; |
| 3901 | WindowState cwin = (WindowState)win.mChildWindows.get(j); |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 3902 | if (cwin.mSubLayer >= 0) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3903 | for (int pos=NW-1; pos>=0; pos--) { |
| 3904 | if (mWindows.get(pos) == cwin) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3905 | if (DEBUG_REORDER) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3906 | "Found child win @" + (pos+1)); |
| 3907 | return pos+1; |
| 3908 | } |
| 3909 | } |
| 3910 | } |
| 3911 | } |
| 3912 | for (int pos=NW-1; pos>=0; pos--) { |
| 3913 | if (mWindows.get(pos) == win) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3914 | if (DEBUG_REORDER) Slog.v(TAG, "Found win @" + (pos+1)); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3915 | return pos+1; |
| 3916 | } |
| 3917 | } |
| 3918 | } |
| 3919 | tokenPos--; |
| 3920 | } |
| 3921 | |
| 3922 | return 0; |
| 3923 | } |
| 3924 | |
| 3925 | private final int reAddWindowLocked(int index, WindowState win) { |
| 3926 | final int NCW = win.mChildWindows.size(); |
| 3927 | boolean added = false; |
| 3928 | for (int j=0; j<NCW; j++) { |
| 3929 | WindowState cwin = (WindowState)win.mChildWindows.get(j); |
| 3930 | if (!added && cwin.mSubLayer >= 0) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3931 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding child window at " |
| Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 3932 | + index + ": " + cwin); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3933 | mWindows.add(index, win); |
| 3934 | index++; |
| 3935 | added = true; |
| 3936 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3937 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding window at " |
| Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 3938 | + index + ": " + cwin); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3939 | mWindows.add(index, cwin); |
| 3940 | index++; |
| 3941 | } |
| 3942 | if (!added) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3943 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding window at " |
| Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 3944 | + index + ": " + win); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3945 | mWindows.add(index, win); |
| 3946 | index++; |
| 3947 | } |
| 3948 | return index; |
| 3949 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3950 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3951 | private final int reAddAppWindowsLocked(int index, WindowToken token) { |
| 3952 | final int NW = token.windows.size(); |
| 3953 | for (int i=0; i<NW; i++) { |
| 3954 | index = reAddWindowLocked(index, token.windows.get(i)); |
| 3955 | } |
| 3956 | return index; |
| 3957 | } |
| 3958 | |
| 3959 | public void moveAppToken(int index, IBinder token) { |
| 3960 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3961 | "moveAppToken()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3962 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3963 | } |
| 3964 | |
| 3965 | synchronized(mWindowMap) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3966 | if (DEBUG_REORDER) Slog.v(TAG, "Initial app tokens:"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3967 | if (DEBUG_REORDER) dumpAppTokensLocked(); |
| 3968 | final AppWindowToken wtoken = findAppWindowToken(token); |
| 3969 | if (wtoken == null || !mAppTokens.remove(wtoken)) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3970 | Slog.w(TAG, "Attempting to reorder token that doesn't exist: " |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3971 | + token + " (" + wtoken + ")"); |
| 3972 | return; |
| 3973 | } |
| 3974 | mAppTokens.add(index, wtoken); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3975 | if (DEBUG_REORDER) Slog.v(TAG, "Moved " + token + " to " + index + ":"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3976 | if (DEBUG_REORDER) dumpAppTokensLocked(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3977 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3978 | final long origId = Binder.clearCallingIdentity(); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3979 | if (DEBUG_REORDER) Slog.v(TAG, "Removing windows in " + token + ":"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3980 | if (DEBUG_REORDER) dumpWindowsLocked(); |
| 3981 | if (tmpRemoveAppWindowsLocked(wtoken)) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3982 | if (DEBUG_REORDER) Slog.v(TAG, "Adding windows back in:"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3983 | if (DEBUG_REORDER) dumpWindowsLocked(); |
| 3984 | reAddAppWindowsLocked(findWindowOffsetLocked(index), wtoken); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3985 | if (DEBUG_REORDER) Slog.v(TAG, "Final window list:"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3986 | if (DEBUG_REORDER) dumpWindowsLocked(); |
| 3987 | updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3988 | mLayoutNeeded = true; |
| 3989 | performLayoutAndPlaceSurfacesLocked(); |
| 3990 | } |
| 3991 | Binder.restoreCallingIdentity(origId); |
| 3992 | } |
| 3993 | } |
| 3994 | |
| 3995 | private void removeAppTokensLocked(List<IBinder> tokens) { |
| 3996 | // XXX This should be done more efficiently! |
| 3997 | // (take advantage of the fact that both lists should be |
| 3998 | // ordered in the same way.) |
| 3999 | int N = tokens.size(); |
| 4000 | for (int i=0; i<N; i++) { |
| 4001 | IBinder token = tokens.get(i); |
| 4002 | final AppWindowToken wtoken = findAppWindowToken(token); |
| 4003 | if (!mAppTokens.remove(wtoken)) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4004 | Slog.w(TAG, "Attempting to reorder token that doesn't exist: " |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4005 | + token + " (" + wtoken + ")"); |
| 4006 | i--; |
| 4007 | N--; |
| 4008 | } |
| 4009 | } |
| 4010 | } |
| 4011 | |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4012 | private void moveAppWindowsLocked(AppWindowToken wtoken, int tokenPos, |
| 4013 | boolean updateFocusAndLayout) { |
| 4014 | // First remove all of the windows from the list. |
| 4015 | tmpRemoveAppWindowsLocked(wtoken); |
| 4016 | |
| 4017 | // Where to start adding? |
| 4018 | int pos = findWindowOffsetLocked(tokenPos); |
| 4019 | |
| 4020 | // And now add them back at the correct place. |
| 4021 | pos = reAddAppWindowsLocked(pos, wtoken); |
| 4022 | |
| 4023 | if (updateFocusAndLayout) { |
| 4024 | if (!updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES)) { |
| 4025 | assignLayersLocked(); |
| 4026 | } |
| 4027 | mLayoutNeeded = true; |
| 4028 | performLayoutAndPlaceSurfacesLocked(); |
| 4029 | } |
| 4030 | } |
| 4031 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4032 | private void moveAppWindowsLocked(List<IBinder> tokens, int tokenPos) { |
| 4033 | // First remove all of the windows from the list. |
| 4034 | final int N = tokens.size(); |
| 4035 | int i; |
| 4036 | for (i=0; i<N; i++) { |
| 4037 | WindowToken token = mTokenMap.get(tokens.get(i)); |
| 4038 | if (token != null) { |
| 4039 | tmpRemoveAppWindowsLocked(token); |
| 4040 | } |
| 4041 | } |
| 4042 | |
| 4043 | // Where to start adding? |
| 4044 | int pos = findWindowOffsetLocked(tokenPos); |
| 4045 | |
| 4046 | // And now add them back at the correct place. |
| 4047 | for (i=0; i<N; i++) { |
| 4048 | WindowToken token = mTokenMap.get(tokens.get(i)); |
| 4049 | if (token != null) { |
| 4050 | pos = reAddAppWindowsLocked(pos, token); |
| 4051 | } |
| 4052 | } |
| 4053 | |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4054 | if (!updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES)) { |
| 4055 | assignLayersLocked(); |
| 4056 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4057 | mLayoutNeeded = true; |
| 4058 | performLayoutAndPlaceSurfacesLocked(); |
| 4059 | |
| 4060 | //dump(); |
| 4061 | } |
| 4062 | |
| 4063 | public void moveAppTokensToTop(List<IBinder> tokens) { |
| 4064 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 4065 | "moveAppTokensToTop()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4066 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4067 | } |
| 4068 | |
| 4069 | final long origId = Binder.clearCallingIdentity(); |
| 4070 | synchronized(mWindowMap) { |
| 4071 | removeAppTokensLocked(tokens); |
| 4072 | final int N = tokens.size(); |
| 4073 | for (int i=0; i<N; i++) { |
| 4074 | AppWindowToken wt = findAppWindowToken(tokens.get(i)); |
| 4075 | if (wt != null) { |
| 4076 | mAppTokens.add(wt); |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 4077 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4078 | mToTopApps.remove(wt); |
| 4079 | mToBottomApps.remove(wt); |
| 4080 | mToTopApps.add(wt); |
| 4081 | wt.sendingToBottom = false; |
| 4082 | wt.sendingToTop = true; |
| 4083 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4084 | } |
| 4085 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 4086 | |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 4087 | if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET) { |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4088 | moveAppWindowsLocked(tokens, mAppTokens.size()); |
| 4089 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4090 | } |
| 4091 | Binder.restoreCallingIdentity(origId); |
| 4092 | } |
| 4093 | |
| 4094 | public void moveAppTokensToBottom(List<IBinder> tokens) { |
| 4095 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 4096 | "moveAppTokensToBottom()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4097 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4098 | } |
| 4099 | |
| 4100 | final long origId = Binder.clearCallingIdentity(); |
| 4101 | synchronized(mWindowMap) { |
| 4102 | removeAppTokensLocked(tokens); |
| 4103 | final int N = tokens.size(); |
| 4104 | int pos = 0; |
| 4105 | for (int i=0; i<N; i++) { |
| 4106 | AppWindowToken wt = findAppWindowToken(tokens.get(i)); |
| 4107 | if (wt != null) { |
| 4108 | mAppTokens.add(pos, wt); |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 4109 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4110 | mToTopApps.remove(wt); |
| 4111 | mToBottomApps.remove(wt); |
| 4112 | mToBottomApps.add(i, wt); |
| 4113 | wt.sendingToTop = false; |
| 4114 | wt.sendingToBottom = true; |
| 4115 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4116 | pos++; |
| 4117 | } |
| 4118 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 4119 | |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 4120 | if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET) { |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4121 | moveAppWindowsLocked(tokens, 0); |
| 4122 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4123 | } |
| 4124 | Binder.restoreCallingIdentity(origId); |
| 4125 | } |
| 4126 | |
| 4127 | // ------------------------------------------------------------- |
| 4128 | // Misc IWindowSession methods |
| 4129 | // ------------------------------------------------------------- |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4130 | |
| Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 4131 | private boolean shouldAllowDisableKeyguard() |
| Jim Miller | d6b5705 | 2010-06-07 17:52:42 -0700 | [diff] [blame] | 4132 | { |
| Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 4133 | // We fail safe and prevent disabling keyguard in the unlikely event this gets |
| 4134 | // called before DevicePolicyManagerService has started. |
| 4135 | if (mAllowDisableKeyguard == ALLOW_DISABLE_UNKNOWN) { |
| 4136 | DevicePolicyManager dpm = (DevicePolicyManager) mContext.getSystemService( |
| 4137 | Context.DEVICE_POLICY_SERVICE); |
| 4138 | if (dpm != null) { |
| 4139 | mAllowDisableKeyguard = dpm.getPasswordQuality(null) |
| 4140 | == DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED ? |
| 4141 | ALLOW_DISABLE_YES : ALLOW_DISABLE_NO; |
| 4142 | } |
| Jim Miller | d6b5705 | 2010-06-07 17:52:42 -0700 | [diff] [blame] | 4143 | } |
| Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 4144 | return mAllowDisableKeyguard == ALLOW_DISABLE_YES; |
| Jim Miller | d6b5705 | 2010-06-07 17:52:42 -0700 | [diff] [blame] | 4145 | } |
| 4146 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4147 | public void disableKeyguard(IBinder token, String tag) { |
| Mike Lockwood | 733fdf3 | 2009-09-28 19:08:53 -0400 | [diff] [blame] | 4148 | if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD) |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4149 | != PackageManager.PERMISSION_GRANTED) { |
| 4150 | throw new SecurityException("Requires DISABLE_KEYGUARD permission"); |
| 4151 | } |
| Jim Miller | d6b5705 | 2010-06-07 17:52:42 -0700 | [diff] [blame] | 4152 | |
| Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 4153 | synchronized (mKeyguardTokenWatcher) { |
| 4154 | mKeyguardTokenWatcher.acquire(token, tag); |
| Mike Lockwood | dd88468 | 2009-10-11 16:57:08 -0400 | [diff] [blame] | 4155 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4156 | } |
| 4157 | |
| 4158 | public void reenableKeyguard(IBinder token) { |
| Mike Lockwood | 733fdf3 | 2009-09-28 19:08:53 -0400 | [diff] [blame] | 4159 | if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD) |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4160 | != PackageManager.PERMISSION_GRANTED) { |
| 4161 | throw new SecurityException("Requires DISABLE_KEYGUARD permission"); |
| 4162 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4163 | |
| Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 4164 | synchronized (mKeyguardTokenWatcher) { |
| 4165 | mKeyguardTokenWatcher.release(token); |
| Jim Miller | d6b5705 | 2010-06-07 17:52:42 -0700 | [diff] [blame] | 4166 | |
| Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 4167 | if (!mKeyguardTokenWatcher.isAcquired()) { |
| 4168 | // If we are the last one to reenable the keyguard wait until |
| 4169 | // we have actually finished reenabling until returning. |
| 4170 | // It is possible that reenableKeyguard() can be called before |
| 4171 | // the previous disableKeyguard() is handled, in which case |
| 4172 | // neither mKeyguardTokenWatcher.acquired() or released() would |
| 4173 | // be called. In that case mKeyguardDisabled will be false here |
| 4174 | // and we have nothing to wait for. |
| 4175 | while (mKeyguardDisabled) { |
| 4176 | try { |
| 4177 | mKeyguardTokenWatcher.wait(); |
| 4178 | } catch (InterruptedException e) { |
| 4179 | Thread.currentThread().interrupt(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4180 | } |
| 4181 | } |
| 4182 | } |
| 4183 | } |
| 4184 | } |
| 4185 | |
| 4186 | /** |
| 4187 | * @see android.app.KeyguardManager#exitKeyguardSecurely |
| 4188 | */ |
| 4189 | public void exitKeyguardSecurely(final IOnKeyguardExitResult callback) { |
| Mike Lockwood | 733fdf3 | 2009-09-28 19:08:53 -0400 | [diff] [blame] | 4190 | if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD) |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4191 | != PackageManager.PERMISSION_GRANTED) { |
| 4192 | throw new SecurityException("Requires DISABLE_KEYGUARD permission"); |
| 4193 | } |
| 4194 | mPolicy.exitKeyguardSecurely(new WindowManagerPolicy.OnKeyguardExitResult() { |
| 4195 | public void onKeyguardExitResult(boolean success) { |
| 4196 | try { |
| 4197 | callback.onKeyguardExitResult(success); |
| 4198 | } catch (RemoteException e) { |
| 4199 | // Client has died, we don't care. |
| 4200 | } |
| 4201 | } |
| 4202 | }); |
| 4203 | } |
| 4204 | |
| 4205 | public boolean inKeyguardRestrictedInputMode() { |
| 4206 | return mPolicy.inKeyguardRestrictedKeyInputMode(); |
| 4207 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4208 | |
| Dianne Hackborn | ffa4248 | 2009-09-23 22:20:11 -0700 | [diff] [blame] | 4209 | public void closeSystemDialogs(String reason) { |
| 4210 | synchronized(mWindowMap) { |
| 4211 | for (int i=mWindows.size()-1; i>=0; i--) { |
| 4212 | WindowState w = (WindowState)mWindows.get(i); |
| 4213 | if (w.mSurface != null) { |
| 4214 | try { |
| 4215 | w.mClient.closeSystemDialogs(reason); |
| 4216 | } catch (RemoteException e) { |
| 4217 | } |
| 4218 | } |
| 4219 | } |
| 4220 | } |
| 4221 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 4222 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4223 | static float fixScale(float scale) { |
| 4224 | if (scale < 0) scale = 0; |
| 4225 | else if (scale > 20) scale = 20; |
| 4226 | return Math.abs(scale); |
| 4227 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4228 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4229 | public void setAnimationScale(int which, float scale) { |
| 4230 | if (!checkCallingPermission(android.Manifest.permission.SET_ANIMATION_SCALE, |
| 4231 | "setAnimationScale()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4232 | throw new SecurityException("Requires SET_ANIMATION_SCALE permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4233 | } |
| 4234 | |
| 4235 | if (scale < 0) scale = 0; |
| 4236 | else if (scale > 20) scale = 20; |
| 4237 | scale = Math.abs(scale); |
| 4238 | switch (which) { |
| 4239 | case 0: mWindowAnimationScale = fixScale(scale); break; |
| 4240 | case 1: mTransitionAnimationScale = fixScale(scale); break; |
| 4241 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4242 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4243 | // Persist setting |
| 4244 | mH.obtainMessage(H.PERSIST_ANIMATION_SCALE).sendToTarget(); |
| 4245 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4246 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4247 | public void setAnimationScales(float[] scales) { |
| 4248 | if (!checkCallingPermission(android.Manifest.permission.SET_ANIMATION_SCALE, |
| 4249 | "setAnimationScale()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4250 | throw new SecurityException("Requires SET_ANIMATION_SCALE permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4251 | } |
| 4252 | |
| 4253 | if (scales != null) { |
| 4254 | if (scales.length >= 1) { |
| 4255 | mWindowAnimationScale = fixScale(scales[0]); |
| 4256 | } |
| 4257 | if (scales.length >= 2) { |
| 4258 | mTransitionAnimationScale = fixScale(scales[1]); |
| 4259 | } |
| 4260 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4261 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4262 | // Persist setting |
| 4263 | mH.obtainMessage(H.PERSIST_ANIMATION_SCALE).sendToTarget(); |
| 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 | public float getAnimationScale(int which) { |
| 4267 | switch (which) { |
| 4268 | case 0: return mWindowAnimationScale; |
| 4269 | case 1: return mTransitionAnimationScale; |
| 4270 | } |
| 4271 | return 0; |
| 4272 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4273 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4274 | public float[] getAnimationScales() { |
| 4275 | return new float[] { mWindowAnimationScale, mTransitionAnimationScale }; |
| 4276 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4277 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4278 | public int getSwitchState(int sw) { |
| 4279 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4280 | "getSwitchState()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4281 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4282 | } |
| Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 4283 | return mInputManager.getSwitchState(sw); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4284 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4285 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4286 | public int getSwitchStateForDevice(int devid, int sw) { |
| 4287 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4288 | "getSwitchStateForDevice()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4289 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4290 | } |
| Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 4291 | return mInputManager.getSwitchState(devid, sw); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4292 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4293 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4294 | public int getScancodeState(int sw) { |
| 4295 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4296 | "getScancodeState()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4297 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4298 | } |
| Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 4299 | return mInputManager.getScancodeState(sw); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4300 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4301 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4302 | public int getScancodeStateForDevice(int devid, int sw) { |
| 4303 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4304 | "getScancodeStateForDevice()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4305 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4306 | } |
| Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 4307 | return mInputManager.getScancodeState(devid, sw); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4308 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4309 | |
| Dianne Hackborn | 1d62ea9 | 2009-11-17 12:49:50 -0800 | [diff] [blame] | 4310 | public int getTrackballScancodeState(int sw) { |
| 4311 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4312 | "getTrackballScancodeState()")) { |
| 4313 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
| 4314 | } |
| Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 4315 | return mInputManager.getTrackballScancodeState(sw); |
| Dianne Hackborn | 1d62ea9 | 2009-11-17 12:49:50 -0800 | [diff] [blame] | 4316 | } |
| 4317 | |
| 4318 | public int getDPadScancodeState(int sw) { |
| 4319 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4320 | "getDPadScancodeState()")) { |
| 4321 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
| 4322 | } |
| Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 4323 | return mInputManager.getDPadScancodeState(sw); |
| Dianne Hackborn | 1d62ea9 | 2009-11-17 12:49:50 -0800 | [diff] [blame] | 4324 | } |
| 4325 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4326 | public int getKeycodeState(int sw) { |
| 4327 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4328 | "getKeycodeState()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4329 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4330 | } |
| Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 4331 | return mInputManager.getKeycodeState(sw); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4332 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4333 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4334 | public int getKeycodeStateForDevice(int devid, int sw) { |
| 4335 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4336 | "getKeycodeStateForDevice()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4337 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4338 | } |
| Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 4339 | return mInputManager.getKeycodeState(devid, sw); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4340 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4341 | |
| Dianne Hackborn | 1d62ea9 | 2009-11-17 12:49:50 -0800 | [diff] [blame] | 4342 | public int getTrackballKeycodeState(int sw) { |
| 4343 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4344 | "getTrackballKeycodeState()")) { |
| 4345 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
| 4346 | } |
| Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 4347 | return mInputManager.getTrackballKeycodeState(sw); |
| Dianne Hackborn | 1d62ea9 | 2009-11-17 12:49:50 -0800 | [diff] [blame] | 4348 | } |
| 4349 | |
| 4350 | public int getDPadKeycodeState(int sw) { |
| 4351 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4352 | "getDPadKeycodeState()")) { |
| 4353 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
| 4354 | } |
| Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 4355 | return mInputManager.getDPadKeycodeState(sw); |
| Dianne Hackborn | 1d62ea9 | 2009-11-17 12:49:50 -0800 | [diff] [blame] | 4356 | } |
| 4357 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4358 | public boolean hasKeys(int[] keycodes, boolean[] keyExists) { |
| Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 4359 | return mInputManager.hasKeys(keycodes, keyExists); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4360 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4361 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4362 | public void enableScreenAfterBoot() { |
| 4363 | synchronized(mWindowMap) { |
| 4364 | if (mSystemBooted) { |
| 4365 | return; |
| 4366 | } |
| 4367 | mSystemBooted = true; |
| 4368 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4369 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4370 | performEnableScreen(); |
| 4371 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4372 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4373 | public void enableScreenIfNeededLocked() { |
| 4374 | if (mDisplayEnabled) { |
| 4375 | return; |
| 4376 | } |
| 4377 | if (!mSystemBooted) { |
| 4378 | return; |
| 4379 | } |
| 4380 | mH.sendMessage(mH.obtainMessage(H.ENABLE_SCREEN)); |
| 4381 | } |
| 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 | public void performEnableScreen() { |
| 4384 | synchronized(mWindowMap) { |
| 4385 | if (mDisplayEnabled) { |
| 4386 | return; |
| 4387 | } |
| 4388 | if (!mSystemBooted) { |
| 4389 | return; |
| 4390 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4391 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4392 | // Don't enable the screen until all existing windows |
| 4393 | // have been drawn. |
| 4394 | final int N = mWindows.size(); |
| 4395 | for (int i=0; i<N; i++) { |
| 4396 | WindowState w = (WindowState)mWindows.get(i); |
| Dianne Hackborn | 5943c20 | 2010-04-12 21:36:49 -0700 | [diff] [blame] | 4397 | if (w.isVisibleLw() && !w.mObscured |
| 4398 | && (w.mOrientationChanging || !w.isDrawnLw())) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4399 | return; |
| 4400 | } |
| 4401 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4402 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4403 | mDisplayEnabled = true; |
| 4404 | if (false) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4405 | Slog.i(TAG, "ENABLING SCREEN!"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4406 | StringWriter sw = new StringWriter(); |
| 4407 | PrintWriter pw = new PrintWriter(sw); |
| 4408 | this.dump(null, pw, null); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4409 | Slog.i(TAG, sw.toString()); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4410 | } |
| 4411 | try { |
| 4412 | IBinder surfaceFlinger = ServiceManager.getService("SurfaceFlinger"); |
| 4413 | if (surfaceFlinger != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4414 | //Slog.i(TAG, "******* TELLING SURFACE FLINGER WE ARE BOOTED!"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4415 | Parcel data = Parcel.obtain(); |
| 4416 | data.writeInterfaceToken("android.ui.ISurfaceComposer"); |
| 4417 | surfaceFlinger.transact(IBinder.FIRST_CALL_TRANSACTION, |
| 4418 | data, null, 0); |
| 4419 | data.recycle(); |
| 4420 | } |
| 4421 | } catch (RemoteException ex) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4422 | Slog.e(TAG, "Boot completed: SurfaceFlinger is dead!"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4423 | } |
| 4424 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4425 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4426 | mPolicy.enableScreenAfterBoot(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4427 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4428 | // Make sure the last requested orientation has been applied. |
| Dianne Hackborn | 321ae68 | 2009-03-27 16:16:03 -0700 | [diff] [blame] | 4429 | setRotationUnchecked(WindowManagerPolicy.USE_LAST_ROTATION, false, |
| 4430 | mLastRotationFlags | Surface.FLAGS_ORIENTATION_ANIMATION_DISABLE); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4431 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4432 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4433 | public void setInTouchMode(boolean mode) { |
| 4434 | synchronized(mWindowMap) { |
| 4435 | mInTouchMode = mode; |
| 4436 | } |
| 4437 | } |
| 4438 | |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4439 | public void setRotation(int rotation, |
| Dianne Hackborn | 1e880db | 2009-03-27 16:04:08 -0700 | [diff] [blame] | 4440 | boolean alwaysSendConfiguration, int animFlags) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4441 | if (!checkCallingPermission(android.Manifest.permission.SET_ORIENTATION, |
| Dianne Hackborn | 1e880db | 2009-03-27 16:04:08 -0700 | [diff] [blame] | 4442 | "setRotation()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4443 | throw new SecurityException("Requires SET_ORIENTATION permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4444 | } |
| 4445 | |
| Dianne Hackborn | 1e880db | 2009-03-27 16:04:08 -0700 | [diff] [blame] | 4446 | setRotationUnchecked(rotation, alwaysSendConfiguration, animFlags); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4447 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4448 | |
| Dianne Hackborn | 1e880db | 2009-03-27 16:04:08 -0700 | [diff] [blame] | 4449 | public void setRotationUnchecked(int rotation, |
| 4450 | boolean alwaysSendConfiguration, int animFlags) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4451 | if(DEBUG_ORIENTATION) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4452 | "alwaysSendConfiguration set to "+alwaysSendConfiguration); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4453 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4454 | long origId = Binder.clearCallingIdentity(); |
| 4455 | boolean changed; |
| 4456 | synchronized(mWindowMap) { |
| Dianne Hackborn | 1e880db | 2009-03-27 16:04:08 -0700 | [diff] [blame] | 4457 | changed = setRotationUncheckedLocked(rotation, animFlags); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4458 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4459 | |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 4460 | if (changed || alwaysSendConfiguration) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4461 | sendNewConfiguration(); |
| 4462 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4463 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4464 | Binder.restoreCallingIdentity(origId); |
| 4465 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4466 | |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 4467 | /** |
| 4468 | * Apply a new rotation to the screen, respecting the requests of |
| 4469 | * applications. Use WindowManagerPolicy.USE_LAST_ROTATION to simply |
| 4470 | * re-evaluate the desired rotation. |
| 4471 | * |
| 4472 | * Returns null if the rotation has been changed. In this case YOU |
| 4473 | * MUST CALL setNewConfiguration() TO UNFREEZE THE SCREEN. |
| 4474 | */ |
| Dianne Hackborn | 1e880db | 2009-03-27 16:04:08 -0700 | [diff] [blame] | 4475 | public boolean setRotationUncheckedLocked(int rotation, int animFlags) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4476 | boolean changed; |
| 4477 | if (rotation == WindowManagerPolicy.USE_LAST_ROTATION) { |
| 4478 | rotation = mRequestedRotation; |
| 4479 | } else { |
| 4480 | mRequestedRotation = rotation; |
| Dianne Hackborn | 321ae68 | 2009-03-27 16:16:03 -0700 | [diff] [blame] | 4481 | mLastRotationFlags = animFlags; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4482 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4483 | if (DEBUG_ORIENTATION) Slog.v(TAG, "Overwriting rotation value from " + rotation); |
| The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 4484 | rotation = mPolicy.rotationForOrientationLw(mForcedAppOrientation, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4485 | mRotation, mDisplayEnabled); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4486 | if (DEBUG_ORIENTATION) Slog.v(TAG, "new rotation is set to " + rotation); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4487 | changed = mDisplayEnabled && mRotation != rotation; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4488 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4489 | if (changed) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4490 | if (DEBUG_ORIENTATION) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4491 | "Rotation changed to " + rotation |
| 4492 | + " from " + mRotation |
| 4493 | + " (forceApp=" + mForcedAppOrientation |
| 4494 | + ", req=" + mRequestedRotation + ")"); |
| 4495 | mRotation = rotation; |
| 4496 | mWindowsFreezingScreen = true; |
| 4497 | mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT); |
| 4498 | mH.sendMessageDelayed(mH.obtainMessage(H.WINDOW_FREEZE_TIMEOUT), |
| 4499 | 2000); |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 4500 | mWaitingForConfig = true; |
| 4501 | mLayoutNeeded = true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4502 | startFreezingDisplayLocked(); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4503 | Slog.i(TAG, "Setting rotation to " + rotation + ", animFlags=" + animFlags); |
| Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 4504 | mInputManager.setDisplayOrientation(0, rotation); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4505 | if (mDisplayEnabled) { |
| Dianne Hackborn | 321ae68 | 2009-03-27 16:16:03 -0700 | [diff] [blame] | 4506 | Surface.setOrientation(0, rotation, animFlags); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4507 | } |
| 4508 | for (int i=mWindows.size()-1; i>=0; i--) { |
| 4509 | WindowState w = (WindowState)mWindows.get(i); |
| 4510 | if (w.mSurface != null) { |
| 4511 | w.mOrientationChanging = true; |
| 4512 | } |
| 4513 | } |
| 4514 | for (int i=mRotationWatchers.size()-1; i>=0; i--) { |
| 4515 | try { |
| 4516 | mRotationWatchers.get(i).onRotationChanged(rotation); |
| 4517 | } catch (RemoteException e) { |
| 4518 | } |
| 4519 | } |
| 4520 | } //end if changed |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4521 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4522 | return changed; |
| 4523 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4524 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4525 | public int getRotation() { |
| 4526 | return mRotation; |
| 4527 | } |
| 4528 | |
| 4529 | public int watchRotation(IRotationWatcher watcher) { |
| 4530 | final IBinder watcherBinder = watcher.asBinder(); |
| 4531 | IBinder.DeathRecipient dr = new IBinder.DeathRecipient() { |
| 4532 | public void binderDied() { |
| 4533 | synchronized (mWindowMap) { |
| 4534 | for (int i=0; i<mRotationWatchers.size(); i++) { |
| 4535 | if (watcherBinder == mRotationWatchers.get(i).asBinder()) { |
| Suchi Amalapurapu | fff2fda | 2009-06-30 21:36:16 -0700 | [diff] [blame] | 4536 | IRotationWatcher removed = mRotationWatchers.remove(i); |
| 4537 | if (removed != null) { |
| 4538 | removed.asBinder().unlinkToDeath(this, 0); |
| 4539 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4540 | i--; |
| 4541 | } |
| 4542 | } |
| 4543 | } |
| 4544 | } |
| 4545 | }; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4546 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4547 | synchronized (mWindowMap) { |
| 4548 | try { |
| 4549 | watcher.asBinder().linkToDeath(dr, 0); |
| 4550 | mRotationWatchers.add(watcher); |
| 4551 | } catch (RemoteException e) { |
| 4552 | // Client died, no cleanup needed. |
| 4553 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4554 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4555 | return mRotation; |
| 4556 | } |
| 4557 | } |
| 4558 | |
| 4559 | /** |
| 4560 | * Starts the view server on the specified port. |
| 4561 | * |
| 4562 | * @param port The port to listener to. |
| 4563 | * |
| 4564 | * @return True if the server was successfully started, false otherwise. |
| 4565 | * |
| 4566 | * @see com.android.server.ViewServer |
| 4567 | * @see com.android.server.ViewServer#VIEW_SERVER_DEFAULT_PORT |
| 4568 | */ |
| 4569 | public boolean startViewServer(int port) { |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4570 | if (isSystemSecure()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4571 | return false; |
| 4572 | } |
| 4573 | |
| 4574 | if (!checkCallingPermission(Manifest.permission.DUMP, "startViewServer")) { |
| 4575 | return false; |
| 4576 | } |
| 4577 | |
| 4578 | if (port < 1024) { |
| 4579 | return false; |
| 4580 | } |
| 4581 | |
| 4582 | if (mViewServer != null) { |
| 4583 | if (!mViewServer.isRunning()) { |
| 4584 | try { |
| 4585 | return mViewServer.start(); |
| 4586 | } catch (IOException e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4587 | Slog.w(TAG, "View server did not start"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4588 | } |
| 4589 | } |
| 4590 | return false; |
| 4591 | } |
| 4592 | |
| 4593 | try { |
| 4594 | mViewServer = new ViewServer(this, port); |
| 4595 | return mViewServer.start(); |
| 4596 | } catch (IOException e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4597 | Slog.w(TAG, "View server did not start"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4598 | } |
| 4599 | return false; |
| 4600 | } |
| 4601 | |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4602 | private boolean isSystemSecure() { |
| 4603 | return "1".equals(SystemProperties.get(SYSTEM_SECURE, "1")) && |
| 4604 | "0".equals(SystemProperties.get(SYSTEM_DEBUGGABLE, "0")); |
| 4605 | } |
| 4606 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4607 | /** |
| 4608 | * Stops the view server if it exists. |
| 4609 | * |
| 4610 | * @return True if the server stopped, false if it wasn't started or |
| 4611 | * couldn't be stopped. |
| 4612 | * |
| 4613 | * @see com.android.server.ViewServer |
| 4614 | */ |
| 4615 | public boolean stopViewServer() { |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4616 | if (isSystemSecure()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4617 | return false; |
| 4618 | } |
| 4619 | |
| 4620 | if (!checkCallingPermission(Manifest.permission.DUMP, "stopViewServer")) { |
| 4621 | return false; |
| 4622 | } |
| 4623 | |
| 4624 | if (mViewServer != null) { |
| 4625 | return mViewServer.stop(); |
| 4626 | } |
| 4627 | return false; |
| 4628 | } |
| 4629 | |
| 4630 | /** |
| 4631 | * Indicates whether the view server is running. |
| 4632 | * |
| 4633 | * @return True if the server is running, false otherwise. |
| 4634 | * |
| 4635 | * @see com.android.server.ViewServer |
| 4636 | */ |
| 4637 | public boolean isViewServerRunning() { |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4638 | if (isSystemSecure()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4639 | return false; |
| 4640 | } |
| 4641 | |
| 4642 | if (!checkCallingPermission(Manifest.permission.DUMP, "isViewServerRunning")) { |
| 4643 | return false; |
| 4644 | } |
| 4645 | |
| 4646 | return mViewServer != null && mViewServer.isRunning(); |
| 4647 | } |
| 4648 | |
| 4649 | /** |
| 4650 | * Lists all availble windows in the system. The listing is written in the |
| 4651 | * specified Socket's output stream with the following syntax: |
| 4652 | * windowHashCodeInHexadecimal windowName |
| 4653 | * Each line of the ouput represents a different window. |
| 4654 | * |
| 4655 | * @param client The remote client to send the listing to. |
| 4656 | * @return False if an error occured, true otherwise. |
| 4657 | */ |
| 4658 | boolean viewServerListWindows(Socket client) { |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4659 | if (isSystemSecure()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4660 | return false; |
| 4661 | } |
| 4662 | |
| 4663 | boolean result = true; |
| 4664 | |
| 4665 | Object[] windows; |
| 4666 | synchronized (mWindowMap) { |
| 4667 | windows = new Object[mWindows.size()]; |
| 4668 | //noinspection unchecked |
| 4669 | windows = mWindows.toArray(windows); |
| 4670 | } |
| 4671 | |
| 4672 | BufferedWriter out = null; |
| 4673 | |
| 4674 | // Any uncaught exception will crash the system process |
| 4675 | try { |
| 4676 | OutputStream clientStream = client.getOutputStream(); |
| 4677 | out = new BufferedWriter(new OutputStreamWriter(clientStream), 8 * 1024); |
| 4678 | |
| 4679 | final int count = windows.length; |
| 4680 | for (int i = 0; i < count; i++) { |
| 4681 | final WindowState w = (WindowState) windows[i]; |
| 4682 | out.write(Integer.toHexString(System.identityHashCode(w))); |
| 4683 | out.write(' '); |
| 4684 | out.append(w.mAttrs.getTitle()); |
| 4685 | out.write('\n'); |
| 4686 | } |
| 4687 | |
| 4688 | out.write("DONE.\n"); |
| 4689 | out.flush(); |
| 4690 | } catch (Exception e) { |
| 4691 | result = false; |
| 4692 | } finally { |
| 4693 | if (out != null) { |
| 4694 | try { |
| 4695 | out.close(); |
| 4696 | } catch (IOException e) { |
| 4697 | result = false; |
| 4698 | } |
| 4699 | } |
| 4700 | } |
| 4701 | |
| 4702 | return result; |
| 4703 | } |
| 4704 | |
| 4705 | /** |
| 4706 | * Sends a command to a target window. The result of the command, if any, will be |
| 4707 | * written in the output stream of the specified socket. |
| 4708 | * |
| 4709 | * The parameters must follow this syntax: |
| 4710 | * windowHashcode extra |
| 4711 | * |
| 4712 | * Where XX is the length in characeters of the windowTitle. |
| 4713 | * |
| 4714 | * The first parameter is the target window. The window with the specified hashcode |
| 4715 | * will be the target. If no target can be found, nothing happens. The extra parameters |
| 4716 | * will be delivered to the target window and as parameters to the command itself. |
| 4717 | * |
| 4718 | * @param client The remote client to sent the result, if any, to. |
| 4719 | * @param command The command to execute. |
| 4720 | * @param parameters The command parameters. |
| 4721 | * |
| 4722 | * @return True if the command was successfully delivered, false otherwise. This does |
| 4723 | * not indicate whether the command itself was successful. |
| 4724 | */ |
| 4725 | boolean viewServerWindowCommand(Socket client, String command, String parameters) { |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4726 | if (isSystemSecure()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4727 | return false; |
| 4728 | } |
| 4729 | |
| 4730 | boolean success = true; |
| 4731 | Parcel data = null; |
| 4732 | Parcel reply = null; |
| 4733 | |
| 4734 | // Any uncaught exception will crash the system process |
| 4735 | try { |
| 4736 | // Find the hashcode of the window |
| 4737 | int index = parameters.indexOf(' '); |
| 4738 | if (index == -1) { |
| 4739 | index = parameters.length(); |
| 4740 | } |
| 4741 | final String code = parameters.substring(0, index); |
| Romain Guy | 236092a | 2009-12-14 15:31:48 -0800 | [diff] [blame] | 4742 | int hashCode = (int) Long.parseLong(code, 16); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4743 | |
| 4744 | // Extract the command's parameter after the window description |
| 4745 | if (index < parameters.length()) { |
| 4746 | parameters = parameters.substring(index + 1); |
| 4747 | } else { |
| 4748 | parameters = ""; |
| 4749 | } |
| 4750 | |
| 4751 | final WindowManagerService.WindowState window = findWindow(hashCode); |
| 4752 | if (window == null) { |
| 4753 | return false; |
| 4754 | } |
| 4755 | |
| 4756 | data = Parcel.obtain(); |
| 4757 | data.writeInterfaceToken("android.view.IWindow"); |
| 4758 | data.writeString(command); |
| 4759 | data.writeString(parameters); |
| 4760 | data.writeInt(1); |
| 4761 | ParcelFileDescriptor.fromSocket(client).writeToParcel(data, 0); |
| 4762 | |
| 4763 | reply = Parcel.obtain(); |
| 4764 | |
| 4765 | final IBinder binder = window.mClient.asBinder(); |
| 4766 | // TODO: GET THE TRANSACTION CODE IN A SAFER MANNER |
| 4767 | binder.transact(IBinder.FIRST_CALL_TRANSACTION, data, reply, 0); |
| 4768 | |
| 4769 | reply.readException(); |
| 4770 | |
| 4771 | } catch (Exception e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4772 | Slog.w(TAG, "Could not send command " + command + " with parameters " + parameters, e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4773 | success = false; |
| 4774 | } finally { |
| 4775 | if (data != null) { |
| 4776 | data.recycle(); |
| 4777 | } |
| 4778 | if (reply != null) { |
| 4779 | reply.recycle(); |
| 4780 | } |
| 4781 | } |
| 4782 | |
| 4783 | return success; |
| 4784 | } |
| 4785 | |
| 4786 | private WindowState findWindow(int hashCode) { |
| 4787 | if (hashCode == -1) { |
| 4788 | return getFocusedWindow(); |
| 4789 | } |
| 4790 | |
| 4791 | synchronized (mWindowMap) { |
| 4792 | final ArrayList windows = mWindows; |
| 4793 | final int count = windows.size(); |
| 4794 | |
| 4795 | for (int i = 0; i < count; i++) { |
| 4796 | WindowState w = (WindowState) windows.get(i); |
| 4797 | if (System.identityHashCode(w) == hashCode) { |
| 4798 | return w; |
| 4799 | } |
| 4800 | } |
| 4801 | } |
| 4802 | |
| 4803 | return null; |
| 4804 | } |
| 4805 | |
| 4806 | /* |
| 4807 | * Instruct the Activity Manager to fetch the current configuration and broadcast |
| 4808 | * that to config-changed listeners if appropriate. |
| 4809 | */ |
| 4810 | void sendNewConfiguration() { |
| 4811 | try { |
| 4812 | mActivityManager.updateConfiguration(null); |
| 4813 | } catch (RemoteException e) { |
| 4814 | } |
| 4815 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4816 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4817 | public Configuration computeNewConfiguration() { |
| 4818 | synchronized (mWindowMap) { |
| Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 4819 | return computeNewConfigurationLocked(); |
| 4820 | } |
| 4821 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4822 | |
| Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 4823 | Configuration computeNewConfigurationLocked() { |
| 4824 | Configuration config = new Configuration(); |
| 4825 | if (!computeNewConfigurationLocked(config)) { |
| 4826 | return null; |
| 4827 | } |
| Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 4828 | return config; |
| 4829 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4830 | |
| Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 4831 | boolean computeNewConfigurationLocked(Configuration config) { |
| 4832 | if (mDisplay == null) { |
| 4833 | return false; |
| 4834 | } |
| Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 4835 | |
| 4836 | mInputManager.getInputConfiguration(config); |
| Christopher Tate | b696aee | 2010-04-02 19:08:30 -0700 | [diff] [blame] | 4837 | |
| 4838 | // Use the effective "visual" dimensions based on current rotation |
| 4839 | final boolean rotated = (mRotation == Surface.ROTATION_90 |
| 4840 | || mRotation == Surface.ROTATION_270); |
| 4841 | final int dw = rotated ? mInitialDisplayHeight : mInitialDisplayWidth; |
| 4842 | final int dh = rotated ? mInitialDisplayWidth : mInitialDisplayHeight; |
| 4843 | |
| Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 4844 | int orientation = Configuration.ORIENTATION_SQUARE; |
| 4845 | if (dw < dh) { |
| 4846 | orientation = Configuration.ORIENTATION_PORTRAIT; |
| 4847 | } else if (dw > dh) { |
| 4848 | orientation = Configuration.ORIENTATION_LANDSCAPE; |
| 4849 | } |
| 4850 | config.orientation = orientation; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 4851 | |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 4852 | DisplayMetrics dm = new DisplayMetrics(); |
| 4853 | mDisplay.getMetrics(dm); |
| 4854 | CompatibilityInfo.updateCompatibleScreenFrame(dm, orientation, mCompatibleScreenFrame); |
| 4855 | |
| Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 4856 | if (mScreenLayout == Configuration.SCREENLAYOUT_SIZE_UNDEFINED) { |
| Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 4857 | // Note we only do this once because at this point we don't |
| 4858 | // expect the screen to change in this way at runtime, and want |
| 4859 | // to avoid all of this computation for every config change. |
| Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 4860 | int longSize = dw; |
| 4861 | int shortSize = dh; |
| 4862 | if (longSize < shortSize) { |
| 4863 | int tmp = longSize; |
| 4864 | longSize = shortSize; |
| 4865 | shortSize = tmp; |
| 4866 | } |
| 4867 | longSize = (int)(longSize/dm.density); |
| 4868 | shortSize = (int)(shortSize/dm.density); |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 4869 | |
| Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 4870 | // These semi-magic numbers define our compatibility modes for |
| 4871 | // applications with different screens. Don't change unless you |
| 4872 | // make sure to test lots and lots of apps! |
| 4873 | if (longSize < 470) { |
| 4874 | // This is shorter than an HVGA normal density screen (which |
| 4875 | // is 480 pixels on its long side). |
| Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 4876 | mScreenLayout = Configuration.SCREENLAYOUT_SIZE_SMALL |
| 4877 | | Configuration.SCREENLAYOUT_LONG_NO; |
| Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 4878 | } else { |
| Dianne Hackborn | 14cee9f | 2010-04-23 17:51:26 -0700 | [diff] [blame] | 4879 | // What size is this screen screen? |
| 4880 | if (longSize >= 800 && shortSize >= 600) { |
| 4881 | // SVGA or larger screens at medium density are the point |
| 4882 | // at which we consider it to be an extra large screen. |
| 4883 | mScreenLayout = Configuration.SCREENLAYOUT_SIZE_XLARGE; |
| 4884 | } else if (longSize >= 640 && shortSize >= 480) { |
| Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 4885 | // VGA or larger screens at medium density are the point |
| 4886 | // at which we consider it to be a large screen. |
| 4887 | mScreenLayout = Configuration.SCREENLAYOUT_SIZE_LARGE; |
| 4888 | } else { |
| 4889 | mScreenLayout = Configuration.SCREENLAYOUT_SIZE_NORMAL; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 4890 | |
| Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 4891 | // If this screen is wider than normal HVGA, or taller |
| 4892 | // than FWVGA, then for old apps we want to run in size |
| 4893 | // compatibility mode. |
| 4894 | if (shortSize > 321 || longSize > 570) { |
| 4895 | mScreenLayout |= Configuration.SCREENLAYOUT_COMPAT_NEEDED; |
| 4896 | } |
| 4897 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 4898 | |
| Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 4899 | // Is this a long screen? |
| 4900 | if (((longSize*3)/5) >= (shortSize-1)) { |
| 4901 | // Anything wider than WVGA (5:3) is considering to be long. |
| 4902 | mScreenLayout |= Configuration.SCREENLAYOUT_LONG_YES; |
| 4903 | } else { |
| 4904 | mScreenLayout |= Configuration.SCREENLAYOUT_LONG_NO; |
| 4905 | } |
| Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 4906 | } |
| 4907 | } |
| Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 4908 | config.screenLayout = mScreenLayout; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 4909 | |
| Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 4910 | config.keyboardHidden = Configuration.KEYBOARDHIDDEN_NO; |
| 4911 | config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_NO; |
| 4912 | mPolicy.adjustConfigurationLw(config); |
| 4913 | return true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4914 | } |
| Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 4915 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4916 | // ------------------------------------------------------------- |
| 4917 | // Input Events and Focus Management |
| 4918 | // ------------------------------------------------------------- |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 4919 | |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 4920 | InputMonitor mInputMonitor = new InputMonitor(); |
| 4921 | |
| 4922 | /* Tracks the progress of input dispatch and ensures that input dispatch state |
| 4923 | * is kept in sync with changes in window focus, visibility, registration, and |
| 4924 | * other relevant Window Manager state transitions. */ |
| 4925 | final class InputMonitor { |
| 4926 | // Current window with input focus for keys and other non-touch events. May be null. |
| 4927 | private WindowState mInputFocus; |
| 4928 | |
| 4929 | // When true, prevents input dispatch from proceeding until set to false again. |
| 4930 | private boolean mInputDispatchFrozen; |
| 4931 | |
| 4932 | // When true, input dispatch proceeds normally. Otherwise all events are dropped. |
| 4933 | private boolean mInputDispatchEnabled = true; |
| 4934 | |
| 4935 | // Temporary list of windows information to provide to the input dispatcher. |
| 4936 | private InputWindowList mTempInputWindows = new InputWindowList(); |
| 4937 | |
| 4938 | // Temporary input application object to provide to the input dispatcher. |
| 4939 | private InputApplication mTempInputApplication = new InputApplication(); |
| 4940 | |
| 4941 | /* Notifies the window manager about a broken input channel. |
| 4942 | * |
| 4943 | * Called by the InputManager. |
| 4944 | */ |
| 4945 | public void notifyInputChannelBroken(InputChannel inputChannel) { |
| 4946 | synchronized (mWindowMap) { |
| 4947 | WindowState windowState = getWindowStateForInputChannelLocked(inputChannel); |
| 4948 | if (windowState == null) { |
| 4949 | return; // irrelevant |
| 4950 | } |
| 4951 | |
| 4952 | Slog.i(TAG, "WINDOW DIED " + windowState); |
| 4953 | removeWindowLocked(windowState.mSession, windowState); |
| Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 4954 | } |
| 4955 | } |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 4956 | |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 4957 | /* Notifies the window manager about an input channel that is not responding. |
| 4958 | * The method can either cause dispatching to be aborted by returning -2 or |
| 4959 | * return a new timeout in nanoseconds. |
| 4960 | * |
| 4961 | * Called by the InputManager. |
| 4962 | */ |
| 4963 | public long notifyInputChannelANR(InputChannel inputChannel) { |
| 4964 | AppWindowToken token; |
| 4965 | synchronized (mWindowMap) { |
| 4966 | WindowState windowState = getWindowStateForInputChannelLocked(inputChannel); |
| 4967 | if (windowState == null) { |
| 4968 | return -2; // irrelevant, abort dispatching (-2) |
| 4969 | } |
| Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 4970 | |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 4971 | Slog.i(TAG, "Input event dispatching timed out sending to " |
| 4972 | + windowState.mAttrs.getTitle()); |
| 4973 | token = windowState.mAppToken; |
| Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 4974 | } |
| 4975 | |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 4976 | return notifyANRInternal(token); |
| 4977 | } |
| 4978 | |
| 4979 | /* Notifies the window manager about an input channel spontaneously recovering from ANR |
| 4980 | * by successfully delivering the event that originally timed out. |
| 4981 | * |
| 4982 | * Called by the InputManager. |
| 4983 | */ |
| 4984 | public void notifyInputChannelRecoveredFromANR(InputChannel inputChannel) { |
| 4985 | // Nothing to do just now. |
| 4986 | // Just wait for the user to dismiss the ANR dialog. |
| 4987 | } |
| 4988 | |
| 4989 | /* Notifies the window manager about an application that is not responding |
| 4990 | * in general rather than with respect to a particular input channel. |
| 4991 | * The method can either cause dispatching to be aborted by returning -2 or |
| 4992 | * return a new timeout in nanoseconds. |
| 4993 | * |
| 4994 | * Called by the InputManager. |
| 4995 | */ |
| 4996 | public long notifyANR(Object token) { |
| 4997 | AppWindowToken appWindowToken = (AppWindowToken) token; |
| 4998 | |
| 4999 | Slog.i(TAG, "Input event dispatching timed out sending to application " |
| 5000 | + appWindowToken.stringName); |
| 5001 | return notifyANRInternal(appWindowToken); |
| 5002 | } |
| 5003 | |
| 5004 | private long notifyANRInternal(AppWindowToken token) { |
| 5005 | if (token != null && token.appToken != null) { |
| 5006 | try { |
| 5007 | // Notify the activity manager about the timeout and let it decide whether |
| 5008 | // to abort dispatching or keep waiting. |
| 5009 | boolean abort = token.appToken.keyDispatchingTimedOut(); |
| 5010 | if (! abort) { |
| 5011 | // The activity manager declined to abort dispatching. |
| 5012 | // Wait a bit longer and timeout again later. |
| 5013 | return token.inputDispatchingTimeoutNanos; |
| Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 5014 | } |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5015 | } catch (RemoteException ex) { |
| Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 5016 | } |
| 5017 | } |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5018 | return -2; // abort dispatching |
| Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 5019 | } |
| 5020 | |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5021 | private WindowState getWindowStateForInputChannel(InputChannel inputChannel) { |
| 5022 | synchronized (mWindowMap) { |
| 5023 | return getWindowStateForInputChannelLocked(inputChannel); |
| 5024 | } |
| 5025 | } |
| 5026 | |
| 5027 | private WindowState getWindowStateForInputChannelLocked(InputChannel inputChannel) { |
| 5028 | int windowCount = mWindows.size(); |
| 5029 | for (int i = 0; i < windowCount; i++) { |
| 5030 | WindowState windowState = (WindowState) mWindows.get(i); |
| 5031 | if (windowState.mInputChannel == inputChannel) { |
| 5032 | return windowState; |
| 5033 | } |
| Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 5034 | } |
| 5035 | |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5036 | return null; |
| Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 5037 | } |
| 5038 | |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5039 | /* Updates the cached window information provided to the input dispatcher. */ |
| 5040 | public void updateInputWindowsLw() { |
| 5041 | // Populate the input window list with information about all of the windows that |
| 5042 | // could potentially receive input. |
| 5043 | // As an optimization, we could try to prune the list of windows but this turns |
| 5044 | // out to be difficult because only the native code knows for sure which window |
| 5045 | // currently has touch focus. |
| Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 5046 | final ArrayList windows = mWindows; |
| 5047 | final int N = windows.size(); |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5048 | for (int i = N - 1; i >= 0; i--) { |
| 5049 | final WindowState child = (WindowState) windows.get(i); |
| 5050 | if (child.mInputChannel == null) { |
| 5051 | // Skip this window because it cannot possibly receive input. |
| Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 5052 | continue; |
| 5053 | } |
| 5054 | |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5055 | final int flags = child.mAttrs.flags; |
| 5056 | final int type = child.mAttrs.type; |
| 5057 | |
| 5058 | final boolean hasFocus = (child == mInputFocus); |
| 5059 | final boolean isVisible = child.isVisibleLw(); |
| 5060 | final boolean hasWallpaper = (child == mWallpaperTarget) |
| 5061 | && (type != WindowManager.LayoutParams.TYPE_KEYGUARD); |
| 5062 | |
| 5063 | // Add a window to our list of input windows. |
| 5064 | final InputWindow inputWindow = mTempInputWindows.add(); |
| 5065 | inputWindow.inputChannel = child.mInputChannel; |
| 5066 | inputWindow.layoutParamsFlags = flags; |
| 5067 | inputWindow.layoutParamsType = type; |
| 5068 | inputWindow.dispatchingTimeoutNanos = child.getInputDispatchingTimeoutNanos(); |
| 5069 | inputWindow.visible = isVisible; |
| 5070 | inputWindow.hasFocus = hasFocus; |
| 5071 | inputWindow.hasWallpaper = hasWallpaper; |
| 5072 | inputWindow.paused = child.mAppToken != null ? child.mAppToken.paused : false; |
| 5073 | inputWindow.ownerPid = child.mSession.mPid; |
| 5074 | inputWindow.ownerUid = child.mSession.mUid; |
| 5075 | |
| 5076 | final Rect frame = child.mFrame; |
| 5077 | inputWindow.frameLeft = frame.left; |
| 5078 | inputWindow.frameTop = frame.top; |
| 5079 | |
| 5080 | switch (child.mTouchableInsets) { |
| 5081 | default: |
| 5082 | case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME: |
| 5083 | inputWindow.touchableAreaLeft = frame.left; |
| 5084 | inputWindow.touchableAreaTop = frame.top; |
| 5085 | inputWindow.touchableAreaRight = frame.right; |
| 5086 | inputWindow.touchableAreaBottom = frame.bottom; |
| 5087 | break; |
| 5088 | |
| 5089 | case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_CONTENT: { |
| 5090 | Rect inset = child.mGivenContentInsets; |
| 5091 | inputWindow.touchableAreaLeft = frame.left + inset.left; |
| 5092 | inputWindow.touchableAreaTop = frame.top + inset.top; |
| 5093 | inputWindow.touchableAreaRight = frame.right - inset.right; |
| 5094 | inputWindow.touchableAreaBottom = frame.bottom - inset.bottom; |
| 5095 | break; |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5096 | } |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5097 | |
| 5098 | case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_VISIBLE: { |
| 5099 | Rect inset = child.mGivenVisibleInsets; |
| 5100 | inputWindow.touchableAreaLeft = frame.left + inset.left; |
| 5101 | inputWindow.touchableAreaTop = frame.top + inset.top; |
| 5102 | inputWindow.touchableAreaRight = frame.right - inset.right; |
| 5103 | inputWindow.touchableAreaBottom = frame.bottom - inset.bottom; |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5104 | break; |
| 5105 | } |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5106 | } |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5107 | } |
| Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 5108 | |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5109 | // Send windows to native code. |
| 5110 | mInputManager.setInputWindows(mTempInputWindows.toNullTerminatedArray()); |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5111 | |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5112 | // Clear the list in preparation for the next round. |
| 5113 | // Also avoids keeping InputChannel objects referenced unnecessarily. |
| 5114 | mTempInputWindows.clear(); |
| 5115 | } |
| 5116 | |
| Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 5117 | /* Provides feedback for a virtual key down. */ |
| 5118 | public void virtualKeyDownFeedback() { |
| 5119 | synchronized (mWindowMap) { |
| 5120 | mPolicy.performHapticFeedbackLw(null, HapticFeedbackConstants.VIRTUAL_KEY, false); |
| 5121 | } |
| 5122 | } |
| 5123 | |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5124 | /* Notifies that an app switch key (BACK / HOME) has just been pressed. |
| 5125 | * This essentially starts a .5 second timeout for the application to process |
| 5126 | * subsequent input events while waiting for the app switch to occur. If it takes longer |
| 5127 | * than this, the pending events will be dropped. |
| 5128 | */ |
| 5129 | public void notifyAppSwitchComing() { |
| 5130 | // TODO Not implemented yet. Should go in the native side. |
| 5131 | } |
| Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 5132 | |
| 5133 | /* Notifies that the lid switch changed state. */ |
| 5134 | public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen) { |
| 5135 | mPolicy.notifyLidSwitchChanged(whenNanos, lidOpen); |
| 5136 | } |
| 5137 | |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5138 | /* Provides an opportunity for the window manager policy to intercept early key |
| 5139 | * processing as soon as the key has been read from the device. */ |
| Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 5140 | public int interceptKeyBeforeQueueing(long whenNanos, int keyCode, boolean down, |
| 5141 | int policyFlags, boolean isScreenOn) { |
| 5142 | return mPolicy.interceptKeyBeforeQueueing(whenNanos, |
| 5143 | keyCode, down, policyFlags, isScreenOn); |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5144 | } |
| 5145 | |
| 5146 | /* Provides an opportunity for the window manager policy to process a key before |
| 5147 | * ordinary dispatch. */ |
| Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 5148 | public boolean interceptKeyBeforeDispatching(InputChannel focus, |
| 5149 | int action, int flags, int keyCode, int metaState, int repeatCount, |
| 5150 | int policyFlags) { |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5151 | WindowState windowState = getWindowStateForInputChannel(focus); |
| Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 5152 | return mPolicy.interceptKeyBeforeDispatching(windowState, action, flags, |
| 5153 | keyCode, metaState, repeatCount, policyFlags); |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5154 | } |
| 5155 | |
| 5156 | /* Called when the current input focus changes. |
| 5157 | * Layer assignment is assumed to be complete by the time this is called. |
| 5158 | */ |
| 5159 | public void setInputFocusLw(WindowState newWindow) { |
| 5160 | if (DEBUG_INPUT) { |
| 5161 | Slog.d(TAG, "Input focus has changed to " + newWindow); |
| 5162 | } |
| 5163 | |
| 5164 | if (newWindow != mInputFocus) { |
| 5165 | if (newWindow != null && newWindow.canReceiveKeys()) { |
| 5166 | // If the new input focus is an error window or appears above the current |
| 5167 | // input focus, preempt any pending synchronous dispatch so that we can |
| 5168 | // start delivering events to the new input focus as soon as possible. |
| 5169 | if ((newWindow.mAttrs.flags & FLAG_SYSTEM_ERROR) != 0) { |
| 5170 | if (DEBUG_INPUT) { |
| 5171 | Slog.v(TAG, "New SYSTEM_ERROR window; resetting state"); |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5172 | } |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5173 | preemptInputDispatchLw(); |
| 5174 | } else if (mInputFocus != null && newWindow.mLayer > mInputFocus.mLayer) { |
| 5175 | if (DEBUG_INPUT) { |
| 5176 | Slog.v(TAG, "Transferring focus to new window at higher layer: " |
| 5177 | + "old win layer=" + mInputFocus.mLayer |
| 5178 | + ", new win layer=" + newWindow.mLayer); |
| 5179 | } |
| 5180 | preemptInputDispatchLw(); |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5181 | } |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5182 | |
| 5183 | // Displaying a window implicitly causes dispatching to be unpaused. |
| 5184 | // This is to protect against bugs if someone pauses dispatching but |
| 5185 | // forgets to resume. |
| 5186 | newWindow.mToken.paused = false; |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5187 | } |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5188 | |
| 5189 | mInputFocus = newWindow; |
| 5190 | updateInputWindowsLw(); |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5191 | } |
| 5192 | } |
| 5193 | |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5194 | public void windowIsBecomingInvisibleLw(WindowState window) { |
| 5195 | // The window is becoming invisible. Preempt input dispatch in progress |
| 5196 | // so that the next window below can receive focus. |
| 5197 | if (window == mInputFocus) { |
| 5198 | mInputFocus = null; |
| 5199 | preemptInputDispatchLw(); |
| 5200 | } |
| 5201 | |
| 5202 | updateInputWindowsLw(); |
| 5203 | } |
| 5204 | |
| 5205 | /* Tells the dispatcher to stop waiting for its current synchronous event targets. |
| 5206 | * Essentially, just makes those dispatches asynchronous so a new dispatch cycle |
| 5207 | * can begin. |
| 5208 | */ |
| 5209 | private void preemptInputDispatchLw() { |
| 5210 | mInputManager.preemptInputDispatch(); |
| 5211 | } |
| 5212 | |
| 5213 | public void setFocusedAppLw(AppWindowToken newApp) { |
| 5214 | // Focused app has changed. |
| 5215 | if (newApp == null) { |
| 5216 | mInputManager.setFocusedApplication(null); |
| 5217 | } else { |
| 5218 | mTempInputApplication.name = newApp.toString(); |
| 5219 | mTempInputApplication.dispatchingTimeoutNanos = |
| 5220 | newApp.inputDispatchingTimeoutNanos; |
| 5221 | mTempInputApplication.token = newApp; |
| 5222 | |
| 5223 | mInputManager.setFocusedApplication(mTempInputApplication); |
| 5224 | } |
| 5225 | } |
| 5226 | |
| 5227 | public void windowIsBeingRemovedLw(WindowState window) { |
| 5228 | // Window is being removed. |
| 5229 | updateInputWindowsLw(); |
| 5230 | } |
| 5231 | |
| 5232 | public void pauseDispatchingLw(WindowToken window) { |
| 5233 | if (! window.paused) { |
| 5234 | if (DEBUG_INPUT) { |
| 5235 | Slog.v(TAG, "Pausing WindowToken " + window); |
| 5236 | } |
| 5237 | |
| 5238 | window.paused = true; |
| 5239 | updateInputWindowsLw(); |
| 5240 | } |
| 5241 | } |
| 5242 | |
| 5243 | public void resumeDispatchingLw(WindowToken window) { |
| 5244 | if (window.paused) { |
| 5245 | if (DEBUG_INPUT) { |
| 5246 | Slog.v(TAG, "Resuming WindowToken " + window); |
| 5247 | } |
| 5248 | |
| 5249 | window.paused = false; |
| 5250 | updateInputWindowsLw(); |
| 5251 | } |
| 5252 | } |
| 5253 | |
| 5254 | public void freezeInputDispatchingLw() { |
| 5255 | if (! mInputDispatchFrozen) { |
| 5256 | if (DEBUG_INPUT) { |
| 5257 | Slog.v(TAG, "Freezing input dispatching"); |
| 5258 | } |
| 5259 | |
| 5260 | mInputDispatchFrozen = true; |
| 5261 | updateInputDispatchModeLw(); |
| 5262 | } |
| 5263 | } |
| 5264 | |
| 5265 | public void thawInputDispatchingLw() { |
| 5266 | if (mInputDispatchFrozen) { |
| 5267 | if (DEBUG_INPUT) { |
| 5268 | Slog.v(TAG, "Thawing input dispatching"); |
| 5269 | } |
| 5270 | |
| 5271 | mInputDispatchFrozen = false; |
| 5272 | updateInputDispatchModeLw(); |
| 5273 | } |
| 5274 | } |
| 5275 | |
| 5276 | public void setEventDispatchingLw(boolean enabled) { |
| 5277 | if (mInputDispatchEnabled != enabled) { |
| 5278 | if (DEBUG_INPUT) { |
| 5279 | Slog.v(TAG, "Setting event dispatching to " + enabled); |
| 5280 | } |
| 5281 | |
| 5282 | mInputDispatchEnabled = enabled; |
| 5283 | updateInputDispatchModeLw(); |
| 5284 | } |
| 5285 | } |
| 5286 | |
| 5287 | private void updateInputDispatchModeLw() { |
| 5288 | mInputManager.setInputDispatchMode(mInputDispatchEnabled, mInputDispatchFrozen); |
| 5289 | } |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5290 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5291 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5292 | public void pauseKeyDispatching(IBinder _token) { |
| 5293 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 5294 | "pauseKeyDispatching()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5295 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5296 | } |
| 5297 | |
| 5298 | synchronized (mWindowMap) { |
| 5299 | WindowToken token = mTokenMap.get(_token); |
| 5300 | if (token != null) { |
| Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 5301 | mInputMonitor.pauseDispatchingLw(token); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5302 | } |
| 5303 | } |
| 5304 | } |
| 5305 | |
| 5306 | public void resumeKeyDispatching(IBinder _token) { |
| 5307 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 5308 | "resumeKeyDispatching()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5309 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5310 | } |
| 5311 | |
| 5312 | synchronized (mWindowMap) { |
| 5313 | WindowToken token = mTokenMap.get(_token); |
| 5314 | if (token != null) { |
| Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 5315 | mInputMonitor.resumeDispatchingLw(token); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5316 | } |
| 5317 | } |
| 5318 | } |
| 5319 | |
| 5320 | public void setEventDispatching(boolean enabled) { |
| 5321 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 5322 | "resumeKeyDispatching()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5323 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5324 | } |
| 5325 | |
| 5326 | synchronized (mWindowMap) { |
| Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 5327 | mInputMonitor.setEventDispatchingLw(enabled); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5328 | } |
| 5329 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5330 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5331 | /** |
| 5332 | * Injects a keystroke event into the UI. |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5333 | * |
| 5334 | * @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] | 5335 | * {@link SystemClock#uptimeMillis()} as the timebase.) |
| 5336 | * @param sync If true, wait for the event to be completed before returning to the caller. |
| 5337 | * @return Returns true if event was dispatched, false if it was dropped for any reason |
| 5338 | */ |
| 5339 | public boolean injectKeyEvent(KeyEvent ev, boolean sync) { |
| 5340 | long downTime = ev.getDownTime(); |
| 5341 | long eventTime = ev.getEventTime(); |
| 5342 | |
| 5343 | int action = ev.getAction(); |
| 5344 | int code = ev.getKeyCode(); |
| 5345 | int repeatCount = ev.getRepeatCount(); |
| 5346 | int metaState = ev.getMetaState(); |
| 5347 | int deviceId = ev.getDeviceId(); |
| 5348 | int scancode = ev.getScanCode(); |
| 5349 | |
| 5350 | if (eventTime == 0) eventTime = SystemClock.uptimeMillis(); |
| 5351 | if (downTime == 0) downTime = eventTime; |
| 5352 | |
| 5353 | 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] | 5354 | deviceId, scancode, KeyEvent.FLAG_FROM_SYSTEM); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5355 | |
| Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5356 | final int pid = Binder.getCallingPid(); |
| 5357 | final int uid = Binder.getCallingUid(); |
| 5358 | final long ident = Binder.clearCallingIdentity(); |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5359 | |
| Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 5360 | final int result = mInputManager.injectKeyEvent(newEvent, |
| 5361 | InputQueue.INPUT_EVENT_NATURE_KEY, pid, uid, sync, INJECTION_TIMEOUT_MILLIS); |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5362 | |
| Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5363 | Binder.restoreCallingIdentity(ident); |
| Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 5364 | return reportInjectionResult(result); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5365 | } |
| 5366 | |
| 5367 | /** |
| 5368 | * Inject a pointer (touch) event into the UI. |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5369 | * |
| 5370 | * @param ev A motion event describing the pointer (touch) action. (As noted in |
| 5371 | * {@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] | 5372 | * {@link SystemClock#uptimeMillis()} as the timebase.) |
| 5373 | * @param sync If true, wait for the event to be completed before returning to the caller. |
| 5374 | * @return Returns true if event was dispatched, false if it was dropped for any reason |
| 5375 | */ |
| 5376 | public boolean injectPointerEvent(MotionEvent ev, boolean sync) { |
| Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5377 | final int pid = Binder.getCallingPid(); |
| 5378 | final int uid = Binder.getCallingUid(); |
| 5379 | final long ident = Binder.clearCallingIdentity(); |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5380 | |
| Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 5381 | final int result = mInputManager.injectMotionEvent(ev, |
| 5382 | InputQueue.INPUT_EVENT_NATURE_TOUCH, pid, uid, sync, INJECTION_TIMEOUT_MILLIS); |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5383 | |
| Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5384 | Binder.restoreCallingIdentity(ident); |
| Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 5385 | return reportInjectionResult(result); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5386 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5387 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5388 | /** |
| 5389 | * Inject a trackball (navigation device) event into the UI. |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5390 | * |
| 5391 | * @param ev A motion event describing the trackball action. (As noted in |
| 5392 | * {@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] | 5393 | * {@link SystemClock#uptimeMillis()} as the timebase.) |
| 5394 | * @param sync If true, wait for the event to be completed before returning to the caller. |
| 5395 | * @return Returns true if event was dispatched, false if it was dropped for any reason |
| 5396 | */ |
| 5397 | public boolean injectTrackballEvent(MotionEvent ev, boolean sync) { |
| Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5398 | final int pid = Binder.getCallingPid(); |
| 5399 | final int uid = Binder.getCallingUid(); |
| 5400 | final long ident = Binder.clearCallingIdentity(); |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5401 | |
| Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 5402 | final int result = mInputManager.injectMotionEvent(ev, |
| 5403 | InputQueue.INPUT_EVENT_NATURE_TRACKBALL, pid, uid, sync, INJECTION_TIMEOUT_MILLIS); |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5404 | |
| Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5405 | Binder.restoreCallingIdentity(ident); |
| Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 5406 | return reportInjectionResult(result); |
| 5407 | } |
| 5408 | |
| 5409 | private boolean reportInjectionResult(int result) { |
| Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 5410 | switch (result) { |
| 5411 | case InputManager.INPUT_EVENT_INJECTION_PERMISSION_DENIED: |
| 5412 | Slog.w(TAG, "Input event injection permission denied."); |
| 5413 | throw new SecurityException( |
| 5414 | "Injecting to another application requires INJECT_EVENTS permission"); |
| 5415 | case InputManager.INPUT_EVENT_INJECTION_SUCCEEDED: |
| 5416 | Slog.v(TAG, "Input event injection succeeded."); |
| 5417 | return true; |
| 5418 | case InputManager.INPUT_EVENT_INJECTION_TIMED_OUT: |
| 5419 | Slog.w(TAG, "Input event injection timed out."); |
| 5420 | return false; |
| 5421 | case InputManager.INPUT_EVENT_INJECTION_FAILED: |
| 5422 | default: |
| 5423 | Slog.w(TAG, "Input event injection failed."); |
| 5424 | return false; |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5425 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5426 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5427 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5428 | private WindowState getFocusedWindow() { |
| 5429 | synchronized (mWindowMap) { |
| 5430 | return getFocusedWindowLocked(); |
| 5431 | } |
| 5432 | } |
| 5433 | |
| 5434 | private WindowState getFocusedWindowLocked() { |
| 5435 | return mCurrentFocus; |
| 5436 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5437 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5438 | public boolean detectSafeMode() { |
| 5439 | mSafeMode = mPolicy.detectSafeMode(); |
| 5440 | return mSafeMode; |
| 5441 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5442 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5443 | public void systemReady() { |
| 5444 | mPolicy.systemReady(); |
| 5445 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5446 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5447 | // ------------------------------------------------------------- |
| 5448 | // Client Session State |
| 5449 | // ------------------------------------------------------------- |
| 5450 | |
| 5451 | private final class Session extends IWindowSession.Stub |
| 5452 | implements IBinder.DeathRecipient { |
| 5453 | final IInputMethodClient mClient; |
| 5454 | final IInputContext mInputContext; |
| 5455 | final int mUid; |
| 5456 | final int mPid; |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 5457 | final String mStringName; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5458 | SurfaceSession mSurfaceSession; |
| 5459 | int mNumWindow = 0; |
| 5460 | boolean mClientDead = false; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5461 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5462 | public Session(IInputMethodClient client, IInputContext inputContext) { |
| 5463 | mClient = client; |
| 5464 | mInputContext = inputContext; |
| 5465 | mUid = Binder.getCallingUid(); |
| 5466 | mPid = Binder.getCallingPid(); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 5467 | StringBuilder sb = new StringBuilder(); |
| 5468 | sb.append("Session{"); |
| 5469 | sb.append(Integer.toHexString(System.identityHashCode(this))); |
| 5470 | sb.append(" uid "); |
| 5471 | sb.append(mUid); |
| 5472 | sb.append("}"); |
| 5473 | mStringName = sb.toString(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5474 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5475 | synchronized (mWindowMap) { |
| 5476 | if (mInputMethodManager == null && mHaveInputMethods) { |
| 5477 | IBinder b = ServiceManager.getService( |
| 5478 | Context.INPUT_METHOD_SERVICE); |
| 5479 | mInputMethodManager = IInputMethodManager.Stub.asInterface(b); |
| 5480 | } |
| 5481 | } |
| 5482 | long ident = Binder.clearCallingIdentity(); |
| 5483 | try { |
| 5484 | // Note: it is safe to call in to the input method manager |
| 5485 | // here because we are not holding our lock. |
| 5486 | if (mInputMethodManager != null) { |
| 5487 | mInputMethodManager.addClient(client, inputContext, |
| 5488 | mUid, mPid); |
| 5489 | } else { |
| 5490 | client.setUsingInputMethod(false); |
| 5491 | } |
| 5492 | client.asBinder().linkToDeath(this, 0); |
| 5493 | } catch (RemoteException e) { |
| 5494 | // The caller has died, so we can just forget about this. |
| 5495 | try { |
| 5496 | if (mInputMethodManager != null) { |
| 5497 | mInputMethodManager.removeClient(client); |
| 5498 | } |
| 5499 | } catch (RemoteException ee) { |
| 5500 | } |
| 5501 | } finally { |
| 5502 | Binder.restoreCallingIdentity(ident); |
| 5503 | } |
| 5504 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5505 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5506 | @Override |
| 5507 | public boolean onTransact(int code, Parcel data, Parcel reply, int flags) |
| 5508 | throws RemoteException { |
| 5509 | try { |
| 5510 | return super.onTransact(code, data, reply, flags); |
| 5511 | } catch (RuntimeException e) { |
| 5512 | // Log all 'real' exceptions thrown to the caller |
| 5513 | if (!(e instanceof SecurityException)) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5514 | Slog.e(TAG, "Window Session Crash", e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5515 | } |
| 5516 | throw e; |
| 5517 | } |
| 5518 | } |
| 5519 | |
| 5520 | public void binderDied() { |
| 5521 | // Note: it is safe to call in to the input method manager |
| 5522 | // here because we are not holding our lock. |
| 5523 | try { |
| 5524 | if (mInputMethodManager != null) { |
| 5525 | mInputMethodManager.removeClient(mClient); |
| 5526 | } |
| 5527 | } catch (RemoteException e) { |
| 5528 | } |
| 5529 | synchronized(mWindowMap) { |
| Suchi Amalapurapu | fff2fda | 2009-06-30 21:36:16 -0700 | [diff] [blame] | 5530 | mClient.asBinder().unlinkToDeath(this, 0); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5531 | mClientDead = true; |
| 5532 | killSessionLocked(); |
| 5533 | } |
| 5534 | } |
| 5535 | |
| 5536 | public int add(IWindow window, WindowManager.LayoutParams attrs, |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5537 | int viewVisibility, Rect outContentInsets, InputChannel outInputChannel) { |
| 5538 | return addWindow(this, window, attrs, viewVisibility, outContentInsets, |
| 5539 | outInputChannel); |
| 5540 | } |
| 5541 | |
| 5542 | public int addWithoutInputChannel(IWindow window, WindowManager.LayoutParams attrs, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5543 | int viewVisibility, Rect outContentInsets) { |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5544 | return addWindow(this, window, attrs, viewVisibility, outContentInsets, null); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5545 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5546 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5547 | public void remove(IWindow window) { |
| 5548 | removeWindow(this, window); |
| 5549 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5550 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5551 | public int relayout(IWindow window, WindowManager.LayoutParams attrs, |
| 5552 | int requestedWidth, int requestedHeight, int viewFlags, |
| 5553 | boolean insetsPending, Rect outFrame, Rect outContentInsets, |
| Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 5554 | Rect outVisibleInsets, Configuration outConfig, Surface outSurface) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5555 | return relayoutWindow(this, window, attrs, |
| 5556 | requestedWidth, requestedHeight, viewFlags, insetsPending, |
| Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 5557 | outFrame, outContentInsets, outVisibleInsets, outConfig, outSurface); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5558 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5559 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5560 | public void setTransparentRegion(IWindow window, Region region) { |
| 5561 | setTransparentRegionWindow(this, window, region); |
| 5562 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5563 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5564 | public void setInsets(IWindow window, int touchableInsets, |
| 5565 | Rect contentInsets, Rect visibleInsets) { |
| 5566 | setInsetsWindow(this, window, touchableInsets, contentInsets, |
| 5567 | visibleInsets); |
| 5568 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5569 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5570 | public void getDisplayFrame(IWindow window, Rect outDisplayFrame) { |
| 5571 | getWindowDisplayFrame(this, window, outDisplayFrame); |
| 5572 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5573 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5574 | public void finishDrawing(IWindow window) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5575 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5576 | TAG, "IWindow finishDrawing called for " + window); |
| 5577 | finishDrawingWindow(this, window); |
| 5578 | } |
| 5579 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5580 | public void setInTouchMode(boolean mode) { |
| 5581 | synchronized(mWindowMap) { |
| 5582 | mInTouchMode = mode; |
| 5583 | } |
| 5584 | } |
| 5585 | |
| 5586 | public boolean getInTouchMode() { |
| 5587 | synchronized(mWindowMap) { |
| 5588 | return mInTouchMode; |
| 5589 | } |
| 5590 | } |
| 5591 | |
| 5592 | public boolean performHapticFeedback(IWindow window, int effectId, |
| 5593 | boolean always) { |
| 5594 | synchronized(mWindowMap) { |
| 5595 | long ident = Binder.clearCallingIdentity(); |
| 5596 | try { |
| The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 5597 | return mPolicy.performHapticFeedbackLw( |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 5598 | windowForClientLocked(this, window, true), |
| 5599 | effectId, always); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5600 | } finally { |
| 5601 | Binder.restoreCallingIdentity(ident); |
| 5602 | } |
| 5603 | } |
| 5604 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5605 | |
| Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 5606 | 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] | 5607 | synchronized(mWindowMap) { |
| 5608 | long ident = Binder.clearCallingIdentity(); |
| 5609 | try { |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 5610 | setWindowWallpaperPositionLocked( |
| 5611 | windowForClientLocked(this, window, true), |
| Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 5612 | x, y, xStep, yStep); |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 5613 | } finally { |
| 5614 | Binder.restoreCallingIdentity(ident); |
| 5615 | } |
| 5616 | } |
| 5617 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 5618 | |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 5619 | public void wallpaperOffsetsComplete(IBinder window) { |
| 5620 | WindowManagerService.this.wallpaperOffsetsComplete(window); |
| 5621 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 5622 | |
| Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 5623 | public Bundle sendWallpaperCommand(IBinder window, String action, int x, int y, |
| 5624 | int z, Bundle extras, boolean sync) { |
| 5625 | synchronized(mWindowMap) { |
| 5626 | long ident = Binder.clearCallingIdentity(); |
| 5627 | try { |
| 5628 | return sendWindowWallpaperCommandLocked( |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 5629 | windowForClientLocked(this, window, true), |
| Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 5630 | action, x, y, z, extras, sync); |
| 5631 | } finally { |
| 5632 | Binder.restoreCallingIdentity(ident); |
| 5633 | } |
| 5634 | } |
| 5635 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 5636 | |
| Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 5637 | public void wallpaperCommandComplete(IBinder window, Bundle result) { |
| 5638 | WindowManagerService.this.wallpaperCommandComplete(window, result); |
| 5639 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 5640 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5641 | void windowAddedLocked() { |
| 5642 | if (mSurfaceSession == null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5643 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5644 | TAG, "First window added to " + this + ", creating SurfaceSession"); |
| 5645 | mSurfaceSession = new SurfaceSession(); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5646 | if (SHOW_TRANSACTIONS) Slog.i( |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 5647 | TAG, " NEW SURFACE SESSION " + mSurfaceSession); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5648 | mSessions.add(this); |
| 5649 | } |
| 5650 | mNumWindow++; |
| 5651 | } |
| 5652 | |
| 5653 | void windowRemovedLocked() { |
| 5654 | mNumWindow--; |
| 5655 | killSessionLocked(); |
| 5656 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5657 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5658 | void killSessionLocked() { |
| 5659 | if (mNumWindow <= 0 && mClientDead) { |
| 5660 | mSessions.remove(this); |
| 5661 | if (mSurfaceSession != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5662 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5663 | TAG, "Last window removed from " + this |
| 5664 | + ", destroying " + mSurfaceSession); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5665 | if (SHOW_TRANSACTIONS) Slog.i( |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 5666 | TAG, " KILL SURFACE SESSION " + mSurfaceSession); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5667 | try { |
| 5668 | mSurfaceSession.kill(); |
| 5669 | } catch (Exception e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5670 | Slog.w(TAG, "Exception thrown when killing surface session " |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5671 | + mSurfaceSession + " in session " + this |
| 5672 | + ": " + e.toString()); |
| 5673 | } |
| 5674 | mSurfaceSession = null; |
| 5675 | } |
| 5676 | } |
| 5677 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5678 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5679 | void dump(PrintWriter pw, String prefix) { |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 5680 | pw.print(prefix); pw.print("mNumWindow="); pw.print(mNumWindow); |
| 5681 | pw.print(" mClientDead="); pw.print(mClientDead); |
| 5682 | pw.print(" mSurfaceSession="); pw.println(mSurfaceSession); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5683 | } |
| 5684 | |
| 5685 | @Override |
| 5686 | public String toString() { |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 5687 | return mStringName; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5688 | } |
| 5689 | } |
| 5690 | |
| 5691 | // ------------------------------------------------------------- |
| 5692 | // Client Window State |
| 5693 | // ------------------------------------------------------------- |
| 5694 | |
| 5695 | private final class WindowState implements WindowManagerPolicy.WindowState { |
| 5696 | final Session mSession; |
| 5697 | final IWindow mClient; |
| 5698 | WindowToken mToken; |
| The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 5699 | WindowToken mRootToken; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5700 | AppWindowToken mAppToken; |
| 5701 | AppWindowToken mTargetAppToken; |
| 5702 | final WindowManager.LayoutParams mAttrs = new WindowManager.LayoutParams(); |
| 5703 | final DeathRecipient mDeathRecipient; |
| 5704 | final WindowState mAttachedWindow; |
| 5705 | final ArrayList mChildWindows = new ArrayList(); |
| 5706 | final int mBaseLayer; |
| 5707 | final int mSubLayer; |
| 5708 | final boolean mLayoutAttached; |
| 5709 | final boolean mIsImWindow; |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 5710 | final boolean mIsWallpaper; |
| 5711 | final boolean mIsFloatingLayer; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5712 | int mViewVisibility; |
| 5713 | boolean mPolicyVisibility = true; |
| 5714 | boolean mPolicyVisibilityAfterAnim = true; |
| 5715 | boolean mAppFreezing; |
| 5716 | Surface mSurface; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 5717 | boolean mReportDestroySurface; |
| 5718 | boolean mSurfacePendingDestroy; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5719 | boolean mAttachedHidden; // is our parent window hidden? |
| 5720 | boolean mLastHidden; // was this window last hidden? |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 5721 | boolean mWallpaperVisible; // for wallpaper, what was last vis report? |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5722 | int mRequestedWidth; |
| 5723 | int mRequestedHeight; |
| 5724 | int mLastRequestedWidth; |
| 5725 | int mLastRequestedHeight; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5726 | int mLayer; |
| 5727 | int mAnimLayer; |
| 5728 | int mLastLayer; |
| 5729 | boolean mHaveFrame; |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 5730 | boolean mObscured; |
| Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 5731 | boolean mTurnOnScreen; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5732 | |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 5733 | int mLayoutSeq = -1; |
| 5734 | |
| 5735 | Configuration mConfiguration = null; |
| 5736 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5737 | // Actual frame shown on-screen (may be modified by animation) |
| 5738 | final Rect mShownFrame = new Rect(); |
| 5739 | final Rect mLastShownFrame = new Rect(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5740 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5741 | /** |
| Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 5742 | * Set when we have changed the size of the surface, to know that |
| 5743 | * we must tell them application to resize (and thus redraw itself). |
| 5744 | */ |
| 5745 | boolean mSurfaceResized; |
| 5746 | |
| 5747 | /** |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5748 | * Insets that determine the actually visible area |
| 5749 | */ |
| 5750 | final Rect mVisibleInsets = new Rect(); |
| 5751 | final Rect mLastVisibleInsets = new Rect(); |
| 5752 | boolean mVisibleInsetsChanged; |
| 5753 | |
| 5754 | /** |
| 5755 | * Insets that are covered by system windows |
| 5756 | */ |
| 5757 | final Rect mContentInsets = new Rect(); |
| 5758 | final Rect mLastContentInsets = new Rect(); |
| 5759 | boolean mContentInsetsChanged; |
| 5760 | |
| 5761 | /** |
| 5762 | * Set to true if we are waiting for this window to receive its |
| 5763 | * given internal insets before laying out other windows based on it. |
| 5764 | */ |
| 5765 | boolean mGivenInsetsPending; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5766 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5767 | /** |
| 5768 | * These are the content insets that were given during layout for |
| 5769 | * this window, to be applied to windows behind it. |
| 5770 | */ |
| 5771 | final Rect mGivenContentInsets = new Rect(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5772 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5773 | /** |
| 5774 | * These are the visible insets that were given during layout for |
| 5775 | * this window, to be applied to windows behind it. |
| 5776 | */ |
| 5777 | final Rect mGivenVisibleInsets = new Rect(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5778 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5779 | /** |
| 5780 | * Flag indicating whether the touchable region should be adjusted by |
| 5781 | * the visible insets; if false the area outside the visible insets is |
| 5782 | * NOT touchable, so we must use those to adjust the frame during hit |
| 5783 | * tests. |
| 5784 | */ |
| 5785 | int mTouchableInsets = ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5786 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5787 | // Current transformation being applied. |
| 5788 | float mDsDx=1, mDtDx=0, mDsDy=0, mDtDy=1; |
| 5789 | float mLastDsDx=1, mLastDtDx=0, mLastDsDy=0, mLastDtDy=1; |
| 5790 | float mHScale=1, mVScale=1; |
| 5791 | float mLastHScale=1, mLastVScale=1; |
| 5792 | final Matrix mTmpMatrix = new Matrix(); |
| 5793 | |
| 5794 | // "Real" frame that the application sees. |
| 5795 | final Rect mFrame = new Rect(); |
| 5796 | final Rect mLastFrame = new Rect(); |
| 5797 | |
| 5798 | final Rect mContainingFrame = new Rect(); |
| 5799 | final Rect mDisplayFrame = new Rect(); |
| 5800 | final Rect mContentFrame = new Rect(); |
| 5801 | final Rect mVisibleFrame = new Rect(); |
| 5802 | |
| 5803 | float mShownAlpha = 1; |
| 5804 | float mAlpha = 1; |
| 5805 | float mLastAlpha = 1; |
| 5806 | |
| 5807 | // Set to true if, when the window gets displayed, it should perform |
| 5808 | // an enter animation. |
| 5809 | boolean mEnterAnimationPending; |
| 5810 | |
| 5811 | // Currently running animation. |
| 5812 | boolean mAnimating; |
| 5813 | boolean mLocalAnimating; |
| 5814 | Animation mAnimation; |
| 5815 | boolean mAnimationIsEntrance; |
| 5816 | boolean mHasTransformation; |
| 5817 | boolean mHasLocalTransformation; |
| 5818 | final Transformation mTransformation = new Transformation(); |
| 5819 | |
| Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 5820 | // If a window showing a wallpaper: the requested offset for the |
| 5821 | // wallpaper; if a wallpaper window: the currently applied offset. |
| 5822 | float mWallpaperX = -1; |
| 5823 | float mWallpaperY = -1; |
| Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 5824 | |
| 5825 | // If a window showing a wallpaper: what fraction of the offset |
| 5826 | // range corresponds to a full virtual screen. |
| 5827 | float mWallpaperXStep = -1; |
| 5828 | float mWallpaperYStep = -1; |
| 5829 | |
| Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 5830 | // Wallpaper windows: pixels offset based on above variables. |
| 5831 | int mXOffset; |
| 5832 | int mYOffset; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 5833 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5834 | // This is set after IWindowSession.relayout() has been called at |
| 5835 | // least once for the window. It allows us to detect the situation |
| 5836 | // where we don't yet have a surface, but should have one soon, so |
| 5837 | // we can give the window focus before waiting for the relayout. |
| 5838 | boolean mRelayoutCalled; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5839 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5840 | // This is set after the Surface has been created but before the |
| 5841 | // window has been drawn. During this time the surface is hidden. |
| 5842 | boolean mDrawPending; |
| 5843 | |
| 5844 | // This is set after the window has finished drawing for the first |
| 5845 | // time but before its surface is shown. The surface will be |
| 5846 | // displayed when the next layout is run. |
| 5847 | boolean mCommitDrawPending; |
| 5848 | |
| 5849 | // This is set during the time after the window's drawing has been |
| 5850 | // committed, and before its surface is actually shown. It is used |
| 5851 | // to delay showing the surface until all windows in a token are ready |
| 5852 | // to be shown. |
| 5853 | boolean mReadyToShow; |
| 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 | // Set when the window has been shown in the screen the first time. |
| 5856 | boolean mHasDrawn; |
| 5857 | |
| 5858 | // Currently running an exit animation? |
| 5859 | boolean mExiting; |
| 5860 | |
| 5861 | // Currently on the mDestroySurface list? |
| 5862 | boolean mDestroying; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5863 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5864 | // Completely remove from window manager after exit animation? |
| 5865 | boolean mRemoveOnExit; |
| 5866 | |
| 5867 | // Set when the orientation is changing and this window has not yet |
| 5868 | // been updated for the new orientation. |
| 5869 | boolean mOrientationChanging; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5870 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5871 | // Is this window now (or just being) removed? |
| 5872 | boolean mRemoved; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5873 | |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 5874 | // For debugging, this is the last information given to the surface flinger. |
| 5875 | boolean mSurfaceShown; |
| 5876 | int mSurfaceX, mSurfaceY, mSurfaceW, mSurfaceH; |
| 5877 | int mSurfaceLayer; |
| 5878 | float mSurfaceAlpha; |
| 5879 | |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5880 | // Input channel |
| 5881 | InputChannel mInputChannel; |
| 5882 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5883 | WindowState(Session s, IWindow c, WindowToken token, |
| 5884 | WindowState attachedWindow, WindowManager.LayoutParams a, |
| 5885 | int viewVisibility) { |
| 5886 | mSession = s; |
| 5887 | mClient = c; |
| 5888 | mToken = token; |
| 5889 | mAttrs.copyFrom(a); |
| 5890 | mViewVisibility = viewVisibility; |
| 5891 | DeathRecipient deathRecipient = new DeathRecipient(); |
| 5892 | mAlpha = a.alpha; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5893 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5894 | TAG, "Window " + this + " client=" + c.asBinder() |
| 5895 | + " token=" + token + " (" + mAttrs.token + ")"); |
| 5896 | try { |
| 5897 | c.asBinder().linkToDeath(deathRecipient, 0); |
| 5898 | } catch (RemoteException e) { |
| 5899 | mDeathRecipient = null; |
| 5900 | mAttachedWindow = null; |
| 5901 | mLayoutAttached = false; |
| 5902 | mIsImWindow = false; |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 5903 | mIsWallpaper = false; |
| 5904 | mIsFloatingLayer = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5905 | mBaseLayer = 0; |
| 5906 | mSubLayer = 0; |
| 5907 | return; |
| 5908 | } |
| 5909 | mDeathRecipient = deathRecipient; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5910 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5911 | if ((mAttrs.type >= FIRST_SUB_WINDOW && |
| 5912 | mAttrs.type <= LAST_SUB_WINDOW)) { |
| 5913 | // The multiplier here is to reserve space for multiple |
| 5914 | // windows in the same type layer. |
| 5915 | mBaseLayer = mPolicy.windowTypeToLayerLw( |
| 5916 | attachedWindow.mAttrs.type) * TYPE_LAYER_MULTIPLIER |
| 5917 | + TYPE_LAYER_OFFSET; |
| 5918 | mSubLayer = mPolicy.subWindowTypeToLayerLw(a.type); |
| 5919 | mAttachedWindow = attachedWindow; |
| 5920 | mAttachedWindow.mChildWindows.add(this); |
| 5921 | mLayoutAttached = mAttrs.type != |
| 5922 | WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG; |
| 5923 | mIsImWindow = attachedWindow.mAttrs.type == TYPE_INPUT_METHOD |
| 5924 | || attachedWindow.mAttrs.type == TYPE_INPUT_METHOD_DIALOG; |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 5925 | mIsWallpaper = attachedWindow.mAttrs.type == TYPE_WALLPAPER; |
| 5926 | mIsFloatingLayer = mIsImWindow || mIsWallpaper; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5927 | } else { |
| 5928 | // The multiplier here is to reserve space for multiple |
| 5929 | // windows in the same type layer. |
| 5930 | mBaseLayer = mPolicy.windowTypeToLayerLw(a.type) |
| 5931 | * TYPE_LAYER_MULTIPLIER |
| 5932 | + TYPE_LAYER_OFFSET; |
| 5933 | mSubLayer = 0; |
| 5934 | mAttachedWindow = null; |
| 5935 | mLayoutAttached = false; |
| 5936 | mIsImWindow = mAttrs.type == TYPE_INPUT_METHOD |
| 5937 | || mAttrs.type == TYPE_INPUT_METHOD_DIALOG; |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 5938 | mIsWallpaper = mAttrs.type == TYPE_WALLPAPER; |
| 5939 | mIsFloatingLayer = mIsImWindow || mIsWallpaper; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5940 | } |
| 5941 | |
| 5942 | WindowState appWin = this; |
| 5943 | while (appWin.mAttachedWindow != null) { |
| 5944 | appWin = mAttachedWindow; |
| 5945 | } |
| 5946 | WindowToken appToken = appWin.mToken; |
| 5947 | while (appToken.appWindowToken == null) { |
| 5948 | WindowToken parent = mTokenMap.get(appToken.token); |
| 5949 | if (parent == null || appToken == parent) { |
| 5950 | break; |
| 5951 | } |
| 5952 | appToken = parent; |
| 5953 | } |
| The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 5954 | mRootToken = appToken; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5955 | mAppToken = appToken.appWindowToken; |
| 5956 | |
| 5957 | mSurface = null; |
| 5958 | mRequestedWidth = 0; |
| 5959 | mRequestedHeight = 0; |
| 5960 | mLastRequestedWidth = 0; |
| 5961 | mLastRequestedHeight = 0; |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 5962 | mXOffset = 0; |
| 5963 | mYOffset = 0; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5964 | mLayer = 0; |
| 5965 | mAnimLayer = 0; |
| 5966 | mLastLayer = 0; |
| 5967 | } |
| 5968 | |
| 5969 | void attach() { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5970 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5971 | TAG, "Attaching " + this + " token=" + mToken |
| 5972 | + ", list=" + mToken.windows); |
| 5973 | mSession.windowAddedLocked(); |
| 5974 | } |
| 5975 | |
| 5976 | public void computeFrameLw(Rect pf, Rect df, Rect cf, Rect vf) { |
| 5977 | mHaveFrame = true; |
| 5978 | |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 5979 | final Rect container = mContainingFrame; |
| 5980 | container.set(pf); |
| 5981 | |
| 5982 | final Rect display = mDisplayFrame; |
| 5983 | display.set(df); |
| 5984 | |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 5985 | if ((mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0) { |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 5986 | container.intersect(mCompatibleScreenFrame); |
| Mitsuru Oshima | d2967e2 | 2009-07-20 14:01:43 -0700 | [diff] [blame] | 5987 | if ((mAttrs.flags & FLAG_LAYOUT_NO_LIMITS) == 0) { |
| 5988 | display.intersect(mCompatibleScreenFrame); |
| 5989 | } |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 5990 | } |
| 5991 | |
| 5992 | final int pw = container.right - container.left; |
| 5993 | final int ph = container.bottom - container.top; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5994 | |
| 5995 | int w,h; |
| 5996 | if ((mAttrs.flags & mAttrs.FLAG_SCALED) != 0) { |
| 5997 | w = mAttrs.width < 0 ? pw : mAttrs.width; |
| 5998 | h = mAttrs.height< 0 ? ph : mAttrs.height; |
| 5999 | } else { |
| Romain Guy | 980a938 | 2010-01-08 15:06:28 -0800 | [diff] [blame] | 6000 | w = mAttrs.width == mAttrs.MATCH_PARENT ? pw : mRequestedWidth; |
| 6001 | h = mAttrs.height== mAttrs.MATCH_PARENT ? ph : mRequestedHeight; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6002 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6003 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6004 | final Rect content = mContentFrame; |
| 6005 | content.set(cf); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6006 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6007 | final Rect visible = mVisibleFrame; |
| 6008 | visible.set(vf); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6009 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6010 | final Rect frame = mFrame; |
| Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 6011 | final int fw = frame.width(); |
| 6012 | final int fh = frame.height(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6013 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6014 | //System.out.println("In: w=" + w + " h=" + h + " container=" + |
| 6015 | // container + " x=" + mAttrs.x + " y=" + mAttrs.y); |
| 6016 | |
| 6017 | Gravity.apply(mAttrs.gravity, w, h, container, |
| 6018 | (int) (mAttrs.x + mAttrs.horizontalMargin * pw), |
| 6019 | (int) (mAttrs.y + mAttrs.verticalMargin * ph), frame); |
| 6020 | |
| 6021 | //System.out.println("Out: " + mFrame); |
| 6022 | |
| 6023 | // Now make sure the window fits in the overall display. |
| 6024 | Gravity.applyDisplay(mAttrs.gravity, df, frame); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6025 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6026 | // Make sure the content and visible frames are inside of the |
| 6027 | // final window frame. |
| 6028 | if (content.left < frame.left) content.left = frame.left; |
| 6029 | if (content.top < frame.top) content.top = frame.top; |
| 6030 | if (content.right > frame.right) content.right = frame.right; |
| 6031 | if (content.bottom > frame.bottom) content.bottom = frame.bottom; |
| 6032 | if (visible.left < frame.left) visible.left = frame.left; |
| 6033 | if (visible.top < frame.top) visible.top = frame.top; |
| 6034 | if (visible.right > frame.right) visible.right = frame.right; |
| 6035 | if (visible.bottom > frame.bottom) visible.bottom = frame.bottom; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6036 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6037 | final Rect contentInsets = mContentInsets; |
| 6038 | contentInsets.left = content.left-frame.left; |
| 6039 | contentInsets.top = content.top-frame.top; |
| 6040 | contentInsets.right = frame.right-content.right; |
| 6041 | contentInsets.bottom = frame.bottom-content.bottom; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6042 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6043 | final Rect visibleInsets = mVisibleInsets; |
| 6044 | visibleInsets.left = visible.left-frame.left; |
| 6045 | visibleInsets.top = visible.top-frame.top; |
| 6046 | visibleInsets.right = frame.right-visible.right; |
| 6047 | visibleInsets.bottom = frame.bottom-visible.bottom; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6048 | |
| Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 6049 | if (mIsWallpaper && (fw != frame.width() || fh != frame.height())) { |
| 6050 | updateWallpaperOffsetLocked(this, mDisplay.getWidth(), |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 6051 | mDisplay.getHeight(), false); |
| Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 6052 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6053 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6054 | if (localLOGV) { |
| 6055 | //if ("com.google.android.youtube".equals(mAttrs.packageName) |
| 6056 | // && mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_PANEL) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6057 | Slog.v(TAG, "Resolving (mRequestedWidth=" |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6058 | + mRequestedWidth + ", mRequestedheight=" |
| 6059 | + mRequestedHeight + ") to" + " (pw=" + pw + ", ph=" + ph |
| 6060 | + "): frame=" + mFrame.toShortString() |
| 6061 | + " ci=" + contentInsets.toShortString() |
| 6062 | + " vi=" + visibleInsets.toShortString()); |
| 6063 | //} |
| 6064 | } |
| 6065 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6066 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6067 | public Rect getFrameLw() { |
| 6068 | return mFrame; |
| 6069 | } |
| 6070 | |
| 6071 | public Rect getShownFrameLw() { |
| 6072 | return mShownFrame; |
| 6073 | } |
| 6074 | |
| 6075 | public Rect getDisplayFrameLw() { |
| 6076 | return mDisplayFrame; |
| 6077 | } |
| 6078 | |
| 6079 | public Rect getContentFrameLw() { |
| 6080 | return mContentFrame; |
| 6081 | } |
| 6082 | |
| 6083 | public Rect getVisibleFrameLw() { |
| 6084 | return mVisibleFrame; |
| 6085 | } |
| 6086 | |
| 6087 | public boolean getGivenInsetsPendingLw() { |
| 6088 | return mGivenInsetsPending; |
| 6089 | } |
| 6090 | |
| 6091 | public Rect getGivenContentInsetsLw() { |
| 6092 | return mGivenContentInsets; |
| 6093 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6094 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6095 | public Rect getGivenVisibleInsetsLw() { |
| 6096 | return mGivenVisibleInsets; |
| 6097 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6098 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6099 | public WindowManager.LayoutParams getAttrs() { |
| 6100 | return mAttrs; |
| 6101 | } |
| 6102 | |
| 6103 | public int getSurfaceLayer() { |
| 6104 | return mLayer; |
| 6105 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6106 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6107 | public IApplicationToken getAppToken() { |
| 6108 | return mAppToken != null ? mAppToken.appToken : null; |
| 6109 | } |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 6110 | |
| 6111 | public long getInputDispatchingTimeoutNanos() { |
| 6112 | return mAppToken != null |
| 6113 | ? mAppToken.inputDispatchingTimeoutNanos |
| 6114 | : DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS; |
| 6115 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6116 | |
| 6117 | public boolean hasAppShownWindows() { |
| 6118 | return mAppToken != null ? mAppToken.firstWindowDrawn : false; |
| 6119 | } |
| 6120 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6121 | public void setAnimation(Animation anim) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6122 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6123 | TAG, "Setting animation in " + this + ": " + anim); |
| 6124 | mAnimating = false; |
| 6125 | mLocalAnimating = false; |
| 6126 | mAnimation = anim; |
| 6127 | mAnimation.restrictDuration(MAX_ANIMATION_DURATION); |
| 6128 | mAnimation.scaleCurrentDuration(mWindowAnimationScale); |
| 6129 | } |
| 6130 | |
| 6131 | public void clearAnimation() { |
| 6132 | if (mAnimation != null) { |
| 6133 | mAnimating = true; |
| 6134 | mLocalAnimating = false; |
| 6135 | mAnimation = null; |
| 6136 | } |
| 6137 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6138 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6139 | Surface createSurfaceLocked() { |
| 6140 | if (mSurface == null) { |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 6141 | mReportDestroySurface = false; |
| 6142 | mSurfacePendingDestroy = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6143 | mDrawPending = true; |
| 6144 | mCommitDrawPending = false; |
| 6145 | mReadyToShow = false; |
| 6146 | if (mAppToken != null) { |
| 6147 | mAppToken.allDrawn = false; |
| 6148 | } |
| 6149 | |
| 6150 | int flags = 0; |
| Mathias Agopian | 317a628 | 2009-08-13 17:29:02 -0700 | [diff] [blame] | 6151 | if (mAttrs.memoryType == MEMORY_TYPE_PUSH_BUFFERS) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6152 | flags |= Surface.PUSH_BUFFERS; |
| 6153 | } |
| 6154 | |
| 6155 | if ((mAttrs.flags&WindowManager.LayoutParams.FLAG_SECURE) != 0) { |
| 6156 | flags |= Surface.SECURE; |
| 6157 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6158 | if (DEBUG_VISIBILITY) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6159 | TAG, "Creating surface in session " |
| 6160 | + mSession.mSurfaceSession + " window " + this |
| 6161 | + " w=" + mFrame.width() |
| 6162 | + " h=" + mFrame.height() + " format=" |
| 6163 | + mAttrs.format + " flags=" + flags); |
| 6164 | |
| 6165 | int w = mFrame.width(); |
| 6166 | int h = mFrame.height(); |
| 6167 | if ((mAttrs.flags & LayoutParams.FLAG_SCALED) != 0) { |
| 6168 | // for a scaled surface, we always want the requested |
| 6169 | // size. |
| 6170 | w = mRequestedWidth; |
| 6171 | h = mRequestedHeight; |
| 6172 | } |
| 6173 | |
| Romain Guy | 9825ec6 | 2009-10-01 00:58:09 -0700 | [diff] [blame] | 6174 | // Something is wrong and SurfaceFlinger will not like this, |
| 6175 | // try to revert to sane values |
| 6176 | if (w <= 0) w = 1; |
| 6177 | if (h <= 0) h = 1; |
| 6178 | |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 6179 | mSurfaceShown = false; |
| 6180 | mSurfaceLayer = 0; |
| 6181 | mSurfaceAlpha = 1; |
| 6182 | mSurfaceX = 0; |
| 6183 | mSurfaceY = 0; |
| 6184 | mSurfaceW = w; |
| 6185 | mSurfaceH = h; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6186 | try { |
| 6187 | mSurface = new Surface( |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6188 | mSession.mSurfaceSession, mSession.mPid, |
| Mathias Agopian | 5d26c1e | 2010-03-01 16:09:43 -0800 | [diff] [blame] | 6189 | mAttrs.getTitle().toString(), |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6190 | 0, w, h, mAttrs.format, flags); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6191 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " CREATE SURFACE " |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 6192 | + mSurface + " IN SESSION " |
| 6193 | + mSession.mSurfaceSession |
| 6194 | + ": pid=" + mSession.mPid + " format=" |
| 6195 | + mAttrs.format + " flags=0x" |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 6196 | + Integer.toHexString(flags) |
| 6197 | + " / " + this); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6198 | } catch (Surface.OutOfResourcesException e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6199 | Slog.w(TAG, "OutOfResourcesException creating surface"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6200 | reclaimSomeSurfaceMemoryLocked(this, "create"); |
| 6201 | return null; |
| 6202 | } catch (Exception e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6203 | Slog.e(TAG, "Exception creating surface", e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6204 | return null; |
| 6205 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6206 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6207 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6208 | TAG, "Got surface: " + mSurface |
| 6209 | + ", set left=" + mFrame.left + " top=" + mFrame.top |
| 6210 | + ", animLayer=" + mAnimLayer); |
| 6211 | if (SHOW_TRANSACTIONS) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6212 | Slog.i(TAG, ">>> OPEN TRANSACTION"); |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 6213 | if (SHOW_TRANSACTIONS) logSurface(this, |
| 6214 | "CREATE pos=(" + mFrame.left + "," + mFrame.top + ") (" + |
| 6215 | mFrame.width() + "x" + mFrame.height() + "), layer=" + |
| 6216 | mAnimLayer + " HIDE", null); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6217 | } |
| 6218 | Surface.openTransaction(); |
| 6219 | try { |
| 6220 | try { |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 6221 | mSurfaceX = mFrame.left + mXOffset; |
| Dianne Hackborn | 529bef6 | 2010-03-25 11:48:43 -0700 | [diff] [blame] | 6222 | mSurfaceY = mFrame.top + mYOffset; |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 6223 | mSurface.setPosition(mSurfaceX, mSurfaceY); |
| 6224 | mSurfaceLayer = mAnimLayer; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6225 | mSurface.setLayer(mAnimLayer); |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 6226 | mSurfaceShown = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6227 | mSurface.hide(); |
| 6228 | if ((mAttrs.flags&WindowManager.LayoutParams.FLAG_DITHER) != 0) { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 6229 | if (SHOW_TRANSACTIONS) logSurface(this, "DITHER", null); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6230 | mSurface.setFlags(Surface.SURFACE_DITHER, |
| 6231 | Surface.SURFACE_DITHER); |
| 6232 | } |
| 6233 | } catch (RuntimeException e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6234 | Slog.w(TAG, "Error creating surface in " + w, e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6235 | reclaimSomeSurfaceMemoryLocked(this, "create-init"); |
| 6236 | } |
| 6237 | mLastHidden = true; |
| 6238 | } finally { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6239 | if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6240 | Surface.closeTransaction(); |
| 6241 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6242 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6243 | TAG, "Created surface " + this); |
| 6244 | } |
| 6245 | return mSurface; |
| 6246 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6247 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6248 | void destroySurfaceLocked() { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6249 | if (mAppToken != null && this == mAppToken.startingWindow) { |
| 6250 | mAppToken.startingDisplayed = false; |
| 6251 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6252 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6253 | if (mSurface != null) { |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 6254 | mDrawPending = false; |
| 6255 | mCommitDrawPending = false; |
| 6256 | mReadyToShow = false; |
| 6257 | |
| 6258 | int i = mChildWindows.size(); |
| 6259 | while (i > 0) { |
| 6260 | i--; |
| 6261 | WindowState c = (WindowState)mChildWindows.get(i); |
| 6262 | c.mAttachedHidden = true; |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 6263 | |
| Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 6264 | mInputMonitor.windowIsBecomingInvisibleLw(c); |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 6265 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6266 | |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 6267 | if (mReportDestroySurface) { |
| 6268 | mReportDestroySurface = false; |
| 6269 | mSurfacePendingDestroy = true; |
| 6270 | try { |
| 6271 | mClient.dispatchGetNewSurface(); |
| 6272 | // We'll really destroy on the next time around. |
| 6273 | return; |
| 6274 | } catch (RemoteException e) { |
| 6275 | } |
| 6276 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6277 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6278 | try { |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 6279 | if (DEBUG_VISIBILITY) { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 6280 | RuntimeException e = null; |
| 6281 | if (!HIDE_STACK_CRAWLS) { |
| 6282 | e = new RuntimeException(); |
| 6283 | e.fillInStackTrace(); |
| 6284 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6285 | Slog.w(TAG, "Window " + this + " destroying surface " |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 6286 | + mSurface + ", session " + mSession, e); |
| 6287 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6288 | if (SHOW_TRANSACTIONS) { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 6289 | RuntimeException e = null; |
| 6290 | if (!HIDE_STACK_CRAWLS) { |
| 6291 | e = new RuntimeException(); |
| 6292 | e.fillInStackTrace(); |
| 6293 | } |
| 6294 | if (SHOW_TRANSACTIONS) logSurface(this, "DESTROY", e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6295 | } |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 6296 | mSurface.destroy(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6297 | } catch (RuntimeException e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6298 | Slog.w(TAG, "Exception thrown when destroying Window " + this |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6299 | + " surface " + mSurface + " session " + mSession |
| 6300 | + ": " + e.toString()); |
| 6301 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6302 | |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 6303 | mSurfaceShown = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6304 | mSurface = null; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6305 | } |
| 6306 | } |
| 6307 | |
| 6308 | boolean finishDrawingLocked() { |
| 6309 | if (mDrawPending) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6310 | if (SHOW_TRANSACTIONS || DEBUG_ORIENTATION) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6311 | TAG, "finishDrawingLocked: " + mSurface); |
| 6312 | mCommitDrawPending = true; |
| 6313 | mDrawPending = false; |
| 6314 | return true; |
| 6315 | } |
| 6316 | return false; |
| 6317 | } |
| 6318 | |
| 6319 | // This must be called while inside a transaction. |
| Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 6320 | boolean commitFinishDrawingLocked(long currentTime) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6321 | //Slog.i(TAG, "commitFinishDrawingLocked: " + mSurface); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6322 | if (!mCommitDrawPending) { |
| Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 6323 | return false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6324 | } |
| 6325 | mCommitDrawPending = false; |
| 6326 | mReadyToShow = true; |
| 6327 | final boolean starting = mAttrs.type == TYPE_APPLICATION_STARTING; |
| 6328 | final AppWindowToken atoken = mAppToken; |
| 6329 | if (atoken == null || atoken.allDrawn || starting) { |
| 6330 | performShowLocked(); |
| 6331 | } |
| Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 6332 | return true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6333 | } |
| 6334 | |
| 6335 | // This must be called while inside a transaction. |
| 6336 | boolean performShowLocked() { |
| 6337 | if (DEBUG_VISIBILITY) { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 6338 | RuntimeException e = null; |
| 6339 | if (!HIDE_STACK_CRAWLS) { |
| 6340 | e = new RuntimeException(); |
| 6341 | e.fillInStackTrace(); |
| 6342 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6343 | Slog.v(TAG, "performShow on " + this |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6344 | + ": readyToShow=" + mReadyToShow + " readyForDisplay=" + isReadyForDisplay() |
| 6345 | + " starting=" + (mAttrs.type == TYPE_APPLICATION_STARTING), e); |
| 6346 | } |
| 6347 | if (mReadyToShow && isReadyForDisplay()) { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 6348 | if (SHOW_TRANSACTIONS || DEBUG_ORIENTATION) logSurface(this, |
| 6349 | "SHOW (performShowLocked)", null); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6350 | if (DEBUG_VISIBILITY) Slog.v(TAG, "Showing " + this |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6351 | + " during animation: policyVis=" + mPolicyVisibility |
| 6352 | + " attHidden=" + mAttachedHidden |
| 6353 | + " tok.hiddenRequested=" |
| 6354 | + (mAppToken != null ? mAppToken.hiddenRequested : false) |
| Dianne Hackborn | 248b188 | 2009-09-16 16:46:44 -0700 | [diff] [blame] | 6355 | + " tok.hidden=" |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6356 | + (mAppToken != null ? mAppToken.hidden : false) |
| 6357 | + " animating=" + mAnimating |
| 6358 | + " tok animating=" |
| 6359 | + (mAppToken != null ? mAppToken.animating : false)); |
| 6360 | if (!showSurfaceRobustlyLocked(this)) { |
| 6361 | return false; |
| 6362 | } |
| 6363 | mLastAlpha = -1; |
| 6364 | mHasDrawn = true; |
| 6365 | mLastHidden = false; |
| 6366 | mReadyToShow = false; |
| 6367 | enableScreenIfNeededLocked(); |
| 6368 | |
| 6369 | applyEnterAnimationLocked(this); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6370 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6371 | int i = mChildWindows.size(); |
| 6372 | while (i > 0) { |
| 6373 | i--; |
| 6374 | WindowState c = (WindowState)mChildWindows.get(i); |
| Dianne Hackborn | f09c1a2 | 2010-04-22 15:59:21 -0700 | [diff] [blame] | 6375 | if (c.mAttachedHidden) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6376 | c.mAttachedHidden = false; |
| Dianne Hackborn | f09c1a2 | 2010-04-22 15:59:21 -0700 | [diff] [blame] | 6377 | if (c.mSurface != null) { |
| 6378 | c.performShowLocked(); |
| 6379 | // It hadn't been shown, which means layout not |
| 6380 | // performed on it, so now we want to make sure to |
| 6381 | // do a layout. If called from within the transaction |
| 6382 | // loop, this will cause it to restart with a new |
| 6383 | // layout. |
| 6384 | mLayoutNeeded = true; |
| 6385 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6386 | } |
| 6387 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6388 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6389 | if (mAttrs.type != TYPE_APPLICATION_STARTING |
| 6390 | && mAppToken != null) { |
| 6391 | mAppToken.firstWindowDrawn = true; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6392 | |
| Dianne Hackborn | 248b188 | 2009-09-16 16:46:44 -0700 | [diff] [blame] | 6393 | if (mAppToken.startingData != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6394 | if (DEBUG_STARTING_WINDOW || DEBUG_ANIM) Slog.v(TAG, |
| Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 6395 | "Finish starting " + mToken |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6396 | + ": first real window is shown, no animation"); |
| Dianne Hackborn | 248b188 | 2009-09-16 16:46:44 -0700 | [diff] [blame] | 6397 | // If this initial window is animating, stop it -- we |
| 6398 | // will do an animation to reveal it from behind the |
| 6399 | // starting window, so there is no need for it to also |
| 6400 | // be doing its own stuff. |
| 6401 | if (mAnimation != null) { |
| 6402 | mAnimation = null; |
| 6403 | // Make sure we clean up the animation. |
| 6404 | mAnimating = true; |
| 6405 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6406 | mFinishedStarting.add(mAppToken); |
| 6407 | mH.sendEmptyMessage(H.FINISHED_STARTING); |
| 6408 | } |
| 6409 | mAppToken.updateReportedVisibilityLocked(); |
| 6410 | } |
| 6411 | } |
| 6412 | return true; |
| 6413 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6414 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6415 | // This must be called while inside a transaction. Returns true if |
| 6416 | // there is more animation to run. |
| 6417 | boolean stepAnimationLocked(long currentTime, int dw, int dh) { |
| Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 6418 | if (!mDisplayFrozen && mPolicy.isScreenOn()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6419 | // We will run animations as long as the display isn't frozen. |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6420 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6421 | if (!mDrawPending && !mCommitDrawPending && mAnimation != null) { |
| 6422 | mHasTransformation = true; |
| 6423 | mHasLocalTransformation = true; |
| 6424 | if (!mLocalAnimating) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6425 | if (DEBUG_ANIM) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6426 | TAG, "Starting animation in " + this + |
| 6427 | " @ " + currentTime + ": ww=" + mFrame.width() + " wh=" + mFrame.height() + |
| 6428 | " dw=" + dw + " dh=" + dh + " scale=" + mWindowAnimationScale); |
| 6429 | mAnimation.initialize(mFrame.width(), mFrame.height(), dw, dh); |
| 6430 | mAnimation.setStartTime(currentTime); |
| 6431 | mLocalAnimating = true; |
| 6432 | mAnimating = true; |
| 6433 | } |
| 6434 | mTransformation.clear(); |
| 6435 | final boolean more = mAnimation.getTransformation( |
| 6436 | currentTime, mTransformation); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6437 | if (DEBUG_ANIM) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6438 | TAG, "Stepped animation in " + this + |
| 6439 | ": more=" + more + ", xform=" + mTransformation); |
| 6440 | if (more) { |
| 6441 | // we're not done! |
| 6442 | return true; |
| 6443 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6444 | if (DEBUG_ANIM) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6445 | TAG, "Finished animation in " + this + |
| 6446 | " @ " + currentTime); |
| 6447 | mAnimation = null; |
| 6448 | //WindowManagerService.this.dump(); |
| 6449 | } |
| 6450 | mHasLocalTransformation = false; |
| 6451 | if ((!mLocalAnimating || mAnimationIsEntrance) && mAppToken != null |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 6452 | && mAppToken.animation != null) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6453 | // When our app token is animating, we kind-of pretend like |
| 6454 | // we are as well. Note the mLocalAnimating mAnimationIsEntrance |
| 6455 | // part of this check means that we will only do this if |
| 6456 | // our window is not currently exiting, or it is not |
| 6457 | // locally animating itself. The idea being that one that |
| 6458 | // is exiting and doing a local animation should be removed |
| 6459 | // once that animation is done. |
| 6460 | mAnimating = true; |
| 6461 | mHasTransformation = true; |
| 6462 | mTransformation.clear(); |
| 6463 | return false; |
| 6464 | } else if (mHasTransformation) { |
| 6465 | // Little trick to get through the path below to act like |
| 6466 | // we have finished an animation. |
| 6467 | mAnimating = true; |
| 6468 | } else if (isAnimating()) { |
| 6469 | mAnimating = true; |
| 6470 | } |
| 6471 | } else if (mAnimation != null) { |
| 6472 | // If the display is frozen, and there is a pending animation, |
| 6473 | // clear it and make sure we run the cleanup code. |
| 6474 | mAnimating = true; |
| 6475 | mLocalAnimating = true; |
| 6476 | mAnimation = null; |
| 6477 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6478 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6479 | if (!mAnimating && !mLocalAnimating) { |
| 6480 | return false; |
| 6481 | } |
| 6482 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6483 | if (DEBUG_ANIM) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6484 | TAG, "Animation done in " + this + ": exiting=" + mExiting |
| 6485 | + ", reportedVisible=" |
| 6486 | + (mAppToken != null ? mAppToken.reportedVisible : false)); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6487 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6488 | mAnimating = false; |
| 6489 | mLocalAnimating = false; |
| 6490 | mAnimation = null; |
| 6491 | mAnimLayer = mLayer; |
| 6492 | if (mIsImWindow) { |
| 6493 | mAnimLayer += mInputMethodAnimLayerAdjustment; |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 6494 | } else if (mIsWallpaper) { |
| 6495 | mAnimLayer += mWallpaperAnimLayerAdjustment; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6496 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6497 | if (DEBUG_LAYERS) Slog.v(TAG, "Stepping win " + this |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6498 | + " anim layer: " + mAnimLayer); |
| 6499 | mHasTransformation = false; |
| 6500 | mHasLocalTransformation = false; |
| Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 6501 | if (mPolicyVisibility != mPolicyVisibilityAfterAnim) { |
| 6502 | if (DEBUG_VISIBILITY) { |
| 6503 | Slog.v(TAG, "Policy visibility changing after anim in " + this + ": " |
| 6504 | + mPolicyVisibilityAfterAnim); |
| 6505 | } |
| 6506 | mPolicyVisibility = mPolicyVisibilityAfterAnim; |
| 6507 | if (!mPolicyVisibility) { |
| 6508 | if (mCurrentFocus == this) { |
| 6509 | mFocusMayChange = true; |
| 6510 | } |
| 6511 | // Window is no longer visible -- make sure if we were waiting |
| 6512 | // for it to be displayed before enabling the display, that |
| 6513 | // we allow the display to be enabled now. |
| 6514 | enableScreenIfNeededLocked(); |
| 6515 | } |
| Dianne Hackborn | f3bea9c | 2009-12-09 18:26:21 -0800 | [diff] [blame] | 6516 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6517 | mTransformation.clear(); |
| 6518 | if (mHasDrawn |
| 6519 | && mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING |
| 6520 | && mAppToken != null |
| 6521 | && mAppToken.firstWindowDrawn |
| 6522 | && mAppToken.startingData != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6523 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Finish starting " |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6524 | + mToken + ": first real window done animating"); |
| 6525 | mFinishedStarting.add(mAppToken); |
| 6526 | mH.sendEmptyMessage(H.FINISHED_STARTING); |
| 6527 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6528 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6529 | finishExit(); |
| 6530 | |
| 6531 | if (mAppToken != null) { |
| 6532 | mAppToken.updateReportedVisibilityLocked(); |
| 6533 | } |
| 6534 | |
| 6535 | return false; |
| 6536 | } |
| 6537 | |
| 6538 | void finishExit() { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6539 | if (DEBUG_ANIM) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6540 | TAG, "finishExit in " + this |
| 6541 | + ": exiting=" + mExiting |
| 6542 | + " remove=" + mRemoveOnExit |
| 6543 | + " windowAnimating=" + isWindowAnimating()); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6544 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6545 | final int N = mChildWindows.size(); |
| 6546 | for (int i=0; i<N; i++) { |
| 6547 | ((WindowState)mChildWindows.get(i)).finishExit(); |
| 6548 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6549 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6550 | if (!mExiting) { |
| 6551 | return; |
| 6552 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6553 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6554 | if (isWindowAnimating()) { |
| 6555 | return; |
| 6556 | } |
| 6557 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6558 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6559 | TAG, "Exit animation finished in " + this |
| 6560 | + ": remove=" + mRemoveOnExit); |
| 6561 | if (mSurface != null) { |
| 6562 | mDestroySurface.add(this); |
| 6563 | mDestroying = true; |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 6564 | if (SHOW_TRANSACTIONS) logSurface(this, "HIDE (finishExit)", null); |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 6565 | mSurfaceShown = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6566 | try { |
| 6567 | mSurface.hide(); |
| 6568 | } catch (RuntimeException e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6569 | Slog.w(TAG, "Error hiding surface in " + this, e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6570 | } |
| 6571 | mLastHidden = true; |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 6572 | |
| Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 6573 | for (int i=0; i<N; i++) { |
| 6574 | mInputMonitor.windowIsBecomingInvisibleLw((WindowState)mChildWindows.get(i)); |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 6575 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6576 | } |
| 6577 | mExiting = false; |
| 6578 | if (mRemoveOnExit) { |
| 6579 | mPendingRemove.add(this); |
| 6580 | mRemoveOnExit = false; |
| 6581 | } |
| 6582 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6583 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6584 | boolean isIdentityMatrix(float dsdx, float dtdx, float dsdy, float dtdy) { |
| 6585 | if (dsdx < .99999f || dsdx > 1.00001f) return false; |
| 6586 | if (dtdy < .99999f || dtdy > 1.00001f) return false; |
| 6587 | if (dtdx < -.000001f || dtdx > .000001f) return false; |
| 6588 | if (dsdy < -.000001f || dsdy > .000001f) return false; |
| 6589 | return true; |
| 6590 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6591 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6592 | void computeShownFrameLocked() { |
| 6593 | final boolean selfTransformation = mHasLocalTransformation; |
| 6594 | Transformation attachedTransformation = |
| 6595 | (mAttachedWindow != null && mAttachedWindow.mHasLocalTransformation) |
| 6596 | ? mAttachedWindow.mTransformation : null; |
| 6597 | Transformation appTransformation = |
| 6598 | (mAppToken != null && mAppToken.hasTransformation) |
| 6599 | ? mAppToken.transformation : null; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6600 | |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 6601 | // Wallpapers are animated based on the "real" window they |
| 6602 | // are currently targeting. |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 6603 | if (mAttrs.type == TYPE_WALLPAPER && mLowerWallpaperTarget == null |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 6604 | && mWallpaperTarget != null) { |
| Dianne Hackborn | 5baba16 | 2009-09-23 17:01:12 -0700 | [diff] [blame] | 6605 | if (mWallpaperTarget.mHasLocalTransformation && |
| 6606 | mWallpaperTarget.mAnimation != null && |
| 6607 | !mWallpaperTarget.mAnimation.getDetachWallpaper()) { |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 6608 | attachedTransformation = mWallpaperTarget.mTransformation; |
| Dianne Hackborn | 5baba16 | 2009-09-23 17:01:12 -0700 | [diff] [blame] | 6609 | if (DEBUG_WALLPAPER && attachedTransformation != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6610 | Slog.v(TAG, "WP target attached xform: " + attachedTransformation); |
| Dianne Hackborn | 5baba16 | 2009-09-23 17:01:12 -0700 | [diff] [blame] | 6611 | } |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 6612 | } |
| 6613 | if (mWallpaperTarget.mAppToken != null && |
| Dianne Hackborn | 5baba16 | 2009-09-23 17:01:12 -0700 | [diff] [blame] | 6614 | mWallpaperTarget.mAppToken.hasTransformation && |
| 6615 | mWallpaperTarget.mAppToken.animation != null && |
| 6616 | !mWallpaperTarget.mAppToken.animation.getDetachWallpaper()) { |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 6617 | appTransformation = mWallpaperTarget.mAppToken.transformation; |
| Dianne Hackborn | 5baba16 | 2009-09-23 17:01:12 -0700 | [diff] [blame] | 6618 | if (DEBUG_WALLPAPER && appTransformation != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6619 | Slog.v(TAG, "WP target app xform: " + appTransformation); |
| Dianne Hackborn | 5baba16 | 2009-09-23 17:01:12 -0700 | [diff] [blame] | 6620 | } |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 6621 | } |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 6622 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6623 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6624 | if (selfTransformation || attachedTransformation != null |
| 6625 | || appTransformation != null) { |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6626 | // cache often used attributes locally |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6627 | final Rect frame = mFrame; |
| 6628 | final float tmpFloats[] = mTmpFloats; |
| 6629 | final Matrix tmpMatrix = mTmpMatrix; |
| 6630 | |
| 6631 | // Compute the desired transformation. |
| Dianne Hackborn | 65c2387 | 2009-09-18 17:47:02 -0700 | [diff] [blame] | 6632 | tmpMatrix.setTranslate(0, 0); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6633 | if (selfTransformation) { |
| Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 6634 | tmpMatrix.postConcat(mTransformation.getMatrix()); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6635 | } |
| Dianne Hackborn | 65c2387 | 2009-09-18 17:47:02 -0700 | [diff] [blame] | 6636 | tmpMatrix.postTranslate(frame.left, frame.top); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6637 | if (attachedTransformation != null) { |
| Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 6638 | tmpMatrix.postConcat(attachedTransformation.getMatrix()); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6639 | } |
| 6640 | if (appTransformation != null) { |
| Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 6641 | tmpMatrix.postConcat(appTransformation.getMatrix()); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6642 | } |
| 6643 | |
| 6644 | // "convert" it into SurfaceFlinger's format |
| 6645 | // (a 2x2 matrix + an offset) |
| 6646 | // Here we must not transform the position of the surface |
| 6647 | // since it is already included in the transformation. |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6648 | //Slog.i(TAG, "Transform: " + matrix); |
| 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 | tmpMatrix.getValues(tmpFloats); |
| 6651 | mDsDx = tmpFloats[Matrix.MSCALE_X]; |
| 6652 | mDtDx = tmpFloats[Matrix.MSKEW_X]; |
| 6653 | mDsDy = tmpFloats[Matrix.MSKEW_Y]; |
| 6654 | mDtDy = tmpFloats[Matrix.MSCALE_Y]; |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 6655 | int x = (int)tmpFloats[Matrix.MTRANS_X] + mXOffset; |
| 6656 | int y = (int)tmpFloats[Matrix.MTRANS_Y] + mYOffset; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6657 | int w = frame.width(); |
| 6658 | int h = frame.height(); |
| 6659 | mShownFrame.set(x, y, x+w, y+h); |
| 6660 | |
| 6661 | // Now set the alpha... but because our current hardware |
| 6662 | // can't do alpha transformation on a non-opaque surface, |
| 6663 | // turn it off if we are running an animation that is also |
| 6664 | // transforming since it is more important to have that |
| 6665 | // animation be smooth. |
| 6666 | mShownAlpha = mAlpha; |
| 6667 | if (!mLimitedAlphaCompositing |
| 6668 | || (!PixelFormat.formatHasAlpha(mAttrs.format) |
| 6669 | || (isIdentityMatrix(mDsDx, mDtDx, mDsDy, mDtDy) |
| 6670 | && x == frame.left && y == frame.top))) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6671 | //Slog.i(TAG, "Applying alpha transform"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6672 | if (selfTransformation) { |
| 6673 | mShownAlpha *= mTransformation.getAlpha(); |
| 6674 | } |
| 6675 | if (attachedTransformation != null) { |
| 6676 | mShownAlpha *= attachedTransformation.getAlpha(); |
| 6677 | } |
| 6678 | if (appTransformation != null) { |
| 6679 | mShownAlpha *= appTransformation.getAlpha(); |
| 6680 | } |
| 6681 | } else { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6682 | //Slog.i(TAG, "Not applying alpha transform"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6683 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6684 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6685 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6686 | TAG, "Continuing animation in " + this + |
| 6687 | ": " + mShownFrame + |
| 6688 | ", alpha=" + mTransformation.getAlpha()); |
| 6689 | return; |
| 6690 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6691 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6692 | mShownFrame.set(mFrame); |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 6693 | if (mXOffset != 0 || mYOffset != 0) { |
| 6694 | mShownFrame.offset(mXOffset, mYOffset); |
| 6695 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6696 | mShownAlpha = mAlpha; |
| 6697 | mDsDx = 1; |
| 6698 | mDtDx = 0; |
| 6699 | mDsDy = 0; |
| 6700 | mDtDy = 1; |
| 6701 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6702 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6703 | /** |
| 6704 | * Is this window visible? It is not visible if there is no |
| 6705 | * surface, or we are in the process of running an exit animation |
| 6706 | * that will remove the surface, or its app token has been hidden. |
| 6707 | */ |
| 6708 | public boolean isVisibleLw() { |
| 6709 | final AppWindowToken atoken = mAppToken; |
| 6710 | return mSurface != null && mPolicyVisibility && !mAttachedHidden |
| 6711 | && (atoken == null || !atoken.hiddenRequested) |
| 6712 | && !mExiting && !mDestroying; |
| 6713 | } |
| 6714 | |
| 6715 | /** |
| Dianne Hackborn | 3d163f07 | 2009-10-07 21:26:57 -0700 | [diff] [blame] | 6716 | * Like {@link #isVisibleLw}, but also counts a window that is currently |
| 6717 | * "hidden" behind the keyguard as visible. This allows us to apply |
| 6718 | * things like window flags that impact the keyguard. |
| 6719 | * XXX I am starting to think we need to have ANOTHER visibility flag |
| 6720 | * for this "hidden behind keyguard" state rather than overloading |
| 6721 | * mPolicyVisibility. Ungh. |
| 6722 | */ |
| 6723 | public boolean isVisibleOrBehindKeyguardLw() { |
| 6724 | final AppWindowToken atoken = mAppToken; |
| 6725 | return mSurface != null && !mAttachedHidden |
| 6726 | && (atoken == null ? mPolicyVisibility : !atoken.hiddenRequested) |
| Dianne Hackborn | 5943c20 | 2010-04-12 21:36:49 -0700 | [diff] [blame] | 6727 | && (mOrientationChanging || (!mDrawPending && !mCommitDrawPending)) |
| Dianne Hackborn | 3d163f07 | 2009-10-07 21:26:57 -0700 | [diff] [blame] | 6728 | && !mExiting && !mDestroying; |
| 6729 | } |
| 6730 | |
| 6731 | /** |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6732 | * Is this window visible, ignoring its app token? It is not visible |
| 6733 | * if there is no surface, or we are in the process of running an exit animation |
| 6734 | * that will remove the surface. |
| 6735 | */ |
| 6736 | public boolean isWinVisibleLw() { |
| 6737 | final AppWindowToken atoken = mAppToken; |
| 6738 | return mSurface != null && mPolicyVisibility && !mAttachedHidden |
| 6739 | && (atoken == null || !atoken.hiddenRequested || atoken.animating) |
| 6740 | && !mExiting && !mDestroying; |
| 6741 | } |
| 6742 | |
| 6743 | /** |
| 6744 | * The same as isVisible(), but follows the current hidden state of |
| 6745 | * the associated app token, not the pending requested hidden state. |
| 6746 | */ |
| 6747 | boolean isVisibleNow() { |
| 6748 | return mSurface != null && mPolicyVisibility && !mAttachedHidden |
| The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 6749 | && !mRootToken.hidden && !mExiting && !mDestroying; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6750 | } |
| 6751 | |
| 6752 | /** |
| 6753 | * Same as isVisible(), but we also count it as visible between the |
| 6754 | * call to IWindowSession.add() and the first relayout(). |
| 6755 | */ |
| 6756 | boolean isVisibleOrAdding() { |
| 6757 | final AppWindowToken atoken = mAppToken; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 6758 | return ((mSurface != null && !mReportDestroySurface) |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6759 | || (!mRelayoutCalled && mViewVisibility == View.VISIBLE)) |
| 6760 | && mPolicyVisibility && !mAttachedHidden |
| 6761 | && (atoken == null || !atoken.hiddenRequested) |
| 6762 | && !mExiting && !mDestroying; |
| 6763 | } |
| 6764 | |
| 6765 | /** |
| 6766 | * Is this window currently on-screen? It is on-screen either if it |
| 6767 | * is visible or it is currently running an animation before no longer |
| 6768 | * being visible. |
| 6769 | */ |
| 6770 | boolean isOnScreen() { |
| 6771 | final AppWindowToken atoken = mAppToken; |
| 6772 | if (atoken != null) { |
| 6773 | return mSurface != null && mPolicyVisibility && !mDestroying |
| 6774 | && ((!mAttachedHidden && !atoken.hiddenRequested) |
| Dianne Hackborn | 0cd4887 | 2009-08-13 18:51:59 -0700 | [diff] [blame] | 6775 | || mAnimation != null || atoken.animation != null); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6776 | } else { |
| 6777 | return mSurface != null && mPolicyVisibility && !mDestroying |
| Dianne Hackborn | 0cd4887 | 2009-08-13 18:51:59 -0700 | [diff] [blame] | 6778 | && (!mAttachedHidden || mAnimation != null); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6779 | } |
| 6780 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6781 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6782 | /** |
| 6783 | * Like isOnScreen(), but we don't return true if the window is part |
| 6784 | * of a transition that has not yet been started. |
| 6785 | */ |
| 6786 | boolean isReadyForDisplay() { |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 6787 | if (mRootToken.waitingToShow && |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 6788 | mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 6789 | return false; |
| 6790 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6791 | final AppWindowToken atoken = mAppToken; |
| Dianne Hackborn | 0cd4887 | 2009-08-13 18:51:59 -0700 | [diff] [blame] | 6792 | final boolean animating = atoken != null |
| 6793 | ? (atoken.animation != null) : false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6794 | return mSurface != null && mPolicyVisibility && !mDestroying |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 6795 | && ((!mAttachedHidden && mViewVisibility == View.VISIBLE |
| 6796 | && !mRootToken.hidden) |
| Dianne Hackborn | 0cd4887 | 2009-08-13 18:51:59 -0700 | [diff] [blame] | 6797 | || mAnimation != null || animating); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6798 | } |
| 6799 | |
| 6800 | /** Is the window or its container currently animating? */ |
| 6801 | boolean isAnimating() { |
| 6802 | final WindowState attached = mAttachedWindow; |
| 6803 | final AppWindowToken atoken = mAppToken; |
| 6804 | return mAnimation != null |
| 6805 | || (attached != null && attached.mAnimation != null) |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6806 | || (atoken != null && |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6807 | (atoken.animation != null |
| 6808 | || atoken.inPendingTransaction)); |
| 6809 | } |
| 6810 | |
| 6811 | /** Is this window currently animating? */ |
| 6812 | boolean isWindowAnimating() { |
| 6813 | return mAnimation != null; |
| 6814 | } |
| 6815 | |
| 6816 | /** |
| 6817 | * Like isOnScreen, but returns false if the surface hasn't yet |
| 6818 | * been drawn. |
| 6819 | */ |
| 6820 | public boolean isDisplayedLw() { |
| 6821 | final AppWindowToken atoken = mAppToken; |
| 6822 | return mSurface != null && mPolicyVisibility && !mDestroying |
| 6823 | && !mDrawPending && !mCommitDrawPending |
| 6824 | && ((!mAttachedHidden && |
| 6825 | (atoken == null || !atoken.hiddenRequested)) |
| 6826 | || mAnimating); |
| 6827 | } |
| 6828 | |
| Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 6829 | /** |
| 6830 | * Returns true if the window has a surface that it has drawn a |
| Dianne Hackborn | 5943c20 | 2010-04-12 21:36:49 -0700 | [diff] [blame] | 6831 | * complete UI in to. Note that this returns true if the orientation |
| 6832 | * is changing even if the window hasn't redrawn because we don't want |
| 6833 | * to stop things from executing during that time. |
| Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 6834 | */ |
| 6835 | public boolean isDrawnLw() { |
| 6836 | final AppWindowToken atoken = mAppToken; |
| 6837 | return mSurface != null && !mDestroying |
| Dianne Hackborn | 5943c20 | 2010-04-12 21:36:49 -0700 | [diff] [blame] | 6838 | && (mOrientationChanging || (!mDrawPending && !mCommitDrawPending)); |
| Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 6839 | } |
| 6840 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6841 | public boolean fillsScreenLw(int screenWidth, int screenHeight, |
| 6842 | boolean shownFrame, boolean onlyOpaque) { |
| 6843 | if (mSurface == null) { |
| 6844 | return false; |
| 6845 | } |
| 6846 | if (mAppToken != null && !mAppToken.appFullscreen) { |
| 6847 | return false; |
| 6848 | } |
| 6849 | if (onlyOpaque && mAttrs.format != PixelFormat.OPAQUE) { |
| 6850 | return false; |
| 6851 | } |
| 6852 | final Rect frame = shownFrame ? mShownFrame : mFrame; |
| Mitsuru Oshima | d2967e2 | 2009-07-20 14:01:43 -0700 | [diff] [blame] | 6853 | |
| 6854 | if ((mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0) { |
| 6855 | return frame.left <= mCompatibleScreenFrame.left && |
| 6856 | frame.top <= mCompatibleScreenFrame.top && |
| 6857 | frame.right >= mCompatibleScreenFrame.right && |
| 6858 | frame.bottom >= mCompatibleScreenFrame.bottom; |
| 6859 | } else { |
| 6860 | return frame.left <= 0 && frame.top <= 0 |
| 6861 | && frame.right >= screenWidth |
| 6862 | && frame.bottom >= screenHeight; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6863 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6864 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6865 | |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 6866 | /** |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 6867 | * Return true if the window is opaque and fully drawn. This indicates |
| 6868 | * it may obscure windows behind it. |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 6869 | */ |
| 6870 | boolean isOpaqueDrawn() { |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 6871 | return (mAttrs.format == PixelFormat.OPAQUE |
| 6872 | || mAttrs.type == TYPE_WALLPAPER) |
| 6873 | && mSurface != null && mAnimation == null |
| 6874 | && (mAppToken == null || mAppToken.animation == null) |
| 6875 | && !mDrawPending && !mCommitDrawPending; |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 6876 | } |
| 6877 | |
| 6878 | boolean needsBackgroundFiller(int screenWidth, int screenHeight) { |
| 6879 | return |
| 6880 | // only if the application is requesting compatible window |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 6881 | (mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0 && |
| 6882 | // only if it's visible |
| 6883 | mHasDrawn && mViewVisibility == View.VISIBLE && |
| Mitsuru Oshima | d2967e2 | 2009-07-20 14:01:43 -0700 | [diff] [blame] | 6884 | // and only if the application fills the compatible screen |
| 6885 | mFrame.left <= mCompatibleScreenFrame.left && |
| 6886 | mFrame.top <= mCompatibleScreenFrame.top && |
| 6887 | mFrame.right >= mCompatibleScreenFrame.right && |
| 6888 | mFrame.bottom >= mCompatibleScreenFrame.bottom && |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 6889 | // and starting window do not need background filler |
| Mitsuru Oshima | d2967e2 | 2009-07-20 14:01:43 -0700 | [diff] [blame] | 6890 | mAttrs.type != mAttrs.TYPE_APPLICATION_STARTING; |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 6891 | } |
| 6892 | |
| 6893 | boolean isFullscreen(int screenWidth, int screenHeight) { |
| 6894 | return mFrame.left <= 0 && mFrame.top <= 0 && |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 6895 | mFrame.right >= screenWidth && mFrame.bottom >= screenHeight; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6896 | } |
| 6897 | |
| 6898 | void removeLocked() { |
| 6899 | if (mAttachedWindow != null) { |
| 6900 | mAttachedWindow.mChildWindows.remove(this); |
| 6901 | } |
| 6902 | destroySurfaceLocked(); |
| 6903 | mSession.windowRemovedLocked(); |
| 6904 | try { |
| 6905 | mClient.asBinder().unlinkToDeath(mDeathRecipient, 0); |
| 6906 | } catch (RuntimeException e) { |
| 6907 | // Ignore if it has already been removed (usually because |
| 6908 | // we are doing this as part of processing a death note.) |
| 6909 | } |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 6910 | |
| Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 6911 | if (mInputChannel != null) { |
| 6912 | mInputManager.unregisterInputChannel(mInputChannel); |
| 6913 | |
| 6914 | mInputChannel.dispose(); |
| 6915 | mInputChannel = null; |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 6916 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6917 | } |
| 6918 | |
| 6919 | private class DeathRecipient implements IBinder.DeathRecipient { |
| 6920 | public void binderDied() { |
| 6921 | try { |
| 6922 | synchronized(mWindowMap) { |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 6923 | WindowState win = windowForClientLocked(mSession, mClient, false); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6924 | Slog.i(TAG, "WIN DEATH: " + win); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6925 | if (win != null) { |
| 6926 | removeWindowLocked(mSession, win); |
| 6927 | } |
| 6928 | } |
| 6929 | } catch (IllegalArgumentException ex) { |
| 6930 | // This will happen if the window has already been |
| 6931 | // removed. |
| 6932 | } |
| 6933 | } |
| 6934 | } |
| 6935 | |
| 6936 | /** Returns true if this window desires key events. */ |
| 6937 | public final boolean canReceiveKeys() { |
| 6938 | return isVisibleOrAdding() |
| 6939 | && (mViewVisibility == View.VISIBLE) |
| 6940 | && ((mAttrs.flags & WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) == 0); |
| 6941 | } |
| 6942 | |
| 6943 | public boolean hasDrawnLw() { |
| 6944 | return mHasDrawn; |
| 6945 | } |
| 6946 | |
| 6947 | public boolean showLw(boolean doAnimation) { |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 6948 | return showLw(doAnimation, true); |
| 6949 | } |
| 6950 | |
| 6951 | boolean showLw(boolean doAnimation, boolean requestAnim) { |
| 6952 | if (mPolicyVisibility && mPolicyVisibilityAfterAnim) { |
| 6953 | return false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6954 | } |
| Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 6955 | if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility true: " + this); |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 6956 | if (doAnimation) { |
| 6957 | if (DEBUG_VISIBILITY) Slog.v(TAG, "doAnimation: mPolicyVisibility=" |
| 6958 | + mPolicyVisibility + " mAnimation=" + mAnimation); |
| 6959 | if (mDisplayFrozen || !mPolicy.isScreenOn()) { |
| 6960 | doAnimation = false; |
| 6961 | } else if (mPolicyVisibility && mAnimation == null) { |
| 6962 | // Check for the case where we are currently visible and |
| 6963 | // not animating; we do not want to do animation at such a |
| 6964 | // point to become visible when we already are. |
| 6965 | doAnimation = false; |
| 6966 | } |
| 6967 | } |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 6968 | mPolicyVisibility = true; |
| 6969 | mPolicyVisibilityAfterAnim = true; |
| 6970 | if (doAnimation) { |
| 6971 | applyAnimationLocked(this, WindowManagerPolicy.TRANSIT_ENTER, true); |
| 6972 | } |
| 6973 | if (requestAnim) { |
| 6974 | requestAnimationLocked(0); |
| 6975 | } |
| 6976 | return true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6977 | } |
| 6978 | |
| 6979 | public boolean hideLw(boolean doAnimation) { |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 6980 | return hideLw(doAnimation, true); |
| 6981 | } |
| 6982 | |
| 6983 | boolean hideLw(boolean doAnimation, boolean requestAnim) { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 6984 | if (doAnimation) { |
| 6985 | if (mDisplayFrozen || !mPolicy.isScreenOn()) { |
| 6986 | doAnimation = false; |
| 6987 | } |
| 6988 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6989 | boolean current = doAnimation ? mPolicyVisibilityAfterAnim |
| 6990 | : mPolicyVisibility; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 6991 | if (!current) { |
| 6992 | return false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6993 | } |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 6994 | if (doAnimation) { |
| 6995 | applyAnimationLocked(this, WindowManagerPolicy.TRANSIT_EXIT, false); |
| 6996 | if (mAnimation == null) { |
| 6997 | doAnimation = false; |
| 6998 | } |
| 6999 | } |
| 7000 | if (doAnimation) { |
| 7001 | mPolicyVisibilityAfterAnim = false; |
| 7002 | } else { |
| Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 7003 | if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility false: " + this); |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 7004 | mPolicyVisibilityAfterAnim = false; |
| 7005 | mPolicyVisibility = false; |
| Dianne Hackborn | f3bea9c | 2009-12-09 18:26:21 -0800 | [diff] [blame] | 7006 | // Window is no longer visible -- make sure if we were waiting |
| 7007 | // for it to be displayed before enabling the display, that |
| 7008 | // we allow the display to be enabled now. |
| 7009 | enableScreenIfNeededLocked(); |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 7010 | if (mCurrentFocus == this) { |
| 7011 | mFocusMayChange = true; |
| 7012 | } |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 7013 | } |
| 7014 | if (requestAnim) { |
| 7015 | requestAnimationLocked(0); |
| 7016 | } |
| 7017 | return true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7018 | } |
| 7019 | |
| 7020 | void dump(PrintWriter pw, String prefix) { |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7021 | pw.print(prefix); pw.print("mSession="); pw.print(mSession); |
| 7022 | pw.print(" mClient="); pw.println(mClient.asBinder()); |
| 7023 | pw.print(prefix); pw.print("mAttrs="); pw.println(mAttrs); |
| 7024 | if (mAttachedWindow != null || mLayoutAttached) { |
| 7025 | pw.print(prefix); pw.print("mAttachedWindow="); pw.print(mAttachedWindow); |
| 7026 | pw.print(" mLayoutAttached="); pw.println(mLayoutAttached); |
| 7027 | } |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 7028 | if (mIsImWindow || mIsWallpaper || mIsFloatingLayer) { |
| 7029 | pw.print(prefix); pw.print("mIsImWindow="); pw.print(mIsImWindow); |
| 7030 | pw.print(" mIsWallpaper="); pw.print(mIsWallpaper); |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 7031 | pw.print(" mIsFloatingLayer="); pw.print(mIsFloatingLayer); |
| 7032 | pw.print(" mWallpaperVisible="); pw.println(mWallpaperVisible); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7033 | } |
| 7034 | pw.print(prefix); pw.print("mBaseLayer="); pw.print(mBaseLayer); |
| 7035 | pw.print(" mSubLayer="); pw.print(mSubLayer); |
| 7036 | pw.print(" mAnimLayer="); pw.print(mLayer); pw.print("+"); |
| 7037 | pw.print((mTargetAppToken != null ? mTargetAppToken.animLayerAdjustment |
| 7038 | : (mAppToken != null ? mAppToken.animLayerAdjustment : 0))); |
| 7039 | pw.print("="); pw.print(mAnimLayer); |
| 7040 | pw.print(" mLastLayer="); pw.println(mLastLayer); |
| 7041 | if (mSurface != null) { |
| 7042 | pw.print(prefix); pw.print("mSurface="); pw.println(mSurface); |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 7043 | pw.print(prefix); pw.print("Surface: shown="); pw.print(mSurfaceShown); |
| 7044 | pw.print(" layer="); pw.print(mSurfaceLayer); |
| 7045 | pw.print(" alpha="); pw.print(mSurfaceAlpha); |
| 7046 | pw.print(" rect=("); pw.print(mSurfaceX); |
| 7047 | pw.print(","); pw.print(mSurfaceY); |
| 7048 | pw.print(") "); pw.print(mSurfaceW); |
| 7049 | pw.print(" x "); pw.println(mSurfaceH); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7050 | } |
| 7051 | pw.print(prefix); pw.print("mToken="); pw.println(mToken); |
| 7052 | pw.print(prefix); pw.print("mRootToken="); pw.println(mRootToken); |
| 7053 | if (mAppToken != null) { |
| 7054 | pw.print(prefix); pw.print("mAppToken="); pw.println(mAppToken); |
| 7055 | } |
| 7056 | if (mTargetAppToken != null) { |
| 7057 | pw.print(prefix); pw.print("mTargetAppToken="); pw.println(mTargetAppToken); |
| 7058 | } |
| 7059 | pw.print(prefix); pw.print("mViewVisibility=0x"); |
| 7060 | pw.print(Integer.toHexString(mViewVisibility)); |
| 7061 | pw.print(" mLastHidden="); pw.print(mLastHidden); |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 7062 | pw.print(" mHaveFrame="); pw.print(mHaveFrame); |
| 7063 | pw.print(" mObscured="); pw.println(mObscured); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7064 | if (!mPolicyVisibility || !mPolicyVisibilityAfterAnim || mAttachedHidden) { |
| 7065 | pw.print(prefix); pw.print("mPolicyVisibility="); |
| 7066 | pw.print(mPolicyVisibility); |
| 7067 | pw.print(" mPolicyVisibilityAfterAnim="); |
| 7068 | pw.print(mPolicyVisibilityAfterAnim); |
| 7069 | pw.print(" mAttachedHidden="); pw.println(mAttachedHidden); |
| 7070 | } |
| Dianne Hackborn | 9b52a21 | 2009-12-11 14:51:35 -0800 | [diff] [blame] | 7071 | if (!mRelayoutCalled) { |
| 7072 | pw.print(prefix); pw.print("mRelayoutCalled="); pw.println(mRelayoutCalled); |
| 7073 | } |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7074 | pw.print(prefix); pw.print("Requested w="); pw.print(mRequestedWidth); |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 7075 | pw.print(" h="); pw.print(mRequestedHeight); |
| 7076 | pw.print(" mLayoutSeq="); pw.println(mLayoutSeq); |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 7077 | if (mXOffset != 0 || mYOffset != 0) { |
| 7078 | pw.print(prefix); pw.print("Offsets x="); pw.print(mXOffset); |
| 7079 | pw.print(" y="); pw.println(mYOffset); |
| 7080 | } |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7081 | pw.print(prefix); pw.print("mGivenContentInsets="); |
| 7082 | mGivenContentInsets.printShortString(pw); |
| 7083 | pw.print(" mGivenVisibleInsets="); |
| 7084 | mGivenVisibleInsets.printShortString(pw); |
| 7085 | pw.println(); |
| 7086 | if (mTouchableInsets != 0 || mGivenInsetsPending) { |
| 7087 | pw.print(prefix); pw.print("mTouchableInsets="); pw.print(mTouchableInsets); |
| 7088 | pw.print(" mGivenInsetsPending="); pw.println(mGivenInsetsPending); |
| 7089 | } |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 7090 | pw.print(prefix); pw.print("mConfiguration="); pw.println(mConfiguration); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7091 | pw.print(prefix); pw.print("mShownFrame="); |
| 7092 | mShownFrame.printShortString(pw); |
| 7093 | pw.print(" last="); mLastShownFrame.printShortString(pw); |
| 7094 | pw.println(); |
| 7095 | pw.print(prefix); pw.print("mFrame="); mFrame.printShortString(pw); |
| 7096 | pw.print(" last="); mLastFrame.printShortString(pw); |
| 7097 | pw.println(); |
| 7098 | pw.print(prefix); pw.print("mContainingFrame="); |
| 7099 | mContainingFrame.printShortString(pw); |
| 7100 | pw.print(" mDisplayFrame="); |
| 7101 | mDisplayFrame.printShortString(pw); |
| 7102 | pw.println(); |
| 7103 | pw.print(prefix); pw.print("mContentFrame="); mContentFrame.printShortString(pw); |
| 7104 | pw.print(" mVisibleFrame="); mVisibleFrame.printShortString(pw); |
| 7105 | pw.println(); |
| 7106 | pw.print(prefix); pw.print("mContentInsets="); mContentInsets.printShortString(pw); |
| 7107 | pw.print(" last="); mLastContentInsets.printShortString(pw); |
| 7108 | pw.print(" mVisibleInsets="); mVisibleInsets.printShortString(pw); |
| 7109 | pw.print(" last="); mLastVisibleInsets.printShortString(pw); |
| 7110 | pw.println(); |
| 7111 | if (mShownAlpha != 1 || mAlpha != 1 || mLastAlpha != 1) { |
| 7112 | pw.print(prefix); pw.print("mShownAlpha="); pw.print(mShownAlpha); |
| 7113 | pw.print(" mAlpha="); pw.print(mAlpha); |
| 7114 | pw.print(" mLastAlpha="); pw.println(mLastAlpha); |
| 7115 | } |
| 7116 | if (mAnimating || mLocalAnimating || mAnimationIsEntrance |
| 7117 | || mAnimation != null) { |
| 7118 | pw.print(prefix); pw.print("mAnimating="); pw.print(mAnimating); |
| 7119 | pw.print(" mLocalAnimating="); pw.print(mLocalAnimating); |
| 7120 | pw.print(" mAnimationIsEntrance="); pw.print(mAnimationIsEntrance); |
| 7121 | pw.print(" mAnimation="); pw.println(mAnimation); |
| 7122 | } |
| 7123 | if (mHasTransformation || mHasLocalTransformation) { |
| 7124 | pw.print(prefix); pw.print("XForm: has="); |
| 7125 | pw.print(mHasTransformation); |
| 7126 | pw.print(" hasLocal="); pw.print(mHasLocalTransformation); |
| 7127 | pw.print(" "); mTransformation.printShortString(pw); |
| 7128 | pw.println(); |
| 7129 | } |
| 7130 | pw.print(prefix); pw.print("mDrawPending="); pw.print(mDrawPending); |
| 7131 | pw.print(" mCommitDrawPending="); pw.print(mCommitDrawPending); |
| 7132 | pw.print(" mReadyToShow="); pw.print(mReadyToShow); |
| 7133 | pw.print(" mHasDrawn="); pw.println(mHasDrawn); |
| 7134 | if (mExiting || mRemoveOnExit || mDestroying || mRemoved) { |
| 7135 | pw.print(prefix); pw.print("mExiting="); pw.print(mExiting); |
| 7136 | pw.print(" mRemoveOnExit="); pw.print(mRemoveOnExit); |
| 7137 | pw.print(" mDestroying="); pw.print(mDestroying); |
| 7138 | pw.print(" mRemoved="); pw.println(mRemoved); |
| 7139 | } |
| Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 7140 | if (mOrientationChanging || mAppFreezing || mTurnOnScreen) { |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7141 | pw.print(prefix); pw.print("mOrientationChanging="); |
| 7142 | pw.print(mOrientationChanging); |
| Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 7143 | pw.print(" mAppFreezing="); pw.print(mAppFreezing); |
| 7144 | pw.print(" mTurnOnScreen="); pw.println(mTurnOnScreen); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7145 | } |
| Mitsuru Oshima | 589cebe | 2009-07-22 20:38:58 -0700 | [diff] [blame] | 7146 | if (mHScale != 1 || mVScale != 1) { |
| 7147 | pw.print(prefix); pw.print("mHScale="); pw.print(mHScale); |
| 7148 | pw.print(" mVScale="); pw.println(mVScale); |
| 7149 | } |
| Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 7150 | if (mWallpaperX != -1 || mWallpaperY != -1) { |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 7151 | pw.print(prefix); pw.print("mWallpaperX="); pw.print(mWallpaperX); |
| 7152 | pw.print(" mWallpaperY="); pw.println(mWallpaperY); |
| 7153 | } |
| Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 7154 | if (mWallpaperXStep != -1 || mWallpaperYStep != -1) { |
| 7155 | pw.print(prefix); pw.print("mWallpaperXStep="); pw.print(mWallpaperXStep); |
| 7156 | pw.print(" mWallpaperYStep="); pw.println(mWallpaperYStep); |
| 7157 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7158 | } |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 7159 | |
| 7160 | String makeInputChannelName() { |
| 7161 | return Integer.toHexString(System.identityHashCode(this)) |
| 7162 | + " " + mAttrs.getTitle(); |
| 7163 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7164 | |
| 7165 | @Override |
| 7166 | public String toString() { |
| 7167 | return "Window{" |
| 7168 | + Integer.toHexString(System.identityHashCode(this)) |
| 7169 | + " " + mAttrs.getTitle() + " paused=" + mToken.paused + "}"; |
| 7170 | } |
| 7171 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7172 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7173 | // ------------------------------------------------------------- |
| 7174 | // Window Token State |
| 7175 | // ------------------------------------------------------------- |
| 7176 | |
| 7177 | class WindowToken { |
| 7178 | // The actual token. |
| 7179 | final IBinder token; |
| 7180 | |
| 7181 | // The type of window this token is for, as per WindowManager.LayoutParams. |
| 7182 | final int windowType; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7183 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7184 | // Set if this token was explicitly added by a client, so should |
| 7185 | // not be removed when all windows are removed. |
| 7186 | final boolean explicit; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7187 | |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7188 | // For printing. |
| 7189 | String stringName; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7190 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7191 | // If this is an AppWindowToken, this is non-null. |
| 7192 | AppWindowToken appWindowToken; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7193 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7194 | // All of the windows associated with this token. |
| 7195 | final ArrayList<WindowState> windows = new ArrayList<WindowState>(); |
| 7196 | |
| 7197 | // Is key dispatching paused for this token? |
| 7198 | boolean paused = false; |
| 7199 | |
| 7200 | // Should this token's windows be hidden? |
| 7201 | boolean hidden; |
| 7202 | |
| 7203 | // Temporary for finding which tokens no longer have visible windows. |
| 7204 | boolean hasVisible; |
| 7205 | |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 7206 | // Set to true when this token is in a pending transaction where it |
| 7207 | // will be shown. |
| 7208 | boolean waitingToShow; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7209 | |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 7210 | // Set to true when this token is in a pending transaction where it |
| 7211 | // will be hidden. |
| 7212 | boolean waitingToHide; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7213 | |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 7214 | // Set to true when this token is in a pending transaction where its |
| 7215 | // windows will be put to the bottom of the list. |
| 7216 | boolean sendingToBottom; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7217 | |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 7218 | // Set to true when this token is in a pending transaction where its |
| 7219 | // windows will be put to the top of the list. |
| 7220 | boolean sendingToTop; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7221 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7222 | WindowToken(IBinder _token, int type, boolean _explicit) { |
| 7223 | token = _token; |
| 7224 | windowType = type; |
| 7225 | explicit = _explicit; |
| 7226 | } |
| 7227 | |
| 7228 | void dump(PrintWriter pw, String prefix) { |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7229 | pw.print(prefix); pw.print("token="); pw.println(token); |
| 7230 | pw.print(prefix); pw.print("windows="); pw.println(windows); |
| 7231 | pw.print(prefix); pw.print("windowType="); pw.print(windowType); |
| 7232 | pw.print(" hidden="); pw.print(hidden); |
| 7233 | pw.print(" hasVisible="); pw.println(hasVisible); |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 7234 | if (waitingToShow || waitingToHide || sendingToBottom || sendingToTop) { |
| 7235 | pw.print(prefix); pw.print("waitingToShow="); pw.print(waitingToShow); |
| 7236 | pw.print(" waitingToHide="); pw.print(waitingToHide); |
| 7237 | pw.print(" sendingToBottom="); pw.print(sendingToBottom); |
| 7238 | pw.print(" sendingToTop="); pw.println(sendingToTop); |
| 7239 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7240 | } |
| 7241 | |
| 7242 | @Override |
| 7243 | public String toString() { |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7244 | if (stringName == null) { |
| 7245 | StringBuilder sb = new StringBuilder(); |
| 7246 | sb.append("WindowToken{"); |
| 7247 | sb.append(Integer.toHexString(System.identityHashCode(this))); |
| 7248 | sb.append(" token="); sb.append(token); sb.append('}'); |
| 7249 | stringName = sb.toString(); |
| 7250 | } |
| 7251 | return stringName; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7252 | } |
| 7253 | }; |
| 7254 | |
| 7255 | class AppWindowToken extends WindowToken { |
| 7256 | // Non-null only for application tokens. |
| 7257 | final IApplicationToken appToken; |
| 7258 | |
| 7259 | // All of the windows and child windows that are included in this |
| 7260 | // application token. Note this list is NOT sorted! |
| 7261 | final ArrayList<WindowState> allAppWindows = new ArrayList<WindowState>(); |
| 7262 | |
| 7263 | int groupId = -1; |
| 7264 | boolean appFullscreen; |
| 7265 | int requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 7266 | |
| 7267 | // The input dispatching timeout for this application token in nanoseconds. |
| 7268 | long inputDispatchingTimeoutNanos; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7269 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7270 | // These are used for determining when all windows associated with |
| 7271 | // an activity have been drawn, so they can be made visible together |
| 7272 | // at the same time. |
| 7273 | int lastTransactionSequence = mTransactionSequence-1; |
| 7274 | int numInterestingWindows; |
| 7275 | int numDrawnWindows; |
| 7276 | boolean inPendingTransaction; |
| 7277 | boolean allDrawn; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7278 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7279 | // Is this token going to be hidden in a little while? If so, it |
| 7280 | // won't be taken into account for setting the screen orientation. |
| 7281 | boolean willBeHidden; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7282 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7283 | // Is this window's surface needed? This is almost like hidden, except |
| 7284 | // it will sometimes be true a little earlier: when the token has |
| 7285 | // been shown, but is still waiting for its app transition to execute |
| 7286 | // before making its windows shown. |
| 7287 | boolean hiddenRequested; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7288 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7289 | // Have we told the window clients to hide themselves? |
| 7290 | boolean clientHidden; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7291 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7292 | // Last visibility state we reported to the app token. |
| 7293 | boolean reportedVisible; |
| 7294 | |
| 7295 | // Set to true when the token has been removed from the window mgr. |
| 7296 | boolean removed; |
| 7297 | |
| 7298 | // Have we been asked to have this token keep the screen frozen? |
| 7299 | boolean freezingScreen; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7300 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7301 | boolean animating; |
| 7302 | Animation animation; |
| 7303 | boolean hasTransformation; |
| 7304 | final Transformation transformation = new Transformation(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7305 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7306 | // Offset to the window of all layers in the token, for use by |
| 7307 | // AppWindowToken animations. |
| 7308 | int animLayerAdjustment; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7309 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7310 | // Information about an application starting window if displayed. |
| 7311 | StartingData startingData; |
| 7312 | WindowState startingWindow; |
| 7313 | View startingView; |
| 7314 | boolean startingDisplayed; |
| 7315 | boolean startingMoved; |
| 7316 | boolean firstWindowDrawn; |
| 7317 | |
| 7318 | AppWindowToken(IApplicationToken _token) { |
| 7319 | super(_token.asBinder(), |
| 7320 | WindowManager.LayoutParams.TYPE_APPLICATION, true); |
| 7321 | appWindowToken = this; |
| 7322 | appToken = _token; |
| 7323 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7324 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7325 | public void setAnimation(Animation anim) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7326 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7327 | TAG, "Setting animation in " + this + ": " + anim); |
| 7328 | animation = anim; |
| 7329 | animating = false; |
| 7330 | anim.restrictDuration(MAX_ANIMATION_DURATION); |
| 7331 | anim.scaleCurrentDuration(mTransitionAnimationScale); |
| 7332 | int zorder = anim.getZAdjustment(); |
| 7333 | int adj = 0; |
| 7334 | if (zorder == Animation.ZORDER_TOP) { |
| 7335 | adj = TYPE_LAYER_OFFSET; |
| 7336 | } else if (zorder == Animation.ZORDER_BOTTOM) { |
| 7337 | adj = -TYPE_LAYER_OFFSET; |
| 7338 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7339 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7340 | if (animLayerAdjustment != adj) { |
| 7341 | animLayerAdjustment = adj; |
| 7342 | updateLayers(); |
| 7343 | } |
| 7344 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7345 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7346 | public void setDummyAnimation() { |
| 7347 | if (animation == null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7348 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7349 | TAG, "Setting dummy animation in " + this); |
| 7350 | animation = sDummyAnimation; |
| 7351 | } |
| 7352 | } |
| 7353 | |
| 7354 | public void clearAnimation() { |
| 7355 | if (animation != null) { |
| 7356 | animation = null; |
| 7357 | animating = true; |
| 7358 | } |
| 7359 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7360 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7361 | void updateLayers() { |
| 7362 | final int N = allAppWindows.size(); |
| 7363 | final int adj = animLayerAdjustment; |
| 7364 | for (int i=0; i<N; i++) { |
| 7365 | WindowState w = allAppWindows.get(i); |
| 7366 | w.mAnimLayer = w.mLayer + adj; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7367 | if (DEBUG_LAYERS) Slog.v(TAG, "Updating layer " + w + ": " |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7368 | + w.mAnimLayer); |
| 7369 | if (w == mInputMethodTarget) { |
| 7370 | setInputMethodAnimLayerAdjustment(adj); |
| 7371 | } |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 7372 | if (w == mWallpaperTarget && mLowerWallpaperTarget == null) { |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 7373 | setWallpaperAnimLayerAdjustmentLocked(adj); |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 7374 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7375 | } |
| 7376 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7377 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7378 | void sendAppVisibilityToClients() { |
| 7379 | final int N = allAppWindows.size(); |
| 7380 | for (int i=0; i<N; i++) { |
| 7381 | WindowState win = allAppWindows.get(i); |
| 7382 | if (win == startingWindow && clientHidden) { |
| 7383 | // Don't hide the starting window. |
| 7384 | continue; |
| 7385 | } |
| 7386 | try { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7387 | if (DEBUG_VISIBILITY) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7388 | "Setting visibility of " + win + ": " + (!clientHidden)); |
| 7389 | win.mClient.dispatchAppVisibility(!clientHidden); |
| 7390 | } catch (RemoteException e) { |
| 7391 | } |
| 7392 | } |
| 7393 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7394 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7395 | void showAllWindowsLocked() { |
| 7396 | final int NW = allAppWindows.size(); |
| 7397 | for (int i=0; i<NW; i++) { |
| 7398 | WindowState w = allAppWindows.get(i); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7399 | if (DEBUG_VISIBILITY) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7400 | "performing show on: " + w); |
| 7401 | w.performShowLocked(); |
| 7402 | } |
| 7403 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7404 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7405 | // This must be called while inside a transaction. |
| 7406 | boolean stepAnimationLocked(long currentTime, int dw, int dh) { |
| Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 7407 | if (!mDisplayFrozen && mPolicy.isScreenOn()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7408 | // We will run animations as long as the display isn't frozen. |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7409 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7410 | if (animation == sDummyAnimation) { |
| 7411 | // This guy is going to animate, but not yet. For now count |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 7412 | // it as not animating for purposes of scheduling transactions; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7413 | // when it is really time to animate, this will be set to |
| 7414 | // a real animation and the next call will execute normally. |
| 7415 | return false; |
| 7416 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7417 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7418 | if ((allDrawn || animating || startingDisplayed) && animation != null) { |
| 7419 | if (!animating) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7420 | if (DEBUG_ANIM) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7421 | TAG, "Starting animation in " + this + |
| 7422 | " @ " + currentTime + ": dw=" + dw + " dh=" + dh |
| 7423 | + " scale=" + mTransitionAnimationScale |
| 7424 | + " allDrawn=" + allDrawn + " animating=" + animating); |
| 7425 | animation.initialize(dw, dh, dw, dh); |
| 7426 | animation.setStartTime(currentTime); |
| 7427 | animating = true; |
| 7428 | } |
| 7429 | transformation.clear(); |
| 7430 | final boolean more = animation.getTransformation( |
| 7431 | currentTime, transformation); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7432 | if (DEBUG_ANIM) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7433 | TAG, "Stepped animation in " + this + |
| 7434 | ": more=" + more + ", xform=" + transformation); |
| 7435 | if (more) { |
| 7436 | // we're done! |
| 7437 | hasTransformation = true; |
| 7438 | return true; |
| 7439 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7440 | if (DEBUG_ANIM) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7441 | TAG, "Finished animation in " + this + |
| 7442 | " @ " + currentTime); |
| 7443 | animation = null; |
| 7444 | } |
| 7445 | } else if (animation != null) { |
| 7446 | // If the display is frozen, and there is a pending animation, |
| 7447 | // clear it and make sure we run the cleanup code. |
| 7448 | animating = true; |
| 7449 | animation = null; |
| 7450 | } |
| 7451 | |
| 7452 | hasTransformation = false; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7453 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7454 | if (!animating) { |
| 7455 | return false; |
| 7456 | } |
| 7457 | |
| 7458 | clearAnimation(); |
| 7459 | animating = false; |
| 7460 | if (mInputMethodTarget != null && mInputMethodTarget.mAppToken == this) { |
| 7461 | moveInputMethodWindowsIfNeededLocked(true); |
| 7462 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7463 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7464 | if (DEBUG_ANIM) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7465 | TAG, "Animation done in " + this |
| 7466 | + ": reportedVisible=" + reportedVisible); |
| 7467 | |
| 7468 | transformation.clear(); |
| 7469 | if (animLayerAdjustment != 0) { |
| 7470 | animLayerAdjustment = 0; |
| 7471 | updateLayers(); |
| 7472 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7473 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7474 | final int N = windows.size(); |
| 7475 | for (int i=0; i<N; i++) { |
| 7476 | ((WindowState)windows.get(i)).finishExit(); |
| 7477 | } |
| 7478 | updateReportedVisibilityLocked(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7479 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7480 | return false; |
| 7481 | } |
| 7482 | |
| 7483 | void updateReportedVisibilityLocked() { |
| 7484 | if (appToken == null) { |
| 7485 | return; |
| 7486 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7487 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7488 | int numInteresting = 0; |
| 7489 | int numVisible = 0; |
| 7490 | boolean nowGone = true; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7491 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7492 | if (DEBUG_VISIBILITY) Slog.v(TAG, "Update reported visibility: " + this); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7493 | final int N = allAppWindows.size(); |
| 7494 | for (int i=0; i<N; i++) { |
| 7495 | WindowState win = allAppWindows.get(i); |
| Dianne Hackborn | 6cf67fa | 2009-12-21 16:46:34 -0800 | [diff] [blame] | 7496 | if (win == startingWindow || win.mAppFreezing |
| The Android Open Source Project | 727cec0 | 2010-04-08 11:35:37 -0700 | [diff] [blame] | 7497 | || win.mViewVisibility != View.VISIBLE |
| 7498 | || win.mAttrs.type == TYPE_APPLICATION_STARTING) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7499 | continue; |
| 7500 | } |
| 7501 | if (DEBUG_VISIBILITY) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7502 | Slog.v(TAG, "Win " + win + ": isDrawn=" |
| Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 7503 | + win.isDrawnLw() |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7504 | + ", isAnimating=" + win.isAnimating()); |
| Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 7505 | if (!win.isDrawnLw()) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7506 | Slog.v(TAG, "Not displayed: s=" + win.mSurface |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7507 | + " pv=" + win.mPolicyVisibility |
| 7508 | + " dp=" + win.mDrawPending |
| 7509 | + " cdp=" + win.mCommitDrawPending |
| 7510 | + " ah=" + win.mAttachedHidden |
| 7511 | + " th=" |
| 7512 | + (win.mAppToken != null |
| 7513 | ? win.mAppToken.hiddenRequested : false) |
| 7514 | + " a=" + win.mAnimating); |
| 7515 | } |
| 7516 | } |
| 7517 | numInteresting++; |
| Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 7518 | if (win.isDrawnLw()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7519 | if (!win.isAnimating()) { |
| 7520 | numVisible++; |
| 7521 | } |
| 7522 | nowGone = false; |
| 7523 | } else if (win.isAnimating()) { |
| 7524 | nowGone = false; |
| 7525 | } |
| 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 | boolean nowVisible = numInteresting > 0 && numVisible >= numInteresting; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7529 | if (DEBUG_VISIBILITY) Slog.v(TAG, "VIS " + this + ": interesting=" |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7530 | + numInteresting + " visible=" + numVisible); |
| 7531 | if (nowVisible != reportedVisible) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7532 | if (DEBUG_VISIBILITY) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7533 | TAG, "Visibility changed in " + this |
| 7534 | + ": vis=" + nowVisible); |
| 7535 | reportedVisible = nowVisible; |
| 7536 | Message m = mH.obtainMessage( |
| 7537 | H.REPORT_APPLICATION_TOKEN_WINDOWS, |
| 7538 | nowVisible ? 1 : 0, |
| 7539 | nowGone ? 1 : 0, |
| 7540 | this); |
| 7541 | mH.sendMessage(m); |
| 7542 | } |
| 7543 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7544 | |
| Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 7545 | WindowState findMainWindow() { |
| 7546 | int j = windows.size(); |
| 7547 | while (j > 0) { |
| 7548 | j--; |
| 7549 | WindowState win = windows.get(j); |
| 7550 | if (win.mAttrs.type == WindowManager.LayoutParams.TYPE_BASE_APPLICATION |
| 7551 | || win.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING) { |
| 7552 | return win; |
| 7553 | } |
| 7554 | } |
| 7555 | return null; |
| 7556 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7557 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7558 | void dump(PrintWriter pw, String prefix) { |
| 7559 | super.dump(pw, prefix); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7560 | if (appToken != null) { |
| 7561 | pw.print(prefix); pw.println("app=true"); |
| 7562 | } |
| 7563 | if (allAppWindows.size() > 0) { |
| 7564 | pw.print(prefix); pw.print("allAppWindows="); pw.println(allAppWindows); |
| 7565 | } |
| 7566 | pw.print(prefix); pw.print("groupId="); pw.print(groupId); |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 7567 | pw.print(" appFullscreen="); pw.print(appFullscreen); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7568 | pw.print(" requestedOrientation="); pw.println(requestedOrientation); |
| 7569 | pw.print(prefix); pw.print("hiddenRequested="); pw.print(hiddenRequested); |
| 7570 | pw.print(" clientHidden="); pw.print(clientHidden); |
| 7571 | pw.print(" willBeHidden="); pw.print(willBeHidden); |
| 7572 | pw.print(" reportedVisible="); pw.println(reportedVisible); |
| 7573 | if (paused || freezingScreen) { |
| 7574 | pw.print(prefix); pw.print("paused="); pw.print(paused); |
| 7575 | pw.print(" freezingScreen="); pw.println(freezingScreen); |
| 7576 | } |
| 7577 | if (numInterestingWindows != 0 || numDrawnWindows != 0 |
| 7578 | || inPendingTransaction || allDrawn) { |
| 7579 | pw.print(prefix); pw.print("numInterestingWindows="); |
| 7580 | pw.print(numInterestingWindows); |
| 7581 | pw.print(" numDrawnWindows="); pw.print(numDrawnWindows); |
| 7582 | pw.print(" inPendingTransaction="); pw.print(inPendingTransaction); |
| 7583 | pw.print(" allDrawn="); pw.println(allDrawn); |
| 7584 | } |
| 7585 | if (animating || animation != null) { |
| 7586 | pw.print(prefix); pw.print("animating="); pw.print(animating); |
| 7587 | pw.print(" animation="); pw.println(animation); |
| 7588 | } |
| 7589 | if (animLayerAdjustment != 0) { |
| 7590 | pw.print(prefix); pw.print("animLayerAdjustment="); pw.println(animLayerAdjustment); |
| 7591 | } |
| 7592 | if (hasTransformation) { |
| 7593 | pw.print(prefix); pw.print("hasTransformation="); pw.print(hasTransformation); |
| 7594 | pw.print(" transformation="); transformation.printShortString(pw); |
| 7595 | pw.println(); |
| 7596 | } |
| 7597 | if (startingData != null || removed || firstWindowDrawn) { |
| 7598 | pw.print(prefix); pw.print("startingData="); pw.print(startingData); |
| 7599 | pw.print(" removed="); pw.print(removed); |
| 7600 | pw.print(" firstWindowDrawn="); pw.println(firstWindowDrawn); |
| 7601 | } |
| 7602 | if (startingWindow != null || startingView != null |
| 7603 | || startingDisplayed || startingMoved) { |
| 7604 | pw.print(prefix); pw.print("startingWindow="); pw.print(startingWindow); |
| 7605 | pw.print(" startingView="); pw.print(startingView); |
| 7606 | pw.print(" startingDisplayed="); pw.print(startingDisplayed); |
| 7607 | pw.print(" startingMoved"); pw.println(startingMoved); |
| 7608 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7609 | } |
| 7610 | |
| 7611 | @Override |
| 7612 | public String toString() { |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7613 | if (stringName == null) { |
| 7614 | StringBuilder sb = new StringBuilder(); |
| 7615 | sb.append("AppWindowToken{"); |
| 7616 | sb.append(Integer.toHexString(System.identityHashCode(this))); |
| 7617 | sb.append(" token="); sb.append(token); sb.append('}'); |
| 7618 | stringName = sb.toString(); |
| 7619 | } |
| 7620 | return stringName; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7621 | } |
| 7622 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7623 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7624 | // ------------------------------------------------------------- |
| 7625 | // DummyAnimation |
| 7626 | // ------------------------------------------------------------- |
| 7627 | |
| 7628 | // This is an animation that does nothing: it just immediately finishes |
| 7629 | // itself every time it is called. It is used as a stub animation in cases |
| 7630 | // where we want to synchronize multiple things that may be animating. |
| 7631 | static final class DummyAnimation extends Animation { |
| 7632 | public boolean getTransformation(long currentTime, Transformation outTransformation) { |
| 7633 | return false; |
| 7634 | } |
| 7635 | } |
| 7636 | static final Animation sDummyAnimation = new DummyAnimation(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7637 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7638 | // ------------------------------------------------------------- |
| 7639 | // Async Handler |
| 7640 | // ------------------------------------------------------------- |
| 7641 | |
| 7642 | static final class StartingData { |
| 7643 | final String pkg; |
| 7644 | final int theme; |
| 7645 | final CharSequence nonLocalizedLabel; |
| 7646 | final int labelRes; |
| 7647 | final int icon; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7648 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7649 | StartingData(String _pkg, int _theme, CharSequence _nonLocalizedLabel, |
| 7650 | int _labelRes, int _icon) { |
| 7651 | pkg = _pkg; |
| 7652 | theme = _theme; |
| 7653 | nonLocalizedLabel = _nonLocalizedLabel; |
| 7654 | labelRes = _labelRes; |
| 7655 | icon = _icon; |
| 7656 | } |
| 7657 | } |
| 7658 | |
| 7659 | private final class H extends Handler { |
| 7660 | public static final int REPORT_FOCUS_CHANGE = 2; |
| 7661 | public static final int REPORT_LOSING_FOCUS = 3; |
| 7662 | public static final int ANIMATE = 4; |
| 7663 | public static final int ADD_STARTING = 5; |
| 7664 | public static final int REMOVE_STARTING = 6; |
| 7665 | public static final int FINISHED_STARTING = 7; |
| 7666 | public static final int REPORT_APPLICATION_TOKEN_WINDOWS = 8; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7667 | public static final int WINDOW_FREEZE_TIMEOUT = 11; |
| 7668 | public static final int HOLD_SCREEN_CHANGED = 12; |
| 7669 | public static final int APP_TRANSITION_TIMEOUT = 13; |
| 7670 | public static final int PERSIST_ANIMATION_SCALE = 14; |
| 7671 | public static final int FORCE_GC = 15; |
| 7672 | public static final int ENABLE_SCREEN = 16; |
| 7673 | public static final int APP_FREEZE_TIMEOUT = 17; |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 7674 | public static final int SEND_NEW_CONFIGURATION = 18; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7675 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7676 | private Session mLastReportedHold; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7677 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7678 | public H() { |
| 7679 | } |
| 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 | @Override |
| 7682 | public void handleMessage(Message msg) { |
| 7683 | switch (msg.what) { |
| 7684 | case REPORT_FOCUS_CHANGE: { |
| 7685 | WindowState lastFocus; |
| 7686 | WindowState newFocus; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7687 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7688 | synchronized(mWindowMap) { |
| 7689 | lastFocus = mLastFocus; |
| 7690 | newFocus = mCurrentFocus; |
| 7691 | if (lastFocus == newFocus) { |
| 7692 | // Focus is not changing, so nothing to do. |
| 7693 | return; |
| 7694 | } |
| 7695 | mLastFocus = newFocus; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7696 | //Slog.i(TAG, "Focus moving from " + lastFocus |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7697 | // + " to " + newFocus); |
| 7698 | if (newFocus != null && lastFocus != null |
| 7699 | && !newFocus.isDisplayedLw()) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7700 | //Slog.i(TAG, "Delaying loss of focus..."); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7701 | mLosingFocus.add(lastFocus); |
| 7702 | lastFocus = null; |
| 7703 | } |
| 7704 | } |
| 7705 | |
| 7706 | if (lastFocus != newFocus) { |
| 7707 | //System.out.println("Changing focus from " + lastFocus |
| 7708 | // + " to " + newFocus); |
| 7709 | if (newFocus != null) { |
| 7710 | try { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7711 | //Slog.i(TAG, "Gaining focus: " + newFocus); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7712 | newFocus.mClient.windowFocusChanged(true, mInTouchMode); |
| 7713 | } catch (RemoteException e) { |
| 7714 | // Ignore if process has died. |
| 7715 | } |
| 7716 | } |
| 7717 | |
| 7718 | if (lastFocus != null) { |
| 7719 | try { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7720 | //Slog.i(TAG, "Losing focus: " + lastFocus); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7721 | lastFocus.mClient.windowFocusChanged(false, mInTouchMode); |
| 7722 | } catch (RemoteException e) { |
| 7723 | // Ignore if process has died. |
| 7724 | } |
| 7725 | } |
| 7726 | } |
| 7727 | } break; |
| 7728 | |
| 7729 | case REPORT_LOSING_FOCUS: { |
| 7730 | ArrayList<WindowState> losers; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7731 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7732 | synchronized(mWindowMap) { |
| 7733 | losers = mLosingFocus; |
| 7734 | mLosingFocus = new ArrayList<WindowState>(); |
| 7735 | } |
| 7736 | |
| 7737 | final int N = losers.size(); |
| 7738 | for (int i=0; i<N; i++) { |
| 7739 | try { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7740 | //Slog.i(TAG, "Losing delayed focus: " + losers.get(i)); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7741 | losers.get(i).mClient.windowFocusChanged(false, mInTouchMode); |
| 7742 | } catch (RemoteException e) { |
| 7743 | // Ignore if process has died. |
| 7744 | } |
| 7745 | } |
| 7746 | } break; |
| 7747 | |
| 7748 | case ANIMATE: { |
| 7749 | synchronized(mWindowMap) { |
| 7750 | mAnimationPending = false; |
| 7751 | performLayoutAndPlaceSurfacesLocked(); |
| 7752 | } |
| 7753 | } break; |
| 7754 | |
| 7755 | case ADD_STARTING: { |
| 7756 | final AppWindowToken wtoken = (AppWindowToken)msg.obj; |
| 7757 | final StartingData sd = wtoken.startingData; |
| 7758 | |
| 7759 | if (sd == null) { |
| 7760 | // Animation has been canceled... do nothing. |
| 7761 | return; |
| 7762 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7763 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7764 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Add starting " |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7765 | + wtoken + ": pkg=" + sd.pkg); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7766 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7767 | View view = null; |
| 7768 | try { |
| 7769 | view = mPolicy.addStartingWindow( |
| 7770 | wtoken.token, sd.pkg, |
| 7771 | sd.theme, sd.nonLocalizedLabel, sd.labelRes, |
| 7772 | sd.icon); |
| 7773 | } catch (Exception e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7774 | Slog.w(TAG, "Exception when adding starting window", e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7775 | } |
| 7776 | |
| 7777 | if (view != null) { |
| 7778 | boolean abort = false; |
| 7779 | |
| 7780 | synchronized(mWindowMap) { |
| 7781 | if (wtoken.removed || wtoken.startingData == null) { |
| 7782 | // If the window was successfully added, then |
| 7783 | // we need to remove it. |
| 7784 | if (wtoken.startingWindow != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7785 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7786 | "Aborted starting " + wtoken |
| 7787 | + ": removed=" + wtoken.removed |
| 7788 | + " startingData=" + wtoken.startingData); |
| 7789 | wtoken.startingWindow = null; |
| 7790 | wtoken.startingData = null; |
| 7791 | abort = true; |
| 7792 | } |
| 7793 | } else { |
| 7794 | wtoken.startingView = view; |
| 7795 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7796 | if (DEBUG_STARTING_WINDOW && !abort) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7797 | "Added starting " + wtoken |
| 7798 | + ": startingWindow=" |
| 7799 | + wtoken.startingWindow + " startingView=" |
| 7800 | + wtoken.startingView); |
| 7801 | } |
| 7802 | |
| 7803 | if (abort) { |
| 7804 | try { |
| 7805 | mPolicy.removeStartingWindow(wtoken.token, view); |
| 7806 | } catch (Exception e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7807 | Slog.w(TAG, "Exception when removing starting window", e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7808 | } |
| 7809 | } |
| 7810 | } |
| 7811 | } break; |
| 7812 | |
| 7813 | case REMOVE_STARTING: { |
| 7814 | final AppWindowToken wtoken = (AppWindowToken)msg.obj; |
| 7815 | IBinder token = null; |
| 7816 | View view = null; |
| 7817 | synchronized (mWindowMap) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7818 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Remove starting " |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7819 | + wtoken + ": startingWindow=" |
| 7820 | + wtoken.startingWindow + " startingView=" |
| 7821 | + wtoken.startingView); |
| 7822 | if (wtoken.startingWindow != null) { |
| 7823 | view = wtoken.startingView; |
| 7824 | token = wtoken.token; |
| 7825 | wtoken.startingData = null; |
| 7826 | wtoken.startingView = null; |
| 7827 | wtoken.startingWindow = null; |
| 7828 | } |
| 7829 | } |
| 7830 | if (view != null) { |
| 7831 | try { |
| 7832 | mPolicy.removeStartingWindow(token, view); |
| 7833 | } catch (Exception e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7834 | Slog.w(TAG, "Exception when removing starting window", e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7835 | } |
| 7836 | } |
| 7837 | } break; |
| 7838 | |
| 7839 | case FINISHED_STARTING: { |
| 7840 | IBinder token = null; |
| 7841 | View view = null; |
| 7842 | while (true) { |
| 7843 | synchronized (mWindowMap) { |
| 7844 | final int N = mFinishedStarting.size(); |
| 7845 | if (N <= 0) { |
| 7846 | break; |
| 7847 | } |
| 7848 | AppWindowToken wtoken = mFinishedStarting.remove(N-1); |
| 7849 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7850 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7851 | "Finished starting " + wtoken |
| 7852 | + ": startingWindow=" + wtoken.startingWindow |
| 7853 | + " startingView=" + wtoken.startingView); |
| 7854 | |
| 7855 | if (wtoken.startingWindow == null) { |
| 7856 | continue; |
| 7857 | } |
| 7858 | |
| 7859 | view = wtoken.startingView; |
| 7860 | token = wtoken.token; |
| 7861 | wtoken.startingData = null; |
| 7862 | wtoken.startingView = null; |
| 7863 | wtoken.startingWindow = null; |
| 7864 | } |
| 7865 | |
| 7866 | try { |
| 7867 | mPolicy.removeStartingWindow(token, view); |
| 7868 | } catch (Exception e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7869 | Slog.w(TAG, "Exception when removing starting window", e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7870 | } |
| 7871 | } |
| 7872 | } break; |
| 7873 | |
| 7874 | case REPORT_APPLICATION_TOKEN_WINDOWS: { |
| 7875 | final AppWindowToken wtoken = (AppWindowToken)msg.obj; |
| 7876 | |
| 7877 | boolean nowVisible = msg.arg1 != 0; |
| 7878 | boolean nowGone = msg.arg2 != 0; |
| 7879 | |
| 7880 | try { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7881 | if (DEBUG_VISIBILITY) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7882 | TAG, "Reporting visible in " + wtoken |
| 7883 | + " visible=" + nowVisible |
| 7884 | + " gone=" + nowGone); |
| 7885 | if (nowVisible) { |
| 7886 | wtoken.appToken.windowsVisible(); |
| 7887 | } else { |
| 7888 | wtoken.appToken.windowsGone(); |
| 7889 | } |
| 7890 | } catch (RemoteException ex) { |
| 7891 | } |
| 7892 | } break; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7893 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7894 | case WINDOW_FREEZE_TIMEOUT: { |
| 7895 | synchronized (mWindowMap) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7896 | Slog.w(TAG, "Window freeze timeout expired."); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7897 | int i = mWindows.size(); |
| 7898 | while (i > 0) { |
| 7899 | i--; |
| 7900 | WindowState w = (WindowState)mWindows.get(i); |
| 7901 | if (w.mOrientationChanging) { |
| 7902 | w.mOrientationChanging = false; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7903 | Slog.w(TAG, "Force clearing orientation change: " + w); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7904 | } |
| 7905 | } |
| 7906 | performLayoutAndPlaceSurfacesLocked(); |
| 7907 | } |
| 7908 | break; |
| 7909 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7910 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7911 | case HOLD_SCREEN_CHANGED: { |
| 7912 | Session oldHold; |
| 7913 | Session newHold; |
| 7914 | synchronized (mWindowMap) { |
| 7915 | oldHold = mLastReportedHold; |
| 7916 | newHold = (Session)msg.obj; |
| 7917 | mLastReportedHold = newHold; |
| 7918 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7919 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7920 | if (oldHold != newHold) { |
| 7921 | try { |
| 7922 | if (oldHold != null) { |
| 7923 | mBatteryStats.noteStopWakelock(oldHold.mUid, |
| 7924 | "window", |
| 7925 | BatteryStats.WAKE_TYPE_WINDOW); |
| 7926 | } |
| 7927 | if (newHold != null) { |
| 7928 | mBatteryStats.noteStartWakelock(newHold.mUid, |
| 7929 | "window", |
| 7930 | BatteryStats.WAKE_TYPE_WINDOW); |
| 7931 | } |
| 7932 | } catch (RemoteException e) { |
| 7933 | } |
| 7934 | } |
| 7935 | break; |
| 7936 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7937 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7938 | case APP_TRANSITION_TIMEOUT: { |
| 7939 | synchronized (mWindowMap) { |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 7940 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7941 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7942 | "*** APP TRANSITION TIMEOUT"); |
| 7943 | mAppTransitionReady = true; |
| 7944 | mAppTransitionTimeout = true; |
| 7945 | performLayoutAndPlaceSurfacesLocked(); |
| 7946 | } |
| 7947 | } |
| 7948 | break; |
| 7949 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7950 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7951 | case PERSIST_ANIMATION_SCALE: { |
| 7952 | Settings.System.putFloat(mContext.getContentResolver(), |
| 7953 | Settings.System.WINDOW_ANIMATION_SCALE, mWindowAnimationScale); |
| 7954 | Settings.System.putFloat(mContext.getContentResolver(), |
| 7955 | Settings.System.TRANSITION_ANIMATION_SCALE, mTransitionAnimationScale); |
| 7956 | break; |
| 7957 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7958 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7959 | case FORCE_GC: { |
| 7960 | synchronized(mWindowMap) { |
| 7961 | if (mAnimationPending) { |
| 7962 | // If we are animating, don't do the gc now but |
| 7963 | // delay a bit so we don't interrupt the animation. |
| 7964 | mH.sendMessageDelayed(mH.obtainMessage(H.FORCE_GC), |
| 7965 | 2000); |
| 7966 | return; |
| 7967 | } |
| 7968 | // If we are currently rotating the display, it will |
| 7969 | // schedule a new message when done. |
| 7970 | if (mDisplayFrozen) { |
| 7971 | return; |
| 7972 | } |
| 7973 | mFreezeGcPending = 0; |
| 7974 | } |
| 7975 | Runtime.getRuntime().gc(); |
| 7976 | break; |
| 7977 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7978 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7979 | case ENABLE_SCREEN: { |
| 7980 | performEnableScreen(); |
| 7981 | break; |
| 7982 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7983 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7984 | case APP_FREEZE_TIMEOUT: { |
| 7985 | synchronized (mWindowMap) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7986 | Slog.w(TAG, "App freeze timeout expired."); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7987 | int i = mAppTokens.size(); |
| 7988 | while (i > 0) { |
| 7989 | i--; |
| 7990 | AppWindowToken tok = mAppTokens.get(i); |
| 7991 | if (tok.freezingScreen) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7992 | Slog.w(TAG, "Force clearing freeze: " + tok); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7993 | unsetAppFreezingScreenLocked(tok, true, true); |
| 7994 | } |
| 7995 | } |
| 7996 | } |
| 7997 | break; |
| 7998 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7999 | |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 8000 | case SEND_NEW_CONFIGURATION: { |
| 8001 | removeMessages(SEND_NEW_CONFIGURATION); |
| 8002 | sendNewConfiguration(); |
| The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 8003 | break; |
| 8004 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8005 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8006 | } |
| 8007 | } |
| 8008 | } |
| 8009 | |
| 8010 | // ------------------------------------------------------------- |
| 8011 | // IWindowManager API |
| 8012 | // ------------------------------------------------------------- |
| 8013 | |
| 8014 | public IWindowSession openSession(IInputMethodClient client, |
| 8015 | IInputContext inputContext) { |
| 8016 | if (client == null) throw new IllegalArgumentException("null client"); |
| 8017 | if (inputContext == null) throw new IllegalArgumentException("null inputContext"); |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 8018 | Session session = new Session(client, inputContext); |
| 8019 | return session; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8020 | } |
| 8021 | |
| 8022 | public boolean inputMethodClientHasFocus(IInputMethodClient client) { |
| 8023 | synchronized (mWindowMap) { |
| 8024 | // The focus for the client is the window immediately below |
| 8025 | // where we would place the input method window. |
| 8026 | int idx = findDesiredInputMethodWindowIndexLocked(false); |
| 8027 | WindowState imFocus; |
| 8028 | if (idx > 0) { |
| 8029 | imFocus = (WindowState)mWindows.get(idx-1); |
| 8030 | if (imFocus != null) { |
| 8031 | if (imFocus.mSession.mClient != null && |
| 8032 | imFocus.mSession.mClient.asBinder() == client.asBinder()) { |
| 8033 | return true; |
| 8034 | } |
| 8035 | } |
| 8036 | } |
| 8037 | } |
| 8038 | return false; |
| 8039 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8040 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8041 | // ------------------------------------------------------------- |
| 8042 | // Internals |
| 8043 | // ------------------------------------------------------------- |
| 8044 | |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 8045 | final WindowState windowForClientLocked(Session session, IWindow client, |
| 8046 | boolean throwOnError) { |
| 8047 | return windowForClientLocked(session, client.asBinder(), throwOnError); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8048 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8049 | |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 8050 | final WindowState windowForClientLocked(Session session, IBinder client, |
| 8051 | boolean throwOnError) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8052 | WindowState win = mWindowMap.get(client); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8053 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8054 | TAG, "Looking up client " + client + ": " + win); |
| 8055 | if (win == null) { |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 8056 | RuntimeException ex = new IllegalArgumentException( |
| 8057 | "Requested window " + client + " does not exist"); |
| 8058 | if (throwOnError) { |
| 8059 | throw ex; |
| 8060 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8061 | Slog.w(TAG, "Failed looking up window", ex); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8062 | return null; |
| 8063 | } |
| 8064 | if (session != null && win.mSession != session) { |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 8065 | RuntimeException ex = new IllegalArgumentException( |
| 8066 | "Requested window " + client + " is in session " + |
| 8067 | win.mSession + ", not " + session); |
| 8068 | if (throwOnError) { |
| 8069 | throw ex; |
| 8070 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8071 | Slog.w(TAG, "Failed looking up window", ex); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8072 | return null; |
| 8073 | } |
| 8074 | |
| 8075 | return win; |
| 8076 | } |
| 8077 | |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8078 | final void rebuildAppWindowListLocked() { |
| 8079 | int NW = mWindows.size(); |
| 8080 | int i; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8081 | int lastWallpaper = -1; |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 8082 | int numRemoved = 0; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8083 | |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8084 | // First remove all existing app windows. |
| 8085 | i=0; |
| 8086 | while (i < NW) { |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8087 | WindowState w = (WindowState)mWindows.get(i); |
| 8088 | if (w.mAppToken != null) { |
| Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 8089 | WindowState win = (WindowState)mWindows.remove(i); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8090 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, |
| Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 8091 | "Rebuild removing window: " + win); |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8092 | NW--; |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 8093 | numRemoved++; |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8094 | continue; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8095 | } else if (w.mAttrs.type == WindowManager.LayoutParams.TYPE_WALLPAPER |
| 8096 | && lastWallpaper == i-1) { |
| 8097 | lastWallpaper = i; |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8098 | } |
| 8099 | i++; |
| 8100 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8101 | |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8102 | // The wallpaper window(s) typically live at the bottom of the stack, |
| 8103 | // so skip them before adding app tokens. |
| 8104 | lastWallpaper++; |
| 8105 | i = lastWallpaper; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8106 | |
| Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 8107 | // First add all of the exiting app tokens... these are no longer |
| 8108 | // in the main app list, but still have windows shown. We put them |
| 8109 | // in the back because now that the animation is over we no longer |
| 8110 | // will care about them. |
| 8111 | int NT = mExitingAppTokens.size(); |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8112 | for (int j=0; j<NT; j++) { |
| Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 8113 | i = reAddAppWindowsLocked(i, mExitingAppTokens.get(j)); |
| 8114 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8115 | |
| Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 8116 | // And add in the still active app tokens in Z order. |
| 8117 | NT = mAppTokens.size(); |
| 8118 | for (int j=0; j<NT; j++) { |
| 8119 | i = reAddAppWindowsLocked(i, mAppTokens.get(j)); |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8120 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8121 | |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8122 | i -= lastWallpaper; |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 8123 | if (i != numRemoved) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8124 | Slog.w(TAG, "Rebuild removed " + numRemoved |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 8125 | + " windows but added " + i); |
| 8126 | } |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8127 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8128 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8129 | private final void assignLayersLocked() { |
| 8130 | int N = mWindows.size(); |
| 8131 | int curBaseLayer = 0; |
| 8132 | int curLayer = 0; |
| 8133 | int i; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8134 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8135 | for (i=0; i<N; i++) { |
| 8136 | WindowState w = (WindowState)mWindows.get(i); |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 8137 | if (w.mBaseLayer == curBaseLayer || w.mIsImWindow |
| 8138 | || (i > 0 && w.mIsWallpaper)) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8139 | curLayer += WINDOW_LAYER_MULTIPLIER; |
| 8140 | w.mLayer = curLayer; |
| 8141 | } else { |
| 8142 | curBaseLayer = curLayer = w.mBaseLayer; |
| 8143 | w.mLayer = curLayer; |
| 8144 | } |
| 8145 | if (w.mTargetAppToken != null) { |
| 8146 | w.mAnimLayer = w.mLayer + w.mTargetAppToken.animLayerAdjustment; |
| 8147 | } else if (w.mAppToken != null) { |
| 8148 | w.mAnimLayer = w.mLayer + w.mAppToken.animLayerAdjustment; |
| 8149 | } else { |
| 8150 | w.mAnimLayer = w.mLayer; |
| 8151 | } |
| 8152 | if (w.mIsImWindow) { |
| 8153 | w.mAnimLayer += mInputMethodAnimLayerAdjustment; |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 8154 | } else if (w.mIsWallpaper) { |
| 8155 | w.mAnimLayer += mWallpaperAnimLayerAdjustment; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8156 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8157 | if (DEBUG_LAYERS) Slog.v(TAG, "Assign layer " + w + ": " |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8158 | + w.mAnimLayer); |
| 8159 | //System.out.println( |
| 8160 | // "Assigned layer " + curLayer + " to " + w.mClient.asBinder()); |
| 8161 | } |
| 8162 | } |
| 8163 | |
| 8164 | private boolean mInLayout = false; |
| 8165 | private final void performLayoutAndPlaceSurfacesLocked() { |
| 8166 | if (mInLayout) { |
| Dave Bort | cfe6524 | 2009-04-09 14:51:04 -0700 | [diff] [blame] | 8167 | if (DEBUG) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8168 | throw new RuntimeException("Recursive call!"); |
| 8169 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8170 | Slog.w(TAG, "performLayoutAndPlaceSurfacesLocked called while in layout"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8171 | return; |
| 8172 | } |
| 8173 | |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 8174 | if (mWaitingForConfig) { |
| 8175 | // Our configuration has changed (most likely rotation), but we |
| 8176 | // don't yet have the complete configuration to report to |
| 8177 | // applications. Don't do any window layout until we have it. |
| 8178 | return; |
| 8179 | } |
| 8180 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8181 | boolean recoveringMemory = false; |
| 8182 | if (mForceRemoves != null) { |
| 8183 | recoveringMemory = true; |
| 8184 | // Wait a little it for things to settle down, and off we go. |
| 8185 | for (int i=0; i<mForceRemoves.size(); i++) { |
| 8186 | WindowState ws = mForceRemoves.get(i); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8187 | Slog.i(TAG, "Force removing: " + ws); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8188 | removeWindowInnerLocked(ws.mSession, ws); |
| 8189 | } |
| 8190 | mForceRemoves = null; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8191 | Slog.w(TAG, "Due to memory failure, waiting a bit for next layout"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8192 | Object tmp = new Object(); |
| 8193 | synchronized (tmp) { |
| 8194 | try { |
| 8195 | tmp.wait(250); |
| 8196 | } catch (InterruptedException e) { |
| 8197 | } |
| 8198 | } |
| 8199 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8200 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8201 | mInLayout = true; |
| 8202 | try { |
| 8203 | performLayoutAndPlaceSurfacesLockedInner(recoveringMemory); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8204 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8205 | int i = mPendingRemove.size()-1; |
| 8206 | if (i >= 0) { |
| 8207 | while (i >= 0) { |
| 8208 | WindowState w = mPendingRemove.get(i); |
| 8209 | removeWindowInnerLocked(w.mSession, w); |
| 8210 | i--; |
| 8211 | } |
| 8212 | mPendingRemove.clear(); |
| 8213 | |
| 8214 | mInLayout = false; |
| 8215 | assignLayersLocked(); |
| 8216 | mLayoutNeeded = true; |
| 8217 | performLayoutAndPlaceSurfacesLocked(); |
| 8218 | |
| 8219 | } else { |
| 8220 | mInLayout = false; |
| 8221 | if (mLayoutNeeded) { |
| 8222 | requestAnimationLocked(0); |
| 8223 | } |
| 8224 | } |
| 8225 | } catch (RuntimeException e) { |
| 8226 | mInLayout = false; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8227 | Slog.e(TAG, "Unhandled exception while layout out windows", e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8228 | } |
| 8229 | } |
| 8230 | |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 8231 | private final int performLayoutLockedInner() { |
| 8232 | if (!mLayoutNeeded) { |
| 8233 | return 0; |
| 8234 | } |
| 8235 | |
| 8236 | mLayoutNeeded = false; |
| 8237 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8238 | final int dw = mDisplay.getWidth(); |
| 8239 | final int dh = mDisplay.getHeight(); |
| 8240 | |
| 8241 | final int N = mWindows.size(); |
| 8242 | int i; |
| 8243 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8244 | if (DEBUG_LAYOUT) Slog.v(TAG, "performLayout: needed=" |
| Dianne Hackborn | 9b52a21 | 2009-12-11 14:51:35 -0800 | [diff] [blame] | 8245 | + mLayoutNeeded + " dw=" + dw + " dh=" + dh); |
| 8246 | |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 8247 | mPolicy.beginLayoutLw(dw, dh); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8248 | |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 8249 | int seq = mLayoutSeq+1; |
| 8250 | if (seq < 0) seq = 0; |
| 8251 | mLayoutSeq = seq; |
| 8252 | |
| 8253 | // First perform layout of any root windows (not attached |
| 8254 | // to another window). |
| 8255 | int topAttached = -1; |
| 8256 | for (i = N-1; i >= 0; i--) { |
| 8257 | WindowState win = (WindowState) mWindows.get(i); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8258 | |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 8259 | // Don't do layout of a window if it is not visible, or |
| 8260 | // soon won't be visible, to avoid wasting time and funky |
| 8261 | // changes while a window is animating away. |
| 8262 | final AppWindowToken atoken = win.mAppToken; |
| 8263 | final boolean gone = win.mViewVisibility == View.GONE |
| 8264 | || !win.mRelayoutCalled |
| 8265 | || win.mRootToken.hidden |
| 8266 | || (atoken != null && atoken.hiddenRequested) |
| 8267 | || win.mAttachedHidden |
| 8268 | || win.mExiting || win.mDestroying; |
| 8269 | |
| 8270 | if (!win.mLayoutAttached) { |
| 8271 | if (DEBUG_LAYOUT) Slog.v(TAG, "First pass " + win |
| 8272 | + ": gone=" + gone + " mHaveFrame=" + win.mHaveFrame |
| 8273 | + " mLayoutAttached=" + win.mLayoutAttached); |
| 8274 | if (DEBUG_LAYOUT && gone) Slog.v(TAG, " (mViewVisibility=" |
| 8275 | + win.mViewVisibility + " mRelayoutCalled=" |
| 8276 | + win.mRelayoutCalled + " hidden=" |
| 8277 | + win.mRootToken.hidden + " hiddenRequested=" |
| 8278 | + (atoken != null && atoken.hiddenRequested) |
| 8279 | + " mAttachedHidden=" + win.mAttachedHidden); |
| 8280 | } |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 8281 | |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 8282 | // If this view is GONE, then skip it -- keep the current |
| 8283 | // frame, and let the caller know so they can ignore it |
| 8284 | // if they want. (We do the normal layout for INVISIBLE |
| 8285 | // windows, since that means "perform layout as normal, |
| 8286 | // just don't display"). |
| 8287 | if (!gone || !win.mHaveFrame) { |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 8288 | if (!win.mLayoutAttached) { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 8289 | mPolicy.layoutWindowLw(win, win.mAttrs, null); |
| 8290 | win.mLayoutSeq = seq; |
| 8291 | if (DEBUG_LAYOUT) Slog.v(TAG, "-> mFrame=" |
| 8292 | + win.mFrame + " mContainingFrame=" |
| 8293 | + win.mContainingFrame + " mDisplayFrame=" |
| 8294 | + win.mDisplayFrame); |
| 8295 | } else { |
| 8296 | if (topAttached < 0) topAttached = i; |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 8297 | } |
| Dianne Hackborn | 958b9ad | 2009-03-31 18:00:36 -0700 | [diff] [blame] | 8298 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8299 | } |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 8300 | |
| 8301 | // Now perform layout of attached windows, which usually |
| 8302 | // depend on the position of the window they are attached to. |
| 8303 | // XXX does not deal with windows that are attached to windows |
| 8304 | // that are themselves attached. |
| 8305 | for (i = topAttached; i >= 0; i--) { |
| 8306 | WindowState win = (WindowState) mWindows.get(i); |
| 8307 | |
| 8308 | // If this view is GONE, then skip it -- keep the current |
| 8309 | // frame, and let the caller know so they can ignore it |
| 8310 | // if they want. (We do the normal layout for INVISIBLE |
| 8311 | // windows, since that means "perform layout as normal, |
| 8312 | // just don't display"). |
| 8313 | if (win.mLayoutAttached) { |
| 8314 | if (DEBUG_LAYOUT) Slog.v(TAG, "Second pass " + win |
| 8315 | + " mHaveFrame=" + win.mHaveFrame |
| 8316 | + " mViewVisibility=" + win.mViewVisibility |
| 8317 | + " mRelayoutCalled=" + win.mRelayoutCalled); |
| 8318 | if ((win.mViewVisibility != View.GONE && win.mRelayoutCalled) |
| 8319 | || !win.mHaveFrame) { |
| 8320 | mPolicy.layoutWindowLw(win, win.mAttrs, win.mAttachedWindow); |
| 8321 | win.mLayoutSeq = seq; |
| 8322 | if (DEBUG_LAYOUT) Slog.v(TAG, "-> mFrame=" |
| 8323 | + win.mFrame + " mContainingFrame=" |
| 8324 | + win.mContainingFrame + " mDisplayFrame=" |
| 8325 | + win.mDisplayFrame); |
| 8326 | } |
| 8327 | } |
| 8328 | } |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 8329 | |
| 8330 | // Window frames may have changed. Tell the input dispatcher about it. |
| Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 8331 | mInputMonitor.updateInputWindowsLw(); |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 8332 | |
| 8333 | return mPolicy.finishLayoutLw(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8334 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8335 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8336 | private final void performLayoutAndPlaceSurfacesLockedInner( |
| 8337 | boolean recoveringMemory) { |
| 8338 | final long currentTime = SystemClock.uptimeMillis(); |
| 8339 | final int dw = mDisplay.getWidth(); |
| 8340 | final int dh = mDisplay.getHeight(); |
| 8341 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8342 | int i; |
| 8343 | |
| Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 8344 | if (mFocusMayChange) { |
| 8345 | mFocusMayChange = false; |
| 8346 | updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES); |
| 8347 | } |
| 8348 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8349 | if (mFxSession == null) { |
| 8350 | mFxSession = new SurfaceSession(); |
| 8351 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8352 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8353 | if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8354 | |
| 8355 | // Initialize state of exiting tokens. |
| 8356 | for (i=mExitingTokens.size()-1; i>=0; i--) { |
| 8357 | mExitingTokens.get(i).hasVisible = false; |
| 8358 | } |
| 8359 | |
| 8360 | // Initialize state of exiting applications. |
| 8361 | for (i=mExitingAppTokens.size()-1; i>=0; i--) { |
| 8362 | mExitingAppTokens.get(i).hasVisible = false; |
| 8363 | } |
| 8364 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8365 | boolean orientationChangeComplete = true; |
| 8366 | Session holdScreen = null; |
| 8367 | float screenBrightness = -1; |
| Mike Lockwood | fb73f79 | 2009-11-20 11:31:18 -0500 | [diff] [blame] | 8368 | float buttonBrightness = -1; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8369 | boolean focusDisplayed = false; |
| 8370 | boolean animating = false; |
| 8371 | |
| 8372 | Surface.openTransaction(); |
| 8373 | try { |
| Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 8374 | boolean wallpaperForceHidingChanged = false; |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 8375 | int repeats = 0; |
| 8376 | int changes = 0; |
| 8377 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8378 | do { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 8379 | repeats++; |
| 8380 | if (repeats > 6) { |
| 8381 | Slog.w(TAG, "Animation repeat aborted after too many iterations"); |
| 8382 | mLayoutNeeded = false; |
| 8383 | break; |
| 8384 | } |
| 8385 | |
| 8386 | if ((changes&(WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER |
| 8387 | | WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG |
| 8388 | | WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT)) != 0) { |
| 8389 | if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER) != 0) { |
| 8390 | if ((adjustWallpaperWindowsLocked()&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) { |
| 8391 | assignLayersLocked(); |
| 8392 | mLayoutNeeded = true; |
| 8393 | } |
| 8394 | } |
| 8395 | if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG) != 0) { |
| 8396 | if (DEBUG_LAYOUT) Slog.v(TAG, "Computing new config from layout"); |
| 8397 | if (updateOrientationFromAppTokensLocked()) { |
| 8398 | mLayoutNeeded = true; |
| 8399 | mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION); |
| 8400 | } |
| 8401 | } |
| 8402 | if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT) != 0) { |
| 8403 | mLayoutNeeded = true; |
| 8404 | } |
| 8405 | } |
| 8406 | |
| 8407 | // FIRST LOOP: Perform a layout, if needed. |
| 8408 | if (repeats < 4) { |
| 8409 | changes = performLayoutLockedInner(); |
| 8410 | if (changes != 0) { |
| 8411 | continue; |
| 8412 | } |
| 8413 | } else { |
| 8414 | Slog.w(TAG, "Layout repeat skipped after too many iterations"); |
| 8415 | changes = 0; |
| 8416 | } |
| 8417 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8418 | final int transactionSequence = ++mTransactionSequence; |
| 8419 | |
| 8420 | // Update animations of all applications, including those |
| 8421 | // associated with exiting/removed apps |
| 8422 | boolean tokensAnimating = false; |
| 8423 | final int NAT = mAppTokens.size(); |
| 8424 | for (i=0; i<NAT; i++) { |
| 8425 | if (mAppTokens.get(i).stepAnimationLocked(currentTime, dw, dh)) { |
| 8426 | tokensAnimating = true; |
| 8427 | } |
| 8428 | } |
| 8429 | final int NEAT = mExitingAppTokens.size(); |
| 8430 | for (i=0; i<NEAT; i++) { |
| 8431 | if (mExitingAppTokens.get(i).stepAnimationLocked(currentTime, dw, dh)) { |
| 8432 | tokensAnimating = true; |
| 8433 | } |
| 8434 | } |
| 8435 | |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 8436 | // SECOND LOOP: Execute animations and update visibility of windows. |
| 8437 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8438 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "*** ANIM STEP: seq=" |
| Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 8439 | + transactionSequence + " tokensAnimating=" |
| 8440 | + tokensAnimating); |
| 8441 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8442 | animating = tokensAnimating; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8443 | |
| 8444 | boolean tokenMayBeDrawn = false; |
| Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 8445 | boolean wallpaperMayChange = false; |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 8446 | boolean forceHiding = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8447 | |
| 8448 | mPolicy.beginAnimationLw(dw, dh); |
| 8449 | |
| Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 8450 | final int N = mWindows.size(); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8451 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8452 | for (i=N-1; i>=0; i--) { |
| 8453 | WindowState w = (WindowState)mWindows.get(i); |
| 8454 | |
| 8455 | final WindowManager.LayoutParams attrs = w.mAttrs; |
| 8456 | |
| 8457 | if (w.mSurface != null) { |
| 8458 | // Execute animation. |
| Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 8459 | if (w.commitFinishDrawingLocked(currentTime)) { |
| 8460 | if ((w.mAttrs.flags |
| 8461 | & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER) != 0) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8462 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 8463 | "First draw done in potential wallpaper target " + w); |
| Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 8464 | wallpaperMayChange = true; |
| 8465 | } |
| 8466 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8467 | |
| Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 8468 | boolean wasAnimating = w.mAnimating; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8469 | if (w.stepAnimationLocked(currentTime, dw, dh)) { |
| 8470 | animating = true; |
| 8471 | //w.dump(" "); |
| 8472 | } |
| Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 8473 | if (wasAnimating && !w.mAnimating && mWallpaperTarget == w) { |
| 8474 | wallpaperMayChange = true; |
| 8475 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8476 | |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8477 | if (mPolicy.doesForceHide(w, attrs)) { |
| 8478 | if (!wasAnimating && animating) { |
| Dianne Hackborn | 20cb56e | 2010-03-04 00:58:29 -0800 | [diff] [blame] | 8479 | if (DEBUG_VISIBILITY) Slog.v(TAG, |
| 8480 | "Animation done that could impact force hide: " |
| 8481 | + w); |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8482 | wallpaperForceHidingChanged = true; |
| Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 8483 | mFocusMayChange = true; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8484 | } else if (w.isReadyForDisplay() && w.mAnimation == null) { |
| 8485 | forceHiding = true; |
| 8486 | } |
| 8487 | } else if (mPolicy.canBeForceHidden(w, attrs)) { |
| 8488 | boolean changed; |
| 8489 | if (forceHiding) { |
| 8490 | changed = w.hideLw(false, false); |
| Dianne Hackborn | 20cb56e | 2010-03-04 00:58:29 -0800 | [diff] [blame] | 8491 | if (DEBUG_VISIBILITY && changed) Slog.v(TAG, |
| 8492 | "Now policy hidden: " + w); |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8493 | } else { |
| 8494 | changed = w.showLw(false, false); |
| Dianne Hackborn | 20cb56e | 2010-03-04 00:58:29 -0800 | [diff] [blame] | 8495 | if (DEBUG_VISIBILITY && changed) Slog.v(TAG, |
| 8496 | "Now policy shown: " + w); |
| 8497 | if (changed) { |
| 8498 | if (wallpaperForceHidingChanged |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 8499 | && w.isVisibleNow() /*w.isReadyForDisplay()*/) { |
| Dianne Hackborn | 20cb56e | 2010-03-04 00:58:29 -0800 | [diff] [blame] | 8500 | // Assume we will need to animate. If |
| 8501 | // we don't (because the wallpaper will |
| 8502 | // stay with the lock screen), then we will |
| 8503 | // clean up later. |
| 8504 | Animation a = mPolicy.createForceHideEnterAnimation(); |
| 8505 | if (a != null) { |
| 8506 | w.setAnimation(a); |
| 8507 | } |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8508 | } |
| Dianne Hackborn | 20cb56e | 2010-03-04 00:58:29 -0800 | [diff] [blame] | 8509 | if (mCurrentFocus == null || |
| 8510 | mCurrentFocus.mLayer < w.mLayer) { |
| 8511 | // We are showing on to of the current |
| 8512 | // focus, so re-evaluate focus to make |
| 8513 | // sure it is correct. |
| 8514 | mFocusMayChange = true; |
| 8515 | } |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8516 | } |
| 8517 | } |
| 8518 | if (changed && (attrs.flags |
| 8519 | & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER) != 0) { |
| 8520 | wallpaperMayChange = true; |
| 8521 | } |
| 8522 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8523 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8524 | mPolicy.animatingWindowLw(w, attrs); |
| 8525 | } |
| 8526 | |
| 8527 | final AppWindowToken atoken = w.mAppToken; |
| 8528 | if (atoken != null && (!atoken.allDrawn || atoken.freezingScreen)) { |
| 8529 | if (atoken.lastTransactionSequence != transactionSequence) { |
| 8530 | atoken.lastTransactionSequence = transactionSequence; |
| 8531 | atoken.numInterestingWindows = atoken.numDrawnWindows = 0; |
| 8532 | atoken.startingDisplayed = false; |
| 8533 | } |
| 8534 | if ((w.isOnScreen() || w.mAttrs.type |
| 8535 | == WindowManager.LayoutParams.TYPE_BASE_APPLICATION) |
| 8536 | && !w.mExiting && !w.mDestroying) { |
| 8537 | if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8538 | Slog.v(TAG, "Eval win " + w + ": isDrawn=" |
| Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 8539 | + w.isDrawnLw() |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8540 | + ", isAnimating=" + w.isAnimating()); |
| Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 8541 | if (!w.isDrawnLw()) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8542 | Slog.v(TAG, "Not displayed: s=" + w.mSurface |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8543 | + " pv=" + w.mPolicyVisibility |
| 8544 | + " dp=" + w.mDrawPending |
| 8545 | + " cdp=" + w.mCommitDrawPending |
| 8546 | + " ah=" + w.mAttachedHidden |
| 8547 | + " th=" + atoken.hiddenRequested |
| 8548 | + " a=" + w.mAnimating); |
| 8549 | } |
| 8550 | } |
| 8551 | if (w != atoken.startingWindow) { |
| 8552 | if (!atoken.freezingScreen || !w.mAppFreezing) { |
| 8553 | atoken.numInterestingWindows++; |
| Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 8554 | if (w.isDrawnLw()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8555 | atoken.numDrawnWindows++; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8556 | if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8557 | "tokenMayBeDrawn: " + atoken |
| 8558 | + " freezingScreen=" + atoken.freezingScreen |
| 8559 | + " mAppFreezing=" + w.mAppFreezing); |
| 8560 | tokenMayBeDrawn = true; |
| 8561 | } |
| 8562 | } |
| Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 8563 | } else if (w.isDrawnLw()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8564 | atoken.startingDisplayed = true; |
| 8565 | } |
| 8566 | } |
| 8567 | } else if (w.mReadyToShow) { |
| 8568 | w.performShowLocked(); |
| 8569 | } |
| 8570 | } |
| 8571 | |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 8572 | changes |= mPolicy.finishAnimationLw(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8573 | |
| 8574 | if (tokenMayBeDrawn) { |
| 8575 | // See if any windows have been drawn, so they (and others |
| 8576 | // associated with them) can now be shown. |
| 8577 | final int NT = mTokenList.size(); |
| 8578 | for (i=0; i<NT; i++) { |
| 8579 | AppWindowToken wtoken = mTokenList.get(i).appWindowToken; |
| 8580 | if (wtoken == null) { |
| 8581 | continue; |
| 8582 | } |
| 8583 | if (wtoken.freezingScreen) { |
| 8584 | int numInteresting = wtoken.numInterestingWindows; |
| 8585 | if (numInteresting > 0 && wtoken.numDrawnWindows >= numInteresting) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8586 | if (DEBUG_VISIBILITY) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8587 | "allDrawn: " + wtoken |
| 8588 | + " interesting=" + numInteresting |
| 8589 | + " drawn=" + wtoken.numDrawnWindows); |
| 8590 | wtoken.showAllWindowsLocked(); |
| 8591 | unsetAppFreezingScreenLocked(wtoken, false, true); |
| 8592 | orientationChangeComplete = true; |
| 8593 | } |
| 8594 | } else if (!wtoken.allDrawn) { |
| 8595 | int numInteresting = wtoken.numInterestingWindows; |
| 8596 | if (numInteresting > 0 && wtoken.numDrawnWindows >= numInteresting) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8597 | if (DEBUG_VISIBILITY) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8598 | "allDrawn: " + wtoken |
| 8599 | + " interesting=" + numInteresting |
| 8600 | + " drawn=" + wtoken.numDrawnWindows); |
| 8601 | wtoken.allDrawn = true; |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 8602 | changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8603 | |
| 8604 | // We can now show all of the drawn windows! |
| 8605 | if (!mOpeningApps.contains(wtoken)) { |
| 8606 | wtoken.showAllWindowsLocked(); |
| 8607 | } |
| 8608 | } |
| 8609 | } |
| 8610 | } |
| 8611 | } |
| 8612 | |
| 8613 | // If we are ready to perform an app transition, check through |
| 8614 | // all of the app tokens to be shown and see if they are ready |
| 8615 | // to go. |
| 8616 | if (mAppTransitionReady) { |
| 8617 | int NN = mOpeningApps.size(); |
| 8618 | boolean goodToGo = true; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8619 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8620 | "Checking " + NN + " opening apps (frozen=" |
| 8621 | + mDisplayFrozen + " timeout=" |
| 8622 | + mAppTransitionTimeout + ")..."); |
| 8623 | if (!mDisplayFrozen && !mAppTransitionTimeout) { |
| 8624 | // If the display isn't frozen, wait to do anything until |
| 8625 | // all of the apps are ready. Otherwise just go because |
| 8626 | // we'll unfreeze the display when everyone is ready. |
| 8627 | for (i=0; i<NN && goodToGo; i++) { |
| 8628 | AppWindowToken wtoken = mOpeningApps.get(i); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8629 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8630 | "Check opening app" + wtoken + ": allDrawn=" |
| 8631 | + wtoken.allDrawn + " startingDisplayed=" |
| 8632 | + wtoken.startingDisplayed); |
| 8633 | if (!wtoken.allDrawn && !wtoken.startingDisplayed |
| 8634 | && !wtoken.startingMoved) { |
| 8635 | goodToGo = false; |
| 8636 | } |
| 8637 | } |
| 8638 | } |
| 8639 | if (goodToGo) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8640 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "**** GOOD TO GO"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8641 | int transit = mNextAppTransition; |
| 8642 | if (mSkipAppTransitionAnimation) { |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 8643 | transit = WindowManagerPolicy.TRANSIT_UNSET; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8644 | } |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 8645 | mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8646 | mAppTransitionReady = false; |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8647 | mAppTransitionRunning = true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8648 | mAppTransitionTimeout = false; |
| 8649 | mStartingIconInTransition = false; |
| 8650 | mSkipAppTransitionAnimation = false; |
| 8651 | |
| 8652 | mH.removeMessages(H.APP_TRANSITION_TIMEOUT); |
| 8653 | |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8654 | // If there are applications waiting to come to the |
| 8655 | // top of the stack, now is the time to move their windows. |
| 8656 | // (Note that we don't do apps going to the bottom |
| 8657 | // here -- we want to keep their windows in the old |
| 8658 | // Z-order until the animation completes.) |
| 8659 | if (mToTopApps.size() > 0) { |
| 8660 | NN = mAppTokens.size(); |
| 8661 | for (i=0; i<NN; i++) { |
| 8662 | AppWindowToken wtoken = mAppTokens.get(i); |
| 8663 | if (wtoken.sendingToTop) { |
| 8664 | wtoken.sendingToTop = false; |
| 8665 | moveAppWindowsLocked(wtoken, NN, false); |
| 8666 | } |
| 8667 | } |
| 8668 | mToTopApps.clear(); |
| 8669 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8670 | |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 8671 | WindowState oldWallpaper = mWallpaperTarget; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8672 | |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 8673 | adjustWallpaperWindowsLocked(); |
| Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 8674 | wallpaperMayChange = false; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8675 | |
| Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 8676 | // The top-most window will supply the layout params, |
| 8677 | // and we will determine it below. |
| 8678 | LayoutParams animLp = null; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8679 | AppWindowToken animToken = null; |
| Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 8680 | int bestAnimLayer = -1; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8681 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8682 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 8683 | "New wallpaper target=" + mWallpaperTarget |
| 8684 | + ", lower target=" + mLowerWallpaperTarget |
| 8685 | + ", upper target=" + mUpperWallpaperTarget); |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 8686 | int foundWallpapers = 0; |
| Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 8687 | // Do a first pass through the tokens for two |
| 8688 | // things: |
| 8689 | // (1) Determine if both the closing and opening |
| 8690 | // app token sets are wallpaper targets, in which |
| 8691 | // case special animations are needed |
| 8692 | // (since the wallpaper needs to stay static |
| 8693 | // behind them). |
| 8694 | // (2) Find the layout params of the top-most |
| 8695 | // application window in the tokens, which is |
| 8696 | // what will control the animation theme. |
| 8697 | final int NC = mClosingApps.size(); |
| 8698 | NN = NC + mOpeningApps.size(); |
| 8699 | for (i=0; i<NN; i++) { |
| 8700 | AppWindowToken wtoken; |
| 8701 | int mode; |
| 8702 | if (i < NC) { |
| 8703 | wtoken = mClosingApps.get(i); |
| 8704 | mode = 1; |
| 8705 | } else { |
| 8706 | wtoken = mOpeningApps.get(i-NC); |
| 8707 | mode = 2; |
| 8708 | } |
| 8709 | if (mLowerWallpaperTarget != null) { |
| 8710 | if (mLowerWallpaperTarget.mAppToken == wtoken |
| 8711 | || mUpperWallpaperTarget.mAppToken == wtoken) { |
| 8712 | foundWallpapers |= mode; |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 8713 | } |
| 8714 | } |
| Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 8715 | if (wtoken.appFullscreen) { |
| 8716 | WindowState ws = wtoken.findMainWindow(); |
| 8717 | if (ws != null) { |
| 8718 | // If this is a compatibility mode |
| 8719 | // window, we will always use its anim. |
| 8720 | if ((ws.mAttrs.flags&FLAG_COMPATIBLE_WINDOW) != 0) { |
| 8721 | animLp = ws.mAttrs; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8722 | animToken = ws.mAppToken; |
| Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 8723 | bestAnimLayer = Integer.MAX_VALUE; |
| 8724 | } else if (ws.mLayer > bestAnimLayer) { |
| 8725 | animLp = ws.mAttrs; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8726 | animToken = ws.mAppToken; |
| Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 8727 | bestAnimLayer = ws.mLayer; |
| 8728 | } |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 8729 | } |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 8730 | } |
| 8731 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8732 | |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 8733 | if (foundWallpapers == 3) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8734 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 8735 | "Wallpaper animation!"); |
| 8736 | switch (transit) { |
| 8737 | case WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN: |
| 8738 | case WindowManagerPolicy.TRANSIT_TASK_OPEN: |
| 8739 | case WindowManagerPolicy.TRANSIT_TASK_TO_FRONT: |
| 8740 | transit = WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_OPEN; |
| 8741 | break; |
| 8742 | case WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE: |
| 8743 | case WindowManagerPolicy.TRANSIT_TASK_CLOSE: |
| 8744 | case WindowManagerPolicy.TRANSIT_TASK_TO_BACK: |
| 8745 | transit = WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_CLOSE; |
| 8746 | break; |
| 8747 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8748 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 8749 | "New transit: " + transit); |
| 8750 | } else if (oldWallpaper != null) { |
| 8751 | // We are transitioning from an activity with |
| 8752 | // a wallpaper to one without. |
| 8753 | transit = WindowManagerPolicy.TRANSIT_WALLPAPER_CLOSE; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8754 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 8755 | "New transit away from wallpaper: " + transit); |
| 8756 | } else if (mWallpaperTarget != null) { |
| 8757 | // We are transitioning from an activity without |
| 8758 | // a wallpaper to now showing the wallpaper |
| 8759 | transit = WindowManagerPolicy.TRANSIT_WALLPAPER_OPEN; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8760 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 8761 | "New transit into wallpaper: " + transit); |
| 8762 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8763 | |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8764 | if ((transit&WindowManagerPolicy.TRANSIT_ENTER_MASK) != 0) { |
| 8765 | mLastEnterAnimToken = animToken; |
| 8766 | mLastEnterAnimParams = animLp; |
| 8767 | } else if (mLastEnterAnimParams != null) { |
| 8768 | animLp = mLastEnterAnimParams; |
| 8769 | mLastEnterAnimToken = null; |
| 8770 | mLastEnterAnimParams = null; |
| 8771 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8772 | |
| Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 8773 | // If all closing windows are obscured, then there is |
| 8774 | // no need to do an animation. This is the case, for |
| 8775 | // example, when this transition is being done behind |
| 8776 | // the lock screen. |
| 8777 | if (!mPolicy.allowAppAnimationsLw()) { |
| 8778 | animLp = null; |
| 8779 | } |
| 8780 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8781 | NN = mOpeningApps.size(); |
| 8782 | for (i=0; i<NN; i++) { |
| 8783 | AppWindowToken wtoken = mOpeningApps.get(i); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8784 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8785 | "Now opening app" + wtoken); |
| 8786 | wtoken.reportedVisible = false; |
| 8787 | wtoken.inPendingTransaction = false; |
| Dianne Hackborn | 83360b3 | 2009-08-24 18:43:32 -0700 | [diff] [blame] | 8788 | wtoken.animation = null; |
| Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 8789 | setTokenVisibilityLocked(wtoken, animLp, true, transit, false); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8790 | wtoken.updateReportedVisibilityLocked(); |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8791 | wtoken.waitingToShow = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8792 | wtoken.showAllWindowsLocked(); |
| 8793 | } |
| 8794 | NN = mClosingApps.size(); |
| 8795 | for (i=0; i<NN; i++) { |
| 8796 | AppWindowToken wtoken = mClosingApps.get(i); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8797 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8798 | "Now closing app" + wtoken); |
| 8799 | wtoken.inPendingTransaction = false; |
| Dianne Hackborn | 83360b3 | 2009-08-24 18:43:32 -0700 | [diff] [blame] | 8800 | wtoken.animation = null; |
| Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 8801 | setTokenVisibilityLocked(wtoken, animLp, false, transit, false); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8802 | wtoken.updateReportedVisibilityLocked(); |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8803 | wtoken.waitingToHide = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8804 | // Force the allDrawn flag, because we want to start |
| 8805 | // this guy's animations regardless of whether it's |
| 8806 | // gotten drawn. |
| 8807 | wtoken.allDrawn = true; |
| 8808 | } |
| 8809 | |
| Dianne Hackborn | 8b571a8 | 2009-09-25 16:09:43 -0700 | [diff] [blame] | 8810 | mNextAppTransitionPackage = null; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8811 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8812 | mOpeningApps.clear(); |
| 8813 | mClosingApps.clear(); |
| 8814 | |
| 8815 | // This has changed the visibility of windows, so perform |
| 8816 | // a new layout to get them all up-to-date. |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 8817 | changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8818 | mLayoutNeeded = true; |
| Dianne Hackborn | 20583ff | 2009-07-27 21:51:05 -0700 | [diff] [blame] | 8819 | if (!moveInputMethodWindowsIfNeededLocked(true)) { |
| 8820 | assignLayersLocked(); |
| 8821 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8822 | updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES); |
| Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 8823 | mFocusMayChange = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8824 | } |
| 8825 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8826 | |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 8827 | int adjResult = 0; |
| 8828 | |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8829 | if (!animating && mAppTransitionRunning) { |
| 8830 | // We have finished the animation of an app transition. To do |
| 8831 | // this, we have delayed a lot of operations like showing and |
| 8832 | // hiding apps, moving apps in Z-order, etc. The app token list |
| 8833 | // reflects the correct Z-order, but the window list may now |
| 8834 | // be out of sync with it. So here we will just rebuild the |
| 8835 | // entire app window list. Fun! |
| 8836 | mAppTransitionRunning = false; |
| 8837 | // Clear information about apps that were moving. |
| 8838 | mToBottomApps.clear(); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8839 | |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8840 | rebuildAppWindowListLocked(); |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 8841 | changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT; |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 8842 | adjResult |= ADJUST_WALLPAPER_LAYERS_CHANGED; |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8843 | moveInputMethodWindowsIfNeededLocked(false); |
| 8844 | wallpaperMayChange = true; |
| Suchi Amalapurapu | c9568e3 | 2009-11-05 18:51:16 -0800 | [diff] [blame] | 8845 | // Since the window list has been rebuilt, focus might |
| 8846 | // have to be recomputed since the actual order of windows |
| 8847 | // might have changed again. |
| Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 8848 | mFocusMayChange = true; |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8849 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8850 | |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 8851 | if (wallpaperForceHidingChanged && changes == 0 && !mAppTransitionReady) { |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8852 | // At this point, there was a window with a wallpaper that |
| 8853 | // was force hiding other windows behind it, but now it |
| 8854 | // is going away. This may be simple -- just animate |
| 8855 | // away the wallpaper and its window -- or it may be |
| 8856 | // hard -- the wallpaper now needs to be shown behind |
| 8857 | // something that was hidden. |
| 8858 | WindowState oldWallpaper = mWallpaperTarget; |
| Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 8859 | if (mLowerWallpaperTarget != null |
| 8860 | && mLowerWallpaperTarget.mAppToken != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8861 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
| Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 8862 | "wallpaperForceHiding changed with lower=" |
| 8863 | + mLowerWallpaperTarget); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8864 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
| Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 8865 | "hidden=" + mLowerWallpaperTarget.mAppToken.hidden + |
| 8866 | " hiddenRequested=" + mLowerWallpaperTarget.mAppToken.hiddenRequested); |
| 8867 | if (mLowerWallpaperTarget.mAppToken.hidden) { |
| 8868 | // The lower target has become hidden before we |
| 8869 | // actually started the animation... let's completely |
| 8870 | // re-evaluate everything. |
| 8871 | mLowerWallpaperTarget = mUpperWallpaperTarget = null; |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 8872 | changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM; |
| Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 8873 | } |
| 8874 | } |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 8875 | adjResult |= adjustWallpaperWindowsLocked(); |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8876 | wallpaperMayChange = false; |
| Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 8877 | wallpaperForceHidingChanged = false; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8878 | if (DEBUG_WALLPAPER) Slog.v(TAG, "****** OLD: " + oldWallpaper |
| Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 8879 | + " NEW: " + mWallpaperTarget |
| 8880 | + " LOWER: " + mLowerWallpaperTarget); |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8881 | if (mLowerWallpaperTarget == null) { |
| 8882 | // Whoops, we don't need a special wallpaper animation. |
| 8883 | // Clear them out. |
| 8884 | forceHiding = false; |
| 8885 | for (i=N-1; i>=0; i--) { |
| 8886 | WindowState w = (WindowState)mWindows.get(i); |
| 8887 | if (w.mSurface != null) { |
| 8888 | final WindowManager.LayoutParams attrs = w.mAttrs; |
| Suchi Amalapurapu | c03d28b | 2009-10-28 14:32:05 -0700 | [diff] [blame] | 8889 | if (mPolicy.doesForceHide(w, attrs) && w.isVisibleLw()) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8890 | if (DEBUG_FOCUS) Slog.i(TAG, "win=" + w + " force hides other windows"); |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8891 | forceHiding = true; |
| 8892 | } else if (mPolicy.canBeForceHidden(w, attrs)) { |
| 8893 | if (!w.mAnimating) { |
| 8894 | // We set the animation above so it |
| 8895 | // is not yet running. |
| 8896 | w.clearAnimation(); |
| 8897 | } |
| 8898 | } |
| 8899 | } |
| 8900 | } |
| 8901 | } |
| 8902 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8903 | |
| Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 8904 | if (wallpaperMayChange) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8905 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 8906 | "Wallpaper may change! Adjusting"); |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 8907 | adjResult |= adjustWallpaperWindowsLocked(); |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8908 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8909 | |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8910 | if ((adjResult&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8911 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8912 | "Wallpaper layer changed: assigning layers + relayout"); |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 8913 | changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8914 | assignLayersLocked(); |
| 8915 | } else if ((adjResult&ADJUST_WALLPAPER_VISIBILITY_CHANGED) != 0) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8916 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8917 | "Wallpaper visibility changed: relayout"); |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 8918 | changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8919 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8920 | |
| Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 8921 | if (mFocusMayChange) { |
| 8922 | mFocusMayChange = false; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8923 | if (updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES)) { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 8924 | changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8925 | adjResult = 0; |
| Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 8926 | } |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8927 | } |
| 8928 | |
| 8929 | if (mLayoutNeeded) { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 8930 | changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT; |
| Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 8931 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8932 | |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 8933 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "*** ANIM STEP: changes=0x" |
| 8934 | + Integer.toHexString(changes)); |
| Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 8935 | |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 8936 | } while (changes != 0); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8937 | |
| 8938 | // THIRD LOOP: Update the surfaces of all windows. |
| 8939 | |
| 8940 | final boolean someoneLosingFocus = mLosingFocus.size() != 0; |
| 8941 | |
| 8942 | boolean obscured = false; |
| 8943 | boolean blurring = false; |
| 8944 | boolean dimming = false; |
| 8945 | boolean covered = false; |
| Dianne Hackborn | 9ed4a4b | 2009-03-25 17:10:37 -0700 | [diff] [blame] | 8946 | boolean syswin = false; |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 8947 | boolean backgroundFillerShown = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8948 | |
| Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 8949 | final int N = mWindows.size(); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8950 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8951 | for (i=N-1; i>=0; i--) { |
| 8952 | WindowState w = (WindowState)mWindows.get(i); |
| 8953 | |
| 8954 | boolean displayed = false; |
| 8955 | final WindowManager.LayoutParams attrs = w.mAttrs; |
| 8956 | final int attrFlags = attrs.flags; |
| 8957 | |
| 8958 | if (w.mSurface != null) { |
| Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 8959 | // XXX NOTE: The logic here could be improved. We have |
| 8960 | // the decision about whether to resize a window separated |
| 8961 | // from whether to hide the surface. This can cause us to |
| 8962 | // resize a surface even if we are going to hide it. You |
| 8963 | // can see this by (1) holding device in landscape mode on |
| 8964 | // home screen; (2) tapping browser icon (device will rotate |
| 8965 | // to landscape; (3) tap home. The wallpaper will be resized |
| 8966 | // in step 2 but then immediately hidden, causing us to |
| 8967 | // have to resize and then redraw it again in step 3. It |
| 8968 | // would be nice to figure out how to avoid this, but it is |
| 8969 | // difficult because we do need to resize surfaces in some |
| 8970 | // cases while they are hidden such as when first showing a |
| 8971 | // window. |
| 8972 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8973 | w.computeShownFrameLocked(); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8974 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8975 | TAG, "Placing surface #" + i + " " + w.mSurface |
| 8976 | + ": new=" + w.mShownFrame + ", old=" |
| 8977 | + w.mLastShownFrame); |
| 8978 | |
| 8979 | boolean resize; |
| 8980 | int width, height; |
| 8981 | if ((w.mAttrs.flags & w.mAttrs.FLAG_SCALED) != 0) { |
| 8982 | resize = w.mLastRequestedWidth != w.mRequestedWidth || |
| 8983 | w.mLastRequestedHeight != w.mRequestedHeight; |
| 8984 | // for a scaled surface, we just want to use |
| 8985 | // the requested size. |
| 8986 | width = w.mRequestedWidth; |
| 8987 | height = w.mRequestedHeight; |
| 8988 | w.mLastRequestedWidth = width; |
| 8989 | w.mLastRequestedHeight = height; |
| 8990 | w.mLastShownFrame.set(w.mShownFrame); |
| 8991 | try { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 8992 | if (SHOW_TRANSACTIONS) logSurface(w, |
| 8993 | "POS " + w.mShownFrame.left |
| 8994 | + ", " + w.mShownFrame.top, null); |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 8995 | w.mSurfaceX = w.mShownFrame.left; |
| 8996 | w.mSurfaceY = w.mShownFrame.top; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8997 | w.mSurface.setPosition(w.mShownFrame.left, w.mShownFrame.top); |
| 8998 | } catch (RuntimeException e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8999 | Slog.w(TAG, "Error positioning surface in " + w, e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9000 | if (!recoveringMemory) { |
| 9001 | reclaimSomeSurfaceMemoryLocked(w, "position"); |
| 9002 | } |
| 9003 | } |
| 9004 | } else { |
| 9005 | resize = !w.mLastShownFrame.equals(w.mShownFrame); |
| 9006 | width = w.mShownFrame.width(); |
| 9007 | height = w.mShownFrame.height(); |
| 9008 | w.mLastShownFrame.set(w.mShownFrame); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9009 | } |
| 9010 | |
| 9011 | if (resize) { |
| 9012 | if (width < 1) width = 1; |
| 9013 | if (height < 1) height = 1; |
| 9014 | if (w.mSurface != null) { |
| 9015 | try { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9016 | if (SHOW_TRANSACTIONS) logSurface(w, |
| 9017 | "POS " + w.mShownFrame.left + "," |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 9018 | + w.mShownFrame.top + " SIZE " |
| 9019 | + w.mShownFrame.width() + "x" |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9020 | + w.mShownFrame.height(), null); |
| Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 9021 | w.mSurfaceResized = true; |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 9022 | w.mSurfaceW = width; |
| 9023 | w.mSurfaceH = height; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9024 | w.mSurface.setSize(width, height); |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 9025 | w.mSurfaceX = w.mShownFrame.left; |
| 9026 | w.mSurfaceY = w.mShownFrame.top; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9027 | w.mSurface.setPosition(w.mShownFrame.left, |
| 9028 | w.mShownFrame.top); |
| 9029 | } catch (RuntimeException e) { |
| 9030 | // If something goes wrong with the surface (such |
| 9031 | // as running out of memory), don't take down the |
| 9032 | // entire system. |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9033 | Slog.e(TAG, "Failure updating surface of " + w |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9034 | + "size=(" + width + "x" + height |
| 9035 | + "), pos=(" + w.mShownFrame.left |
| 9036 | + "," + w.mShownFrame.top + ")", e); |
| 9037 | if (!recoveringMemory) { |
| 9038 | reclaimSomeSurfaceMemoryLocked(w, "size"); |
| 9039 | } |
| 9040 | } |
| 9041 | } |
| 9042 | } |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 9043 | if (!w.mAppFreezing && w.mLayoutSeq == mLayoutSeq) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9044 | w.mContentInsetsChanged = |
| 9045 | !w.mLastContentInsets.equals(w.mContentInsets); |
| 9046 | w.mVisibleInsetsChanged = |
| 9047 | !w.mLastVisibleInsets.equals(w.mVisibleInsets); |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 9048 | boolean configChanged = |
| 9049 | w.mConfiguration != mCurConfiguration |
| 9050 | && (w.mConfiguration == null |
| 9051 | || mCurConfiguration.diff(w.mConfiguration) != 0); |
| Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 9052 | if (DEBUG_CONFIGURATION && configChanged) { |
| 9053 | Slog.v(TAG, "Win " + w + " config changed: " |
| 9054 | + mCurConfiguration); |
| 9055 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9056 | if (localLOGV) Slog.v(TAG, "Resizing " + w |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 9057 | + ": configChanged=" + configChanged |
| 9058 | + " last=" + w.mLastFrame + " frame=" + w.mFrame); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9059 | if (!w.mLastFrame.equals(w.mFrame) |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9060 | || w.mContentInsetsChanged |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 9061 | || w.mVisibleInsetsChanged |
| Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 9062 | || w.mSurfaceResized |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 9063 | || configChanged) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9064 | w.mLastFrame.set(w.mFrame); |
| 9065 | w.mLastContentInsets.set(w.mContentInsets); |
| 9066 | w.mLastVisibleInsets.set(w.mVisibleInsets); |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 9067 | // If the screen is currently frozen, then keep |
| 9068 | // it frozen until this window draws at its new |
| 9069 | // orientation. |
| 9070 | if (mDisplayFrozen) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9071 | if (DEBUG_ORIENTATION) Slog.v(TAG, |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 9072 | "Resizing while display frozen: " + w); |
| 9073 | w.mOrientationChanging = true; |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 9074 | if (!mWindowsFreezingScreen) { |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 9075 | mWindowsFreezingScreen = true; |
| 9076 | // XXX should probably keep timeout from |
| 9077 | // when we first froze the display. |
| 9078 | mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT); |
| 9079 | mH.sendMessageDelayed(mH.obtainMessage( |
| 9080 | H.WINDOW_FREEZE_TIMEOUT), 2000); |
| 9081 | } |
| 9082 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9083 | // If the orientation is changing, then we need to |
| 9084 | // hold off on unfreezing the display until this |
| 9085 | // window has been redrawn; to do that, we need |
| 9086 | // to go through the process of getting informed |
| 9087 | // by the application when it has finished drawing. |
| 9088 | if (w.mOrientationChanging) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9089 | if (DEBUG_ORIENTATION) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9090 | "Orientation start waiting for draw in " |
| 9091 | + w + ", surface " + w.mSurface); |
| 9092 | w.mDrawPending = true; |
| 9093 | w.mCommitDrawPending = false; |
| 9094 | w.mReadyToShow = false; |
| 9095 | if (w.mAppToken != null) { |
| 9096 | w.mAppToken.allDrawn = false; |
| 9097 | } |
| 9098 | } |
| Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 9099 | if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9100 | "Resizing window " + w + " to " + w.mFrame); |
| 9101 | mResizingWindows.add(w); |
| 9102 | } else if (w.mOrientationChanging) { |
| 9103 | if (!w.mDrawPending && !w.mCommitDrawPending) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9104 | if (DEBUG_ORIENTATION) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9105 | "Orientation not waiting for draw in " |
| 9106 | + w + ", surface " + w.mSurface); |
| 9107 | w.mOrientationChanging = false; |
| 9108 | } |
| 9109 | } |
| 9110 | } |
| 9111 | |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9112 | if (w.mAttachedHidden || !w.isReadyForDisplay()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9113 | if (!w.mLastHidden) { |
| 9114 | //dump(); |
| Dianne Hackborn | 5943c20 | 2010-04-12 21:36:49 -0700 | [diff] [blame] | 9115 | if (DEBUG_CONFIGURATION) Slog.v(TAG, "Window hiding: waitingToShow=" |
| 9116 | + w.mRootToken.waitingToShow + " polvis=" |
| 9117 | + w.mPolicyVisibility + " atthid=" |
| 9118 | + w.mAttachedHidden + " tokhid=" |
| 9119 | + w.mRootToken.hidden + " vis=" |
| 9120 | + w.mViewVisibility); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9121 | w.mLastHidden = true; |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9122 | if (SHOW_TRANSACTIONS) logSurface(w, |
| 9123 | "HIDE (performLayout)", null); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9124 | if (w.mSurface != null) { |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 9125 | w.mSurfaceShown = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9126 | try { |
| 9127 | w.mSurface.hide(); |
| 9128 | } catch (RuntimeException e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9129 | Slog.w(TAG, "Exception hiding surface in " + w); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9130 | } |
| 9131 | } |
| Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 9132 | mInputMonitor.windowIsBecomingInvisibleLw(w); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9133 | } |
| 9134 | // If we are waiting for this window to handle an |
| 9135 | // orientation change, well, it is hidden, so |
| 9136 | // doesn't really matter. Note that this does |
| 9137 | // introduce a potential glitch if the window |
| 9138 | // becomes unhidden before it has drawn for the |
| 9139 | // new orientation. |
| 9140 | if (w.mOrientationChanging) { |
| 9141 | w.mOrientationChanging = false; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9142 | if (DEBUG_ORIENTATION) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9143 | "Orientation change skips hidden " + w); |
| 9144 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9145 | } else if (w.mLastLayer != w.mAnimLayer |
| 9146 | || w.mLastAlpha != w.mShownAlpha |
| 9147 | || w.mLastDsDx != w.mDsDx |
| 9148 | || w.mLastDtDx != w.mDtDx |
| 9149 | || w.mLastDsDy != w.mDsDy |
| 9150 | || w.mLastDtDy != w.mDtDy |
| 9151 | || w.mLastHScale != w.mHScale |
| 9152 | || w.mLastVScale != w.mVScale |
| 9153 | || w.mLastHidden) { |
| 9154 | displayed = true; |
| 9155 | w.mLastAlpha = w.mShownAlpha; |
| 9156 | w.mLastLayer = w.mAnimLayer; |
| 9157 | w.mLastDsDx = w.mDsDx; |
| 9158 | w.mLastDtDx = w.mDtDx; |
| 9159 | w.mLastDsDy = w.mDsDy; |
| 9160 | w.mLastDtDy = w.mDtDy; |
| 9161 | w.mLastHScale = w.mHScale; |
| 9162 | w.mLastVScale = w.mVScale; |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9163 | if (SHOW_TRANSACTIONS) logSurface(w, |
| 9164 | "alpha=" + w.mShownAlpha + " layer=" + w.mAnimLayer |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 9165 | + " matrix=[" + (w.mDsDx*w.mHScale) |
| 9166 | + "," + (w.mDtDx*w.mVScale) |
| 9167 | + "][" + (w.mDsDy*w.mHScale) |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9168 | + "," + (w.mDtDy*w.mVScale) + "]", null); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9169 | if (w.mSurface != null) { |
| 9170 | try { |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 9171 | w.mSurfaceAlpha = w.mShownAlpha; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9172 | w.mSurface.setAlpha(w.mShownAlpha); |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 9173 | w.mSurfaceLayer = w.mAnimLayer; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9174 | w.mSurface.setLayer(w.mAnimLayer); |
| 9175 | w.mSurface.setMatrix( |
| 9176 | w.mDsDx*w.mHScale, w.mDtDx*w.mVScale, |
| 9177 | w.mDsDy*w.mHScale, w.mDtDy*w.mVScale); |
| 9178 | } catch (RuntimeException e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9179 | Slog.w(TAG, "Error updating surface in " + w, e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9180 | if (!recoveringMemory) { |
| 9181 | reclaimSomeSurfaceMemoryLocked(w, "update"); |
| 9182 | } |
| 9183 | } |
| 9184 | } |
| 9185 | |
| 9186 | if (w.mLastHidden && !w.mDrawPending |
| 9187 | && !w.mCommitDrawPending |
| 9188 | && !w.mReadyToShow) { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9189 | if (SHOW_TRANSACTIONS) logSurface(w, |
| 9190 | "SHOW (performLayout)", null); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9191 | if (DEBUG_VISIBILITY) Slog.v(TAG, "Showing " + w |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9192 | + " during relayout"); |
| 9193 | if (showSurfaceRobustlyLocked(w)) { |
| 9194 | w.mHasDrawn = true; |
| 9195 | w.mLastHidden = false; |
| 9196 | } else { |
| 9197 | w.mOrientationChanging = false; |
| 9198 | } |
| 9199 | } |
| 9200 | if (w.mSurface != null) { |
| 9201 | w.mToken.hasVisible = true; |
| 9202 | } |
| 9203 | } else { |
| 9204 | displayed = true; |
| 9205 | } |
| 9206 | |
| 9207 | if (displayed) { |
| 9208 | if (!covered) { |
| Romain Guy | 980a938 | 2010-01-08 15:06:28 -0800 | [diff] [blame] | 9209 | if (attrs.width == LayoutParams.MATCH_PARENT |
| 9210 | && attrs.height == LayoutParams.MATCH_PARENT) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9211 | covered = true; |
| 9212 | } |
| 9213 | } |
| 9214 | if (w.mOrientationChanging) { |
| 9215 | if (w.mDrawPending || w.mCommitDrawPending) { |
| 9216 | orientationChangeComplete = false; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9217 | if (DEBUG_ORIENTATION) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9218 | "Orientation continue waiting for draw in " + w); |
| 9219 | } else { |
| 9220 | w.mOrientationChanging = false; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9221 | if (DEBUG_ORIENTATION) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9222 | "Orientation change complete in " + w); |
| 9223 | } |
| 9224 | } |
| 9225 | w.mToken.hasVisible = true; |
| 9226 | } |
| 9227 | } else if (w.mOrientationChanging) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9228 | if (DEBUG_ORIENTATION) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9229 | "Orientation change skips hidden " + w); |
| 9230 | w.mOrientationChanging = false; |
| 9231 | } |
| 9232 | |
| 9233 | final boolean canBeSeen = w.isDisplayedLw(); |
| 9234 | |
| 9235 | if (someoneLosingFocus && w == mCurrentFocus && canBeSeen) { |
| 9236 | focusDisplayed = true; |
| 9237 | } |
| 9238 | |
| Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 9239 | final boolean obscuredChanged = w.mObscured != obscured; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9240 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9241 | // Update effect. |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 9242 | if (!(w.mObscured=obscured)) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9243 | if (w.mSurface != null) { |
| 9244 | if ((attrFlags&FLAG_KEEP_SCREEN_ON) != 0) { |
| 9245 | holdScreen = w.mSession; |
| 9246 | } |
| Dianne Hackborn | 9ed4a4b | 2009-03-25 17:10:37 -0700 | [diff] [blame] | 9247 | if (!syswin && w.mAttrs.screenBrightness >= 0 |
| 9248 | && screenBrightness < 0) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9249 | screenBrightness = w.mAttrs.screenBrightness; |
| 9250 | } |
| Mike Lockwood | fb73f79 | 2009-11-20 11:31:18 -0500 | [diff] [blame] | 9251 | if (!syswin && w.mAttrs.buttonBrightness >= 0 |
| 9252 | && buttonBrightness < 0) { |
| 9253 | buttonBrightness = w.mAttrs.buttonBrightness; |
| 9254 | } |
| Mike Lockwood | 46af6a8 | 2010-03-09 08:28:22 -0500 | [diff] [blame] | 9255 | if (canBeSeen |
| 9256 | && (attrs.type == WindowManager.LayoutParams.TYPE_SYSTEM_DIALOG |
| 9257 | || attrs.type == WindowManager.LayoutParams.TYPE_KEYGUARD |
| 9258 | || attrs.type == WindowManager.LayoutParams.TYPE_SYSTEM_ERROR)) { |
| Dianne Hackborn | 9ed4a4b | 2009-03-25 17:10:37 -0700 | [diff] [blame] | 9259 | syswin = true; |
| 9260 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9261 | } |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 9262 | |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 9263 | boolean opaqueDrawn = canBeSeen && w.isOpaqueDrawn(); |
| 9264 | if (opaqueDrawn && w.isFullscreen(dw, dh)) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9265 | // This window completely covers everything behind it, |
| 9266 | // so we want to leave all of them as unblurred (for |
| 9267 | // performance reasons). |
| 9268 | obscured = true; |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 9269 | } else if (opaqueDrawn && w.needsBackgroundFiller(dw, dh)) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9270 | if (SHOW_TRANSACTIONS) Slog.d(TAG, "showing background filler"); |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 9271 | // This window is in compatibility mode, and needs background filler. |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 9272 | obscured = true; |
| 9273 | if (mBackgroundFillerSurface == null) { |
| 9274 | try { |
| 9275 | mBackgroundFillerSurface = new Surface(mFxSession, 0, |
| Mathias Agopian | 5d26c1e | 2010-03-01 16:09:43 -0800 | [diff] [blame] | 9276 | "BackGroundFiller", |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 9277 | 0, dw, dh, |
| 9278 | PixelFormat.OPAQUE, |
| 9279 | Surface.FX_SURFACE_NORMAL); |
| 9280 | } catch (Exception e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9281 | Slog.e(TAG, "Exception creating filler surface", e); |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 9282 | } |
| 9283 | } |
| 9284 | try { |
| 9285 | mBackgroundFillerSurface.setPosition(0, 0); |
| 9286 | mBackgroundFillerSurface.setSize(dw, dh); |
| 9287 | // Using the same layer as Dim because they will never be shown at the |
| 9288 | // same time. |
| 9289 | mBackgroundFillerSurface.setLayer(w.mAnimLayer - 1); |
| 9290 | mBackgroundFillerSurface.show(); |
| 9291 | } catch (RuntimeException e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9292 | Slog.e(TAG, "Exception showing filler surface"); |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 9293 | } |
| 9294 | backgroundFillerShown = true; |
| 9295 | mBackgroundFillerShown = true; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9296 | } else if (canBeSeen && !obscured && |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9297 | (attrFlags&FLAG_BLUR_BEHIND|FLAG_DIM_BEHIND) != 0) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9298 | if (localLOGV) Slog.v(TAG, "Win " + w |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9299 | + ": blurring=" + blurring |
| 9300 | + " obscured=" + obscured |
| 9301 | + " displayed=" + displayed); |
| 9302 | if ((attrFlags&FLAG_DIM_BEHIND) != 0) { |
| 9303 | if (!dimming) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9304 | //Slog.i(TAG, "DIM BEHIND: " + w); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9305 | dimming = true; |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 9306 | if (mDimAnimator == null) { |
| 9307 | mDimAnimator = new DimAnimator(mFxSession); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9308 | } |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 9309 | mDimAnimator.show(dw, dh); |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 9310 | mDimAnimator.updateParameters(w, currentTime); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9311 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9312 | } |
| 9313 | if ((attrFlags&FLAG_BLUR_BEHIND) != 0) { |
| 9314 | if (!blurring) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9315 | //Slog.i(TAG, "BLUR BEHIND: " + w); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9316 | blurring = true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9317 | if (mBlurSurface == null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9318 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR " |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9319 | + mBlurSurface + ": CREATE"); |
| 9320 | try { |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9321 | mBlurSurface = new Surface(mFxSession, 0, |
| Mathias Agopian | 5d26c1e | 2010-03-01 16:09:43 -0800 | [diff] [blame] | 9322 | "BlurSurface", |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9323 | -1, 16, 16, |
| 9324 | PixelFormat.OPAQUE, |
| 9325 | Surface.FX_SURFACE_BLUR); |
| 9326 | } catch (Exception e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9327 | Slog.e(TAG, "Exception creating Blur surface", e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9328 | } |
| 9329 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9330 | if (mBlurSurface != null) { |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 9331 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR " |
| 9332 | + mBlurSurface + ": pos=(0,0) (" + |
| 9333 | dw + "x" + dh + "), layer=" + (w.mAnimLayer-1)); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9334 | mBlurSurface.setPosition(0, 0); |
| 9335 | mBlurSurface.setSize(dw, dh); |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 9336 | mBlurSurface.setLayer(w.mAnimLayer-2); |
| 9337 | if (!mBlurShown) { |
| 9338 | try { |
| 9339 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR " |
| 9340 | + mBlurSurface + ": SHOW"); |
| 9341 | mBlurSurface.show(); |
| 9342 | } catch (RuntimeException e) { |
| 9343 | Slog.w(TAG, "Failure showing blur surface", e); |
| 9344 | } |
| 9345 | mBlurShown = true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9346 | } |
| 9347 | } |
| 9348 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9349 | } |
| 9350 | } |
| 9351 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9352 | |
| Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 9353 | if (obscuredChanged && mWallpaperTarget == w) { |
| 9354 | // This is the wallpaper target and its obscured state |
| 9355 | // changed... make sure the current wallaper's visibility |
| 9356 | // has been updated accordingly. |
| 9357 | updateWallpaperVisibilityLocked(); |
| 9358 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9359 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9360 | |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 9361 | if (backgroundFillerShown == false && mBackgroundFillerShown) { |
| 9362 | mBackgroundFillerShown = false; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9363 | if (SHOW_TRANSACTIONS) Slog.d(TAG, "hiding background filler"); |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 9364 | try { |
| 9365 | mBackgroundFillerSurface.hide(); |
| 9366 | } catch (RuntimeException e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9367 | Slog.e(TAG, "Exception hiding filler surface", e); |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 9368 | } |
| 9369 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9370 | |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 9371 | if (mDimAnimator != null && mDimAnimator.mDimShown) { |
| Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 9372 | animating |= mDimAnimator.updateSurface(dimming, currentTime, |
| 9373 | mDisplayFrozen || !mPolicy.isScreenOn()); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9374 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9375 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9376 | if (!blurring && mBlurShown) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9377 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR " + mBlurSurface |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9378 | + ": HIDE"); |
| 9379 | try { |
| 9380 | mBlurSurface.hide(); |
| 9381 | } catch (IllegalArgumentException e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9382 | Slog.w(TAG, "Illegal argument exception hiding blur surface"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9383 | } |
| 9384 | mBlurShown = false; |
| 9385 | } |
| 9386 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9387 | if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9388 | } catch (RuntimeException e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9389 | Slog.e(TAG, "Unhandled exception in Window Manager", e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9390 | } |
| 9391 | |
| 9392 | Surface.closeTransaction(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9393 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9394 | if (DEBUG_ORIENTATION && mDisplayFrozen) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9395 | "With display frozen, orientationChangeComplete=" |
| 9396 | + orientationChangeComplete); |
| 9397 | if (orientationChangeComplete) { |
| 9398 | if (mWindowsFreezingScreen) { |
| 9399 | mWindowsFreezingScreen = false; |
| 9400 | mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT); |
| 9401 | } |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 9402 | stopFreezingDisplayLocked(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9403 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9404 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9405 | i = mResizingWindows.size(); |
| 9406 | if (i > 0) { |
| 9407 | do { |
| 9408 | i--; |
| 9409 | WindowState win = mResizingWindows.get(i); |
| 9410 | try { |
| Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 9411 | if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG, |
| 9412 | "Reporting new frame to " + win + ": " + win.mFrame); |
| Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 9413 | int diff = 0; |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 9414 | boolean configChanged = |
| 9415 | win.mConfiguration != mCurConfiguration |
| 9416 | && (win.mConfiguration == null |
| Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 9417 | || (diff=mCurConfiguration.diff(win.mConfiguration)) != 0); |
| 9418 | if ((DEBUG_RESIZE || DEBUG_ORIENTATION || DEBUG_CONFIGURATION) |
| 9419 | && configChanged) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9420 | Slog.i(TAG, "Sending new config to window " + win + ": " |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 9421 | + win.mFrame.width() + "x" + win.mFrame.height() |
| Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 9422 | + " / " + mCurConfiguration + " / 0x" |
| 9423 | + Integer.toHexString(diff)); |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 9424 | } |
| Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 9425 | win.mConfiguration = mCurConfiguration; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9426 | win.mClient.resized(win.mFrame.width(), |
| 9427 | win.mFrame.height(), win.mLastContentInsets, |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 9428 | win.mLastVisibleInsets, win.mDrawPending, |
| 9429 | configChanged ? win.mConfiguration : null); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9430 | win.mContentInsetsChanged = false; |
| 9431 | win.mVisibleInsetsChanged = false; |
| Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 9432 | win.mSurfaceResized = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9433 | } catch (RemoteException e) { |
| 9434 | win.mOrientationChanging = false; |
| 9435 | } |
| 9436 | } while (i > 0); |
| 9437 | mResizingWindows.clear(); |
| 9438 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9439 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9440 | // Destroy the surface of any windows that are no longer visible. |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 9441 | boolean wallpaperDestroyed = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9442 | i = mDestroySurface.size(); |
| 9443 | if (i > 0) { |
| 9444 | do { |
| 9445 | i--; |
| 9446 | WindowState win = mDestroySurface.get(i); |
| 9447 | win.mDestroying = false; |
| 9448 | if (mInputMethodWindow == win) { |
| 9449 | mInputMethodWindow = null; |
| 9450 | } |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 9451 | if (win == mWallpaperTarget) { |
| 9452 | wallpaperDestroyed = true; |
| 9453 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9454 | win.destroySurfaceLocked(); |
| 9455 | } while (i > 0); |
| 9456 | mDestroySurface.clear(); |
| 9457 | } |
| 9458 | |
| 9459 | // Time to remove any exiting tokens? |
| 9460 | for (i=mExitingTokens.size()-1; i>=0; i--) { |
| 9461 | WindowToken token = mExitingTokens.get(i); |
| 9462 | if (!token.hasVisible) { |
| 9463 | mExitingTokens.remove(i); |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 9464 | if (token.windowType == TYPE_WALLPAPER) { |
| 9465 | mWallpaperTokens.remove(token); |
| 9466 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9467 | } |
| 9468 | } |
| 9469 | |
| 9470 | // Time to remove any exiting applications? |
| 9471 | for (i=mExitingAppTokens.size()-1; i>=0; i--) { |
| 9472 | AppWindowToken token = mExitingAppTokens.get(i); |
| 9473 | if (!token.hasVisible && !mClosingApps.contains(token)) { |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 9474 | // Make sure there is no animation running on this token, |
| 9475 | // so any windows associated with it will be removed as |
| 9476 | // soon as their animations are complete |
| 9477 | token.animation = null; |
| 9478 | token.animating = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9479 | mAppTokens.remove(token); |
| 9480 | mExitingAppTokens.remove(i); |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9481 | if (mLastEnterAnimToken == token) { |
| 9482 | mLastEnterAnimToken = null; |
| 9483 | mLastEnterAnimParams = null; |
| 9484 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9485 | } |
| 9486 | } |
| 9487 | |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9488 | boolean needRelayout = false; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9489 | |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9490 | if (!animating && mAppTransitionRunning) { |
| 9491 | // We have finished the animation of an app transition. To do |
| 9492 | // this, we have delayed a lot of operations like showing and |
| 9493 | // hiding apps, moving apps in Z-order, etc. The app token list |
| 9494 | // reflects the correct Z-order, but the window list may now |
| 9495 | // be out of sync with it. So here we will just rebuild the |
| 9496 | // entire app window list. Fun! |
| 9497 | mAppTransitionRunning = false; |
| 9498 | needRelayout = true; |
| 9499 | rebuildAppWindowListLocked(); |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 9500 | assignLayersLocked(); |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9501 | // Clear information about apps that were moving. |
| 9502 | mToBottomApps.clear(); |
| 9503 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9504 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9505 | if (focusDisplayed) { |
| 9506 | mH.sendEmptyMessage(H.REPORT_LOSING_FOCUS); |
| 9507 | } |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 9508 | if (wallpaperDestroyed) { |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 9509 | needRelayout = adjustWallpaperWindowsLocked() != 0; |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 9510 | } |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9511 | if (needRelayout) { |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 9512 | requestAnimationLocked(0); |
| 9513 | } else if (animating) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9514 | requestAnimationLocked(currentTime+(1000/60)-SystemClock.uptimeMillis()); |
| 9515 | } |
| Dianne Hackborn | ce73c1e | 2010-04-12 23:11:38 -0700 | [diff] [blame] | 9516 | |
| 9517 | if (DEBUG_FREEZE) Slog.v(TAG, "Layout: mDisplayFrozen=" + mDisplayFrozen |
| 9518 | + " holdScreen=" + holdScreen); |
| 9519 | if (!mDisplayFrozen) { |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 9520 | setHoldScreenLocked(holdScreen != null); |
| Dianne Hackborn | ce73c1e | 2010-04-12 23:11:38 -0700 | [diff] [blame] | 9521 | if (screenBrightness < 0 || screenBrightness > 1.0f) { |
| 9522 | mPowerManager.setScreenBrightnessOverride(-1); |
| 9523 | } else { |
| 9524 | mPowerManager.setScreenBrightnessOverride((int) |
| 9525 | (screenBrightness * Power.BRIGHTNESS_ON)); |
| 9526 | } |
| 9527 | if (buttonBrightness < 0 || buttonBrightness > 1.0f) { |
| 9528 | mPowerManager.setButtonBrightnessOverride(-1); |
| 9529 | } else { |
| 9530 | mPowerManager.setButtonBrightnessOverride((int) |
| 9531 | (buttonBrightness * Power.BRIGHTNESS_ON)); |
| 9532 | } |
| 9533 | if (holdScreen != mHoldingScreenOn) { |
| 9534 | mHoldingScreenOn = holdScreen; |
| 9535 | Message m = mH.obtainMessage(H.HOLD_SCREEN_CHANGED, holdScreen); |
| 9536 | mH.sendMessage(m); |
| 9537 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9538 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9539 | |
| Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 9540 | if (mTurnOnScreen) { |
| Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 9541 | if (DEBUG_VISIBILITY) Slog.v(TAG, "Turning screen on after layout!"); |
| Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 9542 | mPowerManager.userActivity(SystemClock.uptimeMillis(), false, |
| 9543 | LocalPowerManager.BUTTON_EVENT, true); |
| 9544 | mTurnOnScreen = false; |
| 9545 | } |
| Dianne Hackborn | f3bea9c | 2009-12-09 18:26:21 -0800 | [diff] [blame] | 9546 | |
| 9547 | // Check to see if we are now in a state where the screen should |
| 9548 | // be enabled, because the window obscured flags have changed. |
| 9549 | enableScreenIfNeededLocked(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9550 | } |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 9551 | |
| 9552 | /** |
| 9553 | * Must be called with the main window manager lock held. |
| 9554 | */ |
| 9555 | void setHoldScreenLocked(boolean holding) { |
| 9556 | boolean state = mHoldingScreenWakeLock.isHeld(); |
| 9557 | if (holding != state) { |
| 9558 | if (holding) { |
| 9559 | mHoldingScreenWakeLock.acquire(); |
| 9560 | } else { |
| 9561 | mPolicy.screenOnStoppedLw(); |
| 9562 | mHoldingScreenWakeLock.release(); |
| 9563 | } |
| 9564 | } |
| 9565 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9566 | |
| 9567 | void requestAnimationLocked(long delay) { |
| 9568 | if (!mAnimationPending) { |
| 9569 | mAnimationPending = true; |
| 9570 | mH.sendMessageDelayed(mH.obtainMessage(H.ANIMATE), delay); |
| 9571 | } |
| 9572 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9573 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9574 | /** |
| 9575 | * Have the surface flinger show a surface, robustly dealing with |
| 9576 | * error conditions. In particular, if there is not enough memory |
| 9577 | * to show the surface, then we will try to get rid of other surfaces |
| 9578 | * in order to succeed. |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9579 | * |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9580 | * @return Returns true if the surface was successfully shown. |
| 9581 | */ |
| 9582 | boolean showSurfaceRobustlyLocked(WindowState win) { |
| 9583 | try { |
| 9584 | if (win.mSurface != null) { |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 9585 | win.mSurfaceShown = true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9586 | win.mSurface.show(); |
| Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 9587 | if (win.mTurnOnScreen) { |
| Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 9588 | if (DEBUG_VISIBILITY) Slog.v(TAG, |
| 9589 | "Show surface turning screen on: " + win); |
| Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 9590 | win.mTurnOnScreen = false; |
| 9591 | mTurnOnScreen = true; |
| 9592 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9593 | } |
| 9594 | return true; |
| 9595 | } catch (RuntimeException e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9596 | Slog.w(TAG, "Failure showing surface " + win.mSurface + " in " + win); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9597 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9598 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9599 | reclaimSomeSurfaceMemoryLocked(win, "show"); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9600 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9601 | return false; |
| 9602 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9603 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9604 | void reclaimSomeSurfaceMemoryLocked(WindowState win, String operation) { |
| 9605 | final Surface surface = win.mSurface; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9606 | |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9607 | EventLog.writeEvent(EventLogTags.WM_NO_SURFACE_MEMORY, win.toString(), |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9608 | win.mSession.mPid, operation); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9609 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9610 | if (mForceRemoves == null) { |
| 9611 | mForceRemoves = new ArrayList<WindowState>(); |
| 9612 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9613 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9614 | long callingIdentity = Binder.clearCallingIdentity(); |
| 9615 | try { |
| 9616 | // There was some problem... first, do a sanity check of the |
| 9617 | // window list to make sure we haven't left any dangling surfaces |
| 9618 | // around. |
| 9619 | int N = mWindows.size(); |
| 9620 | boolean leakedSurface = false; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9621 | Slog.i(TAG, "Out of memory for surface! Looking for leaks..."); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9622 | for (int i=0; i<N; i++) { |
| 9623 | WindowState ws = (WindowState)mWindows.get(i); |
| 9624 | if (ws.mSurface != null) { |
| 9625 | if (!mSessions.contains(ws.mSession)) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9626 | Slog.w(TAG, "LEAKED SURFACE (session doesn't exist): " |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9627 | + ws + " surface=" + ws.mSurface |
| 9628 | + " token=" + win.mToken |
| 9629 | + " pid=" + ws.mSession.mPid |
| 9630 | + " uid=" + ws.mSession.mUid); |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 9631 | ws.mSurface.destroy(); |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 9632 | ws.mSurfaceShown = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9633 | ws.mSurface = null; |
| 9634 | mForceRemoves.add(ws); |
| 9635 | i--; |
| 9636 | N--; |
| 9637 | leakedSurface = true; |
| 9638 | } else if (win.mAppToken != null && win.mAppToken.clientHidden) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9639 | Slog.w(TAG, "LEAKED SURFACE (app token hidden): " |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9640 | + ws + " surface=" + ws.mSurface |
| 9641 | + " token=" + win.mAppToken); |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 9642 | ws.mSurface.destroy(); |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 9643 | ws.mSurfaceShown = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9644 | ws.mSurface = null; |
| 9645 | leakedSurface = true; |
| 9646 | } |
| 9647 | } |
| 9648 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9649 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9650 | boolean killedApps = false; |
| 9651 | if (!leakedSurface) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9652 | Slog.w(TAG, "No leaked surfaces; killing applicatons!"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9653 | SparseIntArray pidCandidates = new SparseIntArray(); |
| 9654 | for (int i=0; i<N; i++) { |
| 9655 | WindowState ws = (WindowState)mWindows.get(i); |
| 9656 | if (ws.mSurface != null) { |
| 9657 | pidCandidates.append(ws.mSession.mPid, ws.mSession.mPid); |
| 9658 | } |
| 9659 | } |
| 9660 | if (pidCandidates.size() > 0) { |
| 9661 | int[] pids = new int[pidCandidates.size()]; |
| 9662 | for (int i=0; i<pids.length; i++) { |
| 9663 | pids[i] = pidCandidates.keyAt(i); |
| 9664 | } |
| 9665 | try { |
| Suchi Amalapurapu | e99bb5f | 2010-03-19 14:36:49 -0700 | [diff] [blame] | 9666 | if (mActivityManager.killPids(pids, "Free memory")) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9667 | killedApps = true; |
| 9668 | } |
| 9669 | } catch (RemoteException e) { |
| 9670 | } |
| 9671 | } |
| 9672 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9673 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9674 | if (leakedSurface || killedApps) { |
| 9675 | // We managed to reclaim some memory, so get rid of the trouble |
| 9676 | // surface and ask the app to request another one. |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9677 | Slog.w(TAG, "Looks like we have reclaimed some memory, clearing surface for retry."); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9678 | if (surface != null) { |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 9679 | surface.destroy(); |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 9680 | win.mSurfaceShown = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9681 | win.mSurface = null; |
| 9682 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9683 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9684 | try { |
| 9685 | win.mClient.dispatchGetNewSurface(); |
| 9686 | } catch (RemoteException e) { |
| 9687 | } |
| 9688 | } |
| 9689 | } finally { |
| 9690 | Binder.restoreCallingIdentity(callingIdentity); |
| 9691 | } |
| 9692 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9693 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9694 | private boolean updateFocusedWindowLocked(int mode) { |
| 9695 | WindowState newFocus = computeFocusedWindowLocked(); |
| 9696 | if (mCurrentFocus != newFocus) { |
| 9697 | // This check makes sure that we don't already have the focus |
| 9698 | // change message pending. |
| 9699 | mH.removeMessages(H.REPORT_FOCUS_CHANGE); |
| 9700 | mH.sendEmptyMessage(H.REPORT_FOCUS_CHANGE); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9701 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9702 | TAG, "Changing focus from " + mCurrentFocus + " to " + newFocus); |
| 9703 | final WindowState oldFocus = mCurrentFocus; |
| 9704 | mCurrentFocus = newFocus; |
| 9705 | mLosingFocus.remove(newFocus); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9706 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9707 | final WindowState imWindow = mInputMethodWindow; |
| 9708 | if (newFocus != imWindow && oldFocus != imWindow) { |
| The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 9709 | if (moveInputMethodWindowsIfNeededLocked( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9710 | mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS && |
| The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 9711 | mode != UPDATE_FOCUS_WILL_PLACE_SURFACES)) { |
| 9712 | mLayoutNeeded = true; |
| 9713 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9714 | if (mode == UPDATE_FOCUS_PLACING_SURFACES) { |
| 9715 | performLayoutLockedInner(); |
| The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 9716 | } else if (mode == UPDATE_FOCUS_WILL_PLACE_SURFACES) { |
| 9717 | // Client will do the layout, but we need to assign layers |
| 9718 | // for handleNewWindowLocked() below. |
| 9719 | assignLayersLocked(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9720 | } |
| 9721 | } |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 9722 | |
| 9723 | if (mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS) { |
| 9724 | // If we defer assigning layers, then the caller is responsible for |
| 9725 | // doing this part. |
| 9726 | finishUpdateFocusedWindowAfterAssignLayersLocked(); |
| The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 9727 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9728 | return true; |
| 9729 | } |
| 9730 | return false; |
| 9731 | } |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 9732 | |
| 9733 | private void finishUpdateFocusedWindowAfterAssignLayersLocked() { |
| Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 9734 | mInputMonitor.setInputFocusLw(mCurrentFocus); |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 9735 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9736 | |
| 9737 | private WindowState computeFocusedWindowLocked() { |
| 9738 | WindowState result = null; |
| 9739 | WindowState win; |
| 9740 | |
| 9741 | int i = mWindows.size() - 1; |
| 9742 | int nextAppIndex = mAppTokens.size()-1; |
| 9743 | WindowToken nextApp = nextAppIndex >= 0 |
| 9744 | ? mAppTokens.get(nextAppIndex) : null; |
| 9745 | |
| 9746 | while (i >= 0) { |
| 9747 | win = (WindowState)mWindows.get(i); |
| 9748 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9749 | if (localLOGV || DEBUG_FOCUS) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9750 | TAG, "Looking for focus: " + i |
| 9751 | + " = " + win |
| 9752 | + ", flags=" + win.mAttrs.flags |
| 9753 | + ", canReceive=" + win.canReceiveKeys()); |
| 9754 | |
| 9755 | AppWindowToken thisApp = win.mAppToken; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9756 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9757 | // If this window's application has been removed, just skip it. |
| 9758 | if (thisApp != null && thisApp.removed) { |
| 9759 | i--; |
| 9760 | continue; |
| 9761 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9762 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9763 | // If there is a focused app, don't allow focus to go to any |
| 9764 | // windows below it. If this is an application window, step |
| 9765 | // through the app tokens until we find its app. |
| 9766 | if (thisApp != null && nextApp != null && thisApp != nextApp |
| 9767 | && win.mAttrs.type != TYPE_APPLICATION_STARTING) { |
| 9768 | int origAppIndex = nextAppIndex; |
| 9769 | while (nextAppIndex > 0) { |
| 9770 | if (nextApp == mFocusedApp) { |
| 9771 | // Whoops, we are below the focused app... no focus |
| 9772 | // for you! |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9773 | if (localLOGV || DEBUG_FOCUS) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9774 | TAG, "Reached focused app: " + mFocusedApp); |
| 9775 | return null; |
| 9776 | } |
| 9777 | nextAppIndex--; |
| 9778 | nextApp = mAppTokens.get(nextAppIndex); |
| 9779 | if (nextApp == thisApp) { |
| 9780 | break; |
| 9781 | } |
| 9782 | } |
| 9783 | if (thisApp != nextApp) { |
| 9784 | // Uh oh, the app token doesn't exist! This shouldn't |
| 9785 | // happen, but if it does we can get totally hosed... |
| 9786 | // so restart at the original app. |
| 9787 | nextAppIndex = origAppIndex; |
| 9788 | nextApp = mAppTokens.get(nextAppIndex); |
| 9789 | } |
| 9790 | } |
| 9791 | |
| 9792 | // Dispatch to this window if it is wants key events. |
| 9793 | if (win.canReceiveKeys()) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9794 | if (DEBUG_FOCUS) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9795 | TAG, "Found focus @ " + i + " = " + win); |
| 9796 | result = win; |
| 9797 | break; |
| 9798 | } |
| 9799 | |
| 9800 | i--; |
| 9801 | } |
| 9802 | |
| 9803 | return result; |
| 9804 | } |
| 9805 | |
| 9806 | private void startFreezingDisplayLocked() { |
| 9807 | if (mDisplayFrozen) { |
| 9808 | return; |
| 9809 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9810 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9811 | mScreenFrozenLock.acquire(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9812 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9813 | long now = SystemClock.uptimeMillis(); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9814 | //Slog.i(TAG, "Freezing, gc pending: " + mFreezeGcPending + ", now " + now); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9815 | if (mFreezeGcPending != 0) { |
| 9816 | if (now > (mFreezeGcPending+1000)) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9817 | //Slog.i(TAG, "Gc! " + now + " > " + (mFreezeGcPending+1000)); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9818 | mH.removeMessages(H.FORCE_GC); |
| 9819 | Runtime.getRuntime().gc(); |
| 9820 | mFreezeGcPending = now; |
| 9821 | } |
| 9822 | } else { |
| 9823 | mFreezeGcPending = now; |
| 9824 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9825 | |
| Dianne Hackborn | ce73c1e | 2010-04-12 23:11:38 -0700 | [diff] [blame] | 9826 | if (DEBUG_FREEZE) Slog.v(TAG, "*** FREEZING DISPLAY", new RuntimeException()); |
| 9827 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9828 | mDisplayFrozen = true; |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 9829 | |
| Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 9830 | mInputMonitor.freezeInputDispatchingLw(); |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 9831 | |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 9832 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
| 9833 | mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9834 | mNextAppTransitionPackage = null; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9835 | mAppTransitionReady = true; |
| 9836 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9837 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9838 | if (PROFILE_ORIENTATION) { |
| 9839 | File file = new File("/data/system/frozen"); |
| 9840 | Debug.startMethodTracing(file.toString(), 8 * 1024 * 1024); |
| 9841 | } |
| 9842 | Surface.freezeDisplay(0); |
| 9843 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9844 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9845 | private void stopFreezingDisplayLocked() { |
| 9846 | if (!mDisplayFrozen) { |
| 9847 | return; |
| 9848 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9849 | |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 9850 | if (mWaitingForConfig || mAppsFreezingScreen > 0 || mWindowsFreezingScreen) { |
| 9851 | return; |
| 9852 | } |
| 9853 | |
| Dianne Hackborn | ce73c1e | 2010-04-12 23:11:38 -0700 | [diff] [blame] | 9854 | if (DEBUG_FREEZE) Slog.v(TAG, "*** UNFREEZING DISPLAY", new RuntimeException()); |
| 9855 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9856 | mDisplayFrozen = false; |
| 9857 | mH.removeMessages(H.APP_FREEZE_TIMEOUT); |
| 9858 | if (PROFILE_ORIENTATION) { |
| 9859 | Debug.stopMethodTracing(); |
| 9860 | } |
| 9861 | Surface.unfreezeDisplay(0); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9862 | |
| Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 9863 | mInputMonitor.thawInputDispatchingLw(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9864 | |
| Christopher Tate | b696aee | 2010-04-02 19:08:30 -0700 | [diff] [blame] | 9865 | // While the display is frozen we don't re-compute the orientation |
| 9866 | // to avoid inconsistent states. However, something interesting |
| 9867 | // could have actually changed during that time so re-evaluate it |
| 9868 | // now to catch that. |
| 9869 | if (updateOrientationFromAppTokensLocked()) { |
| 9870 | mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION); |
| 9871 | } |
| 9872 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9873 | // A little kludge: a lot could have happened while the |
| 9874 | // display was frozen, so now that we are coming back we |
| 9875 | // do a gc so that any remote references the system |
| 9876 | // processes holds on others can be released if they are |
| 9877 | // no longer needed. |
| 9878 | mH.removeMessages(H.FORCE_GC); |
| 9879 | mH.sendMessageDelayed(mH.obtainMessage(H.FORCE_GC), |
| 9880 | 2000); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9881 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9882 | mScreenFrozenLock.release(); |
| 9883 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9884 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9885 | @Override |
| 9886 | public void dump(FileDescriptor fd, PrintWriter pw, String[] args) { |
| 9887 | if (mContext.checkCallingOrSelfPermission("android.permission.DUMP") |
| 9888 | != PackageManager.PERMISSION_GRANTED) { |
| 9889 | pw.println("Permission Denial: can't dump WindowManager from from pid=" |
| 9890 | + Binder.getCallingPid() |
| 9891 | + ", uid=" + Binder.getCallingUid()); |
| 9892 | return; |
| 9893 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9894 | |
| Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 9895 | pw.println("Input Dispatcher State:"); |
| 9896 | mInputManager.dump(pw); |
| Dianne Hackborn | a2e9226 | 2010-03-02 17:19:29 -0800 | [diff] [blame] | 9897 | pw.println(" "); |
| 9898 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9899 | synchronized(mWindowMap) { |
| 9900 | pw.println("Current Window Manager state:"); |
| 9901 | for (int i=mWindows.size()-1; i>=0; i--) { |
| 9902 | WindowState w = (WindowState)mWindows.get(i); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 9903 | pw.print(" Window #"); pw.print(i); pw.print(' '); |
| 9904 | pw.print(w); pw.println(":"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9905 | w.dump(pw, " "); |
| 9906 | } |
| 9907 | if (mInputMethodDialogs.size() > 0) { |
| 9908 | pw.println(" "); |
| 9909 | pw.println(" Input method dialogs:"); |
| 9910 | for (int i=mInputMethodDialogs.size()-1; i>=0; i--) { |
| 9911 | WindowState w = mInputMethodDialogs.get(i); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 9912 | 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] | 9913 | } |
| 9914 | } |
| 9915 | if (mPendingRemove.size() > 0) { |
| 9916 | pw.println(" "); |
| 9917 | pw.println(" Remove pending for:"); |
| 9918 | for (int i=mPendingRemove.size()-1; i>=0; i--) { |
| 9919 | WindowState w = mPendingRemove.get(i); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 9920 | pw.print(" Remove #"); pw.print(i); pw.print(' '); |
| 9921 | pw.print(w); pw.println(":"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9922 | w.dump(pw, " "); |
| 9923 | } |
| 9924 | } |
| 9925 | if (mForceRemoves != null && mForceRemoves.size() > 0) { |
| 9926 | pw.println(" "); |
| 9927 | pw.println(" Windows force removing:"); |
| 9928 | for (int i=mForceRemoves.size()-1; i>=0; i--) { |
| 9929 | WindowState w = mForceRemoves.get(i); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 9930 | pw.print(" Removing #"); pw.print(i); pw.print(' '); |
| 9931 | pw.print(w); pw.println(":"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9932 | w.dump(pw, " "); |
| 9933 | } |
| 9934 | } |
| 9935 | if (mDestroySurface.size() > 0) { |
| 9936 | pw.println(" "); |
| 9937 | pw.println(" Windows waiting to destroy their surface:"); |
| 9938 | for (int i=mDestroySurface.size()-1; i>=0; i--) { |
| 9939 | WindowState w = mDestroySurface.get(i); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 9940 | pw.print(" Destroy #"); pw.print(i); pw.print(' '); |
| 9941 | pw.print(w); pw.println(":"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9942 | w.dump(pw, " "); |
| 9943 | } |
| 9944 | } |
| 9945 | if (mLosingFocus.size() > 0) { |
| 9946 | pw.println(" "); |
| 9947 | pw.println(" Windows losing focus:"); |
| 9948 | for (int i=mLosingFocus.size()-1; i>=0; i--) { |
| 9949 | WindowState w = mLosingFocus.get(i); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 9950 | pw.print(" Losing #"); pw.print(i); pw.print(' '); |
| 9951 | pw.print(w); pw.println(":"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9952 | w.dump(pw, " "); |
| 9953 | } |
| 9954 | } |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 9955 | if (mResizingWindows.size() > 0) { |
| 9956 | pw.println(" "); |
| 9957 | pw.println(" Windows waiting to resize:"); |
| 9958 | for (int i=mResizingWindows.size()-1; i>=0; i--) { |
| 9959 | WindowState w = mResizingWindows.get(i); |
| 9960 | pw.print(" Resizing #"); pw.print(i); pw.print(' '); |
| 9961 | pw.print(w); pw.println(":"); |
| 9962 | w.dump(pw, " "); |
| 9963 | } |
| 9964 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9965 | if (mSessions.size() > 0) { |
| 9966 | pw.println(" "); |
| 9967 | pw.println(" All active sessions:"); |
| 9968 | Iterator<Session> it = mSessions.iterator(); |
| 9969 | while (it.hasNext()) { |
| 9970 | Session s = it.next(); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 9971 | pw.print(" Session "); pw.print(s); pw.println(':'); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9972 | s.dump(pw, " "); |
| 9973 | } |
| 9974 | } |
| 9975 | if (mTokenMap.size() > 0) { |
| 9976 | pw.println(" "); |
| 9977 | pw.println(" All tokens:"); |
| 9978 | Iterator<WindowToken> it = mTokenMap.values().iterator(); |
| 9979 | while (it.hasNext()) { |
| 9980 | WindowToken token = it.next(); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 9981 | pw.print(" Token "); pw.print(token.token); pw.println(':'); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9982 | token.dump(pw, " "); |
| 9983 | } |
| 9984 | } |
| 9985 | if (mTokenList.size() > 0) { |
| 9986 | pw.println(" "); |
| 9987 | pw.println(" Window token list:"); |
| 9988 | for (int i=0; i<mTokenList.size(); i++) { |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 9989 | pw.print(" #"); pw.print(i); pw.print(": "); |
| 9990 | pw.println(mTokenList.get(i)); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9991 | } |
| 9992 | } |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 9993 | if (mWallpaperTokens.size() > 0) { |
| 9994 | pw.println(" "); |
| 9995 | pw.println(" Wallpaper tokens:"); |
| 9996 | for (int i=mWallpaperTokens.size()-1; i>=0; i--) { |
| 9997 | WindowToken token = mWallpaperTokens.get(i); |
| 9998 | pw.print(" Wallpaper #"); pw.print(i); |
| 9999 | pw.print(' '); pw.print(token); pw.println(':'); |
| 10000 | token.dump(pw, " "); |
| 10001 | } |
| 10002 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10003 | if (mAppTokens.size() > 0) { |
| 10004 | pw.println(" "); |
| 10005 | pw.println(" Application tokens in Z order:"); |
| 10006 | for (int i=mAppTokens.size()-1; i>=0; i--) { |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10007 | pw.print(" App #"); pw.print(i); pw.print(": "); |
| 10008 | pw.println(mAppTokens.get(i)); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10009 | } |
| 10010 | } |
| 10011 | if (mFinishedStarting.size() > 0) { |
| 10012 | pw.println(" "); |
| 10013 | pw.println(" Finishing start of application tokens:"); |
| 10014 | for (int i=mFinishedStarting.size()-1; i>=0; i--) { |
| 10015 | WindowToken token = mFinishedStarting.get(i); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10016 | pw.print(" Finished Starting #"); pw.print(i); |
| 10017 | pw.print(' '); pw.print(token); pw.println(':'); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10018 | token.dump(pw, " "); |
| 10019 | } |
| 10020 | } |
| 10021 | if (mExitingTokens.size() > 0) { |
| 10022 | pw.println(" "); |
| 10023 | pw.println(" Exiting tokens:"); |
| 10024 | for (int i=mExitingTokens.size()-1; i>=0; i--) { |
| 10025 | WindowToken token = mExitingTokens.get(i); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10026 | pw.print(" Exiting #"); pw.print(i); |
| 10027 | pw.print(' '); pw.print(token); pw.println(':'); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10028 | token.dump(pw, " "); |
| 10029 | } |
| 10030 | } |
| 10031 | if (mExitingAppTokens.size() > 0) { |
| 10032 | pw.println(" "); |
| 10033 | pw.println(" Exiting application tokens:"); |
| 10034 | for (int i=mExitingAppTokens.size()-1; i>=0; i--) { |
| 10035 | WindowToken token = mExitingAppTokens.get(i); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10036 | pw.print(" Exiting App #"); pw.print(i); |
| 10037 | pw.print(' '); pw.print(token); pw.println(':'); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10038 | token.dump(pw, " "); |
| 10039 | } |
| 10040 | } |
| 10041 | pw.println(" "); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10042 | pw.print(" mCurrentFocus="); pw.println(mCurrentFocus); |
| 10043 | pw.print(" mLastFocus="); pw.println(mLastFocus); |
| 10044 | pw.print(" mFocusedApp="); pw.println(mFocusedApp); |
| 10045 | pw.print(" mInputMethodTarget="); pw.println(mInputMethodTarget); |
| 10046 | pw.print(" mInputMethodWindow="); pw.println(mInputMethodWindow); |
| Dianne Hackborn | f21adf6 | 2009-08-13 10:20:21 -0700 | [diff] [blame] | 10047 | pw.print(" mWallpaperTarget="); pw.println(mWallpaperTarget); |
| Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 10048 | if (mLowerWallpaperTarget != null && mUpperWallpaperTarget != null) { |
| 10049 | pw.print(" mLowerWallpaperTarget="); pw.println(mLowerWallpaperTarget); |
| 10050 | pw.print(" mUpperWallpaperTarget="); pw.println(mUpperWallpaperTarget); |
| 10051 | } |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 10052 | pw.print(" mCurConfiguration="); pw.println(this.mCurConfiguration); |
| 10053 | pw.print(" mInTouchMode="); pw.print(mInTouchMode); |
| 10054 | pw.print(" mLayoutSeq="); pw.println(mLayoutSeq); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10055 | pw.print(" mSystemBooted="); pw.print(mSystemBooted); |
| 10056 | pw.print(" mDisplayEnabled="); pw.println(mDisplayEnabled); |
| 10057 | pw.print(" mLayoutNeeded="); pw.print(mLayoutNeeded); |
| 10058 | pw.print(" mBlurShown="); pw.println(mBlurShown); |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 10059 | if (mDimAnimator != null) { |
| 10060 | mDimAnimator.printTo(pw); |
| 10061 | } else { |
| Dianne Hackborn | a2e9226 | 2010-03-02 17:19:29 -0800 | [diff] [blame] | 10062 | pw.println( " no DimAnimator "); |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 10063 | } |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10064 | pw.print(" mInputMethodAnimLayerAdjustment="); |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 10065 | pw.print(mInputMethodAnimLayerAdjustment); |
| 10066 | pw.print(" mWallpaperAnimLayerAdjustment="); |
| 10067 | pw.println(mWallpaperAnimLayerAdjustment); |
| Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 10068 | pw.print(" mLastWallpaperX="); pw.print(mLastWallpaperX); |
| 10069 | pw.print(" mLastWallpaperY="); pw.println(mLastWallpaperY); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10070 | pw.print(" mDisplayFrozen="); pw.print(mDisplayFrozen); |
| 10071 | pw.print(" mWindowsFreezingScreen="); pw.print(mWindowsFreezingScreen); |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 10072 | pw.print(" mAppsFreezingScreen="); pw.print(mAppsFreezingScreen); |
| 10073 | pw.print(" mWaitingForConfig="); pw.println(mWaitingForConfig); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10074 | pw.print(" mRotation="); pw.print(mRotation); |
| 10075 | pw.print(", mForcedAppOrientation="); pw.print(mForcedAppOrientation); |
| 10076 | pw.print(", mRequestedRotation="); pw.println(mRequestedRotation); |
| 10077 | pw.print(" mAnimationPending="); pw.print(mAnimationPending); |
| 10078 | pw.print(" mWindowAnimationScale="); pw.print(mWindowAnimationScale); |
| 10079 | pw.print(" mTransitionWindowAnimationScale="); pw.println(mTransitionAnimationScale); |
| 10080 | pw.print(" mNextAppTransition=0x"); |
| 10081 | pw.print(Integer.toHexString(mNextAppTransition)); |
| 10082 | pw.print(", mAppTransitionReady="); pw.print(mAppTransitionReady); |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 10083 | pw.print(", mAppTransitionRunning="); pw.print(mAppTransitionRunning); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10084 | pw.print(", mAppTransitionTimeout="); pw.println( mAppTransitionTimeout); |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10085 | if (mNextAppTransitionPackage != null) { |
| 10086 | pw.print(" mNextAppTransitionPackage="); |
| 10087 | pw.print(mNextAppTransitionPackage); |
| 10088 | pw.print(", mNextAppTransitionEnter=0x"); |
| 10089 | pw.print(Integer.toHexString(mNextAppTransitionEnter)); |
| 10090 | pw.print(", mNextAppTransitionExit=0x"); |
| 10091 | pw.print(Integer.toHexString(mNextAppTransitionExit)); |
| 10092 | } |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10093 | pw.print(" mStartingIconInTransition="); pw.print(mStartingIconInTransition); |
| 10094 | pw.print(", mSkipAppTransitionAnimation="); pw.println(mSkipAppTransitionAnimation); |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10095 | if (mLastEnterAnimToken != null || mLastEnterAnimToken != null) { |
| 10096 | pw.print(" mLastEnterAnimToken="); pw.print(mLastEnterAnimToken); |
| 10097 | pw.print(", mLastEnterAnimParams="); pw.println(mLastEnterAnimParams); |
| 10098 | } |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10099 | if (mOpeningApps.size() > 0) { |
| 10100 | pw.print(" mOpeningApps="); pw.println(mOpeningApps); |
| 10101 | } |
| 10102 | if (mClosingApps.size() > 0) { |
| 10103 | pw.print(" mClosingApps="); pw.println(mClosingApps); |
| 10104 | } |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 10105 | if (mToTopApps.size() > 0) { |
| 10106 | pw.print(" mToTopApps="); pw.println(mToTopApps); |
| 10107 | } |
| 10108 | if (mToBottomApps.size() > 0) { |
| 10109 | pw.print(" mToBottomApps="); pw.println(mToBottomApps); |
| 10110 | } |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10111 | pw.print(" DisplayWidth="); pw.print(mDisplay.getWidth()); |
| 10112 | pw.print(" DisplayHeight="); pw.println(mDisplay.getHeight()); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10113 | } |
| 10114 | } |
| 10115 | |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 10116 | // Called by the heartbeat to ensure locks are not held indefnitely (for deadlock detection). |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10117 | public void monitor() { |
| 10118 | synchronized (mWindowMap) { } |
| Mike Lockwood | 983ee09 | 2009-11-22 01:42:24 -0500 | [diff] [blame] | 10119 | synchronized (mKeyguardTokenWatcher) { } |
| Dianne Hackborn | ddca3ee | 2009-07-23 19:01:31 -0700 | [diff] [blame] | 10120 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10121 | |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 10122 | /** |
| 10123 | * DimAnimator class that controls the dim animation. This holds the surface and |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10124 | * all state used for dim animation. |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 10125 | */ |
| 10126 | private static class DimAnimator { |
| 10127 | Surface mDimSurface; |
| 10128 | boolean mDimShown = false; |
| 10129 | float mDimCurrentAlpha; |
| 10130 | float mDimTargetAlpha; |
| 10131 | float mDimDeltaPerMs; |
| 10132 | long mLastDimAnimTime; |
| Dianne Hackborn | f83c555 | 2010-03-31 22:19:32 -0700 | [diff] [blame] | 10133 | |
| 10134 | int mLastDimWidth, mLastDimHeight; |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 10135 | |
| 10136 | DimAnimator (SurfaceSession session) { |
| 10137 | if (mDimSurface == null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10138 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 10139 | + mDimSurface + ": CREATE"); |
| 10140 | try { |
| Mathias Agopian | 5d26c1e | 2010-03-01 16:09:43 -0800 | [diff] [blame] | 10141 | mDimSurface = new Surface(session, 0, |
| 10142 | "DimSurface", |
| 10143 | -1, 16, 16, PixelFormat.OPAQUE, |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 10144 | Surface.FX_SURFACE_DIM); |
| Maciej Białka | 9ee5c22 | 2010-03-24 10:25:40 +0100 | [diff] [blame] | 10145 | mDimSurface.setAlpha(0.0f); |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 10146 | } catch (Exception e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10147 | Slog.e(TAG, "Exception creating Dim surface", e); |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 10148 | } |
| 10149 | } |
| 10150 | } |
| 10151 | |
| 10152 | /** |
| 10153 | * Show the dim surface. |
| 10154 | */ |
| 10155 | void show(int dw, int dh) { |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 10156 | if (!mDimShown) { |
| 10157 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface + ": SHOW pos=(0,0) (" + |
| 10158 | dw + "x" + dh + ")"); |
| 10159 | mDimShown = true; |
| 10160 | try { |
| Dianne Hackborn | f83c555 | 2010-03-31 22:19:32 -0700 | [diff] [blame] | 10161 | mLastDimWidth = dw; |
| 10162 | mLastDimHeight = dh; |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 10163 | mDimSurface.setPosition(0, 0); |
| 10164 | mDimSurface.setSize(dw, dh); |
| 10165 | mDimSurface.show(); |
| 10166 | } catch (RuntimeException e) { |
| 10167 | Slog.w(TAG, "Failure showing dim surface", e); |
| 10168 | } |
| Dianne Hackborn | f83c555 | 2010-03-31 22:19:32 -0700 | [diff] [blame] | 10169 | } else if (mLastDimWidth != dw || mLastDimHeight != dh) { |
| 10170 | mLastDimWidth = dw; |
| 10171 | mLastDimHeight = dh; |
| 10172 | mDimSurface.setSize(dw, dh); |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 10173 | } |
| 10174 | } |
| 10175 | |
| 10176 | /** |
| 10177 | * Set's the dim surface's layer and update dim parameters that will be used in |
| 10178 | * {@link updateSurface} after all windows are examined. |
| 10179 | */ |
| 10180 | void updateParameters(WindowState w, long currentTime) { |
| 10181 | mDimSurface.setLayer(w.mAnimLayer-1); |
| 10182 | |
| 10183 | final float target = w.mExiting ? 0 : w.mAttrs.dimAmount; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10184 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 10185 | + ": layer=" + (w.mAnimLayer-1) + " target=" + target); |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 10186 | if (mDimTargetAlpha != target) { |
| 10187 | // If the desired dim level has changed, then |
| 10188 | // start an animation to it. |
| 10189 | mLastDimAnimTime = currentTime; |
| 10190 | long duration = (w.mAnimating && w.mAnimation != null) |
| 10191 | ? w.mAnimation.computeDurationHint() |
| 10192 | : DEFAULT_DIM_DURATION; |
| 10193 | if (target > mDimTargetAlpha) { |
| 10194 | // This is happening behind the activity UI, |
| 10195 | // so we can make it run a little longer to |
| 10196 | // give a stronger impression without disrupting |
| 10197 | // the user. |
| 10198 | duration *= DIM_DURATION_MULTIPLIER; |
| 10199 | } |
| 10200 | if (duration < 1) { |
| 10201 | // Don't divide by zero |
| 10202 | duration = 1; |
| 10203 | } |
| 10204 | mDimTargetAlpha = target; |
| 10205 | mDimDeltaPerMs = (mDimTargetAlpha-mDimCurrentAlpha) / duration; |
| 10206 | } |
| 10207 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10208 | |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 10209 | /** |
| 10210 | * Updating the surface's alpha. Returns true if the animation continues, or returns |
| 10211 | * false when the animation is finished and the dim surface is hidden. |
| 10212 | */ |
| 10213 | boolean updateSurface(boolean dimming, long currentTime, boolean displayFrozen) { |
| 10214 | if (!dimming) { |
| 10215 | if (mDimTargetAlpha != 0) { |
| 10216 | mLastDimAnimTime = currentTime; |
| 10217 | mDimTargetAlpha = 0; |
| 10218 | mDimDeltaPerMs = (-mDimCurrentAlpha) / DEFAULT_DIM_DURATION; |
| 10219 | } |
| 10220 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10221 | |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 10222 | boolean animating = false; |
| 10223 | if (mLastDimAnimTime != 0) { |
| 10224 | mDimCurrentAlpha += mDimDeltaPerMs |
| 10225 | * (currentTime-mLastDimAnimTime); |
| 10226 | boolean more = true; |
| 10227 | if (displayFrozen) { |
| 10228 | // If the display is frozen, there is no reason to animate. |
| 10229 | more = false; |
| 10230 | } else if (mDimDeltaPerMs > 0) { |
| 10231 | if (mDimCurrentAlpha > mDimTargetAlpha) { |
| 10232 | more = false; |
| 10233 | } |
| 10234 | } else if (mDimDeltaPerMs < 0) { |
| 10235 | if (mDimCurrentAlpha < mDimTargetAlpha) { |
| 10236 | more = false; |
| 10237 | } |
| 10238 | } else { |
| 10239 | more = false; |
| 10240 | } |
| 10241 | |
| 10242 | // Do we need to continue animating? |
| 10243 | if (more) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10244 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 10245 | + mDimSurface + ": alpha=" + mDimCurrentAlpha); |
| 10246 | mLastDimAnimTime = currentTime; |
| 10247 | mDimSurface.setAlpha(mDimCurrentAlpha); |
| 10248 | animating = true; |
| 10249 | } else { |
| 10250 | mDimCurrentAlpha = mDimTargetAlpha; |
| 10251 | mLastDimAnimTime = 0; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10252 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 10253 | + mDimSurface + ": final alpha=" + mDimCurrentAlpha); |
| 10254 | mDimSurface.setAlpha(mDimCurrentAlpha); |
| 10255 | if (!dimming) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10256 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 10257 | + ": HIDE"); |
| 10258 | try { |
| 10259 | mDimSurface.hide(); |
| 10260 | } catch (RuntimeException e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10261 | Slog.w(TAG, "Illegal argument exception hiding dim surface"); |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 10262 | } |
| 10263 | mDimShown = false; |
| 10264 | } |
| 10265 | } |
| 10266 | } |
| 10267 | return animating; |
| 10268 | } |
| 10269 | |
| 10270 | public void printTo(PrintWriter pw) { |
| 10271 | pw.print(" mDimShown="); pw.print(mDimShown); |
| 10272 | pw.print(" current="); pw.print(mDimCurrentAlpha); |
| 10273 | pw.print(" target="); pw.print(mDimTargetAlpha); |
| 10274 | pw.print(" delta="); pw.print(mDimDeltaPerMs); |
| 10275 | pw.print(" lastAnimTime="); pw.println(mLastDimAnimTime); |
| 10276 | } |
| 10277 | } |
| 10278 | |
| 10279 | /** |
| 10280 | * Animation that fade in after 0.5 interpolate time, or fade out in reverse order. |
| 10281 | * This is used for opening/closing transition for apps in compatible mode. |
| 10282 | */ |
| 10283 | private static class FadeInOutAnimation extends Animation { |
| 10284 | int mWidth; |
| 10285 | boolean mFadeIn; |
| 10286 | |
| 10287 | public FadeInOutAnimation(boolean fadeIn) { |
| 10288 | setInterpolator(new AccelerateInterpolator()); |
| 10289 | setDuration(DEFAULT_FADE_IN_OUT_DURATION); |
| 10290 | mFadeIn = fadeIn; |
| 10291 | } |
| 10292 | |
| 10293 | @Override |
| 10294 | protected void applyTransformation(float interpolatedTime, Transformation t) { |
| 10295 | float x = interpolatedTime; |
| 10296 | if (!mFadeIn) { |
| 10297 | x = 1.0f - x; // reverse the interpolation for fade out |
| 10298 | } |
| 10299 | if (x < 0.5) { |
| 10300 | // move the window out of the screen. |
| 10301 | t.getMatrix().setTranslate(mWidth, 0); |
| 10302 | } else { |
| 10303 | t.getMatrix().setTranslate(0, 0);// show |
| 10304 | t.setAlpha((x - 0.5f) * 2); |
| 10305 | } |
| 10306 | } |
| 10307 | |
| 10308 | @Override |
| 10309 | public void initialize(int width, int height, int parentWidth, int parentHeight) { |
| 10310 | // width is the screen width {@see AppWindowToken#stepAnimatinoLocked} |
| 10311 | mWidth = width; |
| 10312 | } |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 10313 | |
| 10314 | @Override |
| Mitsuru Oshima | 5a2b91d | 2009-07-16 16:30:02 -0700 | [diff] [blame] | 10315 | public int getZAdjustment() { |
| 10316 | return Animation.ZORDER_TOP; |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 10317 | } |
| 10318 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10319 | } |