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 | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 104 | import android.view.InputChannel; |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 105 | import android.view.InputDevice; |
Jeff Brown | bbda99d | 2010-07-28 15:48:59 -0700 | [diff] [blame] | 106 | import android.view.InputEvent; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 107 | import android.view.InputQueue; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 108 | import android.view.KeyEvent; |
| 109 | import android.view.MotionEvent; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 110 | import android.view.Surface; |
| 111 | import android.view.SurfaceSession; |
| 112 | import android.view.View; |
Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 113 | import android.view.ViewConfiguration; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 114 | import android.view.ViewTreeObserver; |
| 115 | import android.view.WindowManager; |
| 116 | import android.view.WindowManagerImpl; |
| 117 | import android.view.WindowManagerPolicy; |
| 118 | import android.view.WindowManager.LayoutParams; |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 119 | import android.view.animation.AccelerateInterpolator; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 120 | import android.view.animation.Animation; |
| 121 | import android.view.animation.AnimationUtils; |
| 122 | import android.view.animation.Transformation; |
| 123 | |
| 124 | import java.io.BufferedWriter; |
| 125 | import java.io.File; |
| 126 | import java.io.FileDescriptor; |
| 127 | import java.io.IOException; |
| 128 | import java.io.OutputStream; |
| 129 | import java.io.OutputStreamWriter; |
| 130 | import java.io.PrintWriter; |
| 131 | import java.io.StringWriter; |
| 132 | import java.net.Socket; |
| 133 | import java.util.ArrayList; |
| 134 | import java.util.HashMap; |
| 135 | import java.util.HashSet; |
| 136 | import java.util.Iterator; |
| 137 | import java.util.List; |
| 138 | |
| 139 | /** {@hide} */ |
Dianne Hackborn | ddca3ee | 2009-07-23 19:01:31 -0700 | [diff] [blame] | 140 | public class WindowManagerService extends IWindowManager.Stub |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 141 | implements Watchdog.Monitor { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 142 | static final String TAG = "WindowManager"; |
| 143 | static final boolean DEBUG = false; |
| 144 | static final boolean DEBUG_FOCUS = false; |
| 145 | static final boolean DEBUG_ANIM = false; |
Dianne Hackborn | 9b52a21 | 2009-12-11 14:51:35 -0800 | [diff] [blame] | 146 | static final boolean DEBUG_LAYOUT = false; |
Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 147 | static final boolean DEBUG_RESIZE = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 148 | static final boolean DEBUG_LAYERS = false; |
| 149 | static final boolean DEBUG_INPUT = false; |
| 150 | static final boolean DEBUG_INPUT_METHOD = false; |
| 151 | static final boolean DEBUG_VISIBILITY = false; |
Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 152 | static final boolean DEBUG_WINDOW_MOVEMENT = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 153 | static final boolean DEBUG_ORIENTATION = false; |
Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 154 | static final boolean DEBUG_CONFIGURATION = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 155 | static final boolean DEBUG_APP_TRANSITIONS = false; |
| 156 | static final boolean DEBUG_STARTING_WINDOW = false; |
| 157 | static final boolean DEBUG_REORDER = false; |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 158 | static final boolean DEBUG_WALLPAPER = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 159 | static final boolean SHOW_TRANSACTIONS = false; |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 160 | static final boolean HIDE_STACK_CRAWLS = true; |
Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 161 | static final boolean MEASURE_LATENCY = false; |
| 162 | static private LatencyTimer lt; |
| 163 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 164 | static final boolean PROFILE_ORIENTATION = false; |
| 165 | static final boolean BLUR = true; |
Dave Bort | cfe6524 | 2009-04-09 14:51:04 -0700 | [diff] [blame] | 166 | static final boolean localLOGV = DEBUG; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 167 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 168 | /** How much to multiply the policy's type layer, to reserve room |
| 169 | * for multiple windows of the same type and Z-ordering adjustment |
| 170 | * with TYPE_LAYER_OFFSET. */ |
| 171 | static final int TYPE_LAYER_MULTIPLIER = 10000; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 172 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 173 | /** Offset from TYPE_LAYER_MULTIPLIER for moving a group of windows above |
| 174 | * or below others in the same layer. */ |
| 175 | static final int TYPE_LAYER_OFFSET = 1000; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 176 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 177 | /** How much to increment the layer for each window, to reserve room |
| 178 | * for effect surfaces between them. |
| 179 | */ |
| 180 | static final int WINDOW_LAYER_MULTIPLIER = 5; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 181 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 182 | /** The maximum length we will accept for a loaded animation duration: |
| 183 | * this is 10 seconds. |
| 184 | */ |
| 185 | static final int MAX_ANIMATION_DURATION = 10*1000; |
| 186 | |
| 187 | /** Amount of time (in milliseconds) to animate the dim surface from one |
| 188 | * value to another, when no window animation is driving it. |
| 189 | */ |
| 190 | static final int DEFAULT_DIM_DURATION = 200; |
| 191 | |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 192 | /** Amount of time (in milliseconds) to animate the fade-in-out transition for |
| 193 | * compatible windows. |
| 194 | */ |
| 195 | static final int DEFAULT_FADE_IN_OUT_DURATION = 400; |
| 196 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 197 | /** Adjustment to time to perform a dim, to make it more dramatic. |
| 198 | */ |
| 199 | static final int DIM_DURATION_MULTIPLIER = 6; |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 200 | |
| 201 | // Maximum number of milliseconds to wait for input event injection. |
| 202 | // FIXME is this value reasonable? |
| 203 | private static final int INJECTION_TIMEOUT_MILLIS = 30 * 1000; |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 204 | |
| 205 | // Default input dispatching timeout in nanoseconds. |
| 206 | private static final long DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS = 5000 * 1000000L; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 207 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 208 | static final int UPDATE_FOCUS_NORMAL = 0; |
| 209 | static final int UPDATE_FOCUS_WILL_ASSIGN_LAYERS = 1; |
| 210 | static final int UPDATE_FOCUS_PLACING_SURFACES = 2; |
| 211 | static final int UPDATE_FOCUS_WILL_PLACE_SURFACES = 3; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 212 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 213 | private static final String SYSTEM_SECURE = "ro.secure"; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 214 | private static final String SYSTEM_DEBUGGABLE = "ro.debuggable"; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 215 | |
| 216 | /** |
| 217 | * Condition waited on by {@link #reenableKeyguard} to know the call to |
| 218 | * the window policy has finished. |
Mike Lockwood | 983ee09 | 2009-11-22 01:42:24 -0500 | [diff] [blame] | 219 | * This is set to true only if mKeyguardTokenWatcher.acquired() has |
| 220 | * actually disabled the keyguard. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 221 | */ |
Mike Lockwood | 983ee09 | 2009-11-22 01:42:24 -0500 | [diff] [blame] | 222 | private boolean mKeyguardDisabled = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 223 | |
Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 224 | private static final int ALLOW_DISABLE_YES = 1; |
| 225 | private static final int ALLOW_DISABLE_NO = 0; |
| 226 | private static final int ALLOW_DISABLE_UNKNOWN = -1; // check with DevicePolicyManager |
| 227 | private int mAllowDisableKeyguard = ALLOW_DISABLE_UNKNOWN; // sync'd by mKeyguardTokenWatcher |
| 228 | |
Mike Lockwood | 983ee09 | 2009-11-22 01:42:24 -0500 | [diff] [blame] | 229 | final TokenWatcher mKeyguardTokenWatcher = new TokenWatcher( |
| 230 | new Handler(), "WindowManagerService.mKeyguardTokenWatcher") { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 231 | public void acquired() { |
Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 232 | if (shouldAllowDisableKeyguard()) { |
| 233 | mPolicy.enableKeyguard(false); |
| 234 | mKeyguardDisabled = true; |
| 235 | } else { |
| 236 | Log.v(TAG, "Not disabling keyguard since device policy is enforced"); |
| 237 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 238 | } |
| 239 | public void released() { |
Dianne Hackborn | a33e3f7 | 2009-09-29 17:28:24 -0700 | [diff] [blame] | 240 | mPolicy.enableKeyguard(true); |
Mike Lockwood | 983ee09 | 2009-11-22 01:42:24 -0500 | [diff] [blame] | 241 | synchronized (mKeyguardTokenWatcher) { |
| 242 | mKeyguardDisabled = false; |
| 243 | mKeyguardTokenWatcher.notifyAll(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 244 | } |
| 245 | } |
| 246 | }; |
| 247 | |
Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 248 | final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() { |
| 249 | @Override |
| 250 | public void onReceive(Context context, Intent intent) { |
| 251 | mPolicy.enableKeyguard(true); |
| 252 | synchronized(mKeyguardTokenWatcher) { |
| 253 | // lazily evaluate this next time we're asked to disable keyguard |
| 254 | mAllowDisableKeyguard = ALLOW_DISABLE_UNKNOWN; |
| 255 | mKeyguardDisabled = false; |
| 256 | } |
| 257 | } |
| 258 | }; |
| 259 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 260 | final Context mContext; |
| 261 | |
| 262 | final boolean mHaveInputMethods; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 263 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 264 | final boolean mLimitedAlphaCompositing; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 265 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 266 | final WindowManagerPolicy mPolicy = PolicyManager.makeNewWindowManager(); |
| 267 | |
| 268 | final IActivityManager mActivityManager; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 269 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 270 | final IBatteryStats mBatteryStats; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 271 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 272 | /** |
| 273 | * All currently active sessions with clients. |
| 274 | */ |
| 275 | final HashSet<Session> mSessions = new HashSet<Session>(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 276 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 277 | /** |
| 278 | * Mapping from an IWindow IBinder to the server's Window object. |
| 279 | * This is also used as the lock for all of our state. |
| 280 | */ |
| 281 | final HashMap<IBinder, WindowState> mWindowMap = new HashMap<IBinder, WindowState>(); |
| 282 | |
| 283 | /** |
| 284 | * Mapping from a token IBinder to a WindowToken object. |
| 285 | */ |
| 286 | final HashMap<IBinder, WindowToken> mTokenMap = |
| 287 | new HashMap<IBinder, WindowToken>(); |
| 288 | |
| 289 | /** |
| 290 | * The same tokens as mTokenMap, stored in a list for efficient iteration |
| 291 | * over them. |
| 292 | */ |
| 293 | final ArrayList<WindowToken> mTokenList = new ArrayList<WindowToken>(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 294 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 295 | /** |
| 296 | * Window tokens that are in the process of exiting, but still |
| 297 | * on screen for animations. |
| 298 | */ |
| 299 | final ArrayList<WindowToken> mExitingTokens = new ArrayList<WindowToken>(); |
| 300 | |
| 301 | /** |
| 302 | * Z-ordered (bottom-most first) list of all application tokens, for |
| 303 | * controlling the ordering of windows in different applications. This |
| 304 | * contains WindowToken objects. |
| 305 | */ |
| 306 | final ArrayList<AppWindowToken> mAppTokens = new ArrayList<AppWindowToken>(); |
| 307 | |
| 308 | /** |
| 309 | * Application tokens that are in the process of exiting, but still |
| 310 | * on screen for animations. |
| 311 | */ |
| 312 | final ArrayList<AppWindowToken> mExitingAppTokens = new ArrayList<AppWindowToken>(); |
| 313 | |
| 314 | /** |
| 315 | * List of window tokens that have finished starting their application, |
| 316 | * and now need to have the policy remove their windows. |
| 317 | */ |
| 318 | final ArrayList<AppWindowToken> mFinishedStarting = new ArrayList<AppWindowToken>(); |
| 319 | |
| 320 | /** |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 321 | * This was the app token that was used to retrieve the last enter |
| 322 | * animation. It will be used for the next exit animation. |
| 323 | */ |
| 324 | AppWindowToken mLastEnterAnimToken; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 325 | |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 326 | /** |
| 327 | * These were the layout params used to retrieve the last enter animation. |
| 328 | * They will be used for the next exit animation. |
| 329 | */ |
| 330 | LayoutParams mLastEnterAnimParams; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 331 | |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 332 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 333 | * Z-ordered (bottom-most first) list of all Window objects. |
| 334 | */ |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 335 | final ArrayList<WindowState> mWindows = new ArrayList<WindowState>(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 336 | |
| 337 | /** |
| 338 | * Windows that are being resized. Used so we can tell the client about |
| 339 | * the resize after closing the transaction in which we resized the |
| 340 | * underlying surface. |
| 341 | */ |
| 342 | final ArrayList<WindowState> mResizingWindows = new ArrayList<WindowState>(); |
| 343 | |
| 344 | /** |
| 345 | * Windows whose animations have ended and now must be removed. |
| 346 | */ |
| 347 | final ArrayList<WindowState> mPendingRemove = new ArrayList<WindowState>(); |
| 348 | |
| 349 | /** |
| 350 | * Windows whose surface should be destroyed. |
| 351 | */ |
| 352 | final ArrayList<WindowState> mDestroySurface = new ArrayList<WindowState>(); |
| 353 | |
| 354 | /** |
| 355 | * Windows that have lost input focus and are waiting for the new |
| 356 | * focus window to be displayed before they are told about this. |
| 357 | */ |
| 358 | ArrayList<WindowState> mLosingFocus = new ArrayList<WindowState>(); |
| 359 | |
| 360 | /** |
| 361 | * This is set when we have run out of memory, and will either be an empty |
| 362 | * list or contain windows that need to be force removed. |
| 363 | */ |
| 364 | ArrayList<WindowState> mForceRemoves; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 365 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 366 | IInputMethodManager mInputMethodManager; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 367 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 368 | SurfaceSession mFxSession; |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 369 | private DimAnimator mDimAnimator = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 370 | Surface mBlurSurface; |
| 371 | boolean mBlurShown; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 372 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 373 | int mTransactionSequence = 0; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 374 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 375 | final float[] mTmpFloats = new float[9]; |
| 376 | |
| 377 | boolean mSafeMode; |
| 378 | boolean mDisplayEnabled = false; |
| 379 | boolean mSystemBooted = false; |
Christopher Tate | b696aee | 2010-04-02 19:08:30 -0700 | [diff] [blame] | 380 | int mInitialDisplayWidth = 0; |
| 381 | int mInitialDisplayHeight = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 382 | int mRotation = 0; |
| 383 | int mRequestedRotation = 0; |
| 384 | int mForcedAppOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
Dianne Hackborn | 321ae68 | 2009-03-27 16:16:03 -0700 | [diff] [blame] | 385 | int mLastRotationFlags; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 386 | ArrayList<IRotationWatcher> mRotationWatchers |
| 387 | = new ArrayList<IRotationWatcher>(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 388 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 389 | boolean mLayoutNeeded = true; |
| 390 | boolean mAnimationPending = false; |
| 391 | boolean mDisplayFrozen = false; |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 392 | boolean mWaitingForConfig = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 393 | boolean mWindowsFreezingScreen = false; |
| 394 | long mFreezeGcPending = 0; |
| 395 | int mAppsFreezingScreen = 0; |
| 396 | |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 397 | int mLayoutSeq = 0; |
| 398 | |
Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 399 | // State while inside of layoutAndPlaceSurfacesLocked(). |
| 400 | boolean mFocusMayChange; |
| 401 | |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 402 | Configuration mCurConfiguration = new Configuration(); |
| 403 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 404 | // This is held as long as we have the screen frozen, to give us time to |
| 405 | // perform a rotation animation when turning off shows the lock screen which |
| 406 | // changes the orientation. |
| 407 | PowerManager.WakeLock mScreenFrozenLock; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 408 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 409 | // State management of app transitions. When we are preparing for a |
| 410 | // transition, mNextAppTransition will be the kind of transition to |
| 411 | // perform or TRANSIT_NONE if we are not waiting. If we are waiting, |
| 412 | // mOpeningApps and mClosingApps are the lists of tokens that will be |
| 413 | // made visible or hidden at the next transition. |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 414 | int mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 415 | String mNextAppTransitionPackage; |
| 416 | int mNextAppTransitionEnter; |
| 417 | int mNextAppTransitionExit; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 418 | boolean mAppTransitionReady = false; |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 419 | boolean mAppTransitionRunning = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 420 | boolean mAppTransitionTimeout = false; |
| 421 | boolean mStartingIconInTransition = false; |
| 422 | boolean mSkipAppTransitionAnimation = false; |
| 423 | final ArrayList<AppWindowToken> mOpeningApps = new ArrayList<AppWindowToken>(); |
| 424 | final ArrayList<AppWindowToken> mClosingApps = new ArrayList<AppWindowToken>(); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 425 | final ArrayList<AppWindowToken> mToTopApps = new ArrayList<AppWindowToken>(); |
| 426 | final ArrayList<AppWindowToken> mToBottomApps = new ArrayList<AppWindowToken>(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 427 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 428 | Display mDisplay; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 429 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 430 | H mH = new H(); |
| 431 | |
| 432 | WindowState mCurrentFocus = null; |
| 433 | WindowState mLastFocus = null; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 434 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 435 | // This just indicates the window the input method is on top of, not |
| 436 | // necessarily the window its input is going to. |
| 437 | WindowState mInputMethodTarget = null; |
| 438 | WindowState mUpcomingInputMethodTarget = null; |
| 439 | boolean mInputMethodTargetWaitingAnim; |
| 440 | int mInputMethodAnimLayerAdjustment; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 441 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 442 | WindowState mInputMethodWindow = null; |
| 443 | final ArrayList<WindowState> mInputMethodDialogs = new ArrayList<WindowState>(); |
| 444 | |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 445 | final ArrayList<WindowToken> mWallpaperTokens = new ArrayList<WindowToken>(); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 446 | |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 447 | // If non-null, this is the currently visible window that is associated |
| 448 | // with the wallpaper. |
| 449 | WindowState mWallpaperTarget = null; |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 450 | // If non-null, we are in the middle of animating from one wallpaper target |
| 451 | // to another, and this is the lower one in Z-order. |
| 452 | WindowState mLowerWallpaperTarget = null; |
| 453 | // If non-null, we are in the middle of animating from one wallpaper target |
| 454 | // to another, and this is the higher one in Z-order. |
| 455 | WindowState mUpperWallpaperTarget = null; |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 456 | int mWallpaperAnimLayerAdjustment; |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 457 | float mLastWallpaperX = -1; |
| 458 | float mLastWallpaperY = -1; |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 459 | float mLastWallpaperXStep = -1; |
| 460 | float mLastWallpaperYStep = -1; |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 461 | // This is set when we are waiting for a wallpaper to tell us it is done |
| 462 | // changing its scroll position. |
| 463 | WindowState mWaitingOnWallpaper; |
| 464 | // The last time we had a timeout when waiting for a wallpaper. |
| 465 | long mLastWallpaperTimeoutTime; |
| 466 | // We give a wallpaper up to 150ms to finish scrolling. |
| 467 | static final long WALLPAPER_TIMEOUT = 150; |
| 468 | // Time we wait after a timeout before trying to wait again. |
| 469 | static final long WALLPAPER_TIMEOUT_RECOVERY = 10000; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 470 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 471 | AppWindowToken mFocusedApp = null; |
| 472 | |
| 473 | PowerManagerService mPowerManager; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 474 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 475 | float mWindowAnimationScale = 1.0f; |
| 476 | float mTransitionAnimationScale = 1.0f; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 477 | |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 478 | final InputManager mInputManager; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 479 | |
| 480 | // Who is holding the screen on. |
| 481 | Session mHoldingScreenOn; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 482 | PowerManager.WakeLock mHoldingScreenWakeLock; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 483 | |
Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 484 | boolean mTurnOnScreen; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 485 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 486 | /** |
| 487 | * Whether the UI is currently running in touch mode (not showing |
| 488 | * navigational focus because the user is directly pressing the screen). |
| 489 | */ |
| 490 | boolean mInTouchMode = false; |
| 491 | |
| 492 | private ViewServer mViewServer; |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 493 | private ArrayList<WindowChangeListener> mWindowChangeListeners = |
| 494 | new ArrayList<WindowChangeListener>(); |
| 495 | private boolean mWindowsChanged = false; |
| 496 | |
| 497 | public interface WindowChangeListener { |
| 498 | public void windowsChanged(); |
Konstantin Lopyrev | 6e0f65f | 2010-07-14 14:55:33 -0700 | [diff] [blame] | 499 | public void focusChanged(); |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 500 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 501 | |
Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 502 | final Configuration mTempConfiguration = new Configuration(); |
Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 503 | int mScreenLayout = Configuration.SCREENLAYOUT_SIZE_UNDEFINED; |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 504 | |
| 505 | // The frame use to limit the size of the app running in compatibility mode. |
| 506 | Rect mCompatibleScreenFrame = new Rect(); |
| 507 | // The surface used to fill the outer rim of the app running in compatibility mode. |
| 508 | Surface mBackgroundFillerSurface = null; |
| 509 | boolean mBackgroundFillerShown = false; |
| 510 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 511 | public static WindowManagerService main(Context context, |
| 512 | PowerManagerService pm, boolean haveInputMethods) { |
| 513 | WMThread thr = new WMThread(context, pm, haveInputMethods); |
| 514 | thr.start(); |
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 | synchronized (thr) { |
| 517 | while (thr.mService == null) { |
| 518 | try { |
| 519 | thr.wait(); |
| 520 | } catch (InterruptedException e) { |
| 521 | } |
| 522 | } |
| 523 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 524 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 525 | return thr.mService; |
| 526 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 527 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 528 | static class WMThread extends Thread { |
| 529 | WindowManagerService mService; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 530 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 531 | private final Context mContext; |
| 532 | private final PowerManagerService mPM; |
| 533 | private final boolean mHaveInputMethods; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 534 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 535 | public WMThread(Context context, PowerManagerService pm, |
| 536 | boolean haveInputMethods) { |
| 537 | super("WindowManager"); |
| 538 | mContext = context; |
| 539 | mPM = pm; |
| 540 | mHaveInputMethods = haveInputMethods; |
| 541 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 542 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 543 | public void run() { |
| 544 | Looper.prepare(); |
| 545 | WindowManagerService s = new WindowManagerService(mContext, mPM, |
| 546 | mHaveInputMethods); |
| 547 | android.os.Process.setThreadPriority( |
| 548 | android.os.Process.THREAD_PRIORITY_DISPLAY); |
Christopher Tate | 160edb3 | 2010-06-30 17:46:30 -0700 | [diff] [blame] | 549 | android.os.Process.setCanSelfBackground(false); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 550 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 551 | synchronized (this) { |
| 552 | mService = s; |
| 553 | notifyAll(); |
| 554 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 555 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 556 | Looper.loop(); |
| 557 | } |
| 558 | } |
| 559 | |
| 560 | static class PolicyThread extends Thread { |
| 561 | private final WindowManagerPolicy mPolicy; |
| 562 | private final WindowManagerService mService; |
| 563 | private final Context mContext; |
| 564 | private final PowerManagerService mPM; |
| 565 | boolean mRunning = false; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 566 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 567 | public PolicyThread(WindowManagerPolicy policy, |
| 568 | WindowManagerService service, Context context, |
| 569 | PowerManagerService pm) { |
| 570 | super("WindowManagerPolicy"); |
| 571 | mPolicy = policy; |
| 572 | mService = service; |
| 573 | mContext = context; |
| 574 | mPM = pm; |
| 575 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 576 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 577 | public void run() { |
| 578 | Looper.prepare(); |
Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 579 | WindowManagerPolicyThread.set(this, Looper.myLooper()); |
| 580 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 581 | //Looper.myLooper().setMessageLogging(new LogPrinter( |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 582 | // Log.VERBOSE, "WindowManagerPolicy", Log.LOG_ID_SYSTEM)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 583 | android.os.Process.setThreadPriority( |
| 584 | android.os.Process.THREAD_PRIORITY_FOREGROUND); |
Christopher Tate | 160edb3 | 2010-06-30 17:46:30 -0700 | [diff] [blame] | 585 | android.os.Process.setCanSelfBackground(false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 586 | mPolicy.init(mContext, mService, mPM); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 587 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 588 | synchronized (this) { |
| 589 | mRunning = true; |
| 590 | notifyAll(); |
| 591 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 592 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 593 | Looper.loop(); |
| 594 | } |
| 595 | } |
| 596 | |
| 597 | private WindowManagerService(Context context, PowerManagerService pm, |
| 598 | boolean haveInputMethods) { |
Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 599 | if (MEASURE_LATENCY) { |
| 600 | lt = new LatencyTimer(100, 1000); |
| 601 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 602 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 603 | mContext = context; |
| 604 | mHaveInputMethods = haveInputMethods; |
| 605 | mLimitedAlphaCompositing = context.getResources().getBoolean( |
| 606 | com.android.internal.R.bool.config_sf_limitedAlpha); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 607 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 608 | mPowerManager = pm; |
| 609 | mPowerManager.setPolicy(mPolicy); |
| 610 | PowerManager pmc = (PowerManager)context.getSystemService(Context.POWER_SERVICE); |
| 611 | mScreenFrozenLock = pmc.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, |
| 612 | "SCREEN_FROZEN"); |
| 613 | mScreenFrozenLock.setReferenceCounted(false); |
| 614 | |
| 615 | mActivityManager = ActivityManagerNative.getDefault(); |
| 616 | mBatteryStats = BatteryStatsService.getService(); |
| 617 | |
| 618 | // Get persisted window scale setting |
| 619 | mWindowAnimationScale = Settings.System.getFloat(context.getContentResolver(), |
| 620 | Settings.System.WINDOW_ANIMATION_SCALE, mWindowAnimationScale); |
| 621 | mTransitionAnimationScale = Settings.System.getFloat(context.getContentResolver(), |
| 622 | Settings.System.TRANSITION_ANIMATION_SCALE, mTransitionAnimationScale); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 623 | |
Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 624 | // Track changes to DevicePolicyManager state so we can enable/disable keyguard. |
| 625 | IntentFilter filter = new IntentFilter(); |
| 626 | filter.addAction(DevicePolicyManager.ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED); |
| 627 | mContext.registerReceiver(mBroadcastReceiver, filter); |
| 628 | |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 629 | mHoldingScreenWakeLock = pmc.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK, |
| 630 | "KEEP_SCREEN_ON_FLAG"); |
| 631 | mHoldingScreenWakeLock.setReferenceCounted(false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 632 | |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 633 | mInputManager = new InputManager(context, this); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 634 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 635 | PolicyThread thr = new PolicyThread(mPolicy, this, context, pm); |
| 636 | thr.start(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 637 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 638 | synchronized (thr) { |
| 639 | while (!thr.mRunning) { |
| 640 | try { |
| 641 | thr.wait(); |
| 642 | } catch (InterruptedException e) { |
| 643 | } |
| 644 | } |
| 645 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 646 | |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 647 | mInputManager.start(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 648 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 649 | // Add ourself to the Watchdog monitors. |
| 650 | Watchdog.getInstance().addMonitor(this); |
| 651 | } |
| 652 | |
| 653 | @Override |
| 654 | public boolean onTransact(int code, Parcel data, Parcel reply, int flags) |
| 655 | throws RemoteException { |
| 656 | try { |
| 657 | return super.onTransact(code, data, reply, flags); |
| 658 | } catch (RuntimeException e) { |
| 659 | // The window manager only throws security exceptions, so let's |
| 660 | // log all others. |
| 661 | if (!(e instanceof SecurityException)) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 662 | Slog.e(TAG, "Window Manager Crash", e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 663 | } |
| 664 | throw e; |
| 665 | } |
| 666 | } |
| 667 | |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 668 | private void placeWindowAfter(WindowState pos, WindowState window) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 669 | final int i = mWindows.indexOf(pos); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 670 | if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 671 | TAG, "Adding window " + window + " at " |
| 672 | + (i+1) + " of " + mWindows.size() + " (after " + pos + ")"); |
| 673 | mWindows.add(i+1, window); |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 674 | mWindowsChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 675 | } |
| 676 | |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 677 | private void placeWindowBefore(WindowState pos, WindowState window) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 678 | final int i = mWindows.indexOf(pos); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 679 | if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 680 | TAG, "Adding window " + window + " at " |
| 681 | + i + " of " + mWindows.size() + " (before " + pos + ")"); |
| 682 | mWindows.add(i, window); |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 683 | mWindowsChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 684 | } |
| 685 | |
| 686 | //This method finds out the index of a window that has the same app token as |
| 687 | //win. used for z ordering the windows in mWindows |
| 688 | private int findIdxBasedOnAppTokens(WindowState win) { |
| 689 | //use a local variable to cache mWindows |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 690 | ArrayList<WindowState> localmWindows = mWindows; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 691 | int jmax = localmWindows.size(); |
| 692 | if(jmax == 0) { |
| 693 | return -1; |
| 694 | } |
| 695 | for(int j = (jmax-1); j >= 0; j--) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 696 | WindowState wentry = localmWindows.get(j); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 697 | if(wentry.mAppToken == win.mAppToken) { |
| 698 | return j; |
| 699 | } |
| 700 | } |
| 701 | return -1; |
| 702 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 703 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 704 | private void addWindowToListInOrderLocked(WindowState win, boolean addToToken) { |
| 705 | final IWindow client = win.mClient; |
| 706 | final WindowToken token = win.mToken; |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 707 | final ArrayList<WindowState> localmWindows = mWindows; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 708 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 709 | final int N = localmWindows.size(); |
| 710 | final WindowState attached = win.mAttachedWindow; |
| 711 | int i; |
| 712 | if (attached == null) { |
| 713 | int tokenWindowsPos = token.windows.size(); |
| 714 | if (token.appWindowToken != null) { |
| 715 | int index = tokenWindowsPos-1; |
| 716 | if (index >= 0) { |
| 717 | // If this application has existing windows, we |
| 718 | // simply place the new window on top of them... but |
| 719 | // keep the starting window on top. |
| 720 | if (win.mAttrs.type == TYPE_BASE_APPLICATION) { |
| 721 | // Base windows go behind everything else. |
| 722 | placeWindowBefore(token.windows.get(0), win); |
| 723 | tokenWindowsPos = 0; |
| 724 | } else { |
| 725 | AppWindowToken atoken = win.mAppToken; |
| 726 | if (atoken != null && |
| 727 | token.windows.get(index) == atoken.startingWindow) { |
| 728 | placeWindowBefore(token.windows.get(index), win); |
| 729 | tokenWindowsPos--; |
| 730 | } else { |
| 731 | int newIdx = findIdxBasedOnAppTokens(win); |
| 732 | if(newIdx != -1) { |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 733 | //there is a window above this one associated with the same |
| 734 | //apptoken note that the window could be a floating window |
| 735 | //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] | 736 | //windows associated with this token. |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 737 | if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v( |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 738 | TAG, "Adding window " + win + " at " |
| 739 | + (newIdx+1) + " of " + N); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 740 | localmWindows.add(newIdx+1, win); |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 741 | mWindowsChanged = true; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 742 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 743 | } |
| 744 | } |
| 745 | } else { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 746 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 747 | TAG, "Figuring out where to add app window " |
| 748 | + client.asBinder() + " (token=" + token + ")"); |
| 749 | // Figure out where the window should go, based on the |
| 750 | // order of applications. |
| 751 | final int NA = mAppTokens.size(); |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 752 | WindowState pos = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 753 | for (i=NA-1; i>=0; i--) { |
| 754 | AppWindowToken t = mAppTokens.get(i); |
| 755 | if (t == token) { |
| 756 | i--; |
| 757 | break; |
| 758 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 759 | |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 760 | // We haven't reached the token yet; if this token |
| 761 | // is not going to the bottom and has windows, we can |
| 762 | // use it as an anchor for when we do reach the token. |
| 763 | if (!t.sendingToBottom && t.windows.size() > 0) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 764 | pos = t.windows.get(0); |
| 765 | } |
| 766 | } |
| 767 | // We now know the index into the apps. If we found |
| 768 | // an app window above, that gives us the position; else |
| 769 | // we need to look some more. |
| 770 | if (pos != null) { |
| 771 | // Move behind any windows attached to this one. |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 772 | WindowToken atoken = mTokenMap.get(pos.mClient.asBinder()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 773 | if (atoken != null) { |
| 774 | final int NC = atoken.windows.size(); |
| 775 | if (NC > 0) { |
| 776 | WindowState bottom = atoken.windows.get(0); |
| 777 | if (bottom.mSubLayer < 0) { |
| 778 | pos = bottom; |
| 779 | } |
| 780 | } |
| 781 | } |
| 782 | placeWindowBefore(pos, win); |
| 783 | } else { |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 784 | // Continue looking down until we find the first |
| 785 | // token that has windows. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 786 | while (i >= 0) { |
| 787 | AppWindowToken t = mAppTokens.get(i); |
| 788 | final int NW = t.windows.size(); |
| 789 | if (NW > 0) { |
| 790 | pos = t.windows.get(NW-1); |
| 791 | break; |
| 792 | } |
| 793 | i--; |
| 794 | } |
| 795 | if (pos != null) { |
| 796 | // Move in front of any windows attached to this |
| 797 | // one. |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 798 | WindowToken atoken = mTokenMap.get(pos.mClient.asBinder()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 799 | if (atoken != null) { |
| 800 | final int NC = atoken.windows.size(); |
| 801 | if (NC > 0) { |
| 802 | WindowState top = atoken.windows.get(NC-1); |
| 803 | if (top.mSubLayer >= 0) { |
| 804 | pos = top; |
| 805 | } |
| 806 | } |
| 807 | } |
| 808 | placeWindowAfter(pos, win); |
| 809 | } else { |
| 810 | // Just search for the start of this layer. |
| 811 | final int myLayer = win.mBaseLayer; |
| 812 | for (i=0; i<N; i++) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 813 | WindowState w = localmWindows.get(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 814 | if (w.mBaseLayer > myLayer) { |
| 815 | break; |
| 816 | } |
| 817 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 818 | if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v( |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 819 | TAG, "Adding window " + win + " at " |
| 820 | + i + " of " + N); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 821 | localmWindows.add(i, win); |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 822 | mWindowsChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 823 | } |
| 824 | } |
| 825 | } |
| 826 | } else { |
| 827 | // Figure out where window should go, based on layer. |
| 828 | final int myLayer = win.mBaseLayer; |
| 829 | for (i=N-1; i>=0; i--) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 830 | if (localmWindows.get(i).mBaseLayer <= myLayer) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 831 | i++; |
| 832 | break; |
| 833 | } |
| 834 | } |
| 835 | if (i < 0) i = 0; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 836 | if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v( |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 837 | TAG, "Adding window " + win + " at " |
| 838 | + i + " of " + N); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 839 | localmWindows.add(i, win); |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 840 | mWindowsChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 841 | } |
| 842 | if (addToToken) { |
| 843 | token.windows.add(tokenWindowsPos, win); |
| 844 | } |
| 845 | |
| 846 | } else { |
| 847 | // Figure out this window's ordering relative to the window |
| 848 | // it is attached to. |
| 849 | final int NA = token.windows.size(); |
| 850 | final int sublayer = win.mSubLayer; |
| 851 | int largestSublayer = Integer.MIN_VALUE; |
| 852 | WindowState windowWithLargestSublayer = null; |
| 853 | for (i=0; i<NA; i++) { |
| 854 | WindowState w = token.windows.get(i); |
| 855 | final int wSublayer = w.mSubLayer; |
| 856 | if (wSublayer >= largestSublayer) { |
| 857 | largestSublayer = wSublayer; |
| 858 | windowWithLargestSublayer = w; |
| 859 | } |
| 860 | if (sublayer < 0) { |
| 861 | // For negative sublayers, we go below all windows |
| 862 | // in the same sublayer. |
| 863 | if (wSublayer >= sublayer) { |
| 864 | if (addToToken) { |
| 865 | token.windows.add(i, win); |
| 866 | } |
| 867 | placeWindowBefore( |
| 868 | wSublayer >= 0 ? attached : w, win); |
| 869 | break; |
| 870 | } |
| 871 | } else { |
| 872 | // For positive sublayers, we go above all windows |
| 873 | // in the same sublayer. |
| 874 | if (wSublayer > sublayer) { |
| 875 | if (addToToken) { |
| 876 | token.windows.add(i, win); |
| 877 | } |
| 878 | placeWindowBefore(w, win); |
| 879 | break; |
| 880 | } |
| 881 | } |
| 882 | } |
| 883 | if (i >= NA) { |
| 884 | if (addToToken) { |
| 885 | token.windows.add(win); |
| 886 | } |
| 887 | if (sublayer < 0) { |
| 888 | placeWindowBefore(attached, win); |
| 889 | } else { |
| 890 | placeWindowAfter(largestSublayer >= 0 |
| 891 | ? windowWithLargestSublayer |
| 892 | : attached, |
| 893 | win); |
| 894 | } |
| 895 | } |
| 896 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 897 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 898 | if (win.mAppToken != null && addToToken) { |
| 899 | win.mAppToken.allAppWindows.add(win); |
| 900 | } |
| 901 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 902 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 903 | static boolean canBeImeTarget(WindowState w) { |
| 904 | final int fl = w.mAttrs.flags |
| 905 | & (FLAG_NOT_FOCUSABLE|FLAG_ALT_FOCUSABLE_IM); |
| 906 | if (fl == 0 || fl == (FLAG_NOT_FOCUSABLE|FLAG_ALT_FOCUSABLE_IM)) { |
| 907 | return w.isVisibleOrAdding(); |
| 908 | } |
| 909 | return false; |
| 910 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 911 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 912 | int findDesiredInputMethodWindowIndexLocked(boolean willMove) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 913 | final ArrayList<WindowState> localmWindows = mWindows; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 914 | final int N = localmWindows.size(); |
| 915 | WindowState w = null; |
| 916 | int i = N; |
| 917 | while (i > 0) { |
| 918 | i--; |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 919 | w = localmWindows.get(i); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 920 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 921 | //Slog.i(TAG, "Checking window @" + i + " " + w + " fl=0x" |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 922 | // + Integer.toHexString(w.mAttrs.flags)); |
| 923 | if (canBeImeTarget(w)) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 924 | //Slog.i(TAG, "Putting input method here!"); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 925 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 926 | // Yet more tricksyness! If this window is a "starting" |
| 927 | // window, we do actually want to be on top of it, but |
| 928 | // it is not -really- where input will go. So if the caller |
| 929 | // is not actually looking to move the IME, look down below |
| 930 | // for a real window to target... |
| 931 | if (!willMove |
| 932 | && w.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING |
| 933 | && i > 0) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 934 | WindowState wb = localmWindows.get(i-1); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 935 | if (wb.mAppToken == w.mAppToken && canBeImeTarget(wb)) { |
| 936 | i--; |
| 937 | w = wb; |
| 938 | } |
| 939 | } |
| 940 | break; |
| 941 | } |
| 942 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 943 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 944 | mUpcomingInputMethodTarget = w; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 945 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 946 | 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] | 947 | + w + " willMove=" + willMove); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 948 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 949 | if (willMove && w != null) { |
| 950 | final WindowState curTarget = mInputMethodTarget; |
| 951 | if (curTarget != null && curTarget.mAppToken != null) { |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 952 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 953 | // Now some fun for dealing with window animations that |
| 954 | // modify the Z order. We need to look at all windows below |
| 955 | // the current target that are in this app, finding the highest |
| 956 | // visible one in layering. |
| 957 | AppWindowToken token = curTarget.mAppToken; |
| 958 | WindowState highestTarget = null; |
| 959 | int highestPos = 0; |
| 960 | if (token.animating || token.animation != null) { |
| 961 | int pos = 0; |
| 962 | pos = localmWindows.indexOf(curTarget); |
| 963 | while (pos >= 0) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 964 | WindowState win = localmWindows.get(pos); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 965 | if (win.mAppToken != token) { |
| 966 | break; |
| 967 | } |
| 968 | if (!win.mRemoved) { |
| 969 | if (highestTarget == null || win.mAnimLayer > |
| 970 | highestTarget.mAnimLayer) { |
| 971 | highestTarget = win; |
| 972 | highestPos = pos; |
| 973 | } |
| 974 | } |
| 975 | pos--; |
| 976 | } |
| 977 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 978 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 979 | if (highestTarget != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 980 | if (DEBUG_INPUT_METHOD) Slog.v(TAG, "mNextAppTransition=" |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 981 | + mNextAppTransition + " " + highestTarget |
| 982 | + " animating=" + highestTarget.isAnimating() |
| 983 | + " layer=" + highestTarget.mAnimLayer |
| 984 | + " new layer=" + w.mAnimLayer); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 985 | |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 986 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 987 | // If we are currently setting up for an animation, |
| 988 | // hold everything until we can find out what will happen. |
| 989 | mInputMethodTargetWaitingAnim = true; |
| 990 | mInputMethodTarget = highestTarget; |
| 991 | return highestPos + 1; |
| 992 | } else if (highestTarget.isAnimating() && |
| 993 | highestTarget.mAnimLayer > w.mAnimLayer) { |
| 994 | // If the window we are currently targeting is involved |
| 995 | // with an animation, and it is on top of the next target |
| 996 | // we will be over, then hold off on moving until |
| 997 | // that is done. |
| 998 | mInputMethodTarget = highestTarget; |
| 999 | return highestPos + 1; |
| 1000 | } |
| 1001 | } |
| 1002 | } |
| 1003 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1004 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1005 | //Slog.i(TAG, "Placing input method @" + (i+1)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1006 | if (w != null) { |
| 1007 | if (willMove) { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 1008 | if (DEBUG_INPUT_METHOD) { |
| 1009 | RuntimeException e = null; |
| 1010 | if (!HIDE_STACK_CRAWLS) { |
| 1011 | e = new RuntimeException(); |
| 1012 | e.fillInStackTrace(); |
| 1013 | } |
| 1014 | Slog.w(TAG, "Moving IM target from " |
| 1015 | + mInputMethodTarget + " to " + w, e); |
| 1016 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1017 | mInputMethodTarget = w; |
| 1018 | if (w.mAppToken != null) { |
| 1019 | setInputMethodAnimLayerAdjustment(w.mAppToken.animLayerAdjustment); |
| 1020 | } else { |
| 1021 | setInputMethodAnimLayerAdjustment(0); |
| 1022 | } |
| 1023 | } |
| 1024 | return i+1; |
| 1025 | } |
| 1026 | if (willMove) { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 1027 | if (DEBUG_INPUT_METHOD) { |
| 1028 | RuntimeException e = null; |
| 1029 | if (!HIDE_STACK_CRAWLS) { |
| 1030 | e = new RuntimeException(); |
| 1031 | e.fillInStackTrace(); |
| 1032 | } |
| 1033 | Slog.w(TAG, "Moving IM target from " |
| 1034 | + mInputMethodTarget + " to null", e); |
| 1035 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1036 | mInputMethodTarget = null; |
| 1037 | setInputMethodAnimLayerAdjustment(0); |
| 1038 | } |
| 1039 | return -1; |
| 1040 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1041 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1042 | void addInputMethodWindowToListLocked(WindowState win) { |
| 1043 | int pos = findDesiredInputMethodWindowIndexLocked(true); |
| 1044 | if (pos >= 0) { |
| 1045 | win.mTargetAppToken = mInputMethodTarget.mAppToken; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1046 | if (DEBUG_WINDOW_MOVEMENT) Slog.v( |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 1047 | TAG, "Adding input method window " + win + " at " + pos); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1048 | mWindows.add(pos, win); |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 1049 | mWindowsChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1050 | moveInputMethodDialogsLocked(pos+1); |
| 1051 | return; |
| 1052 | } |
| 1053 | win.mTargetAppToken = null; |
| 1054 | addWindowToListInOrderLocked(win, true); |
| 1055 | moveInputMethodDialogsLocked(pos); |
| 1056 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1057 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1058 | void setInputMethodAnimLayerAdjustment(int adj) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1059 | 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] | 1060 | mInputMethodAnimLayerAdjustment = adj; |
| 1061 | WindowState imw = mInputMethodWindow; |
| 1062 | if (imw != null) { |
| 1063 | imw.mAnimLayer = imw.mLayer + adj; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1064 | if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + imw |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1065 | + " anim layer: " + imw.mAnimLayer); |
| 1066 | int wi = imw.mChildWindows.size(); |
| 1067 | while (wi > 0) { |
| 1068 | wi--; |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1069 | WindowState cw = imw.mChildWindows.get(wi); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1070 | cw.mAnimLayer = cw.mLayer + adj; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1071 | if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + cw |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1072 | + " anim layer: " + cw.mAnimLayer); |
| 1073 | } |
| 1074 | } |
| 1075 | int di = mInputMethodDialogs.size(); |
| 1076 | while (di > 0) { |
| 1077 | di --; |
| 1078 | imw = mInputMethodDialogs.get(di); |
| 1079 | imw.mAnimLayer = imw.mLayer + adj; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1080 | if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + imw |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1081 | + " anim layer: " + imw.mAnimLayer); |
| 1082 | } |
| 1083 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1084 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1085 | private int tmpRemoveWindowLocked(int interestingPos, WindowState win) { |
| 1086 | int wpos = mWindows.indexOf(win); |
| 1087 | if (wpos >= 0) { |
| 1088 | if (wpos < interestingPos) interestingPos--; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1089 | 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] | 1090 | mWindows.remove(wpos); |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 1091 | mWindowsChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1092 | int NC = win.mChildWindows.size(); |
| 1093 | while (NC > 0) { |
| 1094 | NC--; |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1095 | WindowState cw = win.mChildWindows.get(NC); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1096 | int cpos = mWindows.indexOf(cw); |
| 1097 | if (cpos >= 0) { |
| 1098 | if (cpos < interestingPos) interestingPos--; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1099 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Temp removing child at " |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 1100 | + cpos + ": " + cw); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1101 | mWindows.remove(cpos); |
| 1102 | } |
| 1103 | } |
| 1104 | } |
| 1105 | return interestingPos; |
| 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 | private void reAddWindowToListInOrderLocked(WindowState win) { |
| 1109 | addWindowToListInOrderLocked(win, false); |
| 1110 | // This is a hack to get all of the child windows added as well |
| 1111 | // at the right position. Child windows should be rare and |
| 1112 | // this case should be rare, so it shouldn't be that big a deal. |
| 1113 | int wpos = mWindows.indexOf(win); |
| 1114 | if (wpos >= 0) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1115 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "ReAdd removing from " + wpos |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 1116 | + ": " + win); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1117 | mWindows.remove(wpos); |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 1118 | mWindowsChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1119 | reAddWindowLocked(wpos, win); |
| 1120 | } |
| 1121 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1122 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1123 | void logWindowList(String prefix) { |
| 1124 | int N = mWindows.size(); |
| 1125 | while (N > 0) { |
| 1126 | N--; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1127 | Slog.v(TAG, prefix + "#" + N + ": " + mWindows.get(N)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1128 | } |
| 1129 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1130 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1131 | void moveInputMethodDialogsLocked(int pos) { |
| 1132 | ArrayList<WindowState> dialogs = mInputMethodDialogs; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1133 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1134 | final int N = dialogs.size(); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1135 | 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] | 1136 | for (int i=0; i<N; i++) { |
| 1137 | pos = tmpRemoveWindowLocked(pos, dialogs.get(i)); |
| 1138 | } |
| 1139 | if (DEBUG_INPUT_METHOD) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1140 | Slog.v(TAG, "Window list w/pos=" + pos); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1141 | logWindowList(" "); |
| 1142 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1143 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1144 | if (pos >= 0) { |
| 1145 | final AppWindowToken targetAppToken = mInputMethodTarget.mAppToken; |
| 1146 | if (pos < mWindows.size()) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1147 | WindowState wp = mWindows.get(pos); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1148 | if (wp == mInputMethodWindow) { |
| 1149 | pos++; |
| 1150 | } |
| 1151 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1152 | 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] | 1153 | for (int i=0; i<N; i++) { |
| 1154 | WindowState win = dialogs.get(i); |
| 1155 | win.mTargetAppToken = targetAppToken; |
| 1156 | pos = reAddWindowLocked(pos, win); |
| 1157 | } |
| 1158 | if (DEBUG_INPUT_METHOD) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1159 | Slog.v(TAG, "Final window list:"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1160 | logWindowList(" "); |
| 1161 | } |
| 1162 | return; |
| 1163 | } |
| 1164 | for (int i=0; i<N; i++) { |
| 1165 | WindowState win = dialogs.get(i); |
| 1166 | win.mTargetAppToken = null; |
| 1167 | reAddWindowToListInOrderLocked(win); |
| 1168 | if (DEBUG_INPUT_METHOD) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1169 | Slog.v(TAG, "No IM target, final list:"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1170 | logWindowList(" "); |
| 1171 | } |
| 1172 | } |
| 1173 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1174 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1175 | boolean moveInputMethodWindowsIfNeededLocked(boolean needAssignLayers) { |
| 1176 | final WindowState imWin = mInputMethodWindow; |
| 1177 | final int DN = mInputMethodDialogs.size(); |
| 1178 | if (imWin == null && DN == 0) { |
| 1179 | return false; |
| 1180 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1181 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1182 | int imPos = findDesiredInputMethodWindowIndexLocked(true); |
| 1183 | if (imPos >= 0) { |
| 1184 | // In this case, the input method windows are to be placed |
| 1185 | // immediately above the window they are targeting. |
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 | // First check to see if the input method windows are already |
| 1188 | // located here, and contiguous. |
| 1189 | final int N = mWindows.size(); |
| 1190 | WindowState firstImWin = imPos < N |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1191 | ? mWindows.get(imPos) : null; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1192 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1193 | // Figure out the actual input method window that should be |
| 1194 | // at the bottom of their stack. |
| 1195 | WindowState baseImWin = imWin != null |
| 1196 | ? imWin : mInputMethodDialogs.get(0); |
| 1197 | if (baseImWin.mChildWindows.size() > 0) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1198 | WindowState cw = baseImWin.mChildWindows.get(0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1199 | if (cw.mSubLayer < 0) baseImWin = cw; |
| 1200 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1201 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1202 | if (firstImWin == baseImWin) { |
| 1203 | // The windows haven't moved... but are they still contiguous? |
| 1204 | // First find the top IM window. |
| 1205 | int pos = imPos+1; |
| 1206 | while (pos < N) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1207 | if (!(mWindows.get(pos)).mIsImWindow) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1208 | break; |
| 1209 | } |
| 1210 | pos++; |
| 1211 | } |
| 1212 | pos++; |
| 1213 | // Now there should be no more input method windows above. |
| 1214 | while (pos < N) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1215 | if ((mWindows.get(pos)).mIsImWindow) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1216 | break; |
| 1217 | } |
| 1218 | pos++; |
| 1219 | } |
| 1220 | if (pos >= N) { |
| 1221 | // All is good! |
| 1222 | return false; |
| 1223 | } |
| 1224 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1225 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1226 | if (imWin != null) { |
| 1227 | if (DEBUG_INPUT_METHOD) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1228 | Slog.v(TAG, "Moving IM from " + imPos); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1229 | logWindowList(" "); |
| 1230 | } |
| 1231 | imPos = tmpRemoveWindowLocked(imPos, imWin); |
| 1232 | if (DEBUG_INPUT_METHOD) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1233 | 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] | 1234 | logWindowList(" "); |
| 1235 | } |
| 1236 | imWin.mTargetAppToken = mInputMethodTarget.mAppToken; |
| 1237 | reAddWindowLocked(imPos, imWin); |
| 1238 | if (DEBUG_INPUT_METHOD) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1239 | Slog.v(TAG, "List after moving IM to " + imPos + ":"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1240 | logWindowList(" "); |
| 1241 | } |
| 1242 | if (DN > 0) moveInputMethodDialogsLocked(imPos+1); |
| 1243 | } else { |
| 1244 | moveInputMethodDialogsLocked(imPos); |
| 1245 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1246 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1247 | } else { |
| 1248 | // In this case, the input method windows go in a fixed layer, |
| 1249 | // because they aren't currently associated with a focus window. |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1250 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1251 | if (imWin != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1252 | 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] | 1253 | tmpRemoveWindowLocked(0, imWin); |
| 1254 | imWin.mTargetAppToken = null; |
| 1255 | reAddWindowToListInOrderLocked(imWin); |
| 1256 | if (DEBUG_INPUT_METHOD) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1257 | Slog.v(TAG, "List with no IM target:"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1258 | logWindowList(" "); |
| 1259 | } |
| 1260 | if (DN > 0) moveInputMethodDialogsLocked(-1);; |
| 1261 | } else { |
| 1262 | moveInputMethodDialogsLocked(-1);; |
| 1263 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1264 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1265 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1266 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1267 | if (needAssignLayers) { |
| 1268 | assignLayersLocked(); |
| 1269 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1270 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1271 | return true; |
| 1272 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1273 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1274 | void adjustInputMethodDialogsLocked() { |
| 1275 | moveInputMethodDialogsLocked(findDesiredInputMethodWindowIndexLocked(true)); |
| 1276 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1277 | |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 1278 | final boolean isWallpaperVisible(WindowState wallpaperTarget) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1279 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper vis: target obscured=" |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 1280 | + (wallpaperTarget != null ? Boolean.toString(wallpaperTarget.mObscured) : "??") |
| 1281 | + " anim=" + ((wallpaperTarget != null && wallpaperTarget.mAppToken != null) |
| 1282 | ? wallpaperTarget.mAppToken.animation : null) |
| 1283 | + " upper=" + mUpperWallpaperTarget |
| 1284 | + " lower=" + mLowerWallpaperTarget); |
| 1285 | return (wallpaperTarget != null |
| 1286 | && (!wallpaperTarget.mObscured || (wallpaperTarget.mAppToken != null |
| 1287 | && wallpaperTarget.mAppToken.animation != null))) |
| 1288 | || mUpperWallpaperTarget != null |
| 1289 | || mLowerWallpaperTarget != null; |
| 1290 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1291 | |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 1292 | static final int ADJUST_WALLPAPER_LAYERS_CHANGED = 1<<1; |
| 1293 | static final int ADJUST_WALLPAPER_VISIBILITY_CHANGED = 1<<2; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1294 | |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 1295 | int adjustWallpaperWindowsLocked() { |
| 1296 | int changed = 0; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1297 | |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1298 | final int dw = mDisplay.getWidth(); |
| 1299 | final int dh = mDisplay.getHeight(); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1300 | |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1301 | // First find top-most window that has asked to be on top of the |
| 1302 | // wallpaper; all wallpapers go behind it. |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1303 | final ArrayList<WindowState> localmWindows = mWindows; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1304 | int N = localmWindows.size(); |
| 1305 | WindowState w = null; |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1306 | WindowState foundW = null; |
| 1307 | int foundI = 0; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1308 | WindowState topCurW = null; |
| 1309 | int topCurI = 0; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1310 | int i = N; |
| 1311 | while (i > 0) { |
| 1312 | i--; |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1313 | w = localmWindows.get(i); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1314 | if ((w.mAttrs.type == WindowManager.LayoutParams.TYPE_WALLPAPER)) { |
| 1315 | if (topCurW == null) { |
| 1316 | topCurW = w; |
| 1317 | topCurI = i; |
| 1318 | } |
| 1319 | continue; |
| 1320 | } |
| 1321 | topCurW = null; |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1322 | if (w.mAppToken != null) { |
| 1323 | // If this window's app token is hidden and not animating, |
| 1324 | // it is of no interest to us. |
| 1325 | if (w.mAppToken.hidden && w.mAppToken.animation == null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1326 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1327 | "Skipping hidden or animating token: " + w); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1328 | topCurW = null; |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1329 | continue; |
| 1330 | } |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1331 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1332 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Win " + w + ": readyfordisplay=" |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1333 | + w.isReadyForDisplay() + " drawpending=" + w.mDrawPending |
| 1334 | + " commitdrawpending=" + w.mCommitDrawPending); |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1335 | if ((w.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0 && w.isReadyForDisplay() |
Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 1336 | && (mWallpaperTarget == w |
| 1337 | || (!w.mDrawPending && !w.mCommitDrawPending))) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1338 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1339 | "Found wallpaper activity: #" + i + "=" + w); |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1340 | foundW = w; |
| 1341 | foundI = i; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1342 | if (w == mWallpaperTarget && ((w.mAppToken != null |
| 1343 | && w.mAppToken.animation != null) |
| 1344 | || w.mAnimation != null)) { |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1345 | // The current wallpaper target is animating, so we'll |
| 1346 | // look behind it for another possible target and figure |
| 1347 | // out what is going on below. |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1348 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Win " + w |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1349 | + ": token animating, looking behind."); |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1350 | continue; |
| 1351 | } |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1352 | break; |
| 1353 | } |
| 1354 | } |
| 1355 | |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 1356 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1357 | // If we are currently waiting for an app transition, and either |
| 1358 | // the current target or the next target are involved with it, |
| 1359 | // then hold off on doing anything with the wallpaper. |
| 1360 | // Note that we are checking here for just whether the target |
| 1361 | // is part of an app token... which is potentially overly aggressive |
| 1362 | // (the app token may not be involved in the transition), but good |
| 1363 | // enough (we'll just wait until whatever transition is pending |
| 1364 | // executes). |
| 1365 | if (mWallpaperTarget != null && mWallpaperTarget.mAppToken != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1366 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1367 | "Wallpaper not changing: waiting for app anim in current target"); |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 1368 | return 0; |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1369 | } |
| 1370 | if (foundW != null && foundW.mAppToken != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1371 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1372 | "Wallpaper not changing: waiting for app anim in found target"); |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 1373 | return 0; |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1374 | } |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1375 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1376 | |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1377 | if (mWallpaperTarget != foundW) { |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1378 | if (DEBUG_WALLPAPER) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1379 | Slog.v(TAG, "New wallpaper target: " + foundW |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1380 | + " oldTarget: " + mWallpaperTarget); |
| 1381 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1382 | |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1383 | mLowerWallpaperTarget = null; |
| 1384 | mUpperWallpaperTarget = null; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1385 | |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1386 | WindowState oldW = mWallpaperTarget; |
| 1387 | mWallpaperTarget = foundW; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1388 | |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1389 | // Now what is happening... if the current and new targets are |
| 1390 | // animating, then we are in our super special mode! |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1391 | if (foundW != null && oldW != null) { |
| 1392 | boolean oldAnim = oldW.mAnimation != null |
| 1393 | || (oldW.mAppToken != null && oldW.mAppToken.animation != null); |
| 1394 | boolean foundAnim = foundW.mAnimation != null |
| 1395 | || (foundW.mAppToken != null && foundW.mAppToken.animation != null); |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1396 | if (DEBUG_WALLPAPER) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1397 | Slog.v(TAG, "New animation: " + foundAnim |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1398 | + " old animation: " + oldAnim); |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1399 | } |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1400 | if (foundAnim && oldAnim) { |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1401 | int oldI = localmWindows.indexOf(oldW); |
| 1402 | if (DEBUG_WALLPAPER) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1403 | Slog.v(TAG, "New i: " + foundI + " old i: " + oldI); |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1404 | } |
| 1405 | if (oldI >= 0) { |
| 1406 | if (DEBUG_WALLPAPER) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1407 | Slog.v(TAG, "Animating wallpapers: old#" + oldI |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1408 | + "=" + oldW + "; new#" + foundI |
| 1409 | + "=" + foundW); |
| 1410 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1411 | |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1412 | // Set the new target correctly. |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1413 | if (foundW.mAppToken != null && foundW.mAppToken.hiddenRequested) { |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1414 | if (DEBUG_WALLPAPER) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1415 | Slog.v(TAG, "Old wallpaper still the target."); |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1416 | } |
| 1417 | mWallpaperTarget = oldW; |
| 1418 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1419 | |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1420 | // Now set the upper and lower wallpaper targets |
| 1421 | // correctly, and make sure that we are positioning |
| 1422 | // the wallpaper below the lower. |
| 1423 | if (foundI > oldI) { |
| 1424 | // The new target is on top of the old one. |
| 1425 | if (DEBUG_WALLPAPER) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1426 | Slog.v(TAG, "Found target above old target."); |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1427 | } |
| 1428 | mUpperWallpaperTarget = foundW; |
| 1429 | mLowerWallpaperTarget = oldW; |
| 1430 | foundW = oldW; |
| 1431 | foundI = oldI; |
| 1432 | } else { |
| 1433 | // The new target is below the old one. |
| 1434 | if (DEBUG_WALLPAPER) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1435 | Slog.v(TAG, "Found target below old target."); |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1436 | } |
| 1437 | mUpperWallpaperTarget = oldW; |
| 1438 | mLowerWallpaperTarget = foundW; |
| 1439 | } |
| 1440 | } |
| 1441 | } |
| 1442 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1443 | |
Dianne Hackborn | 6b1cb35 | 2009-09-28 18:27:26 -0700 | [diff] [blame] | 1444 | } else if (mLowerWallpaperTarget != null) { |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1445 | // Is it time to stop animating? |
Dianne Hackborn | 6b1cb35 | 2009-09-28 18:27:26 -0700 | [diff] [blame] | 1446 | boolean lowerAnimating = mLowerWallpaperTarget.mAnimation != null |
| 1447 | || (mLowerWallpaperTarget.mAppToken != null |
| 1448 | && mLowerWallpaperTarget.mAppToken.animation != null); |
| 1449 | boolean upperAnimating = mUpperWallpaperTarget.mAnimation != null |
| 1450 | || (mUpperWallpaperTarget.mAppToken != null |
| 1451 | && mUpperWallpaperTarget.mAppToken.animation != null); |
| 1452 | if (!lowerAnimating || !upperAnimating) { |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1453 | if (DEBUG_WALLPAPER) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1454 | Slog.v(TAG, "No longer animating wallpaper targets!"); |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1455 | } |
| 1456 | mLowerWallpaperTarget = null; |
| 1457 | mUpperWallpaperTarget = null; |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1458 | } |
| 1459 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1460 | |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1461 | boolean visible = foundW != null; |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 1462 | if (visible) { |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1463 | // The window is visible to the compositor... but is it visible |
| 1464 | // to the user? That is what the wallpaper cares about. |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 1465 | visible = isWallpaperVisible(foundW); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1466 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper visibility: " + visible); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1467 | |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1468 | // If the wallpaper target is animating, we may need to copy |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1469 | // its layer adjustment. Only do this if we are not transfering |
| 1470 | // between two wallpaper targets. |
| 1471 | mWallpaperAnimLayerAdjustment = |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1472 | (mLowerWallpaperTarget == null && foundW.mAppToken != null) |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1473 | ? foundW.mAppToken.animLayerAdjustment : 0; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1474 | |
Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 1475 | final int maxLayer = mPolicy.getMaxWallpaperLayer() |
| 1476 | * TYPE_LAYER_MULTIPLIER |
| 1477 | + TYPE_LAYER_OFFSET; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1478 | |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1479 | // Now w is the window we are supposed to be behind... but we |
| 1480 | // 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] | 1481 | // AND any starting window associated with it, AND below the |
| 1482 | // maximum layer the policy allows for wallpapers. |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1483 | while (foundI > 0) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1484 | WindowState wb = localmWindows.get(foundI-1); |
Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 1485 | if (wb.mBaseLayer < maxLayer && |
| 1486 | wb.mAttachedWindow != foundW && |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1487 | (wb.mAttrs.type != TYPE_APPLICATION_STARTING || |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1488 | wb.mToken != foundW.mToken)) { |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1489 | // This window is not related to the previous one in any |
| 1490 | // interesting way, so stop here. |
| 1491 | break; |
| 1492 | } |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1493 | foundW = wb; |
| 1494 | foundI--; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1495 | } |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 1496 | } else { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1497 | if (DEBUG_WALLPAPER) Slog.v(TAG, "No wallpaper target"); |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1498 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1499 | |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1500 | if (foundW == null && topCurW != null) { |
| 1501 | // There is no wallpaper target, so it goes at the bottom. |
| 1502 | // We will assume it is the same place as last time, if known. |
| 1503 | foundW = topCurW; |
| 1504 | foundI = topCurI+1; |
| 1505 | } else { |
| 1506 | // Okay i is the position immediately above the wallpaper. Look at |
| 1507 | // what is below it for later. |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1508 | foundW = foundI > 0 ? localmWindows.get(foundI-1) : null; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1509 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1510 | |
Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 1511 | if (visible) { |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1512 | if (mWallpaperTarget.mWallpaperX >= 0) { |
| 1513 | mLastWallpaperX = mWallpaperTarget.mWallpaperX; |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 1514 | mLastWallpaperXStep = mWallpaperTarget.mWallpaperXStep; |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1515 | } |
| 1516 | if (mWallpaperTarget.mWallpaperY >= 0) { |
| 1517 | mLastWallpaperY = mWallpaperTarget.mWallpaperY; |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 1518 | mLastWallpaperYStep = mWallpaperTarget.mWallpaperYStep; |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1519 | } |
Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 1520 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1521 | |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1522 | // Start stepping backwards from here, ensuring that our wallpaper windows |
| 1523 | // are correctly placed. |
| 1524 | int curTokenIndex = mWallpaperTokens.size(); |
| 1525 | while (curTokenIndex > 0) { |
| 1526 | curTokenIndex--; |
| 1527 | WindowToken token = mWallpaperTokens.get(curTokenIndex); |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 1528 | if (token.hidden == visible) { |
| 1529 | changed |= ADJUST_WALLPAPER_VISIBILITY_CHANGED; |
| 1530 | token.hidden = !visible; |
| 1531 | // Need to do a layout to ensure the wallpaper now has the |
| 1532 | // correct size. |
| 1533 | mLayoutNeeded = true; |
| 1534 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1535 | |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1536 | int curWallpaperIndex = token.windows.size(); |
| 1537 | while (curWallpaperIndex > 0) { |
| 1538 | curWallpaperIndex--; |
| 1539 | WindowState wallpaper = token.windows.get(curWallpaperIndex); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1540 | |
Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 1541 | if (visible) { |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1542 | updateWallpaperOffsetLocked(wallpaper, dw, dh, false); |
Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 1543 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1544 | |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 1545 | // First, make sure the client has the current visibility |
| 1546 | // state. |
| 1547 | if (wallpaper.mWallpaperVisible != visible) { |
| 1548 | wallpaper.mWallpaperVisible = visible; |
| 1549 | try { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1550 | if (DEBUG_VISIBILITY || DEBUG_WALLPAPER) Slog.v(TAG, |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 1551 | "Setting visibility of wallpaper " + wallpaper |
| 1552 | + ": " + visible); |
| 1553 | wallpaper.mClient.dispatchAppVisibility(visible); |
| 1554 | } catch (RemoteException e) { |
| 1555 | } |
| 1556 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1557 | |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 1558 | wallpaper.mAnimLayer = wallpaper.mLayer + mWallpaperAnimLayerAdjustment; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1559 | if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper win " |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1560 | + wallpaper + " anim layer: " + wallpaper.mAnimLayer); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1561 | |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1562 | // First, if this window is at the current index, then all |
| 1563 | // is well. |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1564 | if (wallpaper == foundW) { |
| 1565 | foundI--; |
| 1566 | foundW = foundI > 0 |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1567 | ? localmWindows.get(foundI-1) : null; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1568 | continue; |
| 1569 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1570 | |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1571 | // The window didn't match... the current wallpaper window, |
| 1572 | // wherever it is, is in the wrong place, so make sure it is |
| 1573 | // not in the list. |
| 1574 | int oldIndex = localmWindows.indexOf(wallpaper); |
| 1575 | if (oldIndex >= 0) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1576 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Wallpaper removing at " |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 1577 | + oldIndex + ": " + wallpaper); |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1578 | localmWindows.remove(oldIndex); |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 1579 | mWindowsChanged = true; |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1580 | if (oldIndex < foundI) { |
| 1581 | foundI--; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1582 | } |
| 1583 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1584 | |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1585 | // Now stick it in. |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1586 | if (DEBUG_WALLPAPER || DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 1587 | "Moving wallpaper " + wallpaper |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1588 | + " from " + oldIndex + " to " + foundI); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1589 | |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1590 | localmWindows.add(foundI, wallpaper); |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 1591 | mWindowsChanged = true; |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 1592 | changed |= ADJUST_WALLPAPER_LAYERS_CHANGED; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1593 | } |
| 1594 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1595 | |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1596 | return changed; |
| 1597 | } |
| 1598 | |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 1599 | void setWallpaperAnimLayerAdjustmentLocked(int adj) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1600 | if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG, |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1601 | "Setting wallpaper layer adj to " + adj); |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 1602 | mWallpaperAnimLayerAdjustment = adj; |
| 1603 | int curTokenIndex = mWallpaperTokens.size(); |
| 1604 | while (curTokenIndex > 0) { |
| 1605 | curTokenIndex--; |
| 1606 | WindowToken token = mWallpaperTokens.get(curTokenIndex); |
| 1607 | int curWallpaperIndex = token.windows.size(); |
| 1608 | while (curWallpaperIndex > 0) { |
| 1609 | curWallpaperIndex--; |
| 1610 | WindowState wallpaper = token.windows.get(curWallpaperIndex); |
| 1611 | wallpaper.mAnimLayer = wallpaper.mLayer + adj; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1612 | if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper win " |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1613 | + wallpaper + " anim layer: " + wallpaper.mAnimLayer); |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 1614 | } |
| 1615 | } |
| 1616 | } |
| 1617 | |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1618 | boolean updateWallpaperOffsetLocked(WindowState wallpaperWin, int dw, int dh, |
| 1619 | boolean sync) { |
Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 1620 | boolean changed = false; |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1621 | boolean rawChanged = false; |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1622 | float wpx = mLastWallpaperX >= 0 ? mLastWallpaperX : 0.5f; |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 1623 | float wpxs = mLastWallpaperXStep >= 0 ? mLastWallpaperXStep : -1.0f; |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1624 | int availw = wallpaperWin.mFrame.right-wallpaperWin.mFrame.left-dw; |
| 1625 | int offset = availw > 0 ? -(int)(availw*wpx+.5f) : 0; |
| 1626 | changed = wallpaperWin.mXOffset != offset; |
| 1627 | if (changed) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1628 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Update wallpaper " |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1629 | + wallpaperWin + " x: " + offset); |
| 1630 | wallpaperWin.mXOffset = offset; |
| 1631 | } |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 1632 | if (wallpaperWin.mWallpaperX != wpx || wallpaperWin.mWallpaperXStep != wpxs) { |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1633 | wallpaperWin.mWallpaperX = wpx; |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 1634 | wallpaperWin.mWallpaperXStep = wpxs; |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1635 | rawChanged = true; |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 1636 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1637 | |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1638 | float wpy = mLastWallpaperY >= 0 ? mLastWallpaperY : 0.5f; |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 1639 | float wpys = mLastWallpaperYStep >= 0 ? mLastWallpaperYStep : -1.0f; |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1640 | int availh = wallpaperWin.mFrame.bottom-wallpaperWin.mFrame.top-dh; |
| 1641 | offset = availh > 0 ? -(int)(availh*wpy+.5f) : 0; |
| 1642 | if (wallpaperWin.mYOffset != offset) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1643 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Update wallpaper " |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1644 | + wallpaperWin + " y: " + offset); |
| 1645 | changed = true; |
| 1646 | wallpaperWin.mYOffset = offset; |
| 1647 | } |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 1648 | if (wallpaperWin.mWallpaperY != wpy || wallpaperWin.mWallpaperYStep != wpys) { |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1649 | wallpaperWin.mWallpaperY = wpy; |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 1650 | wallpaperWin.mWallpaperYStep = wpys; |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1651 | rawChanged = true; |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 1652 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1653 | |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1654 | if (rawChanged) { |
Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 1655 | try { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1656 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Report new wp offset " |
Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 1657 | + wallpaperWin + " x=" + wallpaperWin.mWallpaperX |
| 1658 | + " y=" + wallpaperWin.mWallpaperY); |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1659 | if (sync) { |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 1660 | mWaitingOnWallpaper = wallpaperWin; |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1661 | } |
Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 1662 | wallpaperWin.mClient.dispatchWallpaperOffsets( |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 1663 | wallpaperWin.mWallpaperX, wallpaperWin.mWallpaperY, |
| 1664 | wallpaperWin.mWallpaperXStep, wallpaperWin.mWallpaperYStep, sync); |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1665 | if (sync) { |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 1666 | if (mWaitingOnWallpaper != null) { |
| 1667 | long start = SystemClock.uptimeMillis(); |
| 1668 | if ((mLastWallpaperTimeoutTime+WALLPAPER_TIMEOUT_RECOVERY) |
| 1669 | < start) { |
| 1670 | try { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1671 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 1672 | "Waiting for offset complete..."); |
| 1673 | mWindowMap.wait(WALLPAPER_TIMEOUT); |
| 1674 | } catch (InterruptedException e) { |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1675 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1676 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Offset complete!"); |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 1677 | if ((start+WALLPAPER_TIMEOUT) |
| 1678 | < SystemClock.uptimeMillis()) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1679 | Slog.i(TAG, "Timeout waiting for wallpaper to offset: " |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 1680 | + wallpaperWin); |
| 1681 | mLastWallpaperTimeoutTime = start; |
| 1682 | } |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1683 | } |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 1684 | mWaitingOnWallpaper = null; |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1685 | } |
| 1686 | } |
Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 1687 | } catch (RemoteException e) { |
| 1688 | } |
| 1689 | } |
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 | return changed; |
| 1692 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1693 | |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1694 | void wallpaperOffsetsComplete(IBinder window) { |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 1695 | synchronized (mWindowMap) { |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1696 | if (mWaitingOnWallpaper != null && |
| 1697 | mWaitingOnWallpaper.mClient.asBinder() == window) { |
| 1698 | mWaitingOnWallpaper = null; |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 1699 | mWindowMap.notifyAll(); |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1700 | } |
| 1701 | } |
| 1702 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1703 | |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1704 | boolean updateWallpaperOffsetLocked(WindowState changingTarget, boolean sync) { |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 1705 | final int dw = mDisplay.getWidth(); |
| 1706 | final int dh = mDisplay.getHeight(); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1707 | |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 1708 | boolean changed = false; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1709 | |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 1710 | WindowState target = mWallpaperTarget; |
| 1711 | if (target != null) { |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1712 | if (target.mWallpaperX >= 0) { |
| 1713 | mLastWallpaperX = target.mWallpaperX; |
| 1714 | } else if (changingTarget.mWallpaperX >= 0) { |
| 1715 | mLastWallpaperX = changingTarget.mWallpaperX; |
| 1716 | } |
| 1717 | if (target.mWallpaperY >= 0) { |
| 1718 | mLastWallpaperY = target.mWallpaperY; |
| 1719 | } else if (changingTarget.mWallpaperY >= 0) { |
| 1720 | mLastWallpaperY = changingTarget.mWallpaperY; |
| 1721 | } |
| 1722 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1723 | |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1724 | int curTokenIndex = mWallpaperTokens.size(); |
| 1725 | while (curTokenIndex > 0) { |
| 1726 | curTokenIndex--; |
| 1727 | WindowToken token = mWallpaperTokens.get(curTokenIndex); |
| 1728 | int curWallpaperIndex = token.windows.size(); |
| 1729 | while (curWallpaperIndex > 0) { |
| 1730 | curWallpaperIndex--; |
| 1731 | WindowState wallpaper = token.windows.get(curWallpaperIndex); |
| 1732 | if (updateWallpaperOffsetLocked(wallpaper, dw, dh, sync)) { |
| 1733 | wallpaper.computeShownFrameLocked(); |
| 1734 | changed = true; |
| 1735 | // We only want to be synchronous with one wallpaper. |
| 1736 | sync = false; |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 1737 | } |
| 1738 | } |
| 1739 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1740 | |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 1741 | return changed; |
| 1742 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1743 | |
Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 1744 | void updateWallpaperVisibilityLocked() { |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 1745 | final boolean visible = isWallpaperVisible(mWallpaperTarget); |
Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 1746 | final int dw = mDisplay.getWidth(); |
| 1747 | final int dh = mDisplay.getHeight(); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1748 | |
Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 1749 | int curTokenIndex = mWallpaperTokens.size(); |
| 1750 | while (curTokenIndex > 0) { |
| 1751 | curTokenIndex--; |
| 1752 | WindowToken token = mWallpaperTokens.get(curTokenIndex); |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 1753 | if (token.hidden == visible) { |
| 1754 | token.hidden = !visible; |
| 1755 | // Need to do a layout to ensure the wallpaper now has the |
| 1756 | // correct size. |
| 1757 | mLayoutNeeded = true; |
| 1758 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1759 | |
Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 1760 | int curWallpaperIndex = token.windows.size(); |
| 1761 | while (curWallpaperIndex > 0) { |
| 1762 | curWallpaperIndex--; |
| 1763 | WindowState wallpaper = token.windows.get(curWallpaperIndex); |
| 1764 | if (visible) { |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1765 | updateWallpaperOffsetLocked(wallpaper, dw, dh, false); |
Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 1766 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1767 | |
Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 1768 | if (wallpaper.mWallpaperVisible != visible) { |
| 1769 | wallpaper.mWallpaperVisible = visible; |
| 1770 | try { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1771 | if (DEBUG_VISIBILITY || DEBUG_WALLPAPER) Slog.v(TAG, |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 1772 | "Updating visibility of wallpaper " + wallpaper |
Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 1773 | + ": " + visible); |
| 1774 | wallpaper.mClient.dispatchAppVisibility(visible); |
| 1775 | } catch (RemoteException e) { |
| 1776 | } |
| 1777 | } |
| 1778 | } |
| 1779 | } |
| 1780 | } |
Dianne Hackborn | 90d2db3 | 2010-02-11 22:19:06 -0800 | [diff] [blame] | 1781 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1782 | public int addWindow(Session session, IWindow client, |
| 1783 | WindowManager.LayoutParams attrs, int viewVisibility, |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1784 | Rect outContentInsets, InputChannel outInputChannel) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1785 | int res = mPolicy.checkAddPermission(attrs); |
| 1786 | if (res != WindowManagerImpl.ADD_OKAY) { |
| 1787 | return res; |
| 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 | boolean reportNewConfig = false; |
| 1791 | WindowState attachedWindow = null; |
| 1792 | WindowState win = null; |
Dianne Hackborn | 5132b37 | 2010-07-29 12:51:35 -0700 | [diff] [blame^] | 1793 | long origId; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1794 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1795 | synchronized(mWindowMap) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1796 | if (mDisplay == null) { |
Dianne Hackborn | 5132b37 | 2010-07-29 12:51:35 -0700 | [diff] [blame^] | 1797 | throw new IllegalStateException("Display has not been initialialized"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1798 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1799 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1800 | if (mWindowMap.containsKey(client.asBinder())) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1801 | Slog.w(TAG, "Window " + client + " is already added"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1802 | return WindowManagerImpl.ADD_DUPLICATE_ADD; |
| 1803 | } |
| 1804 | |
| 1805 | if (attrs.type >= FIRST_SUB_WINDOW && attrs.type <= LAST_SUB_WINDOW) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 1806 | attachedWindow = windowForClientLocked(null, attrs.token, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1807 | if (attachedWindow == null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1808 | 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] | 1809 | + attrs.token + ". Aborting."); |
| 1810 | return WindowManagerImpl.ADD_BAD_SUBWINDOW_TOKEN; |
| 1811 | } |
| 1812 | if (attachedWindow.mAttrs.type >= FIRST_SUB_WINDOW |
| 1813 | && attachedWindow.mAttrs.type <= LAST_SUB_WINDOW) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1814 | 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] | 1815 | + attrs.token + ". Aborting."); |
| 1816 | return WindowManagerImpl.ADD_BAD_SUBWINDOW_TOKEN; |
| 1817 | } |
| 1818 | } |
| 1819 | |
| 1820 | boolean addToken = false; |
| 1821 | WindowToken token = mTokenMap.get(attrs.token); |
| 1822 | if (token == null) { |
| 1823 | if (attrs.type >= FIRST_APPLICATION_WINDOW |
| 1824 | && attrs.type <= LAST_APPLICATION_WINDOW) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1825 | 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] | 1826 | + attrs.token + ". Aborting."); |
| 1827 | return WindowManagerImpl.ADD_BAD_APP_TOKEN; |
| 1828 | } |
| 1829 | if (attrs.type == TYPE_INPUT_METHOD) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1830 | 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] | 1831 | + attrs.token + ". Aborting."); |
| 1832 | return WindowManagerImpl.ADD_BAD_APP_TOKEN; |
| 1833 | } |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1834 | if (attrs.type == TYPE_WALLPAPER) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1835 | Slog.w(TAG, "Attempted to add wallpaper window with unknown token " |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1836 | + attrs.token + ". Aborting."); |
| 1837 | return WindowManagerImpl.ADD_BAD_APP_TOKEN; |
| 1838 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1839 | token = new WindowToken(attrs.token, -1, false); |
| 1840 | addToken = true; |
| 1841 | } else if (attrs.type >= FIRST_APPLICATION_WINDOW |
| 1842 | && attrs.type <= LAST_APPLICATION_WINDOW) { |
| 1843 | AppWindowToken atoken = token.appWindowToken; |
| 1844 | if (atoken == null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1845 | 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] | 1846 | + token + ". Aborting."); |
| 1847 | return WindowManagerImpl.ADD_NOT_APP_TOKEN; |
| 1848 | } else if (atoken.removed) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1849 | 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] | 1850 | + token + ". Aborting."); |
| 1851 | return WindowManagerImpl.ADD_APP_EXITING; |
| 1852 | } |
| 1853 | if (attrs.type == TYPE_APPLICATION_STARTING && atoken.firstWindowDrawn) { |
| 1854 | // No need for this guy! |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1855 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1856 | TAG, "**** NO NEED TO START: " + attrs.getTitle()); |
| 1857 | return WindowManagerImpl.ADD_STARTING_NOT_NEEDED; |
| 1858 | } |
| 1859 | } else if (attrs.type == TYPE_INPUT_METHOD) { |
| 1860 | if (token.windowType != TYPE_INPUT_METHOD) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1861 | 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] | 1862 | + attrs.token + ". Aborting."); |
| 1863 | return WindowManagerImpl.ADD_BAD_APP_TOKEN; |
| 1864 | } |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1865 | } else if (attrs.type == TYPE_WALLPAPER) { |
| 1866 | if (token.windowType != TYPE_WALLPAPER) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1867 | Slog.w(TAG, "Attempted to add wallpaper window with bad token " |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1868 | + attrs.token + ". Aborting."); |
| 1869 | return WindowManagerImpl.ADD_BAD_APP_TOKEN; |
| 1870 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1871 | } |
| 1872 | |
| 1873 | win = new WindowState(session, client, token, |
| 1874 | attachedWindow, attrs, viewVisibility); |
| 1875 | if (win.mDeathRecipient == null) { |
| 1876 | // Client has apparently died, so there is no reason to |
| 1877 | // continue. |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1878 | Slog.w(TAG, "Adding window client " + client.asBinder() |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1879 | + " that is dead, aborting."); |
| 1880 | return WindowManagerImpl.ADD_APP_EXITING; |
| 1881 | } |
| 1882 | |
| 1883 | mPolicy.adjustWindowParamsLw(win.mAttrs); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1884 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1885 | res = mPolicy.prepareAddWindowLw(win, attrs); |
| 1886 | if (res != WindowManagerImpl.ADD_OKAY) { |
| 1887 | return res; |
| 1888 | } |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1889 | |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 1890 | if (outInputChannel != null) { |
| 1891 | String name = win.makeInputChannelName(); |
| 1892 | InputChannel[] inputChannels = InputChannel.openInputChannelPair(name); |
| 1893 | win.mInputChannel = inputChannels[0]; |
| 1894 | inputChannels[1].transferToBinderOutParameter(outInputChannel); |
| 1895 | |
| 1896 | mInputManager.registerInputChannel(win.mInputChannel); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1897 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1898 | |
| 1899 | // From now on, no exceptions or errors allowed! |
| 1900 | |
| 1901 | res = WindowManagerImpl.ADD_OKAY; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1902 | |
Dianne Hackborn | 5132b37 | 2010-07-29 12:51:35 -0700 | [diff] [blame^] | 1903 | origId = Binder.clearCallingIdentity(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1904 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1905 | if (addToken) { |
| 1906 | mTokenMap.put(attrs.token, token); |
| 1907 | mTokenList.add(token); |
| 1908 | } |
| 1909 | win.attach(); |
| 1910 | mWindowMap.put(client.asBinder(), win); |
| 1911 | |
| 1912 | if (attrs.type == TYPE_APPLICATION_STARTING && |
| 1913 | token.appWindowToken != null) { |
| 1914 | token.appWindowToken.startingWindow = win; |
| 1915 | } |
| 1916 | |
| 1917 | boolean imMayMove = true; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1918 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1919 | if (attrs.type == TYPE_INPUT_METHOD) { |
| 1920 | mInputMethodWindow = win; |
| 1921 | addInputMethodWindowToListLocked(win); |
| 1922 | imMayMove = false; |
| 1923 | } else if (attrs.type == TYPE_INPUT_METHOD_DIALOG) { |
| 1924 | mInputMethodDialogs.add(win); |
| 1925 | addWindowToListInOrderLocked(win, true); |
| 1926 | adjustInputMethodDialogsLocked(); |
| 1927 | imMayMove = false; |
| 1928 | } else { |
| 1929 | addWindowToListInOrderLocked(win, true); |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1930 | if (attrs.type == TYPE_WALLPAPER) { |
| 1931 | mLastWallpaperTimeoutTime = 0; |
| 1932 | adjustWallpaperWindowsLocked(); |
| 1933 | } else if ((attrs.flags&FLAG_SHOW_WALLPAPER) != 0) { |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1934 | adjustWallpaperWindowsLocked(); |
| 1935 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1936 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1937 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1938 | win.mEnterAnimationPending = true; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1939 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1940 | mPolicy.getContentInsetHintLw(attrs, outContentInsets); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1941 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1942 | if (mInTouchMode) { |
| 1943 | res |= WindowManagerImpl.ADD_FLAG_IN_TOUCH_MODE; |
| 1944 | } |
| 1945 | if (win == null || win.mAppToken == null || !win.mAppToken.clientHidden) { |
| 1946 | res |= WindowManagerImpl.ADD_FLAG_APP_VISIBLE; |
| 1947 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1948 | |
The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 1949 | boolean focusChanged = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1950 | if (win.canReceiveKeys()) { |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 1951 | focusChanged = updateFocusedWindowLocked(UPDATE_FOCUS_WILL_ASSIGN_LAYERS); |
| 1952 | if (focusChanged) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1953 | imMayMove = false; |
| 1954 | } |
| 1955 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1956 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1957 | if (imMayMove) { |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1958 | moveInputMethodWindowsIfNeededLocked(false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1959 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1960 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1961 | assignLayersLocked(); |
| 1962 | // Don't do layout here, the window must call |
| 1963 | // relayout to be displayed, so we'll do it there. |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1964 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1965 | //dump(); |
| 1966 | |
The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 1967 | if (focusChanged) { |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 1968 | finishUpdateFocusedWindowAfterAssignLayersLocked(); |
The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 1969 | } |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 1970 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1971 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1972 | TAG, "New client " + client.asBinder() |
| 1973 | + ": window=" + win); |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 1974 | |
| 1975 | if (win.isVisibleOrAdding() && updateOrientationFromAppTokensLocked()) { |
| 1976 | reportNewConfig = true; |
| 1977 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1978 | } |
| 1979 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1980 | if (reportNewConfig) { |
| 1981 | sendNewConfiguration(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1982 | } |
Dianne Hackborn | 5132b37 | 2010-07-29 12:51:35 -0700 | [diff] [blame^] | 1983 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1984 | Binder.restoreCallingIdentity(origId); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1985 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1986 | return res; |
| 1987 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1988 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1989 | public void removeWindow(Session session, IWindow client) { |
| 1990 | synchronized(mWindowMap) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 1991 | WindowState win = windowForClientLocked(session, client, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1992 | if (win == null) { |
| 1993 | return; |
| 1994 | } |
| 1995 | removeWindowLocked(session, win); |
| 1996 | } |
| 1997 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1998 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1999 | public void removeWindowLocked(Session session, WindowState win) { |
| 2000 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2001 | if (localLOGV || DEBUG_FOCUS) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2002 | TAG, "Remove " + win + " client=" |
| 2003 | + Integer.toHexString(System.identityHashCode( |
| 2004 | win.mClient.asBinder())) |
| 2005 | + ", surface=" + win.mSurface); |
| 2006 | |
| 2007 | final long origId = Binder.clearCallingIdentity(); |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 2008 | |
| 2009 | win.disposeInputChannel(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2010 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2011 | if (DEBUG_APP_TRANSITIONS) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2012 | TAG, "Remove " + win + ": mSurface=" + win.mSurface |
| 2013 | + " mExiting=" + win.mExiting |
| 2014 | + " isAnimating=" + win.isAnimating() |
| 2015 | + " app-animation=" |
| 2016 | + (win.mAppToken != null ? win.mAppToken.animation : null) |
| 2017 | + " inPendingTransaction=" |
| 2018 | + (win.mAppToken != null ? win.mAppToken.inPendingTransaction : false) |
| 2019 | + " mDisplayFrozen=" + mDisplayFrozen); |
| 2020 | // Visibility of the removed window. Will be used later to update orientation later on. |
| 2021 | boolean wasVisible = false; |
| 2022 | // First, see if we need to run an animation. If we do, we have |
| 2023 | // to hold off on removing the window until the animation is done. |
| 2024 | // If the display is frozen, just remove immediately, since the |
| 2025 | // animation wouldn't be seen. |
Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 2026 | if (win.mSurface != null && !mDisplayFrozen && mPolicy.isScreenOn()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2027 | // If we are not currently running the exit animation, we |
| 2028 | // need to see about starting one. |
| 2029 | if (wasVisible=win.isWinVisibleLw()) { |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2030 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2031 | int transit = WindowManagerPolicy.TRANSIT_EXIT; |
| 2032 | if (win.getAttrs().type == TYPE_APPLICATION_STARTING) { |
| 2033 | transit = WindowManagerPolicy.TRANSIT_PREVIEW_DONE; |
| 2034 | } |
| 2035 | // Try starting an animation. |
| 2036 | if (applyAnimationLocked(win, transit, false)) { |
| 2037 | win.mExiting = true; |
| 2038 | } |
| 2039 | } |
| 2040 | if (win.mExiting || win.isAnimating()) { |
| 2041 | // The exit animation is running... wait for it! |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2042 | //Slog.i(TAG, "*** Running exit animation..."); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2043 | win.mExiting = true; |
| 2044 | win.mRemoveOnExit = true; |
| 2045 | mLayoutNeeded = true; |
| 2046 | updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES); |
| 2047 | performLayoutAndPlaceSurfacesLocked(); |
| 2048 | if (win.mAppToken != null) { |
| 2049 | win.mAppToken.updateReportedVisibilityLocked(); |
| 2050 | } |
| 2051 | //dump(); |
| 2052 | Binder.restoreCallingIdentity(origId); |
| 2053 | return; |
| 2054 | } |
| 2055 | } |
| 2056 | |
| 2057 | removeWindowInnerLocked(session, win); |
| 2058 | // Removing a visible window will effect the computed orientation |
| 2059 | // So just update orientation if needed. |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 2060 | if (wasVisible && computeForcedAppOrientationLocked() |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2061 | != mForcedAppOrientation |
| 2062 | && updateOrientationFromAppTokensLocked()) { |
| 2063 | mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2064 | } |
| 2065 | updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL); |
| 2066 | Binder.restoreCallingIdentity(origId); |
| 2067 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2068 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2069 | private void removeWindowInnerLocked(Session session, WindowState win) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2070 | win.mRemoved = true; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2071 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2072 | if (mInputMethodTarget == win) { |
| 2073 | moveInputMethodWindowsIfNeededLocked(false); |
| 2074 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2075 | |
Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 2076 | if (false) { |
| 2077 | RuntimeException e = new RuntimeException("here"); |
| 2078 | e.fillInStackTrace(); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2079 | Slog.w(TAG, "Removing window " + win, e); |
Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 2080 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2081 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2082 | mPolicy.removeWindowLw(win); |
| 2083 | win.removeLocked(); |
| 2084 | |
| 2085 | mWindowMap.remove(win.mClient.asBinder()); |
| 2086 | mWindows.remove(win); |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 2087 | mWindowsChanged = true; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2088 | 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] | 2089 | |
| 2090 | if (mInputMethodWindow == win) { |
| 2091 | mInputMethodWindow = null; |
| 2092 | } else if (win.mAttrs.type == TYPE_INPUT_METHOD_DIALOG) { |
| 2093 | mInputMethodDialogs.remove(win); |
| 2094 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2095 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2096 | final WindowToken token = win.mToken; |
| 2097 | final AppWindowToken atoken = win.mAppToken; |
| 2098 | token.windows.remove(win); |
| 2099 | if (atoken != null) { |
| 2100 | atoken.allAppWindows.remove(win); |
| 2101 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2102 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2103 | TAG, "**** Removing window " + win + ": count=" |
| 2104 | + token.windows.size()); |
| 2105 | if (token.windows.size() == 0) { |
| 2106 | if (!token.explicit) { |
| 2107 | mTokenMap.remove(token.token); |
| 2108 | mTokenList.remove(token); |
| 2109 | } else if (atoken != null) { |
| 2110 | atoken.firstWindowDrawn = false; |
| 2111 | } |
| 2112 | } |
| 2113 | |
| 2114 | if (atoken != null) { |
| 2115 | if (atoken.startingWindow == win) { |
| 2116 | atoken.startingWindow = null; |
| 2117 | } else if (atoken.allAppWindows.size() == 0 && atoken.startingData != null) { |
| 2118 | // If this is the last window and we had requested a starting |
| 2119 | // transition window, well there is no point now. |
| 2120 | atoken.startingData = null; |
| 2121 | } else if (atoken.allAppWindows.size() == 1 && atoken.startingView != null) { |
| 2122 | // If this is the last window except for a starting transition |
| 2123 | // window, we need to get rid of the starting transition. |
| 2124 | if (DEBUG_STARTING_WINDOW) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2125 | Slog.v(TAG, "Schedule remove starting " + token |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2126 | + ": no more real windows"); |
| 2127 | } |
| 2128 | Message m = mH.obtainMessage(H.REMOVE_STARTING, atoken); |
| 2129 | mH.sendMessage(m); |
| 2130 | } |
| 2131 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2132 | |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 2133 | if (win.mAttrs.type == TYPE_WALLPAPER) { |
| 2134 | mLastWallpaperTimeoutTime = 0; |
| 2135 | adjustWallpaperWindowsLocked(); |
| 2136 | } else if ((win.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0) { |
Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 2137 | adjustWallpaperWindowsLocked(); |
| 2138 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2139 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2140 | if (!mInLayout) { |
| 2141 | assignLayersLocked(); |
| 2142 | mLayoutNeeded = true; |
| 2143 | performLayoutAndPlaceSurfacesLocked(); |
| 2144 | if (win.mAppToken != null) { |
| 2145 | win.mAppToken.updateReportedVisibilityLocked(); |
| 2146 | } |
| 2147 | } |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 2148 | |
| 2149 | mInputMonitor.updateInputWindowsLw(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2150 | } |
| 2151 | |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 2152 | private static void logSurface(WindowState w, String msg, RuntimeException where) { |
| 2153 | String str = " SURFACE " + Integer.toHexString(w.hashCode()) |
| 2154 | + ": " + msg + " / " + w.mAttrs.getTitle(); |
| 2155 | if (where != null) { |
| 2156 | Slog.i(TAG, str, where); |
| 2157 | } else { |
| 2158 | Slog.i(TAG, str); |
| 2159 | } |
| 2160 | } |
| 2161 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2162 | private void setTransparentRegionWindow(Session session, IWindow client, Region region) { |
| 2163 | long origId = Binder.clearCallingIdentity(); |
| 2164 | try { |
| 2165 | synchronized (mWindowMap) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2166 | WindowState w = windowForClientLocked(session, client, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2167 | if ((w != null) && (w.mSurface != null)) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2168 | if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2169 | Surface.openTransaction(); |
| 2170 | try { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 2171 | if (SHOW_TRANSACTIONS) logSurface(w, |
| 2172 | "transparentRegionHint=" + region, null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2173 | w.mSurface.setTransparentRegionHint(region); |
| 2174 | } finally { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2175 | if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2176 | Surface.closeTransaction(); |
| 2177 | } |
| 2178 | } |
| 2179 | } |
| 2180 | } finally { |
| 2181 | Binder.restoreCallingIdentity(origId); |
| 2182 | } |
| 2183 | } |
| 2184 | |
| 2185 | void setInsetsWindow(Session session, IWindow client, |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2186 | int touchableInsets, Rect contentInsets, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2187 | Rect visibleInsets) { |
| 2188 | long origId = Binder.clearCallingIdentity(); |
| 2189 | try { |
| 2190 | synchronized (mWindowMap) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2191 | WindowState w = windowForClientLocked(session, client, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2192 | if (w != null) { |
| 2193 | w.mGivenInsetsPending = false; |
| 2194 | w.mGivenContentInsets.set(contentInsets); |
| 2195 | w.mGivenVisibleInsets.set(visibleInsets); |
| 2196 | w.mTouchableInsets = touchableInsets; |
| 2197 | mLayoutNeeded = true; |
| 2198 | performLayoutAndPlaceSurfacesLocked(); |
| 2199 | } |
| 2200 | } |
| 2201 | } finally { |
| 2202 | Binder.restoreCallingIdentity(origId); |
| 2203 | } |
| 2204 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2205 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2206 | public void getWindowDisplayFrame(Session session, IWindow client, |
| 2207 | Rect outDisplayFrame) { |
| 2208 | synchronized(mWindowMap) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2209 | WindowState win = windowForClientLocked(session, client, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2210 | if (win == null) { |
| 2211 | outDisplayFrame.setEmpty(); |
| 2212 | return; |
| 2213 | } |
| 2214 | outDisplayFrame.set(win.mDisplayFrame); |
| 2215 | } |
| 2216 | } |
| 2217 | |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 2218 | public void setWindowWallpaperPositionLocked(WindowState window, float x, float y, |
| 2219 | float xStep, float yStep) { |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 2220 | if (window.mWallpaperX != x || window.mWallpaperY != y) { |
| 2221 | window.mWallpaperX = x; |
| 2222 | window.mWallpaperY = y; |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 2223 | window.mWallpaperXStep = xStep; |
| 2224 | window.mWallpaperYStep = yStep; |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 2225 | if (updateWallpaperOffsetLocked(window, true)) { |
| 2226 | performLayoutAndPlaceSurfacesLocked(); |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 2227 | } |
| 2228 | } |
| 2229 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2230 | |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 2231 | void wallpaperCommandComplete(IBinder window, Bundle result) { |
| 2232 | synchronized (mWindowMap) { |
| 2233 | if (mWaitingOnWallpaper != null && |
| 2234 | mWaitingOnWallpaper.mClient.asBinder() == window) { |
| 2235 | mWaitingOnWallpaper = null; |
| 2236 | mWindowMap.notifyAll(); |
| 2237 | } |
| 2238 | } |
| 2239 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2240 | |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 2241 | public Bundle sendWindowWallpaperCommandLocked(WindowState window, |
| 2242 | String action, int x, int y, int z, Bundle extras, boolean sync) { |
| 2243 | if (window == mWallpaperTarget || window == mLowerWallpaperTarget |
| 2244 | || window == mUpperWallpaperTarget) { |
| 2245 | boolean doWait = sync; |
| 2246 | int curTokenIndex = mWallpaperTokens.size(); |
| 2247 | while (curTokenIndex > 0) { |
| 2248 | curTokenIndex--; |
| 2249 | WindowToken token = mWallpaperTokens.get(curTokenIndex); |
| 2250 | int curWallpaperIndex = token.windows.size(); |
| 2251 | while (curWallpaperIndex > 0) { |
| 2252 | curWallpaperIndex--; |
| 2253 | WindowState wallpaper = token.windows.get(curWallpaperIndex); |
| 2254 | try { |
| 2255 | wallpaper.mClient.dispatchWallpaperCommand(action, |
| 2256 | x, y, z, extras, sync); |
| 2257 | // We only want to be synchronous with one wallpaper. |
| 2258 | sync = false; |
| 2259 | } catch (RemoteException e) { |
| 2260 | } |
| 2261 | } |
| 2262 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2263 | |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 2264 | if (doWait) { |
| 2265 | // XXX Need to wait for result. |
| 2266 | } |
| 2267 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2268 | |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 2269 | return null; |
| 2270 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2271 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2272 | public int relayoutWindow(Session session, IWindow client, |
| 2273 | WindowManager.LayoutParams attrs, int requestedWidth, |
| 2274 | int requestedHeight, int viewVisibility, boolean insetsPending, |
| 2275 | Rect outFrame, Rect outContentInsets, Rect outVisibleInsets, |
Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 2276 | Configuration outConfig, Surface outSurface) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2277 | boolean displayed = false; |
| 2278 | boolean inTouchMode; |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2279 | boolean configChanged; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2280 | long origId = Binder.clearCallingIdentity(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2281 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2282 | synchronized(mWindowMap) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2283 | WindowState win = windowForClientLocked(session, client, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2284 | if (win == null) { |
| 2285 | return 0; |
| 2286 | } |
| 2287 | win.mRequestedWidth = requestedWidth; |
| 2288 | win.mRequestedHeight = requestedHeight; |
| 2289 | |
| 2290 | if (attrs != null) { |
| 2291 | mPolicy.adjustWindowParamsLw(attrs); |
| 2292 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2293 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2294 | int attrChanges = 0; |
| 2295 | int flagChanges = 0; |
| 2296 | if (attrs != null) { |
| 2297 | flagChanges = win.mAttrs.flags ^= attrs.flags; |
| 2298 | attrChanges = win.mAttrs.copyFrom(attrs); |
| 2299 | } |
| 2300 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2301 | 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] | 2302 | |
| 2303 | if ((attrChanges & WindowManager.LayoutParams.ALPHA_CHANGED) != 0) { |
| 2304 | win.mAlpha = attrs.alpha; |
| 2305 | } |
| 2306 | |
| 2307 | final boolean scaledWindow = |
| 2308 | ((win.mAttrs.flags & WindowManager.LayoutParams.FLAG_SCALED) != 0); |
| 2309 | |
| 2310 | if (scaledWindow) { |
| 2311 | // requested{Width|Height} Surface's physical size |
| 2312 | // attrs.{width|height} Size on screen |
| 2313 | win.mHScale = (attrs.width != requestedWidth) ? |
| 2314 | (attrs.width / (float)requestedWidth) : 1.0f; |
| 2315 | win.mVScale = (attrs.height != requestedHeight) ? |
| 2316 | (attrs.height / (float)requestedHeight) : 1.0f; |
Dianne Hackborn | 9b52a21 | 2009-12-11 14:51:35 -0800 | [diff] [blame] | 2317 | } else { |
| 2318 | win.mHScale = win.mVScale = 1; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2319 | } |
| 2320 | |
| 2321 | boolean imMayMove = (flagChanges&( |
| 2322 | WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM | |
| 2323 | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE)) != 0; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2324 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2325 | boolean focusMayChange = win.mViewVisibility != viewVisibility |
| 2326 | || ((flagChanges&WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) != 0) |
| 2327 | || (!win.mRelayoutCalled); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2328 | |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2329 | boolean wallpaperMayMove = win.mViewVisibility != viewVisibility |
| 2330 | && (win.mAttrs.flags & FLAG_SHOW_WALLPAPER) != 0; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2331 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2332 | win.mRelayoutCalled = true; |
| 2333 | final int oldVisibility = win.mViewVisibility; |
| 2334 | win.mViewVisibility = viewVisibility; |
| 2335 | if (viewVisibility == View.VISIBLE && |
| 2336 | (win.mAppToken == null || !win.mAppToken.clientHidden)) { |
| 2337 | displayed = !win.isVisibleLw(); |
| 2338 | if (win.mExiting) { |
| 2339 | win.mExiting = false; |
| 2340 | win.mAnimation = null; |
| 2341 | } |
| 2342 | if (win.mDestroying) { |
| 2343 | win.mDestroying = false; |
| 2344 | mDestroySurface.remove(win); |
| 2345 | } |
| 2346 | if (oldVisibility == View.GONE) { |
| 2347 | win.mEnterAnimationPending = true; |
| 2348 | } |
Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 2349 | if (displayed) { |
| 2350 | if (win.mSurface != null && !win.mDrawPending |
| 2351 | && !win.mCommitDrawPending && !mDisplayFrozen |
| 2352 | && mPolicy.isScreenOn()) { |
| 2353 | applyEnterAnimationLocked(win); |
| 2354 | } |
| 2355 | if ((win.mAttrs.flags |
| 2356 | & WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON) != 0) { |
| 2357 | if (DEBUG_VISIBILITY) Slog.v(TAG, |
| 2358 | "Relayout window turning screen on: " + win); |
| 2359 | win.mTurnOnScreen = true; |
| 2360 | } |
| 2361 | int diff = 0; |
| 2362 | if (win.mConfiguration != mCurConfiguration |
| 2363 | && (win.mConfiguration == null |
| 2364 | || (diff=mCurConfiguration.diff(win.mConfiguration)) != 0)) { |
| 2365 | win.mConfiguration = mCurConfiguration; |
| 2366 | if (DEBUG_CONFIGURATION) { |
| 2367 | Slog.i(TAG, "Window " + win + " visible with new config: " |
| 2368 | + win.mConfiguration + " / 0x" |
| 2369 | + Integer.toHexString(diff)); |
| 2370 | } |
| 2371 | outConfig.setTo(mCurConfiguration); |
| 2372 | } |
Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 2373 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2374 | if ((attrChanges&WindowManager.LayoutParams.FORMAT_CHANGED) != 0) { |
| 2375 | // To change the format, we need to re-build the surface. |
| 2376 | win.destroySurfaceLocked(); |
| 2377 | displayed = true; |
| 2378 | } |
| 2379 | try { |
| 2380 | Surface surface = win.createSurfaceLocked(); |
| 2381 | if (surface != null) { |
| 2382 | outSurface.copyFrom(surface); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2383 | win.mReportDestroySurface = false; |
| 2384 | win.mSurfacePendingDestroy = false; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2385 | if (SHOW_TRANSACTIONS) Slog.i(TAG, |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 2386 | " OUT SURFACE " + outSurface + ": copied"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2387 | } else { |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 2388 | // For some reason there isn't a surface. Clear the |
| 2389 | // caller's object so they see the same state. |
| 2390 | outSurface.release(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2391 | } |
| 2392 | } catch (Exception e) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 2393 | mInputMonitor.updateInputWindowsLw(); |
| 2394 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2395 | Slog.w(TAG, "Exception thrown when creating surface for client " |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 2396 | + client + " (" + win.mAttrs.getTitle() + ")", |
| 2397 | e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2398 | Binder.restoreCallingIdentity(origId); |
| 2399 | return 0; |
| 2400 | } |
| 2401 | if (displayed) { |
| 2402 | focusMayChange = true; |
| 2403 | } |
| 2404 | if (win.mAttrs.type == TYPE_INPUT_METHOD |
| 2405 | && mInputMethodWindow == null) { |
| 2406 | mInputMethodWindow = win; |
| 2407 | imMayMove = true; |
| 2408 | } |
Dianne Hackborn | 558947c | 2009-12-18 16:02:50 -0800 | [diff] [blame] | 2409 | if (win.mAttrs.type == TYPE_BASE_APPLICATION |
| 2410 | && win.mAppToken != null |
| 2411 | && win.mAppToken.startingWindow != null) { |
| 2412 | // Special handling of starting window over the base |
| 2413 | // window of the app: propagate lock screen flags to it, |
| 2414 | // to provide the correct semantics while starting. |
| 2415 | final int mask = |
| 2416 | WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED |
Mike Lockwood | ef73162 | 2010-01-27 17:51:34 -0500 | [diff] [blame] | 2417 | | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD |
| 2418 | | WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON; |
Dianne Hackborn | 558947c | 2009-12-18 16:02:50 -0800 | [diff] [blame] | 2419 | WindowManager.LayoutParams sa = win.mAppToken.startingWindow.mAttrs; |
| 2420 | sa.flags = (sa.flags&~mask) | (win.mAttrs.flags&mask); |
| 2421 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2422 | } else { |
| 2423 | win.mEnterAnimationPending = false; |
| 2424 | if (win.mSurface != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2425 | if (DEBUG_VISIBILITY) Slog.i(TAG, "Relayout invis " + win |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2426 | + ": mExiting=" + win.mExiting |
| 2427 | + " mSurfacePendingDestroy=" + win.mSurfacePendingDestroy); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2428 | // If we are not currently running the exit animation, we |
| 2429 | // need to see about starting one. |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2430 | if (!win.mExiting || win.mSurfacePendingDestroy) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2431 | // Try starting an animation; if there isn't one, we |
| 2432 | // can destroy the surface right away. |
| 2433 | int transit = WindowManagerPolicy.TRANSIT_EXIT; |
| 2434 | if (win.getAttrs().type == TYPE_APPLICATION_STARTING) { |
| 2435 | transit = WindowManagerPolicy.TRANSIT_PREVIEW_DONE; |
| 2436 | } |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2437 | if (!win.mSurfacePendingDestroy && win.isWinVisibleLw() && |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2438 | applyAnimationLocked(win, transit, false)) { |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2439 | focusMayChange = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2440 | win.mExiting = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2441 | } else if (win.isAnimating()) { |
| 2442 | // Currently in a hide animation... turn this into |
| 2443 | // an exit. |
| 2444 | win.mExiting = true; |
Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 2445 | } else if (win == mWallpaperTarget) { |
| 2446 | // If the wallpaper is currently behind this |
| 2447 | // window, we need to change both of them inside |
| 2448 | // of a transaction to avoid artifacts. |
| 2449 | win.mExiting = true; |
| 2450 | win.mAnimating = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2451 | } else { |
| 2452 | if (mInputMethodWindow == win) { |
| 2453 | mInputMethodWindow = null; |
| 2454 | } |
| 2455 | win.destroySurfaceLocked(); |
| 2456 | } |
| 2457 | } |
| 2458 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2459 | |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2460 | if (win.mSurface == null || (win.getAttrs().flags |
| 2461 | & WindowManager.LayoutParams.FLAG_KEEP_SURFACE_WHILE_ANIMATING) == 0 |
| 2462 | || win.mSurfacePendingDestroy) { |
| 2463 | // We are being called from a local process, which |
| 2464 | // means outSurface holds its current surface. Ensure the |
| 2465 | // surface object is cleared, but we don't want it actually |
| 2466 | // destroyed at this point. |
| 2467 | win.mSurfacePendingDestroy = false; |
| 2468 | outSurface.release(); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2469 | if (DEBUG_VISIBILITY) Slog.i(TAG, "Releasing surface in: " + win); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2470 | } else if (win.mSurface != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2471 | if (DEBUG_VISIBILITY) Slog.i(TAG, |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2472 | "Keeping surface, will report destroy: " + win); |
| 2473 | win.mReportDestroySurface = true; |
| 2474 | outSurface.copyFrom(win.mSurface); |
| 2475 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2476 | } |
| 2477 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2478 | if (focusMayChange) { |
| 2479 | //System.out.println("Focus may change: " + win.mAttrs.getTitle()); |
| 2480 | if (updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2481 | imMayMove = false; |
| 2482 | } |
| 2483 | //System.out.println("Relayout " + win + ": focus=" + mCurrentFocus); |
| 2484 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2485 | |
The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 2486 | // updateFocusedWindowLocked() already assigned layers so we only need to |
| 2487 | // reassign them at this point if the IM window state gets shuffled |
| 2488 | boolean assignLayers = false; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2489 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2490 | if (imMayMove) { |
Dianne Hackborn | 8abd5f0 | 2009-11-20 18:09:03 -0800 | [diff] [blame] | 2491 | if (moveInputMethodWindowsIfNeededLocked(false) || displayed) { |
| 2492 | // Little hack here -- we -should- be able to rely on the |
| 2493 | // function to return true if the IME has moved and needs |
| 2494 | // its layer recomputed. However, if the IME was hidden |
| 2495 | // and isn't actually moved in the list, its layer may be |
| 2496 | // 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] | 2497 | assignLayers = true; |
| 2498 | } |
| 2499 | } |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2500 | if (wallpaperMayMove) { |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 2501 | if ((adjustWallpaperWindowsLocked()&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) { |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2502 | assignLayers = true; |
| 2503 | } |
| 2504 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2505 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2506 | mLayoutNeeded = true; |
| 2507 | win.mGivenInsetsPending = insetsPending; |
| 2508 | if (assignLayers) { |
| 2509 | assignLayersLocked(); |
| 2510 | } |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2511 | configChanged = updateOrientationFromAppTokensLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2512 | performLayoutAndPlaceSurfacesLocked(); |
Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 2513 | if (displayed && win.mIsWallpaper) { |
| 2514 | updateWallpaperOffsetLocked(win, mDisplay.getWidth(), |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 2515 | mDisplay.getHeight(), false); |
Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 2516 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2517 | if (win.mAppToken != null) { |
| 2518 | win.mAppToken.updateReportedVisibilityLocked(); |
| 2519 | } |
| 2520 | outFrame.set(win.mFrame); |
| 2521 | outContentInsets.set(win.mContentInsets); |
| 2522 | outVisibleInsets.set(win.mVisibleInsets); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2523 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2524 | TAG, "Relayout given client " + client.asBinder() |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2525 | + ", requestedWidth=" + requestedWidth |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2526 | + ", requestedHeight=" + requestedHeight |
| 2527 | + ", viewVisibility=" + viewVisibility |
| 2528 | + "\nRelayout returning frame=" + outFrame |
| 2529 | + ", surface=" + outSurface); |
| 2530 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2531 | if (localLOGV || DEBUG_FOCUS) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2532 | TAG, "Relayout of " + win + ": focusMayChange=" + focusMayChange); |
| 2533 | |
| 2534 | inTouchMode = mInTouchMode; |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 2535 | |
| 2536 | mInputMonitor.updateInputWindowsLw(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2537 | } |
| 2538 | |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2539 | if (configChanged) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2540 | sendNewConfiguration(); |
| 2541 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2542 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2543 | Binder.restoreCallingIdentity(origId); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2544 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2545 | return (inTouchMode ? WindowManagerImpl.RELAYOUT_IN_TOUCH_MODE : 0) |
| 2546 | | (displayed ? WindowManagerImpl.RELAYOUT_FIRST_TIME : 0); |
| 2547 | } |
| 2548 | |
| 2549 | public void finishDrawingWindow(Session session, IWindow client) { |
| 2550 | final long origId = Binder.clearCallingIdentity(); |
| 2551 | synchronized(mWindowMap) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2552 | WindowState win = windowForClientLocked(session, client, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2553 | if (win != null && win.finishDrawingLocked()) { |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 2554 | if ((win.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0) { |
| 2555 | adjustWallpaperWindowsLocked(); |
| 2556 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2557 | mLayoutNeeded = true; |
| 2558 | performLayoutAndPlaceSurfacesLocked(); |
| 2559 | } |
| 2560 | } |
| 2561 | Binder.restoreCallingIdentity(origId); |
| 2562 | } |
| 2563 | |
| 2564 | private AttributeCache.Entry getCachedAnimations(WindowManager.LayoutParams lp) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2565 | 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] | 2566 | + (lp != null ? lp.packageName : null) |
| 2567 | + " resId=0x" + (lp != null ? Integer.toHexString(lp.windowAnimations) : null)); |
| 2568 | if (lp != null && lp.windowAnimations != 0) { |
| 2569 | // If this is a system resource, don't try to load it from the |
| 2570 | // application resources. It is nice to avoid loading application |
| 2571 | // resources if we can. |
| 2572 | String packageName = lp.packageName != null ? lp.packageName : "android"; |
| 2573 | int resId = lp.windowAnimations; |
| 2574 | if ((resId&0xFF000000) == 0x01000000) { |
| 2575 | packageName = "android"; |
| 2576 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2577 | 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] | 2578 | + packageName); |
| 2579 | return AttributeCache.instance().get(packageName, resId, |
| 2580 | com.android.internal.R.styleable.WindowAnimation); |
| 2581 | } |
| 2582 | return null; |
| 2583 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2584 | |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2585 | private AttributeCache.Entry getCachedAnimations(String packageName, int resId) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2586 | if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: params package=" |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2587 | + packageName + " resId=0x" + Integer.toHexString(resId)); |
| 2588 | if (packageName != null) { |
| 2589 | if ((resId&0xFF000000) == 0x01000000) { |
| 2590 | packageName = "android"; |
| 2591 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2592 | if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: picked package=" |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2593 | + packageName); |
| 2594 | return AttributeCache.instance().get(packageName, resId, |
| 2595 | com.android.internal.R.styleable.WindowAnimation); |
| 2596 | } |
| 2597 | return null; |
| 2598 | } |
| 2599 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2600 | private void applyEnterAnimationLocked(WindowState win) { |
| 2601 | int transit = WindowManagerPolicy.TRANSIT_SHOW; |
| 2602 | if (win.mEnterAnimationPending) { |
| 2603 | win.mEnterAnimationPending = false; |
| 2604 | transit = WindowManagerPolicy.TRANSIT_ENTER; |
| 2605 | } |
| 2606 | |
| 2607 | applyAnimationLocked(win, transit, true); |
| 2608 | } |
| 2609 | |
| 2610 | private boolean applyAnimationLocked(WindowState win, |
| 2611 | int transit, boolean isEntrance) { |
| 2612 | if (win.mLocalAnimating && win.mAnimationIsEntrance == isEntrance) { |
| 2613 | // If we are trying to apply an animation, but already running |
| 2614 | // an animation of the same type, then just leave that one alone. |
| 2615 | return true; |
| 2616 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2617 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2618 | // Only apply an animation if the display isn't frozen. If it is |
| 2619 | // frozen, there is no reason to animate and it can cause strange |
| 2620 | // artifacts when we unfreeze the display if some different animation |
| 2621 | // is running. |
Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 2622 | if (!mDisplayFrozen && mPolicy.isScreenOn()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2623 | int anim = mPolicy.selectAnimationLw(win, transit); |
| 2624 | int attr = -1; |
| 2625 | Animation a = null; |
| 2626 | if (anim != 0) { |
| 2627 | a = AnimationUtils.loadAnimation(mContext, anim); |
| 2628 | } else { |
| 2629 | switch (transit) { |
| 2630 | case WindowManagerPolicy.TRANSIT_ENTER: |
| 2631 | attr = com.android.internal.R.styleable.WindowAnimation_windowEnterAnimation; |
| 2632 | break; |
| 2633 | case WindowManagerPolicy.TRANSIT_EXIT: |
| 2634 | attr = com.android.internal.R.styleable.WindowAnimation_windowExitAnimation; |
| 2635 | break; |
| 2636 | case WindowManagerPolicy.TRANSIT_SHOW: |
| 2637 | attr = com.android.internal.R.styleable.WindowAnimation_windowShowAnimation; |
| 2638 | break; |
| 2639 | case WindowManagerPolicy.TRANSIT_HIDE: |
| 2640 | attr = com.android.internal.R.styleable.WindowAnimation_windowHideAnimation; |
| 2641 | break; |
| 2642 | } |
| 2643 | if (attr >= 0) { |
| 2644 | a = loadAnimation(win.mAttrs, attr); |
| 2645 | } |
| 2646 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2647 | if (DEBUG_ANIM) Slog.v(TAG, "applyAnimation: win=" + win |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2648 | + " anim=" + anim + " attr=0x" + Integer.toHexString(attr) |
| 2649 | + " mAnimation=" + win.mAnimation |
| 2650 | + " isEntrance=" + isEntrance); |
| 2651 | if (a != null) { |
| 2652 | if (DEBUG_ANIM) { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 2653 | RuntimeException e = null; |
| 2654 | if (!HIDE_STACK_CRAWLS) { |
| 2655 | e = new RuntimeException(); |
| 2656 | e.fillInStackTrace(); |
| 2657 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2658 | Slog.v(TAG, "Loaded animation " + a + " for " + win, e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2659 | } |
| 2660 | win.setAnimation(a); |
| 2661 | win.mAnimationIsEntrance = isEntrance; |
| 2662 | } |
| 2663 | } else { |
| 2664 | win.clearAnimation(); |
| 2665 | } |
| 2666 | |
| 2667 | return win.mAnimation != null; |
| 2668 | } |
| 2669 | |
| 2670 | private Animation loadAnimation(WindowManager.LayoutParams lp, int animAttr) { |
| 2671 | int anim = 0; |
| 2672 | Context context = mContext; |
| 2673 | if (animAttr >= 0) { |
| 2674 | AttributeCache.Entry ent = getCachedAnimations(lp); |
| 2675 | if (ent != null) { |
| 2676 | context = ent.context; |
| 2677 | anim = ent.array.getResourceId(animAttr, 0); |
| 2678 | } |
| 2679 | } |
| 2680 | if (anim != 0) { |
| 2681 | return AnimationUtils.loadAnimation(context, anim); |
| 2682 | } |
| 2683 | return null; |
| 2684 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2685 | |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2686 | private Animation loadAnimation(String packageName, int resId) { |
| 2687 | int anim = 0; |
| 2688 | Context context = mContext; |
| 2689 | if (resId >= 0) { |
| 2690 | AttributeCache.Entry ent = getCachedAnimations(packageName, resId); |
| 2691 | if (ent != null) { |
| 2692 | context = ent.context; |
| 2693 | anim = resId; |
| 2694 | } |
| 2695 | } |
| 2696 | if (anim != 0) { |
| 2697 | return AnimationUtils.loadAnimation(context, anim); |
| 2698 | } |
| 2699 | return null; |
| 2700 | } |
| 2701 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2702 | private boolean applyAnimationLocked(AppWindowToken wtoken, |
| 2703 | WindowManager.LayoutParams lp, int transit, boolean enter) { |
| 2704 | // Only apply an animation if the display isn't frozen. If it is |
| 2705 | // frozen, there is no reason to animate and it can cause strange |
| 2706 | // artifacts when we unfreeze the display if some different animation |
| 2707 | // is running. |
Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 2708 | if (!mDisplayFrozen && mPolicy.isScreenOn()) { |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 2709 | Animation a; |
Mitsuru Oshima | d2967e2 | 2009-07-20 14:01:43 -0700 | [diff] [blame] | 2710 | if (lp != null && (lp.flags & FLAG_COMPATIBLE_WINDOW) != 0) { |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 2711 | a = new FadeInOutAnimation(enter); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2712 | if (DEBUG_ANIM) Slog.v(TAG, |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 2713 | "applying FadeInOutAnimation for a window in compatibility mode"); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2714 | } else if (mNextAppTransitionPackage != null) { |
| 2715 | a = loadAnimation(mNextAppTransitionPackage, enter ? |
| 2716 | mNextAppTransitionEnter : mNextAppTransitionExit); |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 2717 | } else { |
| 2718 | int animAttr = 0; |
| 2719 | switch (transit) { |
| 2720 | case WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN: |
| 2721 | animAttr = enter |
| 2722 | ? com.android.internal.R.styleable.WindowAnimation_activityOpenEnterAnimation |
| 2723 | : com.android.internal.R.styleable.WindowAnimation_activityOpenExitAnimation; |
| 2724 | break; |
| 2725 | case WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE: |
| 2726 | animAttr = enter |
| 2727 | ? com.android.internal.R.styleable.WindowAnimation_activityCloseEnterAnimation |
| 2728 | : com.android.internal.R.styleable.WindowAnimation_activityCloseExitAnimation; |
| 2729 | break; |
| 2730 | case WindowManagerPolicy.TRANSIT_TASK_OPEN: |
| 2731 | animAttr = enter |
| 2732 | ? com.android.internal.R.styleable.WindowAnimation_taskOpenEnterAnimation |
| 2733 | : com.android.internal.R.styleable.WindowAnimation_taskOpenExitAnimation; |
| 2734 | break; |
| 2735 | case WindowManagerPolicy.TRANSIT_TASK_CLOSE: |
| 2736 | animAttr = enter |
| 2737 | ? com.android.internal.R.styleable.WindowAnimation_taskCloseEnterAnimation |
| 2738 | : com.android.internal.R.styleable.WindowAnimation_taskCloseExitAnimation; |
| 2739 | break; |
| 2740 | case WindowManagerPolicy.TRANSIT_TASK_TO_FRONT: |
| 2741 | animAttr = enter |
| 2742 | ? com.android.internal.R.styleable.WindowAnimation_taskToFrontEnterAnimation |
| 2743 | : com.android.internal.R.styleable.WindowAnimation_taskToFrontExitAnimation; |
| 2744 | break; |
| 2745 | case WindowManagerPolicy.TRANSIT_TASK_TO_BACK: |
| 2746 | animAttr = enter |
Mitsuru Oshima | 5a2b91d | 2009-07-16 16:30:02 -0700 | [diff] [blame] | 2747 | ? com.android.internal.R.styleable.WindowAnimation_taskToBackEnterAnimation |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 2748 | : com.android.internal.R.styleable.WindowAnimation_taskToBackExitAnimation; |
| 2749 | break; |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 2750 | case WindowManagerPolicy.TRANSIT_WALLPAPER_OPEN: |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 2751 | animAttr = enter |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 2752 | ? com.android.internal.R.styleable.WindowAnimation_wallpaperOpenEnterAnimation |
| 2753 | : com.android.internal.R.styleable.WindowAnimation_wallpaperOpenExitAnimation; |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 2754 | break; |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 2755 | case WindowManagerPolicy.TRANSIT_WALLPAPER_CLOSE: |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 2756 | animAttr = enter |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 2757 | ? com.android.internal.R.styleable.WindowAnimation_wallpaperCloseEnterAnimation |
| 2758 | : com.android.internal.R.styleable.WindowAnimation_wallpaperCloseExitAnimation; |
| 2759 | break; |
| 2760 | case WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_OPEN: |
| 2761 | animAttr = enter |
| 2762 | ? com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenEnterAnimation |
| 2763 | : com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenExitAnimation; |
| 2764 | break; |
| 2765 | case WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_CLOSE: |
| 2766 | animAttr = enter |
| 2767 | ? com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseEnterAnimation |
| 2768 | : com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseExitAnimation; |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 2769 | break; |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 2770 | } |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 2771 | a = animAttr != 0 ? loadAnimation(lp, animAttr) : null; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2772 | if (DEBUG_ANIM) Slog.v(TAG, "applyAnimation: wtoken=" + wtoken |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 2773 | + " anim=" + a |
| 2774 | + " animAttr=0x" + Integer.toHexString(animAttr) |
| 2775 | + " transit=" + transit); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2776 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2777 | if (a != null) { |
| 2778 | if (DEBUG_ANIM) { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 2779 | RuntimeException e = null; |
| 2780 | if (!HIDE_STACK_CRAWLS) { |
| 2781 | e = new RuntimeException(); |
| 2782 | e.fillInStackTrace(); |
| 2783 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2784 | Slog.v(TAG, "Loaded animation " + a + " for " + wtoken, e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2785 | } |
| 2786 | wtoken.setAnimation(a); |
| 2787 | } |
| 2788 | } else { |
| 2789 | wtoken.clearAnimation(); |
| 2790 | } |
| 2791 | |
| 2792 | return wtoken.animation != null; |
| 2793 | } |
| 2794 | |
| 2795 | // ------------------------------------------------------------- |
| 2796 | // Application Window Tokens |
| 2797 | // ------------------------------------------------------------- |
| 2798 | |
| 2799 | public void validateAppTokens(List tokens) { |
| 2800 | int v = tokens.size()-1; |
| 2801 | int m = mAppTokens.size()-1; |
| 2802 | while (v >= 0 && m >= 0) { |
| 2803 | AppWindowToken wtoken = mAppTokens.get(m); |
| 2804 | if (wtoken.removed) { |
| 2805 | m--; |
| 2806 | continue; |
| 2807 | } |
| 2808 | if (tokens.get(v) != wtoken.token) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2809 | 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] | 2810 | + " @ " + v + ", internal is " + wtoken.token + " @ " + m); |
| 2811 | } |
| 2812 | v--; |
| 2813 | m--; |
| 2814 | } |
| 2815 | while (v >= 0) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2816 | 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] | 2817 | v--; |
| 2818 | } |
| 2819 | while (m >= 0) { |
| 2820 | AppWindowToken wtoken = mAppTokens.get(m); |
| 2821 | if (!wtoken.removed) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2822 | Slog.w(TAG, "Invalid internal token: " + wtoken.token + " @ " + m); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2823 | } |
| 2824 | m--; |
| 2825 | } |
| 2826 | } |
| 2827 | |
| 2828 | boolean checkCallingPermission(String permission, String func) { |
| 2829 | // Quick check: if the calling permission is me, it's all okay. |
| 2830 | if (Binder.getCallingPid() == Process.myPid()) { |
| 2831 | return true; |
| 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 | if (mContext.checkCallingPermission(permission) |
| 2835 | == PackageManager.PERMISSION_GRANTED) { |
| 2836 | return true; |
| 2837 | } |
| 2838 | String msg = "Permission Denial: " + func + " from pid=" |
| 2839 | + Binder.getCallingPid() |
| 2840 | + ", uid=" + Binder.getCallingUid() |
| 2841 | + " requires " + permission; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2842 | Slog.w(TAG, msg); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2843 | return false; |
| 2844 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2845 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2846 | AppWindowToken findAppWindowToken(IBinder token) { |
| 2847 | WindowToken wtoken = mTokenMap.get(token); |
| 2848 | if (wtoken == null) { |
| 2849 | return null; |
| 2850 | } |
| 2851 | return wtoken.appWindowToken; |
| 2852 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2853 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2854 | public void addWindowToken(IBinder token, int type) { |
| 2855 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 2856 | "addWindowToken()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 2857 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2858 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2859 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2860 | synchronized(mWindowMap) { |
| 2861 | WindowToken wtoken = mTokenMap.get(token); |
| 2862 | if (wtoken != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2863 | 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] | 2864 | return; |
| 2865 | } |
| 2866 | wtoken = new WindowToken(token, type, true); |
| 2867 | mTokenMap.put(token, wtoken); |
| 2868 | mTokenList.add(wtoken); |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2869 | if (type == TYPE_WALLPAPER) { |
| 2870 | mWallpaperTokens.add(wtoken); |
| 2871 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2872 | } |
| 2873 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2874 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2875 | public void removeWindowToken(IBinder token) { |
| 2876 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 2877 | "removeWindowToken()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 2878 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2879 | } |
| 2880 | |
| 2881 | final long origId = Binder.clearCallingIdentity(); |
| 2882 | synchronized(mWindowMap) { |
| 2883 | WindowToken wtoken = mTokenMap.remove(token); |
| 2884 | mTokenList.remove(wtoken); |
| 2885 | if (wtoken != null) { |
| 2886 | boolean delayed = false; |
| 2887 | if (!wtoken.hidden) { |
| 2888 | wtoken.hidden = true; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2889 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2890 | final int N = wtoken.windows.size(); |
| 2891 | boolean changed = false; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2892 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2893 | for (int i=0; i<N; i++) { |
| 2894 | WindowState win = wtoken.windows.get(i); |
| 2895 | |
| 2896 | if (win.isAnimating()) { |
| 2897 | delayed = true; |
| 2898 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2899 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2900 | if (win.isVisibleNow()) { |
| 2901 | applyAnimationLocked(win, |
| 2902 | WindowManagerPolicy.TRANSIT_EXIT, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2903 | changed = true; |
| 2904 | } |
| 2905 | } |
| 2906 | |
| 2907 | if (changed) { |
| 2908 | mLayoutNeeded = true; |
| 2909 | performLayoutAndPlaceSurfacesLocked(); |
| 2910 | updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL); |
| 2911 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2912 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2913 | if (delayed) { |
| 2914 | mExitingTokens.add(wtoken); |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2915 | } else if (wtoken.windowType == TYPE_WALLPAPER) { |
| 2916 | mWallpaperTokens.remove(wtoken); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2917 | } |
| 2918 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2919 | |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 2920 | mInputMonitor.updateInputWindowsLw(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2921 | } else { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2922 | 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] | 2923 | } |
| 2924 | } |
| 2925 | Binder.restoreCallingIdentity(origId); |
| 2926 | } |
| 2927 | |
| 2928 | public void addAppToken(int addPos, IApplicationToken token, |
| 2929 | int groupId, int requestedOrientation, boolean fullscreen) { |
| 2930 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 2931 | "addAppToken()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 2932 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2933 | } |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 2934 | |
| 2935 | // Get the dispatching timeout here while we are not holding any locks so that it |
| 2936 | // can be cached by the AppWindowToken. The timeout value is used later by the |
| 2937 | // input dispatcher in code that does hold locks. If we did not cache the value |
| 2938 | // here we would run the chance of introducing a deadlock between the window manager |
| 2939 | // (which holds locks while updating the input dispatcher state) and the activity manager |
| 2940 | // (which holds locks while querying the application token). |
| 2941 | long inputDispatchingTimeoutNanos; |
| 2942 | try { |
| 2943 | inputDispatchingTimeoutNanos = token.getKeyDispatchingTimeout() * 1000000L; |
| 2944 | } catch (RemoteException ex) { |
| 2945 | Slog.w(TAG, "Could not get dispatching timeout.", ex); |
| 2946 | inputDispatchingTimeoutNanos = DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS; |
| 2947 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2948 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2949 | synchronized(mWindowMap) { |
| 2950 | AppWindowToken wtoken = findAppWindowToken(token.asBinder()); |
| 2951 | if (wtoken != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2952 | 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] | 2953 | return; |
| 2954 | } |
| 2955 | wtoken = new AppWindowToken(token); |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 2956 | wtoken.inputDispatchingTimeoutNanos = inputDispatchingTimeoutNanos; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2957 | wtoken.groupId = groupId; |
| 2958 | wtoken.appFullscreen = fullscreen; |
| 2959 | wtoken.requestedOrientation = requestedOrientation; |
| 2960 | mAppTokens.add(addPos, wtoken); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2961 | 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] | 2962 | mTokenMap.put(token.asBinder(), wtoken); |
| 2963 | mTokenList.add(wtoken); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2964 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2965 | // Application tokens start out hidden. |
| 2966 | wtoken.hidden = true; |
| 2967 | wtoken.hiddenRequested = true; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2968 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2969 | //dump(); |
| 2970 | } |
| 2971 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2972 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2973 | public void setAppGroupId(IBinder token, int groupId) { |
| 2974 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 2975 | "setAppStartingIcon()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 2976 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2977 | } |
| 2978 | |
| 2979 | synchronized(mWindowMap) { |
| 2980 | AppWindowToken wtoken = findAppWindowToken(token); |
| 2981 | if (wtoken == null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2982 | 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] | 2983 | return; |
| 2984 | } |
| 2985 | wtoken.groupId = groupId; |
| 2986 | } |
| 2987 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2988 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2989 | public int getOrientationFromWindowsLocked() { |
| 2990 | int pos = mWindows.size() - 1; |
| 2991 | while (pos >= 0) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 2992 | WindowState wtoken = mWindows.get(pos); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2993 | pos--; |
| 2994 | if (wtoken.mAppToken != null) { |
| 2995 | // We hit an application window. so the orientation will be determined by the |
| 2996 | // app window. No point in continuing further. |
| 2997 | return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
| 2998 | } |
Christopher Tate | b696aee | 2010-04-02 19:08:30 -0700 | [diff] [blame] | 2999 | if (!wtoken.isVisibleLw() || !wtoken.mPolicyVisibilityAfterAnim) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3000 | continue; |
| 3001 | } |
| 3002 | int req = wtoken.mAttrs.screenOrientation; |
| 3003 | if((req == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) || |
| 3004 | (req == ActivityInfo.SCREEN_ORIENTATION_BEHIND)){ |
| 3005 | continue; |
| 3006 | } else { |
| 3007 | return req; |
| 3008 | } |
| 3009 | } |
| 3010 | return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
| 3011 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3012 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3013 | public int getOrientationFromAppTokensLocked() { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3014 | int pos = mAppTokens.size() - 1; |
| 3015 | int curGroup = 0; |
| 3016 | int lastOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
| 3017 | boolean findingBehind = false; |
| 3018 | boolean haveGroup = false; |
| 3019 | boolean lastFullscreen = false; |
| 3020 | while (pos >= 0) { |
| 3021 | AppWindowToken wtoken = mAppTokens.get(pos); |
| 3022 | pos--; |
| 3023 | // if we're about to tear down this window and not seek for |
| 3024 | // the behind activity, don't use it for orientation |
| 3025 | if (!findingBehind |
| 3026 | && (!wtoken.hidden && wtoken.hiddenRequested)) { |
| 3027 | continue; |
| 3028 | } |
| 3029 | |
| 3030 | if (!haveGroup) { |
| 3031 | // We ignore any hidden applications on the top. |
| 3032 | if (wtoken.hiddenRequested || wtoken.willBeHidden) { |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3033 | continue; |
| 3034 | } |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3035 | haveGroup = true; |
| 3036 | curGroup = wtoken.groupId; |
| 3037 | lastOrientation = wtoken.requestedOrientation; |
| 3038 | } else if (curGroup != wtoken.groupId) { |
| 3039 | // If we have hit a new application group, and the bottom |
| 3040 | // of the previous group didn't explicitly say to use |
| 3041 | // the orientation behind it, and the last app was |
| 3042 | // full screen, then we'll stick with the |
| 3043 | // user's orientation. |
| 3044 | if (lastOrientation != ActivityInfo.SCREEN_ORIENTATION_BEHIND |
| 3045 | && lastFullscreen) { |
| 3046 | return lastOrientation; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3047 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3048 | } |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3049 | int or = wtoken.requestedOrientation; |
| 3050 | // If this application is fullscreen, and didn't explicitly say |
| 3051 | // to use the orientation behind it, then just take whatever |
| 3052 | // orientation it has and ignores whatever is under it. |
| 3053 | lastFullscreen = wtoken.appFullscreen; |
| 3054 | if (lastFullscreen |
| 3055 | && or != ActivityInfo.SCREEN_ORIENTATION_BEHIND) { |
| 3056 | return or; |
| 3057 | } |
| 3058 | // If this application has requested an explicit orientation, |
| 3059 | // then use it. |
| 3060 | if (or == ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE || |
| 3061 | or == ActivityInfo.SCREEN_ORIENTATION_PORTRAIT || |
| 3062 | or == ActivityInfo.SCREEN_ORIENTATION_SENSOR || |
| 3063 | or == ActivityInfo.SCREEN_ORIENTATION_NOSENSOR || |
| 3064 | or == ActivityInfo.SCREEN_ORIENTATION_USER) { |
| 3065 | return or; |
| 3066 | } |
| 3067 | findingBehind |= (or == ActivityInfo.SCREEN_ORIENTATION_BEHIND); |
| 3068 | } |
| 3069 | return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3070 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3071 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3072 | public Configuration updateOrientationFromAppTokens( |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3073 | Configuration currentConfig, IBinder freezeThisOneIfNeeded) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3074 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3075 | "updateOrientationFromAppTokens()")) { |
| 3076 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| 3077 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3078 | |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3079 | Configuration config = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3080 | long ident = Binder.clearCallingIdentity(); |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3081 | |
| 3082 | synchronized(mWindowMap) { |
| 3083 | if (updateOrientationFromAppTokensLocked()) { |
| 3084 | if (freezeThisOneIfNeeded != null) { |
| 3085 | AppWindowToken wtoken = findAppWindowToken( |
| 3086 | freezeThisOneIfNeeded); |
| 3087 | if (wtoken != null) { |
| 3088 | startAppFreezingScreenLocked(wtoken, |
| 3089 | ActivityInfo.CONFIG_ORIENTATION); |
| 3090 | } |
| 3091 | } |
| 3092 | config = computeNewConfigurationLocked(); |
| 3093 | |
| 3094 | } else if (currentConfig != null) { |
| 3095 | // No obvious action we need to take, but if our current |
| 3096 | // state mismatches the activity maanager's, update it |
| 3097 | mTempConfiguration.setToDefaults(); |
| 3098 | if (computeNewConfigurationLocked(mTempConfiguration)) { |
| 3099 | if (currentConfig.diff(mTempConfiguration) != 0) { |
| 3100 | mWaitingForConfig = true; |
| 3101 | mLayoutNeeded = true; |
| 3102 | startFreezingDisplayLocked(); |
| 3103 | config = new Configuration(mTempConfiguration); |
| 3104 | } |
| 3105 | } |
| 3106 | } |
| 3107 | } |
| 3108 | |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3109 | Binder.restoreCallingIdentity(ident); |
| 3110 | return config; |
| 3111 | } |
| 3112 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3113 | /* |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3114 | * Determine the new desired orientation of the display, returning |
| 3115 | * a non-null new Configuration if it has changed from the current |
| 3116 | * orientation. IF TRUE IS RETURNED SOMEONE MUST CALL |
| 3117 | * setNewConfiguration() TO TELL THE WINDOW MANAGER IT CAN UNFREEZE THE |
| 3118 | * SCREEN. This will typically be done for you if you call |
| 3119 | * sendNewConfiguration(). |
| 3120 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3121 | * The orientation is computed from non-application windows first. If none of |
| 3122 | * the non-application windows specify orientation, the orientation is computed from |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3123 | * application tokens. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3124 | * @see android.view.IWindowManager#updateOrientationFromAppTokens( |
| 3125 | * android.os.IBinder) |
| 3126 | */ |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3127 | boolean updateOrientationFromAppTokensLocked() { |
Christopher Tate | b696aee | 2010-04-02 19:08:30 -0700 | [diff] [blame] | 3128 | if (mDisplayFrozen) { |
| 3129 | // If the display is frozen, some activities may be in the middle |
| 3130 | // of restarting, and thus have removed their old window. If the |
| 3131 | // window has the flag to hide the lock screen, then the lock screen |
| 3132 | // can re-appear and inflict its own orientation on us. Keep the |
| 3133 | // orientation stable until this all settles down. |
| 3134 | return false; |
| 3135 | } |
| 3136 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3137 | boolean changed = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3138 | long ident = Binder.clearCallingIdentity(); |
| 3139 | try { |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 3140 | int req = computeForcedAppOrientationLocked(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3141 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3142 | if (req != mForcedAppOrientation) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3143 | mForcedAppOrientation = req; |
| 3144 | //send a message to Policy indicating orientation change to take |
| 3145 | //action like disabling/enabling sensors etc., |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 3146 | mPolicy.setCurrentOrientationLw(req); |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3147 | if (setRotationUncheckedLocked(WindowManagerPolicy.USE_LAST_ROTATION, |
| 3148 | mLastRotationFlags | Surface.FLAGS_ORIENTATION_ANIMATION_DISABLE)) { |
| 3149 | changed = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3150 | } |
| 3151 | } |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3152 | |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3153 | return changed; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3154 | } finally { |
| 3155 | Binder.restoreCallingIdentity(ident); |
| 3156 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3157 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3158 | |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 3159 | int computeForcedAppOrientationLocked() { |
| 3160 | int req = getOrientationFromWindowsLocked(); |
| 3161 | if (req == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) { |
| 3162 | req = getOrientationFromAppTokensLocked(); |
| 3163 | } |
| 3164 | return req; |
| 3165 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3166 | |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3167 | public void setNewConfiguration(Configuration config) { |
| 3168 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3169 | "setNewConfiguration()")) { |
| 3170 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| 3171 | } |
| 3172 | |
| 3173 | synchronized(mWindowMap) { |
| 3174 | mCurConfiguration = new Configuration(config); |
| 3175 | mWaitingForConfig = false; |
| 3176 | performLayoutAndPlaceSurfacesLocked(); |
| 3177 | } |
| 3178 | } |
| 3179 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3180 | public void setAppOrientation(IApplicationToken token, int requestedOrientation) { |
| 3181 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3182 | "setAppOrientation()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3183 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3184 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3185 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3186 | synchronized(mWindowMap) { |
| 3187 | AppWindowToken wtoken = findAppWindowToken(token.asBinder()); |
| 3188 | if (wtoken == null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3189 | 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] | 3190 | return; |
| 3191 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3192 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3193 | wtoken.requestedOrientation = requestedOrientation; |
| 3194 | } |
| 3195 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3196 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3197 | public int getAppOrientation(IApplicationToken token) { |
| 3198 | synchronized(mWindowMap) { |
| 3199 | AppWindowToken wtoken = findAppWindowToken(token.asBinder()); |
| 3200 | if (wtoken == null) { |
| 3201 | return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
| 3202 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3203 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3204 | return wtoken.requestedOrientation; |
| 3205 | } |
| 3206 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3207 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3208 | public void setFocusedApp(IBinder token, boolean moveFocusNow) { |
| 3209 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3210 | "setFocusedApp()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3211 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3212 | } |
| 3213 | |
| 3214 | synchronized(mWindowMap) { |
| 3215 | boolean changed = false; |
| 3216 | if (token == null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3217 | 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] | 3218 | changed = mFocusedApp != null; |
| 3219 | mFocusedApp = null; |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 3220 | if (changed) { |
| 3221 | mInputMonitor.setFocusedAppLw(null); |
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 | } else { |
| 3224 | AppWindowToken newFocus = findAppWindowToken(token); |
| 3225 | if (newFocus == null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3226 | 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] | 3227 | return; |
| 3228 | } |
| 3229 | changed = mFocusedApp != newFocus; |
| 3230 | mFocusedApp = newFocus; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3231 | if (DEBUG_FOCUS) Slog.v(TAG, "Set focused app to: " + mFocusedApp); |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 3232 | if (changed) { |
| 3233 | mInputMonitor.setFocusedAppLw(newFocus); |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 3234 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3235 | } |
| 3236 | |
| 3237 | if (moveFocusNow && changed) { |
| 3238 | final long origId = Binder.clearCallingIdentity(); |
| 3239 | updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL); |
| 3240 | Binder.restoreCallingIdentity(origId); |
| 3241 | } |
| 3242 | } |
| 3243 | } |
| 3244 | |
| 3245 | public void prepareAppTransition(int transit) { |
| 3246 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3247 | "prepareAppTransition()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3248 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3249 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3250 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3251 | synchronized(mWindowMap) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3252 | if (DEBUG_APP_TRANSITIONS) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3253 | TAG, "Prepare app transition: transit=" + transit |
| 3254 | + " mNextAppTransition=" + mNextAppTransition); |
Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 3255 | if (!mDisplayFrozen && mPolicy.isScreenOn()) { |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 3256 | if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET |
| 3257 | || mNextAppTransition == WindowManagerPolicy.TRANSIT_NONE) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3258 | mNextAppTransition = transit; |
Dianne Hackborn | d7cd29d | 2009-07-01 11:22:45 -0700 | [diff] [blame] | 3259 | } else if (transit == WindowManagerPolicy.TRANSIT_TASK_OPEN |
| 3260 | && mNextAppTransition == WindowManagerPolicy.TRANSIT_TASK_CLOSE) { |
| 3261 | // Opening a new task always supersedes a close for the anim. |
| 3262 | mNextAppTransition = transit; |
| 3263 | } else if (transit == WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN |
| 3264 | && mNextAppTransition == WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE) { |
| 3265 | // Opening a new activity always supersedes a close for the anim. |
| 3266 | mNextAppTransition = transit; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3267 | } |
| 3268 | mAppTransitionReady = false; |
| 3269 | mAppTransitionTimeout = false; |
| 3270 | mStartingIconInTransition = false; |
| 3271 | mSkipAppTransitionAnimation = false; |
| 3272 | mH.removeMessages(H.APP_TRANSITION_TIMEOUT); |
| 3273 | mH.sendMessageDelayed(mH.obtainMessage(H.APP_TRANSITION_TIMEOUT), |
| 3274 | 5000); |
| 3275 | } |
| 3276 | } |
| 3277 | } |
| 3278 | |
| 3279 | public int getPendingAppTransition() { |
| 3280 | return mNextAppTransition; |
| 3281 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3282 | |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 3283 | public void overridePendingAppTransition(String packageName, |
| 3284 | int enterAnim, int exitAnim) { |
Dianne Hackborn | 8b571a8 | 2009-09-25 16:09:43 -0700 | [diff] [blame] | 3285 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 3286 | mNextAppTransitionPackage = packageName; |
| 3287 | mNextAppTransitionEnter = enterAnim; |
| 3288 | mNextAppTransitionExit = exitAnim; |
| 3289 | } |
| 3290 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3291 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3292 | public void executeAppTransition() { |
| 3293 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3294 | "executeAppTransition()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3295 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3296 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3297 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3298 | synchronized(mWindowMap) { |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 3299 | if (DEBUG_APP_TRANSITIONS) { |
| 3300 | RuntimeException e = new RuntimeException("here"); |
| 3301 | e.fillInStackTrace(); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3302 | Slog.w(TAG, "Execute app transition: mNextAppTransition=" |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 3303 | + mNextAppTransition, e); |
| 3304 | } |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 3305 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3306 | mAppTransitionReady = true; |
| 3307 | final long origId = Binder.clearCallingIdentity(); |
| 3308 | performLayoutAndPlaceSurfacesLocked(); |
| 3309 | Binder.restoreCallingIdentity(origId); |
| 3310 | } |
| 3311 | } |
| 3312 | } |
| 3313 | |
| 3314 | public void setAppStartingWindow(IBinder token, String pkg, |
| 3315 | int theme, CharSequence nonLocalizedLabel, int labelRes, int icon, |
| 3316 | IBinder transferFrom, boolean createIfNeeded) { |
| 3317 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3318 | "setAppStartingIcon()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3319 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3320 | } |
| 3321 | |
| 3322 | synchronized(mWindowMap) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3323 | if (DEBUG_STARTING_WINDOW) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3324 | TAG, "setAppStartingIcon: token=" + token + " pkg=" + pkg |
| 3325 | + " transferFrom=" + transferFrom); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3326 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3327 | AppWindowToken wtoken = findAppWindowToken(token); |
| 3328 | if (wtoken == null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3329 | 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] | 3330 | return; |
| 3331 | } |
| 3332 | |
| 3333 | // If the display is frozen, we won't do anything until the |
| 3334 | // actual window is displayed so there is no reason to put in |
| 3335 | // the starting window. |
Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 3336 | if (mDisplayFrozen || !mPolicy.isScreenOn()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3337 | return; |
| 3338 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3339 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3340 | if (wtoken.startingData != null) { |
| 3341 | return; |
| 3342 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3343 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3344 | if (transferFrom != null) { |
| 3345 | AppWindowToken ttoken = findAppWindowToken(transferFrom); |
| 3346 | if (ttoken != null) { |
| 3347 | WindowState startingWindow = ttoken.startingWindow; |
| 3348 | if (startingWindow != null) { |
| 3349 | if (mStartingIconInTransition) { |
| 3350 | // In this case, the starting icon has already |
| 3351 | // been displayed, so start letting windows get |
| 3352 | // shown immediately without any more transitions. |
| 3353 | mSkipAppTransitionAnimation = true; |
| 3354 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3355 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3356 | "Moving existing starting from " + ttoken |
| 3357 | + " to " + wtoken); |
| 3358 | final long origId = Binder.clearCallingIdentity(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3359 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3360 | // Transfer the starting window over to the new |
| 3361 | // token. |
| 3362 | wtoken.startingData = ttoken.startingData; |
| 3363 | wtoken.startingView = ttoken.startingView; |
| 3364 | wtoken.startingWindow = startingWindow; |
| 3365 | ttoken.startingData = null; |
| 3366 | ttoken.startingView = null; |
| 3367 | ttoken.startingWindow = null; |
| 3368 | ttoken.startingMoved = true; |
| 3369 | startingWindow.mToken = wtoken; |
Dianne Hackborn | ef49c57 | 2009-03-24 19:27:32 -0700 | [diff] [blame] | 3370 | startingWindow.mRootToken = wtoken; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3371 | startingWindow.mAppToken = wtoken; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3372 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 3373 | "Removing starting window: " + startingWindow); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3374 | mWindows.remove(startingWindow); |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 3375 | mWindowsChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3376 | ttoken.windows.remove(startingWindow); |
| 3377 | ttoken.allAppWindows.remove(startingWindow); |
| 3378 | addWindowToListInOrderLocked(startingWindow, true); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3379 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3380 | // Propagate other interesting state between the |
| 3381 | // tokens. If the old token is displayed, we should |
| 3382 | // immediately force the new one to be displayed. If |
| 3383 | // it is animating, we need to move that animation to |
| 3384 | // the new one. |
| 3385 | if (ttoken.allDrawn) { |
| 3386 | wtoken.allDrawn = true; |
| 3387 | } |
| 3388 | if (ttoken.firstWindowDrawn) { |
| 3389 | wtoken.firstWindowDrawn = true; |
| 3390 | } |
| 3391 | if (!ttoken.hidden) { |
| 3392 | wtoken.hidden = false; |
| 3393 | wtoken.hiddenRequested = false; |
| 3394 | wtoken.willBeHidden = false; |
| 3395 | } |
| 3396 | if (wtoken.clientHidden != ttoken.clientHidden) { |
| 3397 | wtoken.clientHidden = ttoken.clientHidden; |
| 3398 | wtoken.sendAppVisibilityToClients(); |
| 3399 | } |
| 3400 | if (ttoken.animation != null) { |
| 3401 | wtoken.animation = ttoken.animation; |
| 3402 | wtoken.animating = ttoken.animating; |
| 3403 | wtoken.animLayerAdjustment = ttoken.animLayerAdjustment; |
| 3404 | ttoken.animation = null; |
| 3405 | ttoken.animLayerAdjustment = 0; |
| 3406 | wtoken.updateLayers(); |
| 3407 | ttoken.updateLayers(); |
| 3408 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3409 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3410 | updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3411 | mLayoutNeeded = true; |
| 3412 | performLayoutAndPlaceSurfacesLocked(); |
| 3413 | Binder.restoreCallingIdentity(origId); |
| 3414 | return; |
| 3415 | } else if (ttoken.startingData != null) { |
| 3416 | // The previous app was getting ready to show a |
| 3417 | // starting window, but hasn't yet done so. Steal it! |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3418 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3419 | "Moving pending starting from " + ttoken |
| 3420 | + " to " + wtoken); |
| 3421 | wtoken.startingData = ttoken.startingData; |
| 3422 | ttoken.startingData = null; |
| 3423 | ttoken.startingMoved = true; |
| 3424 | Message m = mH.obtainMessage(H.ADD_STARTING, wtoken); |
| 3425 | // Note: we really want to do sendMessageAtFrontOfQueue() because we |
| 3426 | // want to process the message ASAP, before any other queued |
| 3427 | // messages. |
| 3428 | mH.sendMessageAtFrontOfQueue(m); |
| 3429 | return; |
| 3430 | } |
| 3431 | } |
| 3432 | } |
| 3433 | |
| 3434 | // There is no existing starting window, and the caller doesn't |
| 3435 | // want us to create one, so that's it! |
| 3436 | if (!createIfNeeded) { |
| 3437 | return; |
| 3438 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3439 | |
Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 3440 | // If this is a translucent or wallpaper window, then don't |
| 3441 | // show a starting window -- the current effect (a full-screen |
| 3442 | // opaque starting window that fades away to the real contents |
| 3443 | // when it is ready) does not work for this. |
| 3444 | if (theme != 0) { |
| 3445 | AttributeCache.Entry ent = AttributeCache.instance().get(pkg, theme, |
| 3446 | com.android.internal.R.styleable.Window); |
| 3447 | if (ent.array.getBoolean( |
| 3448 | com.android.internal.R.styleable.Window_windowIsTranslucent, false)) { |
| 3449 | return; |
| 3450 | } |
| 3451 | if (ent.array.getBoolean( |
Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 3452 | com.android.internal.R.styleable.Window_windowIsFloating, false)) { |
| 3453 | return; |
| 3454 | } |
| 3455 | if (ent.array.getBoolean( |
Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 3456 | com.android.internal.R.styleable.Window_windowShowWallpaper, false)) { |
| 3457 | return; |
| 3458 | } |
| 3459 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3460 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3461 | mStartingIconInTransition = true; |
| 3462 | wtoken.startingData = new StartingData( |
| 3463 | pkg, theme, nonLocalizedLabel, |
| 3464 | labelRes, icon); |
| 3465 | Message m = mH.obtainMessage(H.ADD_STARTING, wtoken); |
| 3466 | // Note: we really want to do sendMessageAtFrontOfQueue() because we |
| 3467 | // want to process the message ASAP, before any other queued |
| 3468 | // messages. |
| 3469 | mH.sendMessageAtFrontOfQueue(m); |
| 3470 | } |
| 3471 | } |
| 3472 | |
| 3473 | public void setAppWillBeHidden(IBinder token) { |
| 3474 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3475 | "setAppWillBeHidden()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3476 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3477 | } |
| 3478 | |
| 3479 | AppWindowToken wtoken; |
| 3480 | |
| 3481 | synchronized(mWindowMap) { |
| 3482 | wtoken = findAppWindowToken(token); |
| 3483 | if (wtoken == null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3484 | 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] | 3485 | return; |
| 3486 | } |
| 3487 | wtoken.willBeHidden = true; |
| 3488 | } |
| 3489 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3490 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3491 | boolean setTokenVisibilityLocked(AppWindowToken wtoken, WindowManager.LayoutParams lp, |
| 3492 | boolean visible, int transit, boolean performLayout) { |
| 3493 | boolean delayed = false; |
| 3494 | |
| 3495 | if (wtoken.clientHidden == visible) { |
| 3496 | wtoken.clientHidden = !visible; |
| 3497 | wtoken.sendAppVisibilityToClients(); |
| 3498 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3499 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3500 | wtoken.willBeHidden = false; |
| 3501 | if (wtoken.hidden == visible) { |
| 3502 | final int N = wtoken.allAppWindows.size(); |
| 3503 | boolean changed = false; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3504 | if (DEBUG_APP_TRANSITIONS) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3505 | TAG, "Changing app " + wtoken + " hidden=" + wtoken.hidden |
| 3506 | + " performLayout=" + performLayout); |
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 | boolean runningAppAnimation = false; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3509 | |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 3510 | if (transit != WindowManagerPolicy.TRANSIT_UNSET) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3511 | if (wtoken.animation == sDummyAnimation) { |
| 3512 | wtoken.animation = null; |
| 3513 | } |
| 3514 | applyAnimationLocked(wtoken, lp, transit, visible); |
| 3515 | changed = true; |
| 3516 | if (wtoken.animation != null) { |
| 3517 | delayed = runningAppAnimation = true; |
| 3518 | } |
| 3519 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3520 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3521 | for (int i=0; i<N; i++) { |
| 3522 | WindowState win = wtoken.allAppWindows.get(i); |
| 3523 | if (win == wtoken.startingWindow) { |
| 3524 | continue; |
| 3525 | } |
| 3526 | |
| 3527 | if (win.isAnimating()) { |
| 3528 | delayed = true; |
| 3529 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3530 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3531 | //Slog.i(TAG, "Window " + win + ": vis=" + win.isVisible()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3532 | //win.dump(" "); |
| 3533 | if (visible) { |
| 3534 | if (!win.isVisibleNow()) { |
| 3535 | if (!runningAppAnimation) { |
| 3536 | applyAnimationLocked(win, |
| 3537 | WindowManagerPolicy.TRANSIT_ENTER, true); |
| 3538 | } |
| 3539 | changed = true; |
| 3540 | } |
| 3541 | } else if (win.isVisibleNow()) { |
| 3542 | if (!runningAppAnimation) { |
| 3543 | applyAnimationLocked(win, |
| 3544 | WindowManagerPolicy.TRANSIT_EXIT, false); |
| 3545 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3546 | changed = true; |
| 3547 | } |
| 3548 | } |
| 3549 | |
| 3550 | wtoken.hidden = wtoken.hiddenRequested = !visible; |
| 3551 | if (!visible) { |
| 3552 | unsetAppFreezingScreenLocked(wtoken, true, true); |
| 3553 | } else { |
| 3554 | // If we are being set visible, and the starting window is |
| 3555 | // not yet displayed, then make sure it doesn't get displayed. |
| 3556 | WindowState swin = wtoken.startingWindow; |
| 3557 | if (swin != null && (swin.mDrawPending |
| 3558 | || swin.mCommitDrawPending)) { |
| 3559 | swin.mPolicyVisibility = false; |
| 3560 | swin.mPolicyVisibilityAfterAnim = false; |
| 3561 | } |
| 3562 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3563 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3564 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "setTokenVisibilityLocked: " + wtoken |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3565 | + ": hidden=" + wtoken.hidden + " hiddenRequested=" |
| 3566 | + wtoken.hiddenRequested); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3567 | |
Dianne Hackborn | 9b52a21 | 2009-12-11 14:51:35 -0800 | [diff] [blame] | 3568 | if (changed) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3569 | mLayoutNeeded = true; |
Dianne Hackborn | 9b52a21 | 2009-12-11 14:51:35 -0800 | [diff] [blame] | 3570 | if (performLayout) { |
| 3571 | updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES); |
| 3572 | performLayoutAndPlaceSurfacesLocked(); |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 3573 | } else { |
| 3574 | mInputMonitor.updateInputWindowsLw(); |
Dianne Hackborn | 9b52a21 | 2009-12-11 14:51:35 -0800 | [diff] [blame] | 3575 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3576 | } |
| 3577 | } |
| 3578 | |
| 3579 | if (wtoken.animation != null) { |
| 3580 | delayed = true; |
| 3581 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3582 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3583 | return delayed; |
| 3584 | } |
| 3585 | |
| 3586 | public void setAppVisibility(IBinder token, boolean visible) { |
| 3587 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3588 | "setAppVisibility()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3589 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3590 | } |
| 3591 | |
| 3592 | AppWindowToken wtoken; |
| 3593 | |
| 3594 | synchronized(mWindowMap) { |
| 3595 | wtoken = findAppWindowToken(token); |
| 3596 | if (wtoken == null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3597 | 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] | 3598 | return; |
| 3599 | } |
| 3600 | |
| 3601 | if (DEBUG_APP_TRANSITIONS || DEBUG_ORIENTATION) { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 3602 | RuntimeException e = null; |
| 3603 | if (!HIDE_STACK_CRAWLS) { |
| 3604 | e = new RuntimeException(); |
| 3605 | e.fillInStackTrace(); |
| 3606 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3607 | Slog.v(TAG, "setAppVisibility(" + token + ", " + visible |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3608 | + "): mNextAppTransition=" + mNextAppTransition |
| 3609 | + " hidden=" + wtoken.hidden |
| 3610 | + " hiddenRequested=" + wtoken.hiddenRequested, e); |
| 3611 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3612 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3613 | // If we are preparing an app transition, then delay changing |
| 3614 | // the visibility of this token until we execute that transition. |
Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 3615 | if (!mDisplayFrozen && mPolicy.isScreenOn() |
| 3616 | && mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3617 | // Already in requested state, don't do anything more. |
| 3618 | if (wtoken.hiddenRequested != visible) { |
| 3619 | return; |
| 3620 | } |
| 3621 | wtoken.hiddenRequested = !visible; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3622 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3623 | if (DEBUG_APP_TRANSITIONS) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3624 | TAG, "Setting dummy animation on: " + wtoken); |
| 3625 | wtoken.setDummyAnimation(); |
| 3626 | mOpeningApps.remove(wtoken); |
| 3627 | mClosingApps.remove(wtoken); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 3628 | wtoken.waitingToShow = wtoken.waitingToHide = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3629 | wtoken.inPendingTransaction = true; |
| 3630 | if (visible) { |
| 3631 | mOpeningApps.add(wtoken); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3632 | wtoken.startingDisplayed = false; |
| 3633 | wtoken.startingMoved = false; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3634 | |
Dianne Hackborn | 195f6a0 | 2009-11-24 11:26:00 -0800 | [diff] [blame] | 3635 | // If the token is currently hidden (should be the |
| 3636 | // common case), then we need to set up to wait for |
| 3637 | // its windows to be ready. |
| 3638 | if (wtoken.hidden) { |
| 3639 | wtoken.allDrawn = false; |
| 3640 | wtoken.waitingToShow = true; |
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 (wtoken.clientHidden) { |
| 3643 | // In the case where we are making an app visible |
| 3644 | // but holding off for a transition, we still need |
| 3645 | // to tell the client to make its windows visible so |
| 3646 | // they get drawn. Otherwise, we will wait on |
| 3647 | // performing the transition until all windows have |
| 3648 | // been drawn, they never will be, and we are sad. |
| 3649 | wtoken.clientHidden = false; |
| 3650 | wtoken.sendAppVisibilityToClients(); |
| 3651 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3652 | } |
| 3653 | } else { |
| 3654 | mClosingApps.add(wtoken); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3655 | |
Dianne Hackborn | 195f6a0 | 2009-11-24 11:26:00 -0800 | [diff] [blame] | 3656 | // If the token is currently visible (should be the |
| 3657 | // common case), then set up to wait for it to be hidden. |
| 3658 | if (!wtoken.hidden) { |
| 3659 | wtoken.waitingToHide = true; |
| 3660 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3661 | } |
| 3662 | return; |
| 3663 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3664 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3665 | final long origId = Binder.clearCallingIdentity(); |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 3666 | setTokenVisibilityLocked(wtoken, null, visible, WindowManagerPolicy.TRANSIT_UNSET, true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3667 | wtoken.updateReportedVisibilityLocked(); |
| 3668 | Binder.restoreCallingIdentity(origId); |
| 3669 | } |
| 3670 | } |
| 3671 | |
| 3672 | void unsetAppFreezingScreenLocked(AppWindowToken wtoken, |
| 3673 | boolean unfreezeSurfaceNow, boolean force) { |
| 3674 | if (wtoken.freezingScreen) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3675 | 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] | 3676 | + " force=" + force); |
| 3677 | final int N = wtoken.allAppWindows.size(); |
| 3678 | boolean unfrozeWindows = false; |
| 3679 | for (int i=0; i<N; i++) { |
| 3680 | WindowState w = wtoken.allAppWindows.get(i); |
| 3681 | if (w.mAppFreezing) { |
| 3682 | w.mAppFreezing = false; |
| 3683 | if (w.mSurface != null && !w.mOrientationChanging) { |
| 3684 | w.mOrientationChanging = true; |
| 3685 | } |
| 3686 | unfrozeWindows = true; |
| 3687 | } |
| 3688 | } |
| 3689 | if (force || unfrozeWindows) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3690 | 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] | 3691 | wtoken.freezingScreen = false; |
| 3692 | mAppsFreezingScreen--; |
| 3693 | } |
| 3694 | if (unfreezeSurfaceNow) { |
| 3695 | if (unfrozeWindows) { |
| 3696 | mLayoutNeeded = true; |
| 3697 | performLayoutAndPlaceSurfacesLocked(); |
| 3698 | } |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3699 | stopFreezingDisplayLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3700 | } |
| 3701 | } |
| 3702 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3703 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3704 | public void startAppFreezingScreenLocked(AppWindowToken wtoken, |
| 3705 | int configChanges) { |
| 3706 | if (DEBUG_ORIENTATION) { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 3707 | RuntimeException e = null; |
| 3708 | if (!HIDE_STACK_CRAWLS) { |
| 3709 | e = new RuntimeException(); |
| 3710 | e.fillInStackTrace(); |
| 3711 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3712 | Slog.i(TAG, "Set freezing of " + wtoken.appToken |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3713 | + ": hidden=" + wtoken.hidden + " freezing=" |
| 3714 | + wtoken.freezingScreen, e); |
| 3715 | } |
| 3716 | if (!wtoken.hiddenRequested) { |
| 3717 | if (!wtoken.freezingScreen) { |
| 3718 | wtoken.freezingScreen = true; |
| 3719 | mAppsFreezingScreen++; |
| 3720 | if (mAppsFreezingScreen == 1) { |
| 3721 | startFreezingDisplayLocked(); |
| 3722 | mH.removeMessages(H.APP_FREEZE_TIMEOUT); |
| 3723 | mH.sendMessageDelayed(mH.obtainMessage(H.APP_FREEZE_TIMEOUT), |
| 3724 | 5000); |
| 3725 | } |
| 3726 | } |
| 3727 | final int N = wtoken.allAppWindows.size(); |
| 3728 | for (int i=0; i<N; i++) { |
| 3729 | WindowState w = wtoken.allAppWindows.get(i); |
| 3730 | w.mAppFreezing = true; |
| 3731 | } |
| 3732 | } |
| 3733 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3734 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3735 | public void startAppFreezingScreen(IBinder token, int configChanges) { |
| 3736 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3737 | "setAppFreezingScreen()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3738 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3739 | } |
| 3740 | |
| 3741 | synchronized(mWindowMap) { |
Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 3742 | if (configChanges == 0 && !mDisplayFrozen && mPolicy.isScreenOn()) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3743 | 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] | 3744 | return; |
| 3745 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3746 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3747 | AppWindowToken wtoken = findAppWindowToken(token); |
| 3748 | if (wtoken == null || wtoken.appToken == null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3749 | 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] | 3750 | return; |
| 3751 | } |
| 3752 | final long origId = Binder.clearCallingIdentity(); |
| 3753 | startAppFreezingScreenLocked(wtoken, configChanges); |
| 3754 | Binder.restoreCallingIdentity(origId); |
| 3755 | } |
| 3756 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3757 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3758 | public void stopAppFreezingScreen(IBinder token, boolean force) { |
| 3759 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3760 | "setAppFreezingScreen()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3761 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3762 | } |
| 3763 | |
| 3764 | synchronized(mWindowMap) { |
| 3765 | AppWindowToken wtoken = findAppWindowToken(token); |
| 3766 | if (wtoken == null || wtoken.appToken == null) { |
| 3767 | return; |
| 3768 | } |
| 3769 | final long origId = Binder.clearCallingIdentity(); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3770 | 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] | 3771 | + ": hidden=" + wtoken.hidden + " freezing=" + wtoken.freezingScreen); |
| 3772 | unsetAppFreezingScreenLocked(wtoken, true, force); |
| 3773 | Binder.restoreCallingIdentity(origId); |
| 3774 | } |
| 3775 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3776 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3777 | public void removeAppToken(IBinder token) { |
| 3778 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3779 | "removeAppToken()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3780 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3781 | } |
| 3782 | |
| 3783 | AppWindowToken wtoken = null; |
| 3784 | AppWindowToken startingToken = null; |
| 3785 | boolean delayed = false; |
| 3786 | |
| 3787 | final long origId = Binder.clearCallingIdentity(); |
| 3788 | synchronized(mWindowMap) { |
| 3789 | WindowToken basewtoken = mTokenMap.remove(token); |
| 3790 | mTokenList.remove(basewtoken); |
| 3791 | if (basewtoken != null && (wtoken=basewtoken.appWindowToken) != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3792 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "Removing app token: " + wtoken); |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 3793 | delayed = setTokenVisibilityLocked(wtoken, null, false, WindowManagerPolicy.TRANSIT_UNSET, true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3794 | wtoken.inPendingTransaction = false; |
| 3795 | mOpeningApps.remove(wtoken); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 3796 | wtoken.waitingToShow = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3797 | if (mClosingApps.contains(wtoken)) { |
| 3798 | delayed = true; |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 3799 | } else if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3800 | mClosingApps.add(wtoken); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 3801 | wtoken.waitingToHide = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3802 | delayed = true; |
| 3803 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3804 | if (DEBUG_APP_TRANSITIONS) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3805 | TAG, "Removing app " + wtoken + " delayed=" + delayed |
| 3806 | + " animation=" + wtoken.animation |
| 3807 | + " animating=" + wtoken.animating); |
| 3808 | if (delayed) { |
| 3809 | // set the token aside because it has an active animation to be finished |
| 3810 | mExitingAppTokens.add(wtoken); |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 3811 | } else { |
| 3812 | // Make sure there is no animation running on this token, |
| 3813 | // so any windows associated with it will be removed as |
| 3814 | // soon as their animations are complete |
| 3815 | wtoken.animation = null; |
| 3816 | wtoken.animating = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3817 | } |
| 3818 | mAppTokens.remove(wtoken); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 3819 | if (mLastEnterAnimToken == wtoken) { |
| 3820 | mLastEnterAnimToken = null; |
| 3821 | mLastEnterAnimParams = null; |
| 3822 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3823 | wtoken.removed = true; |
| 3824 | if (wtoken.startingData != null) { |
| 3825 | startingToken = wtoken; |
| 3826 | } |
| 3827 | unsetAppFreezingScreenLocked(wtoken, true, true); |
| 3828 | if (mFocusedApp == wtoken) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3829 | 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] | 3830 | mFocusedApp = null; |
| 3831 | updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL); |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 3832 | mInputMonitor.setFocusedAppLw(null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3833 | } |
| 3834 | } else { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3835 | 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] | 3836 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3837 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3838 | if (!delayed && wtoken != null) { |
| 3839 | wtoken.updateReportedVisibilityLocked(); |
| 3840 | } |
| 3841 | } |
| 3842 | Binder.restoreCallingIdentity(origId); |
| 3843 | |
| 3844 | if (startingToken != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3845 | 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] | 3846 | + startingToken + ": app token removed"); |
| 3847 | Message m = mH.obtainMessage(H.REMOVE_STARTING, startingToken); |
| 3848 | mH.sendMessage(m); |
| 3849 | } |
| 3850 | } |
| 3851 | |
| 3852 | private boolean tmpRemoveAppWindowsLocked(WindowToken token) { |
| 3853 | final int NW = token.windows.size(); |
| 3854 | for (int i=0; i<NW; i++) { |
| 3855 | WindowState win = token.windows.get(i); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3856 | 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] | 3857 | mWindows.remove(win); |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 3858 | mWindowsChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3859 | int j = win.mChildWindows.size(); |
| 3860 | while (j > 0) { |
| 3861 | j--; |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 3862 | WindowState cwin = win.mChildWindows.get(j); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3863 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, |
Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 3864 | "Tmp removing child window " + cwin); |
| 3865 | mWindows.remove(cwin); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3866 | } |
| 3867 | } |
| 3868 | return NW > 0; |
| 3869 | } |
| 3870 | |
| 3871 | void dumpAppTokensLocked() { |
| 3872 | for (int i=mAppTokens.size()-1; i>=0; i--) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3873 | Slog.v(TAG, " #" + i + ": " + mAppTokens.get(i).token); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3874 | } |
| 3875 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3876 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3877 | void dumpWindowsLocked() { |
| 3878 | for (int i=mWindows.size()-1; i>=0; i--) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3879 | Slog.v(TAG, " #" + i + ": " + mWindows.get(i)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3880 | } |
| 3881 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3882 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3883 | private int findWindowOffsetLocked(int tokenPos) { |
| 3884 | final int NW = mWindows.size(); |
| 3885 | |
| 3886 | if (tokenPos >= mAppTokens.size()) { |
| 3887 | int i = NW; |
| 3888 | while (i > 0) { |
| 3889 | i--; |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 3890 | WindowState win = mWindows.get(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3891 | if (win.getAppToken() != null) { |
| 3892 | return i+1; |
| 3893 | } |
| 3894 | } |
| 3895 | } |
| 3896 | |
| 3897 | while (tokenPos > 0) { |
| 3898 | // Find the first app token below the new position that has |
| 3899 | // a window displayed. |
| 3900 | final AppWindowToken wtoken = mAppTokens.get(tokenPos-1); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3901 | 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] | 3902 | + tokenPos + " -- " + wtoken.token); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 3903 | if (wtoken.sendingToBottom) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3904 | if (DEBUG_REORDER) Slog.v(TAG, |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 3905 | "Skipping token -- currently sending to bottom"); |
| 3906 | tokenPos--; |
| 3907 | continue; |
| 3908 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3909 | int i = wtoken.windows.size(); |
| 3910 | while (i > 0) { |
| 3911 | i--; |
| 3912 | WindowState win = wtoken.windows.get(i); |
| 3913 | int j = win.mChildWindows.size(); |
| 3914 | while (j > 0) { |
| 3915 | j--; |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 3916 | WindowState cwin = win.mChildWindows.get(j); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 3917 | if (cwin.mSubLayer >= 0) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3918 | for (int pos=NW-1; pos>=0; pos--) { |
| 3919 | if (mWindows.get(pos) == cwin) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3920 | if (DEBUG_REORDER) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3921 | "Found child win @" + (pos+1)); |
| 3922 | return pos+1; |
| 3923 | } |
| 3924 | } |
| 3925 | } |
| 3926 | } |
| 3927 | for (int pos=NW-1; pos>=0; pos--) { |
| 3928 | if (mWindows.get(pos) == win) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3929 | 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] | 3930 | return pos+1; |
| 3931 | } |
| 3932 | } |
| 3933 | } |
| 3934 | tokenPos--; |
| 3935 | } |
| 3936 | |
| 3937 | return 0; |
| 3938 | } |
| 3939 | |
| 3940 | private final int reAddWindowLocked(int index, WindowState win) { |
| 3941 | final int NCW = win.mChildWindows.size(); |
| 3942 | boolean added = false; |
| 3943 | for (int j=0; j<NCW; j++) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 3944 | WindowState cwin = win.mChildWindows.get(j); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3945 | if (!added && cwin.mSubLayer >= 0) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3946 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding child window at " |
Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 3947 | + index + ": " + cwin); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3948 | mWindows.add(index, win); |
| 3949 | index++; |
| 3950 | added = true; |
| 3951 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3952 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding window at " |
Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 3953 | + index + ": " + cwin); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3954 | mWindows.add(index, cwin); |
| 3955 | index++; |
| 3956 | } |
| 3957 | if (!added) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3958 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding window at " |
Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 3959 | + index + ": " + win); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3960 | mWindows.add(index, win); |
| 3961 | index++; |
| 3962 | } |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 3963 | mWindowsChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3964 | return index; |
| 3965 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3966 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3967 | private final int reAddAppWindowsLocked(int index, WindowToken token) { |
| 3968 | final int NW = token.windows.size(); |
| 3969 | for (int i=0; i<NW; i++) { |
| 3970 | index = reAddWindowLocked(index, token.windows.get(i)); |
| 3971 | } |
| 3972 | return index; |
| 3973 | } |
| 3974 | |
| 3975 | public void moveAppToken(int index, IBinder token) { |
| 3976 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3977 | "moveAppToken()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3978 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3979 | } |
| 3980 | |
| 3981 | synchronized(mWindowMap) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3982 | if (DEBUG_REORDER) Slog.v(TAG, "Initial app tokens:"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3983 | if (DEBUG_REORDER) dumpAppTokensLocked(); |
| 3984 | final AppWindowToken wtoken = findAppWindowToken(token); |
| 3985 | if (wtoken == null || !mAppTokens.remove(wtoken)) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3986 | 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] | 3987 | + token + " (" + wtoken + ")"); |
| 3988 | return; |
| 3989 | } |
| 3990 | mAppTokens.add(index, wtoken); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3991 | 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] | 3992 | if (DEBUG_REORDER) dumpAppTokensLocked(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3993 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3994 | final long origId = Binder.clearCallingIdentity(); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3995 | 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] | 3996 | if (DEBUG_REORDER) dumpWindowsLocked(); |
| 3997 | if (tmpRemoveAppWindowsLocked(wtoken)) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3998 | 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] | 3999 | if (DEBUG_REORDER) dumpWindowsLocked(); |
| 4000 | reAddAppWindowsLocked(findWindowOffsetLocked(index), wtoken); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4001 | if (DEBUG_REORDER) Slog.v(TAG, "Final window list:"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4002 | if (DEBUG_REORDER) dumpWindowsLocked(); |
| 4003 | updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4004 | mLayoutNeeded = true; |
| 4005 | performLayoutAndPlaceSurfacesLocked(); |
| 4006 | } |
| 4007 | Binder.restoreCallingIdentity(origId); |
| 4008 | } |
| 4009 | } |
| 4010 | |
| 4011 | private void removeAppTokensLocked(List<IBinder> tokens) { |
| 4012 | // XXX This should be done more efficiently! |
| 4013 | // (take advantage of the fact that both lists should be |
| 4014 | // ordered in the same way.) |
| 4015 | int N = tokens.size(); |
| 4016 | for (int i=0; i<N; i++) { |
| 4017 | IBinder token = tokens.get(i); |
| 4018 | final AppWindowToken wtoken = findAppWindowToken(token); |
| 4019 | if (!mAppTokens.remove(wtoken)) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4020 | 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] | 4021 | + token + " (" + wtoken + ")"); |
| 4022 | i--; |
| 4023 | N--; |
| 4024 | } |
| 4025 | } |
| 4026 | } |
| 4027 | |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4028 | private void moveAppWindowsLocked(AppWindowToken wtoken, int tokenPos, |
| 4029 | boolean updateFocusAndLayout) { |
| 4030 | // First remove all of the windows from the list. |
| 4031 | tmpRemoveAppWindowsLocked(wtoken); |
| 4032 | |
| 4033 | // Where to start adding? |
| 4034 | int pos = findWindowOffsetLocked(tokenPos); |
| 4035 | |
| 4036 | // And now add them back at the correct place. |
| 4037 | pos = reAddAppWindowsLocked(pos, wtoken); |
| 4038 | |
| 4039 | if (updateFocusAndLayout) { |
| 4040 | if (!updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES)) { |
| 4041 | assignLayersLocked(); |
| 4042 | } |
| 4043 | mLayoutNeeded = true; |
| 4044 | performLayoutAndPlaceSurfacesLocked(); |
| 4045 | } |
| 4046 | } |
| 4047 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4048 | private void moveAppWindowsLocked(List<IBinder> tokens, int tokenPos) { |
| 4049 | // First remove all of the windows from the list. |
| 4050 | final int N = tokens.size(); |
| 4051 | int i; |
| 4052 | for (i=0; i<N; i++) { |
| 4053 | WindowToken token = mTokenMap.get(tokens.get(i)); |
| 4054 | if (token != null) { |
| 4055 | tmpRemoveAppWindowsLocked(token); |
| 4056 | } |
| 4057 | } |
| 4058 | |
| 4059 | // Where to start adding? |
| 4060 | int pos = findWindowOffsetLocked(tokenPos); |
| 4061 | |
| 4062 | // And now add them back at the correct place. |
| 4063 | for (i=0; i<N; i++) { |
| 4064 | WindowToken token = mTokenMap.get(tokens.get(i)); |
| 4065 | if (token != null) { |
| 4066 | pos = reAddAppWindowsLocked(pos, token); |
| 4067 | } |
| 4068 | } |
| 4069 | |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4070 | if (!updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES)) { |
| 4071 | assignLayersLocked(); |
| 4072 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4073 | mLayoutNeeded = true; |
| 4074 | performLayoutAndPlaceSurfacesLocked(); |
| 4075 | |
| 4076 | //dump(); |
| 4077 | } |
| 4078 | |
| 4079 | public void moveAppTokensToTop(List<IBinder> tokens) { |
| 4080 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 4081 | "moveAppTokensToTop()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4082 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4083 | } |
| 4084 | |
| 4085 | final long origId = Binder.clearCallingIdentity(); |
| 4086 | synchronized(mWindowMap) { |
| 4087 | removeAppTokensLocked(tokens); |
| 4088 | final int N = tokens.size(); |
| 4089 | for (int i=0; i<N; i++) { |
| 4090 | AppWindowToken wt = findAppWindowToken(tokens.get(i)); |
| 4091 | if (wt != null) { |
| 4092 | mAppTokens.add(wt); |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 4093 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4094 | mToTopApps.remove(wt); |
| 4095 | mToBottomApps.remove(wt); |
| 4096 | mToTopApps.add(wt); |
| 4097 | wt.sendingToBottom = false; |
| 4098 | wt.sendingToTop = true; |
| 4099 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4100 | } |
| 4101 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 4102 | |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 4103 | if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET) { |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4104 | moveAppWindowsLocked(tokens, mAppTokens.size()); |
| 4105 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4106 | } |
| 4107 | Binder.restoreCallingIdentity(origId); |
| 4108 | } |
| 4109 | |
| 4110 | public void moveAppTokensToBottom(List<IBinder> tokens) { |
| 4111 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 4112 | "moveAppTokensToBottom()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4113 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4114 | } |
| 4115 | |
| 4116 | final long origId = Binder.clearCallingIdentity(); |
| 4117 | synchronized(mWindowMap) { |
| 4118 | removeAppTokensLocked(tokens); |
| 4119 | final int N = tokens.size(); |
| 4120 | int pos = 0; |
| 4121 | for (int i=0; i<N; i++) { |
| 4122 | AppWindowToken wt = findAppWindowToken(tokens.get(i)); |
| 4123 | if (wt != null) { |
| 4124 | mAppTokens.add(pos, wt); |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 4125 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4126 | mToTopApps.remove(wt); |
| 4127 | mToBottomApps.remove(wt); |
| 4128 | mToBottomApps.add(i, wt); |
| 4129 | wt.sendingToTop = false; |
| 4130 | wt.sendingToBottom = true; |
| 4131 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4132 | pos++; |
| 4133 | } |
| 4134 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 4135 | |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 4136 | if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET) { |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4137 | moveAppWindowsLocked(tokens, 0); |
| 4138 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4139 | } |
| 4140 | Binder.restoreCallingIdentity(origId); |
| 4141 | } |
| 4142 | |
| 4143 | // ------------------------------------------------------------- |
| 4144 | // Misc IWindowSession methods |
| 4145 | // ------------------------------------------------------------- |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4146 | |
Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 4147 | private boolean shouldAllowDisableKeyguard() |
Jim Miller | d6b5705 | 2010-06-07 17:52:42 -0700 | [diff] [blame] | 4148 | { |
Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 4149 | // We fail safe and prevent disabling keyguard in the unlikely event this gets |
| 4150 | // called before DevicePolicyManagerService has started. |
| 4151 | if (mAllowDisableKeyguard == ALLOW_DISABLE_UNKNOWN) { |
| 4152 | DevicePolicyManager dpm = (DevicePolicyManager) mContext.getSystemService( |
| 4153 | Context.DEVICE_POLICY_SERVICE); |
| 4154 | if (dpm != null) { |
| 4155 | mAllowDisableKeyguard = dpm.getPasswordQuality(null) |
| 4156 | == DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED ? |
| 4157 | ALLOW_DISABLE_YES : ALLOW_DISABLE_NO; |
| 4158 | } |
Jim Miller | d6b5705 | 2010-06-07 17:52:42 -0700 | [diff] [blame] | 4159 | } |
Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 4160 | return mAllowDisableKeyguard == ALLOW_DISABLE_YES; |
Jim Miller | d6b5705 | 2010-06-07 17:52:42 -0700 | [diff] [blame] | 4161 | } |
| 4162 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4163 | public void disableKeyguard(IBinder token, String tag) { |
Mike Lockwood | 733fdf3 | 2009-09-28 19:08:53 -0400 | [diff] [blame] | 4164 | if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4165 | != PackageManager.PERMISSION_GRANTED) { |
| 4166 | throw new SecurityException("Requires DISABLE_KEYGUARD permission"); |
| 4167 | } |
Jim Miller | d6b5705 | 2010-06-07 17:52:42 -0700 | [diff] [blame] | 4168 | |
Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 4169 | synchronized (mKeyguardTokenWatcher) { |
| 4170 | mKeyguardTokenWatcher.acquire(token, tag); |
Mike Lockwood | dd88468 | 2009-10-11 16:57:08 -0400 | [diff] [blame] | 4171 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4172 | } |
| 4173 | |
| 4174 | public void reenableKeyguard(IBinder token) { |
Mike Lockwood | 733fdf3 | 2009-09-28 19:08:53 -0400 | [diff] [blame] | 4175 | if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4176 | != PackageManager.PERMISSION_GRANTED) { |
| 4177 | throw new SecurityException("Requires DISABLE_KEYGUARD permission"); |
| 4178 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4179 | |
Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 4180 | synchronized (mKeyguardTokenWatcher) { |
| 4181 | mKeyguardTokenWatcher.release(token); |
Jim Miller | d6b5705 | 2010-06-07 17:52:42 -0700 | [diff] [blame] | 4182 | |
Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 4183 | if (!mKeyguardTokenWatcher.isAcquired()) { |
| 4184 | // If we are the last one to reenable the keyguard wait until |
| 4185 | // we have actually finished reenabling until returning. |
| 4186 | // It is possible that reenableKeyguard() can be called before |
| 4187 | // the previous disableKeyguard() is handled, in which case |
| 4188 | // neither mKeyguardTokenWatcher.acquired() or released() would |
| 4189 | // be called. In that case mKeyguardDisabled will be false here |
| 4190 | // and we have nothing to wait for. |
| 4191 | while (mKeyguardDisabled) { |
| 4192 | try { |
| 4193 | mKeyguardTokenWatcher.wait(); |
| 4194 | } catch (InterruptedException e) { |
| 4195 | Thread.currentThread().interrupt(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4196 | } |
| 4197 | } |
| 4198 | } |
| 4199 | } |
| 4200 | } |
| 4201 | |
| 4202 | /** |
| 4203 | * @see android.app.KeyguardManager#exitKeyguardSecurely |
| 4204 | */ |
| 4205 | public void exitKeyguardSecurely(final IOnKeyguardExitResult callback) { |
Mike Lockwood | 733fdf3 | 2009-09-28 19:08:53 -0400 | [diff] [blame] | 4206 | if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4207 | != PackageManager.PERMISSION_GRANTED) { |
| 4208 | throw new SecurityException("Requires DISABLE_KEYGUARD permission"); |
| 4209 | } |
| 4210 | mPolicy.exitKeyguardSecurely(new WindowManagerPolicy.OnKeyguardExitResult() { |
| 4211 | public void onKeyguardExitResult(boolean success) { |
| 4212 | try { |
| 4213 | callback.onKeyguardExitResult(success); |
| 4214 | } catch (RemoteException e) { |
| 4215 | // Client has died, we don't care. |
| 4216 | } |
| 4217 | } |
| 4218 | }); |
| 4219 | } |
| 4220 | |
| 4221 | public boolean inKeyguardRestrictedInputMode() { |
| 4222 | return mPolicy.inKeyguardRestrictedKeyInputMode(); |
| 4223 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4224 | |
Dianne Hackborn | ffa4248 | 2009-09-23 22:20:11 -0700 | [diff] [blame] | 4225 | public void closeSystemDialogs(String reason) { |
| 4226 | synchronized(mWindowMap) { |
| 4227 | for (int i=mWindows.size()-1; i>=0; i--) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 4228 | WindowState w = mWindows.get(i); |
Dianne Hackborn | ffa4248 | 2009-09-23 22:20:11 -0700 | [diff] [blame] | 4229 | if (w.mSurface != null) { |
| 4230 | try { |
| 4231 | w.mClient.closeSystemDialogs(reason); |
| 4232 | } catch (RemoteException e) { |
| 4233 | } |
| 4234 | } |
| 4235 | } |
| 4236 | } |
| 4237 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 4238 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4239 | static float fixScale(float scale) { |
| 4240 | if (scale < 0) scale = 0; |
| 4241 | else if (scale > 20) scale = 20; |
| 4242 | return Math.abs(scale); |
| 4243 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4244 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4245 | public void setAnimationScale(int which, float scale) { |
| 4246 | if (!checkCallingPermission(android.Manifest.permission.SET_ANIMATION_SCALE, |
| 4247 | "setAnimationScale()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4248 | throw new SecurityException("Requires SET_ANIMATION_SCALE permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4249 | } |
| 4250 | |
| 4251 | if (scale < 0) scale = 0; |
| 4252 | else if (scale > 20) scale = 20; |
| 4253 | scale = Math.abs(scale); |
| 4254 | switch (which) { |
| 4255 | case 0: mWindowAnimationScale = fixScale(scale); break; |
| 4256 | case 1: mTransitionAnimationScale = fixScale(scale); break; |
| 4257 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4258 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4259 | // Persist setting |
| 4260 | mH.obtainMessage(H.PERSIST_ANIMATION_SCALE).sendToTarget(); |
| 4261 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4262 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4263 | public void setAnimationScales(float[] scales) { |
| 4264 | if (!checkCallingPermission(android.Manifest.permission.SET_ANIMATION_SCALE, |
| 4265 | "setAnimationScale()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4266 | throw new SecurityException("Requires SET_ANIMATION_SCALE permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4267 | } |
| 4268 | |
| 4269 | if (scales != null) { |
| 4270 | if (scales.length >= 1) { |
| 4271 | mWindowAnimationScale = fixScale(scales[0]); |
| 4272 | } |
| 4273 | if (scales.length >= 2) { |
| 4274 | mTransitionAnimationScale = fixScale(scales[1]); |
| 4275 | } |
| 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 | // Persist setting |
| 4279 | mH.obtainMessage(H.PERSIST_ANIMATION_SCALE).sendToTarget(); |
| 4280 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4281 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4282 | public float getAnimationScale(int which) { |
| 4283 | switch (which) { |
| 4284 | case 0: return mWindowAnimationScale; |
| 4285 | case 1: return mTransitionAnimationScale; |
| 4286 | } |
| 4287 | return 0; |
| 4288 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4289 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4290 | public float[] getAnimationScales() { |
| 4291 | return new float[] { mWindowAnimationScale, mTransitionAnimationScale }; |
| 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 getSwitchState(int sw) { |
| 4295 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4296 | "getSwitchState()")) { |
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 | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 4299 | return mInputManager.getSwitchState(-1, InputDevice.SOURCE_ANY, 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 getSwitchStateForDevice(int devid, int sw) { |
| 4303 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4304 | "getSwitchStateForDevice()")) { |
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 | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 4307 | return mInputManager.getSwitchState(devid, InputDevice.SOURCE_ANY, 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 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4310 | public int getScancodeState(int sw) { |
| 4311 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4312 | "getScancodeState()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4313 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4314 | } |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 4315 | return mInputManager.getScanCodeState(-1, InputDevice.SOURCE_ANY, sw); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4316 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4317 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4318 | public int getScancodeStateForDevice(int devid, int sw) { |
| 4319 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4320 | "getScancodeStateForDevice()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4321 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4322 | } |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 4323 | return mInputManager.getScanCodeState(devid, InputDevice.SOURCE_ANY, sw); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4324 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4325 | |
Dianne Hackborn | 1d62ea9 | 2009-11-17 12:49:50 -0800 | [diff] [blame] | 4326 | public int getTrackballScancodeState(int sw) { |
| 4327 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4328 | "getTrackballScancodeState()")) { |
| 4329 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
| 4330 | } |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 4331 | return mInputManager.getScanCodeState(-1, InputDevice.SOURCE_TRACKBALL, sw); |
Dianne Hackborn | 1d62ea9 | 2009-11-17 12:49:50 -0800 | [diff] [blame] | 4332 | } |
| 4333 | |
| 4334 | public int getDPadScancodeState(int sw) { |
| 4335 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4336 | "getDPadScancodeState()")) { |
| 4337 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
| 4338 | } |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 4339 | return mInputManager.getScanCodeState(-1, InputDevice.SOURCE_DPAD, sw); |
Dianne Hackborn | 1d62ea9 | 2009-11-17 12:49:50 -0800 | [diff] [blame] | 4340 | } |
| 4341 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4342 | public int getKeycodeState(int sw) { |
| 4343 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4344 | "getKeycodeState()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4345 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4346 | } |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 4347 | return mInputManager.getKeyCodeState(-1, InputDevice.SOURCE_ANY, sw); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4348 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4349 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4350 | public int getKeycodeStateForDevice(int devid, int sw) { |
| 4351 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4352 | "getKeycodeStateForDevice()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4353 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4354 | } |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 4355 | return mInputManager.getKeyCodeState(devid, InputDevice.SOURCE_ANY, sw); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4356 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4357 | |
Dianne Hackborn | 1d62ea9 | 2009-11-17 12:49:50 -0800 | [diff] [blame] | 4358 | public int getTrackballKeycodeState(int sw) { |
| 4359 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4360 | "getTrackballKeycodeState()")) { |
| 4361 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
| 4362 | } |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 4363 | return mInputManager.getKeyCodeState(-1, InputDevice.SOURCE_TRACKBALL, sw); |
Dianne Hackborn | 1d62ea9 | 2009-11-17 12:49:50 -0800 | [diff] [blame] | 4364 | } |
| 4365 | |
| 4366 | public int getDPadKeycodeState(int sw) { |
| 4367 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4368 | "getDPadKeycodeState()")) { |
| 4369 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
| 4370 | } |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 4371 | return mInputManager.getKeyCodeState(-1, InputDevice.SOURCE_DPAD, sw); |
Dianne Hackborn | 1d62ea9 | 2009-11-17 12:49:50 -0800 | [diff] [blame] | 4372 | } |
| 4373 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4374 | public boolean hasKeys(int[] keycodes, boolean[] keyExists) { |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 4375 | return mInputManager.hasKeys(-1, InputDevice.SOURCE_ANY, keycodes, keyExists); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4376 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4377 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4378 | public void enableScreenAfterBoot() { |
| 4379 | synchronized(mWindowMap) { |
| 4380 | if (mSystemBooted) { |
| 4381 | return; |
| 4382 | } |
| 4383 | mSystemBooted = true; |
| 4384 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4385 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4386 | performEnableScreen(); |
| 4387 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4388 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4389 | public void enableScreenIfNeededLocked() { |
| 4390 | if (mDisplayEnabled) { |
| 4391 | return; |
| 4392 | } |
| 4393 | if (!mSystemBooted) { |
| 4394 | return; |
| 4395 | } |
| 4396 | mH.sendMessage(mH.obtainMessage(H.ENABLE_SCREEN)); |
| 4397 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4398 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4399 | public void performEnableScreen() { |
| 4400 | synchronized(mWindowMap) { |
| 4401 | if (mDisplayEnabled) { |
| 4402 | return; |
| 4403 | } |
| 4404 | if (!mSystemBooted) { |
| 4405 | return; |
| 4406 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4407 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4408 | // Don't enable the screen until all existing windows |
| 4409 | // have been drawn. |
| 4410 | final int N = mWindows.size(); |
| 4411 | for (int i=0; i<N; i++) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 4412 | WindowState w = mWindows.get(i); |
Dianne Hackborn | f3bea9c | 2009-12-09 18:26:21 -0800 | [diff] [blame] | 4413 | if (w.isVisibleLw() && !w.mObscured && !w.isDrawnLw()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4414 | return; |
| 4415 | } |
| 4416 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4417 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4418 | mDisplayEnabled = true; |
| 4419 | if (false) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4420 | Slog.i(TAG, "ENABLING SCREEN!"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4421 | StringWriter sw = new StringWriter(); |
| 4422 | PrintWriter pw = new PrintWriter(sw); |
| 4423 | this.dump(null, pw, null); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4424 | Slog.i(TAG, sw.toString()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4425 | } |
| 4426 | try { |
| 4427 | IBinder surfaceFlinger = ServiceManager.getService("SurfaceFlinger"); |
| 4428 | if (surfaceFlinger != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4429 | //Slog.i(TAG, "******* TELLING SURFACE FLINGER WE ARE BOOTED!"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4430 | Parcel data = Parcel.obtain(); |
| 4431 | data.writeInterfaceToken("android.ui.ISurfaceComposer"); |
| 4432 | surfaceFlinger.transact(IBinder.FIRST_CALL_TRANSACTION, |
| 4433 | data, null, 0); |
| 4434 | data.recycle(); |
| 4435 | } |
| 4436 | } catch (RemoteException ex) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4437 | Slog.e(TAG, "Boot completed: SurfaceFlinger is dead!"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4438 | } |
| 4439 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4440 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4441 | mPolicy.enableScreenAfterBoot(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4442 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4443 | // Make sure the last requested orientation has been applied. |
Dianne Hackborn | 321ae68 | 2009-03-27 16:16:03 -0700 | [diff] [blame] | 4444 | setRotationUnchecked(WindowManagerPolicy.USE_LAST_ROTATION, false, |
| 4445 | mLastRotationFlags | Surface.FLAGS_ORIENTATION_ANIMATION_DISABLE); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4446 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4447 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4448 | public void setInTouchMode(boolean mode) { |
| 4449 | synchronized(mWindowMap) { |
| 4450 | mInTouchMode = mode; |
| 4451 | } |
| 4452 | } |
| 4453 | |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4454 | public void setRotation(int rotation, |
Dianne Hackborn | 1e880db | 2009-03-27 16:04:08 -0700 | [diff] [blame] | 4455 | boolean alwaysSendConfiguration, int animFlags) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4456 | if (!checkCallingPermission(android.Manifest.permission.SET_ORIENTATION, |
Dianne Hackborn | 1e880db | 2009-03-27 16:04:08 -0700 | [diff] [blame] | 4457 | "setRotation()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4458 | throw new SecurityException("Requires SET_ORIENTATION permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4459 | } |
| 4460 | |
Dianne Hackborn | 1e880db | 2009-03-27 16:04:08 -0700 | [diff] [blame] | 4461 | setRotationUnchecked(rotation, alwaysSendConfiguration, animFlags); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4462 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4463 | |
Dianne Hackborn | 1e880db | 2009-03-27 16:04:08 -0700 | [diff] [blame] | 4464 | public void setRotationUnchecked(int rotation, |
| 4465 | boolean alwaysSendConfiguration, int animFlags) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4466 | if(DEBUG_ORIENTATION) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4467 | "alwaysSendConfiguration set to "+alwaysSendConfiguration); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4468 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4469 | long origId = Binder.clearCallingIdentity(); |
| 4470 | boolean changed; |
| 4471 | synchronized(mWindowMap) { |
Dianne Hackborn | 1e880db | 2009-03-27 16:04:08 -0700 | [diff] [blame] | 4472 | changed = setRotationUncheckedLocked(rotation, animFlags); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4473 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4474 | |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 4475 | if (changed || alwaysSendConfiguration) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4476 | sendNewConfiguration(); |
| 4477 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4478 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4479 | Binder.restoreCallingIdentity(origId); |
| 4480 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4481 | |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 4482 | /** |
| 4483 | * Apply a new rotation to the screen, respecting the requests of |
| 4484 | * applications. Use WindowManagerPolicy.USE_LAST_ROTATION to simply |
| 4485 | * re-evaluate the desired rotation. |
| 4486 | * |
| 4487 | * Returns null if the rotation has been changed. In this case YOU |
| 4488 | * MUST CALL setNewConfiguration() TO UNFREEZE THE SCREEN. |
| 4489 | */ |
Dianne Hackborn | 1e880db | 2009-03-27 16:04:08 -0700 | [diff] [blame] | 4490 | public boolean setRotationUncheckedLocked(int rotation, int animFlags) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4491 | boolean changed; |
| 4492 | if (rotation == WindowManagerPolicy.USE_LAST_ROTATION) { |
| 4493 | rotation = mRequestedRotation; |
| 4494 | } else { |
| 4495 | mRequestedRotation = rotation; |
Dianne Hackborn | 321ae68 | 2009-03-27 16:16:03 -0700 | [diff] [blame] | 4496 | mLastRotationFlags = animFlags; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4497 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4498 | 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] | 4499 | rotation = mPolicy.rotationForOrientationLw(mForcedAppOrientation, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4500 | mRotation, mDisplayEnabled); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4501 | 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] | 4502 | changed = mDisplayEnabled && mRotation != rotation; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4503 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4504 | if (changed) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4505 | if (DEBUG_ORIENTATION) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4506 | "Rotation changed to " + rotation |
| 4507 | + " from " + mRotation |
| 4508 | + " (forceApp=" + mForcedAppOrientation |
| 4509 | + ", req=" + mRequestedRotation + ")"); |
| 4510 | mRotation = rotation; |
| 4511 | mWindowsFreezingScreen = true; |
| 4512 | mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT); |
| 4513 | mH.sendMessageDelayed(mH.obtainMessage(H.WINDOW_FREEZE_TIMEOUT), |
| 4514 | 2000); |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 4515 | mWaitingForConfig = true; |
| 4516 | mLayoutNeeded = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4517 | startFreezingDisplayLocked(); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4518 | Slog.i(TAG, "Setting rotation to " + rotation + ", animFlags=" + animFlags); |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 4519 | mInputManager.setDisplayOrientation(0, rotation); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4520 | if (mDisplayEnabled) { |
Dianne Hackborn | 321ae68 | 2009-03-27 16:16:03 -0700 | [diff] [blame] | 4521 | Surface.setOrientation(0, rotation, animFlags); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4522 | } |
| 4523 | for (int i=mWindows.size()-1; i>=0; i--) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 4524 | WindowState w = mWindows.get(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4525 | if (w.mSurface != null) { |
| 4526 | w.mOrientationChanging = true; |
| 4527 | } |
| 4528 | } |
| 4529 | for (int i=mRotationWatchers.size()-1; i>=0; i--) { |
| 4530 | try { |
| 4531 | mRotationWatchers.get(i).onRotationChanged(rotation); |
| 4532 | } catch (RemoteException e) { |
| 4533 | } |
| 4534 | } |
| 4535 | } //end if changed |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4536 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4537 | return changed; |
| 4538 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4539 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4540 | public int getRotation() { |
| 4541 | return mRotation; |
| 4542 | } |
| 4543 | |
| 4544 | public int watchRotation(IRotationWatcher watcher) { |
| 4545 | final IBinder watcherBinder = watcher.asBinder(); |
| 4546 | IBinder.DeathRecipient dr = new IBinder.DeathRecipient() { |
| 4547 | public void binderDied() { |
| 4548 | synchronized (mWindowMap) { |
| 4549 | for (int i=0; i<mRotationWatchers.size(); i++) { |
| 4550 | if (watcherBinder == mRotationWatchers.get(i).asBinder()) { |
Suchi Amalapurapu | fff2fda | 2009-06-30 21:36:16 -0700 | [diff] [blame] | 4551 | IRotationWatcher removed = mRotationWatchers.remove(i); |
| 4552 | if (removed != null) { |
| 4553 | removed.asBinder().unlinkToDeath(this, 0); |
| 4554 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4555 | i--; |
| 4556 | } |
| 4557 | } |
| 4558 | } |
| 4559 | } |
| 4560 | }; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4561 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4562 | synchronized (mWindowMap) { |
| 4563 | try { |
| 4564 | watcher.asBinder().linkToDeath(dr, 0); |
| 4565 | mRotationWatchers.add(watcher); |
| 4566 | } catch (RemoteException e) { |
| 4567 | // Client died, no cleanup needed. |
| 4568 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4569 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4570 | return mRotation; |
| 4571 | } |
| 4572 | } |
| 4573 | |
| 4574 | /** |
| 4575 | * Starts the view server on the specified port. |
| 4576 | * |
| 4577 | * @param port The port to listener to. |
| 4578 | * |
| 4579 | * @return True if the server was successfully started, false otherwise. |
| 4580 | * |
| 4581 | * @see com.android.server.ViewServer |
| 4582 | * @see com.android.server.ViewServer#VIEW_SERVER_DEFAULT_PORT |
| 4583 | */ |
| 4584 | public boolean startViewServer(int port) { |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4585 | if (isSystemSecure()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4586 | return false; |
| 4587 | } |
| 4588 | |
| 4589 | if (!checkCallingPermission(Manifest.permission.DUMP, "startViewServer")) { |
| 4590 | return false; |
| 4591 | } |
| 4592 | |
| 4593 | if (port < 1024) { |
| 4594 | return false; |
| 4595 | } |
| 4596 | |
| 4597 | if (mViewServer != null) { |
| 4598 | if (!mViewServer.isRunning()) { |
| 4599 | try { |
| 4600 | return mViewServer.start(); |
| 4601 | } catch (IOException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4602 | Slog.w(TAG, "View server did not start"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4603 | } |
| 4604 | } |
| 4605 | return false; |
| 4606 | } |
| 4607 | |
| 4608 | try { |
| 4609 | mViewServer = new ViewServer(this, port); |
| 4610 | return mViewServer.start(); |
| 4611 | } catch (IOException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4612 | Slog.w(TAG, "View server did not start"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4613 | } |
| 4614 | return false; |
| 4615 | } |
| 4616 | |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4617 | private boolean isSystemSecure() { |
| 4618 | return "1".equals(SystemProperties.get(SYSTEM_SECURE, "1")) && |
| 4619 | "0".equals(SystemProperties.get(SYSTEM_DEBUGGABLE, "0")); |
| 4620 | } |
| 4621 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4622 | /** |
| 4623 | * Stops the view server if it exists. |
| 4624 | * |
| 4625 | * @return True if the server stopped, false if it wasn't started or |
| 4626 | * couldn't be stopped. |
| 4627 | * |
| 4628 | * @see com.android.server.ViewServer |
| 4629 | */ |
| 4630 | public boolean stopViewServer() { |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4631 | if (isSystemSecure()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4632 | return false; |
| 4633 | } |
| 4634 | |
| 4635 | if (!checkCallingPermission(Manifest.permission.DUMP, "stopViewServer")) { |
| 4636 | return false; |
| 4637 | } |
| 4638 | |
| 4639 | if (mViewServer != null) { |
| 4640 | return mViewServer.stop(); |
| 4641 | } |
| 4642 | return false; |
| 4643 | } |
| 4644 | |
| 4645 | /** |
| 4646 | * Indicates whether the view server is running. |
| 4647 | * |
| 4648 | * @return True if the server is running, false otherwise. |
| 4649 | * |
| 4650 | * @see com.android.server.ViewServer |
| 4651 | */ |
| 4652 | public boolean isViewServerRunning() { |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4653 | if (isSystemSecure()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4654 | return false; |
| 4655 | } |
| 4656 | |
| 4657 | if (!checkCallingPermission(Manifest.permission.DUMP, "isViewServerRunning")) { |
| 4658 | return false; |
| 4659 | } |
| 4660 | |
| 4661 | return mViewServer != null && mViewServer.isRunning(); |
| 4662 | } |
| 4663 | |
| 4664 | /** |
| 4665 | * Lists all availble windows in the system. The listing is written in the |
| 4666 | * specified Socket's output stream with the following syntax: |
| 4667 | * windowHashCodeInHexadecimal windowName |
| 4668 | * Each line of the ouput represents a different window. |
| 4669 | * |
| 4670 | * @param client The remote client to send the listing to. |
| 4671 | * @return False if an error occured, true otherwise. |
| 4672 | */ |
| 4673 | boolean viewServerListWindows(Socket client) { |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4674 | if (isSystemSecure()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4675 | return false; |
| 4676 | } |
| 4677 | |
| 4678 | boolean result = true; |
| 4679 | |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 4680 | WindowState[] windows; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4681 | synchronized (mWindowMap) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4682 | //noinspection unchecked |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 4683 | windows = mWindows.toArray(new WindowState[mWindows.size()]); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4684 | } |
| 4685 | |
| 4686 | BufferedWriter out = null; |
| 4687 | |
| 4688 | // Any uncaught exception will crash the system process |
| 4689 | try { |
| 4690 | OutputStream clientStream = client.getOutputStream(); |
| 4691 | out = new BufferedWriter(new OutputStreamWriter(clientStream), 8 * 1024); |
| 4692 | |
| 4693 | final int count = windows.length; |
| 4694 | for (int i = 0; i < count; i++) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 4695 | final WindowState w = windows[i]; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4696 | out.write(Integer.toHexString(System.identityHashCode(w))); |
| 4697 | out.write(' '); |
| 4698 | out.append(w.mAttrs.getTitle()); |
| 4699 | out.write('\n'); |
| 4700 | } |
| 4701 | |
| 4702 | out.write("DONE.\n"); |
| 4703 | out.flush(); |
| 4704 | } catch (Exception e) { |
| 4705 | result = false; |
| 4706 | } finally { |
| 4707 | if (out != null) { |
| 4708 | try { |
| 4709 | out.close(); |
| 4710 | } catch (IOException e) { |
| 4711 | result = false; |
| 4712 | } |
| 4713 | } |
| 4714 | } |
| 4715 | |
| 4716 | return result; |
| 4717 | } |
| 4718 | |
| 4719 | /** |
| 4720 | * Sends a command to a target window. The result of the command, if any, will be |
| 4721 | * written in the output stream of the specified socket. |
| 4722 | * |
| 4723 | * The parameters must follow this syntax: |
| 4724 | * windowHashcode extra |
| 4725 | * |
| 4726 | * Where XX is the length in characeters of the windowTitle. |
| 4727 | * |
| 4728 | * The first parameter is the target window. The window with the specified hashcode |
| 4729 | * will be the target. If no target can be found, nothing happens. The extra parameters |
| 4730 | * will be delivered to the target window and as parameters to the command itself. |
| 4731 | * |
| 4732 | * @param client The remote client to sent the result, if any, to. |
| 4733 | * @param command The command to execute. |
| 4734 | * @param parameters The command parameters. |
| 4735 | * |
| 4736 | * @return True if the command was successfully delivered, false otherwise. This does |
| 4737 | * not indicate whether the command itself was successful. |
| 4738 | */ |
| 4739 | boolean viewServerWindowCommand(Socket client, String command, String parameters) { |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4740 | if (isSystemSecure()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4741 | return false; |
| 4742 | } |
| 4743 | |
| 4744 | boolean success = true; |
| 4745 | Parcel data = null; |
| 4746 | Parcel reply = null; |
| 4747 | |
| 4748 | // Any uncaught exception will crash the system process |
| 4749 | try { |
| 4750 | // Find the hashcode of the window |
| 4751 | int index = parameters.indexOf(' '); |
| 4752 | if (index == -1) { |
| 4753 | index = parameters.length(); |
| 4754 | } |
| 4755 | final String code = parameters.substring(0, index); |
Romain Guy | 236092a | 2009-12-14 15:31:48 -0800 | [diff] [blame] | 4756 | int hashCode = (int) Long.parseLong(code, 16); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4757 | |
| 4758 | // Extract the command's parameter after the window description |
| 4759 | if (index < parameters.length()) { |
| 4760 | parameters = parameters.substring(index + 1); |
| 4761 | } else { |
| 4762 | parameters = ""; |
| 4763 | } |
| 4764 | |
| 4765 | final WindowManagerService.WindowState window = findWindow(hashCode); |
| 4766 | if (window == null) { |
| 4767 | return false; |
| 4768 | } |
| 4769 | |
| 4770 | data = Parcel.obtain(); |
| 4771 | data.writeInterfaceToken("android.view.IWindow"); |
| 4772 | data.writeString(command); |
| 4773 | data.writeString(parameters); |
| 4774 | data.writeInt(1); |
| 4775 | ParcelFileDescriptor.fromSocket(client).writeToParcel(data, 0); |
| 4776 | |
| 4777 | reply = Parcel.obtain(); |
| 4778 | |
| 4779 | final IBinder binder = window.mClient.asBinder(); |
| 4780 | // TODO: GET THE TRANSACTION CODE IN A SAFER MANNER |
| 4781 | binder.transact(IBinder.FIRST_CALL_TRANSACTION, data, reply, 0); |
| 4782 | |
| 4783 | reply.readException(); |
| 4784 | |
| 4785 | } catch (Exception e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4786 | 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] | 4787 | success = false; |
| 4788 | } finally { |
| 4789 | if (data != null) { |
| 4790 | data.recycle(); |
| 4791 | } |
| 4792 | if (reply != null) { |
| 4793 | reply.recycle(); |
| 4794 | } |
| 4795 | } |
| 4796 | |
| 4797 | return success; |
| 4798 | } |
| 4799 | |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 4800 | public void addWindowChangeListener(WindowChangeListener listener) { |
| 4801 | synchronized(mWindowMap) { |
| 4802 | mWindowChangeListeners.add(listener); |
| 4803 | } |
| 4804 | } |
| 4805 | |
| 4806 | public void removeWindowChangeListener(WindowChangeListener listener) { |
| 4807 | synchronized(mWindowMap) { |
| 4808 | mWindowChangeListeners.remove(listener); |
| 4809 | } |
| 4810 | } |
| 4811 | |
| 4812 | private void notifyWindowsChanged() { |
| 4813 | WindowChangeListener[] windowChangeListeners; |
| 4814 | synchronized(mWindowMap) { |
| 4815 | if(mWindowChangeListeners.isEmpty()) { |
| 4816 | return; |
| 4817 | } |
| 4818 | windowChangeListeners = new WindowChangeListener[mWindowChangeListeners.size()]; |
| 4819 | windowChangeListeners = mWindowChangeListeners.toArray(windowChangeListeners); |
| 4820 | } |
| 4821 | int N = windowChangeListeners.length; |
| 4822 | for(int i = 0; i < N; i++) { |
| 4823 | windowChangeListeners[i].windowsChanged(); |
| 4824 | } |
| 4825 | } |
| 4826 | |
Konstantin Lopyrev | 6e0f65f | 2010-07-14 14:55:33 -0700 | [diff] [blame] | 4827 | private void notifyFocusChanged() { |
| 4828 | WindowChangeListener[] windowChangeListeners; |
| 4829 | synchronized(mWindowMap) { |
| 4830 | if(mWindowChangeListeners.isEmpty()) { |
| 4831 | return; |
| 4832 | } |
| 4833 | windowChangeListeners = new WindowChangeListener[mWindowChangeListeners.size()]; |
| 4834 | windowChangeListeners = mWindowChangeListeners.toArray(windowChangeListeners); |
| 4835 | } |
| 4836 | int N = windowChangeListeners.length; |
| 4837 | for(int i = 0; i < N; i++) { |
| 4838 | windowChangeListeners[i].focusChanged(); |
| 4839 | } |
| 4840 | } |
| 4841 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4842 | private WindowState findWindow(int hashCode) { |
| 4843 | if (hashCode == -1) { |
| 4844 | return getFocusedWindow(); |
| 4845 | } |
| 4846 | |
| 4847 | synchronized (mWindowMap) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 4848 | final ArrayList<WindowState> windows = mWindows; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4849 | final int count = windows.size(); |
| 4850 | |
| 4851 | for (int i = 0; i < count; i++) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 4852 | WindowState w = windows.get(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4853 | if (System.identityHashCode(w) == hashCode) { |
| 4854 | return w; |
| 4855 | } |
| 4856 | } |
| 4857 | } |
| 4858 | |
| 4859 | return null; |
| 4860 | } |
| 4861 | |
| 4862 | /* |
| 4863 | * Instruct the Activity Manager to fetch the current configuration and broadcast |
| 4864 | * that to config-changed listeners if appropriate. |
| 4865 | */ |
| 4866 | void sendNewConfiguration() { |
| 4867 | try { |
| 4868 | mActivityManager.updateConfiguration(null); |
| 4869 | } catch (RemoteException e) { |
| 4870 | } |
| 4871 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4872 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4873 | public Configuration computeNewConfiguration() { |
| 4874 | synchronized (mWindowMap) { |
Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 4875 | return computeNewConfigurationLocked(); |
| 4876 | } |
| 4877 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4878 | |
Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 4879 | Configuration computeNewConfigurationLocked() { |
| 4880 | Configuration config = new Configuration(); |
| 4881 | if (!computeNewConfigurationLocked(config)) { |
| 4882 | return null; |
| 4883 | } |
Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 4884 | return config; |
| 4885 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4886 | |
Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 4887 | boolean computeNewConfigurationLocked(Configuration config) { |
| 4888 | if (mDisplay == null) { |
| 4889 | return false; |
| 4890 | } |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 4891 | |
| 4892 | mInputManager.getInputConfiguration(config); |
Christopher Tate | b696aee | 2010-04-02 19:08:30 -0700 | [diff] [blame] | 4893 | |
| 4894 | // Use the effective "visual" dimensions based on current rotation |
| 4895 | final boolean rotated = (mRotation == Surface.ROTATION_90 |
| 4896 | || mRotation == Surface.ROTATION_270); |
| 4897 | final int dw = rotated ? mInitialDisplayHeight : mInitialDisplayWidth; |
| 4898 | final int dh = rotated ? mInitialDisplayWidth : mInitialDisplayHeight; |
| 4899 | |
Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 4900 | int orientation = Configuration.ORIENTATION_SQUARE; |
| 4901 | if (dw < dh) { |
| 4902 | orientation = Configuration.ORIENTATION_PORTRAIT; |
| 4903 | } else if (dw > dh) { |
| 4904 | orientation = Configuration.ORIENTATION_LANDSCAPE; |
| 4905 | } |
| 4906 | config.orientation = orientation; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 4907 | |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 4908 | DisplayMetrics dm = new DisplayMetrics(); |
| 4909 | mDisplay.getMetrics(dm); |
| 4910 | CompatibilityInfo.updateCompatibleScreenFrame(dm, orientation, mCompatibleScreenFrame); |
| 4911 | |
Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 4912 | if (mScreenLayout == Configuration.SCREENLAYOUT_SIZE_UNDEFINED) { |
Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 4913 | // Note we only do this once because at this point we don't |
| 4914 | // expect the screen to change in this way at runtime, and want |
| 4915 | // to avoid all of this computation for every config change. |
Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 4916 | int longSize = dw; |
| 4917 | int shortSize = dh; |
| 4918 | if (longSize < shortSize) { |
| 4919 | int tmp = longSize; |
| 4920 | longSize = shortSize; |
| 4921 | shortSize = tmp; |
| 4922 | } |
| 4923 | longSize = (int)(longSize/dm.density); |
| 4924 | shortSize = (int)(shortSize/dm.density); |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 4925 | |
Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 4926 | // These semi-magic numbers define our compatibility modes for |
| 4927 | // applications with different screens. Don't change unless you |
| 4928 | // make sure to test lots and lots of apps! |
| 4929 | if (longSize < 470) { |
| 4930 | // This is shorter than an HVGA normal density screen (which |
| 4931 | // is 480 pixels on its long side). |
Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 4932 | mScreenLayout = Configuration.SCREENLAYOUT_SIZE_SMALL |
| 4933 | | Configuration.SCREENLAYOUT_LONG_NO; |
Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 4934 | } else { |
Dianne Hackborn | 14cee9f | 2010-04-23 17:51:26 -0700 | [diff] [blame] | 4935 | // What size is this screen screen? |
| 4936 | if (longSize >= 800 && shortSize >= 600) { |
| 4937 | // SVGA or larger screens at medium density are the point |
| 4938 | // at which we consider it to be an extra large screen. |
| 4939 | mScreenLayout = Configuration.SCREENLAYOUT_SIZE_XLARGE; |
| 4940 | } else if (longSize >= 640 && shortSize >= 480) { |
Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 4941 | // VGA or larger screens at medium density are the point |
| 4942 | // at which we consider it to be a large screen. |
| 4943 | mScreenLayout = Configuration.SCREENLAYOUT_SIZE_LARGE; |
| 4944 | } else { |
| 4945 | mScreenLayout = Configuration.SCREENLAYOUT_SIZE_NORMAL; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 4946 | |
Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 4947 | // If this screen is wider than normal HVGA, or taller |
| 4948 | // than FWVGA, then for old apps we want to run in size |
| 4949 | // compatibility mode. |
| 4950 | if (shortSize > 321 || longSize > 570) { |
| 4951 | mScreenLayout |= Configuration.SCREENLAYOUT_COMPAT_NEEDED; |
| 4952 | } |
| 4953 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 4954 | |
Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 4955 | // Is this a long screen? |
| 4956 | if (((longSize*3)/5) >= (shortSize-1)) { |
| 4957 | // Anything wider than WVGA (5:3) is considering to be long. |
| 4958 | mScreenLayout |= Configuration.SCREENLAYOUT_LONG_YES; |
| 4959 | } else { |
| 4960 | mScreenLayout |= Configuration.SCREENLAYOUT_LONG_NO; |
| 4961 | } |
Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 4962 | } |
| 4963 | } |
Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 4964 | config.screenLayout = mScreenLayout; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 4965 | |
Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 4966 | config.keyboardHidden = Configuration.KEYBOARDHIDDEN_NO; |
| 4967 | config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_NO; |
| 4968 | mPolicy.adjustConfigurationLw(config); |
| 4969 | return true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4970 | } |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 4971 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4972 | // ------------------------------------------------------------- |
| 4973 | // Input Events and Focus Management |
| 4974 | // ------------------------------------------------------------- |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 4975 | |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 4976 | InputMonitor mInputMonitor = new InputMonitor(); |
| 4977 | |
| 4978 | /* Tracks the progress of input dispatch and ensures that input dispatch state |
| 4979 | * is kept in sync with changes in window focus, visibility, registration, and |
| 4980 | * other relevant Window Manager state transitions. */ |
| 4981 | final class InputMonitor { |
| 4982 | // Current window with input focus for keys and other non-touch events. May be null. |
| 4983 | private WindowState mInputFocus; |
| 4984 | |
| 4985 | // When true, prevents input dispatch from proceeding until set to false again. |
| 4986 | private boolean mInputDispatchFrozen; |
| 4987 | |
| 4988 | // When true, input dispatch proceeds normally. Otherwise all events are dropped. |
| 4989 | private boolean mInputDispatchEnabled = true; |
| 4990 | |
| 4991 | // Temporary list of windows information to provide to the input dispatcher. |
| 4992 | private InputWindowList mTempInputWindows = new InputWindowList(); |
| 4993 | |
| 4994 | // Temporary input application object to provide to the input dispatcher. |
| 4995 | private InputApplication mTempInputApplication = new InputApplication(); |
| 4996 | |
| 4997 | /* Notifies the window manager about a broken input channel. |
| 4998 | * |
| 4999 | * Called by the InputManager. |
| 5000 | */ |
| 5001 | public void notifyInputChannelBroken(InputChannel inputChannel) { |
| 5002 | synchronized (mWindowMap) { |
| 5003 | WindowState windowState = getWindowStateForInputChannelLocked(inputChannel); |
| 5004 | if (windowState == null) { |
| 5005 | return; // irrelevant |
| 5006 | } |
| 5007 | |
| 5008 | Slog.i(TAG, "WINDOW DIED " + windowState); |
| 5009 | removeWindowLocked(windowState.mSession, windowState); |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 5010 | } |
| 5011 | } |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5012 | |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5013 | /* Notifies the window manager about an input channel that is not responding. |
| 5014 | * The method can either cause dispatching to be aborted by returning -2 or |
| 5015 | * return a new timeout in nanoseconds. |
| 5016 | * |
| 5017 | * Called by the InputManager. |
| 5018 | */ |
| 5019 | public long notifyInputChannelANR(InputChannel inputChannel) { |
| 5020 | AppWindowToken token; |
| 5021 | synchronized (mWindowMap) { |
| 5022 | WindowState windowState = getWindowStateForInputChannelLocked(inputChannel); |
| 5023 | if (windowState == null) { |
| 5024 | return -2; // irrelevant, abort dispatching (-2) |
| 5025 | } |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 5026 | |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5027 | Slog.i(TAG, "Input event dispatching timed out sending to " |
| 5028 | + windowState.mAttrs.getTitle()); |
| 5029 | token = windowState.mAppToken; |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 5030 | } |
| 5031 | |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5032 | return notifyANRInternal(token); |
| 5033 | } |
| 5034 | |
| 5035 | /* Notifies the window manager about an input channel spontaneously recovering from ANR |
| 5036 | * by successfully delivering the event that originally timed out. |
| 5037 | * |
| 5038 | * Called by the InputManager. |
| 5039 | */ |
| 5040 | public void notifyInputChannelRecoveredFromANR(InputChannel inputChannel) { |
| 5041 | // Nothing to do just now. |
| 5042 | // Just wait for the user to dismiss the ANR dialog. |
| 5043 | } |
| 5044 | |
| 5045 | /* Notifies the window manager about an application that is not responding |
| 5046 | * in general rather than with respect to a particular input channel. |
| 5047 | * The method can either cause dispatching to be aborted by returning -2 or |
| 5048 | * return a new timeout in nanoseconds. |
| 5049 | * |
| 5050 | * Called by the InputManager. |
| 5051 | */ |
| 5052 | public long notifyANR(Object token) { |
| 5053 | AppWindowToken appWindowToken = (AppWindowToken) token; |
| 5054 | |
| 5055 | Slog.i(TAG, "Input event dispatching timed out sending to application " |
| 5056 | + appWindowToken.stringName); |
| 5057 | return notifyANRInternal(appWindowToken); |
| 5058 | } |
| 5059 | |
| 5060 | private long notifyANRInternal(AppWindowToken token) { |
| 5061 | if (token != null && token.appToken != null) { |
| 5062 | try { |
| 5063 | // Notify the activity manager about the timeout and let it decide whether |
| 5064 | // to abort dispatching or keep waiting. |
| 5065 | boolean abort = token.appToken.keyDispatchingTimedOut(); |
| 5066 | if (! abort) { |
| 5067 | // The activity manager declined to abort dispatching. |
| 5068 | // Wait a bit longer and timeout again later. |
| 5069 | return token.inputDispatchingTimeoutNanos; |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 5070 | } |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5071 | } catch (RemoteException ex) { |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 5072 | } |
| 5073 | } |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5074 | return -2; // abort dispatching |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 5075 | } |
| 5076 | |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5077 | private WindowState getWindowStateForInputChannel(InputChannel inputChannel) { |
| 5078 | synchronized (mWindowMap) { |
| 5079 | return getWindowStateForInputChannelLocked(inputChannel); |
| 5080 | } |
| 5081 | } |
| 5082 | |
| 5083 | private WindowState getWindowStateForInputChannelLocked(InputChannel inputChannel) { |
| 5084 | int windowCount = mWindows.size(); |
| 5085 | for (int i = 0; i < windowCount; i++) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 5086 | WindowState windowState = mWindows.get(i); |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5087 | if (windowState.mInputChannel == inputChannel) { |
| 5088 | return windowState; |
| 5089 | } |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 5090 | } |
| 5091 | |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5092 | return null; |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 5093 | } |
| 5094 | |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5095 | /* Updates the cached window information provided to the input dispatcher. */ |
| 5096 | public void updateInputWindowsLw() { |
| 5097 | // Populate the input window list with information about all of the windows that |
| 5098 | // could potentially receive input. |
| 5099 | // As an optimization, we could try to prune the list of windows but this turns |
| 5100 | // out to be difficult because only the native code knows for sure which window |
| 5101 | // currently has touch focus. |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 5102 | final ArrayList<WindowState> windows = mWindows; |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 5103 | final int N = windows.size(); |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5104 | for (int i = N - 1; i >= 0; i--) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 5105 | final WindowState child = windows.get(i); |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 5106 | if (child.mInputChannel == null || child.mRemoved) { |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5107 | // Skip this window because it cannot possibly receive input. |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 5108 | continue; |
| 5109 | } |
| 5110 | |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5111 | final int flags = child.mAttrs.flags; |
| 5112 | final int type = child.mAttrs.type; |
| 5113 | |
| 5114 | final boolean hasFocus = (child == mInputFocus); |
| 5115 | final boolean isVisible = child.isVisibleLw(); |
| 5116 | final boolean hasWallpaper = (child == mWallpaperTarget) |
| 5117 | && (type != WindowManager.LayoutParams.TYPE_KEYGUARD); |
| 5118 | |
| 5119 | // Add a window to our list of input windows. |
| 5120 | final InputWindow inputWindow = mTempInputWindows.add(); |
| 5121 | inputWindow.inputChannel = child.mInputChannel; |
| 5122 | inputWindow.layoutParamsFlags = flags; |
| 5123 | inputWindow.layoutParamsType = type; |
| 5124 | inputWindow.dispatchingTimeoutNanos = child.getInputDispatchingTimeoutNanos(); |
| 5125 | inputWindow.visible = isVisible; |
| 5126 | inputWindow.hasFocus = hasFocus; |
| 5127 | inputWindow.hasWallpaper = hasWallpaper; |
| 5128 | inputWindow.paused = child.mAppToken != null ? child.mAppToken.paused : false; |
| 5129 | inputWindow.ownerPid = child.mSession.mPid; |
| 5130 | inputWindow.ownerUid = child.mSession.mUid; |
| 5131 | |
| 5132 | final Rect frame = child.mFrame; |
| 5133 | inputWindow.frameLeft = frame.left; |
| 5134 | inputWindow.frameTop = frame.top; |
| 5135 | |
| 5136 | switch (child.mTouchableInsets) { |
| 5137 | default: |
| 5138 | case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME: |
| 5139 | inputWindow.touchableAreaLeft = frame.left; |
| 5140 | inputWindow.touchableAreaTop = frame.top; |
| 5141 | inputWindow.touchableAreaRight = frame.right; |
| 5142 | inputWindow.touchableAreaBottom = frame.bottom; |
| 5143 | break; |
| 5144 | |
| 5145 | case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_CONTENT: { |
| 5146 | Rect inset = child.mGivenContentInsets; |
| 5147 | inputWindow.touchableAreaLeft = frame.left + inset.left; |
| 5148 | inputWindow.touchableAreaTop = frame.top + inset.top; |
| 5149 | inputWindow.touchableAreaRight = frame.right - inset.right; |
| 5150 | inputWindow.touchableAreaBottom = frame.bottom - inset.bottom; |
| 5151 | break; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5152 | } |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5153 | |
| 5154 | case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_VISIBLE: { |
| 5155 | Rect inset = child.mGivenVisibleInsets; |
| 5156 | inputWindow.touchableAreaLeft = frame.left + inset.left; |
| 5157 | inputWindow.touchableAreaTop = frame.top + inset.top; |
| 5158 | inputWindow.touchableAreaRight = frame.right - inset.right; |
| 5159 | inputWindow.touchableAreaBottom = frame.bottom - inset.bottom; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5160 | break; |
| 5161 | } |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5162 | } |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5163 | } |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 5164 | |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5165 | // Send windows to native code. |
| 5166 | mInputManager.setInputWindows(mTempInputWindows.toNullTerminatedArray()); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5167 | |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5168 | // Clear the list in preparation for the next round. |
| 5169 | // Also avoids keeping InputChannel objects referenced unnecessarily. |
| 5170 | mTempInputWindows.clear(); |
| 5171 | } |
| 5172 | |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 5173 | /* Provides feedback for a virtual key down. */ |
| 5174 | public void virtualKeyDownFeedback() { |
| 5175 | synchronized (mWindowMap) { |
| 5176 | mPolicy.performHapticFeedbackLw(null, HapticFeedbackConstants.VIRTUAL_KEY, false); |
| 5177 | } |
| 5178 | } |
| 5179 | |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5180 | /* Notifies that an app switch key (BACK / HOME) has just been pressed. |
| 5181 | * This essentially starts a .5 second timeout for the application to process |
| 5182 | * subsequent input events while waiting for the app switch to occur. If it takes longer |
| 5183 | * than this, the pending events will be dropped. |
| 5184 | */ |
| 5185 | public void notifyAppSwitchComing() { |
| 5186 | // TODO Not implemented yet. Should go in the native side. |
| 5187 | } |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 5188 | |
| 5189 | /* Notifies that the lid switch changed state. */ |
| 5190 | public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen) { |
| 5191 | mPolicy.notifyLidSwitchChanged(whenNanos, lidOpen); |
| 5192 | } |
| 5193 | |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5194 | /* Provides an opportunity for the window manager policy to intercept early key |
| 5195 | * processing as soon as the key has been read from the device. */ |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 5196 | public int interceptKeyBeforeQueueing(long whenNanos, int keyCode, boolean down, |
| 5197 | int policyFlags, boolean isScreenOn) { |
| 5198 | return mPolicy.interceptKeyBeforeQueueing(whenNanos, |
| 5199 | keyCode, down, policyFlags, isScreenOn); |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5200 | } |
| 5201 | |
| 5202 | /* Provides an opportunity for the window manager policy to process a key before |
| 5203 | * ordinary dispatch. */ |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 5204 | public boolean interceptKeyBeforeDispatching(InputChannel focus, |
| 5205 | int action, int flags, int keyCode, int metaState, int repeatCount, |
| 5206 | int policyFlags) { |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5207 | WindowState windowState = getWindowStateForInputChannel(focus); |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 5208 | return mPolicy.interceptKeyBeforeDispatching(windowState, action, flags, |
| 5209 | keyCode, metaState, repeatCount, policyFlags); |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5210 | } |
| 5211 | |
| 5212 | /* Called when the current input focus changes. |
| 5213 | * Layer assignment is assumed to be complete by the time this is called. |
| 5214 | */ |
| 5215 | public void setInputFocusLw(WindowState newWindow) { |
| 5216 | if (DEBUG_INPUT) { |
| 5217 | Slog.d(TAG, "Input focus has changed to " + newWindow); |
| 5218 | } |
| 5219 | |
| 5220 | if (newWindow != mInputFocus) { |
| 5221 | if (newWindow != null && newWindow.canReceiveKeys()) { |
| 5222 | // If the new input focus is an error window or appears above the current |
| 5223 | // input focus, preempt any pending synchronous dispatch so that we can |
| 5224 | // start delivering events to the new input focus as soon as possible. |
| 5225 | if ((newWindow.mAttrs.flags & FLAG_SYSTEM_ERROR) != 0) { |
| 5226 | if (DEBUG_INPUT) { |
| 5227 | Slog.v(TAG, "New SYSTEM_ERROR window; resetting state"); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5228 | } |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5229 | preemptInputDispatchLw(); |
| 5230 | } else if (mInputFocus != null && newWindow.mLayer > mInputFocus.mLayer) { |
| 5231 | if (DEBUG_INPUT) { |
| 5232 | Slog.v(TAG, "Transferring focus to new window at higher layer: " |
| 5233 | + "old win layer=" + mInputFocus.mLayer |
| 5234 | + ", new win layer=" + newWindow.mLayer); |
| 5235 | } |
| 5236 | preemptInputDispatchLw(); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5237 | } |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5238 | |
| 5239 | // Displaying a window implicitly causes dispatching to be unpaused. |
| 5240 | // This is to protect against bugs if someone pauses dispatching but |
| 5241 | // forgets to resume. |
| 5242 | newWindow.mToken.paused = false; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5243 | } |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5244 | |
| 5245 | mInputFocus = newWindow; |
| 5246 | updateInputWindowsLw(); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5247 | } |
| 5248 | } |
| 5249 | |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5250 | /* Tells the dispatcher to stop waiting for its current synchronous event targets. |
| 5251 | * Essentially, just makes those dispatches asynchronous so a new dispatch cycle |
| 5252 | * can begin. |
| 5253 | */ |
| 5254 | private void preemptInputDispatchLw() { |
| 5255 | mInputManager.preemptInputDispatch(); |
| 5256 | } |
| 5257 | |
| 5258 | public void setFocusedAppLw(AppWindowToken newApp) { |
| 5259 | // Focused app has changed. |
| 5260 | if (newApp == null) { |
| 5261 | mInputManager.setFocusedApplication(null); |
| 5262 | } else { |
| 5263 | mTempInputApplication.name = newApp.toString(); |
| 5264 | mTempInputApplication.dispatchingTimeoutNanos = |
| 5265 | newApp.inputDispatchingTimeoutNanos; |
| 5266 | mTempInputApplication.token = newApp; |
| 5267 | |
| 5268 | mInputManager.setFocusedApplication(mTempInputApplication); |
| 5269 | } |
| 5270 | } |
| 5271 | |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5272 | public void pauseDispatchingLw(WindowToken window) { |
| 5273 | if (! window.paused) { |
| 5274 | if (DEBUG_INPUT) { |
| 5275 | Slog.v(TAG, "Pausing WindowToken " + window); |
| 5276 | } |
| 5277 | |
| 5278 | window.paused = true; |
| 5279 | updateInputWindowsLw(); |
| 5280 | } |
| 5281 | } |
| 5282 | |
| 5283 | public void resumeDispatchingLw(WindowToken window) { |
| 5284 | if (window.paused) { |
| 5285 | if (DEBUG_INPUT) { |
| 5286 | Slog.v(TAG, "Resuming WindowToken " + window); |
| 5287 | } |
| 5288 | |
| 5289 | window.paused = false; |
| 5290 | updateInputWindowsLw(); |
| 5291 | } |
| 5292 | } |
| 5293 | |
| 5294 | public void freezeInputDispatchingLw() { |
| 5295 | if (! mInputDispatchFrozen) { |
| 5296 | if (DEBUG_INPUT) { |
| 5297 | Slog.v(TAG, "Freezing input dispatching"); |
| 5298 | } |
| 5299 | |
| 5300 | mInputDispatchFrozen = true; |
| 5301 | updateInputDispatchModeLw(); |
| 5302 | } |
| 5303 | } |
| 5304 | |
| 5305 | public void thawInputDispatchingLw() { |
| 5306 | if (mInputDispatchFrozen) { |
| 5307 | if (DEBUG_INPUT) { |
| 5308 | Slog.v(TAG, "Thawing input dispatching"); |
| 5309 | } |
| 5310 | |
| 5311 | mInputDispatchFrozen = false; |
| 5312 | updateInputDispatchModeLw(); |
| 5313 | } |
| 5314 | } |
| 5315 | |
| 5316 | public void setEventDispatchingLw(boolean enabled) { |
| 5317 | if (mInputDispatchEnabled != enabled) { |
| 5318 | if (DEBUG_INPUT) { |
| 5319 | Slog.v(TAG, "Setting event dispatching to " + enabled); |
| 5320 | } |
| 5321 | |
| 5322 | mInputDispatchEnabled = enabled; |
| 5323 | updateInputDispatchModeLw(); |
| 5324 | } |
| 5325 | } |
| 5326 | |
| 5327 | private void updateInputDispatchModeLw() { |
| 5328 | mInputManager.setInputDispatchMode(mInputDispatchEnabled, mInputDispatchFrozen); |
| 5329 | } |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5330 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5331 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5332 | public void pauseKeyDispatching(IBinder _token) { |
| 5333 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 5334 | "pauseKeyDispatching()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5335 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5336 | } |
| 5337 | |
| 5338 | synchronized (mWindowMap) { |
| 5339 | WindowToken token = mTokenMap.get(_token); |
| 5340 | if (token != null) { |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 5341 | mInputMonitor.pauseDispatchingLw(token); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5342 | } |
| 5343 | } |
| 5344 | } |
| 5345 | |
| 5346 | public void resumeKeyDispatching(IBinder _token) { |
| 5347 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 5348 | "resumeKeyDispatching()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5349 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5350 | } |
| 5351 | |
| 5352 | synchronized (mWindowMap) { |
| 5353 | WindowToken token = mTokenMap.get(_token); |
| 5354 | if (token != null) { |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 5355 | mInputMonitor.resumeDispatchingLw(token); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5356 | } |
| 5357 | } |
| 5358 | } |
| 5359 | |
| 5360 | public void setEventDispatching(boolean enabled) { |
| 5361 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 5362 | "resumeKeyDispatching()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5363 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5364 | } |
| 5365 | |
| 5366 | synchronized (mWindowMap) { |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 5367 | mInputMonitor.setEventDispatchingLw(enabled); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5368 | } |
| 5369 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5370 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5371 | /** |
| 5372 | * Injects a keystroke event into the UI. |
Jeff Brown | bbda99d | 2010-07-28 15:48:59 -0700 | [diff] [blame] | 5373 | * Even when sync is false, this method may block while waiting for current |
| 5374 | * input events to be dispatched. |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5375 | * |
| 5376 | * @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] | 5377 | * {@link SystemClock#uptimeMillis()} as the timebase.) |
| 5378 | * @param sync If true, wait for the event to be completed before returning to the caller. |
| 5379 | * @return Returns true if event was dispatched, false if it was dropped for any reason |
| 5380 | */ |
| 5381 | public boolean injectKeyEvent(KeyEvent ev, boolean sync) { |
| 5382 | long downTime = ev.getDownTime(); |
| 5383 | long eventTime = ev.getEventTime(); |
| 5384 | |
| 5385 | int action = ev.getAction(); |
| 5386 | int code = ev.getKeyCode(); |
| 5387 | int repeatCount = ev.getRepeatCount(); |
| 5388 | int metaState = ev.getMetaState(); |
| 5389 | int deviceId = ev.getDeviceId(); |
| 5390 | int scancode = ev.getScanCode(); |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 5391 | int source = ev.getSource(); |
| 5392 | |
| 5393 | if (source == InputDevice.SOURCE_UNKNOWN) { |
| 5394 | source = InputDevice.SOURCE_KEYBOARD; |
| 5395 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5396 | |
| 5397 | if (eventTime == 0) eventTime = SystemClock.uptimeMillis(); |
| 5398 | if (downTime == 0) downTime = eventTime; |
| 5399 | |
| 5400 | KeyEvent newEvent = new KeyEvent(downTime, eventTime, action, code, repeatCount, metaState, |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 5401 | deviceId, scancode, KeyEvent.FLAG_FROM_SYSTEM, source); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5402 | |
Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5403 | final int pid = Binder.getCallingPid(); |
| 5404 | final int uid = Binder.getCallingUid(); |
| 5405 | final long ident = Binder.clearCallingIdentity(); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5406 | |
Jeff Brown | bbda99d | 2010-07-28 15:48:59 -0700 | [diff] [blame] | 5407 | final int result = mInputManager.injectInputEvent(newEvent, pid, uid, |
| 5408 | sync ? InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH |
| 5409 | : InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT, |
| 5410 | INJECTION_TIMEOUT_MILLIS); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5411 | |
Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5412 | Binder.restoreCallingIdentity(ident); |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 5413 | return reportInjectionResult(result); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5414 | } |
| 5415 | |
| 5416 | /** |
| 5417 | * Inject a pointer (touch) event into the UI. |
Jeff Brown | bbda99d | 2010-07-28 15:48:59 -0700 | [diff] [blame] | 5418 | * Even when sync is false, this method may block while waiting for current |
| 5419 | * input events to be dispatched. |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5420 | * |
| 5421 | * @param ev A motion event describing the pointer (touch) action. (As noted in |
| 5422 | * {@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] | 5423 | * {@link SystemClock#uptimeMillis()} as the timebase.) |
| 5424 | * @param sync If true, wait for the event to be completed before returning to the caller. |
| 5425 | * @return Returns true if event was dispatched, false if it was dropped for any reason |
| 5426 | */ |
| 5427 | public boolean injectPointerEvent(MotionEvent ev, boolean sync) { |
Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5428 | final int pid = Binder.getCallingPid(); |
| 5429 | final int uid = Binder.getCallingUid(); |
| 5430 | final long ident = Binder.clearCallingIdentity(); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5431 | |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 5432 | MotionEvent newEvent = MotionEvent.obtain(ev); |
| 5433 | if ((newEvent.getSource() & InputDevice.SOURCE_CLASS_POINTER) == 0) { |
| 5434 | newEvent.setSource(InputDevice.SOURCE_TOUCHSCREEN); |
| 5435 | } |
| 5436 | |
Jeff Brown | bbda99d | 2010-07-28 15:48:59 -0700 | [diff] [blame] | 5437 | final int result = mInputManager.injectInputEvent(newEvent, pid, uid, |
| 5438 | sync ? InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH |
| 5439 | : InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT, |
| 5440 | INJECTION_TIMEOUT_MILLIS); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5441 | |
Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5442 | Binder.restoreCallingIdentity(ident); |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 5443 | return reportInjectionResult(result); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5444 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5445 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5446 | /** |
| 5447 | * Inject a trackball (navigation device) event into the UI. |
Jeff Brown | bbda99d | 2010-07-28 15:48:59 -0700 | [diff] [blame] | 5448 | * Even when sync is false, this method may block while waiting for current |
| 5449 | * input events to be dispatched. |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5450 | * |
| 5451 | * @param ev A motion event describing the trackball action. (As noted in |
| 5452 | * {@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] | 5453 | * {@link SystemClock#uptimeMillis()} as the timebase.) |
| 5454 | * @param sync If true, wait for the event to be completed before returning to the caller. |
| 5455 | * @return Returns true if event was dispatched, false if it was dropped for any reason |
| 5456 | */ |
| 5457 | public boolean injectTrackballEvent(MotionEvent ev, boolean sync) { |
Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5458 | final int pid = Binder.getCallingPid(); |
| 5459 | final int uid = Binder.getCallingUid(); |
| 5460 | final long ident = Binder.clearCallingIdentity(); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5461 | |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 5462 | MotionEvent newEvent = MotionEvent.obtain(ev); |
| 5463 | if ((newEvent.getSource() & InputDevice.SOURCE_CLASS_TRACKBALL) == 0) { |
| 5464 | newEvent.setSource(InputDevice.SOURCE_TRACKBALL); |
| 5465 | } |
| 5466 | |
Jeff Brown | bbda99d | 2010-07-28 15:48:59 -0700 | [diff] [blame] | 5467 | final int result = mInputManager.injectInputEvent(newEvent, pid, uid, |
| 5468 | sync ? InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH |
| 5469 | : InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT, |
| 5470 | INJECTION_TIMEOUT_MILLIS); |
| 5471 | |
| 5472 | Binder.restoreCallingIdentity(ident); |
| 5473 | return reportInjectionResult(result); |
| 5474 | } |
| 5475 | |
| 5476 | /** |
| 5477 | * Inject an input event into the UI without waiting for dispatch to commence. |
| 5478 | * This variant is useful for fire-and-forget input event injection. It does not |
| 5479 | * block any longer than it takes to enqueue the input event. |
| 5480 | * |
| 5481 | * @param ev An input event. (Be sure to set the input source correctly.) |
| 5482 | * @return Returns true if event was dispatched, false if it was dropped for any reason |
| 5483 | */ |
| 5484 | public boolean injectInputEventNoWait(InputEvent ev) { |
| 5485 | final int pid = Binder.getCallingPid(); |
| 5486 | final int uid = Binder.getCallingUid(); |
| 5487 | final long ident = Binder.clearCallingIdentity(); |
| 5488 | |
| 5489 | final int result = mInputManager.injectInputEvent(ev, pid, uid, |
| 5490 | InputManager.INPUT_EVENT_INJECTION_SYNC_NONE, |
| 5491 | INJECTION_TIMEOUT_MILLIS); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5492 | |
Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5493 | Binder.restoreCallingIdentity(ident); |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 5494 | return reportInjectionResult(result); |
| 5495 | } |
| 5496 | |
| 5497 | private boolean reportInjectionResult(int result) { |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 5498 | switch (result) { |
| 5499 | case InputManager.INPUT_EVENT_INJECTION_PERMISSION_DENIED: |
| 5500 | Slog.w(TAG, "Input event injection permission denied."); |
| 5501 | throw new SecurityException( |
| 5502 | "Injecting to another application requires INJECT_EVENTS permission"); |
| 5503 | case InputManager.INPUT_EVENT_INJECTION_SUCCEEDED: |
| 5504 | Slog.v(TAG, "Input event injection succeeded."); |
| 5505 | return true; |
| 5506 | case InputManager.INPUT_EVENT_INJECTION_TIMED_OUT: |
| 5507 | Slog.w(TAG, "Input event injection timed out."); |
| 5508 | return false; |
| 5509 | case InputManager.INPUT_EVENT_INJECTION_FAILED: |
| 5510 | default: |
| 5511 | Slog.w(TAG, "Input event injection failed."); |
| 5512 | return false; |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5513 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5514 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5515 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5516 | private WindowState getFocusedWindow() { |
| 5517 | synchronized (mWindowMap) { |
| 5518 | return getFocusedWindowLocked(); |
| 5519 | } |
| 5520 | } |
| 5521 | |
| 5522 | private WindowState getFocusedWindowLocked() { |
| 5523 | return mCurrentFocus; |
| 5524 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5525 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5526 | public boolean detectSafeMode() { |
| 5527 | mSafeMode = mPolicy.detectSafeMode(); |
| 5528 | return mSafeMode; |
| 5529 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5530 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5531 | public void systemReady() { |
| 5532 | mPolicy.systemReady(); |
| 5533 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5534 | |
Dianne Hackborn | 5132b37 | 2010-07-29 12:51:35 -0700 | [diff] [blame^] | 5535 | public void initDisplay() { |
| 5536 | synchronized(mWindowMap) { |
| 5537 | if (mDisplay != null) { |
| 5538 | throw new IllegalStateException("Display already initialized"); |
| 5539 | } |
| 5540 | WindowManager wm = (WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE); |
| 5541 | mDisplay = wm.getDefaultDisplay(); |
| 5542 | mInitialDisplayWidth = mDisplay.getWidth(); |
| 5543 | mInitialDisplayHeight = mDisplay.getHeight(); |
| 5544 | mInputManager.setDisplaySize(0, mInitialDisplayWidth, mInitialDisplayHeight); |
| 5545 | } |
| 5546 | |
| 5547 | try { |
| 5548 | mActivityManager.updateConfiguration(null); |
| 5549 | } catch (RemoteException e) { |
| 5550 | } |
| 5551 | } |
| 5552 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5553 | // ------------------------------------------------------------- |
| 5554 | // Client Session State |
| 5555 | // ------------------------------------------------------------- |
| 5556 | |
| 5557 | private final class Session extends IWindowSession.Stub |
| 5558 | implements IBinder.DeathRecipient { |
| 5559 | final IInputMethodClient mClient; |
| 5560 | final IInputContext mInputContext; |
| 5561 | final int mUid; |
| 5562 | final int mPid; |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 5563 | final String mStringName; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5564 | SurfaceSession mSurfaceSession; |
| 5565 | int mNumWindow = 0; |
| 5566 | boolean mClientDead = false; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5567 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5568 | public Session(IInputMethodClient client, IInputContext inputContext) { |
| 5569 | mClient = client; |
| 5570 | mInputContext = inputContext; |
| 5571 | mUid = Binder.getCallingUid(); |
| 5572 | mPid = Binder.getCallingPid(); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 5573 | StringBuilder sb = new StringBuilder(); |
| 5574 | sb.append("Session{"); |
| 5575 | sb.append(Integer.toHexString(System.identityHashCode(this))); |
| 5576 | sb.append(" uid "); |
| 5577 | sb.append(mUid); |
| 5578 | sb.append("}"); |
| 5579 | mStringName = sb.toString(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5580 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5581 | synchronized (mWindowMap) { |
| 5582 | if (mInputMethodManager == null && mHaveInputMethods) { |
| 5583 | IBinder b = ServiceManager.getService( |
| 5584 | Context.INPUT_METHOD_SERVICE); |
| 5585 | mInputMethodManager = IInputMethodManager.Stub.asInterface(b); |
| 5586 | } |
| 5587 | } |
| 5588 | long ident = Binder.clearCallingIdentity(); |
| 5589 | try { |
| 5590 | // Note: it is safe to call in to the input method manager |
| 5591 | // here because we are not holding our lock. |
| 5592 | if (mInputMethodManager != null) { |
| 5593 | mInputMethodManager.addClient(client, inputContext, |
| 5594 | mUid, mPid); |
| 5595 | } else { |
| 5596 | client.setUsingInputMethod(false); |
| 5597 | } |
| 5598 | client.asBinder().linkToDeath(this, 0); |
| 5599 | } catch (RemoteException e) { |
| 5600 | // The caller has died, so we can just forget about this. |
| 5601 | try { |
| 5602 | if (mInputMethodManager != null) { |
| 5603 | mInputMethodManager.removeClient(client); |
| 5604 | } |
| 5605 | } catch (RemoteException ee) { |
| 5606 | } |
| 5607 | } finally { |
| 5608 | Binder.restoreCallingIdentity(ident); |
| 5609 | } |
| 5610 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5611 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5612 | @Override |
| 5613 | public boolean onTransact(int code, Parcel data, Parcel reply, int flags) |
| 5614 | throws RemoteException { |
| 5615 | try { |
| 5616 | return super.onTransact(code, data, reply, flags); |
| 5617 | } catch (RuntimeException e) { |
| 5618 | // Log all 'real' exceptions thrown to the caller |
| 5619 | if (!(e instanceof SecurityException)) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5620 | Slog.e(TAG, "Window Session Crash", e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5621 | } |
| 5622 | throw e; |
| 5623 | } |
| 5624 | } |
| 5625 | |
| 5626 | public void binderDied() { |
| 5627 | // Note: it is safe to call in to the input method manager |
| 5628 | // here because we are not holding our lock. |
| 5629 | try { |
| 5630 | if (mInputMethodManager != null) { |
| 5631 | mInputMethodManager.removeClient(mClient); |
| 5632 | } |
| 5633 | } catch (RemoteException e) { |
| 5634 | } |
| 5635 | synchronized(mWindowMap) { |
Suchi Amalapurapu | fff2fda | 2009-06-30 21:36:16 -0700 | [diff] [blame] | 5636 | mClient.asBinder().unlinkToDeath(this, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5637 | mClientDead = true; |
| 5638 | killSessionLocked(); |
| 5639 | } |
| 5640 | } |
| 5641 | |
| 5642 | public int add(IWindow window, WindowManager.LayoutParams attrs, |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5643 | int viewVisibility, Rect outContentInsets, InputChannel outInputChannel) { |
| 5644 | return addWindow(this, window, attrs, viewVisibility, outContentInsets, |
| 5645 | outInputChannel); |
| 5646 | } |
| 5647 | |
| 5648 | public int addWithoutInputChannel(IWindow window, WindowManager.LayoutParams attrs, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5649 | int viewVisibility, Rect outContentInsets) { |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5650 | return addWindow(this, window, attrs, viewVisibility, outContentInsets, null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5651 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5652 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5653 | public void remove(IWindow window) { |
| 5654 | removeWindow(this, window); |
| 5655 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5656 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5657 | public int relayout(IWindow window, WindowManager.LayoutParams attrs, |
| 5658 | int requestedWidth, int requestedHeight, int viewFlags, |
| 5659 | boolean insetsPending, Rect outFrame, Rect outContentInsets, |
Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 5660 | Rect outVisibleInsets, Configuration outConfig, Surface outSurface) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5661 | return relayoutWindow(this, window, attrs, |
| 5662 | requestedWidth, requestedHeight, viewFlags, insetsPending, |
Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 5663 | outFrame, outContentInsets, outVisibleInsets, outConfig, outSurface); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5664 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5665 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5666 | public void setTransparentRegion(IWindow window, Region region) { |
| 5667 | setTransparentRegionWindow(this, window, region); |
| 5668 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5669 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5670 | public void setInsets(IWindow window, int touchableInsets, |
| 5671 | Rect contentInsets, Rect visibleInsets) { |
| 5672 | setInsetsWindow(this, window, touchableInsets, contentInsets, |
| 5673 | visibleInsets); |
| 5674 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5675 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5676 | public void getDisplayFrame(IWindow window, Rect outDisplayFrame) { |
| 5677 | getWindowDisplayFrame(this, window, outDisplayFrame); |
| 5678 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5679 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5680 | public void finishDrawing(IWindow window) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5681 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5682 | TAG, "IWindow finishDrawing called for " + window); |
| 5683 | finishDrawingWindow(this, window); |
| 5684 | } |
| 5685 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5686 | public void setInTouchMode(boolean mode) { |
| 5687 | synchronized(mWindowMap) { |
| 5688 | mInTouchMode = mode; |
| 5689 | } |
| 5690 | } |
| 5691 | |
| 5692 | public boolean getInTouchMode() { |
| 5693 | synchronized(mWindowMap) { |
| 5694 | return mInTouchMode; |
| 5695 | } |
| 5696 | } |
| 5697 | |
| 5698 | public boolean performHapticFeedback(IWindow window, int effectId, |
| 5699 | boolean always) { |
| 5700 | synchronized(mWindowMap) { |
| 5701 | long ident = Binder.clearCallingIdentity(); |
| 5702 | try { |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 5703 | return mPolicy.performHapticFeedbackLw( |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 5704 | windowForClientLocked(this, window, true), |
| 5705 | effectId, always); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5706 | } finally { |
| 5707 | Binder.restoreCallingIdentity(ident); |
| 5708 | } |
| 5709 | } |
| 5710 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5711 | |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 5712 | 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] | 5713 | synchronized(mWindowMap) { |
| 5714 | long ident = Binder.clearCallingIdentity(); |
| 5715 | try { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 5716 | setWindowWallpaperPositionLocked( |
| 5717 | windowForClientLocked(this, window, true), |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 5718 | x, y, xStep, yStep); |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 5719 | } finally { |
| 5720 | Binder.restoreCallingIdentity(ident); |
| 5721 | } |
| 5722 | } |
| 5723 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 5724 | |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 5725 | public void wallpaperOffsetsComplete(IBinder window) { |
| 5726 | WindowManagerService.this.wallpaperOffsetsComplete(window); |
| 5727 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 5728 | |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 5729 | public Bundle sendWallpaperCommand(IBinder window, String action, int x, int y, |
| 5730 | int z, Bundle extras, boolean sync) { |
| 5731 | synchronized(mWindowMap) { |
| 5732 | long ident = Binder.clearCallingIdentity(); |
| 5733 | try { |
| 5734 | return sendWindowWallpaperCommandLocked( |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 5735 | windowForClientLocked(this, window, true), |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 5736 | action, x, y, z, extras, sync); |
| 5737 | } finally { |
| 5738 | Binder.restoreCallingIdentity(ident); |
| 5739 | } |
| 5740 | } |
| 5741 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 5742 | |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 5743 | public void wallpaperCommandComplete(IBinder window, Bundle result) { |
| 5744 | WindowManagerService.this.wallpaperCommandComplete(window, result); |
| 5745 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 5746 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5747 | void windowAddedLocked() { |
| 5748 | if (mSurfaceSession == null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5749 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5750 | TAG, "First window added to " + this + ", creating SurfaceSession"); |
| 5751 | mSurfaceSession = new SurfaceSession(); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5752 | if (SHOW_TRANSACTIONS) Slog.i( |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 5753 | TAG, " NEW SURFACE SESSION " + mSurfaceSession); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5754 | mSessions.add(this); |
| 5755 | } |
| 5756 | mNumWindow++; |
| 5757 | } |
| 5758 | |
| 5759 | void windowRemovedLocked() { |
| 5760 | mNumWindow--; |
| 5761 | killSessionLocked(); |
| 5762 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5763 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5764 | void killSessionLocked() { |
| 5765 | if (mNumWindow <= 0 && mClientDead) { |
| 5766 | mSessions.remove(this); |
| 5767 | if (mSurfaceSession != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5768 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5769 | TAG, "Last window removed from " + this |
| 5770 | + ", destroying " + mSurfaceSession); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5771 | if (SHOW_TRANSACTIONS) Slog.i( |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 5772 | TAG, " KILL SURFACE SESSION " + mSurfaceSession); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5773 | try { |
| 5774 | mSurfaceSession.kill(); |
| 5775 | } catch (Exception e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5776 | Slog.w(TAG, "Exception thrown when killing surface session " |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5777 | + mSurfaceSession + " in session " + this |
| 5778 | + ": " + e.toString()); |
| 5779 | } |
| 5780 | mSurfaceSession = null; |
| 5781 | } |
| 5782 | } |
| 5783 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5784 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5785 | void dump(PrintWriter pw, String prefix) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 5786 | pw.print(prefix); pw.print("mNumWindow="); pw.print(mNumWindow); |
| 5787 | pw.print(" mClientDead="); pw.print(mClientDead); |
| 5788 | pw.print(" mSurfaceSession="); pw.println(mSurfaceSession); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5789 | } |
| 5790 | |
| 5791 | @Override |
| 5792 | public String toString() { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 5793 | return mStringName; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5794 | } |
| 5795 | } |
| 5796 | |
| 5797 | // ------------------------------------------------------------- |
| 5798 | // Client Window State |
| 5799 | // ------------------------------------------------------------- |
| 5800 | |
| 5801 | private final class WindowState implements WindowManagerPolicy.WindowState { |
| 5802 | final Session mSession; |
| 5803 | final IWindow mClient; |
| 5804 | WindowToken mToken; |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 5805 | WindowToken mRootToken; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5806 | AppWindowToken mAppToken; |
| 5807 | AppWindowToken mTargetAppToken; |
| 5808 | final WindowManager.LayoutParams mAttrs = new WindowManager.LayoutParams(); |
| 5809 | final DeathRecipient mDeathRecipient; |
| 5810 | final WindowState mAttachedWindow; |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 5811 | final ArrayList<WindowState> mChildWindows = new ArrayList<WindowState>(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5812 | final int mBaseLayer; |
| 5813 | final int mSubLayer; |
| 5814 | final boolean mLayoutAttached; |
| 5815 | final boolean mIsImWindow; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 5816 | final boolean mIsWallpaper; |
| 5817 | final boolean mIsFloatingLayer; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5818 | int mViewVisibility; |
| 5819 | boolean mPolicyVisibility = true; |
| 5820 | boolean mPolicyVisibilityAfterAnim = true; |
| 5821 | boolean mAppFreezing; |
| 5822 | Surface mSurface; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 5823 | boolean mReportDestroySurface; |
| 5824 | boolean mSurfacePendingDestroy; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5825 | boolean mAttachedHidden; // is our parent window hidden? |
| 5826 | boolean mLastHidden; // was this window last hidden? |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 5827 | boolean mWallpaperVisible; // for wallpaper, what was last vis report? |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5828 | int mRequestedWidth; |
| 5829 | int mRequestedHeight; |
| 5830 | int mLastRequestedWidth; |
| 5831 | int mLastRequestedHeight; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5832 | int mLayer; |
| 5833 | int mAnimLayer; |
| 5834 | int mLastLayer; |
| 5835 | boolean mHaveFrame; |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 5836 | boolean mObscured; |
Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 5837 | boolean mTurnOnScreen; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5838 | |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 5839 | int mLayoutSeq = -1; |
| 5840 | |
| 5841 | Configuration mConfiguration = null; |
| 5842 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5843 | // Actual frame shown on-screen (may be modified by animation) |
| 5844 | final Rect mShownFrame = new Rect(); |
| 5845 | final Rect mLastShownFrame = new Rect(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5846 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5847 | /** |
Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 5848 | * Set when we have changed the size of the surface, to know that |
| 5849 | * we must tell them application to resize (and thus redraw itself). |
| 5850 | */ |
| 5851 | boolean mSurfaceResized; |
| 5852 | |
| 5853 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5854 | * Insets that determine the actually visible area |
| 5855 | */ |
| 5856 | final Rect mVisibleInsets = new Rect(); |
| 5857 | final Rect mLastVisibleInsets = new Rect(); |
| 5858 | boolean mVisibleInsetsChanged; |
| 5859 | |
| 5860 | /** |
| 5861 | * Insets that are covered by system windows |
| 5862 | */ |
| 5863 | final Rect mContentInsets = new Rect(); |
| 5864 | final Rect mLastContentInsets = new Rect(); |
| 5865 | boolean mContentInsetsChanged; |
| 5866 | |
| 5867 | /** |
| 5868 | * Set to true if we are waiting for this window to receive its |
| 5869 | * given internal insets before laying out other windows based on it. |
| 5870 | */ |
| 5871 | boolean mGivenInsetsPending; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5872 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5873 | /** |
| 5874 | * These are the content insets that were given during layout for |
| 5875 | * this window, to be applied to windows behind it. |
| 5876 | */ |
| 5877 | final Rect mGivenContentInsets = new Rect(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5878 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5879 | /** |
| 5880 | * These are the visible insets that were given during layout for |
| 5881 | * this window, to be applied to windows behind it. |
| 5882 | */ |
| 5883 | final Rect mGivenVisibleInsets = new Rect(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5884 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5885 | /** |
| 5886 | * Flag indicating whether the touchable region should be adjusted by |
| 5887 | * the visible insets; if false the area outside the visible insets is |
| 5888 | * NOT touchable, so we must use those to adjust the frame during hit |
| 5889 | * tests. |
| 5890 | */ |
| 5891 | int mTouchableInsets = ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5892 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5893 | // Current transformation being applied. |
| 5894 | float mDsDx=1, mDtDx=0, mDsDy=0, mDtDy=1; |
| 5895 | float mLastDsDx=1, mLastDtDx=0, mLastDsDy=0, mLastDtDy=1; |
| 5896 | float mHScale=1, mVScale=1; |
| 5897 | float mLastHScale=1, mLastVScale=1; |
| 5898 | final Matrix mTmpMatrix = new Matrix(); |
| 5899 | |
| 5900 | // "Real" frame that the application sees. |
| 5901 | final Rect mFrame = new Rect(); |
| 5902 | final Rect mLastFrame = new Rect(); |
| 5903 | |
| 5904 | final Rect mContainingFrame = new Rect(); |
| 5905 | final Rect mDisplayFrame = new Rect(); |
| 5906 | final Rect mContentFrame = new Rect(); |
| 5907 | final Rect mVisibleFrame = new Rect(); |
| 5908 | |
| 5909 | float mShownAlpha = 1; |
| 5910 | float mAlpha = 1; |
| 5911 | float mLastAlpha = 1; |
| 5912 | |
| 5913 | // Set to true if, when the window gets displayed, it should perform |
| 5914 | // an enter animation. |
| 5915 | boolean mEnterAnimationPending; |
| 5916 | |
| 5917 | // Currently running animation. |
| 5918 | boolean mAnimating; |
| 5919 | boolean mLocalAnimating; |
| 5920 | Animation mAnimation; |
| 5921 | boolean mAnimationIsEntrance; |
| 5922 | boolean mHasTransformation; |
| 5923 | boolean mHasLocalTransformation; |
| 5924 | final Transformation mTransformation = new Transformation(); |
| 5925 | |
Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 5926 | // If a window showing a wallpaper: the requested offset for the |
| 5927 | // wallpaper; if a wallpaper window: the currently applied offset. |
| 5928 | float mWallpaperX = -1; |
| 5929 | float mWallpaperY = -1; |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 5930 | |
| 5931 | // If a window showing a wallpaper: what fraction of the offset |
| 5932 | // range corresponds to a full virtual screen. |
| 5933 | float mWallpaperXStep = -1; |
| 5934 | float mWallpaperYStep = -1; |
| 5935 | |
Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 5936 | // Wallpaper windows: pixels offset based on above variables. |
| 5937 | int mXOffset; |
| 5938 | int mYOffset; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 5939 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5940 | // This is set after IWindowSession.relayout() has been called at |
| 5941 | // least once for the window. It allows us to detect the situation |
| 5942 | // where we don't yet have a surface, but should have one soon, so |
| 5943 | // we can give the window focus before waiting for the relayout. |
| 5944 | boolean mRelayoutCalled; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5945 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5946 | // This is set after the Surface has been created but before the |
| 5947 | // window has been drawn. During this time the surface is hidden. |
| 5948 | boolean mDrawPending; |
| 5949 | |
| 5950 | // This is set after the window has finished drawing for the first |
| 5951 | // time but before its surface is shown. The surface will be |
| 5952 | // displayed when the next layout is run. |
| 5953 | boolean mCommitDrawPending; |
| 5954 | |
| 5955 | // This is set during the time after the window's drawing has been |
| 5956 | // committed, and before its surface is actually shown. It is used |
| 5957 | // to delay showing the surface until all windows in a token are ready |
| 5958 | // to be shown. |
| 5959 | boolean mReadyToShow; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5960 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5961 | // Set when the window has been shown in the screen the first time. |
| 5962 | boolean mHasDrawn; |
| 5963 | |
| 5964 | // Currently running an exit animation? |
| 5965 | boolean mExiting; |
| 5966 | |
| 5967 | // Currently on the mDestroySurface list? |
| 5968 | boolean mDestroying; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5969 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5970 | // Completely remove from window manager after exit animation? |
| 5971 | boolean mRemoveOnExit; |
| 5972 | |
| 5973 | // Set when the orientation is changing and this window has not yet |
| 5974 | // been updated for the new orientation. |
| 5975 | boolean mOrientationChanging; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5976 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5977 | // Is this window now (or just being) removed? |
| 5978 | boolean mRemoved; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5979 | |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 5980 | // For debugging, this is the last information given to the surface flinger. |
| 5981 | boolean mSurfaceShown; |
| 5982 | int mSurfaceX, mSurfaceY, mSurfaceW, mSurfaceH; |
| 5983 | int mSurfaceLayer; |
| 5984 | float mSurfaceAlpha; |
| 5985 | |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5986 | // Input channel |
| 5987 | InputChannel mInputChannel; |
| 5988 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5989 | WindowState(Session s, IWindow c, WindowToken token, |
| 5990 | WindowState attachedWindow, WindowManager.LayoutParams a, |
| 5991 | int viewVisibility) { |
| 5992 | mSession = s; |
| 5993 | mClient = c; |
| 5994 | mToken = token; |
| 5995 | mAttrs.copyFrom(a); |
| 5996 | mViewVisibility = viewVisibility; |
| 5997 | DeathRecipient deathRecipient = new DeathRecipient(); |
| 5998 | mAlpha = a.alpha; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5999 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6000 | TAG, "Window " + this + " client=" + c.asBinder() |
| 6001 | + " token=" + token + " (" + mAttrs.token + ")"); |
| 6002 | try { |
| 6003 | c.asBinder().linkToDeath(deathRecipient, 0); |
| 6004 | } catch (RemoteException e) { |
| 6005 | mDeathRecipient = null; |
| 6006 | mAttachedWindow = null; |
| 6007 | mLayoutAttached = false; |
| 6008 | mIsImWindow = false; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 6009 | mIsWallpaper = false; |
| 6010 | mIsFloatingLayer = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6011 | mBaseLayer = 0; |
| 6012 | mSubLayer = 0; |
| 6013 | return; |
| 6014 | } |
| 6015 | mDeathRecipient = deathRecipient; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6016 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6017 | if ((mAttrs.type >= FIRST_SUB_WINDOW && |
| 6018 | mAttrs.type <= LAST_SUB_WINDOW)) { |
| 6019 | // The multiplier here is to reserve space for multiple |
| 6020 | // windows in the same type layer. |
| 6021 | mBaseLayer = mPolicy.windowTypeToLayerLw( |
| 6022 | attachedWindow.mAttrs.type) * TYPE_LAYER_MULTIPLIER |
| 6023 | + TYPE_LAYER_OFFSET; |
| 6024 | mSubLayer = mPolicy.subWindowTypeToLayerLw(a.type); |
| 6025 | mAttachedWindow = attachedWindow; |
| 6026 | mAttachedWindow.mChildWindows.add(this); |
| 6027 | mLayoutAttached = mAttrs.type != |
| 6028 | WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG; |
| 6029 | mIsImWindow = attachedWindow.mAttrs.type == TYPE_INPUT_METHOD |
| 6030 | || attachedWindow.mAttrs.type == TYPE_INPUT_METHOD_DIALOG; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 6031 | mIsWallpaper = attachedWindow.mAttrs.type == TYPE_WALLPAPER; |
| 6032 | mIsFloatingLayer = mIsImWindow || mIsWallpaper; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6033 | } else { |
| 6034 | // The multiplier here is to reserve space for multiple |
| 6035 | // windows in the same type layer. |
| 6036 | mBaseLayer = mPolicy.windowTypeToLayerLw(a.type) |
| 6037 | * TYPE_LAYER_MULTIPLIER |
| 6038 | + TYPE_LAYER_OFFSET; |
| 6039 | mSubLayer = 0; |
| 6040 | mAttachedWindow = null; |
| 6041 | mLayoutAttached = false; |
| 6042 | mIsImWindow = mAttrs.type == TYPE_INPUT_METHOD |
| 6043 | || mAttrs.type == TYPE_INPUT_METHOD_DIALOG; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 6044 | mIsWallpaper = mAttrs.type == TYPE_WALLPAPER; |
| 6045 | mIsFloatingLayer = mIsImWindow || mIsWallpaper; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6046 | } |
| 6047 | |
| 6048 | WindowState appWin = this; |
| 6049 | while (appWin.mAttachedWindow != null) { |
| 6050 | appWin = mAttachedWindow; |
| 6051 | } |
| 6052 | WindowToken appToken = appWin.mToken; |
| 6053 | while (appToken.appWindowToken == null) { |
| 6054 | WindowToken parent = mTokenMap.get(appToken.token); |
| 6055 | if (parent == null || appToken == parent) { |
| 6056 | break; |
| 6057 | } |
| 6058 | appToken = parent; |
| 6059 | } |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 6060 | mRootToken = appToken; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6061 | mAppToken = appToken.appWindowToken; |
| 6062 | |
| 6063 | mSurface = null; |
| 6064 | mRequestedWidth = 0; |
| 6065 | mRequestedHeight = 0; |
| 6066 | mLastRequestedWidth = 0; |
| 6067 | mLastRequestedHeight = 0; |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 6068 | mXOffset = 0; |
| 6069 | mYOffset = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6070 | mLayer = 0; |
| 6071 | mAnimLayer = 0; |
| 6072 | mLastLayer = 0; |
| 6073 | } |
| 6074 | |
| 6075 | void attach() { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6076 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6077 | TAG, "Attaching " + this + " token=" + mToken |
| 6078 | + ", list=" + mToken.windows); |
| 6079 | mSession.windowAddedLocked(); |
| 6080 | } |
| 6081 | |
| 6082 | public void computeFrameLw(Rect pf, Rect df, Rect cf, Rect vf) { |
| 6083 | mHaveFrame = true; |
| 6084 | |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 6085 | final Rect container = mContainingFrame; |
| 6086 | container.set(pf); |
| 6087 | |
| 6088 | final Rect display = mDisplayFrame; |
| 6089 | display.set(df); |
| 6090 | |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 6091 | if ((mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0) { |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 6092 | container.intersect(mCompatibleScreenFrame); |
Mitsuru Oshima | d2967e2 | 2009-07-20 14:01:43 -0700 | [diff] [blame] | 6093 | if ((mAttrs.flags & FLAG_LAYOUT_NO_LIMITS) == 0) { |
| 6094 | display.intersect(mCompatibleScreenFrame); |
| 6095 | } |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 6096 | } |
| 6097 | |
| 6098 | final int pw = container.right - container.left; |
| 6099 | final int ph = container.bottom - container.top; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6100 | |
| 6101 | int w,h; |
| 6102 | if ((mAttrs.flags & mAttrs.FLAG_SCALED) != 0) { |
| 6103 | w = mAttrs.width < 0 ? pw : mAttrs.width; |
| 6104 | h = mAttrs.height< 0 ? ph : mAttrs.height; |
| 6105 | } else { |
Romain Guy | 980a938 | 2010-01-08 15:06:28 -0800 | [diff] [blame] | 6106 | w = mAttrs.width == mAttrs.MATCH_PARENT ? pw : mRequestedWidth; |
| 6107 | h = mAttrs.height== mAttrs.MATCH_PARENT ? ph : mRequestedHeight; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6108 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6109 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6110 | final Rect content = mContentFrame; |
| 6111 | content.set(cf); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6112 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6113 | final Rect visible = mVisibleFrame; |
| 6114 | visible.set(vf); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6115 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6116 | final Rect frame = mFrame; |
Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 6117 | final int fw = frame.width(); |
| 6118 | final int fh = frame.height(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6119 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6120 | //System.out.println("In: w=" + w + " h=" + h + " container=" + |
| 6121 | // container + " x=" + mAttrs.x + " y=" + mAttrs.y); |
| 6122 | |
| 6123 | Gravity.apply(mAttrs.gravity, w, h, container, |
| 6124 | (int) (mAttrs.x + mAttrs.horizontalMargin * pw), |
| 6125 | (int) (mAttrs.y + mAttrs.verticalMargin * ph), frame); |
| 6126 | |
| 6127 | //System.out.println("Out: " + mFrame); |
| 6128 | |
| 6129 | // Now make sure the window fits in the overall display. |
| 6130 | Gravity.applyDisplay(mAttrs.gravity, df, frame); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6131 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6132 | // Make sure the content and visible frames are inside of the |
| 6133 | // final window frame. |
| 6134 | if (content.left < frame.left) content.left = frame.left; |
| 6135 | if (content.top < frame.top) content.top = frame.top; |
| 6136 | if (content.right > frame.right) content.right = frame.right; |
| 6137 | if (content.bottom > frame.bottom) content.bottom = frame.bottom; |
| 6138 | if (visible.left < frame.left) visible.left = frame.left; |
| 6139 | if (visible.top < frame.top) visible.top = frame.top; |
| 6140 | if (visible.right > frame.right) visible.right = frame.right; |
| 6141 | if (visible.bottom > frame.bottom) visible.bottom = frame.bottom; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6142 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6143 | final Rect contentInsets = mContentInsets; |
| 6144 | contentInsets.left = content.left-frame.left; |
| 6145 | contentInsets.top = content.top-frame.top; |
| 6146 | contentInsets.right = frame.right-content.right; |
| 6147 | contentInsets.bottom = frame.bottom-content.bottom; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6148 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6149 | final Rect visibleInsets = mVisibleInsets; |
| 6150 | visibleInsets.left = visible.left-frame.left; |
| 6151 | visibleInsets.top = visible.top-frame.top; |
| 6152 | visibleInsets.right = frame.right-visible.right; |
| 6153 | visibleInsets.bottom = frame.bottom-visible.bottom; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6154 | |
Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 6155 | if (mIsWallpaper && (fw != frame.width() || fh != frame.height())) { |
| 6156 | updateWallpaperOffsetLocked(this, mDisplay.getWidth(), |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 6157 | mDisplay.getHeight(), false); |
Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 6158 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6159 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6160 | if (localLOGV) { |
| 6161 | //if ("com.google.android.youtube".equals(mAttrs.packageName) |
| 6162 | // && mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_PANEL) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6163 | Slog.v(TAG, "Resolving (mRequestedWidth=" |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6164 | + mRequestedWidth + ", mRequestedheight=" |
| 6165 | + mRequestedHeight + ") to" + " (pw=" + pw + ", ph=" + ph |
| 6166 | + "): frame=" + mFrame.toShortString() |
| 6167 | + " ci=" + contentInsets.toShortString() |
| 6168 | + " vi=" + visibleInsets.toShortString()); |
| 6169 | //} |
| 6170 | } |
| 6171 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6172 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6173 | public Rect getFrameLw() { |
| 6174 | return mFrame; |
| 6175 | } |
| 6176 | |
| 6177 | public Rect getShownFrameLw() { |
| 6178 | return mShownFrame; |
| 6179 | } |
| 6180 | |
| 6181 | public Rect getDisplayFrameLw() { |
| 6182 | return mDisplayFrame; |
| 6183 | } |
| 6184 | |
| 6185 | public Rect getContentFrameLw() { |
| 6186 | return mContentFrame; |
| 6187 | } |
| 6188 | |
| 6189 | public Rect getVisibleFrameLw() { |
| 6190 | return mVisibleFrame; |
| 6191 | } |
| 6192 | |
| 6193 | public boolean getGivenInsetsPendingLw() { |
| 6194 | return mGivenInsetsPending; |
| 6195 | } |
| 6196 | |
| 6197 | public Rect getGivenContentInsetsLw() { |
| 6198 | return mGivenContentInsets; |
| 6199 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6200 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6201 | public Rect getGivenVisibleInsetsLw() { |
| 6202 | return mGivenVisibleInsets; |
| 6203 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6204 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6205 | public WindowManager.LayoutParams getAttrs() { |
| 6206 | return mAttrs; |
| 6207 | } |
| 6208 | |
| 6209 | public int getSurfaceLayer() { |
| 6210 | return mLayer; |
| 6211 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6212 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6213 | public IApplicationToken getAppToken() { |
| 6214 | return mAppToken != null ? mAppToken.appToken : null; |
| 6215 | } |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 6216 | |
| 6217 | public long getInputDispatchingTimeoutNanos() { |
| 6218 | return mAppToken != null |
| 6219 | ? mAppToken.inputDispatchingTimeoutNanos |
| 6220 | : DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS; |
| 6221 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6222 | |
| 6223 | public boolean hasAppShownWindows() { |
| 6224 | return mAppToken != null ? mAppToken.firstWindowDrawn : false; |
| 6225 | } |
| 6226 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6227 | public void setAnimation(Animation anim) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6228 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6229 | TAG, "Setting animation in " + this + ": " + anim); |
| 6230 | mAnimating = false; |
| 6231 | mLocalAnimating = false; |
| 6232 | mAnimation = anim; |
| 6233 | mAnimation.restrictDuration(MAX_ANIMATION_DURATION); |
| 6234 | mAnimation.scaleCurrentDuration(mWindowAnimationScale); |
| 6235 | } |
| 6236 | |
| 6237 | public void clearAnimation() { |
| 6238 | if (mAnimation != null) { |
| 6239 | mAnimating = true; |
| 6240 | mLocalAnimating = false; |
| 6241 | mAnimation = null; |
| 6242 | } |
| 6243 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6244 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6245 | Surface createSurfaceLocked() { |
| 6246 | if (mSurface == null) { |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 6247 | mReportDestroySurface = false; |
| 6248 | mSurfacePendingDestroy = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6249 | mDrawPending = true; |
| 6250 | mCommitDrawPending = false; |
| 6251 | mReadyToShow = false; |
| 6252 | if (mAppToken != null) { |
| 6253 | mAppToken.allDrawn = false; |
| 6254 | } |
| 6255 | |
| 6256 | int flags = 0; |
Mathias Agopian | 317a628 | 2009-08-13 17:29:02 -0700 | [diff] [blame] | 6257 | if (mAttrs.memoryType == MEMORY_TYPE_PUSH_BUFFERS) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6258 | flags |= Surface.PUSH_BUFFERS; |
| 6259 | } |
| 6260 | |
| 6261 | if ((mAttrs.flags&WindowManager.LayoutParams.FLAG_SECURE) != 0) { |
| 6262 | flags |= Surface.SECURE; |
| 6263 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6264 | if (DEBUG_VISIBILITY) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6265 | TAG, "Creating surface in session " |
| 6266 | + mSession.mSurfaceSession + " window " + this |
| 6267 | + " w=" + mFrame.width() |
| 6268 | + " h=" + mFrame.height() + " format=" |
| 6269 | + mAttrs.format + " flags=" + flags); |
| 6270 | |
| 6271 | int w = mFrame.width(); |
| 6272 | int h = mFrame.height(); |
| 6273 | if ((mAttrs.flags & LayoutParams.FLAG_SCALED) != 0) { |
| 6274 | // for a scaled surface, we always want the requested |
| 6275 | // size. |
| 6276 | w = mRequestedWidth; |
| 6277 | h = mRequestedHeight; |
| 6278 | } |
| 6279 | |
Romain Guy | 9825ec6 | 2009-10-01 00:58:09 -0700 | [diff] [blame] | 6280 | // Something is wrong and SurfaceFlinger will not like this, |
| 6281 | // try to revert to sane values |
| 6282 | if (w <= 0) w = 1; |
| 6283 | if (h <= 0) h = 1; |
| 6284 | |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 6285 | mSurfaceShown = false; |
| 6286 | mSurfaceLayer = 0; |
| 6287 | mSurfaceAlpha = 1; |
| 6288 | mSurfaceX = 0; |
| 6289 | mSurfaceY = 0; |
| 6290 | mSurfaceW = w; |
| 6291 | mSurfaceH = h; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6292 | try { |
| 6293 | mSurface = new Surface( |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6294 | mSession.mSurfaceSession, mSession.mPid, |
Mathias Agopian | 5d26c1e | 2010-03-01 16:09:43 -0800 | [diff] [blame] | 6295 | mAttrs.getTitle().toString(), |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6296 | 0, w, h, mAttrs.format, flags); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6297 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " CREATE SURFACE " |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 6298 | + mSurface + " IN SESSION " |
| 6299 | + mSession.mSurfaceSession |
| 6300 | + ": pid=" + mSession.mPid + " format=" |
| 6301 | + mAttrs.format + " flags=0x" |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 6302 | + Integer.toHexString(flags) |
| 6303 | + " / " + this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6304 | } catch (Surface.OutOfResourcesException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6305 | Slog.w(TAG, "OutOfResourcesException creating surface"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6306 | reclaimSomeSurfaceMemoryLocked(this, "create"); |
| 6307 | return null; |
| 6308 | } catch (Exception e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6309 | Slog.e(TAG, "Exception creating surface", e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6310 | return null; |
| 6311 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6312 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6313 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6314 | TAG, "Got surface: " + mSurface |
| 6315 | + ", set left=" + mFrame.left + " top=" + mFrame.top |
| 6316 | + ", animLayer=" + mAnimLayer); |
| 6317 | if (SHOW_TRANSACTIONS) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6318 | Slog.i(TAG, ">>> OPEN TRANSACTION"); |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 6319 | if (SHOW_TRANSACTIONS) logSurface(this, |
| 6320 | "CREATE pos=(" + mFrame.left + "," + mFrame.top + ") (" + |
| 6321 | mFrame.width() + "x" + mFrame.height() + "), layer=" + |
| 6322 | mAnimLayer + " HIDE", null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6323 | } |
| 6324 | Surface.openTransaction(); |
| 6325 | try { |
| 6326 | try { |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 6327 | mSurfaceX = mFrame.left + mXOffset; |
Dianne Hackborn | 529bef6 | 2010-03-25 11:48:43 -0700 | [diff] [blame] | 6328 | mSurfaceY = mFrame.top + mYOffset; |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 6329 | mSurface.setPosition(mSurfaceX, mSurfaceY); |
| 6330 | mSurfaceLayer = mAnimLayer; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6331 | mSurface.setLayer(mAnimLayer); |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 6332 | mSurfaceShown = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6333 | mSurface.hide(); |
| 6334 | if ((mAttrs.flags&WindowManager.LayoutParams.FLAG_DITHER) != 0) { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 6335 | if (SHOW_TRANSACTIONS) logSurface(this, "DITHER", null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6336 | mSurface.setFlags(Surface.SURFACE_DITHER, |
| 6337 | Surface.SURFACE_DITHER); |
| 6338 | } |
| 6339 | } catch (RuntimeException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6340 | Slog.w(TAG, "Error creating surface in " + w, e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6341 | reclaimSomeSurfaceMemoryLocked(this, "create-init"); |
| 6342 | } |
| 6343 | mLastHidden = true; |
| 6344 | } finally { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6345 | if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6346 | Surface.closeTransaction(); |
| 6347 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6348 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6349 | TAG, "Created surface " + this); |
| 6350 | } |
| 6351 | return mSurface; |
| 6352 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6353 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6354 | void destroySurfaceLocked() { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6355 | if (mAppToken != null && this == mAppToken.startingWindow) { |
| 6356 | mAppToken.startingDisplayed = false; |
| 6357 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6358 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6359 | if (mSurface != null) { |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 6360 | mDrawPending = false; |
| 6361 | mCommitDrawPending = false; |
| 6362 | mReadyToShow = false; |
| 6363 | |
| 6364 | int i = mChildWindows.size(); |
| 6365 | while (i > 0) { |
| 6366 | i--; |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 6367 | WindowState c = mChildWindows.get(i); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 6368 | c.mAttachedHidden = true; |
| 6369 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6370 | |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 6371 | if (mReportDestroySurface) { |
| 6372 | mReportDestroySurface = false; |
| 6373 | mSurfacePendingDestroy = true; |
| 6374 | try { |
| 6375 | mClient.dispatchGetNewSurface(); |
| 6376 | // We'll really destroy on the next time around. |
| 6377 | return; |
| 6378 | } catch (RemoteException e) { |
| 6379 | } |
| 6380 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6381 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6382 | try { |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 6383 | if (DEBUG_VISIBILITY) { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 6384 | RuntimeException e = null; |
| 6385 | if (!HIDE_STACK_CRAWLS) { |
| 6386 | e = new RuntimeException(); |
| 6387 | e.fillInStackTrace(); |
| 6388 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6389 | Slog.w(TAG, "Window " + this + " destroying surface " |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 6390 | + mSurface + ", session " + mSession, e); |
| 6391 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6392 | if (SHOW_TRANSACTIONS) { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 6393 | RuntimeException e = null; |
| 6394 | if (!HIDE_STACK_CRAWLS) { |
| 6395 | e = new RuntimeException(); |
| 6396 | e.fillInStackTrace(); |
| 6397 | } |
| 6398 | if (SHOW_TRANSACTIONS) logSurface(this, "DESTROY", e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6399 | } |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 6400 | mSurface.destroy(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6401 | } catch (RuntimeException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6402 | Slog.w(TAG, "Exception thrown when destroying Window " + this |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6403 | + " surface " + mSurface + " session " + mSession |
| 6404 | + ": " + e.toString()); |
| 6405 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6406 | |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 6407 | mSurfaceShown = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6408 | mSurface = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6409 | } |
| 6410 | } |
| 6411 | |
| 6412 | boolean finishDrawingLocked() { |
| 6413 | if (mDrawPending) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6414 | if (SHOW_TRANSACTIONS || DEBUG_ORIENTATION) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6415 | TAG, "finishDrawingLocked: " + mSurface); |
| 6416 | mCommitDrawPending = true; |
| 6417 | mDrawPending = false; |
| 6418 | return true; |
| 6419 | } |
| 6420 | return false; |
| 6421 | } |
| 6422 | |
| 6423 | // This must be called while inside a transaction. |
Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 6424 | boolean commitFinishDrawingLocked(long currentTime) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6425 | //Slog.i(TAG, "commitFinishDrawingLocked: " + mSurface); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6426 | if (!mCommitDrawPending) { |
Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 6427 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6428 | } |
| 6429 | mCommitDrawPending = false; |
| 6430 | mReadyToShow = true; |
| 6431 | final boolean starting = mAttrs.type == TYPE_APPLICATION_STARTING; |
| 6432 | final AppWindowToken atoken = mAppToken; |
| 6433 | if (atoken == null || atoken.allDrawn || starting) { |
| 6434 | performShowLocked(); |
| 6435 | } |
Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 6436 | return true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6437 | } |
| 6438 | |
| 6439 | // This must be called while inside a transaction. |
| 6440 | boolean performShowLocked() { |
| 6441 | if (DEBUG_VISIBILITY) { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 6442 | RuntimeException e = null; |
| 6443 | if (!HIDE_STACK_CRAWLS) { |
| 6444 | e = new RuntimeException(); |
| 6445 | e.fillInStackTrace(); |
| 6446 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6447 | Slog.v(TAG, "performShow on " + this |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6448 | + ": readyToShow=" + mReadyToShow + " readyForDisplay=" + isReadyForDisplay() |
| 6449 | + " starting=" + (mAttrs.type == TYPE_APPLICATION_STARTING), e); |
| 6450 | } |
| 6451 | if (mReadyToShow && isReadyForDisplay()) { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 6452 | if (SHOW_TRANSACTIONS || DEBUG_ORIENTATION) logSurface(this, |
| 6453 | "SHOW (performShowLocked)", null); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6454 | if (DEBUG_VISIBILITY) Slog.v(TAG, "Showing " + this |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6455 | + " during animation: policyVis=" + mPolicyVisibility |
| 6456 | + " attHidden=" + mAttachedHidden |
| 6457 | + " tok.hiddenRequested=" |
| 6458 | + (mAppToken != null ? mAppToken.hiddenRequested : false) |
Dianne Hackborn | 248b188 | 2009-09-16 16:46:44 -0700 | [diff] [blame] | 6459 | + " tok.hidden=" |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6460 | + (mAppToken != null ? mAppToken.hidden : false) |
| 6461 | + " animating=" + mAnimating |
| 6462 | + " tok animating=" |
| 6463 | + (mAppToken != null ? mAppToken.animating : false)); |
| 6464 | if (!showSurfaceRobustlyLocked(this)) { |
| 6465 | return false; |
| 6466 | } |
| 6467 | mLastAlpha = -1; |
| 6468 | mHasDrawn = true; |
| 6469 | mLastHidden = false; |
| 6470 | mReadyToShow = false; |
| 6471 | enableScreenIfNeededLocked(); |
| 6472 | |
| 6473 | applyEnterAnimationLocked(this); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6474 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6475 | int i = mChildWindows.size(); |
| 6476 | while (i > 0) { |
| 6477 | i--; |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 6478 | WindowState c = mChildWindows.get(i); |
Dianne Hackborn | f09c1a2 | 2010-04-22 15:59:21 -0700 | [diff] [blame] | 6479 | if (c.mAttachedHidden) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6480 | c.mAttachedHidden = false; |
Dianne Hackborn | f09c1a2 | 2010-04-22 15:59:21 -0700 | [diff] [blame] | 6481 | if (c.mSurface != null) { |
| 6482 | c.performShowLocked(); |
| 6483 | // It hadn't been shown, which means layout not |
| 6484 | // performed on it, so now we want to make sure to |
| 6485 | // do a layout. If called from within the transaction |
| 6486 | // loop, this will cause it to restart with a new |
| 6487 | // layout. |
| 6488 | mLayoutNeeded = true; |
| 6489 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6490 | } |
| 6491 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6492 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6493 | if (mAttrs.type != TYPE_APPLICATION_STARTING |
| 6494 | && mAppToken != null) { |
| 6495 | mAppToken.firstWindowDrawn = true; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6496 | |
Dianne Hackborn | 248b188 | 2009-09-16 16:46:44 -0700 | [diff] [blame] | 6497 | if (mAppToken.startingData != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6498 | if (DEBUG_STARTING_WINDOW || DEBUG_ANIM) Slog.v(TAG, |
Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 6499 | "Finish starting " + mToken |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6500 | + ": first real window is shown, no animation"); |
Dianne Hackborn | 248b188 | 2009-09-16 16:46:44 -0700 | [diff] [blame] | 6501 | // If this initial window is animating, stop it -- we |
| 6502 | // will do an animation to reveal it from behind the |
| 6503 | // starting window, so there is no need for it to also |
| 6504 | // be doing its own stuff. |
| 6505 | if (mAnimation != null) { |
| 6506 | mAnimation = null; |
| 6507 | // Make sure we clean up the animation. |
| 6508 | mAnimating = true; |
| 6509 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6510 | mFinishedStarting.add(mAppToken); |
| 6511 | mH.sendEmptyMessage(H.FINISHED_STARTING); |
| 6512 | } |
| 6513 | mAppToken.updateReportedVisibilityLocked(); |
| 6514 | } |
| 6515 | } |
| 6516 | return true; |
| 6517 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6518 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6519 | // This must be called while inside a transaction. Returns true if |
| 6520 | // there is more animation to run. |
| 6521 | boolean stepAnimationLocked(long currentTime, int dw, int dh) { |
Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 6522 | if (!mDisplayFrozen && mPolicy.isScreenOn()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6523 | // We will run animations as long as the display isn't frozen. |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6524 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6525 | if (!mDrawPending && !mCommitDrawPending && mAnimation != null) { |
| 6526 | mHasTransformation = true; |
| 6527 | mHasLocalTransformation = true; |
| 6528 | if (!mLocalAnimating) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6529 | if (DEBUG_ANIM) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6530 | TAG, "Starting animation in " + this + |
| 6531 | " @ " + currentTime + ": ww=" + mFrame.width() + " wh=" + mFrame.height() + |
| 6532 | " dw=" + dw + " dh=" + dh + " scale=" + mWindowAnimationScale); |
| 6533 | mAnimation.initialize(mFrame.width(), mFrame.height(), dw, dh); |
| 6534 | mAnimation.setStartTime(currentTime); |
| 6535 | mLocalAnimating = true; |
| 6536 | mAnimating = true; |
| 6537 | } |
| 6538 | mTransformation.clear(); |
| 6539 | final boolean more = mAnimation.getTransformation( |
| 6540 | currentTime, mTransformation); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6541 | if (DEBUG_ANIM) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6542 | TAG, "Stepped animation in " + this + |
| 6543 | ": more=" + more + ", xform=" + mTransformation); |
| 6544 | if (more) { |
| 6545 | // we're not done! |
| 6546 | return true; |
| 6547 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6548 | if (DEBUG_ANIM) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6549 | TAG, "Finished animation in " + this + |
| 6550 | " @ " + currentTime); |
| 6551 | mAnimation = null; |
| 6552 | //WindowManagerService.this.dump(); |
| 6553 | } |
| 6554 | mHasLocalTransformation = false; |
| 6555 | if ((!mLocalAnimating || mAnimationIsEntrance) && mAppToken != null |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 6556 | && mAppToken.animation != null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6557 | // When our app token is animating, we kind-of pretend like |
| 6558 | // we are as well. Note the mLocalAnimating mAnimationIsEntrance |
| 6559 | // part of this check means that we will only do this if |
| 6560 | // our window is not currently exiting, or it is not |
| 6561 | // locally animating itself. The idea being that one that |
| 6562 | // is exiting and doing a local animation should be removed |
| 6563 | // once that animation is done. |
| 6564 | mAnimating = true; |
| 6565 | mHasTransformation = true; |
| 6566 | mTransformation.clear(); |
| 6567 | return false; |
| 6568 | } else if (mHasTransformation) { |
| 6569 | // Little trick to get through the path below to act like |
| 6570 | // we have finished an animation. |
| 6571 | mAnimating = true; |
| 6572 | } else if (isAnimating()) { |
| 6573 | mAnimating = true; |
| 6574 | } |
| 6575 | } else if (mAnimation != null) { |
| 6576 | // If the display is frozen, and there is a pending animation, |
| 6577 | // clear it and make sure we run the cleanup code. |
| 6578 | mAnimating = true; |
| 6579 | mLocalAnimating = true; |
| 6580 | mAnimation = null; |
| 6581 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6582 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6583 | if (!mAnimating && !mLocalAnimating) { |
| 6584 | return false; |
| 6585 | } |
| 6586 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6587 | if (DEBUG_ANIM) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6588 | TAG, "Animation done in " + this + ": exiting=" + mExiting |
| 6589 | + ", reportedVisible=" |
| 6590 | + (mAppToken != null ? mAppToken.reportedVisible : false)); |
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 | mAnimating = false; |
| 6593 | mLocalAnimating = false; |
| 6594 | mAnimation = null; |
| 6595 | mAnimLayer = mLayer; |
| 6596 | if (mIsImWindow) { |
| 6597 | mAnimLayer += mInputMethodAnimLayerAdjustment; |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 6598 | } else if (mIsWallpaper) { |
| 6599 | mAnimLayer += mWallpaperAnimLayerAdjustment; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6600 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6601 | if (DEBUG_LAYERS) Slog.v(TAG, "Stepping win " + this |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6602 | + " anim layer: " + mAnimLayer); |
| 6603 | mHasTransformation = false; |
| 6604 | mHasLocalTransformation = false; |
Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 6605 | if (mPolicyVisibility != mPolicyVisibilityAfterAnim) { |
| 6606 | if (DEBUG_VISIBILITY) { |
| 6607 | Slog.v(TAG, "Policy visibility changing after anim in " + this + ": " |
| 6608 | + mPolicyVisibilityAfterAnim); |
| 6609 | } |
| 6610 | mPolicyVisibility = mPolicyVisibilityAfterAnim; |
| 6611 | if (!mPolicyVisibility) { |
| 6612 | if (mCurrentFocus == this) { |
| 6613 | mFocusMayChange = true; |
| 6614 | } |
| 6615 | // Window is no longer visible -- make sure if we were waiting |
| 6616 | // for it to be displayed before enabling the display, that |
| 6617 | // we allow the display to be enabled now. |
| 6618 | enableScreenIfNeededLocked(); |
| 6619 | } |
Dianne Hackborn | f3bea9c | 2009-12-09 18:26:21 -0800 | [diff] [blame] | 6620 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6621 | mTransformation.clear(); |
| 6622 | if (mHasDrawn |
| 6623 | && mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING |
| 6624 | && mAppToken != null |
| 6625 | && mAppToken.firstWindowDrawn |
| 6626 | && mAppToken.startingData != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6627 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Finish starting " |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6628 | + mToken + ": first real window done animating"); |
| 6629 | mFinishedStarting.add(mAppToken); |
| 6630 | mH.sendEmptyMessage(H.FINISHED_STARTING); |
| 6631 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6632 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6633 | finishExit(); |
| 6634 | |
| 6635 | if (mAppToken != null) { |
| 6636 | mAppToken.updateReportedVisibilityLocked(); |
| 6637 | } |
| 6638 | |
| 6639 | return false; |
| 6640 | } |
| 6641 | |
| 6642 | void finishExit() { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6643 | if (DEBUG_ANIM) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6644 | TAG, "finishExit in " + this |
| 6645 | + ": exiting=" + mExiting |
| 6646 | + " remove=" + mRemoveOnExit |
| 6647 | + " windowAnimating=" + isWindowAnimating()); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6648 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6649 | final int N = mChildWindows.size(); |
| 6650 | for (int i=0; i<N; i++) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 6651 | mChildWindows.get(i).finishExit(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6652 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6653 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6654 | if (!mExiting) { |
| 6655 | return; |
| 6656 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6657 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6658 | if (isWindowAnimating()) { |
| 6659 | return; |
| 6660 | } |
| 6661 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6662 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6663 | TAG, "Exit animation finished in " + this |
| 6664 | + ": remove=" + mRemoveOnExit); |
| 6665 | if (mSurface != null) { |
| 6666 | mDestroySurface.add(this); |
| 6667 | mDestroying = true; |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 6668 | if (SHOW_TRANSACTIONS) logSurface(this, "HIDE (finishExit)", null); |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 6669 | mSurfaceShown = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6670 | try { |
| 6671 | mSurface.hide(); |
| 6672 | } catch (RuntimeException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6673 | Slog.w(TAG, "Error hiding surface in " + this, e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6674 | } |
| 6675 | mLastHidden = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6676 | } |
| 6677 | mExiting = false; |
| 6678 | if (mRemoveOnExit) { |
| 6679 | mPendingRemove.add(this); |
| 6680 | mRemoveOnExit = false; |
| 6681 | } |
| 6682 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6683 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6684 | boolean isIdentityMatrix(float dsdx, float dtdx, float dsdy, float dtdy) { |
| 6685 | if (dsdx < .99999f || dsdx > 1.00001f) return false; |
| 6686 | if (dtdy < .99999f || dtdy > 1.00001f) return false; |
| 6687 | if (dtdx < -.000001f || dtdx > .000001f) return false; |
| 6688 | if (dsdy < -.000001f || dsdy > .000001f) return false; |
| 6689 | return true; |
| 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 | void computeShownFrameLocked() { |
| 6693 | final boolean selfTransformation = mHasLocalTransformation; |
| 6694 | Transformation attachedTransformation = |
| 6695 | (mAttachedWindow != null && mAttachedWindow.mHasLocalTransformation) |
| 6696 | ? mAttachedWindow.mTransformation : null; |
| 6697 | Transformation appTransformation = |
| 6698 | (mAppToken != null && mAppToken.hasTransformation) |
| 6699 | ? mAppToken.transformation : null; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6700 | |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 6701 | // Wallpapers are animated based on the "real" window they |
| 6702 | // are currently targeting. |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 6703 | if (mAttrs.type == TYPE_WALLPAPER && mLowerWallpaperTarget == null |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 6704 | && mWallpaperTarget != null) { |
Dianne Hackborn | 5baba16 | 2009-09-23 17:01:12 -0700 | [diff] [blame] | 6705 | if (mWallpaperTarget.mHasLocalTransformation && |
| 6706 | mWallpaperTarget.mAnimation != null && |
| 6707 | !mWallpaperTarget.mAnimation.getDetachWallpaper()) { |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 6708 | attachedTransformation = mWallpaperTarget.mTransformation; |
Dianne Hackborn | 5baba16 | 2009-09-23 17:01:12 -0700 | [diff] [blame] | 6709 | if (DEBUG_WALLPAPER && attachedTransformation != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6710 | Slog.v(TAG, "WP target attached xform: " + attachedTransformation); |
Dianne Hackborn | 5baba16 | 2009-09-23 17:01:12 -0700 | [diff] [blame] | 6711 | } |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 6712 | } |
| 6713 | if (mWallpaperTarget.mAppToken != null && |
Dianne Hackborn | 5baba16 | 2009-09-23 17:01:12 -0700 | [diff] [blame] | 6714 | mWallpaperTarget.mAppToken.hasTransformation && |
| 6715 | mWallpaperTarget.mAppToken.animation != null && |
| 6716 | !mWallpaperTarget.mAppToken.animation.getDetachWallpaper()) { |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 6717 | appTransformation = mWallpaperTarget.mAppToken.transformation; |
Dianne Hackborn | 5baba16 | 2009-09-23 17:01:12 -0700 | [diff] [blame] | 6718 | if (DEBUG_WALLPAPER && appTransformation != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6719 | Slog.v(TAG, "WP target app xform: " + appTransformation); |
Dianne Hackborn | 5baba16 | 2009-09-23 17:01:12 -0700 | [diff] [blame] | 6720 | } |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 6721 | } |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 6722 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6723 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6724 | if (selfTransformation || attachedTransformation != null |
| 6725 | || appTransformation != null) { |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6726 | // cache often used attributes locally |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6727 | final Rect frame = mFrame; |
| 6728 | final float tmpFloats[] = mTmpFloats; |
| 6729 | final Matrix tmpMatrix = mTmpMatrix; |
| 6730 | |
| 6731 | // Compute the desired transformation. |
Dianne Hackborn | 65c2387 | 2009-09-18 17:47:02 -0700 | [diff] [blame] | 6732 | tmpMatrix.setTranslate(0, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6733 | if (selfTransformation) { |
Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 6734 | tmpMatrix.postConcat(mTransformation.getMatrix()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6735 | } |
Dianne Hackborn | 65c2387 | 2009-09-18 17:47:02 -0700 | [diff] [blame] | 6736 | tmpMatrix.postTranslate(frame.left, frame.top); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6737 | if (attachedTransformation != null) { |
Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 6738 | tmpMatrix.postConcat(attachedTransformation.getMatrix()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6739 | } |
| 6740 | if (appTransformation != null) { |
Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 6741 | tmpMatrix.postConcat(appTransformation.getMatrix()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6742 | } |
| 6743 | |
| 6744 | // "convert" it into SurfaceFlinger's format |
| 6745 | // (a 2x2 matrix + an offset) |
| 6746 | // Here we must not transform the position of the surface |
| 6747 | // since it is already included in the transformation. |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6748 | //Slog.i(TAG, "Transform: " + matrix); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6749 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6750 | tmpMatrix.getValues(tmpFloats); |
| 6751 | mDsDx = tmpFloats[Matrix.MSCALE_X]; |
| 6752 | mDtDx = tmpFloats[Matrix.MSKEW_X]; |
| 6753 | mDsDy = tmpFloats[Matrix.MSKEW_Y]; |
| 6754 | mDtDy = tmpFloats[Matrix.MSCALE_Y]; |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 6755 | int x = (int)tmpFloats[Matrix.MTRANS_X] + mXOffset; |
| 6756 | int y = (int)tmpFloats[Matrix.MTRANS_Y] + mYOffset; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6757 | int w = frame.width(); |
| 6758 | int h = frame.height(); |
| 6759 | mShownFrame.set(x, y, x+w, y+h); |
| 6760 | |
| 6761 | // Now set the alpha... but because our current hardware |
| 6762 | // can't do alpha transformation on a non-opaque surface, |
| 6763 | // turn it off if we are running an animation that is also |
| 6764 | // transforming since it is more important to have that |
| 6765 | // animation be smooth. |
| 6766 | mShownAlpha = mAlpha; |
| 6767 | if (!mLimitedAlphaCompositing |
| 6768 | || (!PixelFormat.formatHasAlpha(mAttrs.format) |
| 6769 | || (isIdentityMatrix(mDsDx, mDtDx, mDsDy, mDtDy) |
| 6770 | && x == frame.left && y == frame.top))) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6771 | //Slog.i(TAG, "Applying alpha transform"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6772 | if (selfTransformation) { |
| 6773 | mShownAlpha *= mTransformation.getAlpha(); |
| 6774 | } |
| 6775 | if (attachedTransformation != null) { |
| 6776 | mShownAlpha *= attachedTransformation.getAlpha(); |
| 6777 | } |
| 6778 | if (appTransformation != null) { |
| 6779 | mShownAlpha *= appTransformation.getAlpha(); |
| 6780 | } |
| 6781 | } else { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6782 | //Slog.i(TAG, "Not applying alpha transform"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6783 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6784 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6785 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6786 | TAG, "Continuing animation in " + this + |
| 6787 | ": " + mShownFrame + |
| 6788 | ", alpha=" + mTransformation.getAlpha()); |
| 6789 | return; |
| 6790 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6791 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6792 | mShownFrame.set(mFrame); |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 6793 | if (mXOffset != 0 || mYOffset != 0) { |
| 6794 | mShownFrame.offset(mXOffset, mYOffset); |
| 6795 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6796 | mShownAlpha = mAlpha; |
| 6797 | mDsDx = 1; |
| 6798 | mDtDx = 0; |
| 6799 | mDsDy = 0; |
| 6800 | mDtDy = 1; |
| 6801 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6802 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6803 | /** |
| 6804 | * Is this window visible? It is not visible if there is no |
| 6805 | * surface, or we are in the process of running an exit animation |
| 6806 | * that will remove the surface, or its app token has been hidden. |
| 6807 | */ |
| 6808 | public boolean isVisibleLw() { |
| 6809 | final AppWindowToken atoken = mAppToken; |
| 6810 | return mSurface != null && mPolicyVisibility && !mAttachedHidden |
| 6811 | && (atoken == null || !atoken.hiddenRequested) |
| 6812 | && !mExiting && !mDestroying; |
| 6813 | } |
| 6814 | |
| 6815 | /** |
Dianne Hackborn | 3d163f07 | 2009-10-07 21:26:57 -0700 | [diff] [blame] | 6816 | * Like {@link #isVisibleLw}, but also counts a window that is currently |
| 6817 | * "hidden" behind the keyguard as visible. This allows us to apply |
| 6818 | * things like window flags that impact the keyguard. |
| 6819 | * XXX I am starting to think we need to have ANOTHER visibility flag |
| 6820 | * for this "hidden behind keyguard" state rather than overloading |
| 6821 | * mPolicyVisibility. Ungh. |
| 6822 | */ |
| 6823 | public boolean isVisibleOrBehindKeyguardLw() { |
| 6824 | final AppWindowToken atoken = mAppToken; |
| 6825 | return mSurface != null && !mAttachedHidden |
| 6826 | && (atoken == null ? mPolicyVisibility : !atoken.hiddenRequested) |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 6827 | && !mDrawPending && !mCommitDrawPending |
Dianne Hackborn | 3d163f07 | 2009-10-07 21:26:57 -0700 | [diff] [blame] | 6828 | && !mExiting && !mDestroying; |
| 6829 | } |
| 6830 | |
| 6831 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6832 | * Is this window visible, ignoring its app token? It is not visible |
| 6833 | * if there is no surface, or we are in the process of running an exit animation |
| 6834 | * that will remove the surface. |
| 6835 | */ |
| 6836 | public boolean isWinVisibleLw() { |
| 6837 | final AppWindowToken atoken = mAppToken; |
| 6838 | return mSurface != null && mPolicyVisibility && !mAttachedHidden |
| 6839 | && (atoken == null || !atoken.hiddenRequested || atoken.animating) |
| 6840 | && !mExiting && !mDestroying; |
| 6841 | } |
| 6842 | |
| 6843 | /** |
| 6844 | * The same as isVisible(), but follows the current hidden state of |
| 6845 | * the associated app token, not the pending requested hidden state. |
| 6846 | */ |
| 6847 | boolean isVisibleNow() { |
| 6848 | return mSurface != null && mPolicyVisibility && !mAttachedHidden |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 6849 | && !mRootToken.hidden && !mExiting && !mDestroying; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6850 | } |
| 6851 | |
| 6852 | /** |
| 6853 | * Same as isVisible(), but we also count it as visible between the |
| 6854 | * call to IWindowSession.add() and the first relayout(). |
| 6855 | */ |
| 6856 | boolean isVisibleOrAdding() { |
| 6857 | final AppWindowToken atoken = mAppToken; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 6858 | return ((mSurface != null && !mReportDestroySurface) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6859 | || (!mRelayoutCalled && mViewVisibility == View.VISIBLE)) |
| 6860 | && mPolicyVisibility && !mAttachedHidden |
| 6861 | && (atoken == null || !atoken.hiddenRequested) |
| 6862 | && !mExiting && !mDestroying; |
| 6863 | } |
| 6864 | |
| 6865 | /** |
| 6866 | * Is this window currently on-screen? It is on-screen either if it |
| 6867 | * is visible or it is currently running an animation before no longer |
| 6868 | * being visible. |
| 6869 | */ |
| 6870 | boolean isOnScreen() { |
| 6871 | final AppWindowToken atoken = mAppToken; |
| 6872 | if (atoken != null) { |
| 6873 | return mSurface != null && mPolicyVisibility && !mDestroying |
| 6874 | && ((!mAttachedHidden && !atoken.hiddenRequested) |
Dianne Hackborn | 0cd4887 | 2009-08-13 18:51:59 -0700 | [diff] [blame] | 6875 | || mAnimation != null || atoken.animation != null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6876 | } else { |
| 6877 | return mSurface != null && mPolicyVisibility && !mDestroying |
Dianne Hackborn | 0cd4887 | 2009-08-13 18:51:59 -0700 | [diff] [blame] | 6878 | && (!mAttachedHidden || mAnimation != null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6879 | } |
| 6880 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6881 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6882 | /** |
| 6883 | * Like isOnScreen(), but we don't return true if the window is part |
| 6884 | * of a transition that has not yet been started. |
| 6885 | */ |
| 6886 | boolean isReadyForDisplay() { |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 6887 | if (mRootToken.waitingToShow && |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 6888 | mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 6889 | return false; |
| 6890 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6891 | final AppWindowToken atoken = mAppToken; |
Dianne Hackborn | 0cd4887 | 2009-08-13 18:51:59 -0700 | [diff] [blame] | 6892 | final boolean animating = atoken != null |
| 6893 | ? (atoken.animation != null) : false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6894 | return mSurface != null && mPolicyVisibility && !mDestroying |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 6895 | && ((!mAttachedHidden && mViewVisibility == View.VISIBLE |
| 6896 | && !mRootToken.hidden) |
Dianne Hackborn | 0cd4887 | 2009-08-13 18:51:59 -0700 | [diff] [blame] | 6897 | || mAnimation != null || animating); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6898 | } |
| 6899 | |
| 6900 | /** Is the window or its container currently animating? */ |
| 6901 | boolean isAnimating() { |
| 6902 | final WindowState attached = mAttachedWindow; |
| 6903 | final AppWindowToken atoken = mAppToken; |
| 6904 | return mAnimation != null |
| 6905 | || (attached != null && attached.mAnimation != null) |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6906 | || (atoken != null && |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6907 | (atoken.animation != null |
| 6908 | || atoken.inPendingTransaction)); |
| 6909 | } |
| 6910 | |
| 6911 | /** Is this window currently animating? */ |
| 6912 | boolean isWindowAnimating() { |
| 6913 | return mAnimation != null; |
| 6914 | } |
| 6915 | |
| 6916 | /** |
| 6917 | * Like isOnScreen, but returns false if the surface hasn't yet |
| 6918 | * been drawn. |
| 6919 | */ |
| 6920 | public boolean isDisplayedLw() { |
| 6921 | final AppWindowToken atoken = mAppToken; |
| 6922 | return mSurface != null && mPolicyVisibility && !mDestroying |
| 6923 | && !mDrawPending && !mCommitDrawPending |
| 6924 | && ((!mAttachedHidden && |
| 6925 | (atoken == null || !atoken.hiddenRequested)) |
| 6926 | || mAnimating); |
| 6927 | } |
| 6928 | |
Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 6929 | /** |
| 6930 | * Returns true if the window has a surface that it has drawn a |
| 6931 | * complete UI in to. |
| 6932 | */ |
| 6933 | public boolean isDrawnLw() { |
| 6934 | final AppWindowToken atoken = mAppToken; |
| 6935 | return mSurface != null && !mDestroying |
| 6936 | && !mDrawPending && !mCommitDrawPending; |
| 6937 | } |
| 6938 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6939 | public boolean fillsScreenLw(int screenWidth, int screenHeight, |
| 6940 | boolean shownFrame, boolean onlyOpaque) { |
| 6941 | if (mSurface == null) { |
| 6942 | return false; |
| 6943 | } |
| 6944 | if (mAppToken != null && !mAppToken.appFullscreen) { |
| 6945 | return false; |
| 6946 | } |
| 6947 | if (onlyOpaque && mAttrs.format != PixelFormat.OPAQUE) { |
| 6948 | return false; |
| 6949 | } |
| 6950 | final Rect frame = shownFrame ? mShownFrame : mFrame; |
Mitsuru Oshima | d2967e2 | 2009-07-20 14:01:43 -0700 | [diff] [blame] | 6951 | |
| 6952 | if ((mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0) { |
| 6953 | return frame.left <= mCompatibleScreenFrame.left && |
| 6954 | frame.top <= mCompatibleScreenFrame.top && |
| 6955 | frame.right >= mCompatibleScreenFrame.right && |
| 6956 | frame.bottom >= mCompatibleScreenFrame.bottom; |
| 6957 | } else { |
| 6958 | return frame.left <= 0 && frame.top <= 0 |
| 6959 | && frame.right >= screenWidth |
| 6960 | && frame.bottom >= screenHeight; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6961 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6962 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6963 | |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 6964 | /** |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 6965 | * Return true if the window is opaque and fully drawn. This indicates |
| 6966 | * it may obscure windows behind it. |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 6967 | */ |
| 6968 | boolean isOpaqueDrawn() { |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 6969 | return (mAttrs.format == PixelFormat.OPAQUE |
| 6970 | || mAttrs.type == TYPE_WALLPAPER) |
| 6971 | && mSurface != null && mAnimation == null |
| 6972 | && (mAppToken == null || mAppToken.animation == null) |
| 6973 | && !mDrawPending && !mCommitDrawPending; |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 6974 | } |
| 6975 | |
| 6976 | boolean needsBackgroundFiller(int screenWidth, int screenHeight) { |
| 6977 | return |
| 6978 | // only if the application is requesting compatible window |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 6979 | (mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0 && |
| 6980 | // only if it's visible |
| 6981 | mHasDrawn && mViewVisibility == View.VISIBLE && |
Mitsuru Oshima | d2967e2 | 2009-07-20 14:01:43 -0700 | [diff] [blame] | 6982 | // and only if the application fills the compatible screen |
| 6983 | mFrame.left <= mCompatibleScreenFrame.left && |
| 6984 | mFrame.top <= mCompatibleScreenFrame.top && |
| 6985 | mFrame.right >= mCompatibleScreenFrame.right && |
| 6986 | mFrame.bottom >= mCompatibleScreenFrame.bottom && |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 6987 | // and starting window do not need background filler |
Mitsuru Oshima | d2967e2 | 2009-07-20 14:01:43 -0700 | [diff] [blame] | 6988 | mAttrs.type != mAttrs.TYPE_APPLICATION_STARTING; |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 6989 | } |
| 6990 | |
| 6991 | boolean isFullscreen(int screenWidth, int screenHeight) { |
| 6992 | return mFrame.left <= 0 && mFrame.top <= 0 && |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 6993 | mFrame.right >= screenWidth && mFrame.bottom >= screenHeight; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6994 | } |
| 6995 | |
| 6996 | void removeLocked() { |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 6997 | disposeInputChannel(); |
| 6998 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6999 | if (mAttachedWindow != null) { |
| 7000 | mAttachedWindow.mChildWindows.remove(this); |
| 7001 | } |
| 7002 | destroySurfaceLocked(); |
| 7003 | mSession.windowRemovedLocked(); |
| 7004 | try { |
| 7005 | mClient.asBinder().unlinkToDeath(mDeathRecipient, 0); |
| 7006 | } catch (RuntimeException e) { |
| 7007 | // Ignore if it has already been removed (usually because |
| 7008 | // we are doing this as part of processing a death note.) |
| 7009 | } |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 7010 | } |
| 7011 | |
| 7012 | void disposeInputChannel() { |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 7013 | if (mInputChannel != null) { |
| 7014 | mInputManager.unregisterInputChannel(mInputChannel); |
| 7015 | |
| 7016 | mInputChannel.dispose(); |
| 7017 | mInputChannel = null; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 7018 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7019 | } |
| 7020 | |
| 7021 | private class DeathRecipient implements IBinder.DeathRecipient { |
| 7022 | public void binderDied() { |
| 7023 | try { |
| 7024 | synchronized(mWindowMap) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 7025 | WindowState win = windowForClientLocked(mSession, mClient, false); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7026 | Slog.i(TAG, "WIN DEATH: " + win); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7027 | if (win != null) { |
| 7028 | removeWindowLocked(mSession, win); |
| 7029 | } |
| 7030 | } |
| 7031 | } catch (IllegalArgumentException ex) { |
| 7032 | // This will happen if the window has already been |
| 7033 | // removed. |
| 7034 | } |
| 7035 | } |
| 7036 | } |
| 7037 | |
| 7038 | /** Returns true if this window desires key events. */ |
| 7039 | public final boolean canReceiveKeys() { |
| 7040 | return isVisibleOrAdding() |
| 7041 | && (mViewVisibility == View.VISIBLE) |
| 7042 | && ((mAttrs.flags & WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) == 0); |
| 7043 | } |
| 7044 | |
| 7045 | public boolean hasDrawnLw() { |
| 7046 | return mHasDrawn; |
| 7047 | } |
| 7048 | |
| 7049 | public boolean showLw(boolean doAnimation) { |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 7050 | return showLw(doAnimation, true); |
| 7051 | } |
| 7052 | |
| 7053 | boolean showLw(boolean doAnimation, boolean requestAnim) { |
| 7054 | if (mPolicyVisibility && mPolicyVisibilityAfterAnim) { |
| 7055 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7056 | } |
Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 7057 | if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility true: " + this); |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 7058 | if (doAnimation) { |
| 7059 | if (DEBUG_VISIBILITY) Slog.v(TAG, "doAnimation: mPolicyVisibility=" |
| 7060 | + mPolicyVisibility + " mAnimation=" + mAnimation); |
| 7061 | if (mDisplayFrozen || !mPolicy.isScreenOn()) { |
| 7062 | doAnimation = false; |
| 7063 | } else if (mPolicyVisibility && mAnimation == null) { |
| 7064 | // Check for the case where we are currently visible and |
| 7065 | // not animating; we do not want to do animation at such a |
| 7066 | // point to become visible when we already are. |
| 7067 | doAnimation = false; |
| 7068 | } |
| 7069 | } |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 7070 | mPolicyVisibility = true; |
| 7071 | mPolicyVisibilityAfterAnim = true; |
| 7072 | if (doAnimation) { |
| 7073 | applyAnimationLocked(this, WindowManagerPolicy.TRANSIT_ENTER, true); |
| 7074 | } |
| 7075 | if (requestAnim) { |
| 7076 | requestAnimationLocked(0); |
| 7077 | } |
| 7078 | return true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7079 | } |
| 7080 | |
| 7081 | public boolean hideLw(boolean doAnimation) { |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 7082 | return hideLw(doAnimation, true); |
| 7083 | } |
| 7084 | |
| 7085 | boolean hideLw(boolean doAnimation, boolean requestAnim) { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 7086 | if (doAnimation) { |
| 7087 | if (mDisplayFrozen || !mPolicy.isScreenOn()) { |
| 7088 | doAnimation = false; |
| 7089 | } |
| 7090 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7091 | boolean current = doAnimation ? mPolicyVisibilityAfterAnim |
| 7092 | : mPolicyVisibility; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 7093 | if (!current) { |
| 7094 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7095 | } |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 7096 | if (doAnimation) { |
| 7097 | applyAnimationLocked(this, WindowManagerPolicy.TRANSIT_EXIT, false); |
| 7098 | if (mAnimation == null) { |
| 7099 | doAnimation = false; |
| 7100 | } |
| 7101 | } |
| 7102 | if (doAnimation) { |
| 7103 | mPolicyVisibilityAfterAnim = false; |
| 7104 | } else { |
Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 7105 | if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility false: " + this); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 7106 | mPolicyVisibilityAfterAnim = false; |
| 7107 | mPolicyVisibility = false; |
Dianne Hackborn | f3bea9c | 2009-12-09 18:26:21 -0800 | [diff] [blame] | 7108 | // Window is no longer visible -- make sure if we were waiting |
| 7109 | // for it to be displayed before enabling the display, that |
| 7110 | // we allow the display to be enabled now. |
| 7111 | enableScreenIfNeededLocked(); |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 7112 | if (mCurrentFocus == this) { |
| 7113 | mFocusMayChange = true; |
| 7114 | } |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 7115 | } |
| 7116 | if (requestAnim) { |
| 7117 | requestAnimationLocked(0); |
| 7118 | } |
| 7119 | return true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7120 | } |
| 7121 | |
| 7122 | void dump(PrintWriter pw, String prefix) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7123 | pw.print(prefix); pw.print("mSession="); pw.print(mSession); |
| 7124 | pw.print(" mClient="); pw.println(mClient.asBinder()); |
| 7125 | pw.print(prefix); pw.print("mAttrs="); pw.println(mAttrs); |
| 7126 | if (mAttachedWindow != null || mLayoutAttached) { |
| 7127 | pw.print(prefix); pw.print("mAttachedWindow="); pw.print(mAttachedWindow); |
| 7128 | pw.print(" mLayoutAttached="); pw.println(mLayoutAttached); |
| 7129 | } |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 7130 | if (mIsImWindow || mIsWallpaper || mIsFloatingLayer) { |
| 7131 | pw.print(prefix); pw.print("mIsImWindow="); pw.print(mIsImWindow); |
| 7132 | pw.print(" mIsWallpaper="); pw.print(mIsWallpaper); |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 7133 | pw.print(" mIsFloatingLayer="); pw.print(mIsFloatingLayer); |
| 7134 | pw.print(" mWallpaperVisible="); pw.println(mWallpaperVisible); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7135 | } |
| 7136 | pw.print(prefix); pw.print("mBaseLayer="); pw.print(mBaseLayer); |
| 7137 | pw.print(" mSubLayer="); pw.print(mSubLayer); |
| 7138 | pw.print(" mAnimLayer="); pw.print(mLayer); pw.print("+"); |
| 7139 | pw.print((mTargetAppToken != null ? mTargetAppToken.animLayerAdjustment |
| 7140 | : (mAppToken != null ? mAppToken.animLayerAdjustment : 0))); |
| 7141 | pw.print("="); pw.print(mAnimLayer); |
| 7142 | pw.print(" mLastLayer="); pw.println(mLastLayer); |
| 7143 | if (mSurface != null) { |
| 7144 | pw.print(prefix); pw.print("mSurface="); pw.println(mSurface); |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 7145 | pw.print(prefix); pw.print("Surface: shown="); pw.print(mSurfaceShown); |
| 7146 | pw.print(" layer="); pw.print(mSurfaceLayer); |
| 7147 | pw.print(" alpha="); pw.print(mSurfaceAlpha); |
| 7148 | pw.print(" rect=("); pw.print(mSurfaceX); |
| 7149 | pw.print(","); pw.print(mSurfaceY); |
| 7150 | pw.print(") "); pw.print(mSurfaceW); |
| 7151 | pw.print(" x "); pw.println(mSurfaceH); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7152 | } |
| 7153 | pw.print(prefix); pw.print("mToken="); pw.println(mToken); |
| 7154 | pw.print(prefix); pw.print("mRootToken="); pw.println(mRootToken); |
| 7155 | if (mAppToken != null) { |
| 7156 | pw.print(prefix); pw.print("mAppToken="); pw.println(mAppToken); |
| 7157 | } |
| 7158 | if (mTargetAppToken != null) { |
| 7159 | pw.print(prefix); pw.print("mTargetAppToken="); pw.println(mTargetAppToken); |
| 7160 | } |
| 7161 | pw.print(prefix); pw.print("mViewVisibility=0x"); |
| 7162 | pw.print(Integer.toHexString(mViewVisibility)); |
| 7163 | pw.print(" mLastHidden="); pw.print(mLastHidden); |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 7164 | pw.print(" mHaveFrame="); pw.print(mHaveFrame); |
| 7165 | pw.print(" mObscured="); pw.println(mObscured); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7166 | if (!mPolicyVisibility || !mPolicyVisibilityAfterAnim || mAttachedHidden) { |
| 7167 | pw.print(prefix); pw.print("mPolicyVisibility="); |
| 7168 | pw.print(mPolicyVisibility); |
| 7169 | pw.print(" mPolicyVisibilityAfterAnim="); |
| 7170 | pw.print(mPolicyVisibilityAfterAnim); |
| 7171 | pw.print(" mAttachedHidden="); pw.println(mAttachedHidden); |
| 7172 | } |
Dianne Hackborn | 9b52a21 | 2009-12-11 14:51:35 -0800 | [diff] [blame] | 7173 | if (!mRelayoutCalled) { |
| 7174 | pw.print(prefix); pw.print("mRelayoutCalled="); pw.println(mRelayoutCalled); |
| 7175 | } |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7176 | pw.print(prefix); pw.print("Requested w="); pw.print(mRequestedWidth); |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 7177 | pw.print(" h="); pw.print(mRequestedHeight); |
| 7178 | pw.print(" mLayoutSeq="); pw.println(mLayoutSeq); |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 7179 | if (mXOffset != 0 || mYOffset != 0) { |
| 7180 | pw.print(prefix); pw.print("Offsets x="); pw.print(mXOffset); |
| 7181 | pw.print(" y="); pw.println(mYOffset); |
| 7182 | } |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7183 | pw.print(prefix); pw.print("mGivenContentInsets="); |
| 7184 | mGivenContentInsets.printShortString(pw); |
| 7185 | pw.print(" mGivenVisibleInsets="); |
| 7186 | mGivenVisibleInsets.printShortString(pw); |
| 7187 | pw.println(); |
| 7188 | if (mTouchableInsets != 0 || mGivenInsetsPending) { |
| 7189 | pw.print(prefix); pw.print("mTouchableInsets="); pw.print(mTouchableInsets); |
| 7190 | pw.print(" mGivenInsetsPending="); pw.println(mGivenInsetsPending); |
| 7191 | } |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 7192 | pw.print(prefix); pw.print("mConfiguration="); pw.println(mConfiguration); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7193 | pw.print(prefix); pw.print("mShownFrame="); |
| 7194 | mShownFrame.printShortString(pw); |
| 7195 | pw.print(" last="); mLastShownFrame.printShortString(pw); |
| 7196 | pw.println(); |
| 7197 | pw.print(prefix); pw.print("mFrame="); mFrame.printShortString(pw); |
| 7198 | pw.print(" last="); mLastFrame.printShortString(pw); |
| 7199 | pw.println(); |
| 7200 | pw.print(prefix); pw.print("mContainingFrame="); |
| 7201 | mContainingFrame.printShortString(pw); |
| 7202 | pw.print(" mDisplayFrame="); |
| 7203 | mDisplayFrame.printShortString(pw); |
| 7204 | pw.println(); |
| 7205 | pw.print(prefix); pw.print("mContentFrame="); mContentFrame.printShortString(pw); |
| 7206 | pw.print(" mVisibleFrame="); mVisibleFrame.printShortString(pw); |
| 7207 | pw.println(); |
| 7208 | pw.print(prefix); pw.print("mContentInsets="); mContentInsets.printShortString(pw); |
| 7209 | pw.print(" last="); mLastContentInsets.printShortString(pw); |
| 7210 | pw.print(" mVisibleInsets="); mVisibleInsets.printShortString(pw); |
| 7211 | pw.print(" last="); mLastVisibleInsets.printShortString(pw); |
| 7212 | pw.println(); |
| 7213 | if (mShownAlpha != 1 || mAlpha != 1 || mLastAlpha != 1) { |
| 7214 | pw.print(prefix); pw.print("mShownAlpha="); pw.print(mShownAlpha); |
| 7215 | pw.print(" mAlpha="); pw.print(mAlpha); |
| 7216 | pw.print(" mLastAlpha="); pw.println(mLastAlpha); |
| 7217 | } |
| 7218 | if (mAnimating || mLocalAnimating || mAnimationIsEntrance |
| 7219 | || mAnimation != null) { |
| 7220 | pw.print(prefix); pw.print("mAnimating="); pw.print(mAnimating); |
| 7221 | pw.print(" mLocalAnimating="); pw.print(mLocalAnimating); |
| 7222 | pw.print(" mAnimationIsEntrance="); pw.print(mAnimationIsEntrance); |
| 7223 | pw.print(" mAnimation="); pw.println(mAnimation); |
| 7224 | } |
| 7225 | if (mHasTransformation || mHasLocalTransformation) { |
| 7226 | pw.print(prefix); pw.print("XForm: has="); |
| 7227 | pw.print(mHasTransformation); |
| 7228 | pw.print(" hasLocal="); pw.print(mHasLocalTransformation); |
| 7229 | pw.print(" "); mTransformation.printShortString(pw); |
| 7230 | pw.println(); |
| 7231 | } |
| 7232 | pw.print(prefix); pw.print("mDrawPending="); pw.print(mDrawPending); |
| 7233 | pw.print(" mCommitDrawPending="); pw.print(mCommitDrawPending); |
| 7234 | pw.print(" mReadyToShow="); pw.print(mReadyToShow); |
| 7235 | pw.print(" mHasDrawn="); pw.println(mHasDrawn); |
| 7236 | if (mExiting || mRemoveOnExit || mDestroying || mRemoved) { |
| 7237 | pw.print(prefix); pw.print("mExiting="); pw.print(mExiting); |
| 7238 | pw.print(" mRemoveOnExit="); pw.print(mRemoveOnExit); |
| 7239 | pw.print(" mDestroying="); pw.print(mDestroying); |
| 7240 | pw.print(" mRemoved="); pw.println(mRemoved); |
| 7241 | } |
Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 7242 | if (mOrientationChanging || mAppFreezing || mTurnOnScreen) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7243 | pw.print(prefix); pw.print("mOrientationChanging="); |
| 7244 | pw.print(mOrientationChanging); |
Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 7245 | pw.print(" mAppFreezing="); pw.print(mAppFreezing); |
| 7246 | pw.print(" mTurnOnScreen="); pw.println(mTurnOnScreen); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7247 | } |
Mitsuru Oshima | 589cebe | 2009-07-22 20:38:58 -0700 | [diff] [blame] | 7248 | if (mHScale != 1 || mVScale != 1) { |
| 7249 | pw.print(prefix); pw.print("mHScale="); pw.print(mHScale); |
| 7250 | pw.print(" mVScale="); pw.println(mVScale); |
| 7251 | } |
Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 7252 | if (mWallpaperX != -1 || mWallpaperY != -1) { |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 7253 | pw.print(prefix); pw.print("mWallpaperX="); pw.print(mWallpaperX); |
| 7254 | pw.print(" mWallpaperY="); pw.println(mWallpaperY); |
| 7255 | } |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 7256 | if (mWallpaperXStep != -1 || mWallpaperYStep != -1) { |
| 7257 | pw.print(prefix); pw.print("mWallpaperXStep="); pw.print(mWallpaperXStep); |
| 7258 | pw.print(" mWallpaperYStep="); pw.println(mWallpaperYStep); |
| 7259 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7260 | } |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 7261 | |
| 7262 | String makeInputChannelName() { |
| 7263 | return Integer.toHexString(System.identityHashCode(this)) |
| 7264 | + " " + mAttrs.getTitle(); |
| 7265 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7266 | |
| 7267 | @Override |
| 7268 | public String toString() { |
| 7269 | return "Window{" |
| 7270 | + Integer.toHexString(System.identityHashCode(this)) |
| 7271 | + " " + mAttrs.getTitle() + " paused=" + mToken.paused + "}"; |
| 7272 | } |
| 7273 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7274 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7275 | // ------------------------------------------------------------- |
| 7276 | // Window Token State |
| 7277 | // ------------------------------------------------------------- |
| 7278 | |
| 7279 | class WindowToken { |
| 7280 | // The actual token. |
| 7281 | final IBinder token; |
| 7282 | |
| 7283 | // The type of window this token is for, as per WindowManager.LayoutParams. |
| 7284 | final int windowType; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7285 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7286 | // Set if this token was explicitly added by a client, so should |
| 7287 | // not be removed when all windows are removed. |
| 7288 | final boolean explicit; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7289 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7290 | // For printing. |
| 7291 | String stringName; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7292 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7293 | // If this is an AppWindowToken, this is non-null. |
| 7294 | AppWindowToken appWindowToken; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7295 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7296 | // All of the windows associated with this token. |
| 7297 | final ArrayList<WindowState> windows = new ArrayList<WindowState>(); |
| 7298 | |
| 7299 | // Is key dispatching paused for this token? |
| 7300 | boolean paused = false; |
| 7301 | |
| 7302 | // Should this token's windows be hidden? |
| 7303 | boolean hidden; |
| 7304 | |
| 7305 | // Temporary for finding which tokens no longer have visible windows. |
| 7306 | boolean hasVisible; |
| 7307 | |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 7308 | // Set to true when this token is in a pending transaction where it |
| 7309 | // will be shown. |
| 7310 | boolean waitingToShow; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7311 | |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 7312 | // Set to true when this token is in a pending transaction where it |
| 7313 | // will be hidden. |
| 7314 | boolean waitingToHide; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7315 | |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 7316 | // Set to true when this token is in a pending transaction where its |
| 7317 | // windows will be put to the bottom of the list. |
| 7318 | boolean sendingToBottom; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7319 | |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 7320 | // Set to true when this token is in a pending transaction where its |
| 7321 | // windows will be put to the top of the list. |
| 7322 | boolean sendingToTop; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7323 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7324 | WindowToken(IBinder _token, int type, boolean _explicit) { |
| 7325 | token = _token; |
| 7326 | windowType = type; |
| 7327 | explicit = _explicit; |
| 7328 | } |
| 7329 | |
| 7330 | void dump(PrintWriter pw, String prefix) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7331 | pw.print(prefix); pw.print("token="); pw.println(token); |
| 7332 | pw.print(prefix); pw.print("windows="); pw.println(windows); |
| 7333 | pw.print(prefix); pw.print("windowType="); pw.print(windowType); |
| 7334 | pw.print(" hidden="); pw.print(hidden); |
| 7335 | pw.print(" hasVisible="); pw.println(hasVisible); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 7336 | if (waitingToShow || waitingToHide || sendingToBottom || sendingToTop) { |
| 7337 | pw.print(prefix); pw.print("waitingToShow="); pw.print(waitingToShow); |
| 7338 | pw.print(" waitingToHide="); pw.print(waitingToHide); |
| 7339 | pw.print(" sendingToBottom="); pw.print(sendingToBottom); |
| 7340 | pw.print(" sendingToTop="); pw.println(sendingToTop); |
| 7341 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7342 | } |
| 7343 | |
| 7344 | @Override |
| 7345 | public String toString() { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7346 | if (stringName == null) { |
| 7347 | StringBuilder sb = new StringBuilder(); |
| 7348 | sb.append("WindowToken{"); |
| 7349 | sb.append(Integer.toHexString(System.identityHashCode(this))); |
| 7350 | sb.append(" token="); sb.append(token); sb.append('}'); |
| 7351 | stringName = sb.toString(); |
| 7352 | } |
| 7353 | return stringName; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7354 | } |
| 7355 | }; |
| 7356 | |
| 7357 | class AppWindowToken extends WindowToken { |
| 7358 | // Non-null only for application tokens. |
| 7359 | final IApplicationToken appToken; |
| 7360 | |
| 7361 | // All of the windows and child windows that are included in this |
| 7362 | // application token. Note this list is NOT sorted! |
| 7363 | final ArrayList<WindowState> allAppWindows = new ArrayList<WindowState>(); |
| 7364 | |
| 7365 | int groupId = -1; |
| 7366 | boolean appFullscreen; |
| 7367 | int requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 7368 | |
| 7369 | // The input dispatching timeout for this application token in nanoseconds. |
| 7370 | long inputDispatchingTimeoutNanos; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7371 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7372 | // These are used for determining when all windows associated with |
| 7373 | // an activity have been drawn, so they can be made visible together |
| 7374 | // at the same time. |
| 7375 | int lastTransactionSequence = mTransactionSequence-1; |
| 7376 | int numInterestingWindows; |
| 7377 | int numDrawnWindows; |
| 7378 | boolean inPendingTransaction; |
| 7379 | boolean allDrawn; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7380 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7381 | // Is this token going to be hidden in a little while? If so, it |
| 7382 | // won't be taken into account for setting the screen orientation. |
| 7383 | boolean willBeHidden; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7384 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7385 | // Is this window's surface needed? This is almost like hidden, except |
| 7386 | // it will sometimes be true a little earlier: when the token has |
| 7387 | // been shown, but is still waiting for its app transition to execute |
| 7388 | // before making its windows shown. |
| 7389 | boolean hiddenRequested; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7390 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7391 | // Have we told the window clients to hide themselves? |
| 7392 | boolean clientHidden; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7393 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7394 | // Last visibility state we reported to the app token. |
| 7395 | boolean reportedVisible; |
| 7396 | |
| 7397 | // Set to true when the token has been removed from the window mgr. |
| 7398 | boolean removed; |
| 7399 | |
| 7400 | // Have we been asked to have this token keep the screen frozen? |
| 7401 | boolean freezingScreen; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7402 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7403 | boolean animating; |
| 7404 | Animation animation; |
| 7405 | boolean hasTransformation; |
| 7406 | final Transformation transformation = new Transformation(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7407 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7408 | // Offset to the window of all layers in the token, for use by |
| 7409 | // AppWindowToken animations. |
| 7410 | int animLayerAdjustment; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7411 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7412 | // Information about an application starting window if displayed. |
| 7413 | StartingData startingData; |
| 7414 | WindowState startingWindow; |
| 7415 | View startingView; |
| 7416 | boolean startingDisplayed; |
| 7417 | boolean startingMoved; |
| 7418 | boolean firstWindowDrawn; |
| 7419 | |
| 7420 | AppWindowToken(IApplicationToken _token) { |
| 7421 | super(_token.asBinder(), |
| 7422 | WindowManager.LayoutParams.TYPE_APPLICATION, true); |
| 7423 | appWindowToken = this; |
| 7424 | appToken = _token; |
| 7425 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7426 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7427 | public void setAnimation(Animation anim) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7428 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7429 | TAG, "Setting animation in " + this + ": " + anim); |
| 7430 | animation = anim; |
| 7431 | animating = false; |
| 7432 | anim.restrictDuration(MAX_ANIMATION_DURATION); |
| 7433 | anim.scaleCurrentDuration(mTransitionAnimationScale); |
| 7434 | int zorder = anim.getZAdjustment(); |
| 7435 | int adj = 0; |
| 7436 | if (zorder == Animation.ZORDER_TOP) { |
| 7437 | adj = TYPE_LAYER_OFFSET; |
| 7438 | } else if (zorder == Animation.ZORDER_BOTTOM) { |
| 7439 | adj = -TYPE_LAYER_OFFSET; |
| 7440 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7441 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7442 | if (animLayerAdjustment != adj) { |
| 7443 | animLayerAdjustment = adj; |
| 7444 | updateLayers(); |
| 7445 | } |
| 7446 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7447 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7448 | public void setDummyAnimation() { |
| 7449 | if (animation == null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7450 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7451 | TAG, "Setting dummy animation in " + this); |
| 7452 | animation = sDummyAnimation; |
| 7453 | } |
| 7454 | } |
| 7455 | |
| 7456 | public void clearAnimation() { |
| 7457 | if (animation != null) { |
| 7458 | animation = null; |
| 7459 | animating = true; |
| 7460 | } |
| 7461 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7462 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7463 | void updateLayers() { |
| 7464 | final int N = allAppWindows.size(); |
| 7465 | final int adj = animLayerAdjustment; |
| 7466 | for (int i=0; i<N; i++) { |
| 7467 | WindowState w = allAppWindows.get(i); |
| 7468 | w.mAnimLayer = w.mLayer + adj; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7469 | if (DEBUG_LAYERS) Slog.v(TAG, "Updating layer " + w + ": " |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7470 | + w.mAnimLayer); |
| 7471 | if (w == mInputMethodTarget) { |
| 7472 | setInputMethodAnimLayerAdjustment(adj); |
| 7473 | } |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 7474 | if (w == mWallpaperTarget && mLowerWallpaperTarget == null) { |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 7475 | setWallpaperAnimLayerAdjustmentLocked(adj); |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 7476 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7477 | } |
| 7478 | } |
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 | void sendAppVisibilityToClients() { |
| 7481 | final int N = allAppWindows.size(); |
| 7482 | for (int i=0; i<N; i++) { |
| 7483 | WindowState win = allAppWindows.get(i); |
| 7484 | if (win == startingWindow && clientHidden) { |
| 7485 | // Don't hide the starting window. |
| 7486 | continue; |
| 7487 | } |
| 7488 | try { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7489 | if (DEBUG_VISIBILITY) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7490 | "Setting visibility of " + win + ": " + (!clientHidden)); |
| 7491 | win.mClient.dispatchAppVisibility(!clientHidden); |
| 7492 | } catch (RemoteException e) { |
| 7493 | } |
| 7494 | } |
| 7495 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7496 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7497 | void showAllWindowsLocked() { |
| 7498 | final int NW = allAppWindows.size(); |
| 7499 | for (int i=0; i<NW; i++) { |
| 7500 | WindowState w = allAppWindows.get(i); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7501 | if (DEBUG_VISIBILITY) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7502 | "performing show on: " + w); |
| 7503 | w.performShowLocked(); |
| 7504 | } |
| 7505 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7506 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7507 | // This must be called while inside a transaction. |
| 7508 | boolean stepAnimationLocked(long currentTime, int dw, int dh) { |
Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 7509 | if (!mDisplayFrozen && mPolicy.isScreenOn()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7510 | // We will run animations as long as the display isn't frozen. |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7511 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7512 | if (animation == sDummyAnimation) { |
| 7513 | // This guy is going to animate, but not yet. For now count |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 7514 | // it as not animating for purposes of scheduling transactions; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7515 | // when it is really time to animate, this will be set to |
| 7516 | // a real animation and the next call will execute normally. |
| 7517 | return false; |
| 7518 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7519 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7520 | if ((allDrawn || animating || startingDisplayed) && animation != null) { |
| 7521 | if (!animating) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7522 | if (DEBUG_ANIM) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7523 | TAG, "Starting animation in " + this + |
| 7524 | " @ " + currentTime + ": dw=" + dw + " dh=" + dh |
| 7525 | + " scale=" + mTransitionAnimationScale |
| 7526 | + " allDrawn=" + allDrawn + " animating=" + animating); |
| 7527 | animation.initialize(dw, dh, dw, dh); |
| 7528 | animation.setStartTime(currentTime); |
| 7529 | animating = true; |
| 7530 | } |
| 7531 | transformation.clear(); |
| 7532 | final boolean more = animation.getTransformation( |
| 7533 | currentTime, transformation); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7534 | if (DEBUG_ANIM) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7535 | TAG, "Stepped animation in " + this + |
| 7536 | ": more=" + more + ", xform=" + transformation); |
| 7537 | if (more) { |
| 7538 | // we're done! |
| 7539 | hasTransformation = true; |
| 7540 | return true; |
| 7541 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7542 | if (DEBUG_ANIM) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7543 | TAG, "Finished animation in " + this + |
| 7544 | " @ " + currentTime); |
| 7545 | animation = null; |
| 7546 | } |
| 7547 | } else if (animation != null) { |
| 7548 | // If the display is frozen, and there is a pending animation, |
| 7549 | // clear it and make sure we run the cleanup code. |
| 7550 | animating = true; |
| 7551 | animation = null; |
| 7552 | } |
| 7553 | |
| 7554 | hasTransformation = false; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7555 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7556 | if (!animating) { |
| 7557 | return false; |
| 7558 | } |
| 7559 | |
| 7560 | clearAnimation(); |
| 7561 | animating = false; |
| 7562 | if (mInputMethodTarget != null && mInputMethodTarget.mAppToken == this) { |
| 7563 | moveInputMethodWindowsIfNeededLocked(true); |
| 7564 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7565 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7566 | if (DEBUG_ANIM) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7567 | TAG, "Animation done in " + this |
| 7568 | + ": reportedVisible=" + reportedVisible); |
| 7569 | |
| 7570 | transformation.clear(); |
| 7571 | if (animLayerAdjustment != 0) { |
| 7572 | animLayerAdjustment = 0; |
| 7573 | updateLayers(); |
| 7574 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7575 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7576 | final int N = windows.size(); |
| 7577 | for (int i=0; i<N; i++) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 7578 | windows.get(i).finishExit(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7579 | } |
| 7580 | updateReportedVisibilityLocked(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7581 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7582 | return false; |
| 7583 | } |
| 7584 | |
| 7585 | void updateReportedVisibilityLocked() { |
| 7586 | if (appToken == null) { |
| 7587 | return; |
| 7588 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7589 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7590 | int numInteresting = 0; |
| 7591 | int numVisible = 0; |
| 7592 | boolean nowGone = true; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7593 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7594 | 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] | 7595 | final int N = allAppWindows.size(); |
| 7596 | for (int i=0; i<N; i++) { |
| 7597 | WindowState win = allAppWindows.get(i); |
Dianne Hackborn | 6cf67fa | 2009-12-21 16:46:34 -0800 | [diff] [blame] | 7598 | if (win == startingWindow || win.mAppFreezing |
The Android Open Source Project | 727cec0 | 2010-04-08 11:35:37 -0700 | [diff] [blame] | 7599 | || win.mViewVisibility != View.VISIBLE |
| 7600 | || win.mAttrs.type == TYPE_APPLICATION_STARTING) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7601 | continue; |
| 7602 | } |
| 7603 | if (DEBUG_VISIBILITY) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7604 | Slog.v(TAG, "Win " + win + ": isDrawn=" |
Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 7605 | + win.isDrawnLw() |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7606 | + ", isAnimating=" + win.isAnimating()); |
Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 7607 | if (!win.isDrawnLw()) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7608 | Slog.v(TAG, "Not displayed: s=" + win.mSurface |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7609 | + " pv=" + win.mPolicyVisibility |
| 7610 | + " dp=" + win.mDrawPending |
| 7611 | + " cdp=" + win.mCommitDrawPending |
| 7612 | + " ah=" + win.mAttachedHidden |
| 7613 | + " th=" |
| 7614 | + (win.mAppToken != null |
| 7615 | ? win.mAppToken.hiddenRequested : false) |
| 7616 | + " a=" + win.mAnimating); |
| 7617 | } |
| 7618 | } |
| 7619 | numInteresting++; |
Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 7620 | if (win.isDrawnLw()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7621 | if (!win.isAnimating()) { |
| 7622 | numVisible++; |
| 7623 | } |
| 7624 | nowGone = false; |
| 7625 | } else if (win.isAnimating()) { |
| 7626 | nowGone = false; |
| 7627 | } |
| 7628 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7629 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7630 | boolean nowVisible = numInteresting > 0 && numVisible >= numInteresting; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7631 | if (DEBUG_VISIBILITY) Slog.v(TAG, "VIS " + this + ": interesting=" |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7632 | + numInteresting + " visible=" + numVisible); |
| 7633 | if (nowVisible != reportedVisible) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7634 | if (DEBUG_VISIBILITY) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7635 | TAG, "Visibility changed in " + this |
| 7636 | + ": vis=" + nowVisible); |
| 7637 | reportedVisible = nowVisible; |
| 7638 | Message m = mH.obtainMessage( |
| 7639 | H.REPORT_APPLICATION_TOKEN_WINDOWS, |
| 7640 | nowVisible ? 1 : 0, |
| 7641 | nowGone ? 1 : 0, |
| 7642 | this); |
| 7643 | mH.sendMessage(m); |
| 7644 | } |
| 7645 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7646 | |
Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 7647 | WindowState findMainWindow() { |
| 7648 | int j = windows.size(); |
| 7649 | while (j > 0) { |
| 7650 | j--; |
| 7651 | WindowState win = windows.get(j); |
| 7652 | if (win.mAttrs.type == WindowManager.LayoutParams.TYPE_BASE_APPLICATION |
| 7653 | || win.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING) { |
| 7654 | return win; |
| 7655 | } |
| 7656 | } |
| 7657 | return null; |
| 7658 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7659 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7660 | void dump(PrintWriter pw, String prefix) { |
| 7661 | super.dump(pw, prefix); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7662 | if (appToken != null) { |
| 7663 | pw.print(prefix); pw.println("app=true"); |
| 7664 | } |
| 7665 | if (allAppWindows.size() > 0) { |
| 7666 | pw.print(prefix); pw.print("allAppWindows="); pw.println(allAppWindows); |
| 7667 | } |
| 7668 | pw.print(prefix); pw.print("groupId="); pw.print(groupId); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 7669 | pw.print(" appFullscreen="); pw.print(appFullscreen); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7670 | pw.print(" requestedOrientation="); pw.println(requestedOrientation); |
| 7671 | pw.print(prefix); pw.print("hiddenRequested="); pw.print(hiddenRequested); |
| 7672 | pw.print(" clientHidden="); pw.print(clientHidden); |
| 7673 | pw.print(" willBeHidden="); pw.print(willBeHidden); |
| 7674 | pw.print(" reportedVisible="); pw.println(reportedVisible); |
| 7675 | if (paused || freezingScreen) { |
| 7676 | pw.print(prefix); pw.print("paused="); pw.print(paused); |
| 7677 | pw.print(" freezingScreen="); pw.println(freezingScreen); |
| 7678 | } |
| 7679 | if (numInterestingWindows != 0 || numDrawnWindows != 0 |
| 7680 | || inPendingTransaction || allDrawn) { |
| 7681 | pw.print(prefix); pw.print("numInterestingWindows="); |
| 7682 | pw.print(numInterestingWindows); |
| 7683 | pw.print(" numDrawnWindows="); pw.print(numDrawnWindows); |
| 7684 | pw.print(" inPendingTransaction="); pw.print(inPendingTransaction); |
| 7685 | pw.print(" allDrawn="); pw.println(allDrawn); |
| 7686 | } |
| 7687 | if (animating || animation != null) { |
| 7688 | pw.print(prefix); pw.print("animating="); pw.print(animating); |
| 7689 | pw.print(" animation="); pw.println(animation); |
| 7690 | } |
| 7691 | if (animLayerAdjustment != 0) { |
| 7692 | pw.print(prefix); pw.print("animLayerAdjustment="); pw.println(animLayerAdjustment); |
| 7693 | } |
| 7694 | if (hasTransformation) { |
| 7695 | pw.print(prefix); pw.print("hasTransformation="); pw.print(hasTransformation); |
| 7696 | pw.print(" transformation="); transformation.printShortString(pw); |
| 7697 | pw.println(); |
| 7698 | } |
| 7699 | if (startingData != null || removed || firstWindowDrawn) { |
| 7700 | pw.print(prefix); pw.print("startingData="); pw.print(startingData); |
| 7701 | pw.print(" removed="); pw.print(removed); |
| 7702 | pw.print(" firstWindowDrawn="); pw.println(firstWindowDrawn); |
| 7703 | } |
| 7704 | if (startingWindow != null || startingView != null |
| 7705 | || startingDisplayed || startingMoved) { |
| 7706 | pw.print(prefix); pw.print("startingWindow="); pw.print(startingWindow); |
| 7707 | pw.print(" startingView="); pw.print(startingView); |
| 7708 | pw.print(" startingDisplayed="); pw.print(startingDisplayed); |
| 7709 | pw.print(" startingMoved"); pw.println(startingMoved); |
| 7710 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7711 | } |
| 7712 | |
| 7713 | @Override |
| 7714 | public String toString() { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7715 | if (stringName == null) { |
| 7716 | StringBuilder sb = new StringBuilder(); |
| 7717 | sb.append("AppWindowToken{"); |
| 7718 | sb.append(Integer.toHexString(System.identityHashCode(this))); |
| 7719 | sb.append(" token="); sb.append(token); sb.append('}'); |
| 7720 | stringName = sb.toString(); |
| 7721 | } |
| 7722 | return stringName; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7723 | } |
| 7724 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7725 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7726 | // ------------------------------------------------------------- |
| 7727 | // DummyAnimation |
| 7728 | // ------------------------------------------------------------- |
| 7729 | |
| 7730 | // This is an animation that does nothing: it just immediately finishes |
| 7731 | // itself every time it is called. It is used as a stub animation in cases |
| 7732 | // where we want to synchronize multiple things that may be animating. |
| 7733 | static final class DummyAnimation extends Animation { |
| 7734 | public boolean getTransformation(long currentTime, Transformation outTransformation) { |
| 7735 | return false; |
| 7736 | } |
| 7737 | } |
| 7738 | static final Animation sDummyAnimation = new DummyAnimation(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7739 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7740 | // ------------------------------------------------------------- |
| 7741 | // Async Handler |
| 7742 | // ------------------------------------------------------------- |
| 7743 | |
| 7744 | static final class StartingData { |
| 7745 | final String pkg; |
| 7746 | final int theme; |
| 7747 | final CharSequence nonLocalizedLabel; |
| 7748 | final int labelRes; |
| 7749 | final int icon; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7750 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7751 | StartingData(String _pkg, int _theme, CharSequence _nonLocalizedLabel, |
| 7752 | int _labelRes, int _icon) { |
| 7753 | pkg = _pkg; |
| 7754 | theme = _theme; |
| 7755 | nonLocalizedLabel = _nonLocalizedLabel; |
| 7756 | labelRes = _labelRes; |
| 7757 | icon = _icon; |
| 7758 | } |
| 7759 | } |
| 7760 | |
| 7761 | private final class H extends Handler { |
| 7762 | public static final int REPORT_FOCUS_CHANGE = 2; |
| 7763 | public static final int REPORT_LOSING_FOCUS = 3; |
| 7764 | public static final int ANIMATE = 4; |
| 7765 | public static final int ADD_STARTING = 5; |
| 7766 | public static final int REMOVE_STARTING = 6; |
| 7767 | public static final int FINISHED_STARTING = 7; |
| 7768 | public static final int REPORT_APPLICATION_TOKEN_WINDOWS = 8; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7769 | public static final int WINDOW_FREEZE_TIMEOUT = 11; |
| 7770 | public static final int HOLD_SCREEN_CHANGED = 12; |
| 7771 | public static final int APP_TRANSITION_TIMEOUT = 13; |
| 7772 | public static final int PERSIST_ANIMATION_SCALE = 14; |
| 7773 | public static final int FORCE_GC = 15; |
| 7774 | public static final int ENABLE_SCREEN = 16; |
| 7775 | public static final int APP_FREEZE_TIMEOUT = 17; |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 7776 | public static final int SEND_NEW_CONFIGURATION = 18; |
Konstantin Lopyrev | 6e0f65f | 2010-07-14 14:55:33 -0700 | [diff] [blame] | 7777 | public static final int REPORT_WINDOWS_CHANGE = 19; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7778 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7779 | private Session mLastReportedHold; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7780 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7781 | public H() { |
| 7782 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7783 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7784 | @Override |
| 7785 | public void handleMessage(Message msg) { |
| 7786 | switch (msg.what) { |
| 7787 | case REPORT_FOCUS_CHANGE: { |
| 7788 | WindowState lastFocus; |
| 7789 | WindowState newFocus; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7790 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7791 | synchronized(mWindowMap) { |
| 7792 | lastFocus = mLastFocus; |
| 7793 | newFocus = mCurrentFocus; |
| 7794 | if (lastFocus == newFocus) { |
| 7795 | // Focus is not changing, so nothing to do. |
| 7796 | return; |
| 7797 | } |
| 7798 | mLastFocus = newFocus; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7799 | //Slog.i(TAG, "Focus moving from " + lastFocus |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7800 | // + " to " + newFocus); |
| 7801 | if (newFocus != null && lastFocus != null |
| 7802 | && !newFocus.isDisplayedLw()) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7803 | //Slog.i(TAG, "Delaying loss of focus..."); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7804 | mLosingFocus.add(lastFocus); |
| 7805 | lastFocus = null; |
| 7806 | } |
| 7807 | } |
| 7808 | |
| 7809 | if (lastFocus != newFocus) { |
| 7810 | //System.out.println("Changing focus from " + lastFocus |
| 7811 | // + " to " + newFocus); |
| 7812 | if (newFocus != null) { |
| 7813 | try { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7814 | //Slog.i(TAG, "Gaining focus: " + newFocus); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7815 | newFocus.mClient.windowFocusChanged(true, mInTouchMode); |
| 7816 | } catch (RemoteException e) { |
| 7817 | // Ignore if process has died. |
| 7818 | } |
| 7819 | } |
| 7820 | |
| 7821 | if (lastFocus != null) { |
| 7822 | try { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7823 | //Slog.i(TAG, "Losing focus: " + lastFocus); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7824 | lastFocus.mClient.windowFocusChanged(false, mInTouchMode); |
| 7825 | } catch (RemoteException e) { |
| 7826 | // Ignore if process has died. |
| 7827 | } |
| 7828 | } |
Konstantin Lopyrev | 6e0f65f | 2010-07-14 14:55:33 -0700 | [diff] [blame] | 7829 | notifyFocusChanged(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7830 | } |
| 7831 | } break; |
| 7832 | |
| 7833 | case REPORT_LOSING_FOCUS: { |
| 7834 | ArrayList<WindowState> losers; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7835 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7836 | synchronized(mWindowMap) { |
| 7837 | losers = mLosingFocus; |
| 7838 | mLosingFocus = new ArrayList<WindowState>(); |
| 7839 | } |
| 7840 | |
| 7841 | final int N = losers.size(); |
| 7842 | for (int i=0; i<N; i++) { |
| 7843 | try { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7844 | //Slog.i(TAG, "Losing delayed focus: " + losers.get(i)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7845 | losers.get(i).mClient.windowFocusChanged(false, mInTouchMode); |
| 7846 | } catch (RemoteException e) { |
| 7847 | // Ignore if process has died. |
| 7848 | } |
| 7849 | } |
| 7850 | } break; |
| 7851 | |
| 7852 | case ANIMATE: { |
| 7853 | synchronized(mWindowMap) { |
| 7854 | mAnimationPending = false; |
| 7855 | performLayoutAndPlaceSurfacesLocked(); |
| 7856 | } |
| 7857 | } break; |
| 7858 | |
| 7859 | case ADD_STARTING: { |
| 7860 | final AppWindowToken wtoken = (AppWindowToken)msg.obj; |
| 7861 | final StartingData sd = wtoken.startingData; |
| 7862 | |
| 7863 | if (sd == null) { |
| 7864 | // Animation has been canceled... do nothing. |
| 7865 | return; |
| 7866 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7867 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7868 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Add starting " |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7869 | + wtoken + ": pkg=" + sd.pkg); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7870 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7871 | View view = null; |
| 7872 | try { |
| 7873 | view = mPolicy.addStartingWindow( |
| 7874 | wtoken.token, sd.pkg, |
| 7875 | sd.theme, sd.nonLocalizedLabel, sd.labelRes, |
| 7876 | sd.icon); |
| 7877 | } catch (Exception e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7878 | Slog.w(TAG, "Exception when adding starting window", e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7879 | } |
| 7880 | |
| 7881 | if (view != null) { |
| 7882 | boolean abort = false; |
| 7883 | |
| 7884 | synchronized(mWindowMap) { |
| 7885 | if (wtoken.removed || wtoken.startingData == null) { |
| 7886 | // If the window was successfully added, then |
| 7887 | // we need to remove it. |
| 7888 | if (wtoken.startingWindow != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7889 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7890 | "Aborted starting " + wtoken |
| 7891 | + ": removed=" + wtoken.removed |
| 7892 | + " startingData=" + wtoken.startingData); |
| 7893 | wtoken.startingWindow = null; |
| 7894 | wtoken.startingData = null; |
| 7895 | abort = true; |
| 7896 | } |
| 7897 | } else { |
| 7898 | wtoken.startingView = view; |
| 7899 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7900 | if (DEBUG_STARTING_WINDOW && !abort) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7901 | "Added starting " + wtoken |
| 7902 | + ": startingWindow=" |
| 7903 | + wtoken.startingWindow + " startingView=" |
| 7904 | + wtoken.startingView); |
| 7905 | } |
| 7906 | |
| 7907 | if (abort) { |
| 7908 | try { |
| 7909 | mPolicy.removeStartingWindow(wtoken.token, view); |
| 7910 | } catch (Exception e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7911 | Slog.w(TAG, "Exception when removing starting window", e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7912 | } |
| 7913 | } |
| 7914 | } |
| 7915 | } break; |
| 7916 | |
| 7917 | case REMOVE_STARTING: { |
| 7918 | final AppWindowToken wtoken = (AppWindowToken)msg.obj; |
| 7919 | IBinder token = null; |
| 7920 | View view = null; |
| 7921 | synchronized (mWindowMap) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7922 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Remove starting " |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7923 | + wtoken + ": startingWindow=" |
| 7924 | + wtoken.startingWindow + " startingView=" |
| 7925 | + wtoken.startingView); |
| 7926 | if (wtoken.startingWindow != null) { |
| 7927 | view = wtoken.startingView; |
| 7928 | token = wtoken.token; |
| 7929 | wtoken.startingData = null; |
| 7930 | wtoken.startingView = null; |
| 7931 | wtoken.startingWindow = null; |
| 7932 | } |
| 7933 | } |
| 7934 | if (view != null) { |
| 7935 | try { |
| 7936 | mPolicy.removeStartingWindow(token, view); |
| 7937 | } catch (Exception e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7938 | Slog.w(TAG, "Exception when removing starting window", e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7939 | } |
| 7940 | } |
| 7941 | } break; |
| 7942 | |
| 7943 | case FINISHED_STARTING: { |
| 7944 | IBinder token = null; |
| 7945 | View view = null; |
| 7946 | while (true) { |
| 7947 | synchronized (mWindowMap) { |
| 7948 | final int N = mFinishedStarting.size(); |
| 7949 | if (N <= 0) { |
| 7950 | break; |
| 7951 | } |
| 7952 | AppWindowToken wtoken = mFinishedStarting.remove(N-1); |
| 7953 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7954 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7955 | "Finished starting " + wtoken |
| 7956 | + ": startingWindow=" + wtoken.startingWindow |
| 7957 | + " startingView=" + wtoken.startingView); |
| 7958 | |
| 7959 | if (wtoken.startingWindow == null) { |
| 7960 | continue; |
| 7961 | } |
| 7962 | |
| 7963 | view = wtoken.startingView; |
| 7964 | token = wtoken.token; |
| 7965 | wtoken.startingData = null; |
| 7966 | wtoken.startingView = null; |
| 7967 | wtoken.startingWindow = null; |
| 7968 | } |
| 7969 | |
| 7970 | try { |
| 7971 | mPolicy.removeStartingWindow(token, view); |
| 7972 | } catch (Exception e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7973 | Slog.w(TAG, "Exception when removing starting window", e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7974 | } |
| 7975 | } |
| 7976 | } break; |
| 7977 | |
| 7978 | case REPORT_APPLICATION_TOKEN_WINDOWS: { |
| 7979 | final AppWindowToken wtoken = (AppWindowToken)msg.obj; |
| 7980 | |
| 7981 | boolean nowVisible = msg.arg1 != 0; |
| 7982 | boolean nowGone = msg.arg2 != 0; |
| 7983 | |
| 7984 | try { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7985 | if (DEBUG_VISIBILITY) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7986 | TAG, "Reporting visible in " + wtoken |
| 7987 | + " visible=" + nowVisible |
| 7988 | + " gone=" + nowGone); |
| 7989 | if (nowVisible) { |
| 7990 | wtoken.appToken.windowsVisible(); |
| 7991 | } else { |
| 7992 | wtoken.appToken.windowsGone(); |
| 7993 | } |
| 7994 | } catch (RemoteException ex) { |
| 7995 | } |
| 7996 | } break; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7997 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7998 | case WINDOW_FREEZE_TIMEOUT: { |
| 7999 | synchronized (mWindowMap) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8000 | Slog.w(TAG, "Window freeze timeout expired."); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8001 | int i = mWindows.size(); |
| 8002 | while (i > 0) { |
| 8003 | i--; |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 8004 | WindowState w = mWindows.get(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8005 | if (w.mOrientationChanging) { |
| 8006 | w.mOrientationChanging = false; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8007 | Slog.w(TAG, "Force clearing orientation change: " + w); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8008 | } |
| 8009 | } |
| 8010 | performLayoutAndPlaceSurfacesLocked(); |
| 8011 | } |
| 8012 | break; |
| 8013 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8014 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8015 | case HOLD_SCREEN_CHANGED: { |
| 8016 | Session oldHold; |
| 8017 | Session newHold; |
| 8018 | synchronized (mWindowMap) { |
| 8019 | oldHold = mLastReportedHold; |
| 8020 | newHold = (Session)msg.obj; |
| 8021 | mLastReportedHold = newHold; |
| 8022 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8023 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8024 | if (oldHold != newHold) { |
| 8025 | try { |
| 8026 | if (oldHold != null) { |
| 8027 | mBatteryStats.noteStopWakelock(oldHold.mUid, |
| 8028 | "window", |
| 8029 | BatteryStats.WAKE_TYPE_WINDOW); |
| 8030 | } |
| 8031 | if (newHold != null) { |
| 8032 | mBatteryStats.noteStartWakelock(newHold.mUid, |
| 8033 | "window", |
| 8034 | BatteryStats.WAKE_TYPE_WINDOW); |
| 8035 | } |
| 8036 | } catch (RemoteException e) { |
| 8037 | } |
| 8038 | } |
| 8039 | break; |
| 8040 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8041 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8042 | case APP_TRANSITION_TIMEOUT: { |
| 8043 | synchronized (mWindowMap) { |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 8044 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8045 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8046 | "*** APP TRANSITION TIMEOUT"); |
| 8047 | mAppTransitionReady = true; |
| 8048 | mAppTransitionTimeout = true; |
| 8049 | performLayoutAndPlaceSurfacesLocked(); |
| 8050 | } |
| 8051 | } |
| 8052 | break; |
| 8053 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8054 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8055 | case PERSIST_ANIMATION_SCALE: { |
| 8056 | Settings.System.putFloat(mContext.getContentResolver(), |
| 8057 | Settings.System.WINDOW_ANIMATION_SCALE, mWindowAnimationScale); |
| 8058 | Settings.System.putFloat(mContext.getContentResolver(), |
| 8059 | Settings.System.TRANSITION_ANIMATION_SCALE, mTransitionAnimationScale); |
| 8060 | break; |
| 8061 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8062 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8063 | case FORCE_GC: { |
| 8064 | synchronized(mWindowMap) { |
| 8065 | if (mAnimationPending) { |
| 8066 | // If we are animating, don't do the gc now but |
| 8067 | // delay a bit so we don't interrupt the animation. |
| 8068 | mH.sendMessageDelayed(mH.obtainMessage(H.FORCE_GC), |
| 8069 | 2000); |
| 8070 | return; |
| 8071 | } |
| 8072 | // If we are currently rotating the display, it will |
| 8073 | // schedule a new message when done. |
| 8074 | if (mDisplayFrozen) { |
| 8075 | return; |
| 8076 | } |
| 8077 | mFreezeGcPending = 0; |
| 8078 | } |
| 8079 | Runtime.getRuntime().gc(); |
| 8080 | break; |
| 8081 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8082 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8083 | case ENABLE_SCREEN: { |
| 8084 | performEnableScreen(); |
| 8085 | break; |
| 8086 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8087 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8088 | case APP_FREEZE_TIMEOUT: { |
| 8089 | synchronized (mWindowMap) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8090 | Slog.w(TAG, "App freeze timeout expired."); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8091 | int i = mAppTokens.size(); |
| 8092 | while (i > 0) { |
| 8093 | i--; |
| 8094 | AppWindowToken tok = mAppTokens.get(i); |
| 8095 | if (tok.freezingScreen) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8096 | Slog.w(TAG, "Force clearing freeze: " + tok); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8097 | unsetAppFreezingScreenLocked(tok, true, true); |
| 8098 | } |
| 8099 | } |
| 8100 | } |
| 8101 | break; |
| 8102 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8103 | |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 8104 | case SEND_NEW_CONFIGURATION: { |
| 8105 | removeMessages(SEND_NEW_CONFIGURATION); |
| 8106 | sendNewConfiguration(); |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 8107 | break; |
| 8108 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8109 | |
Konstantin Lopyrev | 6e0f65f | 2010-07-14 14:55:33 -0700 | [diff] [blame] | 8110 | case REPORT_WINDOWS_CHANGE: { |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 8111 | if (mWindowsChanged) { |
| 8112 | synchronized (mWindowMap) { |
| 8113 | mWindowsChanged = false; |
| 8114 | } |
| 8115 | notifyWindowsChanged(); |
| 8116 | } |
| 8117 | break; |
| 8118 | } |
| 8119 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8120 | } |
| 8121 | } |
| 8122 | } |
| 8123 | |
| 8124 | // ------------------------------------------------------------- |
| 8125 | // IWindowManager API |
| 8126 | // ------------------------------------------------------------- |
| 8127 | |
| 8128 | public IWindowSession openSession(IInputMethodClient client, |
| 8129 | IInputContext inputContext) { |
| 8130 | if (client == null) throw new IllegalArgumentException("null client"); |
| 8131 | if (inputContext == null) throw new IllegalArgumentException("null inputContext"); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 8132 | Session session = new Session(client, inputContext); |
| 8133 | return session; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8134 | } |
| 8135 | |
| 8136 | public boolean inputMethodClientHasFocus(IInputMethodClient client) { |
| 8137 | synchronized (mWindowMap) { |
| 8138 | // The focus for the client is the window immediately below |
| 8139 | // where we would place the input method window. |
| 8140 | int idx = findDesiredInputMethodWindowIndexLocked(false); |
| 8141 | WindowState imFocus; |
| 8142 | if (idx > 0) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 8143 | imFocus = mWindows.get(idx-1); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8144 | if (imFocus != null) { |
| 8145 | if (imFocus.mSession.mClient != null && |
| 8146 | imFocus.mSession.mClient.asBinder() == client.asBinder()) { |
| 8147 | return true; |
| 8148 | } |
| 8149 | } |
| 8150 | } |
| 8151 | } |
| 8152 | return false; |
| 8153 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8154 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8155 | // ------------------------------------------------------------- |
| 8156 | // Internals |
| 8157 | // ------------------------------------------------------------- |
| 8158 | |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 8159 | final WindowState windowForClientLocked(Session session, IWindow client, |
| 8160 | boolean throwOnError) { |
| 8161 | return windowForClientLocked(session, client.asBinder(), throwOnError); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8162 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8163 | |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 8164 | final WindowState windowForClientLocked(Session session, IBinder client, |
| 8165 | boolean throwOnError) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8166 | WindowState win = mWindowMap.get(client); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8167 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8168 | TAG, "Looking up client " + client + ": " + win); |
| 8169 | if (win == null) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 8170 | RuntimeException ex = new IllegalArgumentException( |
| 8171 | "Requested window " + client + " does not exist"); |
| 8172 | if (throwOnError) { |
| 8173 | throw ex; |
| 8174 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8175 | Slog.w(TAG, "Failed looking up window", ex); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8176 | return null; |
| 8177 | } |
| 8178 | if (session != null && win.mSession != session) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 8179 | RuntimeException ex = new IllegalArgumentException( |
| 8180 | "Requested window " + client + " is in session " + |
| 8181 | win.mSession + ", not " + session); |
| 8182 | if (throwOnError) { |
| 8183 | throw ex; |
| 8184 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8185 | Slog.w(TAG, "Failed looking up window", ex); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8186 | return null; |
| 8187 | } |
| 8188 | |
| 8189 | return win; |
| 8190 | } |
| 8191 | |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8192 | final void rebuildAppWindowListLocked() { |
| 8193 | int NW = mWindows.size(); |
| 8194 | int i; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8195 | int lastWallpaper = -1; |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 8196 | int numRemoved = 0; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8197 | |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8198 | // First remove all existing app windows. |
| 8199 | i=0; |
| 8200 | while (i < NW) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 8201 | WindowState w = mWindows.get(i); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8202 | if (w.mAppToken != null) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 8203 | WindowState win = mWindows.remove(i); |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 8204 | mWindowsChanged = true; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8205 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, |
Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 8206 | "Rebuild removing window: " + win); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8207 | NW--; |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 8208 | numRemoved++; |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8209 | continue; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8210 | } else if (w.mAttrs.type == WindowManager.LayoutParams.TYPE_WALLPAPER |
| 8211 | && lastWallpaper == i-1) { |
| 8212 | lastWallpaper = i; |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8213 | } |
| 8214 | i++; |
| 8215 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8216 | |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8217 | // The wallpaper window(s) typically live at the bottom of the stack, |
| 8218 | // so skip them before adding app tokens. |
| 8219 | lastWallpaper++; |
| 8220 | i = lastWallpaper; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8221 | |
Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 8222 | // First add all of the exiting app tokens... these are no longer |
| 8223 | // in the main app list, but still have windows shown. We put them |
| 8224 | // in the back because now that the animation is over we no longer |
| 8225 | // will care about them. |
| 8226 | int NT = mExitingAppTokens.size(); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8227 | for (int j=0; j<NT; j++) { |
Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 8228 | i = reAddAppWindowsLocked(i, mExitingAppTokens.get(j)); |
| 8229 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8230 | |
Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 8231 | // And add in the still active app tokens in Z order. |
| 8232 | NT = mAppTokens.size(); |
| 8233 | for (int j=0; j<NT; j++) { |
| 8234 | i = reAddAppWindowsLocked(i, mAppTokens.get(j)); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8235 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8236 | |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8237 | i -= lastWallpaper; |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 8238 | if (i != numRemoved) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8239 | Slog.w(TAG, "Rebuild removed " + numRemoved |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 8240 | + " windows but added " + i); |
| 8241 | } |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8242 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8243 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8244 | private final void assignLayersLocked() { |
| 8245 | int N = mWindows.size(); |
| 8246 | int curBaseLayer = 0; |
| 8247 | int curLayer = 0; |
| 8248 | int i; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8249 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8250 | for (i=0; i<N; i++) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 8251 | WindowState w = mWindows.get(i); |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 8252 | if (w.mBaseLayer == curBaseLayer || w.mIsImWindow |
| 8253 | || (i > 0 && w.mIsWallpaper)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8254 | curLayer += WINDOW_LAYER_MULTIPLIER; |
| 8255 | w.mLayer = curLayer; |
| 8256 | } else { |
| 8257 | curBaseLayer = curLayer = w.mBaseLayer; |
| 8258 | w.mLayer = curLayer; |
| 8259 | } |
| 8260 | if (w.mTargetAppToken != null) { |
| 8261 | w.mAnimLayer = w.mLayer + w.mTargetAppToken.animLayerAdjustment; |
| 8262 | } else if (w.mAppToken != null) { |
| 8263 | w.mAnimLayer = w.mLayer + w.mAppToken.animLayerAdjustment; |
| 8264 | } else { |
| 8265 | w.mAnimLayer = w.mLayer; |
| 8266 | } |
| 8267 | if (w.mIsImWindow) { |
| 8268 | w.mAnimLayer += mInputMethodAnimLayerAdjustment; |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 8269 | } else if (w.mIsWallpaper) { |
| 8270 | w.mAnimLayer += mWallpaperAnimLayerAdjustment; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8271 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8272 | if (DEBUG_LAYERS) Slog.v(TAG, "Assign layer " + w + ": " |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8273 | + w.mAnimLayer); |
| 8274 | //System.out.println( |
| 8275 | // "Assigned layer " + curLayer + " to " + w.mClient.asBinder()); |
| 8276 | } |
| 8277 | } |
| 8278 | |
| 8279 | private boolean mInLayout = false; |
| 8280 | private final void performLayoutAndPlaceSurfacesLocked() { |
| 8281 | if (mInLayout) { |
Dave Bort | cfe6524 | 2009-04-09 14:51:04 -0700 | [diff] [blame] | 8282 | if (DEBUG) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8283 | throw new RuntimeException("Recursive call!"); |
| 8284 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8285 | Slog.w(TAG, "performLayoutAndPlaceSurfacesLocked called while in layout"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8286 | return; |
| 8287 | } |
| 8288 | |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 8289 | if (mWaitingForConfig) { |
| 8290 | // Our configuration has changed (most likely rotation), but we |
| 8291 | // don't yet have the complete configuration to report to |
| 8292 | // applications. Don't do any window layout until we have it. |
| 8293 | return; |
| 8294 | } |
| 8295 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8296 | boolean recoveringMemory = false; |
| 8297 | if (mForceRemoves != null) { |
| 8298 | recoveringMemory = true; |
| 8299 | // Wait a little it for things to settle down, and off we go. |
| 8300 | for (int i=0; i<mForceRemoves.size(); i++) { |
| 8301 | WindowState ws = mForceRemoves.get(i); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8302 | Slog.i(TAG, "Force removing: " + ws); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8303 | removeWindowInnerLocked(ws.mSession, ws); |
| 8304 | } |
| 8305 | mForceRemoves = null; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8306 | 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] | 8307 | Object tmp = new Object(); |
| 8308 | synchronized (tmp) { |
| 8309 | try { |
| 8310 | tmp.wait(250); |
| 8311 | } catch (InterruptedException e) { |
| 8312 | } |
| 8313 | } |
| 8314 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8315 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8316 | mInLayout = true; |
| 8317 | try { |
| 8318 | performLayoutAndPlaceSurfacesLockedInner(recoveringMemory); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8319 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8320 | int i = mPendingRemove.size()-1; |
| 8321 | if (i >= 0) { |
| 8322 | while (i >= 0) { |
| 8323 | WindowState w = mPendingRemove.get(i); |
| 8324 | removeWindowInnerLocked(w.mSession, w); |
| 8325 | i--; |
| 8326 | } |
| 8327 | mPendingRemove.clear(); |
| 8328 | |
| 8329 | mInLayout = false; |
| 8330 | assignLayersLocked(); |
| 8331 | mLayoutNeeded = true; |
| 8332 | performLayoutAndPlaceSurfacesLocked(); |
| 8333 | |
| 8334 | } else { |
| 8335 | mInLayout = false; |
| 8336 | if (mLayoutNeeded) { |
| 8337 | requestAnimationLocked(0); |
| 8338 | } |
| 8339 | } |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 8340 | if (mWindowsChanged && !mWindowChangeListeners.isEmpty()) { |
Konstantin Lopyrev | 6e0f65f | 2010-07-14 14:55:33 -0700 | [diff] [blame] | 8341 | mH.removeMessages(H.REPORT_WINDOWS_CHANGE); |
| 8342 | mH.sendMessage(mH.obtainMessage(H.REPORT_WINDOWS_CHANGE)); |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 8343 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8344 | } catch (RuntimeException e) { |
| 8345 | mInLayout = false; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8346 | 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] | 8347 | } |
| 8348 | } |
| 8349 | |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 8350 | private final int performLayoutLockedInner() { |
| 8351 | if (!mLayoutNeeded) { |
| 8352 | return 0; |
| 8353 | } |
| 8354 | |
| 8355 | mLayoutNeeded = false; |
| 8356 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8357 | final int dw = mDisplay.getWidth(); |
| 8358 | final int dh = mDisplay.getHeight(); |
| 8359 | |
| 8360 | final int N = mWindows.size(); |
| 8361 | int i; |
| 8362 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8363 | if (DEBUG_LAYOUT) Slog.v(TAG, "performLayout: needed=" |
Dianne Hackborn | 9b52a21 | 2009-12-11 14:51:35 -0800 | [diff] [blame] | 8364 | + mLayoutNeeded + " dw=" + dw + " dh=" + dh); |
| 8365 | |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 8366 | mPolicy.beginLayoutLw(dw, dh); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8367 | |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 8368 | int seq = mLayoutSeq+1; |
| 8369 | if (seq < 0) seq = 0; |
| 8370 | mLayoutSeq = seq; |
| 8371 | |
| 8372 | // First perform layout of any root windows (not attached |
| 8373 | // to another window). |
| 8374 | int topAttached = -1; |
| 8375 | for (i = N-1; i >= 0; i--) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 8376 | WindowState win = mWindows.get(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8377 | |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 8378 | // Don't do layout of a window if it is not visible, or |
| 8379 | // soon won't be visible, to avoid wasting time and funky |
| 8380 | // changes while a window is animating away. |
| 8381 | final AppWindowToken atoken = win.mAppToken; |
| 8382 | final boolean gone = win.mViewVisibility == View.GONE |
| 8383 | || !win.mRelayoutCalled |
| 8384 | || win.mRootToken.hidden |
| 8385 | || (atoken != null && atoken.hiddenRequested) |
| 8386 | || win.mAttachedHidden |
| 8387 | || win.mExiting || win.mDestroying; |
| 8388 | |
| 8389 | if (!win.mLayoutAttached) { |
| 8390 | if (DEBUG_LAYOUT) Slog.v(TAG, "First pass " + win |
| 8391 | + ": gone=" + gone + " mHaveFrame=" + win.mHaveFrame |
| 8392 | + " mLayoutAttached=" + win.mLayoutAttached); |
| 8393 | if (DEBUG_LAYOUT && gone) Slog.v(TAG, " (mViewVisibility=" |
| 8394 | + win.mViewVisibility + " mRelayoutCalled=" |
| 8395 | + win.mRelayoutCalled + " hidden=" |
| 8396 | + win.mRootToken.hidden + " hiddenRequested=" |
| 8397 | + (atoken != null && atoken.hiddenRequested) |
| 8398 | + " mAttachedHidden=" + win.mAttachedHidden); |
| 8399 | } |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 8400 | |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 8401 | // If this view is GONE, then skip it -- keep the current |
| 8402 | // frame, and let the caller know so they can ignore it |
| 8403 | // if they want. (We do the normal layout for INVISIBLE |
| 8404 | // windows, since that means "perform layout as normal, |
| 8405 | // just don't display"). |
| 8406 | if (!gone || !win.mHaveFrame) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 8407 | if (!win.mLayoutAttached) { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 8408 | mPolicy.layoutWindowLw(win, win.mAttrs, null); |
| 8409 | win.mLayoutSeq = seq; |
| 8410 | if (DEBUG_LAYOUT) Slog.v(TAG, "-> mFrame=" |
| 8411 | + win.mFrame + " mContainingFrame=" |
| 8412 | + win.mContainingFrame + " mDisplayFrame=" |
| 8413 | + win.mDisplayFrame); |
| 8414 | } else { |
| 8415 | if (topAttached < 0) topAttached = i; |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 8416 | } |
Dianne Hackborn | 958b9ad | 2009-03-31 18:00:36 -0700 | [diff] [blame] | 8417 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8418 | } |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 8419 | |
| 8420 | // Now perform layout of attached windows, which usually |
| 8421 | // depend on the position of the window they are attached to. |
| 8422 | // XXX does not deal with windows that are attached to windows |
| 8423 | // that are themselves attached. |
| 8424 | for (i = topAttached; i >= 0; i--) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 8425 | WindowState win = mWindows.get(i); |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 8426 | |
| 8427 | // If this view is GONE, then skip it -- keep the current |
| 8428 | // frame, and let the caller know so they can ignore it |
| 8429 | // if they want. (We do the normal layout for INVISIBLE |
| 8430 | // windows, since that means "perform layout as normal, |
| 8431 | // just don't display"). |
| 8432 | if (win.mLayoutAttached) { |
| 8433 | if (DEBUG_LAYOUT) Slog.v(TAG, "Second pass " + win |
| 8434 | + " mHaveFrame=" + win.mHaveFrame |
| 8435 | + " mViewVisibility=" + win.mViewVisibility |
| 8436 | + " mRelayoutCalled=" + win.mRelayoutCalled); |
| 8437 | if ((win.mViewVisibility != View.GONE && win.mRelayoutCalled) |
| 8438 | || !win.mHaveFrame) { |
| 8439 | mPolicy.layoutWindowLw(win, win.mAttrs, win.mAttachedWindow); |
| 8440 | win.mLayoutSeq = seq; |
| 8441 | if (DEBUG_LAYOUT) Slog.v(TAG, "-> mFrame=" |
| 8442 | + win.mFrame + " mContainingFrame=" |
| 8443 | + win.mContainingFrame + " mDisplayFrame=" |
| 8444 | + win.mDisplayFrame); |
| 8445 | } |
| 8446 | } |
| 8447 | } |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 8448 | |
| 8449 | // Window frames may have changed. Tell the input dispatcher about it. |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 8450 | mInputMonitor.updateInputWindowsLw(); |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 8451 | |
| 8452 | return mPolicy.finishLayoutLw(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8453 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8454 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8455 | private final void performLayoutAndPlaceSurfacesLockedInner( |
| 8456 | boolean recoveringMemory) { |
Joe Onorato | 34bcebc | 2010-07-07 18:05:01 -0400 | [diff] [blame] | 8457 | if (mDisplay == null) { |
| 8458 | Slog.i(TAG, "skipping performLayoutAndPlaceSurfacesLockedInner with no mDisplay"); |
| 8459 | return; |
| 8460 | } |
| 8461 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8462 | final long currentTime = SystemClock.uptimeMillis(); |
| 8463 | final int dw = mDisplay.getWidth(); |
| 8464 | final int dh = mDisplay.getHeight(); |
| 8465 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8466 | int i; |
| 8467 | |
Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 8468 | if (mFocusMayChange) { |
| 8469 | mFocusMayChange = false; |
| 8470 | updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES); |
| 8471 | } |
| 8472 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8473 | if (mFxSession == null) { |
| 8474 | mFxSession = new SurfaceSession(); |
| 8475 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8476 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8477 | if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8478 | |
| 8479 | // Initialize state of exiting tokens. |
| 8480 | for (i=mExitingTokens.size()-1; i>=0; i--) { |
| 8481 | mExitingTokens.get(i).hasVisible = false; |
| 8482 | } |
| 8483 | |
| 8484 | // Initialize state of exiting applications. |
| 8485 | for (i=mExitingAppTokens.size()-1; i>=0; i--) { |
| 8486 | mExitingAppTokens.get(i).hasVisible = false; |
| 8487 | } |
| 8488 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8489 | boolean orientationChangeComplete = true; |
| 8490 | Session holdScreen = null; |
| 8491 | float screenBrightness = -1; |
Mike Lockwood | fb73f79 | 2009-11-20 11:31:18 -0500 | [diff] [blame] | 8492 | float buttonBrightness = -1; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8493 | boolean focusDisplayed = false; |
| 8494 | boolean animating = false; |
| 8495 | |
| 8496 | Surface.openTransaction(); |
| 8497 | try { |
Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 8498 | boolean wallpaperForceHidingChanged = false; |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 8499 | int repeats = 0; |
| 8500 | int changes = 0; |
| 8501 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8502 | do { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 8503 | repeats++; |
| 8504 | if (repeats > 6) { |
| 8505 | Slog.w(TAG, "Animation repeat aborted after too many iterations"); |
| 8506 | mLayoutNeeded = false; |
| 8507 | break; |
| 8508 | } |
| 8509 | |
| 8510 | if ((changes&(WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER |
| 8511 | | WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG |
| 8512 | | WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT)) != 0) { |
| 8513 | if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER) != 0) { |
| 8514 | if ((adjustWallpaperWindowsLocked()&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) { |
| 8515 | assignLayersLocked(); |
| 8516 | mLayoutNeeded = true; |
| 8517 | } |
| 8518 | } |
| 8519 | if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG) != 0) { |
| 8520 | if (DEBUG_LAYOUT) Slog.v(TAG, "Computing new config from layout"); |
| 8521 | if (updateOrientationFromAppTokensLocked()) { |
| 8522 | mLayoutNeeded = true; |
| 8523 | mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION); |
| 8524 | } |
| 8525 | } |
| 8526 | if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT) != 0) { |
| 8527 | mLayoutNeeded = true; |
| 8528 | } |
| 8529 | } |
| 8530 | |
| 8531 | // FIRST LOOP: Perform a layout, if needed. |
| 8532 | if (repeats < 4) { |
| 8533 | changes = performLayoutLockedInner(); |
| 8534 | if (changes != 0) { |
| 8535 | continue; |
| 8536 | } |
| 8537 | } else { |
| 8538 | Slog.w(TAG, "Layout repeat skipped after too many iterations"); |
| 8539 | changes = 0; |
| 8540 | } |
| 8541 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8542 | final int transactionSequence = ++mTransactionSequence; |
| 8543 | |
| 8544 | // Update animations of all applications, including those |
| 8545 | // associated with exiting/removed apps |
| 8546 | boolean tokensAnimating = false; |
| 8547 | final int NAT = mAppTokens.size(); |
| 8548 | for (i=0; i<NAT; i++) { |
| 8549 | if (mAppTokens.get(i).stepAnimationLocked(currentTime, dw, dh)) { |
| 8550 | tokensAnimating = true; |
| 8551 | } |
| 8552 | } |
| 8553 | final int NEAT = mExitingAppTokens.size(); |
| 8554 | for (i=0; i<NEAT; i++) { |
| 8555 | if (mExitingAppTokens.get(i).stepAnimationLocked(currentTime, dw, dh)) { |
| 8556 | tokensAnimating = true; |
| 8557 | } |
| 8558 | } |
| 8559 | |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 8560 | // SECOND LOOP: Execute animations and update visibility of windows. |
| 8561 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8562 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "*** ANIM STEP: seq=" |
Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 8563 | + transactionSequence + " tokensAnimating=" |
| 8564 | + tokensAnimating); |
| 8565 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8566 | animating = tokensAnimating; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8567 | |
| 8568 | boolean tokenMayBeDrawn = false; |
Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 8569 | boolean wallpaperMayChange = false; |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 8570 | boolean forceHiding = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8571 | |
| 8572 | mPolicy.beginAnimationLw(dw, dh); |
| 8573 | |
Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 8574 | final int N = mWindows.size(); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8575 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8576 | for (i=N-1; i>=0; i--) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 8577 | WindowState w = mWindows.get(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8578 | |
| 8579 | final WindowManager.LayoutParams attrs = w.mAttrs; |
| 8580 | |
| 8581 | if (w.mSurface != null) { |
| 8582 | // Execute animation. |
Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 8583 | if (w.commitFinishDrawingLocked(currentTime)) { |
| 8584 | if ((w.mAttrs.flags |
| 8585 | & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER) != 0) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8586 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 8587 | "First draw done in potential wallpaper target " + w); |
Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 8588 | wallpaperMayChange = true; |
| 8589 | } |
| 8590 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8591 | |
Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 8592 | boolean wasAnimating = w.mAnimating; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8593 | if (w.stepAnimationLocked(currentTime, dw, dh)) { |
| 8594 | animating = true; |
| 8595 | //w.dump(" "); |
| 8596 | } |
Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 8597 | if (wasAnimating && !w.mAnimating && mWallpaperTarget == w) { |
| 8598 | wallpaperMayChange = true; |
| 8599 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8600 | |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8601 | if (mPolicy.doesForceHide(w, attrs)) { |
| 8602 | if (!wasAnimating && animating) { |
Dianne Hackborn | 20cb56e | 2010-03-04 00:58:29 -0800 | [diff] [blame] | 8603 | if (DEBUG_VISIBILITY) Slog.v(TAG, |
| 8604 | "Animation done that could impact force hide: " |
| 8605 | + w); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8606 | wallpaperForceHidingChanged = true; |
Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 8607 | mFocusMayChange = true; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8608 | } else if (w.isReadyForDisplay() && w.mAnimation == null) { |
| 8609 | forceHiding = true; |
| 8610 | } |
| 8611 | } else if (mPolicy.canBeForceHidden(w, attrs)) { |
| 8612 | boolean changed; |
| 8613 | if (forceHiding) { |
| 8614 | changed = w.hideLw(false, false); |
Dianne Hackborn | 20cb56e | 2010-03-04 00:58:29 -0800 | [diff] [blame] | 8615 | if (DEBUG_VISIBILITY && changed) Slog.v(TAG, |
| 8616 | "Now policy hidden: " + w); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8617 | } else { |
| 8618 | changed = w.showLw(false, false); |
Dianne Hackborn | 20cb56e | 2010-03-04 00:58:29 -0800 | [diff] [blame] | 8619 | if (DEBUG_VISIBILITY && changed) Slog.v(TAG, |
| 8620 | "Now policy shown: " + w); |
| 8621 | if (changed) { |
| 8622 | if (wallpaperForceHidingChanged |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 8623 | && w.isVisibleNow() /*w.isReadyForDisplay()*/) { |
Dianne Hackborn | 20cb56e | 2010-03-04 00:58:29 -0800 | [diff] [blame] | 8624 | // Assume we will need to animate. If |
| 8625 | // we don't (because the wallpaper will |
| 8626 | // stay with the lock screen), then we will |
| 8627 | // clean up later. |
| 8628 | Animation a = mPolicy.createForceHideEnterAnimation(); |
| 8629 | if (a != null) { |
| 8630 | w.setAnimation(a); |
| 8631 | } |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8632 | } |
Dianne Hackborn | 20cb56e | 2010-03-04 00:58:29 -0800 | [diff] [blame] | 8633 | if (mCurrentFocus == null || |
| 8634 | mCurrentFocus.mLayer < w.mLayer) { |
| 8635 | // We are showing on to of the current |
| 8636 | // focus, so re-evaluate focus to make |
| 8637 | // sure it is correct. |
| 8638 | mFocusMayChange = true; |
| 8639 | } |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8640 | } |
| 8641 | } |
| 8642 | if (changed && (attrs.flags |
| 8643 | & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER) != 0) { |
| 8644 | wallpaperMayChange = true; |
| 8645 | } |
| 8646 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8647 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8648 | mPolicy.animatingWindowLw(w, attrs); |
| 8649 | } |
| 8650 | |
| 8651 | final AppWindowToken atoken = w.mAppToken; |
| 8652 | if (atoken != null && (!atoken.allDrawn || atoken.freezingScreen)) { |
| 8653 | if (atoken.lastTransactionSequence != transactionSequence) { |
| 8654 | atoken.lastTransactionSequence = transactionSequence; |
| 8655 | atoken.numInterestingWindows = atoken.numDrawnWindows = 0; |
| 8656 | atoken.startingDisplayed = false; |
| 8657 | } |
| 8658 | if ((w.isOnScreen() || w.mAttrs.type |
| 8659 | == WindowManager.LayoutParams.TYPE_BASE_APPLICATION) |
| 8660 | && !w.mExiting && !w.mDestroying) { |
| 8661 | if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8662 | Slog.v(TAG, "Eval win " + w + ": isDrawn=" |
Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 8663 | + w.isDrawnLw() |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8664 | + ", isAnimating=" + w.isAnimating()); |
Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 8665 | if (!w.isDrawnLw()) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8666 | Slog.v(TAG, "Not displayed: s=" + w.mSurface |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8667 | + " pv=" + w.mPolicyVisibility |
| 8668 | + " dp=" + w.mDrawPending |
| 8669 | + " cdp=" + w.mCommitDrawPending |
| 8670 | + " ah=" + w.mAttachedHidden |
| 8671 | + " th=" + atoken.hiddenRequested |
| 8672 | + " a=" + w.mAnimating); |
| 8673 | } |
| 8674 | } |
| 8675 | if (w != atoken.startingWindow) { |
| 8676 | if (!atoken.freezingScreen || !w.mAppFreezing) { |
| 8677 | atoken.numInterestingWindows++; |
Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 8678 | if (w.isDrawnLw()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8679 | atoken.numDrawnWindows++; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8680 | if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8681 | "tokenMayBeDrawn: " + atoken |
| 8682 | + " freezingScreen=" + atoken.freezingScreen |
| 8683 | + " mAppFreezing=" + w.mAppFreezing); |
| 8684 | tokenMayBeDrawn = true; |
| 8685 | } |
| 8686 | } |
Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 8687 | } else if (w.isDrawnLw()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8688 | atoken.startingDisplayed = true; |
| 8689 | } |
| 8690 | } |
| 8691 | } else if (w.mReadyToShow) { |
| 8692 | w.performShowLocked(); |
| 8693 | } |
| 8694 | } |
| 8695 | |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 8696 | changes |= mPolicy.finishAnimationLw(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8697 | |
| 8698 | if (tokenMayBeDrawn) { |
| 8699 | // See if any windows have been drawn, so they (and others |
| 8700 | // associated with them) can now be shown. |
| 8701 | final int NT = mTokenList.size(); |
| 8702 | for (i=0; i<NT; i++) { |
| 8703 | AppWindowToken wtoken = mTokenList.get(i).appWindowToken; |
| 8704 | if (wtoken == null) { |
| 8705 | continue; |
| 8706 | } |
| 8707 | if (wtoken.freezingScreen) { |
| 8708 | int numInteresting = wtoken.numInterestingWindows; |
| 8709 | if (numInteresting > 0 && wtoken.numDrawnWindows >= numInteresting) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8710 | if (DEBUG_VISIBILITY) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8711 | "allDrawn: " + wtoken |
| 8712 | + " interesting=" + numInteresting |
| 8713 | + " drawn=" + wtoken.numDrawnWindows); |
| 8714 | wtoken.showAllWindowsLocked(); |
| 8715 | unsetAppFreezingScreenLocked(wtoken, false, true); |
| 8716 | orientationChangeComplete = true; |
| 8717 | } |
| 8718 | } else if (!wtoken.allDrawn) { |
| 8719 | int numInteresting = wtoken.numInterestingWindows; |
| 8720 | if (numInteresting > 0 && wtoken.numDrawnWindows >= numInteresting) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8721 | if (DEBUG_VISIBILITY) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8722 | "allDrawn: " + wtoken |
| 8723 | + " interesting=" + numInteresting |
| 8724 | + " drawn=" + wtoken.numDrawnWindows); |
| 8725 | wtoken.allDrawn = true; |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 8726 | changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8727 | |
| 8728 | // We can now show all of the drawn windows! |
| 8729 | if (!mOpeningApps.contains(wtoken)) { |
| 8730 | wtoken.showAllWindowsLocked(); |
| 8731 | } |
| 8732 | } |
| 8733 | } |
| 8734 | } |
| 8735 | } |
| 8736 | |
| 8737 | // If we are ready to perform an app transition, check through |
| 8738 | // all of the app tokens to be shown and see if they are ready |
| 8739 | // to go. |
| 8740 | if (mAppTransitionReady) { |
| 8741 | int NN = mOpeningApps.size(); |
| 8742 | boolean goodToGo = true; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8743 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8744 | "Checking " + NN + " opening apps (frozen=" |
| 8745 | + mDisplayFrozen + " timeout=" |
| 8746 | + mAppTransitionTimeout + ")..."); |
| 8747 | if (!mDisplayFrozen && !mAppTransitionTimeout) { |
| 8748 | // If the display isn't frozen, wait to do anything until |
| 8749 | // all of the apps are ready. Otherwise just go because |
| 8750 | // we'll unfreeze the display when everyone is ready. |
| 8751 | for (i=0; i<NN && goodToGo; i++) { |
| 8752 | AppWindowToken wtoken = mOpeningApps.get(i); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8753 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8754 | "Check opening app" + wtoken + ": allDrawn=" |
| 8755 | + wtoken.allDrawn + " startingDisplayed=" |
| 8756 | + wtoken.startingDisplayed); |
| 8757 | if (!wtoken.allDrawn && !wtoken.startingDisplayed |
| 8758 | && !wtoken.startingMoved) { |
| 8759 | goodToGo = false; |
| 8760 | } |
| 8761 | } |
| 8762 | } |
| 8763 | if (goodToGo) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8764 | 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] | 8765 | int transit = mNextAppTransition; |
| 8766 | if (mSkipAppTransitionAnimation) { |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 8767 | transit = WindowManagerPolicy.TRANSIT_UNSET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8768 | } |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 8769 | mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8770 | mAppTransitionReady = false; |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8771 | mAppTransitionRunning = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8772 | mAppTransitionTimeout = false; |
| 8773 | mStartingIconInTransition = false; |
| 8774 | mSkipAppTransitionAnimation = false; |
| 8775 | |
| 8776 | mH.removeMessages(H.APP_TRANSITION_TIMEOUT); |
| 8777 | |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8778 | // If there are applications waiting to come to the |
| 8779 | // top of the stack, now is the time to move their windows. |
| 8780 | // (Note that we don't do apps going to the bottom |
| 8781 | // here -- we want to keep their windows in the old |
| 8782 | // Z-order until the animation completes.) |
| 8783 | if (mToTopApps.size() > 0) { |
| 8784 | NN = mAppTokens.size(); |
| 8785 | for (i=0; i<NN; i++) { |
| 8786 | AppWindowToken wtoken = mAppTokens.get(i); |
| 8787 | if (wtoken.sendingToTop) { |
| 8788 | wtoken.sendingToTop = false; |
| 8789 | moveAppWindowsLocked(wtoken, NN, false); |
| 8790 | } |
| 8791 | } |
| 8792 | mToTopApps.clear(); |
| 8793 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8794 | |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 8795 | WindowState oldWallpaper = mWallpaperTarget; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8796 | |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 8797 | adjustWallpaperWindowsLocked(); |
Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 8798 | wallpaperMayChange = false; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8799 | |
Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 8800 | // The top-most window will supply the layout params, |
| 8801 | // and we will determine it below. |
| 8802 | LayoutParams animLp = null; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8803 | AppWindowToken animToken = null; |
Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 8804 | int bestAnimLayer = -1; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8805 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8806 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 8807 | "New wallpaper target=" + mWallpaperTarget |
| 8808 | + ", lower target=" + mLowerWallpaperTarget |
| 8809 | + ", upper target=" + mUpperWallpaperTarget); |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 8810 | int foundWallpapers = 0; |
Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 8811 | // Do a first pass through the tokens for two |
| 8812 | // things: |
| 8813 | // (1) Determine if both the closing and opening |
| 8814 | // app token sets are wallpaper targets, in which |
| 8815 | // case special animations are needed |
| 8816 | // (since the wallpaper needs to stay static |
| 8817 | // behind them). |
| 8818 | // (2) Find the layout params of the top-most |
| 8819 | // application window in the tokens, which is |
| 8820 | // what will control the animation theme. |
| 8821 | final int NC = mClosingApps.size(); |
| 8822 | NN = NC + mOpeningApps.size(); |
| 8823 | for (i=0; i<NN; i++) { |
| 8824 | AppWindowToken wtoken; |
| 8825 | int mode; |
| 8826 | if (i < NC) { |
| 8827 | wtoken = mClosingApps.get(i); |
| 8828 | mode = 1; |
| 8829 | } else { |
| 8830 | wtoken = mOpeningApps.get(i-NC); |
| 8831 | mode = 2; |
| 8832 | } |
| 8833 | if (mLowerWallpaperTarget != null) { |
| 8834 | if (mLowerWallpaperTarget.mAppToken == wtoken |
| 8835 | || mUpperWallpaperTarget.mAppToken == wtoken) { |
| 8836 | foundWallpapers |= mode; |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 8837 | } |
| 8838 | } |
Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 8839 | if (wtoken.appFullscreen) { |
| 8840 | WindowState ws = wtoken.findMainWindow(); |
| 8841 | if (ws != null) { |
| 8842 | // If this is a compatibility mode |
| 8843 | // window, we will always use its anim. |
| 8844 | if ((ws.mAttrs.flags&FLAG_COMPATIBLE_WINDOW) != 0) { |
| 8845 | animLp = ws.mAttrs; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8846 | animToken = ws.mAppToken; |
Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 8847 | bestAnimLayer = Integer.MAX_VALUE; |
| 8848 | } else if (ws.mLayer > bestAnimLayer) { |
| 8849 | animLp = ws.mAttrs; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8850 | animToken = ws.mAppToken; |
Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 8851 | bestAnimLayer = ws.mLayer; |
| 8852 | } |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 8853 | } |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 8854 | } |
| 8855 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8856 | |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 8857 | if (foundWallpapers == 3) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8858 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 8859 | "Wallpaper animation!"); |
| 8860 | switch (transit) { |
| 8861 | case WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN: |
| 8862 | case WindowManagerPolicy.TRANSIT_TASK_OPEN: |
| 8863 | case WindowManagerPolicy.TRANSIT_TASK_TO_FRONT: |
| 8864 | transit = WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_OPEN; |
| 8865 | break; |
| 8866 | case WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE: |
| 8867 | case WindowManagerPolicy.TRANSIT_TASK_CLOSE: |
| 8868 | case WindowManagerPolicy.TRANSIT_TASK_TO_BACK: |
| 8869 | transit = WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_CLOSE; |
| 8870 | break; |
| 8871 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8872 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 8873 | "New transit: " + transit); |
| 8874 | } else if (oldWallpaper != null) { |
| 8875 | // We are transitioning from an activity with |
| 8876 | // a wallpaper to one without. |
| 8877 | transit = WindowManagerPolicy.TRANSIT_WALLPAPER_CLOSE; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8878 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 8879 | "New transit away from wallpaper: " + transit); |
| 8880 | } else if (mWallpaperTarget != null) { |
| 8881 | // We are transitioning from an activity without |
| 8882 | // a wallpaper to now showing the wallpaper |
| 8883 | transit = WindowManagerPolicy.TRANSIT_WALLPAPER_OPEN; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8884 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 8885 | "New transit into wallpaper: " + transit); |
| 8886 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8887 | |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8888 | if ((transit&WindowManagerPolicy.TRANSIT_ENTER_MASK) != 0) { |
| 8889 | mLastEnterAnimToken = animToken; |
| 8890 | mLastEnterAnimParams = animLp; |
| 8891 | } else if (mLastEnterAnimParams != null) { |
| 8892 | animLp = mLastEnterAnimParams; |
| 8893 | mLastEnterAnimToken = null; |
| 8894 | mLastEnterAnimParams = null; |
| 8895 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8896 | |
Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 8897 | // If all closing windows are obscured, then there is |
| 8898 | // no need to do an animation. This is the case, for |
| 8899 | // example, when this transition is being done behind |
| 8900 | // the lock screen. |
| 8901 | if (!mPolicy.allowAppAnimationsLw()) { |
| 8902 | animLp = null; |
| 8903 | } |
| 8904 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8905 | NN = mOpeningApps.size(); |
| 8906 | for (i=0; i<NN; i++) { |
| 8907 | AppWindowToken wtoken = mOpeningApps.get(i); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8908 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8909 | "Now opening app" + wtoken); |
| 8910 | wtoken.reportedVisible = false; |
| 8911 | wtoken.inPendingTransaction = false; |
Dianne Hackborn | 83360b3 | 2009-08-24 18:43:32 -0700 | [diff] [blame] | 8912 | wtoken.animation = null; |
Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 8913 | setTokenVisibilityLocked(wtoken, animLp, true, transit, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8914 | wtoken.updateReportedVisibilityLocked(); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8915 | wtoken.waitingToShow = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8916 | wtoken.showAllWindowsLocked(); |
| 8917 | } |
| 8918 | NN = mClosingApps.size(); |
| 8919 | for (i=0; i<NN; i++) { |
| 8920 | AppWindowToken wtoken = mClosingApps.get(i); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8921 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8922 | "Now closing app" + wtoken); |
| 8923 | wtoken.inPendingTransaction = false; |
Dianne Hackborn | 83360b3 | 2009-08-24 18:43:32 -0700 | [diff] [blame] | 8924 | wtoken.animation = null; |
Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 8925 | setTokenVisibilityLocked(wtoken, animLp, false, transit, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8926 | wtoken.updateReportedVisibilityLocked(); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8927 | wtoken.waitingToHide = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8928 | // Force the allDrawn flag, because we want to start |
| 8929 | // this guy's animations regardless of whether it's |
| 8930 | // gotten drawn. |
| 8931 | wtoken.allDrawn = true; |
| 8932 | } |
| 8933 | |
Dianne Hackborn | 8b571a8 | 2009-09-25 16:09:43 -0700 | [diff] [blame] | 8934 | mNextAppTransitionPackage = null; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8935 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8936 | mOpeningApps.clear(); |
| 8937 | mClosingApps.clear(); |
| 8938 | |
| 8939 | // This has changed the visibility of windows, so perform |
| 8940 | // a new layout to get them all up-to-date. |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 8941 | changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8942 | mLayoutNeeded = true; |
Dianne Hackborn | 20583ff | 2009-07-27 21:51:05 -0700 | [diff] [blame] | 8943 | if (!moveInputMethodWindowsIfNeededLocked(true)) { |
| 8944 | assignLayersLocked(); |
| 8945 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8946 | updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES); |
Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 8947 | mFocusMayChange = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8948 | } |
| 8949 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8950 | |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 8951 | int adjResult = 0; |
| 8952 | |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8953 | if (!animating && mAppTransitionRunning) { |
| 8954 | // We have finished the animation of an app transition. To do |
| 8955 | // this, we have delayed a lot of operations like showing and |
| 8956 | // hiding apps, moving apps in Z-order, etc. The app token list |
| 8957 | // reflects the correct Z-order, but the window list may now |
| 8958 | // be out of sync with it. So here we will just rebuild the |
| 8959 | // entire app window list. Fun! |
| 8960 | mAppTransitionRunning = false; |
| 8961 | // Clear information about apps that were moving. |
| 8962 | mToBottomApps.clear(); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8963 | |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8964 | rebuildAppWindowListLocked(); |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 8965 | changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT; |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 8966 | adjResult |= ADJUST_WALLPAPER_LAYERS_CHANGED; |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8967 | moveInputMethodWindowsIfNeededLocked(false); |
| 8968 | wallpaperMayChange = true; |
Suchi Amalapurapu | c9568e3 | 2009-11-05 18:51:16 -0800 | [diff] [blame] | 8969 | // Since the window list has been rebuilt, focus might |
| 8970 | // have to be recomputed since the actual order of windows |
| 8971 | // might have changed again. |
Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 8972 | mFocusMayChange = true; |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8973 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8974 | |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 8975 | if (wallpaperForceHidingChanged && changes == 0 && !mAppTransitionReady) { |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8976 | // At this point, there was a window with a wallpaper that |
| 8977 | // was force hiding other windows behind it, but now it |
| 8978 | // is going away. This may be simple -- just animate |
| 8979 | // away the wallpaper and its window -- or it may be |
| 8980 | // hard -- the wallpaper now needs to be shown behind |
| 8981 | // something that was hidden. |
| 8982 | WindowState oldWallpaper = mWallpaperTarget; |
Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 8983 | if (mLowerWallpaperTarget != null |
| 8984 | && mLowerWallpaperTarget.mAppToken != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8985 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 8986 | "wallpaperForceHiding changed with lower=" |
| 8987 | + mLowerWallpaperTarget); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8988 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 8989 | "hidden=" + mLowerWallpaperTarget.mAppToken.hidden + |
| 8990 | " hiddenRequested=" + mLowerWallpaperTarget.mAppToken.hiddenRequested); |
| 8991 | if (mLowerWallpaperTarget.mAppToken.hidden) { |
| 8992 | // The lower target has become hidden before we |
| 8993 | // actually started the animation... let's completely |
| 8994 | // re-evaluate everything. |
| 8995 | mLowerWallpaperTarget = mUpperWallpaperTarget = null; |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 8996 | changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM; |
Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 8997 | } |
| 8998 | } |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 8999 | adjResult |= adjustWallpaperWindowsLocked(); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9000 | wallpaperMayChange = false; |
Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 9001 | wallpaperForceHidingChanged = false; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9002 | if (DEBUG_WALLPAPER) Slog.v(TAG, "****** OLD: " + oldWallpaper |
Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 9003 | + " NEW: " + mWallpaperTarget |
| 9004 | + " LOWER: " + mLowerWallpaperTarget); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9005 | if (mLowerWallpaperTarget == null) { |
| 9006 | // Whoops, we don't need a special wallpaper animation. |
| 9007 | // Clear them out. |
| 9008 | forceHiding = false; |
| 9009 | for (i=N-1; i>=0; i--) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 9010 | WindowState w = mWindows.get(i); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9011 | if (w.mSurface != null) { |
| 9012 | final WindowManager.LayoutParams attrs = w.mAttrs; |
Suchi Amalapurapu | c03d28b | 2009-10-28 14:32:05 -0700 | [diff] [blame] | 9013 | if (mPolicy.doesForceHide(w, attrs) && w.isVisibleLw()) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9014 | if (DEBUG_FOCUS) Slog.i(TAG, "win=" + w + " force hides other windows"); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9015 | forceHiding = true; |
| 9016 | } else if (mPolicy.canBeForceHidden(w, attrs)) { |
| 9017 | if (!w.mAnimating) { |
| 9018 | // We set the animation above so it |
| 9019 | // is not yet running. |
| 9020 | w.clearAnimation(); |
| 9021 | } |
| 9022 | } |
| 9023 | } |
| 9024 | } |
| 9025 | } |
| 9026 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9027 | |
Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 9028 | if (wallpaperMayChange) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9029 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 9030 | "Wallpaper may change! Adjusting"); |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 9031 | adjResult |= adjustWallpaperWindowsLocked(); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9032 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9033 | |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9034 | if ((adjResult&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9035 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9036 | "Wallpaper layer changed: assigning layers + relayout"); |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9037 | changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9038 | assignLayersLocked(); |
| 9039 | } else if ((adjResult&ADJUST_WALLPAPER_VISIBILITY_CHANGED) != 0) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9040 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9041 | "Wallpaper visibility changed: relayout"); |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9042 | changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9043 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9044 | |
Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 9045 | if (mFocusMayChange) { |
| 9046 | mFocusMayChange = false; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9047 | if (updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES)) { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9048 | changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9049 | adjResult = 0; |
Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 9050 | } |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9051 | } |
| 9052 | |
| 9053 | if (mLayoutNeeded) { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9054 | changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT; |
Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 9055 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9056 | |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9057 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "*** ANIM STEP: changes=0x" |
| 9058 | + Integer.toHexString(changes)); |
Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 9059 | |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 9060 | mInputMonitor.updateInputWindowsLw(); |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9061 | } while (changes != 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9062 | |
| 9063 | // THIRD LOOP: Update the surfaces of all windows. |
| 9064 | |
| 9065 | final boolean someoneLosingFocus = mLosingFocus.size() != 0; |
| 9066 | |
| 9067 | boolean obscured = false; |
| 9068 | boolean blurring = false; |
| 9069 | boolean dimming = false; |
| 9070 | boolean covered = false; |
Dianne Hackborn | 9ed4a4b | 2009-03-25 17:10:37 -0700 | [diff] [blame] | 9071 | boolean syswin = false; |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 9072 | boolean backgroundFillerShown = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9073 | |
Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 9074 | final int N = mWindows.size(); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9075 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9076 | for (i=N-1; i>=0; i--) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 9077 | WindowState w = mWindows.get(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9078 | |
| 9079 | boolean displayed = false; |
| 9080 | final WindowManager.LayoutParams attrs = w.mAttrs; |
| 9081 | final int attrFlags = attrs.flags; |
| 9082 | |
| 9083 | if (w.mSurface != null) { |
Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 9084 | // XXX NOTE: The logic here could be improved. We have |
| 9085 | // the decision about whether to resize a window separated |
| 9086 | // from whether to hide the surface. This can cause us to |
| 9087 | // resize a surface even if we are going to hide it. You |
| 9088 | // can see this by (1) holding device in landscape mode on |
| 9089 | // home screen; (2) tapping browser icon (device will rotate |
| 9090 | // to landscape; (3) tap home. The wallpaper will be resized |
| 9091 | // in step 2 but then immediately hidden, causing us to |
| 9092 | // have to resize and then redraw it again in step 3. It |
| 9093 | // would be nice to figure out how to avoid this, but it is |
| 9094 | // difficult because we do need to resize surfaces in some |
| 9095 | // cases while they are hidden such as when first showing a |
| 9096 | // window. |
| 9097 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9098 | w.computeShownFrameLocked(); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9099 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9100 | TAG, "Placing surface #" + i + " " + w.mSurface |
| 9101 | + ": new=" + w.mShownFrame + ", old=" |
| 9102 | + w.mLastShownFrame); |
| 9103 | |
| 9104 | boolean resize; |
| 9105 | int width, height; |
| 9106 | if ((w.mAttrs.flags & w.mAttrs.FLAG_SCALED) != 0) { |
| 9107 | resize = w.mLastRequestedWidth != w.mRequestedWidth || |
| 9108 | w.mLastRequestedHeight != w.mRequestedHeight; |
| 9109 | // for a scaled surface, we just want to use |
| 9110 | // the requested size. |
| 9111 | width = w.mRequestedWidth; |
| 9112 | height = w.mRequestedHeight; |
| 9113 | w.mLastRequestedWidth = width; |
| 9114 | w.mLastRequestedHeight = height; |
| 9115 | w.mLastShownFrame.set(w.mShownFrame); |
| 9116 | try { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9117 | if (SHOW_TRANSACTIONS) logSurface(w, |
| 9118 | "POS " + w.mShownFrame.left |
| 9119 | + ", " + w.mShownFrame.top, null); |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 9120 | w.mSurfaceX = w.mShownFrame.left; |
| 9121 | w.mSurfaceY = w.mShownFrame.top; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9122 | w.mSurface.setPosition(w.mShownFrame.left, w.mShownFrame.top); |
| 9123 | } catch (RuntimeException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9124 | Slog.w(TAG, "Error positioning surface in " + w, e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9125 | if (!recoveringMemory) { |
| 9126 | reclaimSomeSurfaceMemoryLocked(w, "position"); |
| 9127 | } |
| 9128 | } |
| 9129 | } else { |
| 9130 | resize = !w.mLastShownFrame.equals(w.mShownFrame); |
| 9131 | width = w.mShownFrame.width(); |
| 9132 | height = w.mShownFrame.height(); |
| 9133 | w.mLastShownFrame.set(w.mShownFrame); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9134 | } |
| 9135 | |
| 9136 | if (resize) { |
| 9137 | if (width < 1) width = 1; |
| 9138 | if (height < 1) height = 1; |
| 9139 | if (w.mSurface != null) { |
| 9140 | try { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9141 | if (SHOW_TRANSACTIONS) logSurface(w, |
| 9142 | "POS " + w.mShownFrame.left + "," |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 9143 | + w.mShownFrame.top + " SIZE " |
| 9144 | + w.mShownFrame.width() + "x" |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9145 | + w.mShownFrame.height(), null); |
Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 9146 | w.mSurfaceResized = true; |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 9147 | w.mSurfaceW = width; |
| 9148 | w.mSurfaceH = height; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9149 | w.mSurface.setSize(width, height); |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 9150 | w.mSurfaceX = w.mShownFrame.left; |
| 9151 | w.mSurfaceY = w.mShownFrame.top; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9152 | w.mSurface.setPosition(w.mShownFrame.left, |
| 9153 | w.mShownFrame.top); |
| 9154 | } catch (RuntimeException e) { |
| 9155 | // If something goes wrong with the surface (such |
| 9156 | // as running out of memory), don't take down the |
| 9157 | // entire system. |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9158 | Slog.e(TAG, "Failure updating surface of " + w |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9159 | + "size=(" + width + "x" + height |
| 9160 | + "), pos=(" + w.mShownFrame.left |
| 9161 | + "," + w.mShownFrame.top + ")", e); |
| 9162 | if (!recoveringMemory) { |
| 9163 | reclaimSomeSurfaceMemoryLocked(w, "size"); |
| 9164 | } |
| 9165 | } |
| 9166 | } |
| 9167 | } |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 9168 | if (!w.mAppFreezing && w.mLayoutSeq == mLayoutSeq) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9169 | w.mContentInsetsChanged = |
| 9170 | !w.mLastContentInsets.equals(w.mContentInsets); |
| 9171 | w.mVisibleInsetsChanged = |
| 9172 | !w.mLastVisibleInsets.equals(w.mVisibleInsets); |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 9173 | boolean configChanged = |
| 9174 | w.mConfiguration != mCurConfiguration |
| 9175 | && (w.mConfiguration == null |
| 9176 | || mCurConfiguration.diff(w.mConfiguration) != 0); |
Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 9177 | if (DEBUG_CONFIGURATION && configChanged) { |
| 9178 | Slog.v(TAG, "Win " + w + " config changed: " |
| 9179 | + mCurConfiguration); |
| 9180 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9181 | if (localLOGV) Slog.v(TAG, "Resizing " + w |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 9182 | + ": configChanged=" + configChanged |
| 9183 | + " last=" + w.mLastFrame + " frame=" + w.mFrame); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9184 | if (!w.mLastFrame.equals(w.mFrame) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9185 | || w.mContentInsetsChanged |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 9186 | || w.mVisibleInsetsChanged |
Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 9187 | || w.mSurfaceResized |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 9188 | || configChanged) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9189 | w.mLastFrame.set(w.mFrame); |
| 9190 | w.mLastContentInsets.set(w.mContentInsets); |
| 9191 | w.mLastVisibleInsets.set(w.mVisibleInsets); |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 9192 | // If the screen is currently frozen, then keep |
| 9193 | // it frozen until this window draws at its new |
| 9194 | // orientation. |
| 9195 | if (mDisplayFrozen) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9196 | if (DEBUG_ORIENTATION) Slog.v(TAG, |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 9197 | "Resizing while display frozen: " + w); |
| 9198 | w.mOrientationChanging = true; |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 9199 | if (!mWindowsFreezingScreen) { |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 9200 | mWindowsFreezingScreen = true; |
| 9201 | // XXX should probably keep timeout from |
| 9202 | // when we first froze the display. |
| 9203 | mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT); |
| 9204 | mH.sendMessageDelayed(mH.obtainMessage( |
| 9205 | H.WINDOW_FREEZE_TIMEOUT), 2000); |
| 9206 | } |
| 9207 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9208 | // If the orientation is changing, then we need to |
| 9209 | // hold off on unfreezing the display until this |
| 9210 | // window has been redrawn; to do that, we need |
| 9211 | // to go through the process of getting informed |
| 9212 | // by the application when it has finished drawing. |
| 9213 | if (w.mOrientationChanging) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9214 | if (DEBUG_ORIENTATION) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9215 | "Orientation start waiting for draw in " |
| 9216 | + w + ", surface " + w.mSurface); |
| 9217 | w.mDrawPending = true; |
| 9218 | w.mCommitDrawPending = false; |
| 9219 | w.mReadyToShow = false; |
| 9220 | if (w.mAppToken != null) { |
| 9221 | w.mAppToken.allDrawn = false; |
| 9222 | } |
| 9223 | } |
Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 9224 | if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9225 | "Resizing window " + w + " to " + w.mFrame); |
| 9226 | mResizingWindows.add(w); |
| 9227 | } else if (w.mOrientationChanging) { |
| 9228 | if (!w.mDrawPending && !w.mCommitDrawPending) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9229 | if (DEBUG_ORIENTATION) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9230 | "Orientation not waiting for draw in " |
| 9231 | + w + ", surface " + w.mSurface); |
| 9232 | w.mOrientationChanging = false; |
| 9233 | } |
| 9234 | } |
| 9235 | } |
| 9236 | |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9237 | if (w.mAttachedHidden || !w.isReadyForDisplay()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9238 | if (!w.mLastHidden) { |
| 9239 | //dump(); |
| 9240 | w.mLastHidden = true; |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9241 | if (SHOW_TRANSACTIONS) logSurface(w, |
| 9242 | "HIDE (performLayout)", null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9243 | if (w.mSurface != null) { |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 9244 | w.mSurfaceShown = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9245 | try { |
| 9246 | w.mSurface.hide(); |
| 9247 | } catch (RuntimeException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9248 | Slog.w(TAG, "Exception hiding surface in " + w); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9249 | } |
| 9250 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9251 | } |
| 9252 | // If we are waiting for this window to handle an |
| 9253 | // orientation change, well, it is hidden, so |
| 9254 | // doesn't really matter. Note that this does |
| 9255 | // introduce a potential glitch if the window |
| 9256 | // becomes unhidden before it has drawn for the |
| 9257 | // new orientation. |
| 9258 | if (w.mOrientationChanging) { |
| 9259 | w.mOrientationChanging = false; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9260 | if (DEBUG_ORIENTATION) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9261 | "Orientation change skips hidden " + w); |
| 9262 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9263 | } else if (w.mLastLayer != w.mAnimLayer |
| 9264 | || w.mLastAlpha != w.mShownAlpha |
| 9265 | || w.mLastDsDx != w.mDsDx |
| 9266 | || w.mLastDtDx != w.mDtDx |
| 9267 | || w.mLastDsDy != w.mDsDy |
| 9268 | || w.mLastDtDy != w.mDtDy |
| 9269 | || w.mLastHScale != w.mHScale |
| 9270 | || w.mLastVScale != w.mVScale |
| 9271 | || w.mLastHidden) { |
| 9272 | displayed = true; |
| 9273 | w.mLastAlpha = w.mShownAlpha; |
| 9274 | w.mLastLayer = w.mAnimLayer; |
| 9275 | w.mLastDsDx = w.mDsDx; |
| 9276 | w.mLastDtDx = w.mDtDx; |
| 9277 | w.mLastDsDy = w.mDsDy; |
| 9278 | w.mLastDtDy = w.mDtDy; |
| 9279 | w.mLastHScale = w.mHScale; |
| 9280 | w.mLastVScale = w.mVScale; |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9281 | if (SHOW_TRANSACTIONS) logSurface(w, |
| 9282 | "alpha=" + w.mShownAlpha + " layer=" + w.mAnimLayer |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 9283 | + " matrix=[" + (w.mDsDx*w.mHScale) |
| 9284 | + "," + (w.mDtDx*w.mVScale) |
| 9285 | + "][" + (w.mDsDy*w.mHScale) |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9286 | + "," + (w.mDtDy*w.mVScale) + "]", null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9287 | if (w.mSurface != null) { |
| 9288 | try { |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 9289 | w.mSurfaceAlpha = w.mShownAlpha; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9290 | w.mSurface.setAlpha(w.mShownAlpha); |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 9291 | w.mSurfaceLayer = w.mAnimLayer; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9292 | w.mSurface.setLayer(w.mAnimLayer); |
| 9293 | w.mSurface.setMatrix( |
| 9294 | w.mDsDx*w.mHScale, w.mDtDx*w.mVScale, |
| 9295 | w.mDsDy*w.mHScale, w.mDtDy*w.mVScale); |
| 9296 | } catch (RuntimeException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9297 | Slog.w(TAG, "Error updating surface in " + w, e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9298 | if (!recoveringMemory) { |
| 9299 | reclaimSomeSurfaceMemoryLocked(w, "update"); |
| 9300 | } |
| 9301 | } |
| 9302 | } |
| 9303 | |
| 9304 | if (w.mLastHidden && !w.mDrawPending |
| 9305 | && !w.mCommitDrawPending |
| 9306 | && !w.mReadyToShow) { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9307 | if (SHOW_TRANSACTIONS) logSurface(w, |
| 9308 | "SHOW (performLayout)", null); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9309 | if (DEBUG_VISIBILITY) Slog.v(TAG, "Showing " + w |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9310 | + " during relayout"); |
| 9311 | if (showSurfaceRobustlyLocked(w)) { |
| 9312 | w.mHasDrawn = true; |
| 9313 | w.mLastHidden = false; |
| 9314 | } else { |
| 9315 | w.mOrientationChanging = false; |
| 9316 | } |
| 9317 | } |
| 9318 | if (w.mSurface != null) { |
| 9319 | w.mToken.hasVisible = true; |
| 9320 | } |
| 9321 | } else { |
| 9322 | displayed = true; |
| 9323 | } |
| 9324 | |
| 9325 | if (displayed) { |
| 9326 | if (!covered) { |
Romain Guy | 980a938 | 2010-01-08 15:06:28 -0800 | [diff] [blame] | 9327 | if (attrs.width == LayoutParams.MATCH_PARENT |
| 9328 | && attrs.height == LayoutParams.MATCH_PARENT) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9329 | covered = true; |
| 9330 | } |
| 9331 | } |
| 9332 | if (w.mOrientationChanging) { |
| 9333 | if (w.mDrawPending || w.mCommitDrawPending) { |
| 9334 | orientationChangeComplete = false; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9335 | if (DEBUG_ORIENTATION) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9336 | "Orientation continue waiting for draw in " + w); |
| 9337 | } else { |
| 9338 | w.mOrientationChanging = false; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9339 | if (DEBUG_ORIENTATION) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9340 | "Orientation change complete in " + w); |
| 9341 | } |
| 9342 | } |
| 9343 | w.mToken.hasVisible = true; |
| 9344 | } |
| 9345 | } else if (w.mOrientationChanging) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9346 | if (DEBUG_ORIENTATION) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9347 | "Orientation change skips hidden " + w); |
| 9348 | w.mOrientationChanging = false; |
| 9349 | } |
| 9350 | |
| 9351 | final boolean canBeSeen = w.isDisplayedLw(); |
| 9352 | |
| 9353 | if (someoneLosingFocus && w == mCurrentFocus && canBeSeen) { |
| 9354 | focusDisplayed = true; |
| 9355 | } |
| 9356 | |
Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 9357 | final boolean obscuredChanged = w.mObscured != obscured; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9358 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9359 | // Update effect. |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 9360 | if (!(w.mObscured=obscured)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9361 | if (w.mSurface != null) { |
| 9362 | if ((attrFlags&FLAG_KEEP_SCREEN_ON) != 0) { |
| 9363 | holdScreen = w.mSession; |
| 9364 | } |
Dianne Hackborn | 9ed4a4b | 2009-03-25 17:10:37 -0700 | [diff] [blame] | 9365 | if (!syswin && w.mAttrs.screenBrightness >= 0 |
| 9366 | && screenBrightness < 0) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9367 | screenBrightness = w.mAttrs.screenBrightness; |
| 9368 | } |
Mike Lockwood | fb73f79 | 2009-11-20 11:31:18 -0500 | [diff] [blame] | 9369 | if (!syswin && w.mAttrs.buttonBrightness >= 0 |
| 9370 | && buttonBrightness < 0) { |
| 9371 | buttonBrightness = w.mAttrs.buttonBrightness; |
| 9372 | } |
Mike Lockwood | 46af6a8 | 2010-03-09 08:28:22 -0500 | [diff] [blame] | 9373 | if (canBeSeen |
| 9374 | && (attrs.type == WindowManager.LayoutParams.TYPE_SYSTEM_DIALOG |
| 9375 | || attrs.type == WindowManager.LayoutParams.TYPE_KEYGUARD |
| 9376 | || attrs.type == WindowManager.LayoutParams.TYPE_SYSTEM_ERROR)) { |
Dianne Hackborn | 9ed4a4b | 2009-03-25 17:10:37 -0700 | [diff] [blame] | 9377 | syswin = true; |
| 9378 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9379 | } |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 9380 | |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 9381 | boolean opaqueDrawn = canBeSeen && w.isOpaqueDrawn(); |
| 9382 | if (opaqueDrawn && w.isFullscreen(dw, dh)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9383 | // This window completely covers everything behind it, |
| 9384 | // so we want to leave all of them as unblurred (for |
| 9385 | // performance reasons). |
| 9386 | obscured = true; |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 9387 | } else if (opaqueDrawn && w.needsBackgroundFiller(dw, dh)) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9388 | if (SHOW_TRANSACTIONS) Slog.d(TAG, "showing background filler"); |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 9389 | // This window is in compatibility mode, and needs background filler. |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 9390 | obscured = true; |
| 9391 | if (mBackgroundFillerSurface == null) { |
| 9392 | try { |
| 9393 | mBackgroundFillerSurface = new Surface(mFxSession, 0, |
Mathias Agopian | 5d26c1e | 2010-03-01 16:09:43 -0800 | [diff] [blame] | 9394 | "BackGroundFiller", |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 9395 | 0, dw, dh, |
| 9396 | PixelFormat.OPAQUE, |
| 9397 | Surface.FX_SURFACE_NORMAL); |
| 9398 | } catch (Exception e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9399 | Slog.e(TAG, "Exception creating filler surface", e); |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 9400 | } |
| 9401 | } |
| 9402 | try { |
| 9403 | mBackgroundFillerSurface.setPosition(0, 0); |
| 9404 | mBackgroundFillerSurface.setSize(dw, dh); |
| 9405 | // Using the same layer as Dim because they will never be shown at the |
| 9406 | // same time. |
| 9407 | mBackgroundFillerSurface.setLayer(w.mAnimLayer - 1); |
| 9408 | mBackgroundFillerSurface.show(); |
| 9409 | } catch (RuntimeException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9410 | Slog.e(TAG, "Exception showing filler surface"); |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 9411 | } |
| 9412 | backgroundFillerShown = true; |
| 9413 | mBackgroundFillerShown = true; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9414 | } else if (canBeSeen && !obscured && |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9415 | (attrFlags&FLAG_BLUR_BEHIND|FLAG_DIM_BEHIND) != 0) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9416 | if (localLOGV) Slog.v(TAG, "Win " + w |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9417 | + ": blurring=" + blurring |
| 9418 | + " obscured=" + obscured |
| 9419 | + " displayed=" + displayed); |
| 9420 | if ((attrFlags&FLAG_DIM_BEHIND) != 0) { |
| 9421 | if (!dimming) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9422 | //Slog.i(TAG, "DIM BEHIND: " + w); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9423 | dimming = true; |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 9424 | if (mDimAnimator == null) { |
| 9425 | mDimAnimator = new DimAnimator(mFxSession); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9426 | } |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 9427 | mDimAnimator.show(dw, dh); |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 9428 | mDimAnimator.updateParameters(w, currentTime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9429 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9430 | } |
| 9431 | if ((attrFlags&FLAG_BLUR_BEHIND) != 0) { |
| 9432 | if (!blurring) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9433 | //Slog.i(TAG, "BLUR BEHIND: " + w); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9434 | blurring = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9435 | if (mBlurSurface == null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9436 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR " |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9437 | + mBlurSurface + ": CREATE"); |
| 9438 | try { |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9439 | mBlurSurface = new Surface(mFxSession, 0, |
Mathias Agopian | 5d26c1e | 2010-03-01 16:09:43 -0800 | [diff] [blame] | 9440 | "BlurSurface", |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9441 | -1, 16, 16, |
| 9442 | PixelFormat.OPAQUE, |
| 9443 | Surface.FX_SURFACE_BLUR); |
| 9444 | } catch (Exception e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9445 | Slog.e(TAG, "Exception creating Blur surface", e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9446 | } |
| 9447 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9448 | if (mBlurSurface != null) { |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 9449 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR " |
| 9450 | + mBlurSurface + ": pos=(0,0) (" + |
| 9451 | dw + "x" + dh + "), layer=" + (w.mAnimLayer-1)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9452 | mBlurSurface.setPosition(0, 0); |
| 9453 | mBlurSurface.setSize(dw, dh); |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 9454 | mBlurSurface.setLayer(w.mAnimLayer-2); |
| 9455 | if (!mBlurShown) { |
| 9456 | try { |
| 9457 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR " |
| 9458 | + mBlurSurface + ": SHOW"); |
| 9459 | mBlurSurface.show(); |
| 9460 | } catch (RuntimeException e) { |
| 9461 | Slog.w(TAG, "Failure showing blur surface", e); |
| 9462 | } |
| 9463 | mBlurShown = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9464 | } |
| 9465 | } |
| 9466 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9467 | } |
| 9468 | } |
| 9469 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9470 | |
Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 9471 | if (obscuredChanged && mWallpaperTarget == w) { |
| 9472 | // This is the wallpaper target and its obscured state |
| 9473 | // changed... make sure the current wallaper's visibility |
| 9474 | // has been updated accordingly. |
| 9475 | updateWallpaperVisibilityLocked(); |
| 9476 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9477 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9478 | |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 9479 | if (backgroundFillerShown == false && mBackgroundFillerShown) { |
| 9480 | mBackgroundFillerShown = false; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9481 | if (SHOW_TRANSACTIONS) Slog.d(TAG, "hiding background filler"); |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 9482 | try { |
| 9483 | mBackgroundFillerSurface.hide(); |
| 9484 | } catch (RuntimeException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9485 | Slog.e(TAG, "Exception hiding filler surface", e); |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 9486 | } |
| 9487 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9488 | |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 9489 | if (mDimAnimator != null && mDimAnimator.mDimShown) { |
Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 9490 | animating |= mDimAnimator.updateSurface(dimming, currentTime, |
| 9491 | mDisplayFrozen || !mPolicy.isScreenOn()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9492 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9493 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9494 | if (!blurring && mBlurShown) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9495 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR " + mBlurSurface |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9496 | + ": HIDE"); |
| 9497 | try { |
| 9498 | mBlurSurface.hide(); |
| 9499 | } catch (IllegalArgumentException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9500 | Slog.w(TAG, "Illegal argument exception hiding blur surface"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9501 | } |
| 9502 | mBlurShown = false; |
| 9503 | } |
| 9504 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9505 | if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9506 | } catch (RuntimeException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9507 | Slog.e(TAG, "Unhandled exception in Window Manager", e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9508 | } |
| 9509 | |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 9510 | mInputMonitor.updateInputWindowsLw(); |
| 9511 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9512 | Surface.closeTransaction(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9513 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9514 | if (DEBUG_ORIENTATION && mDisplayFrozen) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9515 | "With display frozen, orientationChangeComplete=" |
| 9516 | + orientationChangeComplete); |
| 9517 | if (orientationChangeComplete) { |
| 9518 | if (mWindowsFreezingScreen) { |
| 9519 | mWindowsFreezingScreen = false; |
| 9520 | mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT); |
| 9521 | } |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 9522 | stopFreezingDisplayLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9523 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9524 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9525 | i = mResizingWindows.size(); |
| 9526 | if (i > 0) { |
| 9527 | do { |
| 9528 | i--; |
| 9529 | WindowState win = mResizingWindows.get(i); |
| 9530 | try { |
Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 9531 | if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG, |
| 9532 | "Reporting new frame to " + win + ": " + win.mFrame); |
Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 9533 | int diff = 0; |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 9534 | boolean configChanged = |
| 9535 | win.mConfiguration != mCurConfiguration |
| 9536 | && (win.mConfiguration == null |
Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 9537 | || (diff=mCurConfiguration.diff(win.mConfiguration)) != 0); |
| 9538 | if ((DEBUG_RESIZE || DEBUG_ORIENTATION || DEBUG_CONFIGURATION) |
| 9539 | && configChanged) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9540 | Slog.i(TAG, "Sending new config to window " + win + ": " |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 9541 | + win.mFrame.width() + "x" + win.mFrame.height() |
Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 9542 | + " / " + mCurConfiguration + " / 0x" |
| 9543 | + Integer.toHexString(diff)); |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 9544 | } |
Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 9545 | win.mConfiguration = mCurConfiguration; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9546 | win.mClient.resized(win.mFrame.width(), |
| 9547 | win.mFrame.height(), win.mLastContentInsets, |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 9548 | win.mLastVisibleInsets, win.mDrawPending, |
| 9549 | configChanged ? win.mConfiguration : null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9550 | win.mContentInsetsChanged = false; |
| 9551 | win.mVisibleInsetsChanged = false; |
Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 9552 | win.mSurfaceResized = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9553 | } catch (RemoteException e) { |
| 9554 | win.mOrientationChanging = false; |
| 9555 | } |
| 9556 | } while (i > 0); |
| 9557 | mResizingWindows.clear(); |
| 9558 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9559 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9560 | // Destroy the surface of any windows that are no longer visible. |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 9561 | boolean wallpaperDestroyed = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9562 | i = mDestroySurface.size(); |
| 9563 | if (i > 0) { |
| 9564 | do { |
| 9565 | i--; |
| 9566 | WindowState win = mDestroySurface.get(i); |
| 9567 | win.mDestroying = false; |
| 9568 | if (mInputMethodWindow == win) { |
| 9569 | mInputMethodWindow = null; |
| 9570 | } |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 9571 | if (win == mWallpaperTarget) { |
| 9572 | wallpaperDestroyed = true; |
| 9573 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9574 | win.destroySurfaceLocked(); |
| 9575 | } while (i > 0); |
| 9576 | mDestroySurface.clear(); |
| 9577 | } |
| 9578 | |
| 9579 | // Time to remove any exiting tokens? |
| 9580 | for (i=mExitingTokens.size()-1; i>=0; i--) { |
| 9581 | WindowToken token = mExitingTokens.get(i); |
| 9582 | if (!token.hasVisible) { |
| 9583 | mExitingTokens.remove(i); |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 9584 | if (token.windowType == TYPE_WALLPAPER) { |
| 9585 | mWallpaperTokens.remove(token); |
| 9586 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9587 | } |
| 9588 | } |
| 9589 | |
| 9590 | // Time to remove any exiting applications? |
| 9591 | for (i=mExitingAppTokens.size()-1; i>=0; i--) { |
| 9592 | AppWindowToken token = mExitingAppTokens.get(i); |
| 9593 | if (!token.hasVisible && !mClosingApps.contains(token)) { |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 9594 | // Make sure there is no animation running on this token, |
| 9595 | // so any windows associated with it will be removed as |
| 9596 | // soon as their animations are complete |
| 9597 | token.animation = null; |
| 9598 | token.animating = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9599 | mAppTokens.remove(token); |
| 9600 | mExitingAppTokens.remove(i); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9601 | if (mLastEnterAnimToken == token) { |
| 9602 | mLastEnterAnimToken = null; |
| 9603 | mLastEnterAnimParams = null; |
| 9604 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9605 | } |
| 9606 | } |
| 9607 | |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9608 | boolean needRelayout = false; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9609 | |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9610 | if (!animating && mAppTransitionRunning) { |
| 9611 | // We have finished the animation of an app transition. To do |
| 9612 | // this, we have delayed a lot of operations like showing and |
| 9613 | // hiding apps, moving apps in Z-order, etc. The app token list |
| 9614 | // reflects the correct Z-order, but the window list may now |
| 9615 | // be out of sync with it. So here we will just rebuild the |
| 9616 | // entire app window list. Fun! |
| 9617 | mAppTransitionRunning = false; |
| 9618 | needRelayout = true; |
| 9619 | rebuildAppWindowListLocked(); |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 9620 | assignLayersLocked(); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9621 | // Clear information about apps that were moving. |
| 9622 | mToBottomApps.clear(); |
| 9623 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9624 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9625 | if (focusDisplayed) { |
| 9626 | mH.sendEmptyMessage(H.REPORT_LOSING_FOCUS); |
| 9627 | } |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 9628 | if (wallpaperDestroyed) { |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 9629 | needRelayout = adjustWallpaperWindowsLocked() != 0; |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 9630 | } |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9631 | if (needRelayout) { |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 9632 | requestAnimationLocked(0); |
| 9633 | } else if (animating) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9634 | requestAnimationLocked(currentTime+(1000/60)-SystemClock.uptimeMillis()); |
| 9635 | } |
Jeff Brown | eb857f1 | 2010-07-16 10:06:33 -0700 | [diff] [blame] | 9636 | |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 9637 | mInputMonitor.updateInputWindowsLw(); |
Jeff Brown | eb857f1 | 2010-07-16 10:06:33 -0700 | [diff] [blame] | 9638 | |
Jeff Brown | 8e03b75 | 2010-06-13 19:16:55 -0700 | [diff] [blame] | 9639 | setHoldScreenLocked(holdScreen != null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9640 | if (screenBrightness < 0 || screenBrightness > 1.0f) { |
| 9641 | mPowerManager.setScreenBrightnessOverride(-1); |
| 9642 | } else { |
| 9643 | mPowerManager.setScreenBrightnessOverride((int) |
| 9644 | (screenBrightness * Power.BRIGHTNESS_ON)); |
| 9645 | } |
Mike Lockwood | fb73f79 | 2009-11-20 11:31:18 -0500 | [diff] [blame] | 9646 | if (buttonBrightness < 0 || buttonBrightness > 1.0f) { |
| 9647 | mPowerManager.setButtonBrightnessOverride(-1); |
| 9648 | } else { |
| 9649 | mPowerManager.setButtonBrightnessOverride((int) |
| 9650 | (buttonBrightness * Power.BRIGHTNESS_ON)); |
| 9651 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9652 | if (holdScreen != mHoldingScreenOn) { |
| 9653 | mHoldingScreenOn = holdScreen; |
| 9654 | Message m = mH.obtainMessage(H.HOLD_SCREEN_CHANGED, holdScreen); |
| 9655 | mH.sendMessage(m); |
| 9656 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9657 | |
Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 9658 | if (mTurnOnScreen) { |
Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 9659 | if (DEBUG_VISIBILITY) Slog.v(TAG, "Turning screen on after layout!"); |
Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 9660 | mPowerManager.userActivity(SystemClock.uptimeMillis(), false, |
| 9661 | LocalPowerManager.BUTTON_EVENT, true); |
| 9662 | mTurnOnScreen = false; |
| 9663 | } |
Dianne Hackborn | f3bea9c | 2009-12-09 18:26:21 -0800 | [diff] [blame] | 9664 | |
| 9665 | // Check to see if we are now in a state where the screen should |
| 9666 | // be enabled, because the window obscured flags have changed. |
| 9667 | enableScreenIfNeededLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9668 | } |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 9669 | |
| 9670 | /** |
| 9671 | * Must be called with the main window manager lock held. |
| 9672 | */ |
| 9673 | void setHoldScreenLocked(boolean holding) { |
| 9674 | boolean state = mHoldingScreenWakeLock.isHeld(); |
| 9675 | if (holding != state) { |
| 9676 | if (holding) { |
| 9677 | mHoldingScreenWakeLock.acquire(); |
| 9678 | } else { |
| 9679 | mPolicy.screenOnStoppedLw(); |
| 9680 | mHoldingScreenWakeLock.release(); |
| 9681 | } |
| 9682 | } |
| 9683 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9684 | |
| 9685 | void requestAnimationLocked(long delay) { |
| 9686 | if (!mAnimationPending) { |
| 9687 | mAnimationPending = true; |
| 9688 | mH.sendMessageDelayed(mH.obtainMessage(H.ANIMATE), delay); |
| 9689 | } |
| 9690 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9691 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9692 | /** |
| 9693 | * Have the surface flinger show a surface, robustly dealing with |
| 9694 | * error conditions. In particular, if there is not enough memory |
| 9695 | * to show the surface, then we will try to get rid of other surfaces |
| 9696 | * in order to succeed. |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9697 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9698 | * @return Returns true if the surface was successfully shown. |
| 9699 | */ |
| 9700 | boolean showSurfaceRobustlyLocked(WindowState win) { |
| 9701 | try { |
| 9702 | if (win.mSurface != null) { |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 9703 | win.mSurfaceShown = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9704 | win.mSurface.show(); |
Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 9705 | if (win.mTurnOnScreen) { |
Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 9706 | if (DEBUG_VISIBILITY) Slog.v(TAG, |
| 9707 | "Show surface turning screen on: " + win); |
Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 9708 | win.mTurnOnScreen = false; |
| 9709 | mTurnOnScreen = true; |
| 9710 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9711 | } |
| 9712 | return true; |
| 9713 | } catch (RuntimeException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9714 | 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] | 9715 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9716 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9717 | reclaimSomeSurfaceMemoryLocked(win, "show"); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9718 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9719 | return false; |
| 9720 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9721 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9722 | void reclaimSomeSurfaceMemoryLocked(WindowState win, String operation) { |
| 9723 | final Surface surface = win.mSurface; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9724 | |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9725 | EventLog.writeEvent(EventLogTags.WM_NO_SURFACE_MEMORY, win.toString(), |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9726 | win.mSession.mPid, operation); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9727 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9728 | if (mForceRemoves == null) { |
| 9729 | mForceRemoves = new ArrayList<WindowState>(); |
| 9730 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9731 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9732 | long callingIdentity = Binder.clearCallingIdentity(); |
| 9733 | try { |
| 9734 | // There was some problem... first, do a sanity check of the |
| 9735 | // window list to make sure we haven't left any dangling surfaces |
| 9736 | // around. |
| 9737 | int N = mWindows.size(); |
| 9738 | boolean leakedSurface = false; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9739 | 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] | 9740 | for (int i=0; i<N; i++) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 9741 | WindowState ws = mWindows.get(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9742 | if (ws.mSurface != null) { |
| 9743 | if (!mSessions.contains(ws.mSession)) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9744 | Slog.w(TAG, "LEAKED SURFACE (session doesn't exist): " |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9745 | + ws + " surface=" + ws.mSurface |
| 9746 | + " token=" + win.mToken |
| 9747 | + " pid=" + ws.mSession.mPid |
| 9748 | + " uid=" + ws.mSession.mUid); |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 9749 | ws.mSurface.destroy(); |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 9750 | ws.mSurfaceShown = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9751 | ws.mSurface = null; |
| 9752 | mForceRemoves.add(ws); |
| 9753 | i--; |
| 9754 | N--; |
| 9755 | leakedSurface = true; |
| 9756 | } else if (win.mAppToken != null && win.mAppToken.clientHidden) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9757 | Slog.w(TAG, "LEAKED SURFACE (app token hidden): " |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9758 | + ws + " surface=" + ws.mSurface |
| 9759 | + " token=" + win.mAppToken); |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 9760 | ws.mSurface.destroy(); |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 9761 | ws.mSurfaceShown = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9762 | ws.mSurface = null; |
| 9763 | leakedSurface = true; |
| 9764 | } |
| 9765 | } |
| 9766 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9767 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9768 | boolean killedApps = false; |
| 9769 | if (!leakedSurface) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9770 | Slog.w(TAG, "No leaked surfaces; killing applicatons!"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9771 | SparseIntArray pidCandidates = new SparseIntArray(); |
| 9772 | for (int i=0; i<N; i++) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 9773 | WindowState ws = mWindows.get(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9774 | if (ws.mSurface != null) { |
| 9775 | pidCandidates.append(ws.mSession.mPid, ws.mSession.mPid); |
| 9776 | } |
| 9777 | } |
| 9778 | if (pidCandidates.size() > 0) { |
| 9779 | int[] pids = new int[pidCandidates.size()]; |
| 9780 | for (int i=0; i<pids.length; i++) { |
| 9781 | pids[i] = pidCandidates.keyAt(i); |
| 9782 | } |
| 9783 | try { |
Suchi Amalapurapu | e99bb5f | 2010-03-19 14:36:49 -0700 | [diff] [blame] | 9784 | if (mActivityManager.killPids(pids, "Free memory")) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9785 | killedApps = true; |
| 9786 | } |
| 9787 | } catch (RemoteException e) { |
| 9788 | } |
| 9789 | } |
| 9790 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9791 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9792 | if (leakedSurface || killedApps) { |
| 9793 | // We managed to reclaim some memory, so get rid of the trouble |
| 9794 | // surface and ask the app to request another one. |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9795 | 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] | 9796 | if (surface != null) { |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 9797 | surface.destroy(); |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 9798 | win.mSurfaceShown = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9799 | win.mSurface = null; |
| 9800 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9801 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9802 | try { |
| 9803 | win.mClient.dispatchGetNewSurface(); |
| 9804 | } catch (RemoteException e) { |
| 9805 | } |
| 9806 | } |
| 9807 | } finally { |
| 9808 | Binder.restoreCallingIdentity(callingIdentity); |
| 9809 | } |
| 9810 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9811 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9812 | private boolean updateFocusedWindowLocked(int mode) { |
| 9813 | WindowState newFocus = computeFocusedWindowLocked(); |
| 9814 | if (mCurrentFocus != newFocus) { |
| 9815 | // This check makes sure that we don't already have the focus |
| 9816 | // change message pending. |
| 9817 | mH.removeMessages(H.REPORT_FOCUS_CHANGE); |
| 9818 | mH.sendEmptyMessage(H.REPORT_FOCUS_CHANGE); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9819 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9820 | TAG, "Changing focus from " + mCurrentFocus + " to " + newFocus); |
| 9821 | final WindowState oldFocus = mCurrentFocus; |
| 9822 | mCurrentFocus = newFocus; |
| 9823 | mLosingFocus.remove(newFocus); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9824 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9825 | final WindowState imWindow = mInputMethodWindow; |
| 9826 | if (newFocus != imWindow && oldFocus != imWindow) { |
The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 9827 | if (moveInputMethodWindowsIfNeededLocked( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9828 | mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS && |
The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 9829 | mode != UPDATE_FOCUS_WILL_PLACE_SURFACES)) { |
| 9830 | mLayoutNeeded = true; |
| 9831 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9832 | if (mode == UPDATE_FOCUS_PLACING_SURFACES) { |
| 9833 | performLayoutLockedInner(); |
The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 9834 | } else if (mode == UPDATE_FOCUS_WILL_PLACE_SURFACES) { |
| 9835 | // Client will do the layout, but we need to assign layers |
| 9836 | // for handleNewWindowLocked() below. |
| 9837 | assignLayersLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9838 | } |
| 9839 | } |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 9840 | |
| 9841 | if (mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS) { |
| 9842 | // If we defer assigning layers, then the caller is responsible for |
| 9843 | // doing this part. |
| 9844 | finishUpdateFocusedWindowAfterAssignLayersLocked(); |
The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 9845 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9846 | return true; |
| 9847 | } |
| 9848 | return false; |
| 9849 | } |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 9850 | |
| 9851 | private void finishUpdateFocusedWindowAfterAssignLayersLocked() { |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 9852 | mInputMonitor.setInputFocusLw(mCurrentFocus); |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 9853 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9854 | |
| 9855 | private WindowState computeFocusedWindowLocked() { |
| 9856 | WindowState result = null; |
| 9857 | WindowState win; |
| 9858 | |
| 9859 | int i = mWindows.size() - 1; |
| 9860 | int nextAppIndex = mAppTokens.size()-1; |
| 9861 | WindowToken nextApp = nextAppIndex >= 0 |
| 9862 | ? mAppTokens.get(nextAppIndex) : null; |
| 9863 | |
| 9864 | while (i >= 0) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 9865 | win = mWindows.get(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9866 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9867 | if (localLOGV || DEBUG_FOCUS) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9868 | TAG, "Looking for focus: " + i |
| 9869 | + " = " + win |
| 9870 | + ", flags=" + win.mAttrs.flags |
| 9871 | + ", canReceive=" + win.canReceiveKeys()); |
| 9872 | |
| 9873 | AppWindowToken thisApp = win.mAppToken; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9874 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9875 | // If this window's application has been removed, just skip it. |
| 9876 | if (thisApp != null && thisApp.removed) { |
| 9877 | i--; |
| 9878 | continue; |
| 9879 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9880 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9881 | // If there is a focused app, don't allow focus to go to any |
| 9882 | // windows below it. If this is an application window, step |
| 9883 | // through the app tokens until we find its app. |
| 9884 | if (thisApp != null && nextApp != null && thisApp != nextApp |
| 9885 | && win.mAttrs.type != TYPE_APPLICATION_STARTING) { |
| 9886 | int origAppIndex = nextAppIndex; |
| 9887 | while (nextAppIndex > 0) { |
| 9888 | if (nextApp == mFocusedApp) { |
| 9889 | // Whoops, we are below the focused app... no focus |
| 9890 | // for you! |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9891 | if (localLOGV || DEBUG_FOCUS) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9892 | TAG, "Reached focused app: " + mFocusedApp); |
| 9893 | return null; |
| 9894 | } |
| 9895 | nextAppIndex--; |
| 9896 | nextApp = mAppTokens.get(nextAppIndex); |
| 9897 | if (nextApp == thisApp) { |
| 9898 | break; |
| 9899 | } |
| 9900 | } |
| 9901 | if (thisApp != nextApp) { |
| 9902 | // Uh oh, the app token doesn't exist! This shouldn't |
| 9903 | // happen, but if it does we can get totally hosed... |
| 9904 | // so restart at the original app. |
| 9905 | nextAppIndex = origAppIndex; |
| 9906 | nextApp = mAppTokens.get(nextAppIndex); |
| 9907 | } |
| 9908 | } |
| 9909 | |
| 9910 | // Dispatch to this window if it is wants key events. |
| 9911 | if (win.canReceiveKeys()) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9912 | if (DEBUG_FOCUS) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9913 | TAG, "Found focus @ " + i + " = " + win); |
| 9914 | result = win; |
| 9915 | break; |
| 9916 | } |
| 9917 | |
| 9918 | i--; |
| 9919 | } |
| 9920 | |
| 9921 | return result; |
| 9922 | } |
| 9923 | |
| 9924 | private void startFreezingDisplayLocked() { |
| 9925 | if (mDisplayFrozen) { |
| 9926 | return; |
| 9927 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9928 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9929 | mScreenFrozenLock.acquire(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9930 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9931 | long now = SystemClock.uptimeMillis(); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9932 | //Slog.i(TAG, "Freezing, gc pending: " + mFreezeGcPending + ", now " + now); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9933 | if (mFreezeGcPending != 0) { |
| 9934 | if (now > (mFreezeGcPending+1000)) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9935 | //Slog.i(TAG, "Gc! " + now + " > " + (mFreezeGcPending+1000)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9936 | mH.removeMessages(H.FORCE_GC); |
| 9937 | Runtime.getRuntime().gc(); |
| 9938 | mFreezeGcPending = now; |
| 9939 | } |
| 9940 | } else { |
| 9941 | mFreezeGcPending = now; |
| 9942 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9943 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9944 | mDisplayFrozen = true; |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 9945 | |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 9946 | mInputMonitor.freezeInputDispatchingLw(); |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 9947 | |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 9948 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
| 9949 | mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9950 | mNextAppTransitionPackage = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9951 | mAppTransitionReady = true; |
| 9952 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9953 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9954 | if (PROFILE_ORIENTATION) { |
| 9955 | File file = new File("/data/system/frozen"); |
| 9956 | Debug.startMethodTracing(file.toString(), 8 * 1024 * 1024); |
| 9957 | } |
| 9958 | Surface.freezeDisplay(0); |
| 9959 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9960 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9961 | private void stopFreezingDisplayLocked() { |
| 9962 | if (!mDisplayFrozen) { |
| 9963 | return; |
| 9964 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9965 | |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 9966 | if (mWaitingForConfig || mAppsFreezingScreen > 0 || mWindowsFreezingScreen) { |
| 9967 | return; |
| 9968 | } |
| 9969 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9970 | mDisplayFrozen = false; |
| 9971 | mH.removeMessages(H.APP_FREEZE_TIMEOUT); |
| 9972 | if (PROFILE_ORIENTATION) { |
| 9973 | Debug.stopMethodTracing(); |
| 9974 | } |
| 9975 | Surface.unfreezeDisplay(0); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9976 | |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 9977 | mInputMonitor.thawInputDispatchingLw(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9978 | |
Christopher Tate | b696aee | 2010-04-02 19:08:30 -0700 | [diff] [blame] | 9979 | // While the display is frozen we don't re-compute the orientation |
| 9980 | // to avoid inconsistent states. However, something interesting |
| 9981 | // could have actually changed during that time so re-evaluate it |
| 9982 | // now to catch that. |
| 9983 | if (updateOrientationFromAppTokensLocked()) { |
| 9984 | mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION); |
| 9985 | } |
| 9986 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9987 | // A little kludge: a lot could have happened while the |
| 9988 | // display was frozen, so now that we are coming back we |
| 9989 | // do a gc so that any remote references the system |
| 9990 | // processes holds on others can be released if they are |
| 9991 | // no longer needed. |
| 9992 | mH.removeMessages(H.FORCE_GC); |
| 9993 | mH.sendMessageDelayed(mH.obtainMessage(H.FORCE_GC), |
| 9994 | 2000); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9995 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9996 | mScreenFrozenLock.release(); |
| 9997 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9998 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9999 | @Override |
| 10000 | public void dump(FileDescriptor fd, PrintWriter pw, String[] args) { |
| 10001 | if (mContext.checkCallingOrSelfPermission("android.permission.DUMP") |
| 10002 | != PackageManager.PERMISSION_GRANTED) { |
| 10003 | pw.println("Permission Denial: can't dump WindowManager from from pid=" |
| 10004 | + Binder.getCallingPid() |
| 10005 | + ", uid=" + Binder.getCallingUid()); |
| 10006 | return; |
| 10007 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10008 | |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 10009 | mInputManager.dump(pw); |
Dianne Hackborn | a2e9226 | 2010-03-02 17:19:29 -0800 | [diff] [blame] | 10010 | pw.println(" "); |
| 10011 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10012 | synchronized(mWindowMap) { |
| 10013 | pw.println("Current Window Manager state:"); |
| 10014 | for (int i=mWindows.size()-1; i>=0; i--) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 10015 | WindowState w = mWindows.get(i); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10016 | pw.print(" Window #"); pw.print(i); pw.print(' '); |
| 10017 | pw.print(w); pw.println(":"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10018 | w.dump(pw, " "); |
| 10019 | } |
| 10020 | if (mInputMethodDialogs.size() > 0) { |
| 10021 | pw.println(" "); |
| 10022 | pw.println(" Input method dialogs:"); |
| 10023 | for (int i=mInputMethodDialogs.size()-1; i>=0; i--) { |
| 10024 | WindowState w = mInputMethodDialogs.get(i); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10025 | 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] | 10026 | } |
| 10027 | } |
| 10028 | if (mPendingRemove.size() > 0) { |
| 10029 | pw.println(" "); |
| 10030 | pw.println(" Remove pending for:"); |
| 10031 | for (int i=mPendingRemove.size()-1; i>=0; i--) { |
| 10032 | WindowState w = mPendingRemove.get(i); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10033 | pw.print(" Remove #"); pw.print(i); pw.print(' '); |
| 10034 | pw.print(w); pw.println(":"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10035 | w.dump(pw, " "); |
| 10036 | } |
| 10037 | } |
| 10038 | if (mForceRemoves != null && mForceRemoves.size() > 0) { |
| 10039 | pw.println(" "); |
| 10040 | pw.println(" Windows force removing:"); |
| 10041 | for (int i=mForceRemoves.size()-1; i>=0; i--) { |
| 10042 | WindowState w = mForceRemoves.get(i); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10043 | pw.print(" Removing #"); pw.print(i); pw.print(' '); |
| 10044 | pw.print(w); pw.println(":"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10045 | w.dump(pw, " "); |
| 10046 | } |
| 10047 | } |
| 10048 | if (mDestroySurface.size() > 0) { |
| 10049 | pw.println(" "); |
| 10050 | pw.println(" Windows waiting to destroy their surface:"); |
| 10051 | for (int i=mDestroySurface.size()-1; i>=0; i--) { |
| 10052 | WindowState w = mDestroySurface.get(i); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10053 | pw.print(" Destroy #"); pw.print(i); pw.print(' '); |
| 10054 | pw.print(w); pw.println(":"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10055 | w.dump(pw, " "); |
| 10056 | } |
| 10057 | } |
| 10058 | if (mLosingFocus.size() > 0) { |
| 10059 | pw.println(" "); |
| 10060 | pw.println(" Windows losing focus:"); |
| 10061 | for (int i=mLosingFocus.size()-1; i>=0; i--) { |
| 10062 | WindowState w = mLosingFocus.get(i); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10063 | pw.print(" Losing #"); pw.print(i); pw.print(' '); |
| 10064 | pw.print(w); pw.println(":"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10065 | w.dump(pw, " "); |
| 10066 | } |
| 10067 | } |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 10068 | if (mResizingWindows.size() > 0) { |
| 10069 | pw.println(" "); |
| 10070 | pw.println(" Windows waiting to resize:"); |
| 10071 | for (int i=mResizingWindows.size()-1; i>=0; i--) { |
| 10072 | WindowState w = mResizingWindows.get(i); |
| 10073 | pw.print(" Resizing #"); pw.print(i); pw.print(' '); |
| 10074 | pw.print(w); pw.println(":"); |
| 10075 | w.dump(pw, " "); |
| 10076 | } |
| 10077 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10078 | if (mSessions.size() > 0) { |
| 10079 | pw.println(" "); |
| 10080 | pw.println(" All active sessions:"); |
| 10081 | Iterator<Session> it = mSessions.iterator(); |
| 10082 | while (it.hasNext()) { |
| 10083 | Session s = it.next(); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10084 | pw.print(" Session "); pw.print(s); pw.println(':'); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10085 | s.dump(pw, " "); |
| 10086 | } |
| 10087 | } |
| 10088 | if (mTokenMap.size() > 0) { |
| 10089 | pw.println(" "); |
| 10090 | pw.println(" All tokens:"); |
| 10091 | Iterator<WindowToken> it = mTokenMap.values().iterator(); |
| 10092 | while (it.hasNext()) { |
| 10093 | WindowToken token = it.next(); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10094 | pw.print(" Token "); pw.print(token.token); pw.println(':'); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10095 | token.dump(pw, " "); |
| 10096 | } |
| 10097 | } |
| 10098 | if (mTokenList.size() > 0) { |
| 10099 | pw.println(" "); |
| 10100 | pw.println(" Window token list:"); |
| 10101 | for (int i=0; i<mTokenList.size(); i++) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10102 | pw.print(" #"); pw.print(i); pw.print(": "); |
| 10103 | pw.println(mTokenList.get(i)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10104 | } |
| 10105 | } |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 10106 | if (mWallpaperTokens.size() > 0) { |
| 10107 | pw.println(" "); |
| 10108 | pw.println(" Wallpaper tokens:"); |
| 10109 | for (int i=mWallpaperTokens.size()-1; i>=0; i--) { |
| 10110 | WindowToken token = mWallpaperTokens.get(i); |
| 10111 | pw.print(" Wallpaper #"); pw.print(i); |
| 10112 | pw.print(' '); pw.print(token); pw.println(':'); |
| 10113 | token.dump(pw, " "); |
| 10114 | } |
| 10115 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10116 | if (mAppTokens.size() > 0) { |
| 10117 | pw.println(" "); |
| 10118 | pw.println(" Application tokens in Z order:"); |
| 10119 | for (int i=mAppTokens.size()-1; i>=0; i--) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10120 | pw.print(" App #"); pw.print(i); pw.print(": "); |
| 10121 | pw.println(mAppTokens.get(i)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10122 | } |
| 10123 | } |
| 10124 | if (mFinishedStarting.size() > 0) { |
| 10125 | pw.println(" "); |
| 10126 | pw.println(" Finishing start of application tokens:"); |
| 10127 | for (int i=mFinishedStarting.size()-1; i>=0; i--) { |
| 10128 | WindowToken token = mFinishedStarting.get(i); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10129 | pw.print(" Finished Starting #"); pw.print(i); |
| 10130 | pw.print(' '); pw.print(token); pw.println(':'); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10131 | token.dump(pw, " "); |
| 10132 | } |
| 10133 | } |
| 10134 | if (mExitingTokens.size() > 0) { |
| 10135 | pw.println(" "); |
| 10136 | pw.println(" Exiting tokens:"); |
| 10137 | for (int i=mExitingTokens.size()-1; i>=0; i--) { |
| 10138 | WindowToken token = mExitingTokens.get(i); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10139 | pw.print(" Exiting #"); pw.print(i); |
| 10140 | pw.print(' '); pw.print(token); pw.println(':'); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10141 | token.dump(pw, " "); |
| 10142 | } |
| 10143 | } |
| 10144 | if (mExitingAppTokens.size() > 0) { |
| 10145 | pw.println(" "); |
| 10146 | pw.println(" Exiting application tokens:"); |
| 10147 | for (int i=mExitingAppTokens.size()-1; i>=0; i--) { |
| 10148 | WindowToken token = mExitingAppTokens.get(i); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10149 | pw.print(" Exiting App #"); pw.print(i); |
| 10150 | pw.print(' '); pw.print(token); pw.println(':'); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10151 | token.dump(pw, " "); |
| 10152 | } |
| 10153 | } |
| 10154 | pw.println(" "); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10155 | pw.print(" mCurrentFocus="); pw.println(mCurrentFocus); |
| 10156 | pw.print(" mLastFocus="); pw.println(mLastFocus); |
| 10157 | pw.print(" mFocusedApp="); pw.println(mFocusedApp); |
| 10158 | pw.print(" mInputMethodTarget="); pw.println(mInputMethodTarget); |
| 10159 | pw.print(" mInputMethodWindow="); pw.println(mInputMethodWindow); |
Dianne Hackborn | f21adf6 | 2009-08-13 10:20:21 -0700 | [diff] [blame] | 10160 | pw.print(" mWallpaperTarget="); pw.println(mWallpaperTarget); |
Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 10161 | if (mLowerWallpaperTarget != null && mUpperWallpaperTarget != null) { |
| 10162 | pw.print(" mLowerWallpaperTarget="); pw.println(mLowerWallpaperTarget); |
| 10163 | pw.print(" mUpperWallpaperTarget="); pw.println(mUpperWallpaperTarget); |
| 10164 | } |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 10165 | pw.print(" mCurConfiguration="); pw.println(this.mCurConfiguration); |
| 10166 | pw.print(" mInTouchMode="); pw.print(mInTouchMode); |
| 10167 | pw.print(" mLayoutSeq="); pw.println(mLayoutSeq); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10168 | pw.print(" mSystemBooted="); pw.print(mSystemBooted); |
| 10169 | pw.print(" mDisplayEnabled="); pw.println(mDisplayEnabled); |
| 10170 | pw.print(" mLayoutNeeded="); pw.print(mLayoutNeeded); |
| 10171 | pw.print(" mBlurShown="); pw.println(mBlurShown); |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 10172 | if (mDimAnimator != null) { |
| 10173 | mDimAnimator.printTo(pw); |
| 10174 | } else { |
Dianne Hackborn | a2e9226 | 2010-03-02 17:19:29 -0800 | [diff] [blame] | 10175 | pw.println( " no DimAnimator "); |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 10176 | } |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10177 | pw.print(" mInputMethodAnimLayerAdjustment="); |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 10178 | pw.print(mInputMethodAnimLayerAdjustment); |
| 10179 | pw.print(" mWallpaperAnimLayerAdjustment="); |
| 10180 | pw.println(mWallpaperAnimLayerAdjustment); |
Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 10181 | pw.print(" mLastWallpaperX="); pw.print(mLastWallpaperX); |
| 10182 | pw.print(" mLastWallpaperY="); pw.println(mLastWallpaperY); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10183 | pw.print(" mDisplayFrozen="); pw.print(mDisplayFrozen); |
| 10184 | pw.print(" mWindowsFreezingScreen="); pw.print(mWindowsFreezingScreen); |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 10185 | pw.print(" mAppsFreezingScreen="); pw.print(mAppsFreezingScreen); |
| 10186 | pw.print(" mWaitingForConfig="); pw.println(mWaitingForConfig); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10187 | pw.print(" mRotation="); pw.print(mRotation); |
| 10188 | pw.print(", mForcedAppOrientation="); pw.print(mForcedAppOrientation); |
| 10189 | pw.print(", mRequestedRotation="); pw.println(mRequestedRotation); |
| 10190 | pw.print(" mAnimationPending="); pw.print(mAnimationPending); |
| 10191 | pw.print(" mWindowAnimationScale="); pw.print(mWindowAnimationScale); |
| 10192 | pw.print(" mTransitionWindowAnimationScale="); pw.println(mTransitionAnimationScale); |
| 10193 | pw.print(" mNextAppTransition=0x"); |
| 10194 | pw.print(Integer.toHexString(mNextAppTransition)); |
| 10195 | pw.print(", mAppTransitionReady="); pw.print(mAppTransitionReady); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 10196 | pw.print(", mAppTransitionRunning="); pw.print(mAppTransitionRunning); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10197 | pw.print(", mAppTransitionTimeout="); pw.println( mAppTransitionTimeout); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10198 | if (mNextAppTransitionPackage != null) { |
| 10199 | pw.print(" mNextAppTransitionPackage="); |
| 10200 | pw.print(mNextAppTransitionPackage); |
| 10201 | pw.print(", mNextAppTransitionEnter=0x"); |
| 10202 | pw.print(Integer.toHexString(mNextAppTransitionEnter)); |
| 10203 | pw.print(", mNextAppTransitionExit=0x"); |
| 10204 | pw.print(Integer.toHexString(mNextAppTransitionExit)); |
| 10205 | } |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10206 | pw.print(" mStartingIconInTransition="); pw.print(mStartingIconInTransition); |
| 10207 | pw.print(", mSkipAppTransitionAnimation="); pw.println(mSkipAppTransitionAnimation); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10208 | if (mLastEnterAnimToken != null || mLastEnterAnimToken != null) { |
| 10209 | pw.print(" mLastEnterAnimToken="); pw.print(mLastEnterAnimToken); |
| 10210 | pw.print(", mLastEnterAnimParams="); pw.println(mLastEnterAnimParams); |
| 10211 | } |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10212 | if (mOpeningApps.size() > 0) { |
| 10213 | pw.print(" mOpeningApps="); pw.println(mOpeningApps); |
| 10214 | } |
| 10215 | if (mClosingApps.size() > 0) { |
| 10216 | pw.print(" mClosingApps="); pw.println(mClosingApps); |
| 10217 | } |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 10218 | if (mToTopApps.size() > 0) { |
| 10219 | pw.print(" mToTopApps="); pw.println(mToTopApps); |
| 10220 | } |
| 10221 | if (mToBottomApps.size() > 0) { |
| 10222 | pw.print(" mToBottomApps="); pw.println(mToBottomApps); |
| 10223 | } |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10224 | pw.print(" DisplayWidth="); pw.print(mDisplay.getWidth()); |
| 10225 | pw.print(" DisplayHeight="); pw.println(mDisplay.getHeight()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10226 | } |
| 10227 | } |
| 10228 | |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 10229 | // 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] | 10230 | public void monitor() { |
| 10231 | synchronized (mWindowMap) { } |
Mike Lockwood | 983ee09 | 2009-11-22 01:42:24 -0500 | [diff] [blame] | 10232 | synchronized (mKeyguardTokenWatcher) { } |
Dianne Hackborn | ddca3ee | 2009-07-23 19:01:31 -0700 | [diff] [blame] | 10233 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10234 | |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 10235 | /** |
| 10236 | * DimAnimator class that controls the dim animation. This holds the surface and |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10237 | * all state used for dim animation. |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 10238 | */ |
| 10239 | private static class DimAnimator { |
| 10240 | Surface mDimSurface; |
| 10241 | boolean mDimShown = false; |
| 10242 | float mDimCurrentAlpha; |
| 10243 | float mDimTargetAlpha; |
| 10244 | float mDimDeltaPerMs; |
| 10245 | long mLastDimAnimTime; |
Dianne Hackborn | f83c555 | 2010-03-31 22:19:32 -0700 | [diff] [blame] | 10246 | |
| 10247 | int mLastDimWidth, mLastDimHeight; |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 10248 | |
| 10249 | DimAnimator (SurfaceSession session) { |
| 10250 | if (mDimSurface == null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10251 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 10252 | + mDimSurface + ": CREATE"); |
| 10253 | try { |
Mathias Agopian | 5d26c1e | 2010-03-01 16:09:43 -0800 | [diff] [blame] | 10254 | mDimSurface = new Surface(session, 0, |
| 10255 | "DimSurface", |
| 10256 | -1, 16, 16, PixelFormat.OPAQUE, |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 10257 | Surface.FX_SURFACE_DIM); |
Maciej Białka | 9ee5c22 | 2010-03-24 10:25:40 +0100 | [diff] [blame] | 10258 | mDimSurface.setAlpha(0.0f); |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 10259 | } catch (Exception e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10260 | Slog.e(TAG, "Exception creating Dim surface", e); |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 10261 | } |
| 10262 | } |
| 10263 | } |
| 10264 | |
| 10265 | /** |
| 10266 | * Show the dim surface. |
| 10267 | */ |
| 10268 | void show(int dw, int dh) { |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 10269 | if (!mDimShown) { |
| 10270 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface + ": SHOW pos=(0,0) (" + |
| 10271 | dw + "x" + dh + ")"); |
| 10272 | mDimShown = true; |
| 10273 | try { |
Dianne Hackborn | f83c555 | 2010-03-31 22:19:32 -0700 | [diff] [blame] | 10274 | mLastDimWidth = dw; |
| 10275 | mLastDimHeight = dh; |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 10276 | mDimSurface.setPosition(0, 0); |
| 10277 | mDimSurface.setSize(dw, dh); |
| 10278 | mDimSurface.show(); |
| 10279 | } catch (RuntimeException e) { |
| 10280 | Slog.w(TAG, "Failure showing dim surface", e); |
| 10281 | } |
Dianne Hackborn | f83c555 | 2010-03-31 22:19:32 -0700 | [diff] [blame] | 10282 | } else if (mLastDimWidth != dw || mLastDimHeight != dh) { |
| 10283 | mLastDimWidth = dw; |
| 10284 | mLastDimHeight = dh; |
| 10285 | mDimSurface.setSize(dw, dh); |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 10286 | } |
| 10287 | } |
| 10288 | |
| 10289 | /** |
| 10290 | * Set's the dim surface's layer and update dim parameters that will be used in |
| 10291 | * {@link updateSurface} after all windows are examined. |
| 10292 | */ |
| 10293 | void updateParameters(WindowState w, long currentTime) { |
| 10294 | mDimSurface.setLayer(w.mAnimLayer-1); |
| 10295 | |
| 10296 | final float target = w.mExiting ? 0 : w.mAttrs.dimAmount; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10297 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 10298 | + ": layer=" + (w.mAnimLayer-1) + " target=" + target); |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 10299 | if (mDimTargetAlpha != target) { |
| 10300 | // If the desired dim level has changed, then |
| 10301 | // start an animation to it. |
| 10302 | mLastDimAnimTime = currentTime; |
| 10303 | long duration = (w.mAnimating && w.mAnimation != null) |
| 10304 | ? w.mAnimation.computeDurationHint() |
| 10305 | : DEFAULT_DIM_DURATION; |
| 10306 | if (target > mDimTargetAlpha) { |
| 10307 | // This is happening behind the activity UI, |
| 10308 | // so we can make it run a little longer to |
| 10309 | // give a stronger impression without disrupting |
| 10310 | // the user. |
| 10311 | duration *= DIM_DURATION_MULTIPLIER; |
| 10312 | } |
| 10313 | if (duration < 1) { |
| 10314 | // Don't divide by zero |
| 10315 | duration = 1; |
| 10316 | } |
| 10317 | mDimTargetAlpha = target; |
| 10318 | mDimDeltaPerMs = (mDimTargetAlpha-mDimCurrentAlpha) / duration; |
| 10319 | } |
| 10320 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10321 | |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 10322 | /** |
| 10323 | * Updating the surface's alpha. Returns true if the animation continues, or returns |
| 10324 | * false when the animation is finished and the dim surface is hidden. |
| 10325 | */ |
| 10326 | boolean updateSurface(boolean dimming, long currentTime, boolean displayFrozen) { |
| 10327 | if (!dimming) { |
| 10328 | if (mDimTargetAlpha != 0) { |
| 10329 | mLastDimAnimTime = currentTime; |
| 10330 | mDimTargetAlpha = 0; |
| 10331 | mDimDeltaPerMs = (-mDimCurrentAlpha) / DEFAULT_DIM_DURATION; |
| 10332 | } |
| 10333 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10334 | |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 10335 | boolean animating = false; |
| 10336 | if (mLastDimAnimTime != 0) { |
| 10337 | mDimCurrentAlpha += mDimDeltaPerMs |
| 10338 | * (currentTime-mLastDimAnimTime); |
| 10339 | boolean more = true; |
| 10340 | if (displayFrozen) { |
| 10341 | // If the display is frozen, there is no reason to animate. |
| 10342 | more = false; |
| 10343 | } else if (mDimDeltaPerMs > 0) { |
| 10344 | if (mDimCurrentAlpha > mDimTargetAlpha) { |
| 10345 | more = false; |
| 10346 | } |
| 10347 | } else if (mDimDeltaPerMs < 0) { |
| 10348 | if (mDimCurrentAlpha < mDimTargetAlpha) { |
| 10349 | more = false; |
| 10350 | } |
| 10351 | } else { |
| 10352 | more = false; |
| 10353 | } |
| 10354 | |
| 10355 | // Do we need to continue animating? |
| 10356 | if (more) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10357 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 10358 | + mDimSurface + ": alpha=" + mDimCurrentAlpha); |
| 10359 | mLastDimAnimTime = currentTime; |
| 10360 | mDimSurface.setAlpha(mDimCurrentAlpha); |
| 10361 | animating = true; |
| 10362 | } else { |
| 10363 | mDimCurrentAlpha = mDimTargetAlpha; |
| 10364 | mLastDimAnimTime = 0; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10365 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 10366 | + mDimSurface + ": final alpha=" + mDimCurrentAlpha); |
| 10367 | mDimSurface.setAlpha(mDimCurrentAlpha); |
| 10368 | if (!dimming) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10369 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 10370 | + ": HIDE"); |
| 10371 | try { |
| 10372 | mDimSurface.hide(); |
| 10373 | } catch (RuntimeException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10374 | Slog.w(TAG, "Illegal argument exception hiding dim surface"); |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 10375 | } |
| 10376 | mDimShown = false; |
| 10377 | } |
| 10378 | } |
| 10379 | } |
| 10380 | return animating; |
| 10381 | } |
| 10382 | |
| 10383 | public void printTo(PrintWriter pw) { |
| 10384 | pw.print(" mDimShown="); pw.print(mDimShown); |
| 10385 | pw.print(" current="); pw.print(mDimCurrentAlpha); |
| 10386 | pw.print(" target="); pw.print(mDimTargetAlpha); |
| 10387 | pw.print(" delta="); pw.print(mDimDeltaPerMs); |
| 10388 | pw.print(" lastAnimTime="); pw.println(mLastDimAnimTime); |
| 10389 | } |
| 10390 | } |
| 10391 | |
| 10392 | /** |
| 10393 | * Animation that fade in after 0.5 interpolate time, or fade out in reverse order. |
| 10394 | * This is used for opening/closing transition for apps in compatible mode. |
| 10395 | */ |
| 10396 | private static class FadeInOutAnimation extends Animation { |
| 10397 | int mWidth; |
| 10398 | boolean mFadeIn; |
| 10399 | |
| 10400 | public FadeInOutAnimation(boolean fadeIn) { |
| 10401 | setInterpolator(new AccelerateInterpolator()); |
| 10402 | setDuration(DEFAULT_FADE_IN_OUT_DURATION); |
| 10403 | mFadeIn = fadeIn; |
| 10404 | } |
| 10405 | |
| 10406 | @Override |
| 10407 | protected void applyTransformation(float interpolatedTime, Transformation t) { |
| 10408 | float x = interpolatedTime; |
| 10409 | if (!mFadeIn) { |
| 10410 | x = 1.0f - x; // reverse the interpolation for fade out |
| 10411 | } |
| 10412 | if (x < 0.5) { |
| 10413 | // move the window out of the screen. |
| 10414 | t.getMatrix().setTranslate(mWidth, 0); |
| 10415 | } else { |
| 10416 | t.getMatrix().setTranslate(0, 0);// show |
| 10417 | t.setAlpha((x - 0.5f) * 2); |
| 10418 | } |
| 10419 | } |
| 10420 | |
| 10421 | @Override |
| 10422 | public void initialize(int width, int height, int parentWidth, int parentHeight) { |
| 10423 | // width is the screen width {@see AppWindowToken#stepAnimatinoLocked} |
| 10424 | mWidth = width; |
| 10425 | } |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 10426 | |
| 10427 | @Override |
Mitsuru Oshima | 5a2b91d | 2009-07-16 16:30:02 -0700 | [diff] [blame] | 10428 | public int getZAdjustment() { |
| 10429 | return Animation.ZORDER_TOP; |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 10430 | } |
| 10431 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10432 | } |