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 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 19 | import static android.view.WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW; |
| 20 | import static android.view.WindowManager.LayoutParams.FIRST_SUB_WINDOW; |
| 21 | import static android.view.WindowManager.LayoutParams.FLAG_BLUR_BEHIND; |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 22 | import static android.view.WindowManager.LayoutParams.FLAG_COMPATIBLE_WINDOW; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 23 | import static android.view.WindowManager.LayoutParams.FLAG_DIM_BEHIND; |
| 24 | import static android.view.WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON; |
Mitsuru Oshima | d2967e2 | 2009-07-20 14:01:43 -0700 | [diff] [blame] | 25 | 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] | 26 | import static android.view.WindowManager.LayoutParams.FLAG_SYSTEM_ERROR; |
| 27 | import static android.view.WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE; |
| 28 | import static android.view.WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 29 | import static android.view.WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 30 | import static android.view.WindowManager.LayoutParams.LAST_APPLICATION_WINDOW; |
| 31 | import static android.view.WindowManager.LayoutParams.LAST_SUB_WINDOW; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 32 | import static android.view.WindowManager.LayoutParams.MEMORY_TYPE_PUSH_BUFFERS; |
| 33 | import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_STARTING; |
| 34 | import static android.view.WindowManager.LayoutParams.TYPE_BASE_APPLICATION; |
| 35 | import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD; |
| 36 | import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 37 | import static android.view.WindowManager.LayoutParams.TYPE_WALLPAPER; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 38 | |
| 39 | import com.android.internal.app.IBatteryStats; |
| 40 | import com.android.internal.policy.PolicyManager; |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 41 | import com.android.internal.policy.impl.PhoneWindowManager; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 42 | import com.android.internal.view.IInputContext; |
| 43 | import com.android.internal.view.IInputMethodClient; |
| 44 | import com.android.internal.view.IInputMethodManager; |
Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 45 | import com.android.internal.view.WindowManagerPolicyThread; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 46 | import com.android.server.am.BatteryStatsService; |
| 47 | |
| 48 | import android.Manifest; |
| 49 | import android.app.ActivityManagerNative; |
| 50 | import android.app.IActivityManager; |
Jim Miller | d6b5705 | 2010-06-07 17:52:42 -0700 | [diff] [blame] | 51 | import android.app.admin.DevicePolicyManager; |
Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 52 | import android.content.BroadcastReceiver; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 53 | import android.content.Context; |
Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 54 | import android.content.Intent; |
| 55 | import android.content.IntentFilter; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 56 | import android.content.pm.ActivityInfo; |
| 57 | import android.content.pm.PackageManager; |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 58 | import android.content.res.CompatibilityInfo; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 59 | import android.content.res.Configuration; |
Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 60 | import android.graphics.Canvas; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 61 | import android.graphics.Matrix; |
Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 62 | import android.graphics.Paint; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 63 | import android.graphics.PixelFormat; |
| 64 | import android.graphics.Rect; |
| 65 | import android.graphics.Region; |
Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 66 | import android.graphics.Typeface; |
| 67 | import android.graphics.Paint.FontMetricsInt; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 68 | import android.os.BatteryStats; |
| 69 | import android.os.Binder; |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 70 | import android.os.Bundle; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 71 | import android.os.Debug; |
| 72 | import android.os.Handler; |
| 73 | import android.os.IBinder; |
| 74 | import android.os.LocalPowerManager; |
| 75 | import android.os.Looper; |
| 76 | import android.os.Message; |
| 77 | import android.os.Parcel; |
| 78 | import android.os.ParcelFileDescriptor; |
| 79 | import android.os.Power; |
| 80 | import android.os.PowerManager; |
| 81 | import android.os.Process; |
| 82 | import android.os.RemoteException; |
| 83 | import android.os.ServiceManager; |
| 84 | import android.os.SystemClock; |
| 85 | import android.os.SystemProperties; |
| 86 | import android.os.TokenWatcher; |
| 87 | import android.provider.Settings; |
Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 88 | import android.util.DisplayMetrics; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 89 | import android.util.EventLog; |
Jim Miller | d6b5705 | 2010-06-07 17:52:42 -0700 | [diff] [blame] | 90 | import android.util.Log; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 91 | import android.util.Slog; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 92 | import android.util.SparseIntArray; |
Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 93 | import android.util.TypedValue; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 94 | import android.view.Display; |
| 95 | import android.view.Gravity; |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 96 | import android.view.HapticFeedbackConstants; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 97 | import android.view.IApplicationToken; |
| 98 | import android.view.IOnKeyguardExitResult; |
| 99 | import android.view.IRotationWatcher; |
| 100 | import android.view.IWindow; |
| 101 | import android.view.IWindowManager; |
| 102 | import android.view.IWindowSession; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 103 | import android.view.InputChannel; |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 104 | import android.view.InputDevice; |
Jeff Brown | 6ec402b | 2010-07-28 15:48:59 -0700 | [diff] [blame] | 105 | import android.view.InputEvent; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 106 | import android.view.KeyEvent; |
| 107 | import android.view.MotionEvent; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 108 | import android.view.Surface; |
| 109 | import android.view.SurfaceSession; |
| 110 | import android.view.View; |
| 111 | import android.view.ViewTreeObserver; |
| 112 | import android.view.WindowManager; |
| 113 | import android.view.WindowManagerImpl; |
| 114 | import android.view.WindowManagerPolicy; |
Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 115 | import android.view.Surface.OutOfResourcesException; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 116 | import android.view.WindowManager.LayoutParams; |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 117 | import android.view.animation.AccelerateInterpolator; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 118 | import android.view.animation.Animation; |
| 119 | import android.view.animation.AnimationUtils; |
| 120 | import android.view.animation.Transformation; |
| 121 | |
Dianne Hackborn | b9fb170 | 2010-08-23 16:49:02 -0700 | [diff] [blame^] | 122 | import java.io.BufferedReader; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 123 | import java.io.BufferedWriter; |
Dianne Hackborn | b9fb170 | 2010-08-23 16:49:02 -0700 | [diff] [blame^] | 124 | import java.io.DataInputStream; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 125 | import java.io.File; |
| 126 | import java.io.FileDescriptor; |
Dianne Hackborn | b9fb170 | 2010-08-23 16:49:02 -0700 | [diff] [blame^] | 127 | import java.io.FileInputStream; |
| 128 | import java.io.FileNotFoundException; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 129 | import java.io.IOException; |
| 130 | import java.io.OutputStream; |
| 131 | import java.io.OutputStreamWriter; |
| 132 | import java.io.PrintWriter; |
| 133 | import java.io.StringWriter; |
| 134 | import java.net.Socket; |
| 135 | import java.util.ArrayList; |
| 136 | import java.util.HashMap; |
| 137 | import java.util.HashSet; |
| 138 | import java.util.Iterator; |
| 139 | import java.util.List; |
| 140 | |
| 141 | /** {@hide} */ |
Dianne Hackborn | ddca3ee | 2009-07-23 19:01:31 -0700 | [diff] [blame] | 142 | public class WindowManagerService extends IWindowManager.Stub |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 143 | implements Watchdog.Monitor { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 144 | static final String TAG = "WindowManager"; |
| 145 | static final boolean DEBUG = false; |
| 146 | static final boolean DEBUG_FOCUS = false; |
| 147 | static final boolean DEBUG_ANIM = false; |
Dianne Hackborn | 9b52a21 | 2009-12-11 14:51:35 -0800 | [diff] [blame] | 148 | static final boolean DEBUG_LAYOUT = false; |
Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 149 | static final boolean DEBUG_RESIZE = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 150 | static final boolean DEBUG_LAYERS = false; |
| 151 | static final boolean DEBUG_INPUT = false; |
| 152 | static final boolean DEBUG_INPUT_METHOD = false; |
| 153 | static final boolean DEBUG_VISIBILITY = false; |
Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 154 | static final boolean DEBUG_WINDOW_MOVEMENT = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 155 | static final boolean DEBUG_ORIENTATION = false; |
Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 156 | static final boolean DEBUG_CONFIGURATION = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 157 | static final boolean DEBUG_APP_TRANSITIONS = false; |
| 158 | static final boolean DEBUG_STARTING_WINDOW = false; |
| 159 | static final boolean DEBUG_REORDER = false; |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 160 | static final boolean DEBUG_WALLPAPER = false; |
Dianne Hackborn | ce73c1e | 2010-04-12 23:11:38 -0700 | [diff] [blame] | 161 | static final boolean DEBUG_FREEZE = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 162 | static final boolean SHOW_TRANSACTIONS = false; |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 163 | static final boolean HIDE_STACK_CRAWLS = true; |
Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 164 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 165 | static final boolean PROFILE_ORIENTATION = false; |
| 166 | static final boolean BLUR = true; |
Dave Bort | cfe6524 | 2009-04-09 14:51:04 -0700 | [diff] [blame] | 167 | static final boolean localLOGV = DEBUG; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 168 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 169 | /** How much to multiply the policy's type layer, to reserve room |
| 170 | * for multiple windows of the same type and Z-ordering adjustment |
| 171 | * with TYPE_LAYER_OFFSET. */ |
| 172 | static final int TYPE_LAYER_MULTIPLIER = 10000; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 173 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 174 | /** Offset from TYPE_LAYER_MULTIPLIER for moving a group of windows above |
| 175 | * or below others in the same layer. */ |
| 176 | static final int TYPE_LAYER_OFFSET = 1000; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 177 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 178 | /** How much to increment the layer for each window, to reserve room |
| 179 | * for effect surfaces between them. |
| 180 | */ |
| 181 | static final int WINDOW_LAYER_MULTIPLIER = 5; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 182 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 183 | /** The maximum length we will accept for a loaded animation duration: |
| 184 | * this is 10 seconds. |
| 185 | */ |
| 186 | static final int MAX_ANIMATION_DURATION = 10*1000; |
| 187 | |
| 188 | /** Amount of time (in milliseconds) to animate the dim surface from one |
| 189 | * value to another, when no window animation is driving it. |
| 190 | */ |
| 191 | static final int DEFAULT_DIM_DURATION = 200; |
| 192 | |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 193 | /** Amount of time (in milliseconds) to animate the fade-in-out transition for |
| 194 | * compatible windows. |
| 195 | */ |
| 196 | static final int DEFAULT_FADE_IN_OUT_DURATION = 400; |
| 197 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 198 | /** Adjustment to time to perform a dim, to make it more dramatic. |
| 199 | */ |
| 200 | static final int DIM_DURATION_MULTIPLIER = 6; |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 201 | |
| 202 | // Maximum number of milliseconds to wait for input event injection. |
| 203 | // FIXME is this value reasonable? |
| 204 | private static final int INJECTION_TIMEOUT_MILLIS = 30 * 1000; |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 205 | |
| 206 | // Default input dispatching timeout in nanoseconds. |
| 207 | private static final long DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS = 5000 * 1000000L; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 208 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 209 | static final int UPDATE_FOCUS_NORMAL = 0; |
| 210 | static final int UPDATE_FOCUS_WILL_ASSIGN_LAYERS = 1; |
| 211 | static final int UPDATE_FOCUS_PLACING_SURFACES = 2; |
| 212 | static final int UPDATE_FOCUS_WILL_PLACE_SURFACES = 3; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 213 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 214 | private static final String SYSTEM_SECURE = "ro.secure"; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 215 | private static final String SYSTEM_DEBUGGABLE = "ro.debuggable"; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 216 | |
| 217 | /** |
| 218 | * Condition waited on by {@link #reenableKeyguard} to know the call to |
| 219 | * the window policy has finished. |
Mike Lockwood | 983ee09 | 2009-11-22 01:42:24 -0500 | [diff] [blame] | 220 | * This is set to true only if mKeyguardTokenWatcher.acquired() has |
| 221 | * actually disabled the keyguard. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 222 | */ |
Mike Lockwood | 983ee09 | 2009-11-22 01:42:24 -0500 | [diff] [blame] | 223 | private boolean mKeyguardDisabled = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 224 | |
Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 225 | private static final int ALLOW_DISABLE_YES = 1; |
| 226 | private static final int ALLOW_DISABLE_NO = 0; |
| 227 | private static final int ALLOW_DISABLE_UNKNOWN = -1; // check with DevicePolicyManager |
| 228 | private int mAllowDisableKeyguard = ALLOW_DISABLE_UNKNOWN; // sync'd by mKeyguardTokenWatcher |
| 229 | |
Mike Lockwood | 983ee09 | 2009-11-22 01:42:24 -0500 | [diff] [blame] | 230 | final TokenWatcher mKeyguardTokenWatcher = new TokenWatcher( |
| 231 | new Handler(), "WindowManagerService.mKeyguardTokenWatcher") { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 232 | public void acquired() { |
Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 233 | if (shouldAllowDisableKeyguard()) { |
| 234 | mPolicy.enableKeyguard(false); |
| 235 | mKeyguardDisabled = true; |
| 236 | } else { |
| 237 | Log.v(TAG, "Not disabling keyguard since device policy is enforced"); |
| 238 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 239 | } |
| 240 | public void released() { |
Dianne Hackborn | a33e3f7 | 2009-09-29 17:28:24 -0700 | [diff] [blame] | 241 | mPolicy.enableKeyguard(true); |
Mike Lockwood | 983ee09 | 2009-11-22 01:42:24 -0500 | [diff] [blame] | 242 | synchronized (mKeyguardTokenWatcher) { |
| 243 | mKeyguardDisabled = false; |
| 244 | mKeyguardTokenWatcher.notifyAll(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 245 | } |
| 246 | } |
| 247 | }; |
| 248 | |
Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 249 | final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() { |
| 250 | @Override |
| 251 | public void onReceive(Context context, Intent intent) { |
| 252 | mPolicy.enableKeyguard(true); |
| 253 | synchronized(mKeyguardTokenWatcher) { |
| 254 | // lazily evaluate this next time we're asked to disable keyguard |
| 255 | mAllowDisableKeyguard = ALLOW_DISABLE_UNKNOWN; |
| 256 | mKeyguardDisabled = false; |
| 257 | } |
| 258 | } |
| 259 | }; |
| 260 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 261 | final Context mContext; |
| 262 | |
| 263 | final boolean mHaveInputMethods; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 264 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 265 | final boolean mLimitedAlphaCompositing; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 266 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 267 | final WindowManagerPolicy mPolicy = PolicyManager.makeNewWindowManager(); |
| 268 | |
| 269 | final IActivityManager mActivityManager; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 270 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 271 | final IBatteryStats mBatteryStats; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 272 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 273 | /** |
| 274 | * All currently active sessions with clients. |
| 275 | */ |
| 276 | final HashSet<Session> mSessions = new HashSet<Session>(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 277 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 278 | /** |
| 279 | * Mapping from an IWindow IBinder to the server's Window object. |
| 280 | * This is also used as the lock for all of our state. |
| 281 | */ |
| 282 | final HashMap<IBinder, WindowState> mWindowMap = new HashMap<IBinder, WindowState>(); |
| 283 | |
| 284 | /** |
| 285 | * Mapping from a token IBinder to a WindowToken object. |
| 286 | */ |
| 287 | final HashMap<IBinder, WindowToken> mTokenMap = |
| 288 | new HashMap<IBinder, WindowToken>(); |
| 289 | |
| 290 | /** |
| 291 | * The same tokens as mTokenMap, stored in a list for efficient iteration |
| 292 | * over them. |
| 293 | */ |
| 294 | final ArrayList<WindowToken> mTokenList = new ArrayList<WindowToken>(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 295 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 296 | /** |
| 297 | * Window tokens that are in the process of exiting, but still |
| 298 | * on screen for animations. |
| 299 | */ |
| 300 | final ArrayList<WindowToken> mExitingTokens = new ArrayList<WindowToken>(); |
| 301 | |
| 302 | /** |
| 303 | * Z-ordered (bottom-most first) list of all application tokens, for |
| 304 | * controlling the ordering of windows in different applications. This |
| 305 | * contains WindowToken objects. |
| 306 | */ |
| 307 | final ArrayList<AppWindowToken> mAppTokens = new ArrayList<AppWindowToken>(); |
| 308 | |
| 309 | /** |
| 310 | * Application tokens that are in the process of exiting, but still |
| 311 | * on screen for animations. |
| 312 | */ |
| 313 | final ArrayList<AppWindowToken> mExitingAppTokens = new ArrayList<AppWindowToken>(); |
| 314 | |
| 315 | /** |
| 316 | * List of window tokens that have finished starting their application, |
| 317 | * and now need to have the policy remove their windows. |
| 318 | */ |
| 319 | final ArrayList<AppWindowToken> mFinishedStarting = new ArrayList<AppWindowToken>(); |
| 320 | |
| 321 | /** |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 322 | * This was the app token that was used to retrieve the last enter |
| 323 | * animation. It will be used for the next exit animation. |
| 324 | */ |
| 325 | AppWindowToken mLastEnterAnimToken; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 326 | |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 327 | /** |
| 328 | * These were the layout params used to retrieve the last enter animation. |
| 329 | * They will be used for the next exit animation. |
| 330 | */ |
| 331 | LayoutParams mLastEnterAnimParams; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 332 | |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 333 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 334 | * Z-ordered (bottom-most first) list of all Window objects. |
| 335 | */ |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 336 | final ArrayList<WindowState> mWindows = new ArrayList<WindowState>(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 337 | |
| 338 | /** |
| 339 | * Windows that are being resized. Used so we can tell the client about |
| 340 | * the resize after closing the transaction in which we resized the |
| 341 | * underlying surface. |
| 342 | */ |
| 343 | final ArrayList<WindowState> mResizingWindows = new ArrayList<WindowState>(); |
| 344 | |
| 345 | /** |
| 346 | * Windows whose animations have ended and now must be removed. |
| 347 | */ |
| 348 | final ArrayList<WindowState> mPendingRemove = new ArrayList<WindowState>(); |
| 349 | |
| 350 | /** |
| 351 | * Windows whose surface should be destroyed. |
| 352 | */ |
| 353 | final ArrayList<WindowState> mDestroySurface = new ArrayList<WindowState>(); |
| 354 | |
| 355 | /** |
| 356 | * Windows that have lost input focus and are waiting for the new |
| 357 | * focus window to be displayed before they are told about this. |
| 358 | */ |
| 359 | ArrayList<WindowState> mLosingFocus = new ArrayList<WindowState>(); |
| 360 | |
| 361 | /** |
| 362 | * This is set when we have run out of memory, and will either be an empty |
| 363 | * list or contain windows that need to be force removed. |
| 364 | */ |
| 365 | ArrayList<WindowState> mForceRemoves; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 366 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 367 | IInputMethodManager mInputMethodManager; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 368 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 369 | SurfaceSession mFxSession; |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 370 | private DimAnimator mDimAnimator = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 371 | Surface mBlurSurface; |
| 372 | boolean mBlurShown; |
Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 373 | Watermark mWatermark; |
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 | int mTransactionSequence = 0; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 376 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 377 | final float[] mTmpFloats = new float[9]; |
| 378 | |
| 379 | boolean mSafeMode; |
| 380 | boolean mDisplayEnabled = false; |
| 381 | boolean mSystemBooted = false; |
Christopher Tate | b696aee | 2010-04-02 19:08:30 -0700 | [diff] [blame] | 382 | int mInitialDisplayWidth = 0; |
| 383 | int mInitialDisplayHeight = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 384 | int mRotation = 0; |
| 385 | int mRequestedRotation = 0; |
| 386 | int mForcedAppOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
Dianne Hackborn | 321ae68 | 2009-03-27 16:16:03 -0700 | [diff] [blame] | 387 | int mLastRotationFlags; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 388 | ArrayList<IRotationWatcher> mRotationWatchers |
| 389 | = new ArrayList<IRotationWatcher>(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 390 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 391 | boolean mLayoutNeeded = true; |
| 392 | boolean mAnimationPending = false; |
| 393 | boolean mDisplayFrozen = false; |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 394 | boolean mWaitingForConfig = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 395 | boolean mWindowsFreezingScreen = false; |
| 396 | long mFreezeGcPending = 0; |
| 397 | int mAppsFreezingScreen = 0; |
| 398 | |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 399 | int mLayoutSeq = 0; |
| 400 | |
Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 401 | // State while inside of layoutAndPlaceSurfacesLocked(). |
| 402 | boolean mFocusMayChange; |
| 403 | |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 404 | Configuration mCurConfiguration = new Configuration(); |
| 405 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 406 | // This is held as long as we have the screen frozen, to give us time to |
| 407 | // perform a rotation animation when turning off shows the lock screen which |
| 408 | // changes the orientation. |
| 409 | PowerManager.WakeLock mScreenFrozenLock; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 410 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 411 | // State management of app transitions. When we are preparing for a |
| 412 | // transition, mNextAppTransition will be the kind of transition to |
| 413 | // perform or TRANSIT_NONE if we are not waiting. If we are waiting, |
| 414 | // mOpeningApps and mClosingApps are the lists of tokens that will be |
| 415 | // made visible or hidden at the next transition. |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 416 | int mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 417 | String mNextAppTransitionPackage; |
| 418 | int mNextAppTransitionEnter; |
| 419 | int mNextAppTransitionExit; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 420 | boolean mAppTransitionReady = false; |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 421 | boolean mAppTransitionRunning = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 422 | boolean mAppTransitionTimeout = false; |
| 423 | boolean mStartingIconInTransition = false; |
| 424 | boolean mSkipAppTransitionAnimation = false; |
| 425 | final ArrayList<AppWindowToken> mOpeningApps = new ArrayList<AppWindowToken>(); |
| 426 | final ArrayList<AppWindowToken> mClosingApps = new ArrayList<AppWindowToken>(); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 427 | final ArrayList<AppWindowToken> mToTopApps = new ArrayList<AppWindowToken>(); |
| 428 | final ArrayList<AppWindowToken> mToBottomApps = new ArrayList<AppWindowToken>(); |
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 | Display mDisplay; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 431 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 432 | H mH = new H(); |
| 433 | |
| 434 | WindowState mCurrentFocus = null; |
| 435 | WindowState mLastFocus = null; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 436 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 437 | // This just indicates the window the input method is on top of, not |
| 438 | // necessarily the window its input is going to. |
| 439 | WindowState mInputMethodTarget = null; |
| 440 | WindowState mUpcomingInputMethodTarget = null; |
| 441 | boolean mInputMethodTargetWaitingAnim; |
| 442 | int mInputMethodAnimLayerAdjustment; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 443 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 444 | WindowState mInputMethodWindow = null; |
| 445 | final ArrayList<WindowState> mInputMethodDialogs = new ArrayList<WindowState>(); |
| 446 | |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 447 | final ArrayList<WindowToken> mWallpaperTokens = new ArrayList<WindowToken>(); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 448 | |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 449 | // If non-null, this is the currently visible window that is associated |
| 450 | // with the wallpaper. |
| 451 | WindowState mWallpaperTarget = null; |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 452 | // If non-null, we are in the middle of animating from one wallpaper target |
| 453 | // to another, and this is the lower one in Z-order. |
| 454 | WindowState mLowerWallpaperTarget = null; |
| 455 | // If non-null, we are in the middle of animating from one wallpaper target |
| 456 | // to another, and this is the higher one in Z-order. |
| 457 | WindowState mUpperWallpaperTarget = null; |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 458 | int mWallpaperAnimLayerAdjustment; |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 459 | float mLastWallpaperX = -1; |
| 460 | float mLastWallpaperY = -1; |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 461 | float mLastWallpaperXStep = -1; |
| 462 | float mLastWallpaperYStep = -1; |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 463 | // This is set when we are waiting for a wallpaper to tell us it is done |
| 464 | // changing its scroll position. |
| 465 | WindowState mWaitingOnWallpaper; |
| 466 | // The last time we had a timeout when waiting for a wallpaper. |
| 467 | long mLastWallpaperTimeoutTime; |
| 468 | // We give a wallpaper up to 150ms to finish scrolling. |
| 469 | static final long WALLPAPER_TIMEOUT = 150; |
| 470 | // Time we wait after a timeout before trying to wait again. |
| 471 | static final long WALLPAPER_TIMEOUT_RECOVERY = 10000; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 472 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 473 | AppWindowToken mFocusedApp = null; |
| 474 | |
| 475 | PowerManagerService mPowerManager; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 476 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 477 | float mWindowAnimationScale = 1.0f; |
| 478 | float mTransitionAnimationScale = 1.0f; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 479 | |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 480 | final InputManager mInputManager; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 481 | |
| 482 | // Who is holding the screen on. |
| 483 | Session mHoldingScreenOn; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 484 | PowerManager.WakeLock mHoldingScreenWakeLock; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 485 | |
Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 486 | boolean mTurnOnScreen; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 487 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 488 | /** |
| 489 | * Whether the UI is currently running in touch mode (not showing |
| 490 | * navigational focus because the user is directly pressing the screen). |
| 491 | */ |
| 492 | boolean mInTouchMode = false; |
| 493 | |
| 494 | private ViewServer mViewServer; |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 495 | private ArrayList<WindowChangeListener> mWindowChangeListeners = |
| 496 | new ArrayList<WindowChangeListener>(); |
| 497 | private boolean mWindowsChanged = false; |
| 498 | |
| 499 | public interface WindowChangeListener { |
| 500 | public void windowsChanged(); |
Konstantin Lopyrev | 6e0f65f | 2010-07-14 14:55:33 -0700 | [diff] [blame] | 501 | public void focusChanged(); |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 502 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 503 | |
Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 504 | final Configuration mTempConfiguration = new Configuration(); |
Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 505 | int mScreenLayout = Configuration.SCREENLAYOUT_SIZE_UNDEFINED; |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 506 | |
| 507 | // The frame use to limit the size of the app running in compatibility mode. |
| 508 | Rect mCompatibleScreenFrame = new Rect(); |
| 509 | // The surface used to fill the outer rim of the app running in compatibility mode. |
| 510 | Surface mBackgroundFillerSurface = null; |
| 511 | boolean mBackgroundFillerShown = false; |
| 512 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 513 | public static WindowManagerService main(Context context, |
| 514 | PowerManagerService pm, boolean haveInputMethods) { |
| 515 | WMThread thr = new WMThread(context, pm, haveInputMethods); |
| 516 | thr.start(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 517 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 518 | synchronized (thr) { |
| 519 | while (thr.mService == null) { |
| 520 | try { |
| 521 | thr.wait(); |
| 522 | } catch (InterruptedException e) { |
| 523 | } |
| 524 | } |
| 525 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 526 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 527 | return thr.mService; |
| 528 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 529 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 530 | static class WMThread extends Thread { |
| 531 | WindowManagerService mService; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 532 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 533 | private final Context mContext; |
| 534 | private final PowerManagerService mPM; |
| 535 | private final boolean mHaveInputMethods; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 536 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 537 | public WMThread(Context context, PowerManagerService pm, |
| 538 | boolean haveInputMethods) { |
| 539 | super("WindowManager"); |
| 540 | mContext = context; |
| 541 | mPM = pm; |
| 542 | mHaveInputMethods = haveInputMethods; |
| 543 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 544 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 545 | public void run() { |
| 546 | Looper.prepare(); |
| 547 | WindowManagerService s = new WindowManagerService(mContext, mPM, |
| 548 | mHaveInputMethods); |
| 549 | android.os.Process.setThreadPriority( |
| 550 | android.os.Process.THREAD_PRIORITY_DISPLAY); |
Christopher Tate | 160edb3 | 2010-06-30 17:46:30 -0700 | [diff] [blame] | 551 | android.os.Process.setCanSelfBackground(false); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 552 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 553 | synchronized (this) { |
| 554 | mService = s; |
| 555 | notifyAll(); |
| 556 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 557 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 558 | Looper.loop(); |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | static class PolicyThread extends Thread { |
| 563 | private final WindowManagerPolicy mPolicy; |
| 564 | private final WindowManagerService mService; |
| 565 | private final Context mContext; |
| 566 | private final PowerManagerService mPM; |
| 567 | boolean mRunning = false; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 568 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 569 | public PolicyThread(WindowManagerPolicy policy, |
| 570 | WindowManagerService service, Context context, |
| 571 | PowerManagerService pm) { |
| 572 | super("WindowManagerPolicy"); |
| 573 | mPolicy = policy; |
| 574 | mService = service; |
| 575 | mContext = context; |
| 576 | mPM = pm; |
| 577 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 578 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 579 | public void run() { |
| 580 | Looper.prepare(); |
Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 581 | WindowManagerPolicyThread.set(this, Looper.myLooper()); |
| 582 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 583 | //Looper.myLooper().setMessageLogging(new LogPrinter( |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 584 | // Log.VERBOSE, "WindowManagerPolicy", Log.LOG_ID_SYSTEM)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 585 | android.os.Process.setThreadPriority( |
| 586 | android.os.Process.THREAD_PRIORITY_FOREGROUND); |
Christopher Tate | 160edb3 | 2010-06-30 17:46:30 -0700 | [diff] [blame] | 587 | android.os.Process.setCanSelfBackground(false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 588 | mPolicy.init(mContext, mService, mPM); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 589 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 590 | synchronized (this) { |
| 591 | mRunning = true; |
| 592 | notifyAll(); |
| 593 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 594 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 595 | Looper.loop(); |
| 596 | } |
| 597 | } |
| 598 | |
| 599 | private WindowManagerService(Context context, PowerManagerService pm, |
| 600 | boolean haveInputMethods) { |
| 601 | mContext = context; |
| 602 | mHaveInputMethods = haveInputMethods; |
| 603 | mLimitedAlphaCompositing = context.getResources().getBoolean( |
| 604 | com.android.internal.R.bool.config_sf_limitedAlpha); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 605 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 606 | mPowerManager = pm; |
| 607 | mPowerManager.setPolicy(mPolicy); |
| 608 | PowerManager pmc = (PowerManager)context.getSystemService(Context.POWER_SERVICE); |
| 609 | mScreenFrozenLock = pmc.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, |
| 610 | "SCREEN_FROZEN"); |
| 611 | mScreenFrozenLock.setReferenceCounted(false); |
| 612 | |
| 613 | mActivityManager = ActivityManagerNative.getDefault(); |
| 614 | mBatteryStats = BatteryStatsService.getService(); |
| 615 | |
| 616 | // Get persisted window scale setting |
| 617 | mWindowAnimationScale = Settings.System.getFloat(context.getContentResolver(), |
| 618 | Settings.System.WINDOW_ANIMATION_SCALE, mWindowAnimationScale); |
| 619 | mTransitionAnimationScale = Settings.System.getFloat(context.getContentResolver(), |
| 620 | Settings.System.TRANSITION_ANIMATION_SCALE, mTransitionAnimationScale); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 621 | |
Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 622 | // Track changes to DevicePolicyManager state so we can enable/disable keyguard. |
| 623 | IntentFilter filter = new IntentFilter(); |
| 624 | filter.addAction(DevicePolicyManager.ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED); |
| 625 | mContext.registerReceiver(mBroadcastReceiver, filter); |
| 626 | |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 627 | mHoldingScreenWakeLock = pmc.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK, |
| 628 | "KEEP_SCREEN_ON_FLAG"); |
| 629 | mHoldingScreenWakeLock.setReferenceCounted(false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 630 | |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 631 | mInputManager = new InputManager(context, this); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 632 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 633 | PolicyThread thr = new PolicyThread(mPolicy, this, context, pm); |
| 634 | thr.start(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 635 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 636 | synchronized (thr) { |
| 637 | while (!thr.mRunning) { |
| 638 | try { |
| 639 | thr.wait(); |
| 640 | } catch (InterruptedException e) { |
| 641 | } |
| 642 | } |
| 643 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 644 | |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 645 | mInputManager.start(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 646 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 647 | // Add ourself to the Watchdog monitors. |
| 648 | Watchdog.getInstance().addMonitor(this); |
| 649 | } |
| 650 | |
| 651 | @Override |
| 652 | public boolean onTransact(int code, Parcel data, Parcel reply, int flags) |
| 653 | throws RemoteException { |
| 654 | try { |
| 655 | return super.onTransact(code, data, reply, flags); |
| 656 | } catch (RuntimeException e) { |
| 657 | // The window manager only throws security exceptions, so let's |
| 658 | // log all others. |
| 659 | if (!(e instanceof SecurityException)) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 660 | Slog.e(TAG, "Window Manager Crash", e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 661 | } |
| 662 | throw e; |
| 663 | } |
| 664 | } |
| 665 | |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 666 | private void placeWindowAfter(WindowState pos, WindowState window) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 667 | final int i = mWindows.indexOf(pos); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 668 | if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 669 | TAG, "Adding window " + window + " at " |
| 670 | + (i+1) + " of " + mWindows.size() + " (after " + pos + ")"); |
| 671 | mWindows.add(i+1, window); |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 672 | mWindowsChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 673 | } |
| 674 | |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 675 | private void placeWindowBefore(WindowState pos, WindowState window) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 676 | final int i = mWindows.indexOf(pos); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 677 | if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 678 | TAG, "Adding window " + window + " at " |
| 679 | + i + " of " + mWindows.size() + " (before " + pos + ")"); |
| 680 | mWindows.add(i, window); |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 681 | mWindowsChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 682 | } |
| 683 | |
| 684 | //This method finds out the index of a window that has the same app token as |
| 685 | //win. used for z ordering the windows in mWindows |
| 686 | private int findIdxBasedOnAppTokens(WindowState win) { |
| 687 | //use a local variable to cache mWindows |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 688 | ArrayList<WindowState> localmWindows = mWindows; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 689 | int jmax = localmWindows.size(); |
| 690 | if(jmax == 0) { |
| 691 | return -1; |
| 692 | } |
| 693 | for(int j = (jmax-1); j >= 0; j--) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 694 | WindowState wentry = localmWindows.get(j); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 695 | if(wentry.mAppToken == win.mAppToken) { |
| 696 | return j; |
| 697 | } |
| 698 | } |
| 699 | return -1; |
| 700 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 701 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 702 | private void addWindowToListInOrderLocked(WindowState win, boolean addToToken) { |
| 703 | final IWindow client = win.mClient; |
| 704 | final WindowToken token = win.mToken; |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 705 | final ArrayList<WindowState> localmWindows = mWindows; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 706 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 707 | final int N = localmWindows.size(); |
| 708 | final WindowState attached = win.mAttachedWindow; |
| 709 | int i; |
| 710 | if (attached == null) { |
| 711 | int tokenWindowsPos = token.windows.size(); |
| 712 | if (token.appWindowToken != null) { |
| 713 | int index = tokenWindowsPos-1; |
| 714 | if (index >= 0) { |
| 715 | // If this application has existing windows, we |
| 716 | // simply place the new window on top of them... but |
| 717 | // keep the starting window on top. |
| 718 | if (win.mAttrs.type == TYPE_BASE_APPLICATION) { |
| 719 | // Base windows go behind everything else. |
| 720 | placeWindowBefore(token.windows.get(0), win); |
| 721 | tokenWindowsPos = 0; |
| 722 | } else { |
| 723 | AppWindowToken atoken = win.mAppToken; |
| 724 | if (atoken != null && |
| 725 | token.windows.get(index) == atoken.startingWindow) { |
| 726 | placeWindowBefore(token.windows.get(index), win); |
| 727 | tokenWindowsPos--; |
| 728 | } else { |
| 729 | int newIdx = findIdxBasedOnAppTokens(win); |
| 730 | if(newIdx != -1) { |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 731 | //there is a window above this one associated with the same |
| 732 | //apptoken note that the window could be a floating window |
| 733 | //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] | 734 | //windows associated with this token. |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 735 | if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v( |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 736 | TAG, "Adding window " + win + " at " |
| 737 | + (newIdx+1) + " of " + N); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 738 | localmWindows.add(newIdx+1, win); |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 739 | mWindowsChanged = true; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 740 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 741 | } |
| 742 | } |
| 743 | } else { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 744 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 745 | TAG, "Figuring out where to add app window " |
| 746 | + client.asBinder() + " (token=" + token + ")"); |
| 747 | // Figure out where the window should go, based on the |
| 748 | // order of applications. |
| 749 | final int NA = mAppTokens.size(); |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 750 | WindowState pos = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 751 | for (i=NA-1; i>=0; i--) { |
| 752 | AppWindowToken t = mAppTokens.get(i); |
| 753 | if (t == token) { |
| 754 | i--; |
| 755 | break; |
| 756 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 757 | |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 758 | // We haven't reached the token yet; if this token |
| 759 | // is not going to the bottom and has windows, we can |
| 760 | // use it as an anchor for when we do reach the token. |
| 761 | if (!t.sendingToBottom && t.windows.size() > 0) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 762 | pos = t.windows.get(0); |
| 763 | } |
| 764 | } |
| 765 | // We now know the index into the apps. If we found |
| 766 | // an app window above, that gives us the position; else |
| 767 | // we need to look some more. |
| 768 | if (pos != null) { |
| 769 | // Move behind any windows attached to this one. |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 770 | WindowToken atoken = mTokenMap.get(pos.mClient.asBinder()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 771 | if (atoken != null) { |
| 772 | final int NC = atoken.windows.size(); |
| 773 | if (NC > 0) { |
| 774 | WindowState bottom = atoken.windows.get(0); |
| 775 | if (bottom.mSubLayer < 0) { |
| 776 | pos = bottom; |
| 777 | } |
| 778 | } |
| 779 | } |
| 780 | placeWindowBefore(pos, win); |
| 781 | } else { |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 782 | // Continue looking down until we find the first |
| 783 | // token that has windows. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 784 | while (i >= 0) { |
| 785 | AppWindowToken t = mAppTokens.get(i); |
| 786 | final int NW = t.windows.size(); |
| 787 | if (NW > 0) { |
| 788 | pos = t.windows.get(NW-1); |
| 789 | break; |
| 790 | } |
| 791 | i--; |
| 792 | } |
| 793 | if (pos != null) { |
| 794 | // Move in front of any windows attached to this |
| 795 | // one. |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 796 | WindowToken atoken = mTokenMap.get(pos.mClient.asBinder()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 797 | if (atoken != null) { |
| 798 | final int NC = atoken.windows.size(); |
| 799 | if (NC > 0) { |
| 800 | WindowState top = atoken.windows.get(NC-1); |
| 801 | if (top.mSubLayer >= 0) { |
| 802 | pos = top; |
| 803 | } |
| 804 | } |
| 805 | } |
| 806 | placeWindowAfter(pos, win); |
| 807 | } else { |
| 808 | // Just search for the start of this layer. |
| 809 | final int myLayer = win.mBaseLayer; |
| 810 | for (i=0; i<N; i++) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 811 | WindowState w = localmWindows.get(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 812 | if (w.mBaseLayer > myLayer) { |
| 813 | break; |
| 814 | } |
| 815 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 816 | if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v( |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 817 | TAG, "Adding window " + win + " at " |
| 818 | + i + " of " + N); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 819 | localmWindows.add(i, win); |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 820 | mWindowsChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 821 | } |
| 822 | } |
| 823 | } |
| 824 | } else { |
| 825 | // Figure out where window should go, based on layer. |
| 826 | final int myLayer = win.mBaseLayer; |
| 827 | for (i=N-1; i>=0; i--) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 828 | if (localmWindows.get(i).mBaseLayer <= myLayer) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 829 | i++; |
| 830 | break; |
| 831 | } |
| 832 | } |
| 833 | if (i < 0) i = 0; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 834 | if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v( |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 835 | TAG, "Adding window " + win + " at " |
| 836 | + i + " of " + N); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 837 | localmWindows.add(i, win); |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 838 | mWindowsChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 839 | } |
| 840 | if (addToToken) { |
| 841 | token.windows.add(tokenWindowsPos, win); |
| 842 | } |
| 843 | |
| 844 | } else { |
| 845 | // Figure out this window's ordering relative to the window |
| 846 | // it is attached to. |
| 847 | final int NA = token.windows.size(); |
| 848 | final int sublayer = win.mSubLayer; |
| 849 | int largestSublayer = Integer.MIN_VALUE; |
| 850 | WindowState windowWithLargestSublayer = null; |
| 851 | for (i=0; i<NA; i++) { |
| 852 | WindowState w = token.windows.get(i); |
| 853 | final int wSublayer = w.mSubLayer; |
| 854 | if (wSublayer >= largestSublayer) { |
| 855 | largestSublayer = wSublayer; |
| 856 | windowWithLargestSublayer = w; |
| 857 | } |
| 858 | if (sublayer < 0) { |
| 859 | // For negative sublayers, we go below all windows |
| 860 | // in the same sublayer. |
| 861 | if (wSublayer >= sublayer) { |
| 862 | if (addToToken) { |
| 863 | token.windows.add(i, win); |
| 864 | } |
| 865 | placeWindowBefore( |
| 866 | wSublayer >= 0 ? attached : w, win); |
| 867 | break; |
| 868 | } |
| 869 | } else { |
| 870 | // For positive sublayers, we go above all windows |
| 871 | // in the same sublayer. |
| 872 | if (wSublayer > sublayer) { |
| 873 | if (addToToken) { |
| 874 | token.windows.add(i, win); |
| 875 | } |
| 876 | placeWindowBefore(w, win); |
| 877 | break; |
| 878 | } |
| 879 | } |
| 880 | } |
| 881 | if (i >= NA) { |
| 882 | if (addToToken) { |
| 883 | token.windows.add(win); |
| 884 | } |
| 885 | if (sublayer < 0) { |
| 886 | placeWindowBefore(attached, win); |
| 887 | } else { |
| 888 | placeWindowAfter(largestSublayer >= 0 |
| 889 | ? windowWithLargestSublayer |
| 890 | : attached, |
| 891 | win); |
| 892 | } |
| 893 | } |
| 894 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 895 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 896 | if (win.mAppToken != null && addToToken) { |
| 897 | win.mAppToken.allAppWindows.add(win); |
| 898 | } |
| 899 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 900 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 901 | static boolean canBeImeTarget(WindowState w) { |
| 902 | final int fl = w.mAttrs.flags |
| 903 | & (FLAG_NOT_FOCUSABLE|FLAG_ALT_FOCUSABLE_IM); |
| 904 | if (fl == 0 || fl == (FLAG_NOT_FOCUSABLE|FLAG_ALT_FOCUSABLE_IM)) { |
| 905 | return w.isVisibleOrAdding(); |
| 906 | } |
| 907 | return false; |
| 908 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 909 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 910 | int findDesiredInputMethodWindowIndexLocked(boolean willMove) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 911 | final ArrayList<WindowState> localmWindows = mWindows; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 912 | final int N = localmWindows.size(); |
| 913 | WindowState w = null; |
| 914 | int i = N; |
| 915 | while (i > 0) { |
| 916 | i--; |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 917 | w = localmWindows.get(i); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 918 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 919 | //Slog.i(TAG, "Checking window @" + i + " " + w + " fl=0x" |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 920 | // + Integer.toHexString(w.mAttrs.flags)); |
| 921 | if (canBeImeTarget(w)) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 922 | //Slog.i(TAG, "Putting input method here!"); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 923 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 924 | // Yet more tricksyness! If this window is a "starting" |
| 925 | // window, we do actually want to be on top of it, but |
| 926 | // it is not -really- where input will go. So if the caller |
| 927 | // is not actually looking to move the IME, look down below |
| 928 | // for a real window to target... |
| 929 | if (!willMove |
| 930 | && w.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING |
| 931 | && i > 0) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 932 | WindowState wb = localmWindows.get(i-1); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 933 | if (wb.mAppToken == w.mAppToken && canBeImeTarget(wb)) { |
| 934 | i--; |
| 935 | w = wb; |
| 936 | } |
| 937 | } |
| 938 | break; |
| 939 | } |
| 940 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 941 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 942 | mUpcomingInputMethodTarget = w; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 943 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 944 | 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] | 945 | + w + " willMove=" + willMove); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 946 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 947 | if (willMove && w != null) { |
| 948 | final WindowState curTarget = mInputMethodTarget; |
| 949 | if (curTarget != null && curTarget.mAppToken != null) { |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 950 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 951 | // Now some fun for dealing with window animations that |
| 952 | // modify the Z order. We need to look at all windows below |
| 953 | // the current target that are in this app, finding the highest |
| 954 | // visible one in layering. |
| 955 | AppWindowToken token = curTarget.mAppToken; |
| 956 | WindowState highestTarget = null; |
| 957 | int highestPos = 0; |
| 958 | if (token.animating || token.animation != null) { |
| 959 | int pos = 0; |
| 960 | pos = localmWindows.indexOf(curTarget); |
| 961 | while (pos >= 0) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 962 | WindowState win = localmWindows.get(pos); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 963 | if (win.mAppToken != token) { |
| 964 | break; |
| 965 | } |
| 966 | if (!win.mRemoved) { |
| 967 | if (highestTarget == null || win.mAnimLayer > |
| 968 | highestTarget.mAnimLayer) { |
| 969 | highestTarget = win; |
| 970 | highestPos = pos; |
| 971 | } |
| 972 | } |
| 973 | pos--; |
| 974 | } |
| 975 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 976 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 977 | if (highestTarget != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 978 | if (DEBUG_INPUT_METHOD) Slog.v(TAG, "mNextAppTransition=" |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 979 | + mNextAppTransition + " " + highestTarget |
| 980 | + " animating=" + highestTarget.isAnimating() |
| 981 | + " layer=" + highestTarget.mAnimLayer |
| 982 | + " new layer=" + w.mAnimLayer); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 983 | |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 984 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 985 | // If we are currently setting up for an animation, |
| 986 | // hold everything until we can find out what will happen. |
| 987 | mInputMethodTargetWaitingAnim = true; |
| 988 | mInputMethodTarget = highestTarget; |
| 989 | return highestPos + 1; |
| 990 | } else if (highestTarget.isAnimating() && |
| 991 | highestTarget.mAnimLayer > w.mAnimLayer) { |
| 992 | // If the window we are currently targeting is involved |
| 993 | // with an animation, and it is on top of the next target |
| 994 | // we will be over, then hold off on moving until |
| 995 | // that is done. |
| 996 | mInputMethodTarget = highestTarget; |
| 997 | return highestPos + 1; |
| 998 | } |
| 999 | } |
| 1000 | } |
| 1001 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1002 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1003 | //Slog.i(TAG, "Placing input method @" + (i+1)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1004 | if (w != null) { |
| 1005 | if (willMove) { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 1006 | if (DEBUG_INPUT_METHOD) { |
| 1007 | RuntimeException e = null; |
| 1008 | if (!HIDE_STACK_CRAWLS) { |
| 1009 | e = new RuntimeException(); |
| 1010 | e.fillInStackTrace(); |
| 1011 | } |
| 1012 | Slog.w(TAG, "Moving IM target from " |
| 1013 | + mInputMethodTarget + " to " + w, e); |
| 1014 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1015 | mInputMethodTarget = w; |
| 1016 | if (w.mAppToken != null) { |
| 1017 | setInputMethodAnimLayerAdjustment(w.mAppToken.animLayerAdjustment); |
| 1018 | } else { |
| 1019 | setInputMethodAnimLayerAdjustment(0); |
| 1020 | } |
| 1021 | } |
| 1022 | return i+1; |
| 1023 | } |
| 1024 | if (willMove) { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 1025 | if (DEBUG_INPUT_METHOD) { |
| 1026 | RuntimeException e = null; |
| 1027 | if (!HIDE_STACK_CRAWLS) { |
| 1028 | e = new RuntimeException(); |
| 1029 | e.fillInStackTrace(); |
| 1030 | } |
| 1031 | Slog.w(TAG, "Moving IM target from " |
| 1032 | + mInputMethodTarget + " to null", e); |
| 1033 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1034 | mInputMethodTarget = null; |
| 1035 | setInputMethodAnimLayerAdjustment(0); |
| 1036 | } |
| 1037 | return -1; |
| 1038 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1039 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1040 | void addInputMethodWindowToListLocked(WindowState win) { |
| 1041 | int pos = findDesiredInputMethodWindowIndexLocked(true); |
| 1042 | if (pos >= 0) { |
| 1043 | win.mTargetAppToken = mInputMethodTarget.mAppToken; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1044 | if (DEBUG_WINDOW_MOVEMENT) Slog.v( |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 1045 | TAG, "Adding input method window " + win + " at " + pos); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1046 | mWindows.add(pos, win); |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 1047 | mWindowsChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1048 | moveInputMethodDialogsLocked(pos+1); |
| 1049 | return; |
| 1050 | } |
| 1051 | win.mTargetAppToken = null; |
| 1052 | addWindowToListInOrderLocked(win, true); |
| 1053 | moveInputMethodDialogsLocked(pos); |
| 1054 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1055 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1056 | void setInputMethodAnimLayerAdjustment(int adj) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1057 | 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] | 1058 | mInputMethodAnimLayerAdjustment = adj; |
| 1059 | WindowState imw = mInputMethodWindow; |
| 1060 | if (imw != null) { |
| 1061 | imw.mAnimLayer = imw.mLayer + adj; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1062 | if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + imw |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1063 | + " anim layer: " + imw.mAnimLayer); |
| 1064 | int wi = imw.mChildWindows.size(); |
| 1065 | while (wi > 0) { |
| 1066 | wi--; |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1067 | WindowState cw = imw.mChildWindows.get(wi); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1068 | cw.mAnimLayer = cw.mLayer + adj; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1069 | if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + cw |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1070 | + " anim layer: " + cw.mAnimLayer); |
| 1071 | } |
| 1072 | } |
| 1073 | int di = mInputMethodDialogs.size(); |
| 1074 | while (di > 0) { |
| 1075 | di --; |
| 1076 | imw = mInputMethodDialogs.get(di); |
| 1077 | imw.mAnimLayer = imw.mLayer + adj; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1078 | if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + imw |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1079 | + " anim layer: " + imw.mAnimLayer); |
| 1080 | } |
| 1081 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1082 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1083 | private int tmpRemoveWindowLocked(int interestingPos, WindowState win) { |
| 1084 | int wpos = mWindows.indexOf(win); |
| 1085 | if (wpos >= 0) { |
| 1086 | if (wpos < interestingPos) interestingPos--; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1087 | 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] | 1088 | mWindows.remove(wpos); |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 1089 | mWindowsChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1090 | int NC = win.mChildWindows.size(); |
| 1091 | while (NC > 0) { |
| 1092 | NC--; |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1093 | WindowState cw = win.mChildWindows.get(NC); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1094 | int cpos = mWindows.indexOf(cw); |
| 1095 | if (cpos >= 0) { |
| 1096 | if (cpos < interestingPos) interestingPos--; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1097 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Temp removing child at " |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 1098 | + cpos + ": " + cw); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1099 | mWindows.remove(cpos); |
| 1100 | } |
| 1101 | } |
| 1102 | } |
| 1103 | return interestingPos; |
| 1104 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1105 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1106 | private void reAddWindowToListInOrderLocked(WindowState win) { |
| 1107 | addWindowToListInOrderLocked(win, false); |
| 1108 | // This is a hack to get all of the child windows added as well |
| 1109 | // at the right position. Child windows should be rare and |
| 1110 | // this case should be rare, so it shouldn't be that big a deal. |
| 1111 | int wpos = mWindows.indexOf(win); |
| 1112 | if (wpos >= 0) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1113 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "ReAdd removing from " + wpos |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 1114 | + ": " + win); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1115 | mWindows.remove(wpos); |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 1116 | mWindowsChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1117 | reAddWindowLocked(wpos, win); |
| 1118 | } |
| 1119 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1120 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1121 | void logWindowList(String prefix) { |
| 1122 | int N = mWindows.size(); |
| 1123 | while (N > 0) { |
| 1124 | N--; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1125 | Slog.v(TAG, prefix + "#" + N + ": " + mWindows.get(N)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1126 | } |
| 1127 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1128 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1129 | void moveInputMethodDialogsLocked(int pos) { |
| 1130 | ArrayList<WindowState> dialogs = mInputMethodDialogs; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1131 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1132 | final int N = dialogs.size(); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1133 | 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] | 1134 | for (int i=0; i<N; i++) { |
| 1135 | pos = tmpRemoveWindowLocked(pos, dialogs.get(i)); |
| 1136 | } |
| 1137 | if (DEBUG_INPUT_METHOD) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1138 | Slog.v(TAG, "Window list w/pos=" + pos); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1139 | logWindowList(" "); |
| 1140 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1141 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1142 | if (pos >= 0) { |
| 1143 | final AppWindowToken targetAppToken = mInputMethodTarget.mAppToken; |
| 1144 | if (pos < mWindows.size()) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1145 | WindowState wp = mWindows.get(pos); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1146 | if (wp == mInputMethodWindow) { |
| 1147 | pos++; |
| 1148 | } |
| 1149 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1150 | 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] | 1151 | for (int i=0; i<N; i++) { |
| 1152 | WindowState win = dialogs.get(i); |
| 1153 | win.mTargetAppToken = targetAppToken; |
| 1154 | pos = reAddWindowLocked(pos, win); |
| 1155 | } |
| 1156 | if (DEBUG_INPUT_METHOD) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1157 | Slog.v(TAG, "Final window list:"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1158 | logWindowList(" "); |
| 1159 | } |
| 1160 | return; |
| 1161 | } |
| 1162 | for (int i=0; i<N; i++) { |
| 1163 | WindowState win = dialogs.get(i); |
| 1164 | win.mTargetAppToken = null; |
| 1165 | reAddWindowToListInOrderLocked(win); |
| 1166 | if (DEBUG_INPUT_METHOD) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1167 | Slog.v(TAG, "No IM target, final list:"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1168 | logWindowList(" "); |
| 1169 | } |
| 1170 | } |
| 1171 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1172 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1173 | boolean moveInputMethodWindowsIfNeededLocked(boolean needAssignLayers) { |
| 1174 | final WindowState imWin = mInputMethodWindow; |
| 1175 | final int DN = mInputMethodDialogs.size(); |
| 1176 | if (imWin == null && DN == 0) { |
| 1177 | return false; |
| 1178 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1179 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1180 | int imPos = findDesiredInputMethodWindowIndexLocked(true); |
| 1181 | if (imPos >= 0) { |
| 1182 | // In this case, the input method windows are to be placed |
| 1183 | // immediately above the window they are targeting. |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1184 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1185 | // First check to see if the input method windows are already |
| 1186 | // located here, and contiguous. |
| 1187 | final int N = mWindows.size(); |
| 1188 | WindowState firstImWin = imPos < N |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1189 | ? mWindows.get(imPos) : null; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1190 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1191 | // Figure out the actual input method window that should be |
| 1192 | // at the bottom of their stack. |
| 1193 | WindowState baseImWin = imWin != null |
| 1194 | ? imWin : mInputMethodDialogs.get(0); |
| 1195 | if (baseImWin.mChildWindows.size() > 0) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1196 | WindowState cw = baseImWin.mChildWindows.get(0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1197 | if (cw.mSubLayer < 0) baseImWin = cw; |
| 1198 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1199 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1200 | if (firstImWin == baseImWin) { |
| 1201 | // The windows haven't moved... but are they still contiguous? |
| 1202 | // First find the top IM window. |
| 1203 | int pos = imPos+1; |
| 1204 | while (pos < N) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1205 | if (!(mWindows.get(pos)).mIsImWindow) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1206 | break; |
| 1207 | } |
| 1208 | pos++; |
| 1209 | } |
| 1210 | pos++; |
| 1211 | // Now there should be no more input method windows above. |
| 1212 | while (pos < N) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1213 | if ((mWindows.get(pos)).mIsImWindow) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1214 | break; |
| 1215 | } |
| 1216 | pos++; |
| 1217 | } |
| 1218 | if (pos >= N) { |
| 1219 | // All is good! |
| 1220 | return false; |
| 1221 | } |
| 1222 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1223 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1224 | if (imWin != null) { |
| 1225 | if (DEBUG_INPUT_METHOD) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1226 | Slog.v(TAG, "Moving IM from " + imPos); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1227 | logWindowList(" "); |
| 1228 | } |
| 1229 | imPos = tmpRemoveWindowLocked(imPos, imWin); |
| 1230 | if (DEBUG_INPUT_METHOD) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1231 | 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] | 1232 | logWindowList(" "); |
| 1233 | } |
| 1234 | imWin.mTargetAppToken = mInputMethodTarget.mAppToken; |
| 1235 | reAddWindowLocked(imPos, imWin); |
| 1236 | if (DEBUG_INPUT_METHOD) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1237 | Slog.v(TAG, "List after moving IM to " + imPos + ":"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1238 | logWindowList(" "); |
| 1239 | } |
| 1240 | if (DN > 0) moveInputMethodDialogsLocked(imPos+1); |
| 1241 | } else { |
| 1242 | moveInputMethodDialogsLocked(imPos); |
| 1243 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1244 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1245 | } else { |
| 1246 | // In this case, the input method windows go in a fixed layer, |
| 1247 | // because they aren't currently associated with a focus window. |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1248 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1249 | if (imWin != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1250 | 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] | 1251 | tmpRemoveWindowLocked(0, imWin); |
| 1252 | imWin.mTargetAppToken = null; |
| 1253 | reAddWindowToListInOrderLocked(imWin); |
| 1254 | if (DEBUG_INPUT_METHOD) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1255 | Slog.v(TAG, "List with no IM target:"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1256 | logWindowList(" "); |
| 1257 | } |
| 1258 | if (DN > 0) moveInputMethodDialogsLocked(-1);; |
| 1259 | } else { |
| 1260 | moveInputMethodDialogsLocked(-1);; |
| 1261 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1262 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 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 | if (needAssignLayers) { |
| 1266 | assignLayersLocked(); |
| 1267 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1268 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1269 | return true; |
| 1270 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1271 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1272 | void adjustInputMethodDialogsLocked() { |
| 1273 | moveInputMethodDialogsLocked(findDesiredInputMethodWindowIndexLocked(true)); |
| 1274 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1275 | |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 1276 | final boolean isWallpaperVisible(WindowState wallpaperTarget) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1277 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper vis: target obscured=" |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 1278 | + (wallpaperTarget != null ? Boolean.toString(wallpaperTarget.mObscured) : "??") |
| 1279 | + " anim=" + ((wallpaperTarget != null && wallpaperTarget.mAppToken != null) |
| 1280 | ? wallpaperTarget.mAppToken.animation : null) |
| 1281 | + " upper=" + mUpperWallpaperTarget |
| 1282 | + " lower=" + mLowerWallpaperTarget); |
| 1283 | return (wallpaperTarget != null |
| 1284 | && (!wallpaperTarget.mObscured || (wallpaperTarget.mAppToken != null |
| 1285 | && wallpaperTarget.mAppToken.animation != null))) |
| 1286 | || mUpperWallpaperTarget != null |
| 1287 | || mLowerWallpaperTarget != null; |
| 1288 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1289 | |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 1290 | static final int ADJUST_WALLPAPER_LAYERS_CHANGED = 1<<1; |
| 1291 | static final int ADJUST_WALLPAPER_VISIBILITY_CHANGED = 1<<2; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1292 | |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 1293 | int adjustWallpaperWindowsLocked() { |
| 1294 | int changed = 0; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1295 | |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1296 | final int dw = mDisplay.getWidth(); |
| 1297 | final int dh = mDisplay.getHeight(); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1298 | |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1299 | // First find top-most window that has asked to be on top of the |
| 1300 | // wallpaper; all wallpapers go behind it. |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1301 | final ArrayList<WindowState> localmWindows = mWindows; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1302 | int N = localmWindows.size(); |
| 1303 | WindowState w = null; |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1304 | WindowState foundW = null; |
| 1305 | int foundI = 0; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1306 | WindowState topCurW = null; |
| 1307 | int topCurI = 0; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1308 | int i = N; |
| 1309 | while (i > 0) { |
| 1310 | i--; |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1311 | w = localmWindows.get(i); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1312 | if ((w.mAttrs.type == WindowManager.LayoutParams.TYPE_WALLPAPER)) { |
| 1313 | if (topCurW == null) { |
| 1314 | topCurW = w; |
| 1315 | topCurI = i; |
| 1316 | } |
| 1317 | continue; |
| 1318 | } |
| 1319 | topCurW = null; |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1320 | if (w.mAppToken != null) { |
| 1321 | // If this window's app token is hidden and not animating, |
| 1322 | // it is of no interest to us. |
| 1323 | if (w.mAppToken.hidden && w.mAppToken.animation == null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1324 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1325 | "Skipping hidden or animating token: " + w); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1326 | topCurW = null; |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1327 | continue; |
| 1328 | } |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1329 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1330 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Win " + w + ": readyfordisplay=" |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1331 | + w.isReadyForDisplay() + " drawpending=" + w.mDrawPending |
| 1332 | + " commitdrawpending=" + w.mCommitDrawPending); |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1333 | if ((w.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0 && w.isReadyForDisplay() |
Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 1334 | && (mWallpaperTarget == w |
| 1335 | || (!w.mDrawPending && !w.mCommitDrawPending))) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1336 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1337 | "Found wallpaper activity: #" + i + "=" + w); |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1338 | foundW = w; |
| 1339 | foundI = i; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1340 | if (w == mWallpaperTarget && ((w.mAppToken != null |
| 1341 | && w.mAppToken.animation != null) |
| 1342 | || w.mAnimation != null)) { |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1343 | // The current wallpaper target is animating, so we'll |
| 1344 | // look behind it for another possible target and figure |
| 1345 | // out what is going on below. |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1346 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Win " + w |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1347 | + ": token animating, looking behind."); |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1348 | continue; |
| 1349 | } |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1350 | break; |
| 1351 | } |
| 1352 | } |
| 1353 | |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 1354 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1355 | // If we are currently waiting for an app transition, and either |
| 1356 | // the current target or the next target are involved with it, |
| 1357 | // then hold off on doing anything with the wallpaper. |
| 1358 | // Note that we are checking here for just whether the target |
| 1359 | // is part of an app token... which is potentially overly aggressive |
| 1360 | // (the app token may not be involved in the transition), but good |
| 1361 | // enough (we'll just wait until whatever transition is pending |
| 1362 | // executes). |
| 1363 | if (mWallpaperTarget != null && mWallpaperTarget.mAppToken != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1364 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1365 | "Wallpaper not changing: waiting for app anim in current target"); |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 1366 | return 0; |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1367 | } |
| 1368 | if (foundW != null && foundW.mAppToken != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1369 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1370 | "Wallpaper not changing: waiting for app anim in found target"); |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 1371 | return 0; |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1372 | } |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1373 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1374 | |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1375 | if (mWallpaperTarget != foundW) { |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1376 | if (DEBUG_WALLPAPER) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1377 | Slog.v(TAG, "New wallpaper target: " + foundW |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1378 | + " oldTarget: " + mWallpaperTarget); |
| 1379 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1380 | |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1381 | mLowerWallpaperTarget = null; |
| 1382 | mUpperWallpaperTarget = null; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1383 | |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1384 | WindowState oldW = mWallpaperTarget; |
| 1385 | mWallpaperTarget = foundW; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1386 | |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1387 | // Now what is happening... if the current and new targets are |
| 1388 | // animating, then we are in our super special mode! |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1389 | if (foundW != null && oldW != null) { |
| 1390 | boolean oldAnim = oldW.mAnimation != null |
| 1391 | || (oldW.mAppToken != null && oldW.mAppToken.animation != null); |
| 1392 | boolean foundAnim = foundW.mAnimation != null |
| 1393 | || (foundW.mAppToken != null && foundW.mAppToken.animation != null); |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1394 | if (DEBUG_WALLPAPER) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1395 | Slog.v(TAG, "New animation: " + foundAnim |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1396 | + " old animation: " + oldAnim); |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1397 | } |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1398 | if (foundAnim && oldAnim) { |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1399 | int oldI = localmWindows.indexOf(oldW); |
| 1400 | if (DEBUG_WALLPAPER) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1401 | Slog.v(TAG, "New i: " + foundI + " old i: " + oldI); |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1402 | } |
| 1403 | if (oldI >= 0) { |
| 1404 | if (DEBUG_WALLPAPER) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1405 | Slog.v(TAG, "Animating wallpapers: old#" + oldI |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1406 | + "=" + oldW + "; new#" + foundI |
| 1407 | + "=" + foundW); |
| 1408 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1409 | |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1410 | // Set the new target correctly. |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1411 | if (foundW.mAppToken != null && foundW.mAppToken.hiddenRequested) { |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1412 | if (DEBUG_WALLPAPER) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1413 | Slog.v(TAG, "Old wallpaper still the target."); |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1414 | } |
| 1415 | mWallpaperTarget = oldW; |
| 1416 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1417 | |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1418 | // Now set the upper and lower wallpaper targets |
| 1419 | // correctly, and make sure that we are positioning |
| 1420 | // the wallpaper below the lower. |
| 1421 | if (foundI > oldI) { |
| 1422 | // The new target is on top of the old one. |
| 1423 | if (DEBUG_WALLPAPER) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1424 | Slog.v(TAG, "Found target above old target."); |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1425 | } |
| 1426 | mUpperWallpaperTarget = foundW; |
| 1427 | mLowerWallpaperTarget = oldW; |
| 1428 | foundW = oldW; |
| 1429 | foundI = oldI; |
| 1430 | } else { |
| 1431 | // The new target is below the old one. |
| 1432 | if (DEBUG_WALLPAPER) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1433 | Slog.v(TAG, "Found target below old target."); |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1434 | } |
| 1435 | mUpperWallpaperTarget = oldW; |
| 1436 | mLowerWallpaperTarget = foundW; |
| 1437 | } |
| 1438 | } |
| 1439 | } |
| 1440 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1441 | |
Dianne Hackborn | 6b1cb35 | 2009-09-28 18:27:26 -0700 | [diff] [blame] | 1442 | } else if (mLowerWallpaperTarget != null) { |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1443 | // Is it time to stop animating? |
Dianne Hackborn | 6b1cb35 | 2009-09-28 18:27:26 -0700 | [diff] [blame] | 1444 | boolean lowerAnimating = mLowerWallpaperTarget.mAnimation != null |
| 1445 | || (mLowerWallpaperTarget.mAppToken != null |
| 1446 | && mLowerWallpaperTarget.mAppToken.animation != null); |
| 1447 | boolean upperAnimating = mUpperWallpaperTarget.mAnimation != null |
| 1448 | || (mUpperWallpaperTarget.mAppToken != null |
| 1449 | && mUpperWallpaperTarget.mAppToken.animation != null); |
| 1450 | if (!lowerAnimating || !upperAnimating) { |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1451 | if (DEBUG_WALLPAPER) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1452 | Slog.v(TAG, "No longer animating wallpaper targets!"); |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1453 | } |
| 1454 | mLowerWallpaperTarget = null; |
| 1455 | mUpperWallpaperTarget = null; |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1456 | } |
| 1457 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1458 | |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1459 | boolean visible = foundW != null; |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 1460 | if (visible) { |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1461 | // The window is visible to the compositor... but is it visible |
| 1462 | // to the user? That is what the wallpaper cares about. |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 1463 | visible = isWallpaperVisible(foundW); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1464 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper visibility: " + visible); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1465 | |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1466 | // If the wallpaper target is animating, we may need to copy |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1467 | // its layer adjustment. Only do this if we are not transfering |
| 1468 | // between two wallpaper targets. |
| 1469 | mWallpaperAnimLayerAdjustment = |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1470 | (mLowerWallpaperTarget == null && foundW.mAppToken != null) |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1471 | ? foundW.mAppToken.animLayerAdjustment : 0; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1472 | |
Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 1473 | final int maxLayer = mPolicy.getMaxWallpaperLayer() |
| 1474 | * TYPE_LAYER_MULTIPLIER |
| 1475 | + TYPE_LAYER_OFFSET; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1476 | |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1477 | // Now w is the window we are supposed to be behind... but we |
| 1478 | // 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] | 1479 | // AND any starting window associated with it, AND below the |
| 1480 | // maximum layer the policy allows for wallpapers. |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1481 | while (foundI > 0) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1482 | WindowState wb = localmWindows.get(foundI-1); |
Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 1483 | if (wb.mBaseLayer < maxLayer && |
| 1484 | wb.mAttachedWindow != foundW && |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1485 | (wb.mAttrs.type != TYPE_APPLICATION_STARTING || |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1486 | wb.mToken != foundW.mToken)) { |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1487 | // This window is not related to the previous one in any |
| 1488 | // interesting way, so stop here. |
| 1489 | break; |
| 1490 | } |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1491 | foundW = wb; |
| 1492 | foundI--; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1493 | } |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 1494 | } else { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1495 | if (DEBUG_WALLPAPER) Slog.v(TAG, "No wallpaper target"); |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1496 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1497 | |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1498 | if (foundW == null && topCurW != null) { |
| 1499 | // There is no wallpaper target, so it goes at the bottom. |
| 1500 | // We will assume it is the same place as last time, if known. |
| 1501 | foundW = topCurW; |
| 1502 | foundI = topCurI+1; |
| 1503 | } else { |
| 1504 | // Okay i is the position immediately above the wallpaper. Look at |
| 1505 | // what is below it for later. |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1506 | foundW = foundI > 0 ? localmWindows.get(foundI-1) : null; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1507 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1508 | |
Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 1509 | if (visible) { |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1510 | if (mWallpaperTarget.mWallpaperX >= 0) { |
| 1511 | mLastWallpaperX = mWallpaperTarget.mWallpaperX; |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 1512 | mLastWallpaperXStep = mWallpaperTarget.mWallpaperXStep; |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1513 | } |
| 1514 | if (mWallpaperTarget.mWallpaperY >= 0) { |
| 1515 | mLastWallpaperY = mWallpaperTarget.mWallpaperY; |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 1516 | mLastWallpaperYStep = mWallpaperTarget.mWallpaperYStep; |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1517 | } |
Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 1518 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1519 | |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1520 | // Start stepping backwards from here, ensuring that our wallpaper windows |
| 1521 | // are correctly placed. |
| 1522 | int curTokenIndex = mWallpaperTokens.size(); |
| 1523 | while (curTokenIndex > 0) { |
| 1524 | curTokenIndex--; |
| 1525 | WindowToken token = mWallpaperTokens.get(curTokenIndex); |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 1526 | if (token.hidden == visible) { |
| 1527 | changed |= ADJUST_WALLPAPER_VISIBILITY_CHANGED; |
| 1528 | token.hidden = !visible; |
| 1529 | // Need to do a layout to ensure the wallpaper now has the |
| 1530 | // correct size. |
| 1531 | mLayoutNeeded = true; |
| 1532 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1533 | |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1534 | int curWallpaperIndex = token.windows.size(); |
| 1535 | while (curWallpaperIndex > 0) { |
| 1536 | curWallpaperIndex--; |
| 1537 | WindowState wallpaper = token.windows.get(curWallpaperIndex); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1538 | |
Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 1539 | if (visible) { |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1540 | updateWallpaperOffsetLocked(wallpaper, dw, dh, false); |
Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 1541 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1542 | |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 1543 | // First, make sure the client has the current visibility |
| 1544 | // state. |
| 1545 | if (wallpaper.mWallpaperVisible != visible) { |
| 1546 | wallpaper.mWallpaperVisible = visible; |
| 1547 | try { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1548 | if (DEBUG_VISIBILITY || DEBUG_WALLPAPER) Slog.v(TAG, |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 1549 | "Setting visibility of wallpaper " + wallpaper |
| 1550 | + ": " + visible); |
| 1551 | wallpaper.mClient.dispatchAppVisibility(visible); |
| 1552 | } catch (RemoteException e) { |
| 1553 | } |
| 1554 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1555 | |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 1556 | wallpaper.mAnimLayer = wallpaper.mLayer + mWallpaperAnimLayerAdjustment; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1557 | if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper win " |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1558 | + wallpaper + " anim layer: " + wallpaper.mAnimLayer); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1559 | |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1560 | // First, if this window is at the current index, then all |
| 1561 | // is well. |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1562 | if (wallpaper == foundW) { |
| 1563 | foundI--; |
| 1564 | foundW = foundI > 0 |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1565 | ? localmWindows.get(foundI-1) : null; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1566 | continue; |
| 1567 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1568 | |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1569 | // The window didn't match... the current wallpaper window, |
| 1570 | // wherever it is, is in the wrong place, so make sure it is |
| 1571 | // not in the list. |
| 1572 | int oldIndex = localmWindows.indexOf(wallpaper); |
| 1573 | if (oldIndex >= 0) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1574 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Wallpaper removing at " |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 1575 | + oldIndex + ": " + wallpaper); |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1576 | localmWindows.remove(oldIndex); |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 1577 | mWindowsChanged = true; |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1578 | if (oldIndex < foundI) { |
| 1579 | foundI--; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1580 | } |
| 1581 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1582 | |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1583 | // Now stick it in. |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1584 | if (DEBUG_WALLPAPER || DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 1585 | "Moving wallpaper " + wallpaper |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1586 | + " from " + oldIndex + " to " + foundI); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1587 | |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1588 | localmWindows.add(foundI, wallpaper); |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 1589 | mWindowsChanged = true; |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 1590 | changed |= ADJUST_WALLPAPER_LAYERS_CHANGED; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1591 | } |
| 1592 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1593 | |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1594 | return changed; |
| 1595 | } |
| 1596 | |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 1597 | void setWallpaperAnimLayerAdjustmentLocked(int adj) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1598 | if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG, |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1599 | "Setting wallpaper layer adj to " + adj); |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 1600 | mWallpaperAnimLayerAdjustment = adj; |
| 1601 | int curTokenIndex = mWallpaperTokens.size(); |
| 1602 | while (curTokenIndex > 0) { |
| 1603 | curTokenIndex--; |
| 1604 | WindowToken token = mWallpaperTokens.get(curTokenIndex); |
| 1605 | int curWallpaperIndex = token.windows.size(); |
| 1606 | while (curWallpaperIndex > 0) { |
| 1607 | curWallpaperIndex--; |
| 1608 | WindowState wallpaper = token.windows.get(curWallpaperIndex); |
| 1609 | wallpaper.mAnimLayer = wallpaper.mLayer + adj; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1610 | if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper win " |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1611 | + wallpaper + " anim layer: " + wallpaper.mAnimLayer); |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 1612 | } |
| 1613 | } |
| 1614 | } |
| 1615 | |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1616 | boolean updateWallpaperOffsetLocked(WindowState wallpaperWin, int dw, int dh, |
| 1617 | boolean sync) { |
Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 1618 | boolean changed = false; |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1619 | boolean rawChanged = false; |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1620 | float wpx = mLastWallpaperX >= 0 ? mLastWallpaperX : 0.5f; |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 1621 | float wpxs = mLastWallpaperXStep >= 0 ? mLastWallpaperXStep : -1.0f; |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1622 | int availw = wallpaperWin.mFrame.right-wallpaperWin.mFrame.left-dw; |
| 1623 | int offset = availw > 0 ? -(int)(availw*wpx+.5f) : 0; |
| 1624 | changed = wallpaperWin.mXOffset != offset; |
| 1625 | if (changed) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1626 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Update wallpaper " |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1627 | + wallpaperWin + " x: " + offset); |
| 1628 | wallpaperWin.mXOffset = offset; |
| 1629 | } |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 1630 | if (wallpaperWin.mWallpaperX != wpx || wallpaperWin.mWallpaperXStep != wpxs) { |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1631 | wallpaperWin.mWallpaperX = wpx; |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 1632 | wallpaperWin.mWallpaperXStep = wpxs; |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1633 | rawChanged = true; |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 1634 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1635 | |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1636 | float wpy = mLastWallpaperY >= 0 ? mLastWallpaperY : 0.5f; |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 1637 | float wpys = mLastWallpaperYStep >= 0 ? mLastWallpaperYStep : -1.0f; |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1638 | int availh = wallpaperWin.mFrame.bottom-wallpaperWin.mFrame.top-dh; |
| 1639 | offset = availh > 0 ? -(int)(availh*wpy+.5f) : 0; |
| 1640 | if (wallpaperWin.mYOffset != offset) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1641 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Update wallpaper " |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1642 | + wallpaperWin + " y: " + offset); |
| 1643 | changed = true; |
| 1644 | wallpaperWin.mYOffset = offset; |
| 1645 | } |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 1646 | if (wallpaperWin.mWallpaperY != wpy || wallpaperWin.mWallpaperYStep != wpys) { |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1647 | wallpaperWin.mWallpaperY = wpy; |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 1648 | wallpaperWin.mWallpaperYStep = wpys; |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1649 | rawChanged = true; |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 1650 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1651 | |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1652 | if (rawChanged) { |
Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 1653 | try { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1654 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Report new wp offset " |
Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 1655 | + wallpaperWin + " x=" + wallpaperWin.mWallpaperX |
| 1656 | + " y=" + wallpaperWin.mWallpaperY); |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1657 | if (sync) { |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 1658 | mWaitingOnWallpaper = wallpaperWin; |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1659 | } |
Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 1660 | wallpaperWin.mClient.dispatchWallpaperOffsets( |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 1661 | wallpaperWin.mWallpaperX, wallpaperWin.mWallpaperY, |
| 1662 | wallpaperWin.mWallpaperXStep, wallpaperWin.mWallpaperYStep, sync); |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1663 | if (sync) { |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 1664 | if (mWaitingOnWallpaper != null) { |
| 1665 | long start = SystemClock.uptimeMillis(); |
| 1666 | if ((mLastWallpaperTimeoutTime+WALLPAPER_TIMEOUT_RECOVERY) |
| 1667 | < start) { |
| 1668 | try { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1669 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 1670 | "Waiting for offset complete..."); |
| 1671 | mWindowMap.wait(WALLPAPER_TIMEOUT); |
| 1672 | } catch (InterruptedException e) { |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1673 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1674 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Offset complete!"); |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 1675 | if ((start+WALLPAPER_TIMEOUT) |
| 1676 | < SystemClock.uptimeMillis()) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1677 | Slog.i(TAG, "Timeout waiting for wallpaper to offset: " |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 1678 | + wallpaperWin); |
| 1679 | mLastWallpaperTimeoutTime = start; |
| 1680 | } |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1681 | } |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 1682 | mWaitingOnWallpaper = null; |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1683 | } |
| 1684 | } |
Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 1685 | } catch (RemoteException e) { |
| 1686 | } |
| 1687 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1688 | |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 1689 | return changed; |
| 1690 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1691 | |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1692 | void wallpaperOffsetsComplete(IBinder window) { |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 1693 | synchronized (mWindowMap) { |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1694 | if (mWaitingOnWallpaper != null && |
| 1695 | mWaitingOnWallpaper.mClient.asBinder() == window) { |
| 1696 | mWaitingOnWallpaper = null; |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 1697 | mWindowMap.notifyAll(); |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1698 | } |
| 1699 | } |
| 1700 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1701 | |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1702 | boolean updateWallpaperOffsetLocked(WindowState changingTarget, boolean sync) { |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 1703 | final int dw = mDisplay.getWidth(); |
| 1704 | final int dh = mDisplay.getHeight(); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1705 | |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 1706 | boolean changed = false; |
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 | WindowState target = mWallpaperTarget; |
| 1709 | if (target != null) { |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1710 | if (target.mWallpaperX >= 0) { |
| 1711 | mLastWallpaperX = target.mWallpaperX; |
| 1712 | } else if (changingTarget.mWallpaperX >= 0) { |
| 1713 | mLastWallpaperX = changingTarget.mWallpaperX; |
| 1714 | } |
| 1715 | if (target.mWallpaperY >= 0) { |
| 1716 | mLastWallpaperY = target.mWallpaperY; |
| 1717 | } else if (changingTarget.mWallpaperY >= 0) { |
| 1718 | mLastWallpaperY = changingTarget.mWallpaperY; |
| 1719 | } |
| 1720 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1721 | |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1722 | int curTokenIndex = mWallpaperTokens.size(); |
| 1723 | while (curTokenIndex > 0) { |
| 1724 | curTokenIndex--; |
| 1725 | WindowToken token = mWallpaperTokens.get(curTokenIndex); |
| 1726 | int curWallpaperIndex = token.windows.size(); |
| 1727 | while (curWallpaperIndex > 0) { |
| 1728 | curWallpaperIndex--; |
| 1729 | WindowState wallpaper = token.windows.get(curWallpaperIndex); |
| 1730 | if (updateWallpaperOffsetLocked(wallpaper, dw, dh, sync)) { |
| 1731 | wallpaper.computeShownFrameLocked(); |
| 1732 | changed = true; |
| 1733 | // We only want to be synchronous with one wallpaper. |
| 1734 | sync = false; |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 1735 | } |
| 1736 | } |
| 1737 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1738 | |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 1739 | return changed; |
| 1740 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1741 | |
Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 1742 | void updateWallpaperVisibilityLocked() { |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 1743 | final boolean visible = isWallpaperVisible(mWallpaperTarget); |
Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 1744 | final int dw = mDisplay.getWidth(); |
| 1745 | final int dh = mDisplay.getHeight(); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1746 | |
Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 1747 | int curTokenIndex = mWallpaperTokens.size(); |
| 1748 | while (curTokenIndex > 0) { |
| 1749 | curTokenIndex--; |
| 1750 | WindowToken token = mWallpaperTokens.get(curTokenIndex); |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 1751 | if (token.hidden == visible) { |
| 1752 | token.hidden = !visible; |
| 1753 | // Need to do a layout to ensure the wallpaper now has the |
| 1754 | // correct size. |
| 1755 | mLayoutNeeded = true; |
| 1756 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1757 | |
Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 1758 | int curWallpaperIndex = token.windows.size(); |
| 1759 | while (curWallpaperIndex > 0) { |
| 1760 | curWallpaperIndex--; |
| 1761 | WindowState wallpaper = token.windows.get(curWallpaperIndex); |
| 1762 | if (visible) { |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1763 | updateWallpaperOffsetLocked(wallpaper, dw, dh, false); |
Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 1764 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1765 | |
Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 1766 | if (wallpaper.mWallpaperVisible != visible) { |
| 1767 | wallpaper.mWallpaperVisible = visible; |
| 1768 | try { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1769 | if (DEBUG_VISIBILITY || DEBUG_WALLPAPER) Slog.v(TAG, |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 1770 | "Updating visibility of wallpaper " + wallpaper |
Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 1771 | + ": " + visible); |
| 1772 | wallpaper.mClient.dispatchAppVisibility(visible); |
| 1773 | } catch (RemoteException e) { |
| 1774 | } |
| 1775 | } |
| 1776 | } |
| 1777 | } |
| 1778 | } |
Dianne Hackborn | 90d2db3 | 2010-02-11 22:19:06 -0800 | [diff] [blame] | 1779 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1780 | public int addWindow(Session session, IWindow client, |
| 1781 | WindowManager.LayoutParams attrs, int viewVisibility, |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1782 | Rect outContentInsets, InputChannel outInputChannel) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1783 | int res = mPolicy.checkAddPermission(attrs); |
| 1784 | if (res != WindowManagerImpl.ADD_OKAY) { |
| 1785 | return res; |
| 1786 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1787 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1788 | boolean reportNewConfig = false; |
| 1789 | WindowState attachedWindow = null; |
| 1790 | WindowState win = null; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1791 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1792 | synchronized(mWindowMap) { |
| 1793 | // Instantiating a Display requires talking with the simulator, |
| 1794 | // so don't do it until we know the system is mostly up and |
| 1795 | // running. |
| 1796 | if (mDisplay == null) { |
| 1797 | WindowManager wm = (WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE); |
| 1798 | mDisplay = wm.getDefaultDisplay(); |
Christopher Tate | b696aee | 2010-04-02 19:08:30 -0700 | [diff] [blame] | 1799 | mInitialDisplayWidth = mDisplay.getWidth(); |
| 1800 | mInitialDisplayHeight = mDisplay.getHeight(); |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 1801 | mInputManager.setDisplaySize(0, mInitialDisplayWidth, mInitialDisplayHeight); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1802 | reportNewConfig = true; |
| 1803 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1804 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1805 | if (mWindowMap.containsKey(client.asBinder())) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1806 | Slog.w(TAG, "Window " + client + " is already added"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1807 | return WindowManagerImpl.ADD_DUPLICATE_ADD; |
| 1808 | } |
| 1809 | |
| 1810 | if (attrs.type >= FIRST_SUB_WINDOW && attrs.type <= LAST_SUB_WINDOW) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 1811 | attachedWindow = windowForClientLocked(null, attrs.token, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1812 | if (attachedWindow == null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1813 | 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] | 1814 | + attrs.token + ". Aborting."); |
| 1815 | return WindowManagerImpl.ADD_BAD_SUBWINDOW_TOKEN; |
| 1816 | } |
| 1817 | if (attachedWindow.mAttrs.type >= FIRST_SUB_WINDOW |
| 1818 | && attachedWindow.mAttrs.type <= LAST_SUB_WINDOW) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1819 | 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] | 1820 | + attrs.token + ". Aborting."); |
| 1821 | return WindowManagerImpl.ADD_BAD_SUBWINDOW_TOKEN; |
| 1822 | } |
| 1823 | } |
| 1824 | |
| 1825 | boolean addToken = false; |
| 1826 | WindowToken token = mTokenMap.get(attrs.token); |
| 1827 | if (token == null) { |
| 1828 | if (attrs.type >= FIRST_APPLICATION_WINDOW |
| 1829 | && attrs.type <= LAST_APPLICATION_WINDOW) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1830 | 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] | 1831 | + attrs.token + ". Aborting."); |
| 1832 | return WindowManagerImpl.ADD_BAD_APP_TOKEN; |
| 1833 | } |
| 1834 | if (attrs.type == TYPE_INPUT_METHOD) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1835 | 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] | 1836 | + attrs.token + ". Aborting."); |
| 1837 | return WindowManagerImpl.ADD_BAD_APP_TOKEN; |
| 1838 | } |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1839 | if (attrs.type == TYPE_WALLPAPER) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1840 | Slog.w(TAG, "Attempted to add wallpaper window with unknown token " |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1841 | + attrs.token + ". Aborting."); |
| 1842 | return WindowManagerImpl.ADD_BAD_APP_TOKEN; |
| 1843 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1844 | token = new WindowToken(attrs.token, -1, false); |
| 1845 | addToken = true; |
| 1846 | } else if (attrs.type >= FIRST_APPLICATION_WINDOW |
| 1847 | && attrs.type <= LAST_APPLICATION_WINDOW) { |
| 1848 | AppWindowToken atoken = token.appWindowToken; |
| 1849 | if (atoken == null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1850 | 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] | 1851 | + token + ". Aborting."); |
| 1852 | return WindowManagerImpl.ADD_NOT_APP_TOKEN; |
| 1853 | } else if (atoken.removed) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1854 | 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] | 1855 | + token + ". Aborting."); |
| 1856 | return WindowManagerImpl.ADD_APP_EXITING; |
| 1857 | } |
| 1858 | if (attrs.type == TYPE_APPLICATION_STARTING && atoken.firstWindowDrawn) { |
| 1859 | // No need for this guy! |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1860 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1861 | TAG, "**** NO NEED TO START: " + attrs.getTitle()); |
| 1862 | return WindowManagerImpl.ADD_STARTING_NOT_NEEDED; |
| 1863 | } |
| 1864 | } else if (attrs.type == TYPE_INPUT_METHOD) { |
| 1865 | if (token.windowType != TYPE_INPUT_METHOD) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1866 | 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] | 1867 | + attrs.token + ". Aborting."); |
| 1868 | return WindowManagerImpl.ADD_BAD_APP_TOKEN; |
| 1869 | } |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1870 | } else if (attrs.type == TYPE_WALLPAPER) { |
| 1871 | if (token.windowType != TYPE_WALLPAPER) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1872 | Slog.w(TAG, "Attempted to add wallpaper window with bad token " |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1873 | + attrs.token + ". Aborting."); |
| 1874 | return WindowManagerImpl.ADD_BAD_APP_TOKEN; |
| 1875 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1876 | } |
| 1877 | |
| 1878 | win = new WindowState(session, client, token, |
| 1879 | attachedWindow, attrs, viewVisibility); |
| 1880 | if (win.mDeathRecipient == null) { |
| 1881 | // Client has apparently died, so there is no reason to |
| 1882 | // continue. |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1883 | Slog.w(TAG, "Adding window client " + client.asBinder() |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1884 | + " that is dead, aborting."); |
| 1885 | return WindowManagerImpl.ADD_APP_EXITING; |
| 1886 | } |
| 1887 | |
| 1888 | mPolicy.adjustWindowParamsLw(win.mAttrs); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1889 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1890 | res = mPolicy.prepareAddWindowLw(win, attrs); |
| 1891 | if (res != WindowManagerImpl.ADD_OKAY) { |
| 1892 | return res; |
| 1893 | } |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1894 | |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 1895 | if (outInputChannel != null) { |
| 1896 | String name = win.makeInputChannelName(); |
| 1897 | InputChannel[] inputChannels = InputChannel.openInputChannelPair(name); |
| 1898 | win.mInputChannel = inputChannels[0]; |
| 1899 | inputChannels[1].transferToBinderOutParameter(outInputChannel); |
| 1900 | |
| 1901 | mInputManager.registerInputChannel(win.mInputChannel); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1902 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1903 | |
| 1904 | // From now on, no exceptions or errors allowed! |
| 1905 | |
| 1906 | res = WindowManagerImpl.ADD_OKAY; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1907 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1908 | final long origId = Binder.clearCallingIdentity(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1909 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1910 | if (addToken) { |
| 1911 | mTokenMap.put(attrs.token, token); |
| 1912 | mTokenList.add(token); |
| 1913 | } |
| 1914 | win.attach(); |
| 1915 | mWindowMap.put(client.asBinder(), win); |
| 1916 | |
| 1917 | if (attrs.type == TYPE_APPLICATION_STARTING && |
| 1918 | token.appWindowToken != null) { |
| 1919 | token.appWindowToken.startingWindow = win; |
| 1920 | } |
| 1921 | |
| 1922 | boolean imMayMove = true; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1923 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1924 | if (attrs.type == TYPE_INPUT_METHOD) { |
| 1925 | mInputMethodWindow = win; |
| 1926 | addInputMethodWindowToListLocked(win); |
| 1927 | imMayMove = false; |
| 1928 | } else if (attrs.type == TYPE_INPUT_METHOD_DIALOG) { |
| 1929 | mInputMethodDialogs.add(win); |
| 1930 | addWindowToListInOrderLocked(win, true); |
| 1931 | adjustInputMethodDialogsLocked(); |
| 1932 | imMayMove = false; |
| 1933 | } else { |
| 1934 | addWindowToListInOrderLocked(win, true); |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1935 | if (attrs.type == TYPE_WALLPAPER) { |
| 1936 | mLastWallpaperTimeoutTime = 0; |
| 1937 | adjustWallpaperWindowsLocked(); |
| 1938 | } else if ((attrs.flags&FLAG_SHOW_WALLPAPER) != 0) { |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1939 | adjustWallpaperWindowsLocked(); |
| 1940 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1941 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1942 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1943 | win.mEnterAnimationPending = true; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1944 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1945 | mPolicy.getContentInsetHintLw(attrs, outContentInsets); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1946 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1947 | if (mInTouchMode) { |
| 1948 | res |= WindowManagerImpl.ADD_FLAG_IN_TOUCH_MODE; |
| 1949 | } |
| 1950 | if (win == null || win.mAppToken == null || !win.mAppToken.clientHidden) { |
| 1951 | res |= WindowManagerImpl.ADD_FLAG_APP_VISIBLE; |
| 1952 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1953 | |
The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 1954 | boolean focusChanged = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1955 | if (win.canReceiveKeys()) { |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 1956 | focusChanged = updateFocusedWindowLocked(UPDATE_FOCUS_WILL_ASSIGN_LAYERS); |
| 1957 | if (focusChanged) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1958 | imMayMove = false; |
| 1959 | } |
| 1960 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1961 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1962 | if (imMayMove) { |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1963 | moveInputMethodWindowsIfNeededLocked(false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1964 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1965 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1966 | assignLayersLocked(); |
| 1967 | // Don't do layout here, the window must call |
| 1968 | // relayout to be displayed, so we'll do it there. |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1969 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1970 | //dump(); |
| 1971 | |
The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 1972 | if (focusChanged) { |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 1973 | finishUpdateFocusedWindowAfterAssignLayersLocked(); |
The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 1974 | } |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 1975 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1976 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1977 | TAG, "New client " + client.asBinder() |
| 1978 | + ": window=" + win); |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 1979 | |
| 1980 | if (win.isVisibleOrAdding() && updateOrientationFromAppTokensLocked()) { |
| 1981 | reportNewConfig = true; |
| 1982 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1983 | } |
| 1984 | |
| 1985 | // sendNewConfiguration() checks caller permissions so we must call it with |
| 1986 | // privilege. updateOrientationFromAppTokens() clears and resets the caller |
| 1987 | // identity anyway, so it's safe to just clear & restore around this whole |
| 1988 | // block. |
| 1989 | final long origId = Binder.clearCallingIdentity(); |
| 1990 | if (reportNewConfig) { |
| 1991 | sendNewConfiguration(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1992 | } |
| 1993 | Binder.restoreCallingIdentity(origId); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1994 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1995 | return res; |
| 1996 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1997 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1998 | public void removeWindow(Session session, IWindow client) { |
| 1999 | synchronized(mWindowMap) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2000 | WindowState win = windowForClientLocked(session, client, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2001 | if (win == null) { |
| 2002 | return; |
| 2003 | } |
| 2004 | removeWindowLocked(session, win); |
| 2005 | } |
| 2006 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2007 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2008 | public void removeWindowLocked(Session session, WindowState win) { |
| 2009 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2010 | if (localLOGV || DEBUG_FOCUS) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2011 | TAG, "Remove " + win + " client=" |
| 2012 | + Integer.toHexString(System.identityHashCode( |
| 2013 | win.mClient.asBinder())) |
| 2014 | + ", surface=" + win.mSurface); |
| 2015 | |
| 2016 | final long origId = Binder.clearCallingIdentity(); |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 2017 | |
| 2018 | win.disposeInputChannel(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2019 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2020 | if (DEBUG_APP_TRANSITIONS) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2021 | TAG, "Remove " + win + ": mSurface=" + win.mSurface |
| 2022 | + " mExiting=" + win.mExiting |
| 2023 | + " isAnimating=" + win.isAnimating() |
| 2024 | + " app-animation=" |
| 2025 | + (win.mAppToken != null ? win.mAppToken.animation : null) |
| 2026 | + " inPendingTransaction=" |
| 2027 | + (win.mAppToken != null ? win.mAppToken.inPendingTransaction : false) |
| 2028 | + " mDisplayFrozen=" + mDisplayFrozen); |
| 2029 | // Visibility of the removed window. Will be used later to update orientation later on. |
| 2030 | boolean wasVisible = false; |
| 2031 | // First, see if we need to run an animation. If we do, we have |
| 2032 | // to hold off on removing the window until the animation is done. |
| 2033 | // If the display is frozen, just remove immediately, since the |
| 2034 | // animation wouldn't be seen. |
Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 2035 | if (win.mSurface != null && !mDisplayFrozen && mPolicy.isScreenOn()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2036 | // If we are not currently running the exit animation, we |
| 2037 | // need to see about starting one. |
| 2038 | if (wasVisible=win.isWinVisibleLw()) { |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2039 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2040 | int transit = WindowManagerPolicy.TRANSIT_EXIT; |
| 2041 | if (win.getAttrs().type == TYPE_APPLICATION_STARTING) { |
| 2042 | transit = WindowManagerPolicy.TRANSIT_PREVIEW_DONE; |
| 2043 | } |
| 2044 | // Try starting an animation. |
| 2045 | if (applyAnimationLocked(win, transit, false)) { |
| 2046 | win.mExiting = true; |
| 2047 | } |
| 2048 | } |
| 2049 | if (win.mExiting || win.isAnimating()) { |
| 2050 | // The exit animation is running... wait for it! |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2051 | //Slog.i(TAG, "*** Running exit animation..."); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2052 | win.mExiting = true; |
| 2053 | win.mRemoveOnExit = true; |
| 2054 | mLayoutNeeded = true; |
| 2055 | updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES); |
| 2056 | performLayoutAndPlaceSurfacesLocked(); |
| 2057 | if (win.mAppToken != null) { |
| 2058 | win.mAppToken.updateReportedVisibilityLocked(); |
| 2059 | } |
| 2060 | //dump(); |
| 2061 | Binder.restoreCallingIdentity(origId); |
| 2062 | return; |
| 2063 | } |
| 2064 | } |
| 2065 | |
| 2066 | removeWindowInnerLocked(session, win); |
| 2067 | // Removing a visible window will effect the computed orientation |
| 2068 | // So just update orientation if needed. |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 2069 | if (wasVisible && computeForcedAppOrientationLocked() |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2070 | != mForcedAppOrientation |
| 2071 | && updateOrientationFromAppTokensLocked()) { |
| 2072 | mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2073 | } |
| 2074 | updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL); |
| 2075 | Binder.restoreCallingIdentity(origId); |
| 2076 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2077 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2078 | private void removeWindowInnerLocked(Session session, WindowState win) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2079 | win.mRemoved = true; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2080 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2081 | if (mInputMethodTarget == win) { |
| 2082 | moveInputMethodWindowsIfNeededLocked(false); |
| 2083 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2084 | |
Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 2085 | if (false) { |
| 2086 | RuntimeException e = new RuntimeException("here"); |
| 2087 | e.fillInStackTrace(); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2088 | Slog.w(TAG, "Removing window " + win, e); |
Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 2089 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2090 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2091 | mPolicy.removeWindowLw(win); |
| 2092 | win.removeLocked(); |
| 2093 | |
| 2094 | mWindowMap.remove(win.mClient.asBinder()); |
| 2095 | mWindows.remove(win); |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 2096 | mWindowsChanged = true; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2097 | 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] | 2098 | |
| 2099 | if (mInputMethodWindow == win) { |
| 2100 | mInputMethodWindow = null; |
| 2101 | } else if (win.mAttrs.type == TYPE_INPUT_METHOD_DIALOG) { |
| 2102 | mInputMethodDialogs.remove(win); |
| 2103 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2104 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2105 | final WindowToken token = win.mToken; |
| 2106 | final AppWindowToken atoken = win.mAppToken; |
| 2107 | token.windows.remove(win); |
| 2108 | if (atoken != null) { |
| 2109 | atoken.allAppWindows.remove(win); |
| 2110 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2111 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2112 | TAG, "**** Removing window " + win + ": count=" |
| 2113 | + token.windows.size()); |
| 2114 | if (token.windows.size() == 0) { |
| 2115 | if (!token.explicit) { |
| 2116 | mTokenMap.remove(token.token); |
| 2117 | mTokenList.remove(token); |
| 2118 | } else if (atoken != null) { |
| 2119 | atoken.firstWindowDrawn = false; |
| 2120 | } |
| 2121 | } |
| 2122 | |
| 2123 | if (atoken != null) { |
| 2124 | if (atoken.startingWindow == win) { |
| 2125 | atoken.startingWindow = null; |
| 2126 | } else if (atoken.allAppWindows.size() == 0 && atoken.startingData != null) { |
| 2127 | // If this is the last window and we had requested a starting |
| 2128 | // transition window, well there is no point now. |
| 2129 | atoken.startingData = null; |
| 2130 | } else if (atoken.allAppWindows.size() == 1 && atoken.startingView != null) { |
| 2131 | // If this is the last window except for a starting transition |
| 2132 | // window, we need to get rid of the starting transition. |
| 2133 | if (DEBUG_STARTING_WINDOW) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2134 | Slog.v(TAG, "Schedule remove starting " + token |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2135 | + ": no more real windows"); |
| 2136 | } |
| 2137 | Message m = mH.obtainMessage(H.REMOVE_STARTING, atoken); |
| 2138 | mH.sendMessage(m); |
| 2139 | } |
| 2140 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2141 | |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 2142 | if (win.mAttrs.type == TYPE_WALLPAPER) { |
| 2143 | mLastWallpaperTimeoutTime = 0; |
| 2144 | adjustWallpaperWindowsLocked(); |
| 2145 | } else if ((win.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0) { |
Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 2146 | adjustWallpaperWindowsLocked(); |
| 2147 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2148 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2149 | if (!mInLayout) { |
| 2150 | assignLayersLocked(); |
| 2151 | mLayoutNeeded = true; |
| 2152 | performLayoutAndPlaceSurfacesLocked(); |
| 2153 | if (win.mAppToken != null) { |
| 2154 | win.mAppToken.updateReportedVisibilityLocked(); |
| 2155 | } |
| 2156 | } |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 2157 | |
| 2158 | mInputMonitor.updateInputWindowsLw(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2159 | } |
| 2160 | |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 2161 | private static void logSurface(WindowState w, String msg, RuntimeException where) { |
| 2162 | String str = " SURFACE " + Integer.toHexString(w.hashCode()) |
| 2163 | + ": " + msg + " / " + w.mAttrs.getTitle(); |
| 2164 | if (where != null) { |
| 2165 | Slog.i(TAG, str, where); |
| 2166 | } else { |
| 2167 | Slog.i(TAG, str); |
| 2168 | } |
| 2169 | } |
| 2170 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2171 | private void setTransparentRegionWindow(Session session, IWindow client, Region region) { |
| 2172 | long origId = Binder.clearCallingIdentity(); |
| 2173 | try { |
| 2174 | synchronized (mWindowMap) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2175 | WindowState w = windowForClientLocked(session, client, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2176 | if ((w != null) && (w.mSurface != null)) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2177 | if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2178 | Surface.openTransaction(); |
| 2179 | try { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 2180 | if (SHOW_TRANSACTIONS) logSurface(w, |
| 2181 | "transparentRegionHint=" + region, null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2182 | w.mSurface.setTransparentRegionHint(region); |
| 2183 | } finally { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2184 | if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2185 | Surface.closeTransaction(); |
| 2186 | } |
| 2187 | } |
| 2188 | } |
| 2189 | } finally { |
| 2190 | Binder.restoreCallingIdentity(origId); |
| 2191 | } |
| 2192 | } |
| 2193 | |
| 2194 | void setInsetsWindow(Session session, IWindow client, |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2195 | int touchableInsets, Rect contentInsets, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2196 | Rect visibleInsets) { |
| 2197 | long origId = Binder.clearCallingIdentity(); |
| 2198 | try { |
| 2199 | synchronized (mWindowMap) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2200 | WindowState w = windowForClientLocked(session, client, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2201 | if (w != null) { |
| 2202 | w.mGivenInsetsPending = false; |
| 2203 | w.mGivenContentInsets.set(contentInsets); |
| 2204 | w.mGivenVisibleInsets.set(visibleInsets); |
| 2205 | w.mTouchableInsets = touchableInsets; |
| 2206 | mLayoutNeeded = true; |
| 2207 | performLayoutAndPlaceSurfacesLocked(); |
| 2208 | } |
| 2209 | } |
| 2210 | } finally { |
| 2211 | Binder.restoreCallingIdentity(origId); |
| 2212 | } |
| 2213 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2214 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2215 | public void getWindowDisplayFrame(Session session, IWindow client, |
| 2216 | Rect outDisplayFrame) { |
| 2217 | synchronized(mWindowMap) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2218 | WindowState win = windowForClientLocked(session, client, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2219 | if (win == null) { |
| 2220 | outDisplayFrame.setEmpty(); |
| 2221 | return; |
| 2222 | } |
| 2223 | outDisplayFrame.set(win.mDisplayFrame); |
| 2224 | } |
| 2225 | } |
| 2226 | |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 2227 | public void setWindowWallpaperPositionLocked(WindowState window, float x, float y, |
| 2228 | float xStep, float yStep) { |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 2229 | if (window.mWallpaperX != x || window.mWallpaperY != y) { |
| 2230 | window.mWallpaperX = x; |
| 2231 | window.mWallpaperY = y; |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 2232 | window.mWallpaperXStep = xStep; |
| 2233 | window.mWallpaperYStep = yStep; |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 2234 | if (updateWallpaperOffsetLocked(window, true)) { |
| 2235 | performLayoutAndPlaceSurfacesLocked(); |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 2236 | } |
| 2237 | } |
| 2238 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2239 | |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 2240 | void wallpaperCommandComplete(IBinder window, Bundle result) { |
| 2241 | synchronized (mWindowMap) { |
| 2242 | if (mWaitingOnWallpaper != null && |
| 2243 | mWaitingOnWallpaper.mClient.asBinder() == window) { |
| 2244 | mWaitingOnWallpaper = null; |
| 2245 | mWindowMap.notifyAll(); |
| 2246 | } |
| 2247 | } |
| 2248 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2249 | |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 2250 | public Bundle sendWindowWallpaperCommandLocked(WindowState window, |
| 2251 | String action, int x, int y, int z, Bundle extras, boolean sync) { |
| 2252 | if (window == mWallpaperTarget || window == mLowerWallpaperTarget |
| 2253 | || window == mUpperWallpaperTarget) { |
| 2254 | boolean doWait = sync; |
| 2255 | int curTokenIndex = mWallpaperTokens.size(); |
| 2256 | while (curTokenIndex > 0) { |
| 2257 | curTokenIndex--; |
| 2258 | WindowToken token = mWallpaperTokens.get(curTokenIndex); |
| 2259 | int curWallpaperIndex = token.windows.size(); |
| 2260 | while (curWallpaperIndex > 0) { |
| 2261 | curWallpaperIndex--; |
| 2262 | WindowState wallpaper = token.windows.get(curWallpaperIndex); |
| 2263 | try { |
| 2264 | wallpaper.mClient.dispatchWallpaperCommand(action, |
| 2265 | x, y, z, extras, sync); |
| 2266 | // We only want to be synchronous with one wallpaper. |
| 2267 | sync = false; |
| 2268 | } catch (RemoteException e) { |
| 2269 | } |
| 2270 | } |
| 2271 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2272 | |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 2273 | if (doWait) { |
| 2274 | // XXX Need to wait for result. |
| 2275 | } |
| 2276 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2277 | |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 2278 | return null; |
| 2279 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2280 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2281 | public int relayoutWindow(Session session, IWindow client, |
| 2282 | WindowManager.LayoutParams attrs, int requestedWidth, |
| 2283 | int requestedHeight, int viewVisibility, boolean insetsPending, |
| 2284 | Rect outFrame, Rect outContentInsets, Rect outVisibleInsets, |
Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 2285 | Configuration outConfig, Surface outSurface) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2286 | boolean displayed = false; |
| 2287 | boolean inTouchMode; |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2288 | boolean configChanged; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2289 | long origId = Binder.clearCallingIdentity(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2290 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2291 | synchronized(mWindowMap) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2292 | WindowState win = windowForClientLocked(session, client, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2293 | if (win == null) { |
| 2294 | return 0; |
| 2295 | } |
| 2296 | win.mRequestedWidth = requestedWidth; |
| 2297 | win.mRequestedHeight = requestedHeight; |
| 2298 | |
| 2299 | if (attrs != null) { |
| 2300 | mPolicy.adjustWindowParamsLw(attrs); |
| 2301 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2302 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2303 | int attrChanges = 0; |
| 2304 | int flagChanges = 0; |
| 2305 | if (attrs != null) { |
| 2306 | flagChanges = win.mAttrs.flags ^= attrs.flags; |
| 2307 | attrChanges = win.mAttrs.copyFrom(attrs); |
| 2308 | } |
| 2309 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2310 | 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] | 2311 | |
| 2312 | if ((attrChanges & WindowManager.LayoutParams.ALPHA_CHANGED) != 0) { |
| 2313 | win.mAlpha = attrs.alpha; |
| 2314 | } |
| 2315 | |
| 2316 | final boolean scaledWindow = |
| 2317 | ((win.mAttrs.flags & WindowManager.LayoutParams.FLAG_SCALED) != 0); |
| 2318 | |
| 2319 | if (scaledWindow) { |
| 2320 | // requested{Width|Height} Surface's physical size |
| 2321 | // attrs.{width|height} Size on screen |
| 2322 | win.mHScale = (attrs.width != requestedWidth) ? |
| 2323 | (attrs.width / (float)requestedWidth) : 1.0f; |
| 2324 | win.mVScale = (attrs.height != requestedHeight) ? |
| 2325 | (attrs.height / (float)requestedHeight) : 1.0f; |
Dianne Hackborn | 9b52a21 | 2009-12-11 14:51:35 -0800 | [diff] [blame] | 2326 | } else { |
| 2327 | win.mHScale = win.mVScale = 1; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2328 | } |
| 2329 | |
| 2330 | boolean imMayMove = (flagChanges&( |
| 2331 | WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM | |
| 2332 | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE)) != 0; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2333 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2334 | boolean focusMayChange = win.mViewVisibility != viewVisibility |
| 2335 | || ((flagChanges&WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) != 0) |
| 2336 | || (!win.mRelayoutCalled); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2337 | |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2338 | boolean wallpaperMayMove = win.mViewVisibility != viewVisibility |
| 2339 | && (win.mAttrs.flags & FLAG_SHOW_WALLPAPER) != 0; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2340 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2341 | win.mRelayoutCalled = true; |
| 2342 | final int oldVisibility = win.mViewVisibility; |
| 2343 | win.mViewVisibility = viewVisibility; |
| 2344 | if (viewVisibility == View.VISIBLE && |
| 2345 | (win.mAppToken == null || !win.mAppToken.clientHidden)) { |
| 2346 | displayed = !win.isVisibleLw(); |
| 2347 | if (win.mExiting) { |
| 2348 | win.mExiting = false; |
| 2349 | win.mAnimation = null; |
| 2350 | } |
| 2351 | if (win.mDestroying) { |
| 2352 | win.mDestroying = false; |
| 2353 | mDestroySurface.remove(win); |
| 2354 | } |
| 2355 | if (oldVisibility == View.GONE) { |
| 2356 | win.mEnterAnimationPending = true; |
| 2357 | } |
Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 2358 | if (displayed) { |
| 2359 | if (win.mSurface != null && !win.mDrawPending |
| 2360 | && !win.mCommitDrawPending && !mDisplayFrozen |
| 2361 | && mPolicy.isScreenOn()) { |
| 2362 | applyEnterAnimationLocked(win); |
| 2363 | } |
| 2364 | if ((win.mAttrs.flags |
| 2365 | & WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON) != 0) { |
| 2366 | if (DEBUG_VISIBILITY) Slog.v(TAG, |
| 2367 | "Relayout window turning screen on: " + win); |
| 2368 | win.mTurnOnScreen = true; |
| 2369 | } |
| 2370 | int diff = 0; |
| 2371 | if (win.mConfiguration != mCurConfiguration |
| 2372 | && (win.mConfiguration == null |
| 2373 | || (diff=mCurConfiguration.diff(win.mConfiguration)) != 0)) { |
| 2374 | win.mConfiguration = mCurConfiguration; |
| 2375 | if (DEBUG_CONFIGURATION) { |
| 2376 | Slog.i(TAG, "Window " + win + " visible with new config: " |
| 2377 | + win.mConfiguration + " / 0x" |
| 2378 | + Integer.toHexString(diff)); |
| 2379 | } |
| 2380 | outConfig.setTo(mCurConfiguration); |
| 2381 | } |
Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 2382 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2383 | if ((attrChanges&WindowManager.LayoutParams.FORMAT_CHANGED) != 0) { |
| 2384 | // To change the format, we need to re-build the surface. |
| 2385 | win.destroySurfaceLocked(); |
| 2386 | displayed = true; |
| 2387 | } |
| 2388 | try { |
| 2389 | Surface surface = win.createSurfaceLocked(); |
| 2390 | if (surface != null) { |
| 2391 | outSurface.copyFrom(surface); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2392 | win.mReportDestroySurface = false; |
| 2393 | win.mSurfacePendingDestroy = false; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2394 | if (SHOW_TRANSACTIONS) Slog.i(TAG, |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 2395 | " OUT SURFACE " + outSurface + ": copied"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2396 | } else { |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 2397 | // For some reason there isn't a surface. Clear the |
| 2398 | // caller's object so they see the same state. |
| 2399 | outSurface.release(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2400 | } |
| 2401 | } catch (Exception e) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 2402 | mInputMonitor.updateInputWindowsLw(); |
| 2403 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2404 | Slog.w(TAG, "Exception thrown when creating surface for client " |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 2405 | + client + " (" + win.mAttrs.getTitle() + ")", |
| 2406 | e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2407 | Binder.restoreCallingIdentity(origId); |
| 2408 | return 0; |
| 2409 | } |
| 2410 | if (displayed) { |
| 2411 | focusMayChange = true; |
| 2412 | } |
| 2413 | if (win.mAttrs.type == TYPE_INPUT_METHOD |
| 2414 | && mInputMethodWindow == null) { |
| 2415 | mInputMethodWindow = win; |
| 2416 | imMayMove = true; |
| 2417 | } |
Dianne Hackborn | 558947c | 2009-12-18 16:02:50 -0800 | [diff] [blame] | 2418 | if (win.mAttrs.type == TYPE_BASE_APPLICATION |
| 2419 | && win.mAppToken != null |
| 2420 | && win.mAppToken.startingWindow != null) { |
| 2421 | // Special handling of starting window over the base |
| 2422 | // window of the app: propagate lock screen flags to it, |
| 2423 | // to provide the correct semantics while starting. |
| 2424 | final int mask = |
| 2425 | WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED |
Mike Lockwood | ef73162 | 2010-01-27 17:51:34 -0500 | [diff] [blame] | 2426 | | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD |
| 2427 | | WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON; |
Dianne Hackborn | 558947c | 2009-12-18 16:02:50 -0800 | [diff] [blame] | 2428 | WindowManager.LayoutParams sa = win.mAppToken.startingWindow.mAttrs; |
| 2429 | sa.flags = (sa.flags&~mask) | (win.mAttrs.flags&mask); |
| 2430 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2431 | } else { |
| 2432 | win.mEnterAnimationPending = false; |
| 2433 | if (win.mSurface != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2434 | if (DEBUG_VISIBILITY) Slog.i(TAG, "Relayout invis " + win |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2435 | + ": mExiting=" + win.mExiting |
| 2436 | + " mSurfacePendingDestroy=" + win.mSurfacePendingDestroy); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2437 | // If we are not currently running the exit animation, we |
| 2438 | // need to see about starting one. |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2439 | if (!win.mExiting || win.mSurfacePendingDestroy) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2440 | // Try starting an animation; if there isn't one, we |
| 2441 | // can destroy the surface right away. |
| 2442 | int transit = WindowManagerPolicy.TRANSIT_EXIT; |
| 2443 | if (win.getAttrs().type == TYPE_APPLICATION_STARTING) { |
| 2444 | transit = WindowManagerPolicy.TRANSIT_PREVIEW_DONE; |
| 2445 | } |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2446 | if (!win.mSurfacePendingDestroy && win.isWinVisibleLw() && |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2447 | applyAnimationLocked(win, transit, false)) { |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2448 | focusMayChange = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2449 | win.mExiting = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2450 | } else if (win.isAnimating()) { |
| 2451 | // Currently in a hide animation... turn this into |
| 2452 | // an exit. |
| 2453 | win.mExiting = true; |
Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 2454 | } else if (win == mWallpaperTarget) { |
| 2455 | // If the wallpaper is currently behind this |
| 2456 | // window, we need to change both of them inside |
| 2457 | // of a transaction to avoid artifacts. |
| 2458 | win.mExiting = true; |
| 2459 | win.mAnimating = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2460 | } else { |
| 2461 | if (mInputMethodWindow == win) { |
| 2462 | mInputMethodWindow = null; |
| 2463 | } |
| 2464 | win.destroySurfaceLocked(); |
| 2465 | } |
| 2466 | } |
| 2467 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2468 | |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2469 | if (win.mSurface == null || (win.getAttrs().flags |
| 2470 | & WindowManager.LayoutParams.FLAG_KEEP_SURFACE_WHILE_ANIMATING) == 0 |
| 2471 | || win.mSurfacePendingDestroy) { |
| 2472 | // We are being called from a local process, which |
| 2473 | // means outSurface holds its current surface. Ensure the |
| 2474 | // surface object is cleared, but we don't want it actually |
| 2475 | // destroyed at this point. |
| 2476 | win.mSurfacePendingDestroy = false; |
| 2477 | outSurface.release(); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2478 | if (DEBUG_VISIBILITY) Slog.i(TAG, "Releasing surface in: " + win); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2479 | } else if (win.mSurface != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2480 | if (DEBUG_VISIBILITY) Slog.i(TAG, |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2481 | "Keeping surface, will report destroy: " + win); |
| 2482 | win.mReportDestroySurface = true; |
| 2483 | outSurface.copyFrom(win.mSurface); |
| 2484 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2485 | } |
| 2486 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2487 | if (focusMayChange) { |
| 2488 | //System.out.println("Focus may change: " + win.mAttrs.getTitle()); |
| 2489 | if (updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2490 | imMayMove = false; |
| 2491 | } |
| 2492 | //System.out.println("Relayout " + win + ": focus=" + mCurrentFocus); |
| 2493 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2494 | |
The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 2495 | // updateFocusedWindowLocked() already assigned layers so we only need to |
| 2496 | // reassign them at this point if the IM window state gets shuffled |
| 2497 | boolean assignLayers = false; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2498 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2499 | if (imMayMove) { |
Dianne Hackborn | 8abd5f0 | 2009-11-20 18:09:03 -0800 | [diff] [blame] | 2500 | if (moveInputMethodWindowsIfNeededLocked(false) || displayed) { |
| 2501 | // Little hack here -- we -should- be able to rely on the |
| 2502 | // function to return true if the IME has moved and needs |
| 2503 | // its layer recomputed. However, if the IME was hidden |
| 2504 | // and isn't actually moved in the list, its layer may be |
| 2505 | // 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] | 2506 | assignLayers = true; |
| 2507 | } |
| 2508 | } |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2509 | if (wallpaperMayMove) { |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 2510 | if ((adjustWallpaperWindowsLocked()&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) { |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2511 | assignLayers = true; |
| 2512 | } |
| 2513 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2514 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2515 | mLayoutNeeded = true; |
| 2516 | win.mGivenInsetsPending = insetsPending; |
| 2517 | if (assignLayers) { |
| 2518 | assignLayersLocked(); |
| 2519 | } |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2520 | configChanged = updateOrientationFromAppTokensLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2521 | performLayoutAndPlaceSurfacesLocked(); |
Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 2522 | if (displayed && win.mIsWallpaper) { |
| 2523 | updateWallpaperOffsetLocked(win, mDisplay.getWidth(), |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 2524 | mDisplay.getHeight(), false); |
Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 2525 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2526 | if (win.mAppToken != null) { |
| 2527 | win.mAppToken.updateReportedVisibilityLocked(); |
| 2528 | } |
| 2529 | outFrame.set(win.mFrame); |
| 2530 | outContentInsets.set(win.mContentInsets); |
| 2531 | outVisibleInsets.set(win.mVisibleInsets); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2532 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2533 | TAG, "Relayout given client " + client.asBinder() |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2534 | + ", requestedWidth=" + requestedWidth |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2535 | + ", requestedHeight=" + requestedHeight |
| 2536 | + ", viewVisibility=" + viewVisibility |
| 2537 | + "\nRelayout returning frame=" + outFrame |
| 2538 | + ", surface=" + outSurface); |
| 2539 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2540 | if (localLOGV || DEBUG_FOCUS) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2541 | TAG, "Relayout of " + win + ": focusMayChange=" + focusMayChange); |
| 2542 | |
| 2543 | inTouchMode = mInTouchMode; |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 2544 | |
| 2545 | mInputMonitor.updateInputWindowsLw(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2546 | } |
| 2547 | |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2548 | if (configChanged) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2549 | sendNewConfiguration(); |
| 2550 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2551 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2552 | Binder.restoreCallingIdentity(origId); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2553 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2554 | return (inTouchMode ? WindowManagerImpl.RELAYOUT_IN_TOUCH_MODE : 0) |
| 2555 | | (displayed ? WindowManagerImpl.RELAYOUT_FIRST_TIME : 0); |
| 2556 | } |
| 2557 | |
| 2558 | public void finishDrawingWindow(Session session, IWindow client) { |
| 2559 | final long origId = Binder.clearCallingIdentity(); |
| 2560 | synchronized(mWindowMap) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2561 | WindowState win = windowForClientLocked(session, client, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2562 | if (win != null && win.finishDrawingLocked()) { |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 2563 | if ((win.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0) { |
| 2564 | adjustWallpaperWindowsLocked(); |
| 2565 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2566 | mLayoutNeeded = true; |
| 2567 | performLayoutAndPlaceSurfacesLocked(); |
| 2568 | } |
| 2569 | } |
| 2570 | Binder.restoreCallingIdentity(origId); |
| 2571 | } |
| 2572 | |
| 2573 | private AttributeCache.Entry getCachedAnimations(WindowManager.LayoutParams lp) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2574 | 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] | 2575 | + (lp != null ? lp.packageName : null) |
| 2576 | + " resId=0x" + (lp != null ? Integer.toHexString(lp.windowAnimations) : null)); |
| 2577 | if (lp != null && lp.windowAnimations != 0) { |
| 2578 | // If this is a system resource, don't try to load it from the |
| 2579 | // application resources. It is nice to avoid loading application |
| 2580 | // resources if we can. |
| 2581 | String packageName = lp.packageName != null ? lp.packageName : "android"; |
| 2582 | int resId = lp.windowAnimations; |
| 2583 | if ((resId&0xFF000000) == 0x01000000) { |
| 2584 | packageName = "android"; |
| 2585 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2586 | 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] | 2587 | + packageName); |
| 2588 | return AttributeCache.instance().get(packageName, resId, |
| 2589 | com.android.internal.R.styleable.WindowAnimation); |
| 2590 | } |
| 2591 | return null; |
| 2592 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2593 | |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2594 | private AttributeCache.Entry getCachedAnimations(String packageName, int resId) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2595 | if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: params package=" |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2596 | + packageName + " resId=0x" + Integer.toHexString(resId)); |
| 2597 | if (packageName != null) { |
| 2598 | if ((resId&0xFF000000) == 0x01000000) { |
| 2599 | packageName = "android"; |
| 2600 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2601 | if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: picked package=" |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2602 | + packageName); |
| 2603 | return AttributeCache.instance().get(packageName, resId, |
| 2604 | com.android.internal.R.styleable.WindowAnimation); |
| 2605 | } |
| 2606 | return null; |
| 2607 | } |
| 2608 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2609 | private void applyEnterAnimationLocked(WindowState win) { |
| 2610 | int transit = WindowManagerPolicy.TRANSIT_SHOW; |
| 2611 | if (win.mEnterAnimationPending) { |
| 2612 | win.mEnterAnimationPending = false; |
| 2613 | transit = WindowManagerPolicy.TRANSIT_ENTER; |
| 2614 | } |
| 2615 | |
| 2616 | applyAnimationLocked(win, transit, true); |
| 2617 | } |
| 2618 | |
| 2619 | private boolean applyAnimationLocked(WindowState win, |
| 2620 | int transit, boolean isEntrance) { |
| 2621 | if (win.mLocalAnimating && win.mAnimationIsEntrance == isEntrance) { |
| 2622 | // If we are trying to apply an animation, but already running |
| 2623 | // an animation of the same type, then just leave that one alone. |
| 2624 | return true; |
| 2625 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2626 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2627 | // Only apply an animation if the display isn't frozen. If it is |
| 2628 | // frozen, there is no reason to animate and it can cause strange |
| 2629 | // artifacts when we unfreeze the display if some different animation |
| 2630 | // is running. |
Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 2631 | if (!mDisplayFrozen && mPolicy.isScreenOn()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2632 | int anim = mPolicy.selectAnimationLw(win, transit); |
| 2633 | int attr = -1; |
| 2634 | Animation a = null; |
| 2635 | if (anim != 0) { |
| 2636 | a = AnimationUtils.loadAnimation(mContext, anim); |
| 2637 | } else { |
| 2638 | switch (transit) { |
| 2639 | case WindowManagerPolicy.TRANSIT_ENTER: |
| 2640 | attr = com.android.internal.R.styleable.WindowAnimation_windowEnterAnimation; |
| 2641 | break; |
| 2642 | case WindowManagerPolicy.TRANSIT_EXIT: |
| 2643 | attr = com.android.internal.R.styleable.WindowAnimation_windowExitAnimation; |
| 2644 | break; |
| 2645 | case WindowManagerPolicy.TRANSIT_SHOW: |
| 2646 | attr = com.android.internal.R.styleable.WindowAnimation_windowShowAnimation; |
| 2647 | break; |
| 2648 | case WindowManagerPolicy.TRANSIT_HIDE: |
| 2649 | attr = com.android.internal.R.styleable.WindowAnimation_windowHideAnimation; |
| 2650 | break; |
| 2651 | } |
| 2652 | if (attr >= 0) { |
| 2653 | a = loadAnimation(win.mAttrs, attr); |
| 2654 | } |
| 2655 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2656 | if (DEBUG_ANIM) Slog.v(TAG, "applyAnimation: win=" + win |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2657 | + " anim=" + anim + " attr=0x" + Integer.toHexString(attr) |
| 2658 | + " mAnimation=" + win.mAnimation |
| 2659 | + " isEntrance=" + isEntrance); |
| 2660 | if (a != null) { |
| 2661 | if (DEBUG_ANIM) { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 2662 | RuntimeException e = null; |
| 2663 | if (!HIDE_STACK_CRAWLS) { |
| 2664 | e = new RuntimeException(); |
| 2665 | e.fillInStackTrace(); |
| 2666 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2667 | Slog.v(TAG, "Loaded animation " + a + " for " + win, e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2668 | } |
| 2669 | win.setAnimation(a); |
| 2670 | win.mAnimationIsEntrance = isEntrance; |
| 2671 | } |
| 2672 | } else { |
| 2673 | win.clearAnimation(); |
| 2674 | } |
| 2675 | |
| 2676 | return win.mAnimation != null; |
| 2677 | } |
| 2678 | |
| 2679 | private Animation loadAnimation(WindowManager.LayoutParams lp, int animAttr) { |
| 2680 | int anim = 0; |
| 2681 | Context context = mContext; |
| 2682 | if (animAttr >= 0) { |
| 2683 | AttributeCache.Entry ent = getCachedAnimations(lp); |
| 2684 | if (ent != null) { |
| 2685 | context = ent.context; |
| 2686 | anim = ent.array.getResourceId(animAttr, 0); |
| 2687 | } |
| 2688 | } |
| 2689 | if (anim != 0) { |
| 2690 | return AnimationUtils.loadAnimation(context, anim); |
| 2691 | } |
| 2692 | return null; |
| 2693 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2694 | |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2695 | private Animation loadAnimation(String packageName, int resId) { |
| 2696 | int anim = 0; |
| 2697 | Context context = mContext; |
| 2698 | if (resId >= 0) { |
| 2699 | AttributeCache.Entry ent = getCachedAnimations(packageName, resId); |
| 2700 | if (ent != null) { |
| 2701 | context = ent.context; |
| 2702 | anim = resId; |
| 2703 | } |
| 2704 | } |
| 2705 | if (anim != 0) { |
| 2706 | return AnimationUtils.loadAnimation(context, anim); |
| 2707 | } |
| 2708 | return null; |
| 2709 | } |
| 2710 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2711 | private boolean applyAnimationLocked(AppWindowToken wtoken, |
| 2712 | WindowManager.LayoutParams lp, int transit, boolean enter) { |
| 2713 | // Only apply an animation if the display isn't frozen. If it is |
| 2714 | // frozen, there is no reason to animate and it can cause strange |
| 2715 | // artifacts when we unfreeze the display if some different animation |
| 2716 | // is running. |
Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 2717 | if (!mDisplayFrozen && mPolicy.isScreenOn()) { |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 2718 | Animation a; |
Mitsuru Oshima | d2967e2 | 2009-07-20 14:01:43 -0700 | [diff] [blame] | 2719 | if (lp != null && (lp.flags & FLAG_COMPATIBLE_WINDOW) != 0) { |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 2720 | a = new FadeInOutAnimation(enter); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2721 | if (DEBUG_ANIM) Slog.v(TAG, |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 2722 | "applying FadeInOutAnimation for a window in compatibility mode"); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2723 | } else if (mNextAppTransitionPackage != null) { |
| 2724 | a = loadAnimation(mNextAppTransitionPackage, enter ? |
| 2725 | mNextAppTransitionEnter : mNextAppTransitionExit); |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 2726 | } else { |
| 2727 | int animAttr = 0; |
| 2728 | switch (transit) { |
| 2729 | case WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN: |
| 2730 | animAttr = enter |
| 2731 | ? com.android.internal.R.styleable.WindowAnimation_activityOpenEnterAnimation |
| 2732 | : com.android.internal.R.styleable.WindowAnimation_activityOpenExitAnimation; |
| 2733 | break; |
| 2734 | case WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE: |
| 2735 | animAttr = enter |
| 2736 | ? com.android.internal.R.styleable.WindowAnimation_activityCloseEnterAnimation |
| 2737 | : com.android.internal.R.styleable.WindowAnimation_activityCloseExitAnimation; |
| 2738 | break; |
| 2739 | case WindowManagerPolicy.TRANSIT_TASK_OPEN: |
| 2740 | animAttr = enter |
| 2741 | ? com.android.internal.R.styleable.WindowAnimation_taskOpenEnterAnimation |
| 2742 | : com.android.internal.R.styleable.WindowAnimation_taskOpenExitAnimation; |
| 2743 | break; |
| 2744 | case WindowManagerPolicy.TRANSIT_TASK_CLOSE: |
| 2745 | animAttr = enter |
| 2746 | ? com.android.internal.R.styleable.WindowAnimation_taskCloseEnterAnimation |
| 2747 | : com.android.internal.R.styleable.WindowAnimation_taskCloseExitAnimation; |
| 2748 | break; |
| 2749 | case WindowManagerPolicy.TRANSIT_TASK_TO_FRONT: |
| 2750 | animAttr = enter |
| 2751 | ? com.android.internal.R.styleable.WindowAnimation_taskToFrontEnterAnimation |
| 2752 | : com.android.internal.R.styleable.WindowAnimation_taskToFrontExitAnimation; |
| 2753 | break; |
| 2754 | case WindowManagerPolicy.TRANSIT_TASK_TO_BACK: |
| 2755 | animAttr = enter |
Mitsuru Oshima | 5a2b91d | 2009-07-16 16:30:02 -0700 | [diff] [blame] | 2756 | ? com.android.internal.R.styleable.WindowAnimation_taskToBackEnterAnimation |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 2757 | : com.android.internal.R.styleable.WindowAnimation_taskToBackExitAnimation; |
| 2758 | break; |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 2759 | case WindowManagerPolicy.TRANSIT_WALLPAPER_OPEN: |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 2760 | animAttr = enter |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 2761 | ? com.android.internal.R.styleable.WindowAnimation_wallpaperOpenEnterAnimation |
| 2762 | : com.android.internal.R.styleable.WindowAnimation_wallpaperOpenExitAnimation; |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 2763 | break; |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 2764 | case WindowManagerPolicy.TRANSIT_WALLPAPER_CLOSE: |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 2765 | animAttr = enter |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 2766 | ? com.android.internal.R.styleable.WindowAnimation_wallpaperCloseEnterAnimation |
| 2767 | : com.android.internal.R.styleable.WindowAnimation_wallpaperCloseExitAnimation; |
| 2768 | break; |
| 2769 | case WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_OPEN: |
| 2770 | animAttr = enter |
| 2771 | ? com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenEnterAnimation |
| 2772 | : com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenExitAnimation; |
| 2773 | break; |
| 2774 | case WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_CLOSE: |
| 2775 | animAttr = enter |
| 2776 | ? com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseEnterAnimation |
| 2777 | : com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseExitAnimation; |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 2778 | break; |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 2779 | } |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 2780 | a = animAttr != 0 ? loadAnimation(lp, animAttr) : null; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2781 | if (DEBUG_ANIM) Slog.v(TAG, "applyAnimation: wtoken=" + wtoken |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 2782 | + " anim=" + a |
| 2783 | + " animAttr=0x" + Integer.toHexString(animAttr) |
| 2784 | + " transit=" + transit); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2785 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2786 | if (a != null) { |
| 2787 | if (DEBUG_ANIM) { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 2788 | RuntimeException e = null; |
| 2789 | if (!HIDE_STACK_CRAWLS) { |
| 2790 | e = new RuntimeException(); |
| 2791 | e.fillInStackTrace(); |
| 2792 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2793 | Slog.v(TAG, "Loaded animation " + a + " for " + wtoken, e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2794 | } |
| 2795 | wtoken.setAnimation(a); |
| 2796 | } |
| 2797 | } else { |
| 2798 | wtoken.clearAnimation(); |
| 2799 | } |
| 2800 | |
| 2801 | return wtoken.animation != null; |
| 2802 | } |
| 2803 | |
| 2804 | // ------------------------------------------------------------- |
| 2805 | // Application Window Tokens |
| 2806 | // ------------------------------------------------------------- |
| 2807 | |
| 2808 | public void validateAppTokens(List tokens) { |
| 2809 | int v = tokens.size()-1; |
| 2810 | int m = mAppTokens.size()-1; |
| 2811 | while (v >= 0 && m >= 0) { |
| 2812 | AppWindowToken wtoken = mAppTokens.get(m); |
| 2813 | if (wtoken.removed) { |
| 2814 | m--; |
| 2815 | continue; |
| 2816 | } |
| 2817 | if (tokens.get(v) != wtoken.token) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2818 | 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] | 2819 | + " @ " + v + ", internal is " + wtoken.token + " @ " + m); |
| 2820 | } |
| 2821 | v--; |
| 2822 | m--; |
| 2823 | } |
| 2824 | while (v >= 0) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2825 | 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] | 2826 | v--; |
| 2827 | } |
| 2828 | while (m >= 0) { |
| 2829 | AppWindowToken wtoken = mAppTokens.get(m); |
| 2830 | if (!wtoken.removed) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2831 | Slog.w(TAG, "Invalid internal token: " + wtoken.token + " @ " + m); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2832 | } |
| 2833 | m--; |
| 2834 | } |
| 2835 | } |
| 2836 | |
| 2837 | boolean checkCallingPermission(String permission, String func) { |
| 2838 | // Quick check: if the calling permission is me, it's all okay. |
| 2839 | if (Binder.getCallingPid() == Process.myPid()) { |
| 2840 | return true; |
| 2841 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2842 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2843 | if (mContext.checkCallingPermission(permission) |
| 2844 | == PackageManager.PERMISSION_GRANTED) { |
| 2845 | return true; |
| 2846 | } |
| 2847 | String msg = "Permission Denial: " + func + " from pid=" |
| 2848 | + Binder.getCallingPid() |
| 2849 | + ", uid=" + Binder.getCallingUid() |
| 2850 | + " requires " + permission; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2851 | Slog.w(TAG, msg); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2852 | return false; |
| 2853 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2854 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2855 | AppWindowToken findAppWindowToken(IBinder token) { |
| 2856 | WindowToken wtoken = mTokenMap.get(token); |
| 2857 | if (wtoken == null) { |
| 2858 | return null; |
| 2859 | } |
| 2860 | return wtoken.appWindowToken; |
| 2861 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2862 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2863 | public void addWindowToken(IBinder token, int type) { |
| 2864 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 2865 | "addWindowToken()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 2866 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2867 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2868 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2869 | synchronized(mWindowMap) { |
| 2870 | WindowToken wtoken = mTokenMap.get(token); |
| 2871 | if (wtoken != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2872 | 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] | 2873 | return; |
| 2874 | } |
| 2875 | wtoken = new WindowToken(token, type, true); |
| 2876 | mTokenMap.put(token, wtoken); |
| 2877 | mTokenList.add(wtoken); |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2878 | if (type == TYPE_WALLPAPER) { |
| 2879 | mWallpaperTokens.add(wtoken); |
| 2880 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2881 | } |
| 2882 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2883 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2884 | public void removeWindowToken(IBinder token) { |
| 2885 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 2886 | "removeWindowToken()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 2887 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2888 | } |
| 2889 | |
| 2890 | final long origId = Binder.clearCallingIdentity(); |
| 2891 | synchronized(mWindowMap) { |
| 2892 | WindowToken wtoken = mTokenMap.remove(token); |
| 2893 | mTokenList.remove(wtoken); |
| 2894 | if (wtoken != null) { |
| 2895 | boolean delayed = false; |
| 2896 | if (!wtoken.hidden) { |
| 2897 | wtoken.hidden = true; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2898 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2899 | final int N = wtoken.windows.size(); |
| 2900 | boolean changed = false; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2901 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2902 | for (int i=0; i<N; i++) { |
| 2903 | WindowState win = wtoken.windows.get(i); |
| 2904 | |
| 2905 | if (win.isAnimating()) { |
| 2906 | delayed = true; |
| 2907 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2908 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2909 | if (win.isVisibleNow()) { |
| 2910 | applyAnimationLocked(win, |
| 2911 | WindowManagerPolicy.TRANSIT_EXIT, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2912 | changed = true; |
| 2913 | } |
| 2914 | } |
| 2915 | |
| 2916 | if (changed) { |
| 2917 | mLayoutNeeded = true; |
| 2918 | performLayoutAndPlaceSurfacesLocked(); |
| 2919 | updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL); |
| 2920 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2921 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2922 | if (delayed) { |
| 2923 | mExitingTokens.add(wtoken); |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2924 | } else if (wtoken.windowType == TYPE_WALLPAPER) { |
| 2925 | mWallpaperTokens.remove(wtoken); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2926 | } |
| 2927 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2928 | |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 2929 | mInputMonitor.updateInputWindowsLw(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2930 | } else { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2931 | 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] | 2932 | } |
| 2933 | } |
| 2934 | Binder.restoreCallingIdentity(origId); |
| 2935 | } |
| 2936 | |
| 2937 | public void addAppToken(int addPos, IApplicationToken token, |
| 2938 | int groupId, int requestedOrientation, boolean fullscreen) { |
| 2939 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 2940 | "addAppToken()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 2941 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2942 | } |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 2943 | |
| 2944 | // Get the dispatching timeout here while we are not holding any locks so that it |
| 2945 | // can be cached by the AppWindowToken. The timeout value is used later by the |
| 2946 | // input dispatcher in code that does hold locks. If we did not cache the value |
| 2947 | // here we would run the chance of introducing a deadlock between the window manager |
| 2948 | // (which holds locks while updating the input dispatcher state) and the activity manager |
| 2949 | // (which holds locks while querying the application token). |
| 2950 | long inputDispatchingTimeoutNanos; |
| 2951 | try { |
| 2952 | inputDispatchingTimeoutNanos = token.getKeyDispatchingTimeout() * 1000000L; |
| 2953 | } catch (RemoteException ex) { |
| 2954 | Slog.w(TAG, "Could not get dispatching timeout.", ex); |
| 2955 | inputDispatchingTimeoutNanos = DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS; |
| 2956 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2957 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2958 | synchronized(mWindowMap) { |
| 2959 | AppWindowToken wtoken = findAppWindowToken(token.asBinder()); |
| 2960 | if (wtoken != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2961 | 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] | 2962 | return; |
| 2963 | } |
| 2964 | wtoken = new AppWindowToken(token); |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 2965 | wtoken.inputDispatchingTimeoutNanos = inputDispatchingTimeoutNanos; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2966 | wtoken.groupId = groupId; |
| 2967 | wtoken.appFullscreen = fullscreen; |
| 2968 | wtoken.requestedOrientation = requestedOrientation; |
| 2969 | mAppTokens.add(addPos, wtoken); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2970 | 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] | 2971 | mTokenMap.put(token.asBinder(), wtoken); |
| 2972 | mTokenList.add(wtoken); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2973 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2974 | // Application tokens start out hidden. |
| 2975 | wtoken.hidden = true; |
| 2976 | wtoken.hiddenRequested = true; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2977 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2978 | //dump(); |
| 2979 | } |
| 2980 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2981 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2982 | public void setAppGroupId(IBinder token, int groupId) { |
| 2983 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 2984 | "setAppStartingIcon()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 2985 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2986 | } |
| 2987 | |
| 2988 | synchronized(mWindowMap) { |
| 2989 | AppWindowToken wtoken = findAppWindowToken(token); |
| 2990 | if (wtoken == null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2991 | 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] | 2992 | return; |
| 2993 | } |
| 2994 | wtoken.groupId = groupId; |
| 2995 | } |
| 2996 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2997 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2998 | public int getOrientationFromWindowsLocked() { |
| 2999 | int pos = mWindows.size() - 1; |
| 3000 | while (pos >= 0) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 3001 | WindowState wtoken = mWindows.get(pos); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3002 | pos--; |
| 3003 | if (wtoken.mAppToken != null) { |
| 3004 | // We hit an application window. so the orientation will be determined by the |
| 3005 | // app window. No point in continuing further. |
| 3006 | return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
| 3007 | } |
Christopher Tate | b696aee | 2010-04-02 19:08:30 -0700 | [diff] [blame] | 3008 | if (!wtoken.isVisibleLw() || !wtoken.mPolicyVisibilityAfterAnim) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3009 | continue; |
| 3010 | } |
| 3011 | int req = wtoken.mAttrs.screenOrientation; |
| 3012 | if((req == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) || |
| 3013 | (req == ActivityInfo.SCREEN_ORIENTATION_BEHIND)){ |
| 3014 | continue; |
| 3015 | } else { |
| 3016 | return req; |
| 3017 | } |
| 3018 | } |
| 3019 | return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
| 3020 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3021 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3022 | public int getOrientationFromAppTokensLocked() { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3023 | int pos = mAppTokens.size() - 1; |
| 3024 | int curGroup = 0; |
| 3025 | int lastOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
| 3026 | boolean findingBehind = false; |
| 3027 | boolean haveGroup = false; |
| 3028 | boolean lastFullscreen = false; |
| 3029 | while (pos >= 0) { |
| 3030 | AppWindowToken wtoken = mAppTokens.get(pos); |
| 3031 | pos--; |
| 3032 | // if we're about to tear down this window and not seek for |
| 3033 | // the behind activity, don't use it for orientation |
| 3034 | if (!findingBehind |
| 3035 | && (!wtoken.hidden && wtoken.hiddenRequested)) { |
| 3036 | continue; |
| 3037 | } |
| 3038 | |
| 3039 | if (!haveGroup) { |
| 3040 | // We ignore any hidden applications on the top. |
| 3041 | if (wtoken.hiddenRequested || wtoken.willBeHidden) { |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3042 | continue; |
| 3043 | } |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3044 | haveGroup = true; |
| 3045 | curGroup = wtoken.groupId; |
| 3046 | lastOrientation = wtoken.requestedOrientation; |
| 3047 | } else if (curGroup != wtoken.groupId) { |
| 3048 | // If we have hit a new application group, and the bottom |
| 3049 | // of the previous group didn't explicitly say to use |
| 3050 | // the orientation behind it, and the last app was |
| 3051 | // full screen, then we'll stick with the |
| 3052 | // user's orientation. |
| 3053 | if (lastOrientation != ActivityInfo.SCREEN_ORIENTATION_BEHIND |
| 3054 | && lastFullscreen) { |
| 3055 | return lastOrientation; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3056 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3057 | } |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3058 | int or = wtoken.requestedOrientation; |
| 3059 | // If this application is fullscreen, and didn't explicitly say |
| 3060 | // to use the orientation behind it, then just take whatever |
| 3061 | // orientation it has and ignores whatever is under it. |
| 3062 | lastFullscreen = wtoken.appFullscreen; |
| 3063 | if (lastFullscreen |
| 3064 | && or != ActivityInfo.SCREEN_ORIENTATION_BEHIND) { |
| 3065 | return or; |
| 3066 | } |
| 3067 | // If this application has requested an explicit orientation, |
| 3068 | // then use it. |
| 3069 | if (or == ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE || |
| 3070 | or == ActivityInfo.SCREEN_ORIENTATION_PORTRAIT || |
| 3071 | or == ActivityInfo.SCREEN_ORIENTATION_SENSOR || |
| 3072 | or == ActivityInfo.SCREEN_ORIENTATION_NOSENSOR || |
| 3073 | or == ActivityInfo.SCREEN_ORIENTATION_USER) { |
| 3074 | return or; |
| 3075 | } |
| 3076 | findingBehind |= (or == ActivityInfo.SCREEN_ORIENTATION_BEHIND); |
| 3077 | } |
| 3078 | return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3079 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3080 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3081 | public Configuration updateOrientationFromAppTokens( |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3082 | Configuration currentConfig, IBinder freezeThisOneIfNeeded) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3083 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3084 | "updateOrientationFromAppTokens()")) { |
| 3085 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| 3086 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3087 | |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3088 | Configuration config = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3089 | long ident = Binder.clearCallingIdentity(); |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3090 | |
| 3091 | synchronized(mWindowMap) { |
| 3092 | if (updateOrientationFromAppTokensLocked()) { |
| 3093 | if (freezeThisOneIfNeeded != null) { |
| 3094 | AppWindowToken wtoken = findAppWindowToken( |
| 3095 | freezeThisOneIfNeeded); |
| 3096 | if (wtoken != null) { |
| 3097 | startAppFreezingScreenLocked(wtoken, |
| 3098 | ActivityInfo.CONFIG_ORIENTATION); |
| 3099 | } |
| 3100 | } |
| 3101 | config = computeNewConfigurationLocked(); |
| 3102 | |
| 3103 | } else if (currentConfig != null) { |
| 3104 | // No obvious action we need to take, but if our current |
| 3105 | // state mismatches the activity maanager's, update it |
| 3106 | mTempConfiguration.setToDefaults(); |
| 3107 | if (computeNewConfigurationLocked(mTempConfiguration)) { |
| 3108 | if (currentConfig.diff(mTempConfiguration) != 0) { |
| 3109 | mWaitingForConfig = true; |
| 3110 | mLayoutNeeded = true; |
| 3111 | startFreezingDisplayLocked(); |
| 3112 | config = new Configuration(mTempConfiguration); |
| 3113 | } |
| 3114 | } |
| 3115 | } |
| 3116 | } |
| 3117 | |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3118 | Binder.restoreCallingIdentity(ident); |
| 3119 | return config; |
| 3120 | } |
| 3121 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3122 | /* |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3123 | * Determine the new desired orientation of the display, returning |
| 3124 | * a non-null new Configuration if it has changed from the current |
| 3125 | * orientation. IF TRUE IS RETURNED SOMEONE MUST CALL |
| 3126 | * setNewConfiguration() TO TELL THE WINDOW MANAGER IT CAN UNFREEZE THE |
| 3127 | * SCREEN. This will typically be done for you if you call |
| 3128 | * sendNewConfiguration(). |
| 3129 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3130 | * The orientation is computed from non-application windows first. If none of |
| 3131 | * the non-application windows specify orientation, the orientation is computed from |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3132 | * application tokens. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3133 | * @see android.view.IWindowManager#updateOrientationFromAppTokens( |
| 3134 | * android.os.IBinder) |
| 3135 | */ |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3136 | boolean updateOrientationFromAppTokensLocked() { |
Christopher Tate | b696aee | 2010-04-02 19:08:30 -0700 | [diff] [blame] | 3137 | if (mDisplayFrozen) { |
| 3138 | // If the display is frozen, some activities may be in the middle |
| 3139 | // of restarting, and thus have removed their old window. If the |
| 3140 | // window has the flag to hide the lock screen, then the lock screen |
| 3141 | // can re-appear and inflict its own orientation on us. Keep the |
| 3142 | // orientation stable until this all settles down. |
| 3143 | return false; |
| 3144 | } |
| 3145 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3146 | boolean changed = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3147 | long ident = Binder.clearCallingIdentity(); |
| 3148 | try { |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 3149 | int req = computeForcedAppOrientationLocked(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3150 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3151 | if (req != mForcedAppOrientation) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3152 | mForcedAppOrientation = req; |
| 3153 | //send a message to Policy indicating orientation change to take |
| 3154 | //action like disabling/enabling sensors etc., |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 3155 | mPolicy.setCurrentOrientationLw(req); |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3156 | if (setRotationUncheckedLocked(WindowManagerPolicy.USE_LAST_ROTATION, |
| 3157 | mLastRotationFlags | Surface.FLAGS_ORIENTATION_ANIMATION_DISABLE)) { |
| 3158 | changed = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3159 | } |
| 3160 | } |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3161 | |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3162 | return changed; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3163 | } finally { |
| 3164 | Binder.restoreCallingIdentity(ident); |
| 3165 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3166 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3167 | |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 3168 | int computeForcedAppOrientationLocked() { |
| 3169 | int req = getOrientationFromWindowsLocked(); |
| 3170 | if (req == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) { |
| 3171 | req = getOrientationFromAppTokensLocked(); |
| 3172 | } |
| 3173 | return req; |
| 3174 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3175 | |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3176 | public void setNewConfiguration(Configuration config) { |
| 3177 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3178 | "setNewConfiguration()")) { |
| 3179 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| 3180 | } |
| 3181 | |
| 3182 | synchronized(mWindowMap) { |
| 3183 | mCurConfiguration = new Configuration(config); |
| 3184 | mWaitingForConfig = false; |
| 3185 | performLayoutAndPlaceSurfacesLocked(); |
| 3186 | } |
| 3187 | } |
| 3188 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3189 | public void setAppOrientation(IApplicationToken token, int requestedOrientation) { |
| 3190 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3191 | "setAppOrientation()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3192 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3193 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3194 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3195 | synchronized(mWindowMap) { |
| 3196 | AppWindowToken wtoken = findAppWindowToken(token.asBinder()); |
| 3197 | if (wtoken == null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3198 | 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] | 3199 | return; |
| 3200 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3201 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3202 | wtoken.requestedOrientation = requestedOrientation; |
| 3203 | } |
| 3204 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3205 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3206 | public int getAppOrientation(IApplicationToken token) { |
| 3207 | synchronized(mWindowMap) { |
| 3208 | AppWindowToken wtoken = findAppWindowToken(token.asBinder()); |
| 3209 | if (wtoken == null) { |
| 3210 | return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
| 3211 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3212 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3213 | return wtoken.requestedOrientation; |
| 3214 | } |
| 3215 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3216 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3217 | public void setFocusedApp(IBinder token, boolean moveFocusNow) { |
| 3218 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3219 | "setFocusedApp()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3220 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3221 | } |
| 3222 | |
| 3223 | synchronized(mWindowMap) { |
| 3224 | boolean changed = false; |
| 3225 | if (token == null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3226 | 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] | 3227 | changed = mFocusedApp != null; |
| 3228 | mFocusedApp = null; |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 3229 | if (changed) { |
| 3230 | mInputMonitor.setFocusedAppLw(null); |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 3231 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3232 | } else { |
| 3233 | AppWindowToken newFocus = findAppWindowToken(token); |
| 3234 | if (newFocus == null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3235 | 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] | 3236 | return; |
| 3237 | } |
| 3238 | changed = mFocusedApp != newFocus; |
| 3239 | mFocusedApp = newFocus; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3240 | if (DEBUG_FOCUS) Slog.v(TAG, "Set focused app to: " + mFocusedApp); |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 3241 | if (changed) { |
| 3242 | mInputMonitor.setFocusedAppLw(newFocus); |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 3243 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3244 | } |
| 3245 | |
| 3246 | if (moveFocusNow && changed) { |
| 3247 | final long origId = Binder.clearCallingIdentity(); |
| 3248 | updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL); |
| 3249 | Binder.restoreCallingIdentity(origId); |
| 3250 | } |
| 3251 | } |
| 3252 | } |
| 3253 | |
| 3254 | public void prepareAppTransition(int transit) { |
| 3255 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3256 | "prepareAppTransition()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3257 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3258 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3259 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3260 | synchronized(mWindowMap) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3261 | if (DEBUG_APP_TRANSITIONS) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3262 | TAG, "Prepare app transition: transit=" + transit |
| 3263 | + " mNextAppTransition=" + mNextAppTransition); |
Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 3264 | if (!mDisplayFrozen && mPolicy.isScreenOn()) { |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 3265 | if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET |
| 3266 | || mNextAppTransition == WindowManagerPolicy.TRANSIT_NONE) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3267 | mNextAppTransition = transit; |
Dianne Hackborn | d7cd29d | 2009-07-01 11:22:45 -0700 | [diff] [blame] | 3268 | } else if (transit == WindowManagerPolicy.TRANSIT_TASK_OPEN |
| 3269 | && mNextAppTransition == WindowManagerPolicy.TRANSIT_TASK_CLOSE) { |
| 3270 | // Opening a new task always supersedes a close for the anim. |
| 3271 | mNextAppTransition = transit; |
| 3272 | } else if (transit == WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN |
| 3273 | && mNextAppTransition == WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE) { |
| 3274 | // Opening a new activity always supersedes a close for the anim. |
| 3275 | mNextAppTransition = transit; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3276 | } |
| 3277 | mAppTransitionReady = false; |
| 3278 | mAppTransitionTimeout = false; |
| 3279 | mStartingIconInTransition = false; |
| 3280 | mSkipAppTransitionAnimation = false; |
| 3281 | mH.removeMessages(H.APP_TRANSITION_TIMEOUT); |
| 3282 | mH.sendMessageDelayed(mH.obtainMessage(H.APP_TRANSITION_TIMEOUT), |
| 3283 | 5000); |
| 3284 | } |
| 3285 | } |
| 3286 | } |
| 3287 | |
| 3288 | public int getPendingAppTransition() { |
| 3289 | return mNextAppTransition; |
| 3290 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3291 | |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 3292 | public void overridePendingAppTransition(String packageName, |
| 3293 | int enterAnim, int exitAnim) { |
Dianne Hackborn | 8b571a8 | 2009-09-25 16:09:43 -0700 | [diff] [blame] | 3294 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 3295 | mNextAppTransitionPackage = packageName; |
| 3296 | mNextAppTransitionEnter = enterAnim; |
| 3297 | mNextAppTransitionExit = exitAnim; |
| 3298 | } |
| 3299 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3300 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3301 | public void executeAppTransition() { |
| 3302 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3303 | "executeAppTransition()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3304 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3305 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3306 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3307 | synchronized(mWindowMap) { |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 3308 | if (DEBUG_APP_TRANSITIONS) { |
| 3309 | RuntimeException e = new RuntimeException("here"); |
| 3310 | e.fillInStackTrace(); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3311 | Slog.w(TAG, "Execute app transition: mNextAppTransition=" |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 3312 | + mNextAppTransition, e); |
| 3313 | } |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 3314 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3315 | mAppTransitionReady = true; |
| 3316 | final long origId = Binder.clearCallingIdentity(); |
| 3317 | performLayoutAndPlaceSurfacesLocked(); |
| 3318 | Binder.restoreCallingIdentity(origId); |
| 3319 | } |
| 3320 | } |
| 3321 | } |
| 3322 | |
| 3323 | public void setAppStartingWindow(IBinder token, String pkg, |
| 3324 | int theme, CharSequence nonLocalizedLabel, int labelRes, int icon, |
| 3325 | IBinder transferFrom, boolean createIfNeeded) { |
| 3326 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3327 | "setAppStartingIcon()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3328 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3329 | } |
| 3330 | |
| 3331 | synchronized(mWindowMap) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3332 | if (DEBUG_STARTING_WINDOW) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3333 | TAG, "setAppStartingIcon: token=" + token + " pkg=" + pkg |
| 3334 | + " transferFrom=" + transferFrom); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3335 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3336 | AppWindowToken wtoken = findAppWindowToken(token); |
| 3337 | if (wtoken == null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3338 | 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] | 3339 | return; |
| 3340 | } |
| 3341 | |
| 3342 | // If the display is frozen, we won't do anything until the |
| 3343 | // actual window is displayed so there is no reason to put in |
| 3344 | // the starting window. |
Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 3345 | if (mDisplayFrozen || !mPolicy.isScreenOn()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3346 | return; |
| 3347 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3348 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3349 | if (wtoken.startingData != null) { |
| 3350 | return; |
| 3351 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3352 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3353 | if (transferFrom != null) { |
| 3354 | AppWindowToken ttoken = findAppWindowToken(transferFrom); |
| 3355 | if (ttoken != null) { |
| 3356 | WindowState startingWindow = ttoken.startingWindow; |
| 3357 | if (startingWindow != null) { |
| 3358 | if (mStartingIconInTransition) { |
| 3359 | // In this case, the starting icon has already |
| 3360 | // been displayed, so start letting windows get |
| 3361 | // shown immediately without any more transitions. |
| 3362 | mSkipAppTransitionAnimation = true; |
| 3363 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3364 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3365 | "Moving existing starting from " + ttoken |
| 3366 | + " to " + wtoken); |
| 3367 | final long origId = Binder.clearCallingIdentity(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3368 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3369 | // Transfer the starting window over to the new |
| 3370 | // token. |
| 3371 | wtoken.startingData = ttoken.startingData; |
| 3372 | wtoken.startingView = ttoken.startingView; |
| 3373 | wtoken.startingWindow = startingWindow; |
| 3374 | ttoken.startingData = null; |
| 3375 | ttoken.startingView = null; |
| 3376 | ttoken.startingWindow = null; |
| 3377 | ttoken.startingMoved = true; |
| 3378 | startingWindow.mToken = wtoken; |
Dianne Hackborn | ef49c57 | 2009-03-24 19:27:32 -0700 | [diff] [blame] | 3379 | startingWindow.mRootToken = wtoken; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3380 | startingWindow.mAppToken = wtoken; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3381 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 3382 | "Removing starting window: " + startingWindow); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3383 | mWindows.remove(startingWindow); |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 3384 | mWindowsChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3385 | ttoken.windows.remove(startingWindow); |
| 3386 | ttoken.allAppWindows.remove(startingWindow); |
| 3387 | addWindowToListInOrderLocked(startingWindow, true); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3388 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3389 | // Propagate other interesting state between the |
| 3390 | // tokens. If the old token is displayed, we should |
| 3391 | // immediately force the new one to be displayed. If |
| 3392 | // it is animating, we need to move that animation to |
| 3393 | // the new one. |
| 3394 | if (ttoken.allDrawn) { |
| 3395 | wtoken.allDrawn = true; |
| 3396 | } |
| 3397 | if (ttoken.firstWindowDrawn) { |
| 3398 | wtoken.firstWindowDrawn = true; |
| 3399 | } |
| 3400 | if (!ttoken.hidden) { |
| 3401 | wtoken.hidden = false; |
| 3402 | wtoken.hiddenRequested = false; |
| 3403 | wtoken.willBeHidden = false; |
| 3404 | } |
| 3405 | if (wtoken.clientHidden != ttoken.clientHidden) { |
| 3406 | wtoken.clientHidden = ttoken.clientHidden; |
| 3407 | wtoken.sendAppVisibilityToClients(); |
| 3408 | } |
| 3409 | if (ttoken.animation != null) { |
| 3410 | wtoken.animation = ttoken.animation; |
| 3411 | wtoken.animating = ttoken.animating; |
| 3412 | wtoken.animLayerAdjustment = ttoken.animLayerAdjustment; |
| 3413 | ttoken.animation = null; |
| 3414 | ttoken.animLayerAdjustment = 0; |
| 3415 | wtoken.updateLayers(); |
| 3416 | ttoken.updateLayers(); |
| 3417 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3418 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3419 | updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3420 | mLayoutNeeded = true; |
| 3421 | performLayoutAndPlaceSurfacesLocked(); |
| 3422 | Binder.restoreCallingIdentity(origId); |
| 3423 | return; |
| 3424 | } else if (ttoken.startingData != null) { |
| 3425 | // The previous app was getting ready to show a |
| 3426 | // starting window, but hasn't yet done so. Steal it! |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3427 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3428 | "Moving pending starting from " + ttoken |
| 3429 | + " to " + wtoken); |
| 3430 | wtoken.startingData = ttoken.startingData; |
| 3431 | ttoken.startingData = null; |
| 3432 | ttoken.startingMoved = true; |
| 3433 | Message m = mH.obtainMessage(H.ADD_STARTING, wtoken); |
| 3434 | // Note: we really want to do sendMessageAtFrontOfQueue() because we |
| 3435 | // want to process the message ASAP, before any other queued |
| 3436 | // messages. |
| 3437 | mH.sendMessageAtFrontOfQueue(m); |
| 3438 | return; |
| 3439 | } |
| 3440 | } |
| 3441 | } |
| 3442 | |
| 3443 | // There is no existing starting window, and the caller doesn't |
| 3444 | // want us to create one, so that's it! |
| 3445 | if (!createIfNeeded) { |
| 3446 | return; |
| 3447 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3448 | |
Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 3449 | // If this is a translucent or wallpaper window, then don't |
| 3450 | // show a starting window -- the current effect (a full-screen |
| 3451 | // opaque starting window that fades away to the real contents |
| 3452 | // when it is ready) does not work for this. |
| 3453 | if (theme != 0) { |
| 3454 | AttributeCache.Entry ent = AttributeCache.instance().get(pkg, theme, |
| 3455 | com.android.internal.R.styleable.Window); |
| 3456 | if (ent.array.getBoolean( |
| 3457 | com.android.internal.R.styleable.Window_windowIsTranslucent, false)) { |
| 3458 | return; |
| 3459 | } |
| 3460 | if (ent.array.getBoolean( |
Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 3461 | com.android.internal.R.styleable.Window_windowIsFloating, false)) { |
| 3462 | return; |
| 3463 | } |
| 3464 | if (ent.array.getBoolean( |
Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 3465 | com.android.internal.R.styleable.Window_windowShowWallpaper, false)) { |
| 3466 | return; |
| 3467 | } |
| 3468 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3469 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3470 | mStartingIconInTransition = true; |
| 3471 | wtoken.startingData = new StartingData( |
| 3472 | pkg, theme, nonLocalizedLabel, |
| 3473 | labelRes, icon); |
| 3474 | Message m = mH.obtainMessage(H.ADD_STARTING, wtoken); |
| 3475 | // Note: we really want to do sendMessageAtFrontOfQueue() because we |
| 3476 | // want to process the message ASAP, before any other queued |
| 3477 | // messages. |
| 3478 | mH.sendMessageAtFrontOfQueue(m); |
| 3479 | } |
| 3480 | } |
| 3481 | |
| 3482 | public void setAppWillBeHidden(IBinder token) { |
| 3483 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3484 | "setAppWillBeHidden()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3485 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3486 | } |
| 3487 | |
| 3488 | AppWindowToken wtoken; |
| 3489 | |
| 3490 | synchronized(mWindowMap) { |
| 3491 | wtoken = findAppWindowToken(token); |
| 3492 | if (wtoken == null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3493 | 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] | 3494 | return; |
| 3495 | } |
| 3496 | wtoken.willBeHidden = true; |
| 3497 | } |
| 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 | boolean setTokenVisibilityLocked(AppWindowToken wtoken, WindowManager.LayoutParams lp, |
| 3501 | boolean visible, int transit, boolean performLayout) { |
| 3502 | boolean delayed = false; |
| 3503 | |
| 3504 | if (wtoken.clientHidden == visible) { |
| 3505 | wtoken.clientHidden = !visible; |
| 3506 | wtoken.sendAppVisibilityToClients(); |
| 3507 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3508 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3509 | wtoken.willBeHidden = false; |
| 3510 | if (wtoken.hidden == visible) { |
| 3511 | final int N = wtoken.allAppWindows.size(); |
| 3512 | boolean changed = false; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3513 | if (DEBUG_APP_TRANSITIONS) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3514 | TAG, "Changing app " + wtoken + " hidden=" + wtoken.hidden |
| 3515 | + " performLayout=" + performLayout); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3516 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3517 | boolean runningAppAnimation = false; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3518 | |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 3519 | if (transit != WindowManagerPolicy.TRANSIT_UNSET) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3520 | if (wtoken.animation == sDummyAnimation) { |
| 3521 | wtoken.animation = null; |
| 3522 | } |
| 3523 | applyAnimationLocked(wtoken, lp, transit, visible); |
| 3524 | changed = true; |
| 3525 | if (wtoken.animation != null) { |
| 3526 | delayed = runningAppAnimation = true; |
| 3527 | } |
| 3528 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3529 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3530 | for (int i=0; i<N; i++) { |
| 3531 | WindowState win = wtoken.allAppWindows.get(i); |
| 3532 | if (win == wtoken.startingWindow) { |
| 3533 | continue; |
| 3534 | } |
| 3535 | |
| 3536 | if (win.isAnimating()) { |
| 3537 | delayed = true; |
| 3538 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3539 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3540 | //Slog.i(TAG, "Window " + win + ": vis=" + win.isVisible()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3541 | //win.dump(" "); |
| 3542 | if (visible) { |
| 3543 | if (!win.isVisibleNow()) { |
| 3544 | if (!runningAppAnimation) { |
| 3545 | applyAnimationLocked(win, |
| 3546 | WindowManagerPolicy.TRANSIT_ENTER, true); |
| 3547 | } |
| 3548 | changed = true; |
| 3549 | } |
| 3550 | } else if (win.isVisibleNow()) { |
| 3551 | if (!runningAppAnimation) { |
| 3552 | applyAnimationLocked(win, |
| 3553 | WindowManagerPolicy.TRANSIT_EXIT, false); |
| 3554 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3555 | changed = true; |
| 3556 | } |
| 3557 | } |
| 3558 | |
| 3559 | wtoken.hidden = wtoken.hiddenRequested = !visible; |
| 3560 | if (!visible) { |
| 3561 | unsetAppFreezingScreenLocked(wtoken, true, true); |
| 3562 | } else { |
| 3563 | // If we are being set visible, and the starting window is |
| 3564 | // not yet displayed, then make sure it doesn't get displayed. |
| 3565 | WindowState swin = wtoken.startingWindow; |
| 3566 | if (swin != null && (swin.mDrawPending |
| 3567 | || swin.mCommitDrawPending)) { |
| 3568 | swin.mPolicyVisibility = false; |
| 3569 | swin.mPolicyVisibilityAfterAnim = false; |
| 3570 | } |
| 3571 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3572 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3573 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "setTokenVisibilityLocked: " + wtoken |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3574 | + ": hidden=" + wtoken.hidden + " hiddenRequested=" |
| 3575 | + wtoken.hiddenRequested); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3576 | |
Dianne Hackborn | 9b52a21 | 2009-12-11 14:51:35 -0800 | [diff] [blame] | 3577 | if (changed) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3578 | mLayoutNeeded = true; |
Dianne Hackborn | 9b52a21 | 2009-12-11 14:51:35 -0800 | [diff] [blame] | 3579 | if (performLayout) { |
| 3580 | updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES); |
| 3581 | performLayoutAndPlaceSurfacesLocked(); |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 3582 | } else { |
| 3583 | mInputMonitor.updateInputWindowsLw(); |
Dianne Hackborn | 9b52a21 | 2009-12-11 14:51:35 -0800 | [diff] [blame] | 3584 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3585 | } |
| 3586 | } |
| 3587 | |
| 3588 | if (wtoken.animation != null) { |
| 3589 | delayed = true; |
| 3590 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3591 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3592 | return delayed; |
| 3593 | } |
| 3594 | |
| 3595 | public void setAppVisibility(IBinder token, boolean visible) { |
| 3596 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3597 | "setAppVisibility()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3598 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3599 | } |
| 3600 | |
| 3601 | AppWindowToken wtoken; |
| 3602 | |
| 3603 | synchronized(mWindowMap) { |
| 3604 | wtoken = findAppWindowToken(token); |
| 3605 | if (wtoken == null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3606 | 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] | 3607 | return; |
| 3608 | } |
| 3609 | |
| 3610 | if (DEBUG_APP_TRANSITIONS || DEBUG_ORIENTATION) { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 3611 | RuntimeException e = null; |
| 3612 | if (!HIDE_STACK_CRAWLS) { |
| 3613 | e = new RuntimeException(); |
| 3614 | e.fillInStackTrace(); |
| 3615 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3616 | Slog.v(TAG, "setAppVisibility(" + token + ", " + visible |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3617 | + "): mNextAppTransition=" + mNextAppTransition |
| 3618 | + " hidden=" + wtoken.hidden |
| 3619 | + " hiddenRequested=" + wtoken.hiddenRequested, e); |
| 3620 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3621 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3622 | // If we are preparing an app transition, then delay changing |
| 3623 | // the visibility of this token until we execute that transition. |
Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 3624 | if (!mDisplayFrozen && mPolicy.isScreenOn() |
| 3625 | && mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3626 | // Already in requested state, don't do anything more. |
| 3627 | if (wtoken.hiddenRequested != visible) { |
| 3628 | return; |
| 3629 | } |
| 3630 | wtoken.hiddenRequested = !visible; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3631 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3632 | if (DEBUG_APP_TRANSITIONS) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3633 | TAG, "Setting dummy animation on: " + wtoken); |
| 3634 | wtoken.setDummyAnimation(); |
| 3635 | mOpeningApps.remove(wtoken); |
| 3636 | mClosingApps.remove(wtoken); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 3637 | wtoken.waitingToShow = wtoken.waitingToHide = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3638 | wtoken.inPendingTransaction = true; |
| 3639 | if (visible) { |
| 3640 | mOpeningApps.add(wtoken); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3641 | wtoken.startingDisplayed = false; |
| 3642 | wtoken.startingMoved = false; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3643 | |
Dianne Hackborn | 195f6a0 | 2009-11-24 11:26:00 -0800 | [diff] [blame] | 3644 | // If the token is currently hidden (should be the |
| 3645 | // common case), then we need to set up to wait for |
| 3646 | // its windows to be ready. |
| 3647 | if (wtoken.hidden) { |
| 3648 | wtoken.allDrawn = false; |
| 3649 | wtoken.waitingToShow = true; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3650 | |
Dianne Hackborn | 195f6a0 | 2009-11-24 11:26:00 -0800 | [diff] [blame] | 3651 | if (wtoken.clientHidden) { |
| 3652 | // In the case where we are making an app visible |
| 3653 | // but holding off for a transition, we still need |
| 3654 | // to tell the client to make its windows visible so |
| 3655 | // they get drawn. Otherwise, we will wait on |
| 3656 | // performing the transition until all windows have |
| 3657 | // been drawn, they never will be, and we are sad. |
| 3658 | wtoken.clientHidden = false; |
| 3659 | wtoken.sendAppVisibilityToClients(); |
| 3660 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3661 | } |
| 3662 | } else { |
| 3663 | mClosingApps.add(wtoken); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3664 | |
Dianne Hackborn | 195f6a0 | 2009-11-24 11:26:00 -0800 | [diff] [blame] | 3665 | // If the token is currently visible (should be the |
| 3666 | // common case), then set up to wait for it to be hidden. |
| 3667 | if (!wtoken.hidden) { |
| 3668 | wtoken.waitingToHide = true; |
| 3669 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3670 | } |
| 3671 | return; |
| 3672 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3673 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3674 | final long origId = Binder.clearCallingIdentity(); |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 3675 | setTokenVisibilityLocked(wtoken, null, visible, WindowManagerPolicy.TRANSIT_UNSET, true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3676 | wtoken.updateReportedVisibilityLocked(); |
| 3677 | Binder.restoreCallingIdentity(origId); |
| 3678 | } |
| 3679 | } |
| 3680 | |
| 3681 | void unsetAppFreezingScreenLocked(AppWindowToken wtoken, |
| 3682 | boolean unfreezeSurfaceNow, boolean force) { |
| 3683 | if (wtoken.freezingScreen) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3684 | 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] | 3685 | + " force=" + force); |
| 3686 | final int N = wtoken.allAppWindows.size(); |
| 3687 | boolean unfrozeWindows = false; |
| 3688 | for (int i=0; i<N; i++) { |
| 3689 | WindowState w = wtoken.allAppWindows.get(i); |
| 3690 | if (w.mAppFreezing) { |
| 3691 | w.mAppFreezing = false; |
| 3692 | if (w.mSurface != null && !w.mOrientationChanging) { |
| 3693 | w.mOrientationChanging = true; |
| 3694 | } |
| 3695 | unfrozeWindows = true; |
| 3696 | } |
| 3697 | } |
| 3698 | if (force || unfrozeWindows) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3699 | 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] | 3700 | wtoken.freezingScreen = false; |
| 3701 | mAppsFreezingScreen--; |
| 3702 | } |
| 3703 | if (unfreezeSurfaceNow) { |
| 3704 | if (unfrozeWindows) { |
| 3705 | mLayoutNeeded = true; |
| 3706 | performLayoutAndPlaceSurfacesLocked(); |
| 3707 | } |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3708 | stopFreezingDisplayLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3709 | } |
| 3710 | } |
| 3711 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3712 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3713 | public void startAppFreezingScreenLocked(AppWindowToken wtoken, |
| 3714 | int configChanges) { |
| 3715 | if (DEBUG_ORIENTATION) { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 3716 | RuntimeException e = null; |
| 3717 | if (!HIDE_STACK_CRAWLS) { |
| 3718 | e = new RuntimeException(); |
| 3719 | e.fillInStackTrace(); |
| 3720 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3721 | Slog.i(TAG, "Set freezing of " + wtoken.appToken |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3722 | + ": hidden=" + wtoken.hidden + " freezing=" |
| 3723 | + wtoken.freezingScreen, e); |
| 3724 | } |
| 3725 | if (!wtoken.hiddenRequested) { |
| 3726 | if (!wtoken.freezingScreen) { |
| 3727 | wtoken.freezingScreen = true; |
| 3728 | mAppsFreezingScreen++; |
| 3729 | if (mAppsFreezingScreen == 1) { |
| 3730 | startFreezingDisplayLocked(); |
| 3731 | mH.removeMessages(H.APP_FREEZE_TIMEOUT); |
| 3732 | mH.sendMessageDelayed(mH.obtainMessage(H.APP_FREEZE_TIMEOUT), |
| 3733 | 5000); |
| 3734 | } |
| 3735 | } |
| 3736 | final int N = wtoken.allAppWindows.size(); |
| 3737 | for (int i=0; i<N; i++) { |
| 3738 | WindowState w = wtoken.allAppWindows.get(i); |
| 3739 | w.mAppFreezing = true; |
| 3740 | } |
| 3741 | } |
| 3742 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3743 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3744 | public void startAppFreezingScreen(IBinder token, int configChanges) { |
| 3745 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3746 | "setAppFreezingScreen()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3747 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3748 | } |
| 3749 | |
| 3750 | synchronized(mWindowMap) { |
Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 3751 | if (configChanges == 0 && !mDisplayFrozen && mPolicy.isScreenOn()) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3752 | 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] | 3753 | return; |
| 3754 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3755 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3756 | AppWindowToken wtoken = findAppWindowToken(token); |
| 3757 | if (wtoken == null || wtoken.appToken == null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3758 | 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] | 3759 | return; |
| 3760 | } |
| 3761 | final long origId = Binder.clearCallingIdentity(); |
| 3762 | startAppFreezingScreenLocked(wtoken, configChanges); |
| 3763 | Binder.restoreCallingIdentity(origId); |
| 3764 | } |
| 3765 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3766 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3767 | public void stopAppFreezingScreen(IBinder token, boolean force) { |
| 3768 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3769 | "setAppFreezingScreen()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3770 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3771 | } |
| 3772 | |
| 3773 | synchronized(mWindowMap) { |
| 3774 | AppWindowToken wtoken = findAppWindowToken(token); |
| 3775 | if (wtoken == null || wtoken.appToken == null) { |
| 3776 | return; |
| 3777 | } |
| 3778 | final long origId = Binder.clearCallingIdentity(); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3779 | 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] | 3780 | + ": hidden=" + wtoken.hidden + " freezing=" + wtoken.freezingScreen); |
| 3781 | unsetAppFreezingScreenLocked(wtoken, true, force); |
| 3782 | Binder.restoreCallingIdentity(origId); |
| 3783 | } |
| 3784 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3785 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3786 | public void removeAppToken(IBinder token) { |
| 3787 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3788 | "removeAppToken()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3789 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3790 | } |
| 3791 | |
| 3792 | AppWindowToken wtoken = null; |
| 3793 | AppWindowToken startingToken = null; |
| 3794 | boolean delayed = false; |
| 3795 | |
| 3796 | final long origId = Binder.clearCallingIdentity(); |
| 3797 | synchronized(mWindowMap) { |
| 3798 | WindowToken basewtoken = mTokenMap.remove(token); |
| 3799 | mTokenList.remove(basewtoken); |
| 3800 | if (basewtoken != null && (wtoken=basewtoken.appWindowToken) != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3801 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "Removing app token: " + wtoken); |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 3802 | delayed = setTokenVisibilityLocked(wtoken, null, false, WindowManagerPolicy.TRANSIT_UNSET, true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3803 | wtoken.inPendingTransaction = false; |
| 3804 | mOpeningApps.remove(wtoken); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 3805 | wtoken.waitingToShow = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3806 | if (mClosingApps.contains(wtoken)) { |
| 3807 | delayed = true; |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 3808 | } else if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3809 | mClosingApps.add(wtoken); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 3810 | wtoken.waitingToHide = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3811 | delayed = true; |
| 3812 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3813 | if (DEBUG_APP_TRANSITIONS) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3814 | TAG, "Removing app " + wtoken + " delayed=" + delayed |
| 3815 | + " animation=" + wtoken.animation |
| 3816 | + " animating=" + wtoken.animating); |
| 3817 | if (delayed) { |
| 3818 | // set the token aside because it has an active animation to be finished |
| 3819 | mExitingAppTokens.add(wtoken); |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 3820 | } else { |
| 3821 | // Make sure there is no animation running on this token, |
| 3822 | // so any windows associated with it will be removed as |
| 3823 | // soon as their animations are complete |
| 3824 | wtoken.animation = null; |
| 3825 | wtoken.animating = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3826 | } |
| 3827 | mAppTokens.remove(wtoken); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 3828 | if (mLastEnterAnimToken == wtoken) { |
| 3829 | mLastEnterAnimToken = null; |
| 3830 | mLastEnterAnimParams = null; |
| 3831 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3832 | wtoken.removed = true; |
| 3833 | if (wtoken.startingData != null) { |
| 3834 | startingToken = wtoken; |
| 3835 | } |
| 3836 | unsetAppFreezingScreenLocked(wtoken, true, true); |
| 3837 | if (mFocusedApp == wtoken) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3838 | 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] | 3839 | mFocusedApp = null; |
| 3840 | updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL); |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 3841 | mInputMonitor.setFocusedAppLw(null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3842 | } |
| 3843 | } else { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3844 | 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] | 3845 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3846 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3847 | if (!delayed && wtoken != null) { |
| 3848 | wtoken.updateReportedVisibilityLocked(); |
| 3849 | } |
| 3850 | } |
| 3851 | Binder.restoreCallingIdentity(origId); |
| 3852 | |
| 3853 | if (startingToken != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3854 | 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] | 3855 | + startingToken + ": app token removed"); |
| 3856 | Message m = mH.obtainMessage(H.REMOVE_STARTING, startingToken); |
| 3857 | mH.sendMessage(m); |
| 3858 | } |
| 3859 | } |
| 3860 | |
| 3861 | private boolean tmpRemoveAppWindowsLocked(WindowToken token) { |
| 3862 | final int NW = token.windows.size(); |
| 3863 | for (int i=0; i<NW; i++) { |
| 3864 | WindowState win = token.windows.get(i); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3865 | 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] | 3866 | mWindows.remove(win); |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 3867 | mWindowsChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3868 | int j = win.mChildWindows.size(); |
| 3869 | while (j > 0) { |
| 3870 | j--; |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 3871 | WindowState cwin = win.mChildWindows.get(j); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3872 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, |
Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 3873 | "Tmp removing child window " + cwin); |
| 3874 | mWindows.remove(cwin); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3875 | } |
| 3876 | } |
| 3877 | return NW > 0; |
| 3878 | } |
| 3879 | |
| 3880 | void dumpAppTokensLocked() { |
| 3881 | for (int i=mAppTokens.size()-1; i>=0; i--) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3882 | Slog.v(TAG, " #" + i + ": " + mAppTokens.get(i).token); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3883 | } |
| 3884 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3885 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3886 | void dumpWindowsLocked() { |
| 3887 | for (int i=mWindows.size()-1; i>=0; i--) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3888 | Slog.v(TAG, " #" + i + ": " + mWindows.get(i)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3889 | } |
| 3890 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3891 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3892 | private int findWindowOffsetLocked(int tokenPos) { |
| 3893 | final int NW = mWindows.size(); |
| 3894 | |
| 3895 | if (tokenPos >= mAppTokens.size()) { |
| 3896 | int i = NW; |
| 3897 | while (i > 0) { |
| 3898 | i--; |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 3899 | WindowState win = mWindows.get(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3900 | if (win.getAppToken() != null) { |
| 3901 | return i+1; |
| 3902 | } |
| 3903 | } |
| 3904 | } |
| 3905 | |
| 3906 | while (tokenPos > 0) { |
| 3907 | // Find the first app token below the new position that has |
| 3908 | // a window displayed. |
| 3909 | final AppWindowToken wtoken = mAppTokens.get(tokenPos-1); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3910 | 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] | 3911 | + tokenPos + " -- " + wtoken.token); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 3912 | if (wtoken.sendingToBottom) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3913 | if (DEBUG_REORDER) Slog.v(TAG, |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 3914 | "Skipping token -- currently sending to bottom"); |
| 3915 | tokenPos--; |
| 3916 | continue; |
| 3917 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3918 | int i = wtoken.windows.size(); |
| 3919 | while (i > 0) { |
| 3920 | i--; |
| 3921 | WindowState win = wtoken.windows.get(i); |
| 3922 | int j = win.mChildWindows.size(); |
| 3923 | while (j > 0) { |
| 3924 | j--; |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 3925 | WindowState cwin = win.mChildWindows.get(j); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 3926 | if (cwin.mSubLayer >= 0) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3927 | for (int pos=NW-1; pos>=0; pos--) { |
| 3928 | if (mWindows.get(pos) == cwin) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3929 | if (DEBUG_REORDER) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3930 | "Found child win @" + (pos+1)); |
| 3931 | return pos+1; |
| 3932 | } |
| 3933 | } |
| 3934 | } |
| 3935 | } |
| 3936 | for (int pos=NW-1; pos>=0; pos--) { |
| 3937 | if (mWindows.get(pos) == win) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3938 | 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] | 3939 | return pos+1; |
| 3940 | } |
| 3941 | } |
| 3942 | } |
| 3943 | tokenPos--; |
| 3944 | } |
| 3945 | |
| 3946 | return 0; |
| 3947 | } |
| 3948 | |
| 3949 | private final int reAddWindowLocked(int index, WindowState win) { |
| 3950 | final int NCW = win.mChildWindows.size(); |
| 3951 | boolean added = false; |
| 3952 | for (int j=0; j<NCW; j++) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 3953 | WindowState cwin = win.mChildWindows.get(j); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3954 | if (!added && cwin.mSubLayer >= 0) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3955 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding child window at " |
Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 3956 | + index + ": " + cwin); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3957 | mWindows.add(index, win); |
| 3958 | index++; |
| 3959 | added = true; |
| 3960 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3961 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding window at " |
Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 3962 | + index + ": " + cwin); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3963 | mWindows.add(index, cwin); |
| 3964 | index++; |
| 3965 | } |
| 3966 | if (!added) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3967 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding window at " |
Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 3968 | + index + ": " + win); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3969 | mWindows.add(index, win); |
| 3970 | index++; |
| 3971 | } |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 3972 | mWindowsChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3973 | return index; |
| 3974 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3975 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3976 | private final int reAddAppWindowsLocked(int index, WindowToken token) { |
| 3977 | final int NW = token.windows.size(); |
| 3978 | for (int i=0; i<NW; i++) { |
| 3979 | index = reAddWindowLocked(index, token.windows.get(i)); |
| 3980 | } |
| 3981 | return index; |
| 3982 | } |
| 3983 | |
| 3984 | public void moveAppToken(int index, IBinder token) { |
| 3985 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3986 | "moveAppToken()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3987 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3988 | } |
| 3989 | |
| 3990 | synchronized(mWindowMap) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3991 | if (DEBUG_REORDER) Slog.v(TAG, "Initial app tokens:"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3992 | if (DEBUG_REORDER) dumpAppTokensLocked(); |
| 3993 | final AppWindowToken wtoken = findAppWindowToken(token); |
| 3994 | if (wtoken == null || !mAppTokens.remove(wtoken)) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3995 | 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] | 3996 | + token + " (" + wtoken + ")"); |
| 3997 | return; |
| 3998 | } |
| 3999 | mAppTokens.add(index, wtoken); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4000 | 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] | 4001 | if (DEBUG_REORDER) dumpAppTokensLocked(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4002 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4003 | final long origId = Binder.clearCallingIdentity(); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4004 | 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] | 4005 | if (DEBUG_REORDER) dumpWindowsLocked(); |
| 4006 | if (tmpRemoveAppWindowsLocked(wtoken)) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4007 | 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] | 4008 | if (DEBUG_REORDER) dumpWindowsLocked(); |
| 4009 | reAddAppWindowsLocked(findWindowOffsetLocked(index), wtoken); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4010 | if (DEBUG_REORDER) Slog.v(TAG, "Final window list:"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4011 | if (DEBUG_REORDER) dumpWindowsLocked(); |
| 4012 | updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4013 | mLayoutNeeded = true; |
| 4014 | performLayoutAndPlaceSurfacesLocked(); |
| 4015 | } |
| 4016 | Binder.restoreCallingIdentity(origId); |
| 4017 | } |
| 4018 | } |
| 4019 | |
| 4020 | private void removeAppTokensLocked(List<IBinder> tokens) { |
| 4021 | // XXX This should be done more efficiently! |
| 4022 | // (take advantage of the fact that both lists should be |
| 4023 | // ordered in the same way.) |
| 4024 | int N = tokens.size(); |
| 4025 | for (int i=0; i<N; i++) { |
| 4026 | IBinder token = tokens.get(i); |
| 4027 | final AppWindowToken wtoken = findAppWindowToken(token); |
| 4028 | if (!mAppTokens.remove(wtoken)) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4029 | 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] | 4030 | + token + " (" + wtoken + ")"); |
| 4031 | i--; |
| 4032 | N--; |
| 4033 | } |
| 4034 | } |
| 4035 | } |
| 4036 | |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4037 | private void moveAppWindowsLocked(AppWindowToken wtoken, int tokenPos, |
| 4038 | boolean updateFocusAndLayout) { |
| 4039 | // First remove all of the windows from the list. |
| 4040 | tmpRemoveAppWindowsLocked(wtoken); |
| 4041 | |
| 4042 | // Where to start adding? |
| 4043 | int pos = findWindowOffsetLocked(tokenPos); |
| 4044 | |
| 4045 | // And now add them back at the correct place. |
| 4046 | pos = reAddAppWindowsLocked(pos, wtoken); |
| 4047 | |
| 4048 | if (updateFocusAndLayout) { |
| 4049 | if (!updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES)) { |
| 4050 | assignLayersLocked(); |
| 4051 | } |
| 4052 | mLayoutNeeded = true; |
| 4053 | performLayoutAndPlaceSurfacesLocked(); |
| 4054 | } |
| 4055 | } |
| 4056 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4057 | private void moveAppWindowsLocked(List<IBinder> tokens, int tokenPos) { |
| 4058 | // First remove all of the windows from the list. |
| 4059 | final int N = tokens.size(); |
| 4060 | int i; |
| 4061 | for (i=0; i<N; i++) { |
| 4062 | WindowToken token = mTokenMap.get(tokens.get(i)); |
| 4063 | if (token != null) { |
| 4064 | tmpRemoveAppWindowsLocked(token); |
| 4065 | } |
| 4066 | } |
| 4067 | |
| 4068 | // Where to start adding? |
| 4069 | int pos = findWindowOffsetLocked(tokenPos); |
| 4070 | |
| 4071 | // And now add them back at the correct place. |
| 4072 | for (i=0; i<N; i++) { |
| 4073 | WindowToken token = mTokenMap.get(tokens.get(i)); |
| 4074 | if (token != null) { |
| 4075 | pos = reAddAppWindowsLocked(pos, token); |
| 4076 | } |
| 4077 | } |
| 4078 | |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4079 | if (!updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES)) { |
| 4080 | assignLayersLocked(); |
| 4081 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4082 | mLayoutNeeded = true; |
| 4083 | performLayoutAndPlaceSurfacesLocked(); |
| 4084 | |
| 4085 | //dump(); |
| 4086 | } |
| 4087 | |
| 4088 | public void moveAppTokensToTop(List<IBinder> tokens) { |
| 4089 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 4090 | "moveAppTokensToTop()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4091 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4092 | } |
| 4093 | |
| 4094 | final long origId = Binder.clearCallingIdentity(); |
| 4095 | synchronized(mWindowMap) { |
| 4096 | removeAppTokensLocked(tokens); |
| 4097 | final int N = tokens.size(); |
| 4098 | for (int i=0; i<N; i++) { |
| 4099 | AppWindowToken wt = findAppWindowToken(tokens.get(i)); |
| 4100 | if (wt != null) { |
| 4101 | mAppTokens.add(wt); |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 4102 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4103 | mToTopApps.remove(wt); |
| 4104 | mToBottomApps.remove(wt); |
| 4105 | mToTopApps.add(wt); |
| 4106 | wt.sendingToBottom = false; |
| 4107 | wt.sendingToTop = true; |
| 4108 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4109 | } |
| 4110 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 4111 | |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 4112 | if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET) { |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4113 | moveAppWindowsLocked(tokens, mAppTokens.size()); |
| 4114 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4115 | } |
| 4116 | Binder.restoreCallingIdentity(origId); |
| 4117 | } |
| 4118 | |
| 4119 | public void moveAppTokensToBottom(List<IBinder> tokens) { |
| 4120 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 4121 | "moveAppTokensToBottom()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4122 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4123 | } |
| 4124 | |
| 4125 | final long origId = Binder.clearCallingIdentity(); |
| 4126 | synchronized(mWindowMap) { |
| 4127 | removeAppTokensLocked(tokens); |
| 4128 | final int N = tokens.size(); |
| 4129 | int pos = 0; |
| 4130 | for (int i=0; i<N; i++) { |
| 4131 | AppWindowToken wt = findAppWindowToken(tokens.get(i)); |
| 4132 | if (wt != null) { |
| 4133 | mAppTokens.add(pos, wt); |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 4134 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4135 | mToTopApps.remove(wt); |
| 4136 | mToBottomApps.remove(wt); |
| 4137 | mToBottomApps.add(i, wt); |
| 4138 | wt.sendingToTop = false; |
| 4139 | wt.sendingToBottom = true; |
| 4140 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4141 | pos++; |
| 4142 | } |
| 4143 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 4144 | |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 4145 | if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET) { |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4146 | moveAppWindowsLocked(tokens, 0); |
| 4147 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4148 | } |
| 4149 | Binder.restoreCallingIdentity(origId); |
| 4150 | } |
| 4151 | |
| 4152 | // ------------------------------------------------------------- |
| 4153 | // Misc IWindowSession methods |
| 4154 | // ------------------------------------------------------------- |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4155 | |
Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 4156 | private boolean shouldAllowDisableKeyguard() |
Jim Miller | d6b5705 | 2010-06-07 17:52:42 -0700 | [diff] [blame] | 4157 | { |
Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 4158 | // We fail safe and prevent disabling keyguard in the unlikely event this gets |
| 4159 | // called before DevicePolicyManagerService has started. |
| 4160 | if (mAllowDisableKeyguard == ALLOW_DISABLE_UNKNOWN) { |
| 4161 | DevicePolicyManager dpm = (DevicePolicyManager) mContext.getSystemService( |
| 4162 | Context.DEVICE_POLICY_SERVICE); |
| 4163 | if (dpm != null) { |
| 4164 | mAllowDisableKeyguard = dpm.getPasswordQuality(null) |
| 4165 | == DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED ? |
| 4166 | ALLOW_DISABLE_YES : ALLOW_DISABLE_NO; |
| 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 | return mAllowDisableKeyguard == ALLOW_DISABLE_YES; |
Jim Miller | d6b5705 | 2010-06-07 17:52:42 -0700 | [diff] [blame] | 4170 | } |
| 4171 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4172 | public void disableKeyguard(IBinder token, String tag) { |
Mike Lockwood | 733fdf3 | 2009-09-28 19:08:53 -0400 | [diff] [blame] | 4173 | if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4174 | != PackageManager.PERMISSION_GRANTED) { |
| 4175 | throw new SecurityException("Requires DISABLE_KEYGUARD permission"); |
| 4176 | } |
Jim Miller | d6b5705 | 2010-06-07 17:52:42 -0700 | [diff] [blame] | 4177 | |
Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 4178 | synchronized (mKeyguardTokenWatcher) { |
| 4179 | mKeyguardTokenWatcher.acquire(token, tag); |
Mike Lockwood | dd88468 | 2009-10-11 16:57:08 -0400 | [diff] [blame] | 4180 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4181 | } |
| 4182 | |
| 4183 | public void reenableKeyguard(IBinder token) { |
Mike Lockwood | 733fdf3 | 2009-09-28 19:08:53 -0400 | [diff] [blame] | 4184 | if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4185 | != PackageManager.PERMISSION_GRANTED) { |
| 4186 | throw new SecurityException("Requires DISABLE_KEYGUARD permission"); |
| 4187 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4188 | |
Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 4189 | synchronized (mKeyguardTokenWatcher) { |
| 4190 | mKeyguardTokenWatcher.release(token); |
Jim Miller | d6b5705 | 2010-06-07 17:52:42 -0700 | [diff] [blame] | 4191 | |
Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 4192 | if (!mKeyguardTokenWatcher.isAcquired()) { |
| 4193 | // If we are the last one to reenable the keyguard wait until |
| 4194 | // we have actually finished reenabling until returning. |
| 4195 | // It is possible that reenableKeyguard() can be called before |
| 4196 | // the previous disableKeyguard() is handled, in which case |
| 4197 | // neither mKeyguardTokenWatcher.acquired() or released() would |
| 4198 | // be called. In that case mKeyguardDisabled will be false here |
| 4199 | // and we have nothing to wait for. |
| 4200 | while (mKeyguardDisabled) { |
| 4201 | try { |
| 4202 | mKeyguardTokenWatcher.wait(); |
| 4203 | } catch (InterruptedException e) { |
| 4204 | Thread.currentThread().interrupt(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4205 | } |
| 4206 | } |
| 4207 | } |
| 4208 | } |
| 4209 | } |
| 4210 | |
| 4211 | /** |
| 4212 | * @see android.app.KeyguardManager#exitKeyguardSecurely |
| 4213 | */ |
| 4214 | public void exitKeyguardSecurely(final IOnKeyguardExitResult callback) { |
Mike Lockwood | 733fdf3 | 2009-09-28 19:08:53 -0400 | [diff] [blame] | 4215 | if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4216 | != PackageManager.PERMISSION_GRANTED) { |
| 4217 | throw new SecurityException("Requires DISABLE_KEYGUARD permission"); |
| 4218 | } |
| 4219 | mPolicy.exitKeyguardSecurely(new WindowManagerPolicy.OnKeyguardExitResult() { |
| 4220 | public void onKeyguardExitResult(boolean success) { |
| 4221 | try { |
| 4222 | callback.onKeyguardExitResult(success); |
| 4223 | } catch (RemoteException e) { |
| 4224 | // Client has died, we don't care. |
| 4225 | } |
| 4226 | } |
| 4227 | }); |
| 4228 | } |
| 4229 | |
| 4230 | public boolean inKeyguardRestrictedInputMode() { |
| 4231 | return mPolicy.inKeyguardRestrictedKeyInputMode(); |
| 4232 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4233 | |
Dianne Hackborn | ffa4248 | 2009-09-23 22:20:11 -0700 | [diff] [blame] | 4234 | public void closeSystemDialogs(String reason) { |
| 4235 | synchronized(mWindowMap) { |
| 4236 | for (int i=mWindows.size()-1; i>=0; i--) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 4237 | WindowState w = mWindows.get(i); |
Dianne Hackborn | ffa4248 | 2009-09-23 22:20:11 -0700 | [diff] [blame] | 4238 | if (w.mSurface != null) { |
| 4239 | try { |
| 4240 | w.mClient.closeSystemDialogs(reason); |
| 4241 | } catch (RemoteException e) { |
| 4242 | } |
| 4243 | } |
| 4244 | } |
| 4245 | } |
| 4246 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 4247 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4248 | static float fixScale(float scale) { |
| 4249 | if (scale < 0) scale = 0; |
| 4250 | else if (scale > 20) scale = 20; |
| 4251 | return Math.abs(scale); |
| 4252 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4253 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4254 | public void setAnimationScale(int which, float scale) { |
| 4255 | if (!checkCallingPermission(android.Manifest.permission.SET_ANIMATION_SCALE, |
| 4256 | "setAnimationScale()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4257 | throw new SecurityException("Requires SET_ANIMATION_SCALE permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4258 | } |
| 4259 | |
| 4260 | if (scale < 0) scale = 0; |
| 4261 | else if (scale > 20) scale = 20; |
| 4262 | scale = Math.abs(scale); |
| 4263 | switch (which) { |
| 4264 | case 0: mWindowAnimationScale = fixScale(scale); break; |
| 4265 | case 1: mTransitionAnimationScale = fixScale(scale); break; |
| 4266 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4267 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4268 | // Persist setting |
| 4269 | mH.obtainMessage(H.PERSIST_ANIMATION_SCALE).sendToTarget(); |
| 4270 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4271 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4272 | public void setAnimationScales(float[] scales) { |
| 4273 | if (!checkCallingPermission(android.Manifest.permission.SET_ANIMATION_SCALE, |
| 4274 | "setAnimationScale()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4275 | throw new SecurityException("Requires SET_ANIMATION_SCALE permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4276 | } |
| 4277 | |
| 4278 | if (scales != null) { |
| 4279 | if (scales.length >= 1) { |
| 4280 | mWindowAnimationScale = fixScale(scales[0]); |
| 4281 | } |
| 4282 | if (scales.length >= 2) { |
| 4283 | mTransitionAnimationScale = fixScale(scales[1]); |
| 4284 | } |
| 4285 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4286 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4287 | // Persist setting |
| 4288 | mH.obtainMessage(H.PERSIST_ANIMATION_SCALE).sendToTarget(); |
| 4289 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4290 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4291 | public float getAnimationScale(int which) { |
| 4292 | switch (which) { |
| 4293 | case 0: return mWindowAnimationScale; |
| 4294 | case 1: return mTransitionAnimationScale; |
| 4295 | } |
| 4296 | return 0; |
| 4297 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4298 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4299 | public float[] getAnimationScales() { |
| 4300 | return new float[] { mWindowAnimationScale, mTransitionAnimationScale }; |
| 4301 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4302 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4303 | public int getSwitchState(int sw) { |
| 4304 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4305 | "getSwitchState()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4306 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4307 | } |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 4308 | return mInputManager.getSwitchState(-1, InputDevice.SOURCE_ANY, sw); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4309 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4310 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4311 | public int getSwitchStateForDevice(int devid, int sw) { |
| 4312 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4313 | "getSwitchStateForDevice()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4314 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4315 | } |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 4316 | return mInputManager.getSwitchState(devid, InputDevice.SOURCE_ANY, sw); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4317 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4318 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4319 | public int getScancodeState(int sw) { |
| 4320 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4321 | "getScancodeState()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4322 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4323 | } |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 4324 | return mInputManager.getScanCodeState(-1, InputDevice.SOURCE_ANY, sw); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4325 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4326 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4327 | public int getScancodeStateForDevice(int devid, int sw) { |
| 4328 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4329 | "getScancodeStateForDevice()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4330 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4331 | } |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 4332 | return mInputManager.getScanCodeState(devid, InputDevice.SOURCE_ANY, sw); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4333 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4334 | |
Dianne Hackborn | 1d62ea9 | 2009-11-17 12:49:50 -0800 | [diff] [blame] | 4335 | public int getTrackballScancodeState(int sw) { |
| 4336 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4337 | "getTrackballScancodeState()")) { |
| 4338 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
| 4339 | } |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 4340 | return mInputManager.getScanCodeState(-1, InputDevice.SOURCE_TRACKBALL, sw); |
Dianne Hackborn | 1d62ea9 | 2009-11-17 12:49:50 -0800 | [diff] [blame] | 4341 | } |
| 4342 | |
| 4343 | public int getDPadScancodeState(int sw) { |
| 4344 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4345 | "getDPadScancodeState()")) { |
| 4346 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
| 4347 | } |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 4348 | return mInputManager.getScanCodeState(-1, InputDevice.SOURCE_DPAD, sw); |
Dianne Hackborn | 1d62ea9 | 2009-11-17 12:49:50 -0800 | [diff] [blame] | 4349 | } |
| 4350 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4351 | public int getKeycodeState(int sw) { |
| 4352 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4353 | "getKeycodeState()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4354 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4355 | } |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 4356 | return mInputManager.getKeyCodeState(-1, InputDevice.SOURCE_ANY, sw); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4357 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4358 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4359 | public int getKeycodeStateForDevice(int devid, int sw) { |
| 4360 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4361 | "getKeycodeStateForDevice()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4362 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4363 | } |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 4364 | return mInputManager.getKeyCodeState(devid, InputDevice.SOURCE_ANY, sw); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4365 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4366 | |
Dianne Hackborn | 1d62ea9 | 2009-11-17 12:49:50 -0800 | [diff] [blame] | 4367 | public int getTrackballKeycodeState(int sw) { |
| 4368 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4369 | "getTrackballKeycodeState()")) { |
| 4370 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
| 4371 | } |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 4372 | return mInputManager.getKeyCodeState(-1, InputDevice.SOURCE_TRACKBALL, sw); |
Dianne Hackborn | 1d62ea9 | 2009-11-17 12:49:50 -0800 | [diff] [blame] | 4373 | } |
| 4374 | |
| 4375 | public int getDPadKeycodeState(int sw) { |
| 4376 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4377 | "getDPadKeycodeState()")) { |
| 4378 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
| 4379 | } |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 4380 | return mInputManager.getKeyCodeState(-1, InputDevice.SOURCE_DPAD, sw); |
Dianne Hackborn | 1d62ea9 | 2009-11-17 12:49:50 -0800 | [diff] [blame] | 4381 | } |
Jeff Brown | a41ca77 | 2010-08-11 14:46:32 -0700 | [diff] [blame] | 4382 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4383 | public boolean hasKeys(int[] keycodes, boolean[] keyExists) { |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 4384 | return mInputManager.hasKeys(-1, InputDevice.SOURCE_ANY, keycodes, keyExists); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4385 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4386 | |
Jeff Brown | a41ca77 | 2010-08-11 14:46:32 -0700 | [diff] [blame] | 4387 | public InputChannel monitorInput(String inputChannelName) { |
| 4388 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4389 | "monitorInput()")) { |
| 4390 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
| 4391 | } |
| 4392 | return mInputManager.monitorInput(inputChannelName); |
| 4393 | } |
| 4394 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4395 | public void enableScreenAfterBoot() { |
| 4396 | synchronized(mWindowMap) { |
| 4397 | if (mSystemBooted) { |
| 4398 | return; |
| 4399 | } |
| 4400 | mSystemBooted = true; |
| 4401 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4402 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4403 | performEnableScreen(); |
| 4404 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4405 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4406 | public void enableScreenIfNeededLocked() { |
| 4407 | if (mDisplayEnabled) { |
| 4408 | return; |
| 4409 | } |
| 4410 | if (!mSystemBooted) { |
| 4411 | return; |
| 4412 | } |
| 4413 | mH.sendMessage(mH.obtainMessage(H.ENABLE_SCREEN)); |
| 4414 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4415 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4416 | public void performEnableScreen() { |
| 4417 | synchronized(mWindowMap) { |
| 4418 | if (mDisplayEnabled) { |
| 4419 | return; |
| 4420 | } |
| 4421 | if (!mSystemBooted) { |
| 4422 | return; |
| 4423 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4424 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4425 | // Don't enable the screen until all existing windows |
| 4426 | // have been drawn. |
| 4427 | final int N = mWindows.size(); |
| 4428 | for (int i=0; i<N; i++) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 4429 | WindowState w = mWindows.get(i); |
Dianne Hackborn | 5943c20 | 2010-04-12 21:36:49 -0700 | [diff] [blame] | 4430 | if (w.isVisibleLw() && !w.mObscured |
| 4431 | && (w.mOrientationChanging || !w.isDrawnLw())) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4432 | return; |
| 4433 | } |
| 4434 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4435 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4436 | mDisplayEnabled = true; |
| 4437 | if (false) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4438 | Slog.i(TAG, "ENABLING SCREEN!"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4439 | StringWriter sw = new StringWriter(); |
| 4440 | PrintWriter pw = new PrintWriter(sw); |
| 4441 | this.dump(null, pw, null); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4442 | Slog.i(TAG, sw.toString()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4443 | } |
| 4444 | try { |
| 4445 | IBinder surfaceFlinger = ServiceManager.getService("SurfaceFlinger"); |
| 4446 | if (surfaceFlinger != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4447 | //Slog.i(TAG, "******* TELLING SURFACE FLINGER WE ARE BOOTED!"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4448 | Parcel data = Parcel.obtain(); |
| 4449 | data.writeInterfaceToken("android.ui.ISurfaceComposer"); |
| 4450 | surfaceFlinger.transact(IBinder.FIRST_CALL_TRANSACTION, |
| 4451 | data, null, 0); |
| 4452 | data.recycle(); |
| 4453 | } |
| 4454 | } catch (RemoteException ex) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4455 | Slog.e(TAG, "Boot completed: SurfaceFlinger is dead!"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4456 | } |
| 4457 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4458 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4459 | mPolicy.enableScreenAfterBoot(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4460 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4461 | // Make sure the last requested orientation has been applied. |
Dianne Hackborn | 321ae68 | 2009-03-27 16:16:03 -0700 | [diff] [blame] | 4462 | setRotationUnchecked(WindowManagerPolicy.USE_LAST_ROTATION, false, |
| 4463 | mLastRotationFlags | Surface.FLAGS_ORIENTATION_ANIMATION_DISABLE); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4464 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4465 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4466 | public void setInTouchMode(boolean mode) { |
| 4467 | synchronized(mWindowMap) { |
| 4468 | mInTouchMode = mode; |
| 4469 | } |
| 4470 | } |
| 4471 | |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4472 | public void setRotation(int rotation, |
Dianne Hackborn | 1e880db | 2009-03-27 16:04:08 -0700 | [diff] [blame] | 4473 | boolean alwaysSendConfiguration, int animFlags) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4474 | if (!checkCallingPermission(android.Manifest.permission.SET_ORIENTATION, |
Dianne Hackborn | 1e880db | 2009-03-27 16:04:08 -0700 | [diff] [blame] | 4475 | "setRotation()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4476 | throw new SecurityException("Requires SET_ORIENTATION permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4477 | } |
| 4478 | |
Dianne Hackborn | 1e880db | 2009-03-27 16:04:08 -0700 | [diff] [blame] | 4479 | setRotationUnchecked(rotation, alwaysSendConfiguration, animFlags); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4480 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4481 | |
Dianne Hackborn | 1e880db | 2009-03-27 16:04:08 -0700 | [diff] [blame] | 4482 | public void setRotationUnchecked(int rotation, |
| 4483 | boolean alwaysSendConfiguration, int animFlags) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4484 | if(DEBUG_ORIENTATION) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4485 | "alwaysSendConfiguration set to "+alwaysSendConfiguration); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4486 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4487 | long origId = Binder.clearCallingIdentity(); |
| 4488 | boolean changed; |
| 4489 | synchronized(mWindowMap) { |
Dianne Hackborn | 1e880db | 2009-03-27 16:04:08 -0700 | [diff] [blame] | 4490 | changed = setRotationUncheckedLocked(rotation, animFlags); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4491 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4492 | |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 4493 | if (changed || alwaysSendConfiguration) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4494 | sendNewConfiguration(); |
| 4495 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4496 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4497 | Binder.restoreCallingIdentity(origId); |
| 4498 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4499 | |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 4500 | /** |
| 4501 | * Apply a new rotation to the screen, respecting the requests of |
| 4502 | * applications. Use WindowManagerPolicy.USE_LAST_ROTATION to simply |
| 4503 | * re-evaluate the desired rotation. |
| 4504 | * |
| 4505 | * Returns null if the rotation has been changed. In this case YOU |
| 4506 | * MUST CALL setNewConfiguration() TO UNFREEZE THE SCREEN. |
| 4507 | */ |
Dianne Hackborn | 1e880db | 2009-03-27 16:04:08 -0700 | [diff] [blame] | 4508 | public boolean setRotationUncheckedLocked(int rotation, int animFlags) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4509 | boolean changed; |
| 4510 | if (rotation == WindowManagerPolicy.USE_LAST_ROTATION) { |
| 4511 | rotation = mRequestedRotation; |
| 4512 | } else { |
| 4513 | mRequestedRotation = rotation; |
Dianne Hackborn | 321ae68 | 2009-03-27 16:16:03 -0700 | [diff] [blame] | 4514 | mLastRotationFlags = animFlags; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4515 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4516 | 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] | 4517 | rotation = mPolicy.rotationForOrientationLw(mForcedAppOrientation, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4518 | mRotation, mDisplayEnabled); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4519 | 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] | 4520 | changed = mDisplayEnabled && mRotation != rotation; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4521 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4522 | if (changed) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4523 | if (DEBUG_ORIENTATION) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4524 | "Rotation changed to " + rotation |
| 4525 | + " from " + mRotation |
| 4526 | + " (forceApp=" + mForcedAppOrientation |
| 4527 | + ", req=" + mRequestedRotation + ")"); |
| 4528 | mRotation = rotation; |
| 4529 | mWindowsFreezingScreen = true; |
| 4530 | mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT); |
| 4531 | mH.sendMessageDelayed(mH.obtainMessage(H.WINDOW_FREEZE_TIMEOUT), |
| 4532 | 2000); |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 4533 | mWaitingForConfig = true; |
| 4534 | mLayoutNeeded = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4535 | startFreezingDisplayLocked(); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4536 | Slog.i(TAG, "Setting rotation to " + rotation + ", animFlags=" + animFlags); |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 4537 | mInputManager.setDisplayOrientation(0, rotation); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4538 | if (mDisplayEnabled) { |
Dianne Hackborn | 321ae68 | 2009-03-27 16:16:03 -0700 | [diff] [blame] | 4539 | Surface.setOrientation(0, rotation, animFlags); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4540 | } |
| 4541 | for (int i=mWindows.size()-1; i>=0; i--) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 4542 | WindowState w = mWindows.get(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4543 | if (w.mSurface != null) { |
| 4544 | w.mOrientationChanging = true; |
| 4545 | } |
| 4546 | } |
| 4547 | for (int i=mRotationWatchers.size()-1; i>=0; i--) { |
| 4548 | try { |
| 4549 | mRotationWatchers.get(i).onRotationChanged(rotation); |
| 4550 | } catch (RemoteException e) { |
| 4551 | } |
| 4552 | } |
| 4553 | } //end if changed |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4554 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4555 | return changed; |
| 4556 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4557 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4558 | public int getRotation() { |
| 4559 | return mRotation; |
| 4560 | } |
| 4561 | |
| 4562 | public int watchRotation(IRotationWatcher watcher) { |
| 4563 | final IBinder watcherBinder = watcher.asBinder(); |
| 4564 | IBinder.DeathRecipient dr = new IBinder.DeathRecipient() { |
| 4565 | public void binderDied() { |
| 4566 | synchronized (mWindowMap) { |
| 4567 | for (int i=0; i<mRotationWatchers.size(); i++) { |
| 4568 | if (watcherBinder == mRotationWatchers.get(i).asBinder()) { |
Suchi Amalapurapu | fff2fda | 2009-06-30 21:36:16 -0700 | [diff] [blame] | 4569 | IRotationWatcher removed = mRotationWatchers.remove(i); |
| 4570 | if (removed != null) { |
| 4571 | removed.asBinder().unlinkToDeath(this, 0); |
| 4572 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4573 | i--; |
| 4574 | } |
| 4575 | } |
| 4576 | } |
| 4577 | } |
| 4578 | }; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4579 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4580 | synchronized (mWindowMap) { |
| 4581 | try { |
| 4582 | watcher.asBinder().linkToDeath(dr, 0); |
| 4583 | mRotationWatchers.add(watcher); |
| 4584 | } catch (RemoteException e) { |
| 4585 | // Client died, no cleanup needed. |
| 4586 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4587 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4588 | return mRotation; |
| 4589 | } |
| 4590 | } |
| 4591 | |
| 4592 | /** |
| 4593 | * Starts the view server on the specified port. |
| 4594 | * |
| 4595 | * @param port The port to listener to. |
| 4596 | * |
| 4597 | * @return True if the server was successfully started, false otherwise. |
| 4598 | * |
| 4599 | * @see com.android.server.ViewServer |
| 4600 | * @see com.android.server.ViewServer#VIEW_SERVER_DEFAULT_PORT |
| 4601 | */ |
| 4602 | public boolean startViewServer(int port) { |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4603 | if (isSystemSecure()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4604 | return false; |
| 4605 | } |
| 4606 | |
| 4607 | if (!checkCallingPermission(Manifest.permission.DUMP, "startViewServer")) { |
| 4608 | return false; |
| 4609 | } |
| 4610 | |
| 4611 | if (port < 1024) { |
| 4612 | return false; |
| 4613 | } |
| 4614 | |
| 4615 | if (mViewServer != null) { |
| 4616 | if (!mViewServer.isRunning()) { |
| 4617 | try { |
| 4618 | return mViewServer.start(); |
| 4619 | } catch (IOException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4620 | Slog.w(TAG, "View server did not start"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4621 | } |
| 4622 | } |
| 4623 | return false; |
| 4624 | } |
| 4625 | |
| 4626 | try { |
| 4627 | mViewServer = new ViewServer(this, port); |
| 4628 | return mViewServer.start(); |
| 4629 | } catch (IOException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4630 | Slog.w(TAG, "View server did not start"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4631 | } |
| 4632 | return false; |
| 4633 | } |
| 4634 | |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4635 | private boolean isSystemSecure() { |
| 4636 | return "1".equals(SystemProperties.get(SYSTEM_SECURE, "1")) && |
| 4637 | "0".equals(SystemProperties.get(SYSTEM_DEBUGGABLE, "0")); |
| 4638 | } |
| 4639 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4640 | /** |
| 4641 | * Stops the view server if it exists. |
| 4642 | * |
| 4643 | * @return True if the server stopped, false if it wasn't started or |
| 4644 | * couldn't be stopped. |
| 4645 | * |
| 4646 | * @see com.android.server.ViewServer |
| 4647 | */ |
| 4648 | public boolean stopViewServer() { |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4649 | if (isSystemSecure()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4650 | return false; |
| 4651 | } |
| 4652 | |
| 4653 | if (!checkCallingPermission(Manifest.permission.DUMP, "stopViewServer")) { |
| 4654 | return false; |
| 4655 | } |
| 4656 | |
| 4657 | if (mViewServer != null) { |
| 4658 | return mViewServer.stop(); |
| 4659 | } |
| 4660 | return false; |
| 4661 | } |
| 4662 | |
| 4663 | /** |
| 4664 | * Indicates whether the view server is running. |
| 4665 | * |
| 4666 | * @return True if the server is running, false otherwise. |
| 4667 | * |
| 4668 | * @see com.android.server.ViewServer |
| 4669 | */ |
| 4670 | public boolean isViewServerRunning() { |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4671 | if (isSystemSecure()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4672 | return false; |
| 4673 | } |
| 4674 | |
| 4675 | if (!checkCallingPermission(Manifest.permission.DUMP, "isViewServerRunning")) { |
| 4676 | return false; |
| 4677 | } |
| 4678 | |
| 4679 | return mViewServer != null && mViewServer.isRunning(); |
| 4680 | } |
| 4681 | |
| 4682 | /** |
| 4683 | * Lists all availble windows in the system. The listing is written in the |
| 4684 | * specified Socket's output stream with the following syntax: |
| 4685 | * windowHashCodeInHexadecimal windowName |
| 4686 | * Each line of the ouput represents a different window. |
| 4687 | * |
| 4688 | * @param client The remote client to send the listing to. |
| 4689 | * @return False if an error occured, true otherwise. |
| 4690 | */ |
| 4691 | boolean viewServerListWindows(Socket client) { |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4692 | if (isSystemSecure()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4693 | return false; |
| 4694 | } |
| 4695 | |
| 4696 | boolean result = true; |
| 4697 | |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 4698 | WindowState[] windows; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4699 | synchronized (mWindowMap) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4700 | //noinspection unchecked |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 4701 | windows = mWindows.toArray(new WindowState[mWindows.size()]); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4702 | } |
| 4703 | |
| 4704 | BufferedWriter out = null; |
| 4705 | |
| 4706 | // Any uncaught exception will crash the system process |
| 4707 | try { |
| 4708 | OutputStream clientStream = client.getOutputStream(); |
| 4709 | out = new BufferedWriter(new OutputStreamWriter(clientStream), 8 * 1024); |
| 4710 | |
| 4711 | final int count = windows.length; |
| 4712 | for (int i = 0; i < count; i++) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 4713 | final WindowState w = windows[i]; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4714 | out.write(Integer.toHexString(System.identityHashCode(w))); |
| 4715 | out.write(' '); |
| 4716 | out.append(w.mAttrs.getTitle()); |
| 4717 | out.write('\n'); |
| 4718 | } |
| 4719 | |
| 4720 | out.write("DONE.\n"); |
| 4721 | out.flush(); |
| 4722 | } catch (Exception e) { |
| 4723 | result = false; |
| 4724 | } finally { |
| 4725 | if (out != null) { |
| 4726 | try { |
| 4727 | out.close(); |
| 4728 | } catch (IOException e) { |
| 4729 | result = false; |
| 4730 | } |
| 4731 | } |
| 4732 | } |
| 4733 | |
| 4734 | return result; |
| 4735 | } |
| 4736 | |
| 4737 | /** |
Konstantin Lopyrev | f962476 | 2010-07-14 17:02:37 -0700 | [diff] [blame] | 4738 | * Returns the focused window in the following format: |
| 4739 | * windowHashCodeInHexadecimal windowName |
| 4740 | * |
| 4741 | * @param client The remote client to send the listing to. |
| 4742 | * @return False if an error occurred, true otherwise. |
| 4743 | */ |
| 4744 | boolean viewServerGetFocusedWindow(Socket client) { |
| 4745 | if (isSystemSecure()) { |
| 4746 | return false; |
| 4747 | } |
| 4748 | |
| 4749 | boolean result = true; |
| 4750 | |
| 4751 | WindowState focusedWindow = getFocusedWindow(); |
| 4752 | |
| 4753 | BufferedWriter out = null; |
| 4754 | |
| 4755 | // Any uncaught exception will crash the system process |
| 4756 | try { |
| 4757 | OutputStream clientStream = client.getOutputStream(); |
| 4758 | out = new BufferedWriter(new OutputStreamWriter(clientStream), 8 * 1024); |
| 4759 | |
| 4760 | if(focusedWindow != null) { |
| 4761 | out.write(Integer.toHexString(System.identityHashCode(focusedWindow))); |
| 4762 | out.write(' '); |
| 4763 | out.append(focusedWindow.mAttrs.getTitle()); |
| 4764 | } |
| 4765 | out.write('\n'); |
| 4766 | out.flush(); |
| 4767 | } catch (Exception e) { |
| 4768 | result = false; |
| 4769 | } finally { |
| 4770 | if (out != null) { |
| 4771 | try { |
| 4772 | out.close(); |
| 4773 | } catch (IOException e) { |
| 4774 | result = false; |
| 4775 | } |
| 4776 | } |
| 4777 | } |
| 4778 | |
| 4779 | return result; |
| 4780 | } |
| 4781 | |
| 4782 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4783 | * Sends a command to a target window. The result of the command, if any, will be |
| 4784 | * written in the output stream of the specified socket. |
| 4785 | * |
| 4786 | * The parameters must follow this syntax: |
| 4787 | * windowHashcode extra |
| 4788 | * |
| 4789 | * Where XX is the length in characeters of the windowTitle. |
| 4790 | * |
| 4791 | * The first parameter is the target window. The window with the specified hashcode |
| 4792 | * will be the target. If no target can be found, nothing happens. The extra parameters |
| 4793 | * will be delivered to the target window and as parameters to the command itself. |
| 4794 | * |
| 4795 | * @param client The remote client to sent the result, if any, to. |
| 4796 | * @param command The command to execute. |
| 4797 | * @param parameters The command parameters. |
| 4798 | * |
| 4799 | * @return True if the command was successfully delivered, false otherwise. This does |
| 4800 | * not indicate whether the command itself was successful. |
| 4801 | */ |
| 4802 | boolean viewServerWindowCommand(Socket client, String command, String parameters) { |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4803 | if (isSystemSecure()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4804 | return false; |
| 4805 | } |
| 4806 | |
| 4807 | boolean success = true; |
| 4808 | Parcel data = null; |
| 4809 | Parcel reply = null; |
| 4810 | |
| 4811 | // Any uncaught exception will crash the system process |
| 4812 | try { |
| 4813 | // Find the hashcode of the window |
| 4814 | int index = parameters.indexOf(' '); |
| 4815 | if (index == -1) { |
| 4816 | index = parameters.length(); |
| 4817 | } |
| 4818 | final String code = parameters.substring(0, index); |
Romain Guy | 236092a | 2009-12-14 15:31:48 -0800 | [diff] [blame] | 4819 | int hashCode = (int) Long.parseLong(code, 16); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4820 | |
| 4821 | // Extract the command's parameter after the window description |
| 4822 | if (index < parameters.length()) { |
| 4823 | parameters = parameters.substring(index + 1); |
| 4824 | } else { |
| 4825 | parameters = ""; |
| 4826 | } |
| 4827 | |
| 4828 | final WindowManagerService.WindowState window = findWindow(hashCode); |
| 4829 | if (window == null) { |
| 4830 | return false; |
| 4831 | } |
| 4832 | |
| 4833 | data = Parcel.obtain(); |
| 4834 | data.writeInterfaceToken("android.view.IWindow"); |
| 4835 | data.writeString(command); |
| 4836 | data.writeString(parameters); |
| 4837 | data.writeInt(1); |
| 4838 | ParcelFileDescriptor.fromSocket(client).writeToParcel(data, 0); |
| 4839 | |
| 4840 | reply = Parcel.obtain(); |
| 4841 | |
| 4842 | final IBinder binder = window.mClient.asBinder(); |
| 4843 | // TODO: GET THE TRANSACTION CODE IN A SAFER MANNER |
| 4844 | binder.transact(IBinder.FIRST_CALL_TRANSACTION, data, reply, 0); |
| 4845 | |
| 4846 | reply.readException(); |
| 4847 | |
| 4848 | } catch (Exception e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4849 | 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] | 4850 | success = false; |
| 4851 | } finally { |
| 4852 | if (data != null) { |
| 4853 | data.recycle(); |
| 4854 | } |
| 4855 | if (reply != null) { |
| 4856 | reply.recycle(); |
| 4857 | } |
| 4858 | } |
| 4859 | |
| 4860 | return success; |
| 4861 | } |
| 4862 | |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 4863 | public void addWindowChangeListener(WindowChangeListener listener) { |
| 4864 | synchronized(mWindowMap) { |
| 4865 | mWindowChangeListeners.add(listener); |
| 4866 | } |
| 4867 | } |
| 4868 | |
| 4869 | public void removeWindowChangeListener(WindowChangeListener listener) { |
| 4870 | synchronized(mWindowMap) { |
| 4871 | mWindowChangeListeners.remove(listener); |
| 4872 | } |
| 4873 | } |
| 4874 | |
| 4875 | private void notifyWindowsChanged() { |
| 4876 | WindowChangeListener[] windowChangeListeners; |
| 4877 | synchronized(mWindowMap) { |
| 4878 | if(mWindowChangeListeners.isEmpty()) { |
| 4879 | return; |
| 4880 | } |
| 4881 | windowChangeListeners = new WindowChangeListener[mWindowChangeListeners.size()]; |
| 4882 | windowChangeListeners = mWindowChangeListeners.toArray(windowChangeListeners); |
| 4883 | } |
| 4884 | int N = windowChangeListeners.length; |
| 4885 | for(int i = 0; i < N; i++) { |
| 4886 | windowChangeListeners[i].windowsChanged(); |
| 4887 | } |
| 4888 | } |
| 4889 | |
Konstantin Lopyrev | 6e0f65f | 2010-07-14 14:55:33 -0700 | [diff] [blame] | 4890 | private void notifyFocusChanged() { |
| 4891 | WindowChangeListener[] windowChangeListeners; |
| 4892 | synchronized(mWindowMap) { |
| 4893 | if(mWindowChangeListeners.isEmpty()) { |
| 4894 | return; |
| 4895 | } |
| 4896 | windowChangeListeners = new WindowChangeListener[mWindowChangeListeners.size()]; |
| 4897 | windowChangeListeners = mWindowChangeListeners.toArray(windowChangeListeners); |
| 4898 | } |
| 4899 | int N = windowChangeListeners.length; |
| 4900 | for(int i = 0; i < N; i++) { |
| 4901 | windowChangeListeners[i].focusChanged(); |
| 4902 | } |
| 4903 | } |
| 4904 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4905 | private WindowState findWindow(int hashCode) { |
| 4906 | if (hashCode == -1) { |
| 4907 | return getFocusedWindow(); |
| 4908 | } |
| 4909 | |
| 4910 | synchronized (mWindowMap) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 4911 | final ArrayList<WindowState> windows = mWindows; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4912 | final int count = windows.size(); |
| 4913 | |
| 4914 | for (int i = 0; i < count; i++) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 4915 | WindowState w = windows.get(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4916 | if (System.identityHashCode(w) == hashCode) { |
| 4917 | return w; |
| 4918 | } |
| 4919 | } |
| 4920 | } |
| 4921 | |
| 4922 | return null; |
| 4923 | } |
| 4924 | |
| 4925 | /* |
| 4926 | * Instruct the Activity Manager to fetch the current configuration and broadcast |
| 4927 | * that to config-changed listeners if appropriate. |
| 4928 | */ |
| 4929 | void sendNewConfiguration() { |
| 4930 | try { |
| 4931 | mActivityManager.updateConfiguration(null); |
| 4932 | } catch (RemoteException e) { |
| 4933 | } |
| 4934 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4935 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4936 | public Configuration computeNewConfiguration() { |
| 4937 | synchronized (mWindowMap) { |
Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 4938 | return computeNewConfigurationLocked(); |
| 4939 | } |
| 4940 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4941 | |
Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 4942 | Configuration computeNewConfigurationLocked() { |
| 4943 | Configuration config = new Configuration(); |
| 4944 | if (!computeNewConfigurationLocked(config)) { |
| 4945 | return null; |
| 4946 | } |
Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 4947 | return config; |
| 4948 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4949 | |
Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 4950 | boolean computeNewConfigurationLocked(Configuration config) { |
| 4951 | if (mDisplay == null) { |
| 4952 | return false; |
| 4953 | } |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 4954 | |
| 4955 | mInputManager.getInputConfiguration(config); |
Christopher Tate | b696aee | 2010-04-02 19:08:30 -0700 | [diff] [blame] | 4956 | |
| 4957 | // Use the effective "visual" dimensions based on current rotation |
| 4958 | final boolean rotated = (mRotation == Surface.ROTATION_90 |
| 4959 | || mRotation == Surface.ROTATION_270); |
| 4960 | final int dw = rotated ? mInitialDisplayHeight : mInitialDisplayWidth; |
| 4961 | final int dh = rotated ? mInitialDisplayWidth : mInitialDisplayHeight; |
| 4962 | |
Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 4963 | int orientation = Configuration.ORIENTATION_SQUARE; |
| 4964 | if (dw < dh) { |
| 4965 | orientation = Configuration.ORIENTATION_PORTRAIT; |
| 4966 | } else if (dw > dh) { |
| 4967 | orientation = Configuration.ORIENTATION_LANDSCAPE; |
| 4968 | } |
| 4969 | config.orientation = orientation; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 4970 | |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 4971 | DisplayMetrics dm = new DisplayMetrics(); |
| 4972 | mDisplay.getMetrics(dm); |
| 4973 | CompatibilityInfo.updateCompatibleScreenFrame(dm, orientation, mCompatibleScreenFrame); |
| 4974 | |
Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 4975 | if (mScreenLayout == Configuration.SCREENLAYOUT_SIZE_UNDEFINED) { |
Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 4976 | // Note we only do this once because at this point we don't |
| 4977 | // expect the screen to change in this way at runtime, and want |
| 4978 | // to avoid all of this computation for every config change. |
Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 4979 | int longSize = dw; |
| 4980 | int shortSize = dh; |
| 4981 | if (longSize < shortSize) { |
| 4982 | int tmp = longSize; |
| 4983 | longSize = shortSize; |
| 4984 | shortSize = tmp; |
| 4985 | } |
| 4986 | longSize = (int)(longSize/dm.density); |
| 4987 | shortSize = (int)(shortSize/dm.density); |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 4988 | |
Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 4989 | // These semi-magic numbers define our compatibility modes for |
| 4990 | // applications with different screens. Don't change unless you |
| 4991 | // make sure to test lots and lots of apps! |
| 4992 | if (longSize < 470) { |
| 4993 | // This is shorter than an HVGA normal density screen (which |
| 4994 | // is 480 pixels on its long side). |
Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 4995 | mScreenLayout = Configuration.SCREENLAYOUT_SIZE_SMALL |
| 4996 | | Configuration.SCREENLAYOUT_LONG_NO; |
Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 4997 | } else { |
Dianne Hackborn | 14cee9f | 2010-04-23 17:51:26 -0700 | [diff] [blame] | 4998 | // What size is this screen screen? |
| 4999 | if (longSize >= 800 && shortSize >= 600) { |
| 5000 | // SVGA or larger screens at medium density are the point |
| 5001 | // at which we consider it to be an extra large screen. |
| 5002 | mScreenLayout = Configuration.SCREENLAYOUT_SIZE_XLARGE; |
| 5003 | } else if (longSize >= 640 && shortSize >= 480) { |
Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 5004 | // VGA or larger screens at medium density are the point |
| 5005 | // at which we consider it to be a large screen. |
| 5006 | mScreenLayout = Configuration.SCREENLAYOUT_SIZE_LARGE; |
| 5007 | } else { |
| 5008 | mScreenLayout = Configuration.SCREENLAYOUT_SIZE_NORMAL; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 5009 | |
Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 5010 | // If this screen is wider than normal HVGA, or taller |
| 5011 | // than FWVGA, then for old apps we want to run in size |
| 5012 | // compatibility mode. |
| 5013 | if (shortSize > 321 || longSize > 570) { |
| 5014 | mScreenLayout |= Configuration.SCREENLAYOUT_COMPAT_NEEDED; |
| 5015 | } |
| 5016 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 5017 | |
Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 5018 | // Is this a long screen? |
| 5019 | if (((longSize*3)/5) >= (shortSize-1)) { |
| 5020 | // Anything wider than WVGA (5:3) is considering to be long. |
| 5021 | mScreenLayout |= Configuration.SCREENLAYOUT_LONG_YES; |
| 5022 | } else { |
| 5023 | mScreenLayout |= Configuration.SCREENLAYOUT_LONG_NO; |
| 5024 | } |
Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 5025 | } |
| 5026 | } |
Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 5027 | config.screenLayout = mScreenLayout; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 5028 | |
Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 5029 | config.keyboardHidden = Configuration.KEYBOARDHIDDEN_NO; |
| 5030 | config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_NO; |
| 5031 | mPolicy.adjustConfigurationLw(config); |
| 5032 | return true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5033 | } |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 5034 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5035 | // ------------------------------------------------------------- |
| 5036 | // Input Events and Focus Management |
| 5037 | // ------------------------------------------------------------- |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5038 | |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5039 | InputMonitor mInputMonitor = new InputMonitor(); |
| 5040 | |
| 5041 | /* Tracks the progress of input dispatch and ensures that input dispatch state |
| 5042 | * is kept in sync with changes in window focus, visibility, registration, and |
| 5043 | * other relevant Window Manager state transitions. */ |
| 5044 | final class InputMonitor { |
| 5045 | // Current window with input focus for keys and other non-touch events. May be null. |
| 5046 | private WindowState mInputFocus; |
| 5047 | |
| 5048 | // When true, prevents input dispatch from proceeding until set to false again. |
| 5049 | private boolean mInputDispatchFrozen; |
| 5050 | |
| 5051 | // When true, input dispatch proceeds normally. Otherwise all events are dropped. |
| 5052 | private boolean mInputDispatchEnabled = true; |
| 5053 | |
| 5054 | // Temporary list of windows information to provide to the input dispatcher. |
| 5055 | private InputWindowList mTempInputWindows = new InputWindowList(); |
| 5056 | |
| 5057 | // Temporary input application object to provide to the input dispatcher. |
| 5058 | private InputApplication mTempInputApplication = new InputApplication(); |
| 5059 | |
| 5060 | /* Notifies the window manager about a broken input channel. |
| 5061 | * |
| 5062 | * Called by the InputManager. |
| 5063 | */ |
| 5064 | public void notifyInputChannelBroken(InputChannel inputChannel) { |
| 5065 | synchronized (mWindowMap) { |
| 5066 | WindowState windowState = getWindowStateForInputChannelLocked(inputChannel); |
| 5067 | if (windowState == null) { |
| 5068 | return; // irrelevant |
| 5069 | } |
| 5070 | |
| 5071 | Slog.i(TAG, "WINDOW DIED " + windowState); |
| 5072 | removeWindowLocked(windowState.mSession, windowState); |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 5073 | } |
| 5074 | } |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5075 | |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5076 | /* Notifies the window manager about an input channel that is not responding. |
| 5077 | * The method can either cause dispatching to be aborted by returning -2 or |
| 5078 | * return a new timeout in nanoseconds. |
| 5079 | * |
| 5080 | * Called by the InputManager. |
| 5081 | */ |
| 5082 | public long notifyInputChannelANR(InputChannel inputChannel) { |
| 5083 | AppWindowToken token; |
| 5084 | synchronized (mWindowMap) { |
| 5085 | WindowState windowState = getWindowStateForInputChannelLocked(inputChannel); |
| 5086 | if (windowState == null) { |
| 5087 | return -2; // irrelevant, abort dispatching (-2) |
| 5088 | } |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 5089 | |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5090 | Slog.i(TAG, "Input event dispatching timed out sending to " |
| 5091 | + windowState.mAttrs.getTitle()); |
| 5092 | token = windowState.mAppToken; |
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 | return notifyANRInternal(token); |
| 5096 | } |
| 5097 | |
| 5098 | /* Notifies the window manager about an input channel spontaneously recovering from ANR |
| 5099 | * by successfully delivering the event that originally timed out. |
| 5100 | * |
| 5101 | * Called by the InputManager. |
| 5102 | */ |
| 5103 | public void notifyInputChannelRecoveredFromANR(InputChannel inputChannel) { |
| 5104 | // Nothing to do just now. |
| 5105 | // Just wait for the user to dismiss the ANR dialog. |
| 5106 | } |
| 5107 | |
| 5108 | /* Notifies the window manager about an application that is not responding |
| 5109 | * in general rather than with respect to a particular input channel. |
| 5110 | * The method can either cause dispatching to be aborted by returning -2 or |
| 5111 | * return a new timeout in nanoseconds. |
| 5112 | * |
| 5113 | * Called by the InputManager. |
| 5114 | */ |
| 5115 | public long notifyANR(Object token) { |
| 5116 | AppWindowToken appWindowToken = (AppWindowToken) token; |
| 5117 | |
| 5118 | Slog.i(TAG, "Input event dispatching timed out sending to application " |
| 5119 | + appWindowToken.stringName); |
| 5120 | return notifyANRInternal(appWindowToken); |
| 5121 | } |
| 5122 | |
| 5123 | private long notifyANRInternal(AppWindowToken token) { |
| 5124 | if (token != null && token.appToken != null) { |
| 5125 | try { |
| 5126 | // Notify the activity manager about the timeout and let it decide whether |
| 5127 | // to abort dispatching or keep waiting. |
| 5128 | boolean abort = token.appToken.keyDispatchingTimedOut(); |
| 5129 | if (! abort) { |
| 5130 | // The activity manager declined to abort dispatching. |
| 5131 | // Wait a bit longer and timeout again later. |
| 5132 | return token.inputDispatchingTimeoutNanos; |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 5133 | } |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5134 | } catch (RemoteException ex) { |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 5135 | } |
| 5136 | } |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5137 | return -2; // abort dispatching |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 5138 | } |
| 5139 | |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5140 | private WindowState getWindowStateForInputChannel(InputChannel inputChannel) { |
| 5141 | synchronized (mWindowMap) { |
| 5142 | return getWindowStateForInputChannelLocked(inputChannel); |
| 5143 | } |
| 5144 | } |
| 5145 | |
| 5146 | private WindowState getWindowStateForInputChannelLocked(InputChannel inputChannel) { |
| 5147 | int windowCount = mWindows.size(); |
| 5148 | for (int i = 0; i < windowCount; i++) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 5149 | WindowState windowState = mWindows.get(i); |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5150 | if (windowState.mInputChannel == inputChannel) { |
| 5151 | return windowState; |
| 5152 | } |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 5153 | } |
| 5154 | |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5155 | return null; |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 5156 | } |
| 5157 | |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5158 | /* Updates the cached window information provided to the input dispatcher. */ |
| 5159 | public void updateInputWindowsLw() { |
| 5160 | // Populate the input window list with information about all of the windows that |
| 5161 | // could potentially receive input. |
| 5162 | // As an optimization, we could try to prune the list of windows but this turns |
| 5163 | // out to be difficult because only the native code knows for sure which window |
| 5164 | // currently has touch focus. |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 5165 | final ArrayList<WindowState> windows = mWindows; |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 5166 | final int N = windows.size(); |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5167 | for (int i = N - 1; i >= 0; i--) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 5168 | final WindowState child = windows.get(i); |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 5169 | if (child.mInputChannel == null || child.mRemoved) { |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5170 | // Skip this window because it cannot possibly receive input. |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 5171 | continue; |
| 5172 | } |
| 5173 | |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5174 | final int flags = child.mAttrs.flags; |
| 5175 | final int type = child.mAttrs.type; |
| 5176 | |
| 5177 | final boolean hasFocus = (child == mInputFocus); |
| 5178 | final boolean isVisible = child.isVisibleLw(); |
| 5179 | final boolean hasWallpaper = (child == mWallpaperTarget) |
| 5180 | && (type != WindowManager.LayoutParams.TYPE_KEYGUARD); |
| 5181 | |
| 5182 | // Add a window to our list of input windows. |
| 5183 | final InputWindow inputWindow = mTempInputWindows.add(); |
| 5184 | inputWindow.inputChannel = child.mInputChannel; |
| 5185 | inputWindow.layoutParamsFlags = flags; |
| 5186 | inputWindow.layoutParamsType = type; |
| 5187 | inputWindow.dispatchingTimeoutNanos = child.getInputDispatchingTimeoutNanos(); |
| 5188 | inputWindow.visible = isVisible; |
| 5189 | inputWindow.hasFocus = hasFocus; |
| 5190 | inputWindow.hasWallpaper = hasWallpaper; |
| 5191 | inputWindow.paused = child.mAppToken != null ? child.mAppToken.paused : false; |
| 5192 | inputWindow.ownerPid = child.mSession.mPid; |
| 5193 | inputWindow.ownerUid = child.mSession.mUid; |
| 5194 | |
| 5195 | final Rect frame = child.mFrame; |
| 5196 | inputWindow.frameLeft = frame.left; |
| 5197 | inputWindow.frameTop = frame.top; |
| 5198 | |
| 5199 | switch (child.mTouchableInsets) { |
| 5200 | default: |
| 5201 | case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME: |
| 5202 | inputWindow.touchableAreaLeft = frame.left; |
| 5203 | inputWindow.touchableAreaTop = frame.top; |
| 5204 | inputWindow.touchableAreaRight = frame.right; |
| 5205 | inputWindow.touchableAreaBottom = frame.bottom; |
| 5206 | break; |
| 5207 | |
| 5208 | case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_CONTENT: { |
| 5209 | Rect inset = child.mGivenContentInsets; |
| 5210 | inputWindow.touchableAreaLeft = frame.left + inset.left; |
| 5211 | inputWindow.touchableAreaTop = frame.top + inset.top; |
| 5212 | inputWindow.touchableAreaRight = frame.right - inset.right; |
| 5213 | inputWindow.touchableAreaBottom = frame.bottom - inset.bottom; |
| 5214 | break; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5215 | } |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5216 | |
| 5217 | case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_VISIBLE: { |
| 5218 | Rect inset = child.mGivenVisibleInsets; |
| 5219 | inputWindow.touchableAreaLeft = frame.left + inset.left; |
| 5220 | inputWindow.touchableAreaTop = frame.top + inset.top; |
| 5221 | inputWindow.touchableAreaRight = frame.right - inset.right; |
| 5222 | inputWindow.touchableAreaBottom = frame.bottom - inset.bottom; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5223 | break; |
| 5224 | } |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5225 | } |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5226 | } |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 5227 | |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5228 | // Send windows to native code. |
| 5229 | mInputManager.setInputWindows(mTempInputWindows.toNullTerminatedArray()); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5230 | |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5231 | // Clear the list in preparation for the next round. |
| 5232 | // Also avoids keeping InputChannel objects referenced unnecessarily. |
| 5233 | mTempInputWindows.clear(); |
| 5234 | } |
| 5235 | |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 5236 | /* Provides feedback for a virtual key down. */ |
| 5237 | public void virtualKeyDownFeedback() { |
| 5238 | synchronized (mWindowMap) { |
| 5239 | mPolicy.performHapticFeedbackLw(null, HapticFeedbackConstants.VIRTUAL_KEY, false); |
| 5240 | } |
| 5241 | } |
| 5242 | |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5243 | /* Notifies that an app switch key (BACK / HOME) has just been pressed. |
| 5244 | * This essentially starts a .5 second timeout for the application to process |
| 5245 | * subsequent input events while waiting for the app switch to occur. If it takes longer |
| 5246 | * than this, the pending events will be dropped. |
| 5247 | */ |
| 5248 | public void notifyAppSwitchComing() { |
| 5249 | // TODO Not implemented yet. Should go in the native side. |
| 5250 | } |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 5251 | |
| 5252 | /* Notifies that the lid switch changed state. */ |
| 5253 | public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen) { |
| 5254 | mPolicy.notifyLidSwitchChanged(whenNanos, lidOpen); |
| 5255 | } |
| 5256 | |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5257 | /* Provides an opportunity for the window manager policy to intercept early key |
| 5258 | * processing as soon as the key has been read from the device. */ |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 5259 | public int interceptKeyBeforeQueueing(long whenNanos, int keyCode, boolean down, |
| 5260 | int policyFlags, boolean isScreenOn) { |
| 5261 | return mPolicy.interceptKeyBeforeQueueing(whenNanos, |
| 5262 | keyCode, down, policyFlags, isScreenOn); |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5263 | } |
| 5264 | |
| 5265 | /* Provides an opportunity for the window manager policy to process a key before |
| 5266 | * ordinary dispatch. */ |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 5267 | public boolean interceptKeyBeforeDispatching(InputChannel focus, |
| 5268 | int action, int flags, int keyCode, int metaState, int repeatCount, |
| 5269 | int policyFlags) { |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5270 | WindowState windowState = getWindowStateForInputChannel(focus); |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 5271 | return mPolicy.interceptKeyBeforeDispatching(windowState, action, flags, |
| 5272 | keyCode, metaState, repeatCount, policyFlags); |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5273 | } |
| 5274 | |
| 5275 | /* Called when the current input focus changes. |
| 5276 | * Layer assignment is assumed to be complete by the time this is called. |
| 5277 | */ |
| 5278 | public void setInputFocusLw(WindowState newWindow) { |
| 5279 | if (DEBUG_INPUT) { |
| 5280 | Slog.d(TAG, "Input focus has changed to " + newWindow); |
| 5281 | } |
| 5282 | |
| 5283 | if (newWindow != mInputFocus) { |
| 5284 | if (newWindow != null && newWindow.canReceiveKeys()) { |
| 5285 | // If the new input focus is an error window or appears above the current |
| 5286 | // input focus, preempt any pending synchronous dispatch so that we can |
| 5287 | // start delivering events to the new input focus as soon as possible. |
| 5288 | if ((newWindow.mAttrs.flags & FLAG_SYSTEM_ERROR) != 0) { |
| 5289 | if (DEBUG_INPUT) { |
| 5290 | Slog.v(TAG, "New SYSTEM_ERROR window; resetting state"); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5291 | } |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5292 | preemptInputDispatchLw(); |
| 5293 | } else if (mInputFocus != null && newWindow.mLayer > mInputFocus.mLayer) { |
| 5294 | if (DEBUG_INPUT) { |
| 5295 | Slog.v(TAG, "Transferring focus to new window at higher layer: " |
| 5296 | + "old win layer=" + mInputFocus.mLayer |
| 5297 | + ", new win layer=" + newWindow.mLayer); |
| 5298 | } |
| 5299 | preemptInputDispatchLw(); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5300 | } |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5301 | |
| 5302 | // Displaying a window implicitly causes dispatching to be unpaused. |
| 5303 | // This is to protect against bugs if someone pauses dispatching but |
| 5304 | // forgets to resume. |
| 5305 | newWindow.mToken.paused = false; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5306 | } |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5307 | |
| 5308 | mInputFocus = newWindow; |
| 5309 | updateInputWindowsLw(); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5310 | } |
| 5311 | } |
| 5312 | |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5313 | /* Tells the dispatcher to stop waiting for its current synchronous event targets. |
| 5314 | * Essentially, just makes those dispatches asynchronous so a new dispatch cycle |
| 5315 | * can begin. |
| 5316 | */ |
| 5317 | private void preemptInputDispatchLw() { |
| 5318 | mInputManager.preemptInputDispatch(); |
| 5319 | } |
| 5320 | |
| 5321 | public void setFocusedAppLw(AppWindowToken newApp) { |
| 5322 | // Focused app has changed. |
| 5323 | if (newApp == null) { |
| 5324 | mInputManager.setFocusedApplication(null); |
| 5325 | } else { |
| 5326 | mTempInputApplication.name = newApp.toString(); |
| 5327 | mTempInputApplication.dispatchingTimeoutNanos = |
| 5328 | newApp.inputDispatchingTimeoutNanos; |
| 5329 | mTempInputApplication.token = newApp; |
| 5330 | |
| 5331 | mInputManager.setFocusedApplication(mTempInputApplication); |
| 5332 | } |
| 5333 | } |
| 5334 | |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5335 | public void pauseDispatchingLw(WindowToken window) { |
| 5336 | if (! window.paused) { |
| 5337 | if (DEBUG_INPUT) { |
| 5338 | Slog.v(TAG, "Pausing WindowToken " + window); |
| 5339 | } |
| 5340 | |
| 5341 | window.paused = true; |
| 5342 | updateInputWindowsLw(); |
| 5343 | } |
| 5344 | } |
| 5345 | |
| 5346 | public void resumeDispatchingLw(WindowToken window) { |
| 5347 | if (window.paused) { |
| 5348 | if (DEBUG_INPUT) { |
| 5349 | Slog.v(TAG, "Resuming WindowToken " + window); |
| 5350 | } |
| 5351 | |
| 5352 | window.paused = false; |
| 5353 | updateInputWindowsLw(); |
| 5354 | } |
| 5355 | } |
| 5356 | |
| 5357 | public void freezeInputDispatchingLw() { |
| 5358 | if (! mInputDispatchFrozen) { |
| 5359 | if (DEBUG_INPUT) { |
| 5360 | Slog.v(TAG, "Freezing input dispatching"); |
| 5361 | } |
| 5362 | |
| 5363 | mInputDispatchFrozen = true; |
| 5364 | updateInputDispatchModeLw(); |
| 5365 | } |
| 5366 | } |
| 5367 | |
| 5368 | public void thawInputDispatchingLw() { |
| 5369 | if (mInputDispatchFrozen) { |
| 5370 | if (DEBUG_INPUT) { |
| 5371 | Slog.v(TAG, "Thawing input dispatching"); |
| 5372 | } |
| 5373 | |
| 5374 | mInputDispatchFrozen = false; |
| 5375 | updateInputDispatchModeLw(); |
| 5376 | } |
| 5377 | } |
| 5378 | |
| 5379 | public void setEventDispatchingLw(boolean enabled) { |
| 5380 | if (mInputDispatchEnabled != enabled) { |
| 5381 | if (DEBUG_INPUT) { |
| 5382 | Slog.v(TAG, "Setting event dispatching to " + enabled); |
| 5383 | } |
| 5384 | |
| 5385 | mInputDispatchEnabled = enabled; |
| 5386 | updateInputDispatchModeLw(); |
| 5387 | } |
| 5388 | } |
| 5389 | |
| 5390 | private void updateInputDispatchModeLw() { |
| 5391 | mInputManager.setInputDispatchMode(mInputDispatchEnabled, mInputDispatchFrozen); |
| 5392 | } |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5393 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5394 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5395 | public void pauseKeyDispatching(IBinder _token) { |
| 5396 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 5397 | "pauseKeyDispatching()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5398 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5399 | } |
| 5400 | |
| 5401 | synchronized (mWindowMap) { |
| 5402 | WindowToken token = mTokenMap.get(_token); |
| 5403 | if (token != null) { |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 5404 | mInputMonitor.pauseDispatchingLw(token); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5405 | } |
| 5406 | } |
| 5407 | } |
| 5408 | |
| 5409 | public void resumeKeyDispatching(IBinder _token) { |
| 5410 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 5411 | "resumeKeyDispatching()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5412 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5413 | } |
| 5414 | |
| 5415 | synchronized (mWindowMap) { |
| 5416 | WindowToken token = mTokenMap.get(_token); |
| 5417 | if (token != null) { |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 5418 | mInputMonitor.resumeDispatchingLw(token); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5419 | } |
| 5420 | } |
| 5421 | } |
| 5422 | |
| 5423 | public void setEventDispatching(boolean enabled) { |
| 5424 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 5425 | "resumeKeyDispatching()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5426 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5427 | } |
| 5428 | |
| 5429 | synchronized (mWindowMap) { |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 5430 | mInputMonitor.setEventDispatchingLw(enabled); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5431 | } |
| 5432 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5433 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5434 | /** |
| 5435 | * Injects a keystroke event into the UI. |
Jeff Brown | 6ec402b | 2010-07-28 15:48:59 -0700 | [diff] [blame] | 5436 | * Even when sync is false, this method may block while waiting for current |
| 5437 | * input events to be dispatched. |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5438 | * |
| 5439 | * @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] | 5440 | * {@link SystemClock#uptimeMillis()} as the timebase.) |
| 5441 | * @param sync If true, wait for the event to be completed before returning to the caller. |
| 5442 | * @return Returns true if event was dispatched, false if it was dropped for any reason |
| 5443 | */ |
| 5444 | public boolean injectKeyEvent(KeyEvent ev, boolean sync) { |
| 5445 | long downTime = ev.getDownTime(); |
| 5446 | long eventTime = ev.getEventTime(); |
| 5447 | |
| 5448 | int action = ev.getAction(); |
| 5449 | int code = ev.getKeyCode(); |
| 5450 | int repeatCount = ev.getRepeatCount(); |
| 5451 | int metaState = ev.getMetaState(); |
| 5452 | int deviceId = ev.getDeviceId(); |
| 5453 | int scancode = ev.getScanCode(); |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 5454 | int source = ev.getSource(); |
| 5455 | |
| 5456 | if (source == InputDevice.SOURCE_UNKNOWN) { |
| 5457 | source = InputDevice.SOURCE_KEYBOARD; |
| 5458 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5459 | |
| 5460 | if (eventTime == 0) eventTime = SystemClock.uptimeMillis(); |
| 5461 | if (downTime == 0) downTime = eventTime; |
| 5462 | |
| 5463 | KeyEvent newEvent = new KeyEvent(downTime, eventTime, action, code, repeatCount, metaState, |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 5464 | deviceId, scancode, KeyEvent.FLAG_FROM_SYSTEM, source); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5465 | |
Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5466 | final int pid = Binder.getCallingPid(); |
| 5467 | final int uid = Binder.getCallingUid(); |
| 5468 | final long ident = Binder.clearCallingIdentity(); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5469 | |
Jeff Brown | 6ec402b | 2010-07-28 15:48:59 -0700 | [diff] [blame] | 5470 | final int result = mInputManager.injectInputEvent(newEvent, pid, uid, |
| 5471 | sync ? InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH |
| 5472 | : InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT, |
| 5473 | INJECTION_TIMEOUT_MILLIS); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5474 | |
Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5475 | Binder.restoreCallingIdentity(ident); |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 5476 | return reportInjectionResult(result); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5477 | } |
| 5478 | |
| 5479 | /** |
| 5480 | * Inject a pointer (touch) event into the UI. |
Jeff Brown | 6ec402b | 2010-07-28 15:48:59 -0700 | [diff] [blame] | 5481 | * Even when sync is false, this method may block while waiting for current |
| 5482 | * input events to be dispatched. |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5483 | * |
| 5484 | * @param ev A motion event describing the pointer (touch) action. (As noted in |
| 5485 | * {@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] | 5486 | * {@link SystemClock#uptimeMillis()} as the timebase.) |
| 5487 | * @param sync If true, wait for the event to be completed before returning to the caller. |
| 5488 | * @return Returns true if event was dispatched, false if it was dropped for any reason |
| 5489 | */ |
| 5490 | public boolean injectPointerEvent(MotionEvent ev, boolean sync) { |
Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5491 | final int pid = Binder.getCallingPid(); |
| 5492 | final int uid = Binder.getCallingUid(); |
| 5493 | final long ident = Binder.clearCallingIdentity(); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5494 | |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 5495 | MotionEvent newEvent = MotionEvent.obtain(ev); |
| 5496 | if ((newEvent.getSource() & InputDevice.SOURCE_CLASS_POINTER) == 0) { |
| 5497 | newEvent.setSource(InputDevice.SOURCE_TOUCHSCREEN); |
| 5498 | } |
| 5499 | |
Jeff Brown | 6ec402b | 2010-07-28 15:48:59 -0700 | [diff] [blame] | 5500 | final int result = mInputManager.injectInputEvent(newEvent, pid, uid, |
| 5501 | sync ? InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH |
| 5502 | : InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT, |
| 5503 | INJECTION_TIMEOUT_MILLIS); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5504 | |
Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5505 | Binder.restoreCallingIdentity(ident); |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 5506 | return reportInjectionResult(result); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5507 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5508 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5509 | /** |
| 5510 | * Inject a trackball (navigation device) event into the UI. |
Jeff Brown | 6ec402b | 2010-07-28 15:48:59 -0700 | [diff] [blame] | 5511 | * Even when sync is false, this method may block while waiting for current |
| 5512 | * input events to be dispatched. |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5513 | * |
| 5514 | * @param ev A motion event describing the trackball action. (As noted in |
| 5515 | * {@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] | 5516 | * {@link SystemClock#uptimeMillis()} as the timebase.) |
| 5517 | * @param sync If true, wait for the event to be completed before returning to the caller. |
| 5518 | * @return Returns true if event was dispatched, false if it was dropped for any reason |
| 5519 | */ |
| 5520 | public boolean injectTrackballEvent(MotionEvent ev, boolean sync) { |
Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5521 | final int pid = Binder.getCallingPid(); |
| 5522 | final int uid = Binder.getCallingUid(); |
| 5523 | final long ident = Binder.clearCallingIdentity(); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5524 | |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 5525 | MotionEvent newEvent = MotionEvent.obtain(ev); |
| 5526 | if ((newEvent.getSource() & InputDevice.SOURCE_CLASS_TRACKBALL) == 0) { |
| 5527 | newEvent.setSource(InputDevice.SOURCE_TRACKBALL); |
| 5528 | } |
| 5529 | |
Jeff Brown | 6ec402b | 2010-07-28 15:48:59 -0700 | [diff] [blame] | 5530 | final int result = mInputManager.injectInputEvent(newEvent, pid, uid, |
| 5531 | sync ? InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH |
| 5532 | : InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT, |
| 5533 | INJECTION_TIMEOUT_MILLIS); |
| 5534 | |
| 5535 | Binder.restoreCallingIdentity(ident); |
| 5536 | return reportInjectionResult(result); |
| 5537 | } |
| 5538 | |
| 5539 | /** |
| 5540 | * Inject an input event into the UI without waiting for dispatch to commence. |
| 5541 | * This variant is useful for fire-and-forget input event injection. It does not |
| 5542 | * block any longer than it takes to enqueue the input event. |
| 5543 | * |
| 5544 | * @param ev An input event. (Be sure to set the input source correctly.) |
| 5545 | * @return Returns true if event was dispatched, false if it was dropped for any reason |
| 5546 | */ |
| 5547 | public boolean injectInputEventNoWait(InputEvent ev) { |
| 5548 | final int pid = Binder.getCallingPid(); |
| 5549 | final int uid = Binder.getCallingUid(); |
| 5550 | final long ident = Binder.clearCallingIdentity(); |
| 5551 | |
| 5552 | final int result = mInputManager.injectInputEvent(ev, pid, uid, |
| 5553 | InputManager.INPUT_EVENT_INJECTION_SYNC_NONE, |
| 5554 | INJECTION_TIMEOUT_MILLIS); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5555 | |
Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5556 | Binder.restoreCallingIdentity(ident); |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 5557 | return reportInjectionResult(result); |
| 5558 | } |
| 5559 | |
| 5560 | private boolean reportInjectionResult(int result) { |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 5561 | switch (result) { |
| 5562 | case InputManager.INPUT_EVENT_INJECTION_PERMISSION_DENIED: |
| 5563 | Slog.w(TAG, "Input event injection permission denied."); |
| 5564 | throw new SecurityException( |
| 5565 | "Injecting to another application requires INJECT_EVENTS permission"); |
| 5566 | case InputManager.INPUT_EVENT_INJECTION_SUCCEEDED: |
Christopher Tate | 09e85dc | 2010-08-02 11:54:41 -0700 | [diff] [blame] | 5567 | //Slog.v(TAG, "Input event injection succeeded."); |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 5568 | return true; |
| 5569 | case InputManager.INPUT_EVENT_INJECTION_TIMED_OUT: |
| 5570 | Slog.w(TAG, "Input event injection timed out."); |
| 5571 | return false; |
| 5572 | case InputManager.INPUT_EVENT_INJECTION_FAILED: |
| 5573 | default: |
| 5574 | Slog.w(TAG, "Input event injection failed."); |
| 5575 | return false; |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5576 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5577 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5578 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5579 | private WindowState getFocusedWindow() { |
| 5580 | synchronized (mWindowMap) { |
| 5581 | return getFocusedWindowLocked(); |
| 5582 | } |
| 5583 | } |
| 5584 | |
| 5585 | private WindowState getFocusedWindowLocked() { |
| 5586 | return mCurrentFocus; |
| 5587 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5588 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5589 | public boolean detectSafeMode() { |
| 5590 | mSafeMode = mPolicy.detectSafeMode(); |
| 5591 | return mSafeMode; |
| 5592 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5593 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5594 | public void systemReady() { |
| 5595 | mPolicy.systemReady(); |
| 5596 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5597 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5598 | // ------------------------------------------------------------- |
| 5599 | // Client Session State |
| 5600 | // ------------------------------------------------------------- |
| 5601 | |
| 5602 | private final class Session extends IWindowSession.Stub |
| 5603 | implements IBinder.DeathRecipient { |
| 5604 | final IInputMethodClient mClient; |
| 5605 | final IInputContext mInputContext; |
| 5606 | final int mUid; |
| 5607 | final int mPid; |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 5608 | final String mStringName; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5609 | SurfaceSession mSurfaceSession; |
| 5610 | int mNumWindow = 0; |
| 5611 | boolean mClientDead = false; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5612 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5613 | public Session(IInputMethodClient client, IInputContext inputContext) { |
| 5614 | mClient = client; |
| 5615 | mInputContext = inputContext; |
| 5616 | mUid = Binder.getCallingUid(); |
| 5617 | mPid = Binder.getCallingPid(); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 5618 | StringBuilder sb = new StringBuilder(); |
| 5619 | sb.append("Session{"); |
| 5620 | sb.append(Integer.toHexString(System.identityHashCode(this))); |
| 5621 | sb.append(" uid "); |
| 5622 | sb.append(mUid); |
| 5623 | sb.append("}"); |
| 5624 | mStringName = sb.toString(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5625 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5626 | synchronized (mWindowMap) { |
| 5627 | if (mInputMethodManager == null && mHaveInputMethods) { |
| 5628 | IBinder b = ServiceManager.getService( |
| 5629 | Context.INPUT_METHOD_SERVICE); |
| 5630 | mInputMethodManager = IInputMethodManager.Stub.asInterface(b); |
| 5631 | } |
| 5632 | } |
| 5633 | long ident = Binder.clearCallingIdentity(); |
| 5634 | try { |
| 5635 | // Note: it is safe to call in to the input method manager |
| 5636 | // here because we are not holding our lock. |
| 5637 | if (mInputMethodManager != null) { |
| 5638 | mInputMethodManager.addClient(client, inputContext, |
| 5639 | mUid, mPid); |
| 5640 | } else { |
| 5641 | client.setUsingInputMethod(false); |
| 5642 | } |
| 5643 | client.asBinder().linkToDeath(this, 0); |
| 5644 | } catch (RemoteException e) { |
| 5645 | // The caller has died, so we can just forget about this. |
| 5646 | try { |
| 5647 | if (mInputMethodManager != null) { |
| 5648 | mInputMethodManager.removeClient(client); |
| 5649 | } |
| 5650 | } catch (RemoteException ee) { |
| 5651 | } |
| 5652 | } finally { |
| 5653 | Binder.restoreCallingIdentity(ident); |
| 5654 | } |
| 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 | @Override |
| 5658 | public boolean onTransact(int code, Parcel data, Parcel reply, int flags) |
| 5659 | throws RemoteException { |
| 5660 | try { |
| 5661 | return super.onTransact(code, data, reply, flags); |
| 5662 | } catch (RuntimeException e) { |
| 5663 | // Log all 'real' exceptions thrown to the caller |
| 5664 | if (!(e instanceof SecurityException)) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5665 | Slog.e(TAG, "Window Session Crash", e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5666 | } |
| 5667 | throw e; |
| 5668 | } |
| 5669 | } |
| 5670 | |
| 5671 | public void binderDied() { |
| 5672 | // Note: it is safe to call in to the input method manager |
| 5673 | // here because we are not holding our lock. |
| 5674 | try { |
| 5675 | if (mInputMethodManager != null) { |
| 5676 | mInputMethodManager.removeClient(mClient); |
| 5677 | } |
| 5678 | } catch (RemoteException e) { |
| 5679 | } |
| 5680 | synchronized(mWindowMap) { |
Suchi Amalapurapu | fff2fda | 2009-06-30 21:36:16 -0700 | [diff] [blame] | 5681 | mClient.asBinder().unlinkToDeath(this, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5682 | mClientDead = true; |
| 5683 | killSessionLocked(); |
| 5684 | } |
| 5685 | } |
| 5686 | |
| 5687 | public int add(IWindow window, WindowManager.LayoutParams attrs, |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5688 | int viewVisibility, Rect outContentInsets, InputChannel outInputChannel) { |
| 5689 | return addWindow(this, window, attrs, viewVisibility, outContentInsets, |
| 5690 | outInputChannel); |
| 5691 | } |
| 5692 | |
| 5693 | public int addWithoutInputChannel(IWindow window, WindowManager.LayoutParams attrs, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5694 | int viewVisibility, Rect outContentInsets) { |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5695 | return addWindow(this, window, attrs, viewVisibility, outContentInsets, null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5696 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5697 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5698 | public void remove(IWindow window) { |
| 5699 | removeWindow(this, window); |
| 5700 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5701 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5702 | public int relayout(IWindow window, WindowManager.LayoutParams attrs, |
| 5703 | int requestedWidth, int requestedHeight, int viewFlags, |
| 5704 | boolean insetsPending, Rect outFrame, Rect outContentInsets, |
Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 5705 | Rect outVisibleInsets, Configuration outConfig, Surface outSurface) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5706 | return relayoutWindow(this, window, attrs, |
| 5707 | requestedWidth, requestedHeight, viewFlags, insetsPending, |
Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 5708 | outFrame, outContentInsets, outVisibleInsets, outConfig, outSurface); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5709 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5710 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5711 | public void setTransparentRegion(IWindow window, Region region) { |
| 5712 | setTransparentRegionWindow(this, window, region); |
| 5713 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5714 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5715 | public void setInsets(IWindow window, int touchableInsets, |
| 5716 | Rect contentInsets, Rect visibleInsets) { |
| 5717 | setInsetsWindow(this, window, touchableInsets, contentInsets, |
| 5718 | visibleInsets); |
| 5719 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5720 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5721 | public void getDisplayFrame(IWindow window, Rect outDisplayFrame) { |
| 5722 | getWindowDisplayFrame(this, window, outDisplayFrame); |
| 5723 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5724 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5725 | public void finishDrawing(IWindow window) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5726 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5727 | TAG, "IWindow finishDrawing called for " + window); |
| 5728 | finishDrawingWindow(this, window); |
| 5729 | } |
| 5730 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5731 | public void setInTouchMode(boolean mode) { |
| 5732 | synchronized(mWindowMap) { |
| 5733 | mInTouchMode = mode; |
| 5734 | } |
| 5735 | } |
| 5736 | |
| 5737 | public boolean getInTouchMode() { |
| 5738 | synchronized(mWindowMap) { |
| 5739 | return mInTouchMode; |
| 5740 | } |
| 5741 | } |
| 5742 | |
| 5743 | public boolean performHapticFeedback(IWindow window, int effectId, |
| 5744 | boolean always) { |
| 5745 | synchronized(mWindowMap) { |
| 5746 | long ident = Binder.clearCallingIdentity(); |
| 5747 | try { |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 5748 | return mPolicy.performHapticFeedbackLw( |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 5749 | windowForClientLocked(this, window, true), |
| 5750 | effectId, always); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5751 | } finally { |
| 5752 | Binder.restoreCallingIdentity(ident); |
| 5753 | } |
| 5754 | } |
| 5755 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5756 | |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 5757 | 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] | 5758 | synchronized(mWindowMap) { |
| 5759 | long ident = Binder.clearCallingIdentity(); |
| 5760 | try { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 5761 | setWindowWallpaperPositionLocked( |
| 5762 | windowForClientLocked(this, window, true), |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 5763 | x, y, xStep, yStep); |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 5764 | } finally { |
| 5765 | Binder.restoreCallingIdentity(ident); |
| 5766 | } |
| 5767 | } |
| 5768 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 5769 | |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 5770 | public void wallpaperOffsetsComplete(IBinder window) { |
| 5771 | WindowManagerService.this.wallpaperOffsetsComplete(window); |
| 5772 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 5773 | |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 5774 | public Bundle sendWallpaperCommand(IBinder window, String action, int x, int y, |
| 5775 | int z, Bundle extras, boolean sync) { |
| 5776 | synchronized(mWindowMap) { |
| 5777 | long ident = Binder.clearCallingIdentity(); |
| 5778 | try { |
| 5779 | return sendWindowWallpaperCommandLocked( |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 5780 | windowForClientLocked(this, window, true), |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 5781 | action, x, y, z, extras, sync); |
| 5782 | } finally { |
| 5783 | Binder.restoreCallingIdentity(ident); |
| 5784 | } |
| 5785 | } |
| 5786 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 5787 | |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 5788 | public void wallpaperCommandComplete(IBinder window, Bundle result) { |
| 5789 | WindowManagerService.this.wallpaperCommandComplete(window, result); |
| 5790 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 5791 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5792 | void windowAddedLocked() { |
| 5793 | if (mSurfaceSession == null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5794 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5795 | TAG, "First window added to " + this + ", creating SurfaceSession"); |
| 5796 | mSurfaceSession = new SurfaceSession(); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5797 | if (SHOW_TRANSACTIONS) Slog.i( |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 5798 | TAG, " NEW SURFACE SESSION " + mSurfaceSession); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5799 | mSessions.add(this); |
| 5800 | } |
| 5801 | mNumWindow++; |
| 5802 | } |
| 5803 | |
| 5804 | void windowRemovedLocked() { |
| 5805 | mNumWindow--; |
| 5806 | killSessionLocked(); |
| 5807 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5808 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5809 | void killSessionLocked() { |
| 5810 | if (mNumWindow <= 0 && mClientDead) { |
| 5811 | mSessions.remove(this); |
| 5812 | if (mSurfaceSession != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5813 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5814 | TAG, "Last window removed from " + this |
| 5815 | + ", destroying " + mSurfaceSession); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5816 | if (SHOW_TRANSACTIONS) Slog.i( |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 5817 | TAG, " KILL SURFACE SESSION " + mSurfaceSession); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5818 | try { |
| 5819 | mSurfaceSession.kill(); |
| 5820 | } catch (Exception e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5821 | Slog.w(TAG, "Exception thrown when killing surface session " |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5822 | + mSurfaceSession + " in session " + this |
| 5823 | + ": " + e.toString()); |
| 5824 | } |
| 5825 | mSurfaceSession = null; |
| 5826 | } |
| 5827 | } |
| 5828 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5829 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5830 | void dump(PrintWriter pw, String prefix) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 5831 | pw.print(prefix); pw.print("mNumWindow="); pw.print(mNumWindow); |
| 5832 | pw.print(" mClientDead="); pw.print(mClientDead); |
| 5833 | pw.print(" mSurfaceSession="); pw.println(mSurfaceSession); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5834 | } |
| 5835 | |
| 5836 | @Override |
| 5837 | public String toString() { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 5838 | return mStringName; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5839 | } |
| 5840 | } |
| 5841 | |
| 5842 | // ------------------------------------------------------------- |
| 5843 | // Client Window State |
| 5844 | // ------------------------------------------------------------- |
| 5845 | |
| 5846 | private final class WindowState implements WindowManagerPolicy.WindowState { |
| 5847 | final Session mSession; |
| 5848 | final IWindow mClient; |
| 5849 | WindowToken mToken; |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 5850 | WindowToken mRootToken; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5851 | AppWindowToken mAppToken; |
| 5852 | AppWindowToken mTargetAppToken; |
| 5853 | final WindowManager.LayoutParams mAttrs = new WindowManager.LayoutParams(); |
| 5854 | final DeathRecipient mDeathRecipient; |
| 5855 | final WindowState mAttachedWindow; |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 5856 | final ArrayList<WindowState> mChildWindows = new ArrayList<WindowState>(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5857 | final int mBaseLayer; |
| 5858 | final int mSubLayer; |
| 5859 | final boolean mLayoutAttached; |
| 5860 | final boolean mIsImWindow; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 5861 | final boolean mIsWallpaper; |
| 5862 | final boolean mIsFloatingLayer; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5863 | int mViewVisibility; |
| 5864 | boolean mPolicyVisibility = true; |
| 5865 | boolean mPolicyVisibilityAfterAnim = true; |
| 5866 | boolean mAppFreezing; |
| 5867 | Surface mSurface; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 5868 | boolean mReportDestroySurface; |
| 5869 | boolean mSurfacePendingDestroy; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5870 | boolean mAttachedHidden; // is our parent window hidden? |
| 5871 | boolean mLastHidden; // was this window last hidden? |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 5872 | boolean mWallpaperVisible; // for wallpaper, what was last vis report? |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5873 | int mRequestedWidth; |
| 5874 | int mRequestedHeight; |
| 5875 | int mLastRequestedWidth; |
| 5876 | int mLastRequestedHeight; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5877 | int mLayer; |
| 5878 | int mAnimLayer; |
| 5879 | int mLastLayer; |
| 5880 | boolean mHaveFrame; |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 5881 | boolean mObscured; |
Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 5882 | boolean mTurnOnScreen; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5883 | |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 5884 | int mLayoutSeq = -1; |
| 5885 | |
| 5886 | Configuration mConfiguration = null; |
| 5887 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5888 | // Actual frame shown on-screen (may be modified by animation) |
| 5889 | final Rect mShownFrame = new Rect(); |
| 5890 | final Rect mLastShownFrame = new Rect(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5891 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5892 | /** |
Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 5893 | * Set when we have changed the size of the surface, to know that |
| 5894 | * we must tell them application to resize (and thus redraw itself). |
| 5895 | */ |
| 5896 | boolean mSurfaceResized; |
| 5897 | |
| 5898 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5899 | * Insets that determine the actually visible area |
| 5900 | */ |
| 5901 | final Rect mVisibleInsets = new Rect(); |
| 5902 | final Rect mLastVisibleInsets = new Rect(); |
| 5903 | boolean mVisibleInsetsChanged; |
| 5904 | |
| 5905 | /** |
| 5906 | * Insets that are covered by system windows |
| 5907 | */ |
| 5908 | final Rect mContentInsets = new Rect(); |
| 5909 | final Rect mLastContentInsets = new Rect(); |
| 5910 | boolean mContentInsetsChanged; |
| 5911 | |
| 5912 | /** |
| 5913 | * Set to true if we are waiting for this window to receive its |
| 5914 | * given internal insets before laying out other windows based on it. |
| 5915 | */ |
| 5916 | boolean mGivenInsetsPending; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5917 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5918 | /** |
| 5919 | * These are the content insets that were given during layout for |
| 5920 | * this window, to be applied to windows behind it. |
| 5921 | */ |
| 5922 | final Rect mGivenContentInsets = new Rect(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5923 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5924 | /** |
| 5925 | * These are the visible insets that were given during layout for |
| 5926 | * this window, to be applied to windows behind it. |
| 5927 | */ |
| 5928 | final Rect mGivenVisibleInsets = new Rect(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5929 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5930 | /** |
| 5931 | * Flag indicating whether the touchable region should be adjusted by |
| 5932 | * the visible insets; if false the area outside the visible insets is |
| 5933 | * NOT touchable, so we must use those to adjust the frame during hit |
| 5934 | * tests. |
| 5935 | */ |
| 5936 | int mTouchableInsets = ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5937 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5938 | // Current transformation being applied. |
| 5939 | float mDsDx=1, mDtDx=0, mDsDy=0, mDtDy=1; |
| 5940 | float mLastDsDx=1, mLastDtDx=0, mLastDsDy=0, mLastDtDy=1; |
| 5941 | float mHScale=1, mVScale=1; |
| 5942 | float mLastHScale=1, mLastVScale=1; |
| 5943 | final Matrix mTmpMatrix = new Matrix(); |
| 5944 | |
| 5945 | // "Real" frame that the application sees. |
| 5946 | final Rect mFrame = new Rect(); |
| 5947 | final Rect mLastFrame = new Rect(); |
| 5948 | |
| 5949 | final Rect mContainingFrame = new Rect(); |
| 5950 | final Rect mDisplayFrame = new Rect(); |
| 5951 | final Rect mContentFrame = new Rect(); |
| 5952 | final Rect mVisibleFrame = new Rect(); |
| 5953 | |
| 5954 | float mShownAlpha = 1; |
| 5955 | float mAlpha = 1; |
| 5956 | float mLastAlpha = 1; |
| 5957 | |
| 5958 | // Set to true if, when the window gets displayed, it should perform |
| 5959 | // an enter animation. |
| 5960 | boolean mEnterAnimationPending; |
| 5961 | |
| 5962 | // Currently running animation. |
| 5963 | boolean mAnimating; |
| 5964 | boolean mLocalAnimating; |
| 5965 | Animation mAnimation; |
| 5966 | boolean mAnimationIsEntrance; |
| 5967 | boolean mHasTransformation; |
| 5968 | boolean mHasLocalTransformation; |
| 5969 | final Transformation mTransformation = new Transformation(); |
| 5970 | |
Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 5971 | // If a window showing a wallpaper: the requested offset for the |
| 5972 | // wallpaper; if a wallpaper window: the currently applied offset. |
| 5973 | float mWallpaperX = -1; |
| 5974 | float mWallpaperY = -1; |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 5975 | |
| 5976 | // If a window showing a wallpaper: what fraction of the offset |
| 5977 | // range corresponds to a full virtual screen. |
| 5978 | float mWallpaperXStep = -1; |
| 5979 | float mWallpaperYStep = -1; |
| 5980 | |
Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 5981 | // Wallpaper windows: pixels offset based on above variables. |
| 5982 | int mXOffset; |
| 5983 | int mYOffset; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 5984 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5985 | // This is set after IWindowSession.relayout() has been called at |
| 5986 | // least once for the window. It allows us to detect the situation |
| 5987 | // where we don't yet have a surface, but should have one soon, so |
| 5988 | // we can give the window focus before waiting for the relayout. |
| 5989 | boolean mRelayoutCalled; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5990 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5991 | // This is set after the Surface has been created but before the |
| 5992 | // window has been drawn. During this time the surface is hidden. |
| 5993 | boolean mDrawPending; |
| 5994 | |
| 5995 | // This is set after the window has finished drawing for the first |
| 5996 | // time but before its surface is shown. The surface will be |
| 5997 | // displayed when the next layout is run. |
| 5998 | boolean mCommitDrawPending; |
| 5999 | |
| 6000 | // This is set during the time after the window's drawing has been |
| 6001 | // committed, and before its surface is actually shown. It is used |
| 6002 | // to delay showing the surface until all windows in a token are ready |
| 6003 | // to be shown. |
| 6004 | boolean mReadyToShow; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6005 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6006 | // Set when the window has been shown in the screen the first time. |
| 6007 | boolean mHasDrawn; |
| 6008 | |
| 6009 | // Currently running an exit animation? |
| 6010 | boolean mExiting; |
| 6011 | |
| 6012 | // Currently on the mDestroySurface list? |
| 6013 | boolean mDestroying; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6014 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6015 | // Completely remove from window manager after exit animation? |
| 6016 | boolean mRemoveOnExit; |
| 6017 | |
| 6018 | // Set when the orientation is changing and this window has not yet |
| 6019 | // been updated for the new orientation. |
| 6020 | boolean mOrientationChanging; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6021 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6022 | // Is this window now (or just being) removed? |
| 6023 | boolean mRemoved; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6024 | |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 6025 | // For debugging, this is the last information given to the surface flinger. |
| 6026 | boolean mSurfaceShown; |
| 6027 | int mSurfaceX, mSurfaceY, mSurfaceW, mSurfaceH; |
| 6028 | int mSurfaceLayer; |
| 6029 | float mSurfaceAlpha; |
| 6030 | |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 6031 | // Input channel |
| 6032 | InputChannel mInputChannel; |
| 6033 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6034 | WindowState(Session s, IWindow c, WindowToken token, |
| 6035 | WindowState attachedWindow, WindowManager.LayoutParams a, |
| 6036 | int viewVisibility) { |
| 6037 | mSession = s; |
| 6038 | mClient = c; |
| 6039 | mToken = token; |
| 6040 | mAttrs.copyFrom(a); |
| 6041 | mViewVisibility = viewVisibility; |
| 6042 | DeathRecipient deathRecipient = new DeathRecipient(); |
| 6043 | mAlpha = a.alpha; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6044 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6045 | TAG, "Window " + this + " client=" + c.asBinder() |
| 6046 | + " token=" + token + " (" + mAttrs.token + ")"); |
| 6047 | try { |
| 6048 | c.asBinder().linkToDeath(deathRecipient, 0); |
| 6049 | } catch (RemoteException e) { |
| 6050 | mDeathRecipient = null; |
| 6051 | mAttachedWindow = null; |
| 6052 | mLayoutAttached = false; |
| 6053 | mIsImWindow = false; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 6054 | mIsWallpaper = false; |
| 6055 | mIsFloatingLayer = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6056 | mBaseLayer = 0; |
| 6057 | mSubLayer = 0; |
| 6058 | return; |
| 6059 | } |
| 6060 | mDeathRecipient = deathRecipient; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6061 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6062 | if ((mAttrs.type >= FIRST_SUB_WINDOW && |
| 6063 | mAttrs.type <= LAST_SUB_WINDOW)) { |
| 6064 | // The multiplier here is to reserve space for multiple |
| 6065 | // windows in the same type layer. |
| 6066 | mBaseLayer = mPolicy.windowTypeToLayerLw( |
| 6067 | attachedWindow.mAttrs.type) * TYPE_LAYER_MULTIPLIER |
| 6068 | + TYPE_LAYER_OFFSET; |
| 6069 | mSubLayer = mPolicy.subWindowTypeToLayerLw(a.type); |
| 6070 | mAttachedWindow = attachedWindow; |
| 6071 | mAttachedWindow.mChildWindows.add(this); |
| 6072 | mLayoutAttached = mAttrs.type != |
| 6073 | WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG; |
| 6074 | mIsImWindow = attachedWindow.mAttrs.type == TYPE_INPUT_METHOD |
| 6075 | || attachedWindow.mAttrs.type == TYPE_INPUT_METHOD_DIALOG; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 6076 | mIsWallpaper = attachedWindow.mAttrs.type == TYPE_WALLPAPER; |
| 6077 | mIsFloatingLayer = mIsImWindow || mIsWallpaper; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6078 | } else { |
| 6079 | // The multiplier here is to reserve space for multiple |
| 6080 | // windows in the same type layer. |
| 6081 | mBaseLayer = mPolicy.windowTypeToLayerLw(a.type) |
| 6082 | * TYPE_LAYER_MULTIPLIER |
| 6083 | + TYPE_LAYER_OFFSET; |
| 6084 | mSubLayer = 0; |
| 6085 | mAttachedWindow = null; |
| 6086 | mLayoutAttached = false; |
| 6087 | mIsImWindow = mAttrs.type == TYPE_INPUT_METHOD |
| 6088 | || mAttrs.type == TYPE_INPUT_METHOD_DIALOG; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 6089 | mIsWallpaper = mAttrs.type == TYPE_WALLPAPER; |
| 6090 | mIsFloatingLayer = mIsImWindow || mIsWallpaper; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6091 | } |
| 6092 | |
| 6093 | WindowState appWin = this; |
| 6094 | while (appWin.mAttachedWindow != null) { |
| 6095 | appWin = mAttachedWindow; |
| 6096 | } |
| 6097 | WindowToken appToken = appWin.mToken; |
| 6098 | while (appToken.appWindowToken == null) { |
| 6099 | WindowToken parent = mTokenMap.get(appToken.token); |
| 6100 | if (parent == null || appToken == parent) { |
| 6101 | break; |
| 6102 | } |
| 6103 | appToken = parent; |
| 6104 | } |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 6105 | mRootToken = appToken; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6106 | mAppToken = appToken.appWindowToken; |
| 6107 | |
| 6108 | mSurface = null; |
| 6109 | mRequestedWidth = 0; |
| 6110 | mRequestedHeight = 0; |
| 6111 | mLastRequestedWidth = 0; |
| 6112 | mLastRequestedHeight = 0; |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 6113 | mXOffset = 0; |
| 6114 | mYOffset = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6115 | mLayer = 0; |
| 6116 | mAnimLayer = 0; |
| 6117 | mLastLayer = 0; |
| 6118 | } |
| 6119 | |
| 6120 | void attach() { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6121 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6122 | TAG, "Attaching " + this + " token=" + mToken |
| 6123 | + ", list=" + mToken.windows); |
| 6124 | mSession.windowAddedLocked(); |
| 6125 | } |
| 6126 | |
| 6127 | public void computeFrameLw(Rect pf, Rect df, Rect cf, Rect vf) { |
| 6128 | mHaveFrame = true; |
| 6129 | |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 6130 | final Rect container = mContainingFrame; |
| 6131 | container.set(pf); |
| 6132 | |
| 6133 | final Rect display = mDisplayFrame; |
| 6134 | display.set(df); |
| 6135 | |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 6136 | if ((mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0) { |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 6137 | container.intersect(mCompatibleScreenFrame); |
Mitsuru Oshima | d2967e2 | 2009-07-20 14:01:43 -0700 | [diff] [blame] | 6138 | if ((mAttrs.flags & FLAG_LAYOUT_NO_LIMITS) == 0) { |
| 6139 | display.intersect(mCompatibleScreenFrame); |
| 6140 | } |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 6141 | } |
| 6142 | |
| 6143 | final int pw = container.right - container.left; |
| 6144 | final int ph = container.bottom - container.top; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6145 | |
| 6146 | int w,h; |
| 6147 | if ((mAttrs.flags & mAttrs.FLAG_SCALED) != 0) { |
| 6148 | w = mAttrs.width < 0 ? pw : mAttrs.width; |
| 6149 | h = mAttrs.height< 0 ? ph : mAttrs.height; |
| 6150 | } else { |
Romain Guy | 980a938 | 2010-01-08 15:06:28 -0800 | [diff] [blame] | 6151 | w = mAttrs.width == mAttrs.MATCH_PARENT ? pw : mRequestedWidth; |
| 6152 | h = mAttrs.height== mAttrs.MATCH_PARENT ? ph : mRequestedHeight; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6153 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6154 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6155 | final Rect content = mContentFrame; |
| 6156 | content.set(cf); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6157 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6158 | final Rect visible = mVisibleFrame; |
| 6159 | visible.set(vf); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6160 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6161 | final Rect frame = mFrame; |
Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 6162 | final int fw = frame.width(); |
| 6163 | final int fh = frame.height(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6164 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6165 | //System.out.println("In: w=" + w + " h=" + h + " container=" + |
| 6166 | // container + " x=" + mAttrs.x + " y=" + mAttrs.y); |
| 6167 | |
| 6168 | Gravity.apply(mAttrs.gravity, w, h, container, |
| 6169 | (int) (mAttrs.x + mAttrs.horizontalMargin * pw), |
| 6170 | (int) (mAttrs.y + mAttrs.verticalMargin * ph), frame); |
| 6171 | |
| 6172 | //System.out.println("Out: " + mFrame); |
| 6173 | |
| 6174 | // Now make sure the window fits in the overall display. |
| 6175 | Gravity.applyDisplay(mAttrs.gravity, df, frame); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6176 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6177 | // Make sure the content and visible frames are inside of the |
| 6178 | // final window frame. |
| 6179 | if (content.left < frame.left) content.left = frame.left; |
| 6180 | if (content.top < frame.top) content.top = frame.top; |
| 6181 | if (content.right > frame.right) content.right = frame.right; |
| 6182 | if (content.bottom > frame.bottom) content.bottom = frame.bottom; |
| 6183 | if (visible.left < frame.left) visible.left = frame.left; |
| 6184 | if (visible.top < frame.top) visible.top = frame.top; |
| 6185 | if (visible.right > frame.right) visible.right = frame.right; |
| 6186 | if (visible.bottom > frame.bottom) visible.bottom = frame.bottom; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6187 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6188 | final Rect contentInsets = mContentInsets; |
| 6189 | contentInsets.left = content.left-frame.left; |
| 6190 | contentInsets.top = content.top-frame.top; |
| 6191 | contentInsets.right = frame.right-content.right; |
| 6192 | contentInsets.bottom = frame.bottom-content.bottom; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6193 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6194 | final Rect visibleInsets = mVisibleInsets; |
| 6195 | visibleInsets.left = visible.left-frame.left; |
| 6196 | visibleInsets.top = visible.top-frame.top; |
| 6197 | visibleInsets.right = frame.right-visible.right; |
| 6198 | visibleInsets.bottom = frame.bottom-visible.bottom; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6199 | |
Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 6200 | if (mIsWallpaper && (fw != frame.width() || fh != frame.height())) { |
| 6201 | updateWallpaperOffsetLocked(this, mDisplay.getWidth(), |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 6202 | mDisplay.getHeight(), false); |
Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 6203 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6204 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6205 | if (localLOGV) { |
| 6206 | //if ("com.google.android.youtube".equals(mAttrs.packageName) |
| 6207 | // && mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_PANEL) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6208 | Slog.v(TAG, "Resolving (mRequestedWidth=" |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6209 | + mRequestedWidth + ", mRequestedheight=" |
| 6210 | + mRequestedHeight + ") to" + " (pw=" + pw + ", ph=" + ph |
| 6211 | + "): frame=" + mFrame.toShortString() |
| 6212 | + " ci=" + contentInsets.toShortString() |
| 6213 | + " vi=" + visibleInsets.toShortString()); |
| 6214 | //} |
| 6215 | } |
| 6216 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6217 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6218 | public Rect getFrameLw() { |
| 6219 | return mFrame; |
| 6220 | } |
| 6221 | |
| 6222 | public Rect getShownFrameLw() { |
| 6223 | return mShownFrame; |
| 6224 | } |
| 6225 | |
| 6226 | public Rect getDisplayFrameLw() { |
| 6227 | return mDisplayFrame; |
| 6228 | } |
| 6229 | |
| 6230 | public Rect getContentFrameLw() { |
| 6231 | return mContentFrame; |
| 6232 | } |
| 6233 | |
| 6234 | public Rect getVisibleFrameLw() { |
| 6235 | return mVisibleFrame; |
| 6236 | } |
| 6237 | |
| 6238 | public boolean getGivenInsetsPendingLw() { |
| 6239 | return mGivenInsetsPending; |
| 6240 | } |
| 6241 | |
| 6242 | public Rect getGivenContentInsetsLw() { |
| 6243 | return mGivenContentInsets; |
| 6244 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6245 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6246 | public Rect getGivenVisibleInsetsLw() { |
| 6247 | return mGivenVisibleInsets; |
| 6248 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6249 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6250 | public WindowManager.LayoutParams getAttrs() { |
| 6251 | return mAttrs; |
| 6252 | } |
| 6253 | |
| 6254 | public int getSurfaceLayer() { |
| 6255 | return mLayer; |
| 6256 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6257 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6258 | public IApplicationToken getAppToken() { |
| 6259 | return mAppToken != null ? mAppToken.appToken : null; |
| 6260 | } |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 6261 | |
| 6262 | public long getInputDispatchingTimeoutNanos() { |
| 6263 | return mAppToken != null |
| 6264 | ? mAppToken.inputDispatchingTimeoutNanos |
| 6265 | : DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS; |
| 6266 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6267 | |
| 6268 | public boolean hasAppShownWindows() { |
| 6269 | return mAppToken != null ? mAppToken.firstWindowDrawn : false; |
| 6270 | } |
| 6271 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6272 | public void setAnimation(Animation anim) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6273 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6274 | TAG, "Setting animation in " + this + ": " + anim); |
| 6275 | mAnimating = false; |
| 6276 | mLocalAnimating = false; |
| 6277 | mAnimation = anim; |
| 6278 | mAnimation.restrictDuration(MAX_ANIMATION_DURATION); |
| 6279 | mAnimation.scaleCurrentDuration(mWindowAnimationScale); |
| 6280 | } |
| 6281 | |
| 6282 | public void clearAnimation() { |
| 6283 | if (mAnimation != null) { |
| 6284 | mAnimating = true; |
| 6285 | mLocalAnimating = false; |
| 6286 | mAnimation = null; |
| 6287 | } |
| 6288 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6289 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6290 | Surface createSurfaceLocked() { |
| 6291 | if (mSurface == null) { |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 6292 | mReportDestroySurface = false; |
| 6293 | mSurfacePendingDestroy = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6294 | mDrawPending = true; |
| 6295 | mCommitDrawPending = false; |
| 6296 | mReadyToShow = false; |
| 6297 | if (mAppToken != null) { |
| 6298 | mAppToken.allDrawn = false; |
| 6299 | } |
| 6300 | |
| 6301 | int flags = 0; |
Mathias Agopian | 317a628 | 2009-08-13 17:29:02 -0700 | [diff] [blame] | 6302 | if (mAttrs.memoryType == MEMORY_TYPE_PUSH_BUFFERS) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6303 | flags |= Surface.PUSH_BUFFERS; |
| 6304 | } |
| 6305 | |
| 6306 | if ((mAttrs.flags&WindowManager.LayoutParams.FLAG_SECURE) != 0) { |
| 6307 | flags |= Surface.SECURE; |
| 6308 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6309 | if (DEBUG_VISIBILITY) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6310 | TAG, "Creating surface in session " |
| 6311 | + mSession.mSurfaceSession + " window " + this |
| 6312 | + " w=" + mFrame.width() |
| 6313 | + " h=" + mFrame.height() + " format=" |
| 6314 | + mAttrs.format + " flags=" + flags); |
| 6315 | |
| 6316 | int w = mFrame.width(); |
| 6317 | int h = mFrame.height(); |
| 6318 | if ((mAttrs.flags & LayoutParams.FLAG_SCALED) != 0) { |
| 6319 | // for a scaled surface, we always want the requested |
| 6320 | // size. |
| 6321 | w = mRequestedWidth; |
| 6322 | h = mRequestedHeight; |
| 6323 | } |
| 6324 | |
Romain Guy | 9825ec6 | 2009-10-01 00:58:09 -0700 | [diff] [blame] | 6325 | // Something is wrong and SurfaceFlinger will not like this, |
| 6326 | // try to revert to sane values |
| 6327 | if (w <= 0) w = 1; |
| 6328 | if (h <= 0) h = 1; |
| 6329 | |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 6330 | mSurfaceShown = false; |
| 6331 | mSurfaceLayer = 0; |
| 6332 | mSurfaceAlpha = 1; |
| 6333 | mSurfaceX = 0; |
| 6334 | mSurfaceY = 0; |
| 6335 | mSurfaceW = w; |
| 6336 | mSurfaceH = h; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6337 | try { |
| 6338 | mSurface = new Surface( |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6339 | mSession.mSurfaceSession, mSession.mPid, |
Mathias Agopian | 5d26c1e | 2010-03-01 16:09:43 -0800 | [diff] [blame] | 6340 | mAttrs.getTitle().toString(), |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6341 | 0, w, h, mAttrs.format, flags); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6342 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " CREATE SURFACE " |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 6343 | + mSurface + " IN SESSION " |
| 6344 | + mSession.mSurfaceSession |
| 6345 | + ": pid=" + mSession.mPid + " format=" |
| 6346 | + mAttrs.format + " flags=0x" |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 6347 | + Integer.toHexString(flags) |
| 6348 | + " / " + this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6349 | } catch (Surface.OutOfResourcesException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6350 | Slog.w(TAG, "OutOfResourcesException creating surface"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6351 | reclaimSomeSurfaceMemoryLocked(this, "create"); |
| 6352 | return null; |
| 6353 | } catch (Exception e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6354 | Slog.e(TAG, "Exception creating surface", e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6355 | return null; |
| 6356 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6357 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6358 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6359 | TAG, "Got surface: " + mSurface |
| 6360 | + ", set left=" + mFrame.left + " top=" + mFrame.top |
| 6361 | + ", animLayer=" + mAnimLayer); |
| 6362 | if (SHOW_TRANSACTIONS) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6363 | Slog.i(TAG, ">>> OPEN TRANSACTION"); |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 6364 | if (SHOW_TRANSACTIONS) logSurface(this, |
| 6365 | "CREATE pos=(" + mFrame.left + "," + mFrame.top + ") (" + |
| 6366 | mFrame.width() + "x" + mFrame.height() + "), layer=" + |
| 6367 | mAnimLayer + " HIDE", null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6368 | } |
| 6369 | Surface.openTransaction(); |
| 6370 | try { |
| 6371 | try { |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 6372 | mSurfaceX = mFrame.left + mXOffset; |
Dianne Hackborn | 529bef6 | 2010-03-25 11:48:43 -0700 | [diff] [blame] | 6373 | mSurfaceY = mFrame.top + mYOffset; |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 6374 | mSurface.setPosition(mSurfaceX, mSurfaceY); |
| 6375 | mSurfaceLayer = mAnimLayer; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6376 | mSurface.setLayer(mAnimLayer); |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 6377 | mSurfaceShown = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6378 | mSurface.hide(); |
| 6379 | if ((mAttrs.flags&WindowManager.LayoutParams.FLAG_DITHER) != 0) { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 6380 | if (SHOW_TRANSACTIONS) logSurface(this, "DITHER", null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6381 | mSurface.setFlags(Surface.SURFACE_DITHER, |
| 6382 | Surface.SURFACE_DITHER); |
| 6383 | } |
| 6384 | } catch (RuntimeException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6385 | Slog.w(TAG, "Error creating surface in " + w, e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6386 | reclaimSomeSurfaceMemoryLocked(this, "create-init"); |
| 6387 | } |
| 6388 | mLastHidden = true; |
| 6389 | } finally { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6390 | if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6391 | Surface.closeTransaction(); |
| 6392 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6393 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6394 | TAG, "Created surface " + this); |
| 6395 | } |
| 6396 | return mSurface; |
| 6397 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6398 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6399 | void destroySurfaceLocked() { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6400 | if (mAppToken != null && this == mAppToken.startingWindow) { |
| 6401 | mAppToken.startingDisplayed = false; |
| 6402 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6403 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6404 | if (mSurface != null) { |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 6405 | mDrawPending = false; |
| 6406 | mCommitDrawPending = false; |
| 6407 | mReadyToShow = false; |
| 6408 | |
| 6409 | int i = mChildWindows.size(); |
| 6410 | while (i > 0) { |
| 6411 | i--; |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 6412 | WindowState c = mChildWindows.get(i); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 6413 | c.mAttachedHidden = true; |
| 6414 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6415 | |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 6416 | if (mReportDestroySurface) { |
| 6417 | mReportDestroySurface = false; |
| 6418 | mSurfacePendingDestroy = true; |
| 6419 | try { |
| 6420 | mClient.dispatchGetNewSurface(); |
| 6421 | // We'll really destroy on the next time around. |
| 6422 | return; |
| 6423 | } catch (RemoteException e) { |
| 6424 | } |
| 6425 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6426 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6427 | try { |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 6428 | if (DEBUG_VISIBILITY) { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 6429 | RuntimeException e = null; |
| 6430 | if (!HIDE_STACK_CRAWLS) { |
| 6431 | e = new RuntimeException(); |
| 6432 | e.fillInStackTrace(); |
| 6433 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6434 | Slog.w(TAG, "Window " + this + " destroying surface " |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 6435 | + mSurface + ", session " + mSession, e); |
| 6436 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6437 | if (SHOW_TRANSACTIONS) { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 6438 | RuntimeException e = null; |
| 6439 | if (!HIDE_STACK_CRAWLS) { |
| 6440 | e = new RuntimeException(); |
| 6441 | e.fillInStackTrace(); |
| 6442 | } |
| 6443 | if (SHOW_TRANSACTIONS) logSurface(this, "DESTROY", e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6444 | } |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 6445 | mSurface.destroy(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6446 | } catch (RuntimeException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6447 | Slog.w(TAG, "Exception thrown when destroying Window " + this |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6448 | + " surface " + mSurface + " session " + mSession |
| 6449 | + ": " + e.toString()); |
| 6450 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6451 | |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 6452 | mSurfaceShown = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6453 | mSurface = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6454 | } |
| 6455 | } |
| 6456 | |
| 6457 | boolean finishDrawingLocked() { |
| 6458 | if (mDrawPending) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6459 | if (SHOW_TRANSACTIONS || DEBUG_ORIENTATION) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6460 | TAG, "finishDrawingLocked: " + mSurface); |
| 6461 | mCommitDrawPending = true; |
| 6462 | mDrawPending = false; |
| 6463 | return true; |
| 6464 | } |
| 6465 | return false; |
| 6466 | } |
| 6467 | |
| 6468 | // This must be called while inside a transaction. |
Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 6469 | boolean commitFinishDrawingLocked(long currentTime) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6470 | //Slog.i(TAG, "commitFinishDrawingLocked: " + mSurface); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6471 | if (!mCommitDrawPending) { |
Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 6472 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6473 | } |
| 6474 | mCommitDrawPending = false; |
| 6475 | mReadyToShow = true; |
| 6476 | final boolean starting = mAttrs.type == TYPE_APPLICATION_STARTING; |
| 6477 | final AppWindowToken atoken = mAppToken; |
| 6478 | if (atoken == null || atoken.allDrawn || starting) { |
| 6479 | performShowLocked(); |
| 6480 | } |
Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 6481 | return true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6482 | } |
| 6483 | |
| 6484 | // This must be called while inside a transaction. |
| 6485 | boolean performShowLocked() { |
| 6486 | if (DEBUG_VISIBILITY) { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 6487 | RuntimeException e = null; |
| 6488 | if (!HIDE_STACK_CRAWLS) { |
| 6489 | e = new RuntimeException(); |
| 6490 | e.fillInStackTrace(); |
| 6491 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6492 | Slog.v(TAG, "performShow on " + this |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6493 | + ": readyToShow=" + mReadyToShow + " readyForDisplay=" + isReadyForDisplay() |
| 6494 | + " starting=" + (mAttrs.type == TYPE_APPLICATION_STARTING), e); |
| 6495 | } |
| 6496 | if (mReadyToShow && isReadyForDisplay()) { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 6497 | if (SHOW_TRANSACTIONS || DEBUG_ORIENTATION) logSurface(this, |
| 6498 | "SHOW (performShowLocked)", null); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6499 | if (DEBUG_VISIBILITY) Slog.v(TAG, "Showing " + this |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6500 | + " during animation: policyVis=" + mPolicyVisibility |
| 6501 | + " attHidden=" + mAttachedHidden |
| 6502 | + " tok.hiddenRequested=" |
| 6503 | + (mAppToken != null ? mAppToken.hiddenRequested : false) |
Dianne Hackborn | 248b188 | 2009-09-16 16:46:44 -0700 | [diff] [blame] | 6504 | + " tok.hidden=" |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6505 | + (mAppToken != null ? mAppToken.hidden : false) |
| 6506 | + " animating=" + mAnimating |
| 6507 | + " tok animating=" |
| 6508 | + (mAppToken != null ? mAppToken.animating : false)); |
| 6509 | if (!showSurfaceRobustlyLocked(this)) { |
| 6510 | return false; |
| 6511 | } |
| 6512 | mLastAlpha = -1; |
| 6513 | mHasDrawn = true; |
| 6514 | mLastHidden = false; |
| 6515 | mReadyToShow = false; |
| 6516 | enableScreenIfNeededLocked(); |
| 6517 | |
| 6518 | applyEnterAnimationLocked(this); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6519 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6520 | int i = mChildWindows.size(); |
| 6521 | while (i > 0) { |
| 6522 | i--; |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 6523 | WindowState c = mChildWindows.get(i); |
Dianne Hackborn | f09c1a2 | 2010-04-22 15:59:21 -0700 | [diff] [blame] | 6524 | if (c.mAttachedHidden) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6525 | c.mAttachedHidden = false; |
Dianne Hackborn | f09c1a2 | 2010-04-22 15:59:21 -0700 | [diff] [blame] | 6526 | if (c.mSurface != null) { |
| 6527 | c.performShowLocked(); |
| 6528 | // It hadn't been shown, which means layout not |
| 6529 | // performed on it, so now we want to make sure to |
| 6530 | // do a layout. If called from within the transaction |
| 6531 | // loop, this will cause it to restart with a new |
| 6532 | // layout. |
| 6533 | mLayoutNeeded = true; |
| 6534 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6535 | } |
| 6536 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6537 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6538 | if (mAttrs.type != TYPE_APPLICATION_STARTING |
| 6539 | && mAppToken != null) { |
| 6540 | mAppToken.firstWindowDrawn = true; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6541 | |
Dianne Hackborn | 248b188 | 2009-09-16 16:46:44 -0700 | [diff] [blame] | 6542 | if (mAppToken.startingData != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6543 | if (DEBUG_STARTING_WINDOW || DEBUG_ANIM) Slog.v(TAG, |
Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 6544 | "Finish starting " + mToken |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6545 | + ": first real window is shown, no animation"); |
Dianne Hackborn | 248b188 | 2009-09-16 16:46:44 -0700 | [diff] [blame] | 6546 | // If this initial window is animating, stop it -- we |
| 6547 | // will do an animation to reveal it from behind the |
| 6548 | // starting window, so there is no need for it to also |
| 6549 | // be doing its own stuff. |
| 6550 | if (mAnimation != null) { |
| 6551 | mAnimation = null; |
| 6552 | // Make sure we clean up the animation. |
| 6553 | mAnimating = true; |
| 6554 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6555 | mFinishedStarting.add(mAppToken); |
| 6556 | mH.sendEmptyMessage(H.FINISHED_STARTING); |
| 6557 | } |
| 6558 | mAppToken.updateReportedVisibilityLocked(); |
| 6559 | } |
| 6560 | } |
| 6561 | return true; |
| 6562 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6563 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6564 | // This must be called while inside a transaction. Returns true if |
| 6565 | // there is more animation to run. |
| 6566 | boolean stepAnimationLocked(long currentTime, int dw, int dh) { |
Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 6567 | if (!mDisplayFrozen && mPolicy.isScreenOn()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6568 | // We will run animations as long as the display isn't frozen. |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6569 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6570 | if (!mDrawPending && !mCommitDrawPending && mAnimation != null) { |
| 6571 | mHasTransformation = true; |
| 6572 | mHasLocalTransformation = true; |
| 6573 | if (!mLocalAnimating) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6574 | if (DEBUG_ANIM) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6575 | TAG, "Starting animation in " + this + |
| 6576 | " @ " + currentTime + ": ww=" + mFrame.width() + " wh=" + mFrame.height() + |
| 6577 | " dw=" + dw + " dh=" + dh + " scale=" + mWindowAnimationScale); |
| 6578 | mAnimation.initialize(mFrame.width(), mFrame.height(), dw, dh); |
| 6579 | mAnimation.setStartTime(currentTime); |
| 6580 | mLocalAnimating = true; |
| 6581 | mAnimating = true; |
| 6582 | } |
| 6583 | mTransformation.clear(); |
| 6584 | final boolean more = mAnimation.getTransformation( |
| 6585 | currentTime, mTransformation); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6586 | if (DEBUG_ANIM) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6587 | TAG, "Stepped animation in " + this + |
| 6588 | ": more=" + more + ", xform=" + mTransformation); |
| 6589 | if (more) { |
| 6590 | // we're not done! |
| 6591 | return true; |
| 6592 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6593 | if (DEBUG_ANIM) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6594 | TAG, "Finished animation in " + this + |
| 6595 | " @ " + currentTime); |
| 6596 | mAnimation = null; |
| 6597 | //WindowManagerService.this.dump(); |
| 6598 | } |
| 6599 | mHasLocalTransformation = false; |
| 6600 | if ((!mLocalAnimating || mAnimationIsEntrance) && mAppToken != null |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 6601 | && mAppToken.animation != null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6602 | // When our app token is animating, we kind-of pretend like |
| 6603 | // we are as well. Note the mLocalAnimating mAnimationIsEntrance |
| 6604 | // part of this check means that we will only do this if |
| 6605 | // our window is not currently exiting, or it is not |
| 6606 | // locally animating itself. The idea being that one that |
| 6607 | // is exiting and doing a local animation should be removed |
| 6608 | // once that animation is done. |
| 6609 | mAnimating = true; |
| 6610 | mHasTransformation = true; |
| 6611 | mTransformation.clear(); |
| 6612 | return false; |
| 6613 | } else if (mHasTransformation) { |
| 6614 | // Little trick to get through the path below to act like |
| 6615 | // we have finished an animation. |
| 6616 | mAnimating = true; |
| 6617 | } else if (isAnimating()) { |
| 6618 | mAnimating = true; |
| 6619 | } |
| 6620 | } else if (mAnimation != null) { |
| 6621 | // If the display is frozen, and there is a pending animation, |
| 6622 | // clear it and make sure we run the cleanup code. |
| 6623 | mAnimating = true; |
| 6624 | mLocalAnimating = true; |
| 6625 | mAnimation = null; |
| 6626 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6627 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6628 | if (!mAnimating && !mLocalAnimating) { |
| 6629 | return false; |
| 6630 | } |
| 6631 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6632 | if (DEBUG_ANIM) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6633 | TAG, "Animation done in " + this + ": exiting=" + mExiting |
| 6634 | + ", reportedVisible=" |
| 6635 | + (mAppToken != null ? mAppToken.reportedVisible : false)); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6636 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6637 | mAnimating = false; |
| 6638 | mLocalAnimating = false; |
| 6639 | mAnimation = null; |
| 6640 | mAnimLayer = mLayer; |
| 6641 | if (mIsImWindow) { |
| 6642 | mAnimLayer += mInputMethodAnimLayerAdjustment; |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 6643 | } else if (mIsWallpaper) { |
| 6644 | mAnimLayer += mWallpaperAnimLayerAdjustment; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6645 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6646 | if (DEBUG_LAYERS) Slog.v(TAG, "Stepping win " + this |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6647 | + " anim layer: " + mAnimLayer); |
| 6648 | mHasTransformation = false; |
| 6649 | mHasLocalTransformation = false; |
Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 6650 | if (mPolicyVisibility != mPolicyVisibilityAfterAnim) { |
| 6651 | if (DEBUG_VISIBILITY) { |
| 6652 | Slog.v(TAG, "Policy visibility changing after anim in " + this + ": " |
| 6653 | + mPolicyVisibilityAfterAnim); |
| 6654 | } |
| 6655 | mPolicyVisibility = mPolicyVisibilityAfterAnim; |
| 6656 | if (!mPolicyVisibility) { |
| 6657 | if (mCurrentFocus == this) { |
| 6658 | mFocusMayChange = true; |
| 6659 | } |
| 6660 | // Window is no longer visible -- make sure if we were waiting |
| 6661 | // for it to be displayed before enabling the display, that |
| 6662 | // we allow the display to be enabled now. |
| 6663 | enableScreenIfNeededLocked(); |
| 6664 | } |
Dianne Hackborn | f3bea9c | 2009-12-09 18:26:21 -0800 | [diff] [blame] | 6665 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6666 | mTransformation.clear(); |
| 6667 | if (mHasDrawn |
| 6668 | && mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING |
| 6669 | && mAppToken != null |
| 6670 | && mAppToken.firstWindowDrawn |
| 6671 | && mAppToken.startingData != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6672 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Finish starting " |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6673 | + mToken + ": first real window done animating"); |
| 6674 | mFinishedStarting.add(mAppToken); |
| 6675 | mH.sendEmptyMessage(H.FINISHED_STARTING); |
| 6676 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6677 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6678 | finishExit(); |
| 6679 | |
| 6680 | if (mAppToken != null) { |
| 6681 | mAppToken.updateReportedVisibilityLocked(); |
| 6682 | } |
| 6683 | |
| 6684 | return false; |
| 6685 | } |
| 6686 | |
| 6687 | void finishExit() { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6688 | if (DEBUG_ANIM) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6689 | TAG, "finishExit in " + this |
| 6690 | + ": exiting=" + mExiting |
| 6691 | + " remove=" + mRemoveOnExit |
| 6692 | + " windowAnimating=" + isWindowAnimating()); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6693 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6694 | final int N = mChildWindows.size(); |
| 6695 | for (int i=0; i<N; i++) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 6696 | mChildWindows.get(i).finishExit(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6697 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6698 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6699 | if (!mExiting) { |
| 6700 | return; |
| 6701 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6702 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6703 | if (isWindowAnimating()) { |
| 6704 | return; |
| 6705 | } |
| 6706 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6707 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6708 | TAG, "Exit animation finished in " + this |
| 6709 | + ": remove=" + mRemoveOnExit); |
| 6710 | if (mSurface != null) { |
| 6711 | mDestroySurface.add(this); |
| 6712 | mDestroying = true; |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 6713 | if (SHOW_TRANSACTIONS) logSurface(this, "HIDE (finishExit)", null); |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 6714 | mSurfaceShown = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6715 | try { |
| 6716 | mSurface.hide(); |
| 6717 | } catch (RuntimeException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6718 | Slog.w(TAG, "Error hiding surface in " + this, e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6719 | } |
| 6720 | mLastHidden = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6721 | } |
| 6722 | mExiting = false; |
| 6723 | if (mRemoveOnExit) { |
| 6724 | mPendingRemove.add(this); |
| 6725 | mRemoveOnExit = false; |
| 6726 | } |
| 6727 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6728 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6729 | boolean isIdentityMatrix(float dsdx, float dtdx, float dsdy, float dtdy) { |
| 6730 | if (dsdx < .99999f || dsdx > 1.00001f) return false; |
| 6731 | if (dtdy < .99999f || dtdy > 1.00001f) return false; |
| 6732 | if (dtdx < -.000001f || dtdx > .000001f) return false; |
| 6733 | if (dsdy < -.000001f || dsdy > .000001f) return false; |
| 6734 | return true; |
| 6735 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6736 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6737 | void computeShownFrameLocked() { |
| 6738 | final boolean selfTransformation = mHasLocalTransformation; |
| 6739 | Transformation attachedTransformation = |
| 6740 | (mAttachedWindow != null && mAttachedWindow.mHasLocalTransformation) |
| 6741 | ? mAttachedWindow.mTransformation : null; |
| 6742 | Transformation appTransformation = |
| 6743 | (mAppToken != null && mAppToken.hasTransformation) |
| 6744 | ? mAppToken.transformation : null; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6745 | |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 6746 | // Wallpapers are animated based on the "real" window they |
| 6747 | // are currently targeting. |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 6748 | if (mAttrs.type == TYPE_WALLPAPER && mLowerWallpaperTarget == null |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 6749 | && mWallpaperTarget != null) { |
Dianne Hackborn | 5baba16 | 2009-09-23 17:01:12 -0700 | [diff] [blame] | 6750 | if (mWallpaperTarget.mHasLocalTransformation && |
| 6751 | mWallpaperTarget.mAnimation != null && |
| 6752 | !mWallpaperTarget.mAnimation.getDetachWallpaper()) { |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 6753 | attachedTransformation = mWallpaperTarget.mTransformation; |
Dianne Hackborn | 5baba16 | 2009-09-23 17:01:12 -0700 | [diff] [blame] | 6754 | if (DEBUG_WALLPAPER && attachedTransformation != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6755 | Slog.v(TAG, "WP target attached xform: " + attachedTransformation); |
Dianne Hackborn | 5baba16 | 2009-09-23 17:01:12 -0700 | [diff] [blame] | 6756 | } |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 6757 | } |
| 6758 | if (mWallpaperTarget.mAppToken != null && |
Dianne Hackborn | 5baba16 | 2009-09-23 17:01:12 -0700 | [diff] [blame] | 6759 | mWallpaperTarget.mAppToken.hasTransformation && |
| 6760 | mWallpaperTarget.mAppToken.animation != null && |
| 6761 | !mWallpaperTarget.mAppToken.animation.getDetachWallpaper()) { |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 6762 | appTransformation = mWallpaperTarget.mAppToken.transformation; |
Dianne Hackborn | 5baba16 | 2009-09-23 17:01:12 -0700 | [diff] [blame] | 6763 | if (DEBUG_WALLPAPER && appTransformation != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6764 | Slog.v(TAG, "WP target app xform: " + appTransformation); |
Dianne Hackborn | 5baba16 | 2009-09-23 17:01:12 -0700 | [diff] [blame] | 6765 | } |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 6766 | } |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 6767 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6768 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6769 | if (selfTransformation || attachedTransformation != null |
| 6770 | || appTransformation != null) { |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6771 | // cache often used attributes locally |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6772 | final Rect frame = mFrame; |
| 6773 | final float tmpFloats[] = mTmpFloats; |
| 6774 | final Matrix tmpMatrix = mTmpMatrix; |
| 6775 | |
| 6776 | // Compute the desired transformation. |
Dianne Hackborn | 65c2387 | 2009-09-18 17:47:02 -0700 | [diff] [blame] | 6777 | tmpMatrix.setTranslate(0, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6778 | if (selfTransformation) { |
Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 6779 | tmpMatrix.postConcat(mTransformation.getMatrix()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6780 | } |
Dianne Hackborn | 65c2387 | 2009-09-18 17:47:02 -0700 | [diff] [blame] | 6781 | tmpMatrix.postTranslate(frame.left, frame.top); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6782 | if (attachedTransformation != null) { |
Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 6783 | tmpMatrix.postConcat(attachedTransformation.getMatrix()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6784 | } |
| 6785 | if (appTransformation != null) { |
Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 6786 | tmpMatrix.postConcat(appTransformation.getMatrix()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6787 | } |
| 6788 | |
| 6789 | // "convert" it into SurfaceFlinger's format |
| 6790 | // (a 2x2 matrix + an offset) |
| 6791 | // Here we must not transform the position of the surface |
| 6792 | // since it is already included in the transformation. |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6793 | //Slog.i(TAG, "Transform: " + matrix); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6794 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6795 | tmpMatrix.getValues(tmpFloats); |
| 6796 | mDsDx = tmpFloats[Matrix.MSCALE_X]; |
| 6797 | mDtDx = tmpFloats[Matrix.MSKEW_X]; |
| 6798 | mDsDy = tmpFloats[Matrix.MSKEW_Y]; |
| 6799 | mDtDy = tmpFloats[Matrix.MSCALE_Y]; |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 6800 | int x = (int)tmpFloats[Matrix.MTRANS_X] + mXOffset; |
| 6801 | int y = (int)tmpFloats[Matrix.MTRANS_Y] + mYOffset; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6802 | int w = frame.width(); |
| 6803 | int h = frame.height(); |
| 6804 | mShownFrame.set(x, y, x+w, y+h); |
| 6805 | |
| 6806 | // Now set the alpha... but because our current hardware |
| 6807 | // can't do alpha transformation on a non-opaque surface, |
| 6808 | // turn it off if we are running an animation that is also |
| 6809 | // transforming since it is more important to have that |
| 6810 | // animation be smooth. |
| 6811 | mShownAlpha = mAlpha; |
| 6812 | if (!mLimitedAlphaCompositing |
| 6813 | || (!PixelFormat.formatHasAlpha(mAttrs.format) |
| 6814 | || (isIdentityMatrix(mDsDx, mDtDx, mDsDy, mDtDy) |
| 6815 | && x == frame.left && y == frame.top))) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6816 | //Slog.i(TAG, "Applying alpha transform"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6817 | if (selfTransformation) { |
| 6818 | mShownAlpha *= mTransformation.getAlpha(); |
| 6819 | } |
| 6820 | if (attachedTransformation != null) { |
| 6821 | mShownAlpha *= attachedTransformation.getAlpha(); |
| 6822 | } |
| 6823 | if (appTransformation != null) { |
| 6824 | mShownAlpha *= appTransformation.getAlpha(); |
| 6825 | } |
| 6826 | } else { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6827 | //Slog.i(TAG, "Not applying alpha transform"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6828 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6829 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6830 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6831 | TAG, "Continuing animation in " + this + |
| 6832 | ": " + mShownFrame + |
| 6833 | ", alpha=" + mTransformation.getAlpha()); |
| 6834 | return; |
| 6835 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6836 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6837 | mShownFrame.set(mFrame); |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 6838 | if (mXOffset != 0 || mYOffset != 0) { |
| 6839 | mShownFrame.offset(mXOffset, mYOffset); |
| 6840 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6841 | mShownAlpha = mAlpha; |
| 6842 | mDsDx = 1; |
| 6843 | mDtDx = 0; |
| 6844 | mDsDy = 0; |
| 6845 | mDtDy = 1; |
| 6846 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6847 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6848 | /** |
| 6849 | * Is this window visible? It is not visible if there is no |
| 6850 | * surface, or we are in the process of running an exit animation |
| 6851 | * that will remove the surface, or its app token has been hidden. |
| 6852 | */ |
| 6853 | public boolean isVisibleLw() { |
| 6854 | final AppWindowToken atoken = mAppToken; |
| 6855 | return mSurface != null && mPolicyVisibility && !mAttachedHidden |
| 6856 | && (atoken == null || !atoken.hiddenRequested) |
| 6857 | && !mExiting && !mDestroying; |
| 6858 | } |
| 6859 | |
| 6860 | /** |
Dianne Hackborn | 3d163f07 | 2009-10-07 21:26:57 -0700 | [diff] [blame] | 6861 | * Like {@link #isVisibleLw}, but also counts a window that is currently |
| 6862 | * "hidden" behind the keyguard as visible. This allows us to apply |
| 6863 | * things like window flags that impact the keyguard. |
| 6864 | * XXX I am starting to think we need to have ANOTHER visibility flag |
| 6865 | * for this "hidden behind keyguard" state rather than overloading |
| 6866 | * mPolicyVisibility. Ungh. |
| 6867 | */ |
| 6868 | public boolean isVisibleOrBehindKeyguardLw() { |
| 6869 | final AppWindowToken atoken = mAppToken; |
| 6870 | return mSurface != null && !mAttachedHidden |
| 6871 | && (atoken == null ? mPolicyVisibility : !atoken.hiddenRequested) |
Dianne Hackborn | 5943c20 | 2010-04-12 21:36:49 -0700 | [diff] [blame] | 6872 | && (mOrientationChanging || (!mDrawPending && !mCommitDrawPending)) |
Dianne Hackborn | 3d163f07 | 2009-10-07 21:26:57 -0700 | [diff] [blame] | 6873 | && !mExiting && !mDestroying; |
| 6874 | } |
| 6875 | |
| 6876 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6877 | * Is this window visible, ignoring its app token? It is not visible |
| 6878 | * if there is no surface, or we are in the process of running an exit animation |
| 6879 | * that will remove the surface. |
| 6880 | */ |
| 6881 | public boolean isWinVisibleLw() { |
| 6882 | final AppWindowToken atoken = mAppToken; |
| 6883 | return mSurface != null && mPolicyVisibility && !mAttachedHidden |
| 6884 | && (atoken == null || !atoken.hiddenRequested || atoken.animating) |
| 6885 | && !mExiting && !mDestroying; |
| 6886 | } |
| 6887 | |
| 6888 | /** |
| 6889 | * The same as isVisible(), but follows the current hidden state of |
| 6890 | * the associated app token, not the pending requested hidden state. |
| 6891 | */ |
| 6892 | boolean isVisibleNow() { |
| 6893 | return mSurface != null && mPolicyVisibility && !mAttachedHidden |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 6894 | && !mRootToken.hidden && !mExiting && !mDestroying; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6895 | } |
| 6896 | |
| 6897 | /** |
| 6898 | * Same as isVisible(), but we also count it as visible between the |
| 6899 | * call to IWindowSession.add() and the first relayout(). |
| 6900 | */ |
| 6901 | boolean isVisibleOrAdding() { |
| 6902 | final AppWindowToken atoken = mAppToken; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 6903 | return ((mSurface != null && !mReportDestroySurface) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6904 | || (!mRelayoutCalled && mViewVisibility == View.VISIBLE)) |
| 6905 | && mPolicyVisibility && !mAttachedHidden |
| 6906 | && (atoken == null || !atoken.hiddenRequested) |
| 6907 | && !mExiting && !mDestroying; |
| 6908 | } |
| 6909 | |
| 6910 | /** |
| 6911 | * Is this window currently on-screen? It is on-screen either if it |
| 6912 | * is visible or it is currently running an animation before no longer |
| 6913 | * being visible. |
| 6914 | */ |
| 6915 | boolean isOnScreen() { |
| 6916 | final AppWindowToken atoken = mAppToken; |
| 6917 | if (atoken != null) { |
| 6918 | return mSurface != null && mPolicyVisibility && !mDestroying |
| 6919 | && ((!mAttachedHidden && !atoken.hiddenRequested) |
Dianne Hackborn | 0cd4887 | 2009-08-13 18:51:59 -0700 | [diff] [blame] | 6920 | || mAnimation != null || atoken.animation != null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6921 | } else { |
| 6922 | return mSurface != null && mPolicyVisibility && !mDestroying |
Dianne Hackborn | 0cd4887 | 2009-08-13 18:51:59 -0700 | [diff] [blame] | 6923 | && (!mAttachedHidden || mAnimation != null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6924 | } |
| 6925 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6926 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6927 | /** |
| 6928 | * Like isOnScreen(), but we don't return true if the window is part |
| 6929 | * of a transition that has not yet been started. |
| 6930 | */ |
| 6931 | boolean isReadyForDisplay() { |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 6932 | if (mRootToken.waitingToShow && |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 6933 | mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 6934 | return false; |
| 6935 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6936 | final AppWindowToken atoken = mAppToken; |
Dianne Hackborn | 0cd4887 | 2009-08-13 18:51:59 -0700 | [diff] [blame] | 6937 | final boolean animating = atoken != null |
| 6938 | ? (atoken.animation != null) : false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6939 | return mSurface != null && mPolicyVisibility && !mDestroying |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 6940 | && ((!mAttachedHidden && mViewVisibility == View.VISIBLE |
| 6941 | && !mRootToken.hidden) |
Dianne Hackborn | 0cd4887 | 2009-08-13 18:51:59 -0700 | [diff] [blame] | 6942 | || mAnimation != null || animating); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6943 | } |
| 6944 | |
| 6945 | /** Is the window or its container currently animating? */ |
| 6946 | boolean isAnimating() { |
| 6947 | final WindowState attached = mAttachedWindow; |
| 6948 | final AppWindowToken atoken = mAppToken; |
| 6949 | return mAnimation != null |
| 6950 | || (attached != null && attached.mAnimation != null) |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6951 | || (atoken != null && |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6952 | (atoken.animation != null |
| 6953 | || atoken.inPendingTransaction)); |
| 6954 | } |
| 6955 | |
| 6956 | /** Is this window currently animating? */ |
| 6957 | boolean isWindowAnimating() { |
| 6958 | return mAnimation != null; |
| 6959 | } |
| 6960 | |
| 6961 | /** |
| 6962 | * Like isOnScreen, but returns false if the surface hasn't yet |
| 6963 | * been drawn. |
| 6964 | */ |
| 6965 | public boolean isDisplayedLw() { |
| 6966 | final AppWindowToken atoken = mAppToken; |
| 6967 | return mSurface != null && mPolicyVisibility && !mDestroying |
| 6968 | && !mDrawPending && !mCommitDrawPending |
| 6969 | && ((!mAttachedHidden && |
| 6970 | (atoken == null || !atoken.hiddenRequested)) |
| 6971 | || mAnimating); |
| 6972 | } |
| 6973 | |
Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 6974 | /** |
| 6975 | * Returns true if the window has a surface that it has drawn a |
Dianne Hackborn | 5943c20 | 2010-04-12 21:36:49 -0700 | [diff] [blame] | 6976 | * complete UI in to. Note that this returns true if the orientation |
| 6977 | * is changing even if the window hasn't redrawn because we don't want |
| 6978 | * to stop things from executing during that time. |
Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 6979 | */ |
| 6980 | public boolean isDrawnLw() { |
| 6981 | final AppWindowToken atoken = mAppToken; |
| 6982 | return mSurface != null && !mDestroying |
Dianne Hackborn | 5943c20 | 2010-04-12 21:36:49 -0700 | [diff] [blame] | 6983 | && (mOrientationChanging || (!mDrawPending && !mCommitDrawPending)); |
Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 6984 | } |
| 6985 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6986 | public boolean fillsScreenLw(int screenWidth, int screenHeight, |
| 6987 | boolean shownFrame, boolean onlyOpaque) { |
| 6988 | if (mSurface == null) { |
| 6989 | return false; |
| 6990 | } |
| 6991 | if (mAppToken != null && !mAppToken.appFullscreen) { |
| 6992 | return false; |
| 6993 | } |
| 6994 | if (onlyOpaque && mAttrs.format != PixelFormat.OPAQUE) { |
| 6995 | return false; |
| 6996 | } |
| 6997 | final Rect frame = shownFrame ? mShownFrame : mFrame; |
Mitsuru Oshima | d2967e2 | 2009-07-20 14:01:43 -0700 | [diff] [blame] | 6998 | |
| 6999 | if ((mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0) { |
| 7000 | return frame.left <= mCompatibleScreenFrame.left && |
| 7001 | frame.top <= mCompatibleScreenFrame.top && |
| 7002 | frame.right >= mCompatibleScreenFrame.right && |
| 7003 | frame.bottom >= mCompatibleScreenFrame.bottom; |
| 7004 | } else { |
| 7005 | return frame.left <= 0 && frame.top <= 0 |
| 7006 | && frame.right >= screenWidth |
| 7007 | && frame.bottom >= screenHeight; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7008 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7009 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7010 | |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 7011 | /** |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 7012 | * Return true if the window is opaque and fully drawn. This indicates |
| 7013 | * it may obscure windows behind it. |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 7014 | */ |
| 7015 | boolean isOpaqueDrawn() { |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 7016 | return (mAttrs.format == PixelFormat.OPAQUE |
| 7017 | || mAttrs.type == TYPE_WALLPAPER) |
| 7018 | && mSurface != null && mAnimation == null |
| 7019 | && (mAppToken == null || mAppToken.animation == null) |
| 7020 | && !mDrawPending && !mCommitDrawPending; |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 7021 | } |
| 7022 | |
| 7023 | boolean needsBackgroundFiller(int screenWidth, int screenHeight) { |
| 7024 | return |
| 7025 | // only if the application is requesting compatible window |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 7026 | (mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0 && |
| 7027 | // only if it's visible |
| 7028 | mHasDrawn && mViewVisibility == View.VISIBLE && |
Mitsuru Oshima | d2967e2 | 2009-07-20 14:01:43 -0700 | [diff] [blame] | 7029 | // and only if the application fills the compatible screen |
| 7030 | mFrame.left <= mCompatibleScreenFrame.left && |
| 7031 | mFrame.top <= mCompatibleScreenFrame.top && |
| 7032 | mFrame.right >= mCompatibleScreenFrame.right && |
| 7033 | mFrame.bottom >= mCompatibleScreenFrame.bottom && |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 7034 | // and starting window do not need background filler |
Mitsuru Oshima | d2967e2 | 2009-07-20 14:01:43 -0700 | [diff] [blame] | 7035 | mAttrs.type != mAttrs.TYPE_APPLICATION_STARTING; |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 7036 | } |
| 7037 | |
| 7038 | boolean isFullscreen(int screenWidth, int screenHeight) { |
| 7039 | return mFrame.left <= 0 && mFrame.top <= 0 && |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 7040 | mFrame.right >= screenWidth && mFrame.bottom >= screenHeight; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7041 | } |
| 7042 | |
| 7043 | void removeLocked() { |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 7044 | disposeInputChannel(); |
| 7045 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7046 | if (mAttachedWindow != null) { |
| 7047 | mAttachedWindow.mChildWindows.remove(this); |
| 7048 | } |
| 7049 | destroySurfaceLocked(); |
| 7050 | mSession.windowRemovedLocked(); |
| 7051 | try { |
| 7052 | mClient.asBinder().unlinkToDeath(mDeathRecipient, 0); |
| 7053 | } catch (RuntimeException e) { |
| 7054 | // Ignore if it has already been removed (usually because |
| 7055 | // we are doing this as part of processing a death note.) |
| 7056 | } |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 7057 | } |
| 7058 | |
| 7059 | void disposeInputChannel() { |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 7060 | if (mInputChannel != null) { |
| 7061 | mInputManager.unregisterInputChannel(mInputChannel); |
| 7062 | |
| 7063 | mInputChannel.dispose(); |
| 7064 | mInputChannel = null; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 7065 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7066 | } |
| 7067 | |
| 7068 | private class DeathRecipient implements IBinder.DeathRecipient { |
| 7069 | public void binderDied() { |
| 7070 | try { |
| 7071 | synchronized(mWindowMap) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 7072 | WindowState win = windowForClientLocked(mSession, mClient, false); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7073 | Slog.i(TAG, "WIN DEATH: " + win); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7074 | if (win != null) { |
| 7075 | removeWindowLocked(mSession, win); |
| 7076 | } |
| 7077 | } |
| 7078 | } catch (IllegalArgumentException ex) { |
| 7079 | // This will happen if the window has already been |
| 7080 | // removed. |
| 7081 | } |
| 7082 | } |
| 7083 | } |
| 7084 | |
| 7085 | /** Returns true if this window desires key events. */ |
| 7086 | public final boolean canReceiveKeys() { |
| 7087 | return isVisibleOrAdding() |
| 7088 | && (mViewVisibility == View.VISIBLE) |
| 7089 | && ((mAttrs.flags & WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) == 0); |
| 7090 | } |
| 7091 | |
| 7092 | public boolean hasDrawnLw() { |
| 7093 | return mHasDrawn; |
| 7094 | } |
| 7095 | |
| 7096 | public boolean showLw(boolean doAnimation) { |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 7097 | return showLw(doAnimation, true); |
| 7098 | } |
| 7099 | |
| 7100 | boolean showLw(boolean doAnimation, boolean requestAnim) { |
| 7101 | if (mPolicyVisibility && mPolicyVisibilityAfterAnim) { |
| 7102 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7103 | } |
Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 7104 | if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility true: " + this); |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 7105 | if (doAnimation) { |
| 7106 | if (DEBUG_VISIBILITY) Slog.v(TAG, "doAnimation: mPolicyVisibility=" |
| 7107 | + mPolicyVisibility + " mAnimation=" + mAnimation); |
| 7108 | if (mDisplayFrozen || !mPolicy.isScreenOn()) { |
| 7109 | doAnimation = false; |
| 7110 | } else if (mPolicyVisibility && mAnimation == null) { |
| 7111 | // Check for the case where we are currently visible and |
| 7112 | // not animating; we do not want to do animation at such a |
| 7113 | // point to become visible when we already are. |
| 7114 | doAnimation = false; |
| 7115 | } |
| 7116 | } |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 7117 | mPolicyVisibility = true; |
| 7118 | mPolicyVisibilityAfterAnim = true; |
| 7119 | if (doAnimation) { |
| 7120 | applyAnimationLocked(this, WindowManagerPolicy.TRANSIT_ENTER, true); |
| 7121 | } |
| 7122 | if (requestAnim) { |
| 7123 | requestAnimationLocked(0); |
| 7124 | } |
| 7125 | return true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7126 | } |
| 7127 | |
| 7128 | public boolean hideLw(boolean doAnimation) { |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 7129 | return hideLw(doAnimation, true); |
| 7130 | } |
| 7131 | |
| 7132 | boolean hideLw(boolean doAnimation, boolean requestAnim) { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 7133 | if (doAnimation) { |
| 7134 | if (mDisplayFrozen || !mPolicy.isScreenOn()) { |
| 7135 | doAnimation = false; |
| 7136 | } |
| 7137 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7138 | boolean current = doAnimation ? mPolicyVisibilityAfterAnim |
| 7139 | : mPolicyVisibility; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 7140 | if (!current) { |
| 7141 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7142 | } |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 7143 | if (doAnimation) { |
| 7144 | applyAnimationLocked(this, WindowManagerPolicy.TRANSIT_EXIT, false); |
| 7145 | if (mAnimation == null) { |
| 7146 | doAnimation = false; |
| 7147 | } |
| 7148 | } |
| 7149 | if (doAnimation) { |
| 7150 | mPolicyVisibilityAfterAnim = false; |
| 7151 | } else { |
Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 7152 | if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility false: " + this); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 7153 | mPolicyVisibilityAfterAnim = false; |
| 7154 | mPolicyVisibility = false; |
Dianne Hackborn | f3bea9c | 2009-12-09 18:26:21 -0800 | [diff] [blame] | 7155 | // Window is no longer visible -- make sure if we were waiting |
| 7156 | // for it to be displayed before enabling the display, that |
| 7157 | // we allow the display to be enabled now. |
| 7158 | enableScreenIfNeededLocked(); |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 7159 | if (mCurrentFocus == this) { |
| 7160 | mFocusMayChange = true; |
| 7161 | } |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 7162 | } |
| 7163 | if (requestAnim) { |
| 7164 | requestAnimationLocked(0); |
| 7165 | } |
| 7166 | return true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7167 | } |
| 7168 | |
| 7169 | void dump(PrintWriter pw, String prefix) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7170 | pw.print(prefix); pw.print("mSession="); pw.print(mSession); |
| 7171 | pw.print(" mClient="); pw.println(mClient.asBinder()); |
| 7172 | pw.print(prefix); pw.print("mAttrs="); pw.println(mAttrs); |
| 7173 | if (mAttachedWindow != null || mLayoutAttached) { |
| 7174 | pw.print(prefix); pw.print("mAttachedWindow="); pw.print(mAttachedWindow); |
| 7175 | pw.print(" mLayoutAttached="); pw.println(mLayoutAttached); |
| 7176 | } |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 7177 | if (mIsImWindow || mIsWallpaper || mIsFloatingLayer) { |
| 7178 | pw.print(prefix); pw.print("mIsImWindow="); pw.print(mIsImWindow); |
| 7179 | pw.print(" mIsWallpaper="); pw.print(mIsWallpaper); |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 7180 | pw.print(" mIsFloatingLayer="); pw.print(mIsFloatingLayer); |
| 7181 | pw.print(" mWallpaperVisible="); pw.println(mWallpaperVisible); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7182 | } |
| 7183 | pw.print(prefix); pw.print("mBaseLayer="); pw.print(mBaseLayer); |
| 7184 | pw.print(" mSubLayer="); pw.print(mSubLayer); |
| 7185 | pw.print(" mAnimLayer="); pw.print(mLayer); pw.print("+"); |
| 7186 | pw.print((mTargetAppToken != null ? mTargetAppToken.animLayerAdjustment |
| 7187 | : (mAppToken != null ? mAppToken.animLayerAdjustment : 0))); |
| 7188 | pw.print("="); pw.print(mAnimLayer); |
| 7189 | pw.print(" mLastLayer="); pw.println(mLastLayer); |
| 7190 | if (mSurface != null) { |
| 7191 | pw.print(prefix); pw.print("mSurface="); pw.println(mSurface); |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 7192 | pw.print(prefix); pw.print("Surface: shown="); pw.print(mSurfaceShown); |
| 7193 | pw.print(" layer="); pw.print(mSurfaceLayer); |
| 7194 | pw.print(" alpha="); pw.print(mSurfaceAlpha); |
| 7195 | pw.print(" rect=("); pw.print(mSurfaceX); |
| 7196 | pw.print(","); pw.print(mSurfaceY); |
| 7197 | pw.print(") "); pw.print(mSurfaceW); |
| 7198 | pw.print(" x "); pw.println(mSurfaceH); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7199 | } |
| 7200 | pw.print(prefix); pw.print("mToken="); pw.println(mToken); |
| 7201 | pw.print(prefix); pw.print("mRootToken="); pw.println(mRootToken); |
| 7202 | if (mAppToken != null) { |
| 7203 | pw.print(prefix); pw.print("mAppToken="); pw.println(mAppToken); |
| 7204 | } |
| 7205 | if (mTargetAppToken != null) { |
| 7206 | pw.print(prefix); pw.print("mTargetAppToken="); pw.println(mTargetAppToken); |
| 7207 | } |
| 7208 | pw.print(prefix); pw.print("mViewVisibility=0x"); |
| 7209 | pw.print(Integer.toHexString(mViewVisibility)); |
| 7210 | pw.print(" mLastHidden="); pw.print(mLastHidden); |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 7211 | pw.print(" mHaveFrame="); pw.print(mHaveFrame); |
| 7212 | pw.print(" mObscured="); pw.println(mObscured); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7213 | if (!mPolicyVisibility || !mPolicyVisibilityAfterAnim || mAttachedHidden) { |
| 7214 | pw.print(prefix); pw.print("mPolicyVisibility="); |
| 7215 | pw.print(mPolicyVisibility); |
| 7216 | pw.print(" mPolicyVisibilityAfterAnim="); |
| 7217 | pw.print(mPolicyVisibilityAfterAnim); |
| 7218 | pw.print(" mAttachedHidden="); pw.println(mAttachedHidden); |
| 7219 | } |
Dianne Hackborn | 9b52a21 | 2009-12-11 14:51:35 -0800 | [diff] [blame] | 7220 | if (!mRelayoutCalled) { |
| 7221 | pw.print(prefix); pw.print("mRelayoutCalled="); pw.println(mRelayoutCalled); |
| 7222 | } |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7223 | pw.print(prefix); pw.print("Requested w="); pw.print(mRequestedWidth); |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 7224 | pw.print(" h="); pw.print(mRequestedHeight); |
| 7225 | pw.print(" mLayoutSeq="); pw.println(mLayoutSeq); |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 7226 | if (mXOffset != 0 || mYOffset != 0) { |
| 7227 | pw.print(prefix); pw.print("Offsets x="); pw.print(mXOffset); |
| 7228 | pw.print(" y="); pw.println(mYOffset); |
| 7229 | } |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7230 | pw.print(prefix); pw.print("mGivenContentInsets="); |
| 7231 | mGivenContentInsets.printShortString(pw); |
| 7232 | pw.print(" mGivenVisibleInsets="); |
| 7233 | mGivenVisibleInsets.printShortString(pw); |
| 7234 | pw.println(); |
| 7235 | if (mTouchableInsets != 0 || mGivenInsetsPending) { |
| 7236 | pw.print(prefix); pw.print("mTouchableInsets="); pw.print(mTouchableInsets); |
| 7237 | pw.print(" mGivenInsetsPending="); pw.println(mGivenInsetsPending); |
| 7238 | } |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 7239 | pw.print(prefix); pw.print("mConfiguration="); pw.println(mConfiguration); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7240 | pw.print(prefix); pw.print("mShownFrame="); |
| 7241 | mShownFrame.printShortString(pw); |
| 7242 | pw.print(" last="); mLastShownFrame.printShortString(pw); |
| 7243 | pw.println(); |
| 7244 | pw.print(prefix); pw.print("mFrame="); mFrame.printShortString(pw); |
| 7245 | pw.print(" last="); mLastFrame.printShortString(pw); |
| 7246 | pw.println(); |
| 7247 | pw.print(prefix); pw.print("mContainingFrame="); |
| 7248 | mContainingFrame.printShortString(pw); |
| 7249 | pw.print(" mDisplayFrame="); |
| 7250 | mDisplayFrame.printShortString(pw); |
| 7251 | pw.println(); |
| 7252 | pw.print(prefix); pw.print("mContentFrame="); mContentFrame.printShortString(pw); |
| 7253 | pw.print(" mVisibleFrame="); mVisibleFrame.printShortString(pw); |
| 7254 | pw.println(); |
| 7255 | pw.print(prefix); pw.print("mContentInsets="); mContentInsets.printShortString(pw); |
| 7256 | pw.print(" last="); mLastContentInsets.printShortString(pw); |
| 7257 | pw.print(" mVisibleInsets="); mVisibleInsets.printShortString(pw); |
| 7258 | pw.print(" last="); mLastVisibleInsets.printShortString(pw); |
| 7259 | pw.println(); |
| 7260 | if (mShownAlpha != 1 || mAlpha != 1 || mLastAlpha != 1) { |
| 7261 | pw.print(prefix); pw.print("mShownAlpha="); pw.print(mShownAlpha); |
| 7262 | pw.print(" mAlpha="); pw.print(mAlpha); |
| 7263 | pw.print(" mLastAlpha="); pw.println(mLastAlpha); |
| 7264 | } |
| 7265 | if (mAnimating || mLocalAnimating || mAnimationIsEntrance |
| 7266 | || mAnimation != null) { |
| 7267 | pw.print(prefix); pw.print("mAnimating="); pw.print(mAnimating); |
| 7268 | pw.print(" mLocalAnimating="); pw.print(mLocalAnimating); |
| 7269 | pw.print(" mAnimationIsEntrance="); pw.print(mAnimationIsEntrance); |
| 7270 | pw.print(" mAnimation="); pw.println(mAnimation); |
| 7271 | } |
| 7272 | if (mHasTransformation || mHasLocalTransformation) { |
| 7273 | pw.print(prefix); pw.print("XForm: has="); |
| 7274 | pw.print(mHasTransformation); |
| 7275 | pw.print(" hasLocal="); pw.print(mHasLocalTransformation); |
| 7276 | pw.print(" "); mTransformation.printShortString(pw); |
| 7277 | pw.println(); |
| 7278 | } |
| 7279 | pw.print(prefix); pw.print("mDrawPending="); pw.print(mDrawPending); |
| 7280 | pw.print(" mCommitDrawPending="); pw.print(mCommitDrawPending); |
| 7281 | pw.print(" mReadyToShow="); pw.print(mReadyToShow); |
| 7282 | pw.print(" mHasDrawn="); pw.println(mHasDrawn); |
| 7283 | if (mExiting || mRemoveOnExit || mDestroying || mRemoved) { |
| 7284 | pw.print(prefix); pw.print("mExiting="); pw.print(mExiting); |
| 7285 | pw.print(" mRemoveOnExit="); pw.print(mRemoveOnExit); |
| 7286 | pw.print(" mDestroying="); pw.print(mDestroying); |
| 7287 | pw.print(" mRemoved="); pw.println(mRemoved); |
| 7288 | } |
Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 7289 | if (mOrientationChanging || mAppFreezing || mTurnOnScreen) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7290 | pw.print(prefix); pw.print("mOrientationChanging="); |
| 7291 | pw.print(mOrientationChanging); |
Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 7292 | pw.print(" mAppFreezing="); pw.print(mAppFreezing); |
| 7293 | pw.print(" mTurnOnScreen="); pw.println(mTurnOnScreen); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7294 | } |
Mitsuru Oshima | 589cebe | 2009-07-22 20:38:58 -0700 | [diff] [blame] | 7295 | if (mHScale != 1 || mVScale != 1) { |
| 7296 | pw.print(prefix); pw.print("mHScale="); pw.print(mHScale); |
| 7297 | pw.print(" mVScale="); pw.println(mVScale); |
| 7298 | } |
Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 7299 | if (mWallpaperX != -1 || mWallpaperY != -1) { |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 7300 | pw.print(prefix); pw.print("mWallpaperX="); pw.print(mWallpaperX); |
| 7301 | pw.print(" mWallpaperY="); pw.println(mWallpaperY); |
| 7302 | } |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 7303 | if (mWallpaperXStep != -1 || mWallpaperYStep != -1) { |
| 7304 | pw.print(prefix); pw.print("mWallpaperXStep="); pw.print(mWallpaperXStep); |
| 7305 | pw.print(" mWallpaperYStep="); pw.println(mWallpaperYStep); |
| 7306 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7307 | } |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 7308 | |
| 7309 | String makeInputChannelName() { |
| 7310 | return Integer.toHexString(System.identityHashCode(this)) |
| 7311 | + " " + mAttrs.getTitle(); |
| 7312 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7313 | |
| 7314 | @Override |
| 7315 | public String toString() { |
| 7316 | return "Window{" |
| 7317 | + Integer.toHexString(System.identityHashCode(this)) |
| 7318 | + " " + mAttrs.getTitle() + " paused=" + mToken.paused + "}"; |
| 7319 | } |
| 7320 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7321 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7322 | // ------------------------------------------------------------- |
| 7323 | // Window Token State |
| 7324 | // ------------------------------------------------------------- |
| 7325 | |
| 7326 | class WindowToken { |
| 7327 | // The actual token. |
| 7328 | final IBinder token; |
| 7329 | |
| 7330 | // The type of window this token is for, as per WindowManager.LayoutParams. |
| 7331 | final int windowType; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7332 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7333 | // Set if this token was explicitly added by a client, so should |
| 7334 | // not be removed when all windows are removed. |
| 7335 | final boolean explicit; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7336 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7337 | // For printing. |
| 7338 | String stringName; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7339 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7340 | // If this is an AppWindowToken, this is non-null. |
| 7341 | AppWindowToken appWindowToken; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7342 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7343 | // All of the windows associated with this token. |
| 7344 | final ArrayList<WindowState> windows = new ArrayList<WindowState>(); |
| 7345 | |
| 7346 | // Is key dispatching paused for this token? |
| 7347 | boolean paused = false; |
| 7348 | |
| 7349 | // Should this token's windows be hidden? |
| 7350 | boolean hidden; |
| 7351 | |
| 7352 | // Temporary for finding which tokens no longer have visible windows. |
| 7353 | boolean hasVisible; |
| 7354 | |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 7355 | // Set to true when this token is in a pending transaction where it |
| 7356 | // will be shown. |
| 7357 | boolean waitingToShow; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7358 | |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 7359 | // Set to true when this token is in a pending transaction where it |
| 7360 | // will be hidden. |
| 7361 | boolean waitingToHide; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7362 | |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 7363 | // Set to true when this token is in a pending transaction where its |
| 7364 | // windows will be put to the bottom of the list. |
| 7365 | boolean sendingToBottom; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7366 | |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 7367 | // Set to true when this token is in a pending transaction where its |
| 7368 | // windows will be put to the top of the list. |
| 7369 | boolean sendingToTop; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7370 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7371 | WindowToken(IBinder _token, int type, boolean _explicit) { |
| 7372 | token = _token; |
| 7373 | windowType = type; |
| 7374 | explicit = _explicit; |
| 7375 | } |
| 7376 | |
| 7377 | void dump(PrintWriter pw, String prefix) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7378 | pw.print(prefix); pw.print("token="); pw.println(token); |
| 7379 | pw.print(prefix); pw.print("windows="); pw.println(windows); |
| 7380 | pw.print(prefix); pw.print("windowType="); pw.print(windowType); |
| 7381 | pw.print(" hidden="); pw.print(hidden); |
| 7382 | pw.print(" hasVisible="); pw.println(hasVisible); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 7383 | if (waitingToShow || waitingToHide || sendingToBottom || sendingToTop) { |
| 7384 | pw.print(prefix); pw.print("waitingToShow="); pw.print(waitingToShow); |
| 7385 | pw.print(" waitingToHide="); pw.print(waitingToHide); |
| 7386 | pw.print(" sendingToBottom="); pw.print(sendingToBottom); |
| 7387 | pw.print(" sendingToTop="); pw.println(sendingToTop); |
| 7388 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7389 | } |
| 7390 | |
| 7391 | @Override |
| 7392 | public String toString() { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7393 | if (stringName == null) { |
| 7394 | StringBuilder sb = new StringBuilder(); |
| 7395 | sb.append("WindowToken{"); |
| 7396 | sb.append(Integer.toHexString(System.identityHashCode(this))); |
| 7397 | sb.append(" token="); sb.append(token); sb.append('}'); |
| 7398 | stringName = sb.toString(); |
| 7399 | } |
| 7400 | return stringName; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7401 | } |
| 7402 | }; |
| 7403 | |
| 7404 | class AppWindowToken extends WindowToken { |
| 7405 | // Non-null only for application tokens. |
| 7406 | final IApplicationToken appToken; |
| 7407 | |
| 7408 | // All of the windows and child windows that are included in this |
| 7409 | // application token. Note this list is NOT sorted! |
| 7410 | final ArrayList<WindowState> allAppWindows = new ArrayList<WindowState>(); |
| 7411 | |
| 7412 | int groupId = -1; |
| 7413 | boolean appFullscreen; |
| 7414 | int requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 7415 | |
| 7416 | // The input dispatching timeout for this application token in nanoseconds. |
| 7417 | long inputDispatchingTimeoutNanos; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7418 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7419 | // These are used for determining when all windows associated with |
| 7420 | // an activity have been drawn, so they can be made visible together |
| 7421 | // at the same time. |
| 7422 | int lastTransactionSequence = mTransactionSequence-1; |
| 7423 | int numInterestingWindows; |
| 7424 | int numDrawnWindows; |
| 7425 | boolean inPendingTransaction; |
| 7426 | boolean allDrawn; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7427 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7428 | // Is this token going to be hidden in a little while? If so, it |
| 7429 | // won't be taken into account for setting the screen orientation. |
| 7430 | boolean willBeHidden; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7431 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7432 | // Is this window's surface needed? This is almost like hidden, except |
| 7433 | // it will sometimes be true a little earlier: when the token has |
| 7434 | // been shown, but is still waiting for its app transition to execute |
| 7435 | // before making its windows shown. |
| 7436 | boolean hiddenRequested; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7437 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7438 | // Have we told the window clients to hide themselves? |
| 7439 | boolean clientHidden; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7440 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7441 | // Last visibility state we reported to the app token. |
| 7442 | boolean reportedVisible; |
| 7443 | |
| 7444 | // Set to true when the token has been removed from the window mgr. |
| 7445 | boolean removed; |
| 7446 | |
| 7447 | // Have we been asked to have this token keep the screen frozen? |
| 7448 | boolean freezingScreen; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7449 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7450 | boolean animating; |
| 7451 | Animation animation; |
| 7452 | boolean hasTransformation; |
| 7453 | final Transformation transformation = new Transformation(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7454 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7455 | // Offset to the window of all layers in the token, for use by |
| 7456 | // AppWindowToken animations. |
| 7457 | int animLayerAdjustment; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7458 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7459 | // Information about an application starting window if displayed. |
| 7460 | StartingData startingData; |
| 7461 | WindowState startingWindow; |
| 7462 | View startingView; |
| 7463 | boolean startingDisplayed; |
| 7464 | boolean startingMoved; |
| 7465 | boolean firstWindowDrawn; |
| 7466 | |
| 7467 | AppWindowToken(IApplicationToken _token) { |
| 7468 | super(_token.asBinder(), |
| 7469 | WindowManager.LayoutParams.TYPE_APPLICATION, true); |
| 7470 | appWindowToken = this; |
| 7471 | appToken = _token; |
| 7472 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7473 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7474 | public void setAnimation(Animation anim) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7475 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7476 | TAG, "Setting animation in " + this + ": " + anim); |
| 7477 | animation = anim; |
| 7478 | animating = false; |
| 7479 | anim.restrictDuration(MAX_ANIMATION_DURATION); |
| 7480 | anim.scaleCurrentDuration(mTransitionAnimationScale); |
| 7481 | int zorder = anim.getZAdjustment(); |
| 7482 | int adj = 0; |
| 7483 | if (zorder == Animation.ZORDER_TOP) { |
| 7484 | adj = TYPE_LAYER_OFFSET; |
| 7485 | } else if (zorder == Animation.ZORDER_BOTTOM) { |
| 7486 | adj = -TYPE_LAYER_OFFSET; |
| 7487 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7488 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7489 | if (animLayerAdjustment != adj) { |
| 7490 | animLayerAdjustment = adj; |
| 7491 | updateLayers(); |
| 7492 | } |
| 7493 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7494 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7495 | public void setDummyAnimation() { |
| 7496 | if (animation == null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7497 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7498 | TAG, "Setting dummy animation in " + this); |
| 7499 | animation = sDummyAnimation; |
| 7500 | } |
| 7501 | } |
| 7502 | |
| 7503 | public void clearAnimation() { |
| 7504 | if (animation != null) { |
| 7505 | animation = null; |
| 7506 | animating = true; |
| 7507 | } |
| 7508 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7509 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7510 | void updateLayers() { |
| 7511 | final int N = allAppWindows.size(); |
| 7512 | final int adj = animLayerAdjustment; |
| 7513 | for (int i=0; i<N; i++) { |
| 7514 | WindowState w = allAppWindows.get(i); |
| 7515 | w.mAnimLayer = w.mLayer + adj; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7516 | if (DEBUG_LAYERS) Slog.v(TAG, "Updating layer " + w + ": " |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7517 | + w.mAnimLayer); |
| 7518 | if (w == mInputMethodTarget) { |
| 7519 | setInputMethodAnimLayerAdjustment(adj); |
| 7520 | } |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 7521 | if (w == mWallpaperTarget && mLowerWallpaperTarget == null) { |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 7522 | setWallpaperAnimLayerAdjustmentLocked(adj); |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 7523 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7524 | } |
| 7525 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7526 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7527 | void sendAppVisibilityToClients() { |
| 7528 | final int N = allAppWindows.size(); |
| 7529 | for (int i=0; i<N; i++) { |
| 7530 | WindowState win = allAppWindows.get(i); |
| 7531 | if (win == startingWindow && clientHidden) { |
| 7532 | // Don't hide the starting window. |
| 7533 | continue; |
| 7534 | } |
| 7535 | try { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7536 | if (DEBUG_VISIBILITY) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7537 | "Setting visibility of " + win + ": " + (!clientHidden)); |
| 7538 | win.mClient.dispatchAppVisibility(!clientHidden); |
| 7539 | } catch (RemoteException e) { |
| 7540 | } |
| 7541 | } |
| 7542 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7543 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7544 | void showAllWindowsLocked() { |
| 7545 | final int NW = allAppWindows.size(); |
| 7546 | for (int i=0; i<NW; i++) { |
| 7547 | WindowState w = allAppWindows.get(i); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7548 | if (DEBUG_VISIBILITY) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7549 | "performing show on: " + w); |
| 7550 | w.performShowLocked(); |
| 7551 | } |
| 7552 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7553 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7554 | // This must be called while inside a transaction. |
| 7555 | boolean stepAnimationLocked(long currentTime, int dw, int dh) { |
Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 7556 | if (!mDisplayFrozen && mPolicy.isScreenOn()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7557 | // We will run animations as long as the display isn't frozen. |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7558 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7559 | if (animation == sDummyAnimation) { |
| 7560 | // This guy is going to animate, but not yet. For now count |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 7561 | // it as not animating for purposes of scheduling transactions; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7562 | // when it is really time to animate, this will be set to |
| 7563 | // a real animation and the next call will execute normally. |
| 7564 | return false; |
| 7565 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7566 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7567 | if ((allDrawn || animating || startingDisplayed) && animation != null) { |
| 7568 | if (!animating) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7569 | if (DEBUG_ANIM) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7570 | TAG, "Starting animation in " + this + |
| 7571 | " @ " + currentTime + ": dw=" + dw + " dh=" + dh |
| 7572 | + " scale=" + mTransitionAnimationScale |
| 7573 | + " allDrawn=" + allDrawn + " animating=" + animating); |
| 7574 | animation.initialize(dw, dh, dw, dh); |
| 7575 | animation.setStartTime(currentTime); |
| 7576 | animating = true; |
| 7577 | } |
| 7578 | transformation.clear(); |
| 7579 | final boolean more = animation.getTransformation( |
| 7580 | currentTime, transformation); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7581 | if (DEBUG_ANIM) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7582 | TAG, "Stepped animation in " + this + |
| 7583 | ": more=" + more + ", xform=" + transformation); |
| 7584 | if (more) { |
| 7585 | // we're done! |
| 7586 | hasTransformation = true; |
| 7587 | return true; |
| 7588 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7589 | if (DEBUG_ANIM) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7590 | TAG, "Finished animation in " + this + |
| 7591 | " @ " + currentTime); |
| 7592 | animation = null; |
| 7593 | } |
| 7594 | } else if (animation != null) { |
| 7595 | // If the display is frozen, and there is a pending animation, |
| 7596 | // clear it and make sure we run the cleanup code. |
| 7597 | animating = true; |
| 7598 | animation = null; |
| 7599 | } |
| 7600 | |
| 7601 | hasTransformation = false; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7602 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7603 | if (!animating) { |
| 7604 | return false; |
| 7605 | } |
| 7606 | |
| 7607 | clearAnimation(); |
| 7608 | animating = false; |
| 7609 | if (mInputMethodTarget != null && mInputMethodTarget.mAppToken == this) { |
| 7610 | moveInputMethodWindowsIfNeededLocked(true); |
| 7611 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7612 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7613 | if (DEBUG_ANIM) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7614 | TAG, "Animation done in " + this |
| 7615 | + ": reportedVisible=" + reportedVisible); |
| 7616 | |
| 7617 | transformation.clear(); |
| 7618 | if (animLayerAdjustment != 0) { |
| 7619 | animLayerAdjustment = 0; |
| 7620 | updateLayers(); |
| 7621 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7622 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7623 | final int N = windows.size(); |
| 7624 | for (int i=0; i<N; i++) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 7625 | windows.get(i).finishExit(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7626 | } |
| 7627 | updateReportedVisibilityLocked(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7628 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7629 | return false; |
| 7630 | } |
| 7631 | |
| 7632 | void updateReportedVisibilityLocked() { |
| 7633 | if (appToken == null) { |
| 7634 | return; |
| 7635 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7636 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7637 | int numInteresting = 0; |
| 7638 | int numVisible = 0; |
| 7639 | boolean nowGone = true; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7640 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7641 | 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] | 7642 | final int N = allAppWindows.size(); |
| 7643 | for (int i=0; i<N; i++) { |
| 7644 | WindowState win = allAppWindows.get(i); |
Dianne Hackborn | 6cf67fa | 2009-12-21 16:46:34 -0800 | [diff] [blame] | 7645 | if (win == startingWindow || win.mAppFreezing |
The Android Open Source Project | 727cec0 | 2010-04-08 11:35:37 -0700 | [diff] [blame] | 7646 | || win.mViewVisibility != View.VISIBLE |
| 7647 | || win.mAttrs.type == TYPE_APPLICATION_STARTING) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7648 | continue; |
| 7649 | } |
| 7650 | if (DEBUG_VISIBILITY) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7651 | Slog.v(TAG, "Win " + win + ": isDrawn=" |
Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 7652 | + win.isDrawnLw() |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7653 | + ", isAnimating=" + win.isAnimating()); |
Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 7654 | if (!win.isDrawnLw()) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7655 | Slog.v(TAG, "Not displayed: s=" + win.mSurface |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7656 | + " pv=" + win.mPolicyVisibility |
| 7657 | + " dp=" + win.mDrawPending |
| 7658 | + " cdp=" + win.mCommitDrawPending |
| 7659 | + " ah=" + win.mAttachedHidden |
| 7660 | + " th=" |
| 7661 | + (win.mAppToken != null |
| 7662 | ? win.mAppToken.hiddenRequested : false) |
| 7663 | + " a=" + win.mAnimating); |
| 7664 | } |
| 7665 | } |
| 7666 | numInteresting++; |
Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 7667 | if (win.isDrawnLw()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7668 | if (!win.isAnimating()) { |
| 7669 | numVisible++; |
| 7670 | } |
| 7671 | nowGone = false; |
| 7672 | } else if (win.isAnimating()) { |
| 7673 | nowGone = false; |
| 7674 | } |
| 7675 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7676 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7677 | boolean nowVisible = numInteresting > 0 && numVisible >= numInteresting; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7678 | if (DEBUG_VISIBILITY) Slog.v(TAG, "VIS " + this + ": interesting=" |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7679 | + numInteresting + " visible=" + numVisible); |
| 7680 | if (nowVisible != reportedVisible) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7681 | if (DEBUG_VISIBILITY) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7682 | TAG, "Visibility changed in " + this |
| 7683 | + ": vis=" + nowVisible); |
| 7684 | reportedVisible = nowVisible; |
| 7685 | Message m = mH.obtainMessage( |
| 7686 | H.REPORT_APPLICATION_TOKEN_WINDOWS, |
| 7687 | nowVisible ? 1 : 0, |
| 7688 | nowGone ? 1 : 0, |
| 7689 | this); |
| 7690 | mH.sendMessage(m); |
| 7691 | } |
| 7692 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7693 | |
Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 7694 | WindowState findMainWindow() { |
| 7695 | int j = windows.size(); |
| 7696 | while (j > 0) { |
| 7697 | j--; |
| 7698 | WindowState win = windows.get(j); |
| 7699 | if (win.mAttrs.type == WindowManager.LayoutParams.TYPE_BASE_APPLICATION |
| 7700 | || win.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING) { |
| 7701 | return win; |
| 7702 | } |
| 7703 | } |
| 7704 | return null; |
| 7705 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7706 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7707 | void dump(PrintWriter pw, String prefix) { |
| 7708 | super.dump(pw, prefix); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7709 | if (appToken != null) { |
| 7710 | pw.print(prefix); pw.println("app=true"); |
| 7711 | } |
| 7712 | if (allAppWindows.size() > 0) { |
| 7713 | pw.print(prefix); pw.print("allAppWindows="); pw.println(allAppWindows); |
| 7714 | } |
| 7715 | pw.print(prefix); pw.print("groupId="); pw.print(groupId); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 7716 | pw.print(" appFullscreen="); pw.print(appFullscreen); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7717 | pw.print(" requestedOrientation="); pw.println(requestedOrientation); |
| 7718 | pw.print(prefix); pw.print("hiddenRequested="); pw.print(hiddenRequested); |
| 7719 | pw.print(" clientHidden="); pw.print(clientHidden); |
| 7720 | pw.print(" willBeHidden="); pw.print(willBeHidden); |
| 7721 | pw.print(" reportedVisible="); pw.println(reportedVisible); |
| 7722 | if (paused || freezingScreen) { |
| 7723 | pw.print(prefix); pw.print("paused="); pw.print(paused); |
| 7724 | pw.print(" freezingScreen="); pw.println(freezingScreen); |
| 7725 | } |
| 7726 | if (numInterestingWindows != 0 || numDrawnWindows != 0 |
| 7727 | || inPendingTransaction || allDrawn) { |
| 7728 | pw.print(prefix); pw.print("numInterestingWindows="); |
| 7729 | pw.print(numInterestingWindows); |
| 7730 | pw.print(" numDrawnWindows="); pw.print(numDrawnWindows); |
| 7731 | pw.print(" inPendingTransaction="); pw.print(inPendingTransaction); |
| 7732 | pw.print(" allDrawn="); pw.println(allDrawn); |
| 7733 | } |
| 7734 | if (animating || animation != null) { |
| 7735 | pw.print(prefix); pw.print("animating="); pw.print(animating); |
| 7736 | pw.print(" animation="); pw.println(animation); |
| 7737 | } |
| 7738 | if (animLayerAdjustment != 0) { |
| 7739 | pw.print(prefix); pw.print("animLayerAdjustment="); pw.println(animLayerAdjustment); |
| 7740 | } |
| 7741 | if (hasTransformation) { |
| 7742 | pw.print(prefix); pw.print("hasTransformation="); pw.print(hasTransformation); |
| 7743 | pw.print(" transformation="); transformation.printShortString(pw); |
| 7744 | pw.println(); |
| 7745 | } |
| 7746 | if (startingData != null || removed || firstWindowDrawn) { |
| 7747 | pw.print(prefix); pw.print("startingData="); pw.print(startingData); |
| 7748 | pw.print(" removed="); pw.print(removed); |
| 7749 | pw.print(" firstWindowDrawn="); pw.println(firstWindowDrawn); |
| 7750 | } |
| 7751 | if (startingWindow != null || startingView != null |
| 7752 | || startingDisplayed || startingMoved) { |
| 7753 | pw.print(prefix); pw.print("startingWindow="); pw.print(startingWindow); |
| 7754 | pw.print(" startingView="); pw.print(startingView); |
| 7755 | pw.print(" startingDisplayed="); pw.print(startingDisplayed); |
| 7756 | pw.print(" startingMoved"); pw.println(startingMoved); |
| 7757 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7758 | } |
| 7759 | |
| 7760 | @Override |
| 7761 | public String toString() { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7762 | if (stringName == null) { |
| 7763 | StringBuilder sb = new StringBuilder(); |
| 7764 | sb.append("AppWindowToken{"); |
| 7765 | sb.append(Integer.toHexString(System.identityHashCode(this))); |
| 7766 | sb.append(" token="); sb.append(token); sb.append('}'); |
| 7767 | stringName = sb.toString(); |
| 7768 | } |
| 7769 | return stringName; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7770 | } |
| 7771 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7772 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7773 | // ------------------------------------------------------------- |
| 7774 | // DummyAnimation |
| 7775 | // ------------------------------------------------------------- |
| 7776 | |
| 7777 | // This is an animation that does nothing: it just immediately finishes |
| 7778 | // itself every time it is called. It is used as a stub animation in cases |
| 7779 | // where we want to synchronize multiple things that may be animating. |
| 7780 | static final class DummyAnimation extends Animation { |
| 7781 | public boolean getTransformation(long currentTime, Transformation outTransformation) { |
| 7782 | return false; |
| 7783 | } |
| 7784 | } |
| 7785 | static final Animation sDummyAnimation = new DummyAnimation(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7786 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7787 | // ------------------------------------------------------------- |
| 7788 | // Async Handler |
| 7789 | // ------------------------------------------------------------- |
| 7790 | |
| 7791 | static final class StartingData { |
| 7792 | final String pkg; |
| 7793 | final int theme; |
| 7794 | final CharSequence nonLocalizedLabel; |
| 7795 | final int labelRes; |
| 7796 | final int icon; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7797 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7798 | StartingData(String _pkg, int _theme, CharSequence _nonLocalizedLabel, |
| 7799 | int _labelRes, int _icon) { |
| 7800 | pkg = _pkg; |
| 7801 | theme = _theme; |
| 7802 | nonLocalizedLabel = _nonLocalizedLabel; |
| 7803 | labelRes = _labelRes; |
| 7804 | icon = _icon; |
| 7805 | } |
| 7806 | } |
| 7807 | |
| 7808 | private final class H extends Handler { |
| 7809 | public static final int REPORT_FOCUS_CHANGE = 2; |
| 7810 | public static final int REPORT_LOSING_FOCUS = 3; |
| 7811 | public static final int ANIMATE = 4; |
| 7812 | public static final int ADD_STARTING = 5; |
| 7813 | public static final int REMOVE_STARTING = 6; |
| 7814 | public static final int FINISHED_STARTING = 7; |
| 7815 | public static final int REPORT_APPLICATION_TOKEN_WINDOWS = 8; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7816 | public static final int WINDOW_FREEZE_TIMEOUT = 11; |
| 7817 | public static final int HOLD_SCREEN_CHANGED = 12; |
| 7818 | public static final int APP_TRANSITION_TIMEOUT = 13; |
| 7819 | public static final int PERSIST_ANIMATION_SCALE = 14; |
| 7820 | public static final int FORCE_GC = 15; |
| 7821 | public static final int ENABLE_SCREEN = 16; |
| 7822 | public static final int APP_FREEZE_TIMEOUT = 17; |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 7823 | public static final int SEND_NEW_CONFIGURATION = 18; |
Konstantin Lopyrev | 6e0f65f | 2010-07-14 14:55:33 -0700 | [diff] [blame] | 7824 | public static final int REPORT_WINDOWS_CHANGE = 19; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7825 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7826 | private Session mLastReportedHold; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7827 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7828 | public H() { |
| 7829 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7830 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7831 | @Override |
| 7832 | public void handleMessage(Message msg) { |
| 7833 | switch (msg.what) { |
| 7834 | case REPORT_FOCUS_CHANGE: { |
| 7835 | WindowState lastFocus; |
| 7836 | WindowState newFocus; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7837 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7838 | synchronized(mWindowMap) { |
| 7839 | lastFocus = mLastFocus; |
| 7840 | newFocus = mCurrentFocus; |
| 7841 | if (lastFocus == newFocus) { |
| 7842 | // Focus is not changing, so nothing to do. |
| 7843 | return; |
| 7844 | } |
| 7845 | mLastFocus = newFocus; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7846 | //Slog.i(TAG, "Focus moving from " + lastFocus |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7847 | // + " to " + newFocus); |
| 7848 | if (newFocus != null && lastFocus != null |
| 7849 | && !newFocus.isDisplayedLw()) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7850 | //Slog.i(TAG, "Delaying loss of focus..."); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7851 | mLosingFocus.add(lastFocus); |
| 7852 | lastFocus = null; |
| 7853 | } |
| 7854 | } |
| 7855 | |
| 7856 | if (lastFocus != newFocus) { |
| 7857 | //System.out.println("Changing focus from " + lastFocus |
| 7858 | // + " to " + newFocus); |
| 7859 | if (newFocus != null) { |
| 7860 | try { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7861 | //Slog.i(TAG, "Gaining focus: " + newFocus); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7862 | newFocus.mClient.windowFocusChanged(true, mInTouchMode); |
| 7863 | } catch (RemoteException e) { |
| 7864 | // Ignore if process has died. |
| 7865 | } |
Konstantin Lopyrev | 5e7833a | 2010-08-09 17:01:11 -0700 | [diff] [blame] | 7866 | notifyFocusChanged(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7867 | } |
| 7868 | |
| 7869 | if (lastFocus != null) { |
| 7870 | try { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7871 | //Slog.i(TAG, "Losing focus: " + lastFocus); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7872 | lastFocus.mClient.windowFocusChanged(false, mInTouchMode); |
| 7873 | } catch (RemoteException e) { |
| 7874 | // Ignore if process has died. |
| 7875 | } |
| 7876 | } |
| 7877 | } |
| 7878 | } break; |
| 7879 | |
| 7880 | case REPORT_LOSING_FOCUS: { |
| 7881 | ArrayList<WindowState> losers; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7882 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7883 | synchronized(mWindowMap) { |
| 7884 | losers = mLosingFocus; |
| 7885 | mLosingFocus = new ArrayList<WindowState>(); |
| 7886 | } |
| 7887 | |
| 7888 | final int N = losers.size(); |
| 7889 | for (int i=0; i<N; i++) { |
| 7890 | try { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7891 | //Slog.i(TAG, "Losing delayed focus: " + losers.get(i)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7892 | losers.get(i).mClient.windowFocusChanged(false, mInTouchMode); |
| 7893 | } catch (RemoteException e) { |
| 7894 | // Ignore if process has died. |
| 7895 | } |
| 7896 | } |
| 7897 | } break; |
| 7898 | |
| 7899 | case ANIMATE: { |
| 7900 | synchronized(mWindowMap) { |
| 7901 | mAnimationPending = false; |
| 7902 | performLayoutAndPlaceSurfacesLocked(); |
| 7903 | } |
| 7904 | } break; |
| 7905 | |
| 7906 | case ADD_STARTING: { |
| 7907 | final AppWindowToken wtoken = (AppWindowToken)msg.obj; |
| 7908 | final StartingData sd = wtoken.startingData; |
| 7909 | |
| 7910 | if (sd == null) { |
| 7911 | // Animation has been canceled... do nothing. |
| 7912 | return; |
| 7913 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7914 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7915 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Add starting " |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7916 | + wtoken + ": pkg=" + sd.pkg); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7917 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7918 | View view = null; |
| 7919 | try { |
| 7920 | view = mPolicy.addStartingWindow( |
| 7921 | wtoken.token, sd.pkg, |
| 7922 | sd.theme, sd.nonLocalizedLabel, sd.labelRes, |
| 7923 | sd.icon); |
| 7924 | } catch (Exception e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7925 | Slog.w(TAG, "Exception when adding starting window", e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7926 | } |
| 7927 | |
| 7928 | if (view != null) { |
| 7929 | boolean abort = false; |
| 7930 | |
| 7931 | synchronized(mWindowMap) { |
| 7932 | if (wtoken.removed || wtoken.startingData == null) { |
| 7933 | // If the window was successfully added, then |
| 7934 | // we need to remove it. |
| 7935 | if (wtoken.startingWindow != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7936 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7937 | "Aborted starting " + wtoken |
| 7938 | + ": removed=" + wtoken.removed |
| 7939 | + " startingData=" + wtoken.startingData); |
| 7940 | wtoken.startingWindow = null; |
| 7941 | wtoken.startingData = null; |
| 7942 | abort = true; |
| 7943 | } |
| 7944 | } else { |
| 7945 | wtoken.startingView = view; |
| 7946 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7947 | if (DEBUG_STARTING_WINDOW && !abort) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7948 | "Added starting " + wtoken |
| 7949 | + ": startingWindow=" |
| 7950 | + wtoken.startingWindow + " startingView=" |
| 7951 | + wtoken.startingView); |
| 7952 | } |
| 7953 | |
| 7954 | if (abort) { |
| 7955 | try { |
| 7956 | mPolicy.removeStartingWindow(wtoken.token, view); |
| 7957 | } catch (Exception e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7958 | Slog.w(TAG, "Exception when removing starting window", e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7959 | } |
| 7960 | } |
| 7961 | } |
| 7962 | } break; |
| 7963 | |
| 7964 | case REMOVE_STARTING: { |
| 7965 | final AppWindowToken wtoken = (AppWindowToken)msg.obj; |
| 7966 | IBinder token = null; |
| 7967 | View view = null; |
| 7968 | synchronized (mWindowMap) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7969 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Remove starting " |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7970 | + wtoken + ": startingWindow=" |
| 7971 | + wtoken.startingWindow + " startingView=" |
| 7972 | + wtoken.startingView); |
| 7973 | if (wtoken.startingWindow != null) { |
| 7974 | view = wtoken.startingView; |
| 7975 | token = wtoken.token; |
| 7976 | wtoken.startingData = null; |
| 7977 | wtoken.startingView = null; |
| 7978 | wtoken.startingWindow = null; |
| 7979 | } |
| 7980 | } |
| 7981 | if (view != null) { |
| 7982 | try { |
| 7983 | mPolicy.removeStartingWindow(token, view); |
| 7984 | } catch (Exception e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7985 | Slog.w(TAG, "Exception when removing starting window", e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7986 | } |
| 7987 | } |
| 7988 | } break; |
| 7989 | |
| 7990 | case FINISHED_STARTING: { |
| 7991 | IBinder token = null; |
| 7992 | View view = null; |
| 7993 | while (true) { |
| 7994 | synchronized (mWindowMap) { |
| 7995 | final int N = mFinishedStarting.size(); |
| 7996 | if (N <= 0) { |
| 7997 | break; |
| 7998 | } |
| 7999 | AppWindowToken wtoken = mFinishedStarting.remove(N-1); |
| 8000 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8001 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8002 | "Finished starting " + wtoken |
| 8003 | + ": startingWindow=" + wtoken.startingWindow |
| 8004 | + " startingView=" + wtoken.startingView); |
| 8005 | |
| 8006 | if (wtoken.startingWindow == null) { |
| 8007 | continue; |
| 8008 | } |
| 8009 | |
| 8010 | view = wtoken.startingView; |
| 8011 | token = wtoken.token; |
| 8012 | wtoken.startingData = null; |
| 8013 | wtoken.startingView = null; |
| 8014 | wtoken.startingWindow = null; |
| 8015 | } |
| 8016 | |
| 8017 | try { |
| 8018 | mPolicy.removeStartingWindow(token, view); |
| 8019 | } catch (Exception e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8020 | Slog.w(TAG, "Exception when removing starting window", e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8021 | } |
| 8022 | } |
| 8023 | } break; |
| 8024 | |
| 8025 | case REPORT_APPLICATION_TOKEN_WINDOWS: { |
| 8026 | final AppWindowToken wtoken = (AppWindowToken)msg.obj; |
| 8027 | |
| 8028 | boolean nowVisible = msg.arg1 != 0; |
| 8029 | boolean nowGone = msg.arg2 != 0; |
| 8030 | |
| 8031 | try { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8032 | if (DEBUG_VISIBILITY) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8033 | TAG, "Reporting visible in " + wtoken |
| 8034 | + " visible=" + nowVisible |
| 8035 | + " gone=" + nowGone); |
| 8036 | if (nowVisible) { |
| 8037 | wtoken.appToken.windowsVisible(); |
| 8038 | } else { |
| 8039 | wtoken.appToken.windowsGone(); |
| 8040 | } |
| 8041 | } catch (RemoteException ex) { |
| 8042 | } |
| 8043 | } break; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8044 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8045 | case WINDOW_FREEZE_TIMEOUT: { |
| 8046 | synchronized (mWindowMap) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8047 | Slog.w(TAG, "Window freeze timeout expired."); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8048 | int i = mWindows.size(); |
| 8049 | while (i > 0) { |
| 8050 | i--; |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 8051 | WindowState w = mWindows.get(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8052 | if (w.mOrientationChanging) { |
| 8053 | w.mOrientationChanging = false; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8054 | Slog.w(TAG, "Force clearing orientation change: " + w); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8055 | } |
| 8056 | } |
| 8057 | performLayoutAndPlaceSurfacesLocked(); |
| 8058 | } |
| 8059 | break; |
| 8060 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8061 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8062 | case HOLD_SCREEN_CHANGED: { |
| 8063 | Session oldHold; |
| 8064 | Session newHold; |
| 8065 | synchronized (mWindowMap) { |
| 8066 | oldHold = mLastReportedHold; |
| 8067 | newHold = (Session)msg.obj; |
| 8068 | mLastReportedHold = newHold; |
| 8069 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8070 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8071 | if (oldHold != newHold) { |
| 8072 | try { |
| 8073 | if (oldHold != null) { |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 8074 | mBatteryStats.noteStopWakelock(oldHold.mUid, -1, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8075 | "window", |
| 8076 | BatteryStats.WAKE_TYPE_WINDOW); |
| 8077 | } |
| 8078 | if (newHold != null) { |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 8079 | mBatteryStats.noteStartWakelock(newHold.mUid, -1, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8080 | "window", |
| 8081 | BatteryStats.WAKE_TYPE_WINDOW); |
| 8082 | } |
| 8083 | } catch (RemoteException e) { |
| 8084 | } |
| 8085 | } |
| 8086 | break; |
| 8087 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8088 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8089 | case APP_TRANSITION_TIMEOUT: { |
| 8090 | synchronized (mWindowMap) { |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 8091 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8092 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8093 | "*** APP TRANSITION TIMEOUT"); |
| 8094 | mAppTransitionReady = true; |
| 8095 | mAppTransitionTimeout = true; |
| 8096 | performLayoutAndPlaceSurfacesLocked(); |
| 8097 | } |
| 8098 | } |
| 8099 | break; |
| 8100 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8101 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8102 | case PERSIST_ANIMATION_SCALE: { |
| 8103 | Settings.System.putFloat(mContext.getContentResolver(), |
| 8104 | Settings.System.WINDOW_ANIMATION_SCALE, mWindowAnimationScale); |
| 8105 | Settings.System.putFloat(mContext.getContentResolver(), |
| 8106 | Settings.System.TRANSITION_ANIMATION_SCALE, mTransitionAnimationScale); |
| 8107 | break; |
| 8108 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8109 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8110 | case FORCE_GC: { |
| 8111 | synchronized(mWindowMap) { |
| 8112 | if (mAnimationPending) { |
| 8113 | // If we are animating, don't do the gc now but |
| 8114 | // delay a bit so we don't interrupt the animation. |
| 8115 | mH.sendMessageDelayed(mH.obtainMessage(H.FORCE_GC), |
| 8116 | 2000); |
| 8117 | return; |
| 8118 | } |
| 8119 | // If we are currently rotating the display, it will |
| 8120 | // schedule a new message when done. |
| 8121 | if (mDisplayFrozen) { |
| 8122 | return; |
| 8123 | } |
| 8124 | mFreezeGcPending = 0; |
| 8125 | } |
| 8126 | Runtime.getRuntime().gc(); |
| 8127 | break; |
| 8128 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8129 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8130 | case ENABLE_SCREEN: { |
| 8131 | performEnableScreen(); |
| 8132 | break; |
| 8133 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8134 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8135 | case APP_FREEZE_TIMEOUT: { |
| 8136 | synchronized (mWindowMap) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8137 | Slog.w(TAG, "App freeze timeout expired."); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8138 | int i = mAppTokens.size(); |
| 8139 | while (i > 0) { |
| 8140 | i--; |
| 8141 | AppWindowToken tok = mAppTokens.get(i); |
| 8142 | if (tok.freezingScreen) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8143 | Slog.w(TAG, "Force clearing freeze: " + tok); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8144 | unsetAppFreezingScreenLocked(tok, true, true); |
| 8145 | } |
| 8146 | } |
| 8147 | } |
| 8148 | break; |
| 8149 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8150 | |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 8151 | case SEND_NEW_CONFIGURATION: { |
| 8152 | removeMessages(SEND_NEW_CONFIGURATION); |
| 8153 | sendNewConfiguration(); |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 8154 | break; |
| 8155 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8156 | |
Konstantin Lopyrev | 6e0f65f | 2010-07-14 14:55:33 -0700 | [diff] [blame] | 8157 | case REPORT_WINDOWS_CHANGE: { |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 8158 | if (mWindowsChanged) { |
| 8159 | synchronized (mWindowMap) { |
| 8160 | mWindowsChanged = false; |
| 8161 | } |
| 8162 | notifyWindowsChanged(); |
| 8163 | } |
| 8164 | break; |
| 8165 | } |
| 8166 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8167 | } |
| 8168 | } |
| 8169 | } |
| 8170 | |
| 8171 | // ------------------------------------------------------------- |
| 8172 | // IWindowManager API |
| 8173 | // ------------------------------------------------------------- |
| 8174 | |
| 8175 | public IWindowSession openSession(IInputMethodClient client, |
| 8176 | IInputContext inputContext) { |
| 8177 | if (client == null) throw new IllegalArgumentException("null client"); |
| 8178 | if (inputContext == null) throw new IllegalArgumentException("null inputContext"); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 8179 | Session session = new Session(client, inputContext); |
| 8180 | return session; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8181 | } |
| 8182 | |
| 8183 | public boolean inputMethodClientHasFocus(IInputMethodClient client) { |
| 8184 | synchronized (mWindowMap) { |
| 8185 | // The focus for the client is the window immediately below |
| 8186 | // where we would place the input method window. |
| 8187 | int idx = findDesiredInputMethodWindowIndexLocked(false); |
| 8188 | WindowState imFocus; |
| 8189 | if (idx > 0) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 8190 | imFocus = mWindows.get(idx-1); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8191 | if (imFocus != null) { |
| 8192 | if (imFocus.mSession.mClient != null && |
| 8193 | imFocus.mSession.mClient.asBinder() == client.asBinder()) { |
| 8194 | return true; |
| 8195 | } |
| 8196 | } |
| 8197 | } |
| 8198 | } |
| 8199 | return false; |
| 8200 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8201 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8202 | // ------------------------------------------------------------- |
| 8203 | // Internals |
| 8204 | // ------------------------------------------------------------- |
| 8205 | |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 8206 | final WindowState windowForClientLocked(Session session, IWindow client, |
| 8207 | boolean throwOnError) { |
| 8208 | return windowForClientLocked(session, client.asBinder(), throwOnError); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8209 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8210 | |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 8211 | final WindowState windowForClientLocked(Session session, IBinder client, |
| 8212 | boolean throwOnError) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8213 | WindowState win = mWindowMap.get(client); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8214 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8215 | TAG, "Looking up client " + client + ": " + win); |
| 8216 | if (win == null) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 8217 | RuntimeException ex = new IllegalArgumentException( |
| 8218 | "Requested window " + client + " does not exist"); |
| 8219 | if (throwOnError) { |
| 8220 | throw ex; |
| 8221 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8222 | Slog.w(TAG, "Failed looking up window", ex); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8223 | return null; |
| 8224 | } |
| 8225 | if (session != null && win.mSession != session) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 8226 | RuntimeException ex = new IllegalArgumentException( |
| 8227 | "Requested window " + client + " is in session " + |
| 8228 | win.mSession + ", not " + session); |
| 8229 | if (throwOnError) { |
| 8230 | throw ex; |
| 8231 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8232 | Slog.w(TAG, "Failed looking up window", ex); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8233 | return null; |
| 8234 | } |
| 8235 | |
| 8236 | return win; |
| 8237 | } |
| 8238 | |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8239 | final void rebuildAppWindowListLocked() { |
| 8240 | int NW = mWindows.size(); |
| 8241 | int i; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8242 | int lastWallpaper = -1; |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 8243 | int numRemoved = 0; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8244 | |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8245 | // First remove all existing app windows. |
| 8246 | i=0; |
| 8247 | while (i < NW) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 8248 | WindowState w = mWindows.get(i); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8249 | if (w.mAppToken != null) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 8250 | WindowState win = mWindows.remove(i); |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 8251 | mWindowsChanged = true; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8252 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, |
Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 8253 | "Rebuild removing window: " + win); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8254 | NW--; |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 8255 | numRemoved++; |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8256 | continue; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8257 | } else if (w.mAttrs.type == WindowManager.LayoutParams.TYPE_WALLPAPER |
| 8258 | && lastWallpaper == i-1) { |
| 8259 | lastWallpaper = i; |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8260 | } |
| 8261 | i++; |
| 8262 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8263 | |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8264 | // The wallpaper window(s) typically live at the bottom of the stack, |
| 8265 | // so skip them before adding app tokens. |
| 8266 | lastWallpaper++; |
| 8267 | i = lastWallpaper; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8268 | |
Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 8269 | // First add all of the exiting app tokens... these are no longer |
| 8270 | // in the main app list, but still have windows shown. We put them |
| 8271 | // in the back because now that the animation is over we no longer |
| 8272 | // will care about them. |
| 8273 | int NT = mExitingAppTokens.size(); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8274 | for (int j=0; j<NT; j++) { |
Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 8275 | i = reAddAppWindowsLocked(i, mExitingAppTokens.get(j)); |
| 8276 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8277 | |
Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 8278 | // And add in the still active app tokens in Z order. |
| 8279 | NT = mAppTokens.size(); |
| 8280 | for (int j=0; j<NT; j++) { |
| 8281 | i = reAddAppWindowsLocked(i, mAppTokens.get(j)); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8282 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8283 | |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8284 | i -= lastWallpaper; |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 8285 | if (i != numRemoved) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8286 | Slog.w(TAG, "Rebuild removed " + numRemoved |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 8287 | + " windows but added " + i); |
| 8288 | } |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8289 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8290 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8291 | private final void assignLayersLocked() { |
| 8292 | int N = mWindows.size(); |
| 8293 | int curBaseLayer = 0; |
| 8294 | int curLayer = 0; |
| 8295 | int i; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8296 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8297 | for (i=0; i<N; i++) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 8298 | WindowState w = mWindows.get(i); |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 8299 | if (w.mBaseLayer == curBaseLayer || w.mIsImWindow |
| 8300 | || (i > 0 && w.mIsWallpaper)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8301 | curLayer += WINDOW_LAYER_MULTIPLIER; |
| 8302 | w.mLayer = curLayer; |
| 8303 | } else { |
| 8304 | curBaseLayer = curLayer = w.mBaseLayer; |
| 8305 | w.mLayer = curLayer; |
| 8306 | } |
| 8307 | if (w.mTargetAppToken != null) { |
| 8308 | w.mAnimLayer = w.mLayer + w.mTargetAppToken.animLayerAdjustment; |
| 8309 | } else if (w.mAppToken != null) { |
| 8310 | w.mAnimLayer = w.mLayer + w.mAppToken.animLayerAdjustment; |
| 8311 | } else { |
| 8312 | w.mAnimLayer = w.mLayer; |
| 8313 | } |
| 8314 | if (w.mIsImWindow) { |
| 8315 | w.mAnimLayer += mInputMethodAnimLayerAdjustment; |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 8316 | } else if (w.mIsWallpaper) { |
| 8317 | w.mAnimLayer += mWallpaperAnimLayerAdjustment; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8318 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8319 | if (DEBUG_LAYERS) Slog.v(TAG, "Assign layer " + w + ": " |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8320 | + w.mAnimLayer); |
| 8321 | //System.out.println( |
| 8322 | // "Assigned layer " + curLayer + " to " + w.mClient.asBinder()); |
| 8323 | } |
| 8324 | } |
| 8325 | |
| 8326 | private boolean mInLayout = false; |
| 8327 | private final void performLayoutAndPlaceSurfacesLocked() { |
| 8328 | if (mInLayout) { |
Dave Bort | cfe6524 | 2009-04-09 14:51:04 -0700 | [diff] [blame] | 8329 | if (DEBUG) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8330 | throw new RuntimeException("Recursive call!"); |
| 8331 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8332 | Slog.w(TAG, "performLayoutAndPlaceSurfacesLocked called while in layout"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8333 | return; |
| 8334 | } |
| 8335 | |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 8336 | if (mWaitingForConfig) { |
| 8337 | // Our configuration has changed (most likely rotation), but we |
| 8338 | // don't yet have the complete configuration to report to |
| 8339 | // applications. Don't do any window layout until we have it. |
| 8340 | return; |
| 8341 | } |
| 8342 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8343 | boolean recoveringMemory = false; |
| 8344 | if (mForceRemoves != null) { |
| 8345 | recoveringMemory = true; |
| 8346 | // Wait a little it for things to settle down, and off we go. |
| 8347 | for (int i=0; i<mForceRemoves.size(); i++) { |
| 8348 | WindowState ws = mForceRemoves.get(i); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8349 | Slog.i(TAG, "Force removing: " + ws); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8350 | removeWindowInnerLocked(ws.mSession, ws); |
| 8351 | } |
| 8352 | mForceRemoves = null; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8353 | 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] | 8354 | Object tmp = new Object(); |
| 8355 | synchronized (tmp) { |
| 8356 | try { |
| 8357 | tmp.wait(250); |
| 8358 | } catch (InterruptedException e) { |
| 8359 | } |
| 8360 | } |
| 8361 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8362 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8363 | mInLayout = true; |
| 8364 | try { |
| 8365 | performLayoutAndPlaceSurfacesLockedInner(recoveringMemory); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8366 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8367 | int i = mPendingRemove.size()-1; |
| 8368 | if (i >= 0) { |
| 8369 | while (i >= 0) { |
| 8370 | WindowState w = mPendingRemove.get(i); |
| 8371 | removeWindowInnerLocked(w.mSession, w); |
| 8372 | i--; |
| 8373 | } |
| 8374 | mPendingRemove.clear(); |
| 8375 | |
| 8376 | mInLayout = false; |
| 8377 | assignLayersLocked(); |
| 8378 | mLayoutNeeded = true; |
| 8379 | performLayoutAndPlaceSurfacesLocked(); |
| 8380 | |
| 8381 | } else { |
| 8382 | mInLayout = false; |
| 8383 | if (mLayoutNeeded) { |
| 8384 | requestAnimationLocked(0); |
| 8385 | } |
| 8386 | } |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 8387 | if (mWindowsChanged && !mWindowChangeListeners.isEmpty()) { |
Konstantin Lopyrev | 6e0f65f | 2010-07-14 14:55:33 -0700 | [diff] [blame] | 8388 | mH.removeMessages(H.REPORT_WINDOWS_CHANGE); |
| 8389 | mH.sendMessage(mH.obtainMessage(H.REPORT_WINDOWS_CHANGE)); |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 8390 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8391 | } catch (RuntimeException e) { |
| 8392 | mInLayout = false; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8393 | 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] | 8394 | } |
| 8395 | } |
| 8396 | |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 8397 | private final int performLayoutLockedInner() { |
| 8398 | if (!mLayoutNeeded) { |
| 8399 | return 0; |
| 8400 | } |
| 8401 | |
| 8402 | mLayoutNeeded = false; |
| 8403 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8404 | final int dw = mDisplay.getWidth(); |
| 8405 | final int dh = mDisplay.getHeight(); |
| 8406 | |
| 8407 | final int N = mWindows.size(); |
| 8408 | int i; |
| 8409 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8410 | if (DEBUG_LAYOUT) Slog.v(TAG, "performLayout: needed=" |
Dianne Hackborn | 9b52a21 | 2009-12-11 14:51:35 -0800 | [diff] [blame] | 8411 | + mLayoutNeeded + " dw=" + dw + " dh=" + dh); |
| 8412 | |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 8413 | mPolicy.beginLayoutLw(dw, dh); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8414 | |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 8415 | int seq = mLayoutSeq+1; |
| 8416 | if (seq < 0) seq = 0; |
| 8417 | mLayoutSeq = seq; |
| 8418 | |
| 8419 | // First perform layout of any root windows (not attached |
| 8420 | // to another window). |
| 8421 | int topAttached = -1; |
| 8422 | for (i = N-1; i >= 0; i--) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 8423 | WindowState win = mWindows.get(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8424 | |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 8425 | // Don't do layout of a window if it is not visible, or |
| 8426 | // soon won't be visible, to avoid wasting time and funky |
| 8427 | // changes while a window is animating away. |
| 8428 | final AppWindowToken atoken = win.mAppToken; |
| 8429 | final boolean gone = win.mViewVisibility == View.GONE |
| 8430 | || !win.mRelayoutCalled |
| 8431 | || win.mRootToken.hidden |
| 8432 | || (atoken != null && atoken.hiddenRequested) |
| 8433 | || win.mAttachedHidden |
| 8434 | || win.mExiting || win.mDestroying; |
| 8435 | |
| 8436 | if (!win.mLayoutAttached) { |
| 8437 | if (DEBUG_LAYOUT) Slog.v(TAG, "First pass " + win |
| 8438 | + ": gone=" + gone + " mHaveFrame=" + win.mHaveFrame |
| 8439 | + " mLayoutAttached=" + win.mLayoutAttached); |
| 8440 | if (DEBUG_LAYOUT && gone) Slog.v(TAG, " (mViewVisibility=" |
| 8441 | + win.mViewVisibility + " mRelayoutCalled=" |
| 8442 | + win.mRelayoutCalled + " hidden=" |
| 8443 | + win.mRootToken.hidden + " hiddenRequested=" |
| 8444 | + (atoken != null && atoken.hiddenRequested) |
| 8445 | + " mAttachedHidden=" + win.mAttachedHidden); |
| 8446 | } |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 8447 | |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 8448 | // If this view is GONE, then skip it -- keep the current |
| 8449 | // frame, and let the caller know so they can ignore it |
| 8450 | // if they want. (We do the normal layout for INVISIBLE |
| 8451 | // windows, since that means "perform layout as normal, |
| 8452 | // just don't display"). |
| 8453 | if (!gone || !win.mHaveFrame) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 8454 | if (!win.mLayoutAttached) { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 8455 | mPolicy.layoutWindowLw(win, win.mAttrs, null); |
| 8456 | win.mLayoutSeq = seq; |
| 8457 | if (DEBUG_LAYOUT) Slog.v(TAG, "-> mFrame=" |
| 8458 | + win.mFrame + " mContainingFrame=" |
| 8459 | + win.mContainingFrame + " mDisplayFrame=" |
| 8460 | + win.mDisplayFrame); |
| 8461 | } else { |
| 8462 | if (topAttached < 0) topAttached = i; |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 8463 | } |
Dianne Hackborn | 958b9ad | 2009-03-31 18:00:36 -0700 | [diff] [blame] | 8464 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8465 | } |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 8466 | |
| 8467 | // Now perform layout of attached windows, which usually |
| 8468 | // depend on the position of the window they are attached to. |
| 8469 | // XXX does not deal with windows that are attached to windows |
| 8470 | // that are themselves attached. |
| 8471 | for (i = topAttached; i >= 0; i--) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 8472 | WindowState win = mWindows.get(i); |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 8473 | |
| 8474 | // If this view is GONE, then skip it -- keep the current |
| 8475 | // frame, and let the caller know so they can ignore it |
| 8476 | // if they want. (We do the normal layout for INVISIBLE |
| 8477 | // windows, since that means "perform layout as normal, |
| 8478 | // just don't display"). |
| 8479 | if (win.mLayoutAttached) { |
| 8480 | if (DEBUG_LAYOUT) Slog.v(TAG, "Second pass " + win |
| 8481 | + " mHaveFrame=" + win.mHaveFrame |
| 8482 | + " mViewVisibility=" + win.mViewVisibility |
| 8483 | + " mRelayoutCalled=" + win.mRelayoutCalled); |
| 8484 | if ((win.mViewVisibility != View.GONE && win.mRelayoutCalled) |
| 8485 | || !win.mHaveFrame) { |
| 8486 | mPolicy.layoutWindowLw(win, win.mAttrs, win.mAttachedWindow); |
| 8487 | win.mLayoutSeq = seq; |
| 8488 | if (DEBUG_LAYOUT) Slog.v(TAG, "-> mFrame=" |
| 8489 | + win.mFrame + " mContainingFrame=" |
| 8490 | + win.mContainingFrame + " mDisplayFrame=" |
| 8491 | + win.mDisplayFrame); |
| 8492 | } |
| 8493 | } |
| 8494 | } |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 8495 | |
| 8496 | // Window frames may have changed. Tell the input dispatcher about it. |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 8497 | mInputMonitor.updateInputWindowsLw(); |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 8498 | |
| 8499 | return mPolicy.finishLayoutLw(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8500 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8501 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8502 | private final void performLayoutAndPlaceSurfacesLockedInner( |
| 8503 | boolean recoveringMemory) { |
| 8504 | final long currentTime = SystemClock.uptimeMillis(); |
| 8505 | final int dw = mDisplay.getWidth(); |
| 8506 | final int dh = mDisplay.getHeight(); |
| 8507 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8508 | int i; |
| 8509 | |
Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 8510 | if (mFocusMayChange) { |
| 8511 | mFocusMayChange = false; |
| 8512 | updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES); |
| 8513 | } |
| 8514 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8515 | // Initialize state of exiting tokens. |
| 8516 | for (i=mExitingTokens.size()-1; i>=0; i--) { |
| 8517 | mExitingTokens.get(i).hasVisible = false; |
| 8518 | } |
| 8519 | |
| 8520 | // Initialize state of exiting applications. |
| 8521 | for (i=mExitingAppTokens.size()-1; i>=0; i--) { |
| 8522 | mExitingAppTokens.get(i).hasVisible = false; |
| 8523 | } |
| 8524 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8525 | boolean orientationChangeComplete = true; |
| 8526 | Session holdScreen = null; |
| 8527 | float screenBrightness = -1; |
Mike Lockwood | fb73f79 | 2009-11-20 11:31:18 -0500 | [diff] [blame] | 8528 | float buttonBrightness = -1; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8529 | boolean focusDisplayed = false; |
| 8530 | boolean animating = false; |
Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 8531 | boolean createWatermark = false; |
| 8532 | |
| 8533 | if (mFxSession == null) { |
| 8534 | mFxSession = new SurfaceSession(); |
| 8535 | createWatermark = true; |
| 8536 | } |
| 8537 | |
| 8538 | if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8539 | |
| 8540 | Surface.openTransaction(); |
Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 8541 | |
| 8542 | if (createWatermark) { |
| 8543 | createWatermark(); |
| 8544 | } |
| 8545 | if (mWatermark != null) { |
| 8546 | mWatermark.positionSurface(dw, dh); |
| 8547 | } |
| 8548 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8549 | try { |
Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 8550 | boolean wallpaperForceHidingChanged = false; |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 8551 | int repeats = 0; |
| 8552 | int changes = 0; |
| 8553 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8554 | do { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 8555 | repeats++; |
| 8556 | if (repeats > 6) { |
| 8557 | Slog.w(TAG, "Animation repeat aborted after too many iterations"); |
| 8558 | mLayoutNeeded = false; |
| 8559 | break; |
| 8560 | } |
| 8561 | |
| 8562 | if ((changes&(WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER |
| 8563 | | WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG |
| 8564 | | WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT)) != 0) { |
| 8565 | if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER) != 0) { |
| 8566 | if ((adjustWallpaperWindowsLocked()&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) { |
| 8567 | assignLayersLocked(); |
| 8568 | mLayoutNeeded = true; |
| 8569 | } |
| 8570 | } |
| 8571 | if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG) != 0) { |
| 8572 | if (DEBUG_LAYOUT) Slog.v(TAG, "Computing new config from layout"); |
| 8573 | if (updateOrientationFromAppTokensLocked()) { |
| 8574 | mLayoutNeeded = true; |
| 8575 | mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION); |
| 8576 | } |
| 8577 | } |
| 8578 | if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT) != 0) { |
| 8579 | mLayoutNeeded = true; |
| 8580 | } |
| 8581 | } |
| 8582 | |
| 8583 | // FIRST LOOP: Perform a layout, if needed. |
| 8584 | if (repeats < 4) { |
| 8585 | changes = performLayoutLockedInner(); |
| 8586 | if (changes != 0) { |
| 8587 | continue; |
| 8588 | } |
| 8589 | } else { |
| 8590 | Slog.w(TAG, "Layout repeat skipped after too many iterations"); |
| 8591 | changes = 0; |
| 8592 | } |
| 8593 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8594 | final int transactionSequence = ++mTransactionSequence; |
| 8595 | |
| 8596 | // Update animations of all applications, including those |
| 8597 | // associated with exiting/removed apps |
| 8598 | boolean tokensAnimating = false; |
| 8599 | final int NAT = mAppTokens.size(); |
| 8600 | for (i=0; i<NAT; i++) { |
| 8601 | if (mAppTokens.get(i).stepAnimationLocked(currentTime, dw, dh)) { |
| 8602 | tokensAnimating = true; |
| 8603 | } |
| 8604 | } |
| 8605 | final int NEAT = mExitingAppTokens.size(); |
| 8606 | for (i=0; i<NEAT; i++) { |
| 8607 | if (mExitingAppTokens.get(i).stepAnimationLocked(currentTime, dw, dh)) { |
| 8608 | tokensAnimating = true; |
| 8609 | } |
| 8610 | } |
| 8611 | |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 8612 | // SECOND LOOP: Execute animations and update visibility of windows. |
| 8613 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8614 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "*** ANIM STEP: seq=" |
Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 8615 | + transactionSequence + " tokensAnimating=" |
| 8616 | + tokensAnimating); |
| 8617 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8618 | animating = tokensAnimating; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8619 | |
| 8620 | boolean tokenMayBeDrawn = false; |
Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 8621 | boolean wallpaperMayChange = false; |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 8622 | boolean forceHiding = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8623 | |
| 8624 | mPolicy.beginAnimationLw(dw, dh); |
| 8625 | |
Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 8626 | final int N = mWindows.size(); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8627 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8628 | for (i=N-1; i>=0; i--) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 8629 | WindowState w = mWindows.get(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8630 | |
| 8631 | final WindowManager.LayoutParams attrs = w.mAttrs; |
| 8632 | |
| 8633 | if (w.mSurface != null) { |
| 8634 | // Execute animation. |
Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 8635 | if (w.commitFinishDrawingLocked(currentTime)) { |
| 8636 | if ((w.mAttrs.flags |
| 8637 | & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER) != 0) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8638 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 8639 | "First draw done in potential wallpaper target " + w); |
Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 8640 | wallpaperMayChange = true; |
| 8641 | } |
| 8642 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8643 | |
Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 8644 | boolean wasAnimating = w.mAnimating; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8645 | if (w.stepAnimationLocked(currentTime, dw, dh)) { |
| 8646 | animating = true; |
| 8647 | //w.dump(" "); |
| 8648 | } |
Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 8649 | if (wasAnimating && !w.mAnimating && mWallpaperTarget == w) { |
| 8650 | wallpaperMayChange = true; |
| 8651 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8652 | |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8653 | if (mPolicy.doesForceHide(w, attrs)) { |
| 8654 | if (!wasAnimating && animating) { |
Dianne Hackborn | 20cb56e | 2010-03-04 00:58:29 -0800 | [diff] [blame] | 8655 | if (DEBUG_VISIBILITY) Slog.v(TAG, |
| 8656 | "Animation done that could impact force hide: " |
| 8657 | + w); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8658 | wallpaperForceHidingChanged = true; |
Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 8659 | mFocusMayChange = true; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8660 | } else if (w.isReadyForDisplay() && w.mAnimation == null) { |
| 8661 | forceHiding = true; |
| 8662 | } |
| 8663 | } else if (mPolicy.canBeForceHidden(w, attrs)) { |
| 8664 | boolean changed; |
| 8665 | if (forceHiding) { |
| 8666 | changed = w.hideLw(false, false); |
Dianne Hackborn | 20cb56e | 2010-03-04 00:58:29 -0800 | [diff] [blame] | 8667 | if (DEBUG_VISIBILITY && changed) Slog.v(TAG, |
| 8668 | "Now policy hidden: " + w); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8669 | } else { |
| 8670 | changed = w.showLw(false, false); |
Dianne Hackborn | 20cb56e | 2010-03-04 00:58:29 -0800 | [diff] [blame] | 8671 | if (DEBUG_VISIBILITY && changed) Slog.v(TAG, |
| 8672 | "Now policy shown: " + w); |
| 8673 | if (changed) { |
| 8674 | if (wallpaperForceHidingChanged |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 8675 | && w.isVisibleNow() /*w.isReadyForDisplay()*/) { |
Dianne Hackborn | 20cb56e | 2010-03-04 00:58:29 -0800 | [diff] [blame] | 8676 | // Assume we will need to animate. If |
| 8677 | // we don't (because the wallpaper will |
| 8678 | // stay with the lock screen), then we will |
| 8679 | // clean up later. |
| 8680 | Animation a = mPolicy.createForceHideEnterAnimation(); |
| 8681 | if (a != null) { |
| 8682 | w.setAnimation(a); |
| 8683 | } |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8684 | } |
Dianne Hackborn | 20cb56e | 2010-03-04 00:58:29 -0800 | [diff] [blame] | 8685 | if (mCurrentFocus == null || |
| 8686 | mCurrentFocus.mLayer < w.mLayer) { |
| 8687 | // We are showing on to of the current |
| 8688 | // focus, so re-evaluate focus to make |
| 8689 | // sure it is correct. |
| 8690 | mFocusMayChange = true; |
| 8691 | } |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8692 | } |
| 8693 | } |
| 8694 | if (changed && (attrs.flags |
| 8695 | & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER) != 0) { |
| 8696 | wallpaperMayChange = true; |
| 8697 | } |
| 8698 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8699 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8700 | mPolicy.animatingWindowLw(w, attrs); |
| 8701 | } |
| 8702 | |
| 8703 | final AppWindowToken atoken = w.mAppToken; |
| 8704 | if (atoken != null && (!atoken.allDrawn || atoken.freezingScreen)) { |
| 8705 | if (atoken.lastTransactionSequence != transactionSequence) { |
| 8706 | atoken.lastTransactionSequence = transactionSequence; |
| 8707 | atoken.numInterestingWindows = atoken.numDrawnWindows = 0; |
| 8708 | atoken.startingDisplayed = false; |
| 8709 | } |
| 8710 | if ((w.isOnScreen() || w.mAttrs.type |
| 8711 | == WindowManager.LayoutParams.TYPE_BASE_APPLICATION) |
| 8712 | && !w.mExiting && !w.mDestroying) { |
| 8713 | if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8714 | Slog.v(TAG, "Eval win " + w + ": isDrawn=" |
Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 8715 | + w.isDrawnLw() |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8716 | + ", isAnimating=" + w.isAnimating()); |
Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 8717 | if (!w.isDrawnLw()) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8718 | Slog.v(TAG, "Not displayed: s=" + w.mSurface |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8719 | + " pv=" + w.mPolicyVisibility |
| 8720 | + " dp=" + w.mDrawPending |
| 8721 | + " cdp=" + w.mCommitDrawPending |
| 8722 | + " ah=" + w.mAttachedHidden |
| 8723 | + " th=" + atoken.hiddenRequested |
| 8724 | + " a=" + w.mAnimating); |
| 8725 | } |
| 8726 | } |
| 8727 | if (w != atoken.startingWindow) { |
| 8728 | if (!atoken.freezingScreen || !w.mAppFreezing) { |
| 8729 | atoken.numInterestingWindows++; |
Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 8730 | if (w.isDrawnLw()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8731 | atoken.numDrawnWindows++; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8732 | if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8733 | "tokenMayBeDrawn: " + atoken |
| 8734 | + " freezingScreen=" + atoken.freezingScreen |
| 8735 | + " mAppFreezing=" + w.mAppFreezing); |
| 8736 | tokenMayBeDrawn = true; |
| 8737 | } |
| 8738 | } |
Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 8739 | } else if (w.isDrawnLw()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8740 | atoken.startingDisplayed = true; |
| 8741 | } |
| 8742 | } |
| 8743 | } else if (w.mReadyToShow) { |
| 8744 | w.performShowLocked(); |
| 8745 | } |
| 8746 | } |
| 8747 | |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 8748 | changes |= mPolicy.finishAnimationLw(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8749 | |
| 8750 | if (tokenMayBeDrawn) { |
| 8751 | // See if any windows have been drawn, so they (and others |
| 8752 | // associated with them) can now be shown. |
| 8753 | final int NT = mTokenList.size(); |
| 8754 | for (i=0; i<NT; i++) { |
| 8755 | AppWindowToken wtoken = mTokenList.get(i).appWindowToken; |
| 8756 | if (wtoken == null) { |
| 8757 | continue; |
| 8758 | } |
| 8759 | if (wtoken.freezingScreen) { |
| 8760 | int numInteresting = wtoken.numInterestingWindows; |
| 8761 | if (numInteresting > 0 && wtoken.numDrawnWindows >= numInteresting) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8762 | if (DEBUG_VISIBILITY) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8763 | "allDrawn: " + wtoken |
| 8764 | + " interesting=" + numInteresting |
| 8765 | + " drawn=" + wtoken.numDrawnWindows); |
| 8766 | wtoken.showAllWindowsLocked(); |
| 8767 | unsetAppFreezingScreenLocked(wtoken, false, true); |
| 8768 | orientationChangeComplete = true; |
| 8769 | } |
| 8770 | } else if (!wtoken.allDrawn) { |
| 8771 | int numInteresting = wtoken.numInterestingWindows; |
| 8772 | if (numInteresting > 0 && wtoken.numDrawnWindows >= numInteresting) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8773 | if (DEBUG_VISIBILITY) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8774 | "allDrawn: " + wtoken |
| 8775 | + " interesting=" + numInteresting |
| 8776 | + " drawn=" + wtoken.numDrawnWindows); |
| 8777 | wtoken.allDrawn = true; |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 8778 | changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8779 | |
| 8780 | // We can now show all of the drawn windows! |
| 8781 | if (!mOpeningApps.contains(wtoken)) { |
| 8782 | wtoken.showAllWindowsLocked(); |
| 8783 | } |
| 8784 | } |
| 8785 | } |
| 8786 | } |
| 8787 | } |
| 8788 | |
| 8789 | // If we are ready to perform an app transition, check through |
| 8790 | // all of the app tokens to be shown and see if they are ready |
| 8791 | // to go. |
| 8792 | if (mAppTransitionReady) { |
| 8793 | int NN = mOpeningApps.size(); |
| 8794 | boolean goodToGo = true; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8795 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8796 | "Checking " + NN + " opening apps (frozen=" |
| 8797 | + mDisplayFrozen + " timeout=" |
| 8798 | + mAppTransitionTimeout + ")..."); |
| 8799 | if (!mDisplayFrozen && !mAppTransitionTimeout) { |
| 8800 | // If the display isn't frozen, wait to do anything until |
| 8801 | // all of the apps are ready. Otherwise just go because |
| 8802 | // we'll unfreeze the display when everyone is ready. |
| 8803 | for (i=0; i<NN && goodToGo; i++) { |
| 8804 | AppWindowToken wtoken = mOpeningApps.get(i); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8805 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8806 | "Check opening app" + wtoken + ": allDrawn=" |
| 8807 | + wtoken.allDrawn + " startingDisplayed=" |
| 8808 | + wtoken.startingDisplayed); |
| 8809 | if (!wtoken.allDrawn && !wtoken.startingDisplayed |
| 8810 | && !wtoken.startingMoved) { |
| 8811 | goodToGo = false; |
| 8812 | } |
| 8813 | } |
| 8814 | } |
| 8815 | if (goodToGo) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8816 | 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] | 8817 | int transit = mNextAppTransition; |
| 8818 | if (mSkipAppTransitionAnimation) { |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 8819 | transit = WindowManagerPolicy.TRANSIT_UNSET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8820 | } |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 8821 | mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8822 | mAppTransitionReady = false; |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8823 | mAppTransitionRunning = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8824 | mAppTransitionTimeout = false; |
| 8825 | mStartingIconInTransition = false; |
| 8826 | mSkipAppTransitionAnimation = false; |
| 8827 | |
| 8828 | mH.removeMessages(H.APP_TRANSITION_TIMEOUT); |
| 8829 | |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8830 | // If there are applications waiting to come to the |
| 8831 | // top of the stack, now is the time to move their windows. |
| 8832 | // (Note that we don't do apps going to the bottom |
| 8833 | // here -- we want to keep their windows in the old |
| 8834 | // Z-order until the animation completes.) |
| 8835 | if (mToTopApps.size() > 0) { |
| 8836 | NN = mAppTokens.size(); |
| 8837 | for (i=0; i<NN; i++) { |
| 8838 | AppWindowToken wtoken = mAppTokens.get(i); |
| 8839 | if (wtoken.sendingToTop) { |
| 8840 | wtoken.sendingToTop = false; |
| 8841 | moveAppWindowsLocked(wtoken, NN, false); |
| 8842 | } |
| 8843 | } |
| 8844 | mToTopApps.clear(); |
| 8845 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8846 | |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 8847 | WindowState oldWallpaper = mWallpaperTarget; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8848 | |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 8849 | adjustWallpaperWindowsLocked(); |
Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 8850 | wallpaperMayChange = false; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8851 | |
Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 8852 | // The top-most window will supply the layout params, |
| 8853 | // and we will determine it below. |
| 8854 | LayoutParams animLp = null; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8855 | AppWindowToken animToken = null; |
Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 8856 | int bestAnimLayer = -1; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8857 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8858 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 8859 | "New wallpaper target=" + mWallpaperTarget |
| 8860 | + ", lower target=" + mLowerWallpaperTarget |
| 8861 | + ", upper target=" + mUpperWallpaperTarget); |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 8862 | int foundWallpapers = 0; |
Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 8863 | // Do a first pass through the tokens for two |
| 8864 | // things: |
| 8865 | // (1) Determine if both the closing and opening |
| 8866 | // app token sets are wallpaper targets, in which |
| 8867 | // case special animations are needed |
| 8868 | // (since the wallpaper needs to stay static |
| 8869 | // behind them). |
| 8870 | // (2) Find the layout params of the top-most |
| 8871 | // application window in the tokens, which is |
| 8872 | // what will control the animation theme. |
| 8873 | final int NC = mClosingApps.size(); |
| 8874 | NN = NC + mOpeningApps.size(); |
| 8875 | for (i=0; i<NN; i++) { |
| 8876 | AppWindowToken wtoken; |
| 8877 | int mode; |
| 8878 | if (i < NC) { |
| 8879 | wtoken = mClosingApps.get(i); |
| 8880 | mode = 1; |
| 8881 | } else { |
| 8882 | wtoken = mOpeningApps.get(i-NC); |
| 8883 | mode = 2; |
| 8884 | } |
| 8885 | if (mLowerWallpaperTarget != null) { |
| 8886 | if (mLowerWallpaperTarget.mAppToken == wtoken |
| 8887 | || mUpperWallpaperTarget.mAppToken == wtoken) { |
| 8888 | foundWallpapers |= mode; |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 8889 | } |
| 8890 | } |
Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 8891 | if (wtoken.appFullscreen) { |
| 8892 | WindowState ws = wtoken.findMainWindow(); |
| 8893 | if (ws != null) { |
| 8894 | // If this is a compatibility mode |
| 8895 | // window, we will always use its anim. |
| 8896 | if ((ws.mAttrs.flags&FLAG_COMPATIBLE_WINDOW) != 0) { |
| 8897 | animLp = ws.mAttrs; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8898 | animToken = ws.mAppToken; |
Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 8899 | bestAnimLayer = Integer.MAX_VALUE; |
| 8900 | } else if (ws.mLayer > bestAnimLayer) { |
| 8901 | animLp = ws.mAttrs; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8902 | animToken = ws.mAppToken; |
Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 8903 | bestAnimLayer = ws.mLayer; |
| 8904 | } |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 8905 | } |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 8906 | } |
| 8907 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8908 | |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 8909 | if (foundWallpapers == 3) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8910 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 8911 | "Wallpaper animation!"); |
| 8912 | switch (transit) { |
| 8913 | case WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN: |
| 8914 | case WindowManagerPolicy.TRANSIT_TASK_OPEN: |
| 8915 | case WindowManagerPolicy.TRANSIT_TASK_TO_FRONT: |
| 8916 | transit = WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_OPEN; |
| 8917 | break; |
| 8918 | case WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE: |
| 8919 | case WindowManagerPolicy.TRANSIT_TASK_CLOSE: |
| 8920 | case WindowManagerPolicy.TRANSIT_TASK_TO_BACK: |
| 8921 | transit = WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_CLOSE; |
| 8922 | break; |
| 8923 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8924 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 8925 | "New transit: " + transit); |
| 8926 | } else if (oldWallpaper != null) { |
| 8927 | // We are transitioning from an activity with |
| 8928 | // a wallpaper to one without. |
| 8929 | transit = WindowManagerPolicy.TRANSIT_WALLPAPER_CLOSE; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8930 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 8931 | "New transit away from wallpaper: " + transit); |
| 8932 | } else if (mWallpaperTarget != null) { |
| 8933 | // We are transitioning from an activity without |
| 8934 | // a wallpaper to now showing the wallpaper |
| 8935 | transit = WindowManagerPolicy.TRANSIT_WALLPAPER_OPEN; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8936 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 8937 | "New transit into wallpaper: " + transit); |
| 8938 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8939 | |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8940 | if ((transit&WindowManagerPolicy.TRANSIT_ENTER_MASK) != 0) { |
| 8941 | mLastEnterAnimToken = animToken; |
| 8942 | mLastEnterAnimParams = animLp; |
| 8943 | } else if (mLastEnterAnimParams != null) { |
| 8944 | animLp = mLastEnterAnimParams; |
| 8945 | mLastEnterAnimToken = null; |
| 8946 | mLastEnterAnimParams = null; |
| 8947 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8948 | |
Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 8949 | // If all closing windows are obscured, then there is |
| 8950 | // no need to do an animation. This is the case, for |
| 8951 | // example, when this transition is being done behind |
| 8952 | // the lock screen. |
| 8953 | if (!mPolicy.allowAppAnimationsLw()) { |
| 8954 | animLp = null; |
| 8955 | } |
| 8956 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8957 | NN = mOpeningApps.size(); |
| 8958 | for (i=0; i<NN; i++) { |
| 8959 | AppWindowToken wtoken = mOpeningApps.get(i); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8960 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8961 | "Now opening app" + wtoken); |
| 8962 | wtoken.reportedVisible = false; |
| 8963 | wtoken.inPendingTransaction = false; |
Dianne Hackborn | 83360b3 | 2009-08-24 18:43:32 -0700 | [diff] [blame] | 8964 | wtoken.animation = null; |
Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 8965 | setTokenVisibilityLocked(wtoken, animLp, true, transit, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8966 | wtoken.updateReportedVisibilityLocked(); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8967 | wtoken.waitingToShow = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8968 | wtoken.showAllWindowsLocked(); |
| 8969 | } |
| 8970 | NN = mClosingApps.size(); |
| 8971 | for (i=0; i<NN; i++) { |
| 8972 | AppWindowToken wtoken = mClosingApps.get(i); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8973 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8974 | "Now closing app" + wtoken); |
| 8975 | wtoken.inPendingTransaction = false; |
Dianne Hackborn | 83360b3 | 2009-08-24 18:43:32 -0700 | [diff] [blame] | 8976 | wtoken.animation = null; |
Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 8977 | setTokenVisibilityLocked(wtoken, animLp, false, transit, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8978 | wtoken.updateReportedVisibilityLocked(); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8979 | wtoken.waitingToHide = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8980 | // Force the allDrawn flag, because we want to start |
| 8981 | // this guy's animations regardless of whether it's |
| 8982 | // gotten drawn. |
| 8983 | wtoken.allDrawn = true; |
| 8984 | } |
| 8985 | |
Dianne Hackborn | 8b571a8 | 2009-09-25 16:09:43 -0700 | [diff] [blame] | 8986 | mNextAppTransitionPackage = null; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8987 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8988 | mOpeningApps.clear(); |
| 8989 | mClosingApps.clear(); |
| 8990 | |
| 8991 | // This has changed the visibility of windows, so perform |
| 8992 | // a new layout to get them all up-to-date. |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 8993 | changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8994 | mLayoutNeeded = true; |
Dianne Hackborn | 20583ff | 2009-07-27 21:51:05 -0700 | [diff] [blame] | 8995 | if (!moveInputMethodWindowsIfNeededLocked(true)) { |
| 8996 | assignLayersLocked(); |
| 8997 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8998 | updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES); |
Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 8999 | mFocusMayChange = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9000 | } |
| 9001 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9002 | |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 9003 | int adjResult = 0; |
| 9004 | |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9005 | if (!animating && mAppTransitionRunning) { |
| 9006 | // We have finished the animation of an app transition. To do |
| 9007 | // this, we have delayed a lot of operations like showing and |
| 9008 | // hiding apps, moving apps in Z-order, etc. The app token list |
| 9009 | // reflects the correct Z-order, but the window list may now |
| 9010 | // be out of sync with it. So here we will just rebuild the |
| 9011 | // entire app window list. Fun! |
| 9012 | mAppTransitionRunning = false; |
| 9013 | // Clear information about apps that were moving. |
| 9014 | mToBottomApps.clear(); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9015 | |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9016 | rebuildAppWindowListLocked(); |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9017 | changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT; |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 9018 | adjResult |= ADJUST_WALLPAPER_LAYERS_CHANGED; |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9019 | moveInputMethodWindowsIfNeededLocked(false); |
| 9020 | wallpaperMayChange = true; |
Suchi Amalapurapu | c9568e3 | 2009-11-05 18:51:16 -0800 | [diff] [blame] | 9021 | // Since the window list has been rebuilt, focus might |
| 9022 | // have to be recomputed since the actual order of windows |
| 9023 | // might have changed again. |
Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 9024 | mFocusMayChange = true; |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9025 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9026 | |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9027 | if (wallpaperForceHidingChanged && changes == 0 && !mAppTransitionReady) { |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9028 | // At this point, there was a window with a wallpaper that |
| 9029 | // was force hiding other windows behind it, but now it |
| 9030 | // is going away. This may be simple -- just animate |
| 9031 | // away the wallpaper and its window -- or it may be |
| 9032 | // hard -- the wallpaper now needs to be shown behind |
| 9033 | // something that was hidden. |
| 9034 | WindowState oldWallpaper = mWallpaperTarget; |
Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 9035 | if (mLowerWallpaperTarget != null |
| 9036 | && mLowerWallpaperTarget.mAppToken != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9037 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 9038 | "wallpaperForceHiding changed with lower=" |
| 9039 | + mLowerWallpaperTarget); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9040 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 9041 | "hidden=" + mLowerWallpaperTarget.mAppToken.hidden + |
| 9042 | " hiddenRequested=" + mLowerWallpaperTarget.mAppToken.hiddenRequested); |
| 9043 | if (mLowerWallpaperTarget.mAppToken.hidden) { |
| 9044 | // The lower target has become hidden before we |
| 9045 | // actually started the animation... let's completely |
| 9046 | // re-evaluate everything. |
| 9047 | mLowerWallpaperTarget = mUpperWallpaperTarget = null; |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9048 | changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM; |
Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 9049 | } |
| 9050 | } |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 9051 | adjResult |= adjustWallpaperWindowsLocked(); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9052 | wallpaperMayChange = false; |
Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 9053 | wallpaperForceHidingChanged = false; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9054 | if (DEBUG_WALLPAPER) Slog.v(TAG, "****** OLD: " + oldWallpaper |
Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 9055 | + " NEW: " + mWallpaperTarget |
| 9056 | + " LOWER: " + mLowerWallpaperTarget); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9057 | if (mLowerWallpaperTarget == null) { |
| 9058 | // Whoops, we don't need a special wallpaper animation. |
| 9059 | // Clear them out. |
| 9060 | forceHiding = false; |
| 9061 | for (i=N-1; i>=0; i--) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 9062 | WindowState w = mWindows.get(i); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9063 | if (w.mSurface != null) { |
| 9064 | final WindowManager.LayoutParams attrs = w.mAttrs; |
Suchi Amalapurapu | c03d28b | 2009-10-28 14:32:05 -0700 | [diff] [blame] | 9065 | if (mPolicy.doesForceHide(w, attrs) && w.isVisibleLw()) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9066 | if (DEBUG_FOCUS) Slog.i(TAG, "win=" + w + " force hides other windows"); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9067 | forceHiding = true; |
| 9068 | } else if (mPolicy.canBeForceHidden(w, attrs)) { |
| 9069 | if (!w.mAnimating) { |
| 9070 | // We set the animation above so it |
| 9071 | // is not yet running. |
| 9072 | w.clearAnimation(); |
| 9073 | } |
| 9074 | } |
| 9075 | } |
| 9076 | } |
| 9077 | } |
| 9078 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9079 | |
Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 9080 | if (wallpaperMayChange) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9081 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 9082 | "Wallpaper may change! Adjusting"); |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 9083 | adjResult |= adjustWallpaperWindowsLocked(); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9084 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9085 | |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9086 | if ((adjResult&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9087 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9088 | "Wallpaper layer changed: assigning layers + relayout"); |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9089 | changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9090 | assignLayersLocked(); |
| 9091 | } else if ((adjResult&ADJUST_WALLPAPER_VISIBILITY_CHANGED) != 0) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9092 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9093 | "Wallpaper visibility changed: relayout"); |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9094 | changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9095 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9096 | |
Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 9097 | if (mFocusMayChange) { |
| 9098 | mFocusMayChange = false; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9099 | if (updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES)) { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9100 | changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9101 | adjResult = 0; |
Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 9102 | } |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9103 | } |
| 9104 | |
| 9105 | if (mLayoutNeeded) { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9106 | changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT; |
Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 9107 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9108 | |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9109 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "*** ANIM STEP: changes=0x" |
| 9110 | + Integer.toHexString(changes)); |
Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 9111 | |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 9112 | mInputMonitor.updateInputWindowsLw(); |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9113 | } while (changes != 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9114 | |
| 9115 | // THIRD LOOP: Update the surfaces of all windows. |
| 9116 | |
| 9117 | final boolean someoneLosingFocus = mLosingFocus.size() != 0; |
| 9118 | |
| 9119 | boolean obscured = false; |
| 9120 | boolean blurring = false; |
| 9121 | boolean dimming = false; |
| 9122 | boolean covered = false; |
Dianne Hackborn | 9ed4a4b | 2009-03-25 17:10:37 -0700 | [diff] [blame] | 9123 | boolean syswin = false; |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 9124 | boolean backgroundFillerShown = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9125 | |
Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 9126 | final int N = mWindows.size(); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9127 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9128 | for (i=N-1; i>=0; i--) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 9129 | WindowState w = mWindows.get(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9130 | |
| 9131 | boolean displayed = false; |
| 9132 | final WindowManager.LayoutParams attrs = w.mAttrs; |
| 9133 | final int attrFlags = attrs.flags; |
| 9134 | |
| 9135 | if (w.mSurface != null) { |
Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 9136 | // XXX NOTE: The logic here could be improved. We have |
| 9137 | // the decision about whether to resize a window separated |
| 9138 | // from whether to hide the surface. This can cause us to |
| 9139 | // resize a surface even if we are going to hide it. You |
| 9140 | // can see this by (1) holding device in landscape mode on |
| 9141 | // home screen; (2) tapping browser icon (device will rotate |
| 9142 | // to landscape; (3) tap home. The wallpaper will be resized |
| 9143 | // in step 2 but then immediately hidden, causing us to |
| 9144 | // have to resize and then redraw it again in step 3. It |
| 9145 | // would be nice to figure out how to avoid this, but it is |
| 9146 | // difficult because we do need to resize surfaces in some |
| 9147 | // cases while they are hidden such as when first showing a |
| 9148 | // window. |
| 9149 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9150 | w.computeShownFrameLocked(); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9151 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9152 | TAG, "Placing surface #" + i + " " + w.mSurface |
| 9153 | + ": new=" + w.mShownFrame + ", old=" |
| 9154 | + w.mLastShownFrame); |
| 9155 | |
| 9156 | boolean resize; |
| 9157 | int width, height; |
| 9158 | if ((w.mAttrs.flags & w.mAttrs.FLAG_SCALED) != 0) { |
| 9159 | resize = w.mLastRequestedWidth != w.mRequestedWidth || |
| 9160 | w.mLastRequestedHeight != w.mRequestedHeight; |
| 9161 | // for a scaled surface, we just want to use |
| 9162 | // the requested size. |
| 9163 | width = w.mRequestedWidth; |
| 9164 | height = w.mRequestedHeight; |
| 9165 | w.mLastRequestedWidth = width; |
| 9166 | w.mLastRequestedHeight = height; |
| 9167 | w.mLastShownFrame.set(w.mShownFrame); |
| 9168 | try { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9169 | if (SHOW_TRANSACTIONS) logSurface(w, |
| 9170 | "POS " + w.mShownFrame.left |
| 9171 | + ", " + w.mShownFrame.top, null); |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 9172 | w.mSurfaceX = w.mShownFrame.left; |
| 9173 | w.mSurfaceY = w.mShownFrame.top; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9174 | w.mSurface.setPosition(w.mShownFrame.left, w.mShownFrame.top); |
| 9175 | } catch (RuntimeException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9176 | Slog.w(TAG, "Error positioning surface in " + w, e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9177 | if (!recoveringMemory) { |
| 9178 | reclaimSomeSurfaceMemoryLocked(w, "position"); |
| 9179 | } |
| 9180 | } |
| 9181 | } else { |
| 9182 | resize = !w.mLastShownFrame.equals(w.mShownFrame); |
| 9183 | width = w.mShownFrame.width(); |
| 9184 | height = w.mShownFrame.height(); |
| 9185 | w.mLastShownFrame.set(w.mShownFrame); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9186 | } |
| 9187 | |
| 9188 | if (resize) { |
| 9189 | if (width < 1) width = 1; |
| 9190 | if (height < 1) height = 1; |
| 9191 | if (w.mSurface != null) { |
| 9192 | try { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9193 | if (SHOW_TRANSACTIONS) logSurface(w, |
| 9194 | "POS " + w.mShownFrame.left + "," |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 9195 | + w.mShownFrame.top + " SIZE " |
| 9196 | + w.mShownFrame.width() + "x" |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9197 | + w.mShownFrame.height(), null); |
Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 9198 | w.mSurfaceResized = true; |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 9199 | w.mSurfaceW = width; |
| 9200 | w.mSurfaceH = height; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9201 | w.mSurface.setSize(width, height); |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 9202 | w.mSurfaceX = w.mShownFrame.left; |
| 9203 | w.mSurfaceY = w.mShownFrame.top; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9204 | w.mSurface.setPosition(w.mShownFrame.left, |
| 9205 | w.mShownFrame.top); |
| 9206 | } catch (RuntimeException e) { |
| 9207 | // If something goes wrong with the surface (such |
| 9208 | // as running out of memory), don't take down the |
| 9209 | // entire system. |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9210 | Slog.e(TAG, "Failure updating surface of " + w |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9211 | + "size=(" + width + "x" + height |
| 9212 | + "), pos=(" + w.mShownFrame.left |
| 9213 | + "," + w.mShownFrame.top + ")", e); |
| 9214 | if (!recoveringMemory) { |
| 9215 | reclaimSomeSurfaceMemoryLocked(w, "size"); |
| 9216 | } |
| 9217 | } |
| 9218 | } |
| 9219 | } |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 9220 | if (!w.mAppFreezing && w.mLayoutSeq == mLayoutSeq) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9221 | w.mContentInsetsChanged = |
| 9222 | !w.mLastContentInsets.equals(w.mContentInsets); |
| 9223 | w.mVisibleInsetsChanged = |
| 9224 | !w.mLastVisibleInsets.equals(w.mVisibleInsets); |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 9225 | boolean configChanged = |
| 9226 | w.mConfiguration != mCurConfiguration |
| 9227 | && (w.mConfiguration == null |
| 9228 | || mCurConfiguration.diff(w.mConfiguration) != 0); |
Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 9229 | if (DEBUG_CONFIGURATION && configChanged) { |
| 9230 | Slog.v(TAG, "Win " + w + " config changed: " |
| 9231 | + mCurConfiguration); |
| 9232 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9233 | if (localLOGV) Slog.v(TAG, "Resizing " + w |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 9234 | + ": configChanged=" + configChanged |
| 9235 | + " last=" + w.mLastFrame + " frame=" + w.mFrame); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9236 | if (!w.mLastFrame.equals(w.mFrame) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9237 | || w.mContentInsetsChanged |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 9238 | || w.mVisibleInsetsChanged |
Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 9239 | || w.mSurfaceResized |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 9240 | || configChanged) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9241 | w.mLastFrame.set(w.mFrame); |
| 9242 | w.mLastContentInsets.set(w.mContentInsets); |
| 9243 | w.mLastVisibleInsets.set(w.mVisibleInsets); |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 9244 | // If the screen is currently frozen, then keep |
| 9245 | // it frozen until this window draws at its new |
| 9246 | // orientation. |
| 9247 | if (mDisplayFrozen) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9248 | if (DEBUG_ORIENTATION) Slog.v(TAG, |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 9249 | "Resizing while display frozen: " + w); |
| 9250 | w.mOrientationChanging = true; |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 9251 | if (!mWindowsFreezingScreen) { |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 9252 | mWindowsFreezingScreen = true; |
| 9253 | // XXX should probably keep timeout from |
| 9254 | // when we first froze the display. |
| 9255 | mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT); |
| 9256 | mH.sendMessageDelayed(mH.obtainMessage( |
| 9257 | H.WINDOW_FREEZE_TIMEOUT), 2000); |
| 9258 | } |
| 9259 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9260 | // If the orientation is changing, then we need to |
| 9261 | // hold off on unfreezing the display until this |
| 9262 | // window has been redrawn; to do that, we need |
| 9263 | // to go through the process of getting informed |
| 9264 | // by the application when it has finished drawing. |
| 9265 | if (w.mOrientationChanging) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9266 | if (DEBUG_ORIENTATION) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9267 | "Orientation start waiting for draw in " |
| 9268 | + w + ", surface " + w.mSurface); |
| 9269 | w.mDrawPending = true; |
| 9270 | w.mCommitDrawPending = false; |
| 9271 | w.mReadyToShow = false; |
| 9272 | if (w.mAppToken != null) { |
| 9273 | w.mAppToken.allDrawn = false; |
| 9274 | } |
| 9275 | } |
Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 9276 | if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9277 | "Resizing window " + w + " to " + w.mFrame); |
| 9278 | mResizingWindows.add(w); |
| 9279 | } else if (w.mOrientationChanging) { |
| 9280 | if (!w.mDrawPending && !w.mCommitDrawPending) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9281 | if (DEBUG_ORIENTATION) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9282 | "Orientation not waiting for draw in " |
| 9283 | + w + ", surface " + w.mSurface); |
| 9284 | w.mOrientationChanging = false; |
| 9285 | } |
| 9286 | } |
| 9287 | } |
| 9288 | |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9289 | if (w.mAttachedHidden || !w.isReadyForDisplay()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9290 | if (!w.mLastHidden) { |
| 9291 | //dump(); |
Dianne Hackborn | 5943c20 | 2010-04-12 21:36:49 -0700 | [diff] [blame] | 9292 | if (DEBUG_CONFIGURATION) Slog.v(TAG, "Window hiding: waitingToShow=" |
| 9293 | + w.mRootToken.waitingToShow + " polvis=" |
| 9294 | + w.mPolicyVisibility + " atthid=" |
| 9295 | + w.mAttachedHidden + " tokhid=" |
| 9296 | + w.mRootToken.hidden + " vis=" |
| 9297 | + w.mViewVisibility); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9298 | w.mLastHidden = true; |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9299 | if (SHOW_TRANSACTIONS) logSurface(w, |
| 9300 | "HIDE (performLayout)", null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9301 | if (w.mSurface != null) { |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 9302 | w.mSurfaceShown = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9303 | try { |
| 9304 | w.mSurface.hide(); |
| 9305 | } catch (RuntimeException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9306 | Slog.w(TAG, "Exception hiding surface in " + w); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9307 | } |
| 9308 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9309 | } |
| 9310 | // If we are waiting for this window to handle an |
| 9311 | // orientation change, well, it is hidden, so |
| 9312 | // doesn't really matter. Note that this does |
| 9313 | // introduce a potential glitch if the window |
| 9314 | // becomes unhidden before it has drawn for the |
| 9315 | // new orientation. |
| 9316 | if (w.mOrientationChanging) { |
| 9317 | w.mOrientationChanging = false; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9318 | if (DEBUG_ORIENTATION) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9319 | "Orientation change skips hidden " + w); |
| 9320 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9321 | } else if (w.mLastLayer != w.mAnimLayer |
| 9322 | || w.mLastAlpha != w.mShownAlpha |
| 9323 | || w.mLastDsDx != w.mDsDx |
| 9324 | || w.mLastDtDx != w.mDtDx |
| 9325 | || w.mLastDsDy != w.mDsDy |
| 9326 | || w.mLastDtDy != w.mDtDy |
| 9327 | || w.mLastHScale != w.mHScale |
| 9328 | || w.mLastVScale != w.mVScale |
| 9329 | || w.mLastHidden) { |
| 9330 | displayed = true; |
| 9331 | w.mLastAlpha = w.mShownAlpha; |
| 9332 | w.mLastLayer = w.mAnimLayer; |
| 9333 | w.mLastDsDx = w.mDsDx; |
| 9334 | w.mLastDtDx = w.mDtDx; |
| 9335 | w.mLastDsDy = w.mDsDy; |
| 9336 | w.mLastDtDy = w.mDtDy; |
| 9337 | w.mLastHScale = w.mHScale; |
| 9338 | w.mLastVScale = w.mVScale; |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9339 | if (SHOW_TRANSACTIONS) logSurface(w, |
| 9340 | "alpha=" + w.mShownAlpha + " layer=" + w.mAnimLayer |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 9341 | + " matrix=[" + (w.mDsDx*w.mHScale) |
| 9342 | + "," + (w.mDtDx*w.mVScale) |
| 9343 | + "][" + (w.mDsDy*w.mHScale) |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9344 | + "," + (w.mDtDy*w.mVScale) + "]", null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9345 | if (w.mSurface != null) { |
| 9346 | try { |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 9347 | w.mSurfaceAlpha = w.mShownAlpha; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9348 | w.mSurface.setAlpha(w.mShownAlpha); |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 9349 | w.mSurfaceLayer = w.mAnimLayer; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9350 | w.mSurface.setLayer(w.mAnimLayer); |
| 9351 | w.mSurface.setMatrix( |
| 9352 | w.mDsDx*w.mHScale, w.mDtDx*w.mVScale, |
| 9353 | w.mDsDy*w.mHScale, w.mDtDy*w.mVScale); |
| 9354 | } catch (RuntimeException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9355 | Slog.w(TAG, "Error updating surface in " + w, e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9356 | if (!recoveringMemory) { |
| 9357 | reclaimSomeSurfaceMemoryLocked(w, "update"); |
| 9358 | } |
| 9359 | } |
| 9360 | } |
| 9361 | |
| 9362 | if (w.mLastHidden && !w.mDrawPending |
| 9363 | && !w.mCommitDrawPending |
| 9364 | && !w.mReadyToShow) { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9365 | if (SHOW_TRANSACTIONS) logSurface(w, |
| 9366 | "SHOW (performLayout)", null); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9367 | if (DEBUG_VISIBILITY) Slog.v(TAG, "Showing " + w |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9368 | + " during relayout"); |
| 9369 | if (showSurfaceRobustlyLocked(w)) { |
| 9370 | w.mHasDrawn = true; |
| 9371 | w.mLastHidden = false; |
| 9372 | } else { |
| 9373 | w.mOrientationChanging = false; |
| 9374 | } |
| 9375 | } |
| 9376 | if (w.mSurface != null) { |
| 9377 | w.mToken.hasVisible = true; |
| 9378 | } |
| 9379 | } else { |
| 9380 | displayed = true; |
| 9381 | } |
| 9382 | |
| 9383 | if (displayed) { |
| 9384 | if (!covered) { |
Romain Guy | 980a938 | 2010-01-08 15:06:28 -0800 | [diff] [blame] | 9385 | if (attrs.width == LayoutParams.MATCH_PARENT |
| 9386 | && attrs.height == LayoutParams.MATCH_PARENT) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9387 | covered = true; |
| 9388 | } |
| 9389 | } |
| 9390 | if (w.mOrientationChanging) { |
| 9391 | if (w.mDrawPending || w.mCommitDrawPending) { |
| 9392 | orientationChangeComplete = false; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9393 | if (DEBUG_ORIENTATION) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9394 | "Orientation continue waiting for draw in " + w); |
| 9395 | } else { |
| 9396 | w.mOrientationChanging = false; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9397 | if (DEBUG_ORIENTATION) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9398 | "Orientation change complete in " + w); |
| 9399 | } |
| 9400 | } |
| 9401 | w.mToken.hasVisible = true; |
| 9402 | } |
| 9403 | } else if (w.mOrientationChanging) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9404 | if (DEBUG_ORIENTATION) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9405 | "Orientation change skips hidden " + w); |
| 9406 | w.mOrientationChanging = false; |
| 9407 | } |
| 9408 | |
| 9409 | final boolean canBeSeen = w.isDisplayedLw(); |
| 9410 | |
| 9411 | if (someoneLosingFocus && w == mCurrentFocus && canBeSeen) { |
| 9412 | focusDisplayed = true; |
| 9413 | } |
| 9414 | |
Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 9415 | final boolean obscuredChanged = w.mObscured != obscured; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9416 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9417 | // Update effect. |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 9418 | if (!(w.mObscured=obscured)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9419 | if (w.mSurface != null) { |
| 9420 | if ((attrFlags&FLAG_KEEP_SCREEN_ON) != 0) { |
| 9421 | holdScreen = w.mSession; |
| 9422 | } |
Dianne Hackborn | 9ed4a4b | 2009-03-25 17:10:37 -0700 | [diff] [blame] | 9423 | if (!syswin && w.mAttrs.screenBrightness >= 0 |
| 9424 | && screenBrightness < 0) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9425 | screenBrightness = w.mAttrs.screenBrightness; |
| 9426 | } |
Mike Lockwood | fb73f79 | 2009-11-20 11:31:18 -0500 | [diff] [blame] | 9427 | if (!syswin && w.mAttrs.buttonBrightness >= 0 |
| 9428 | && buttonBrightness < 0) { |
| 9429 | buttonBrightness = w.mAttrs.buttonBrightness; |
| 9430 | } |
Mike Lockwood | 46af6a8 | 2010-03-09 08:28:22 -0500 | [diff] [blame] | 9431 | if (canBeSeen |
| 9432 | && (attrs.type == WindowManager.LayoutParams.TYPE_SYSTEM_DIALOG |
| 9433 | || attrs.type == WindowManager.LayoutParams.TYPE_KEYGUARD |
| 9434 | || attrs.type == WindowManager.LayoutParams.TYPE_SYSTEM_ERROR)) { |
Dianne Hackborn | 9ed4a4b | 2009-03-25 17:10:37 -0700 | [diff] [blame] | 9435 | syswin = true; |
| 9436 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9437 | } |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 9438 | |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 9439 | boolean opaqueDrawn = canBeSeen && w.isOpaqueDrawn(); |
| 9440 | if (opaqueDrawn && w.isFullscreen(dw, dh)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9441 | // This window completely covers everything behind it, |
| 9442 | // so we want to leave all of them as unblurred (for |
| 9443 | // performance reasons). |
| 9444 | obscured = true; |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 9445 | } else if (opaqueDrawn && w.needsBackgroundFiller(dw, dh)) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9446 | if (SHOW_TRANSACTIONS) Slog.d(TAG, "showing background filler"); |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 9447 | // This window is in compatibility mode, and needs background filler. |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 9448 | obscured = true; |
| 9449 | if (mBackgroundFillerSurface == null) { |
| 9450 | try { |
| 9451 | mBackgroundFillerSurface = new Surface(mFxSession, 0, |
Mathias Agopian | 5d26c1e | 2010-03-01 16:09:43 -0800 | [diff] [blame] | 9452 | "BackGroundFiller", |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 9453 | 0, dw, dh, |
| 9454 | PixelFormat.OPAQUE, |
| 9455 | Surface.FX_SURFACE_NORMAL); |
| 9456 | } catch (Exception e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9457 | Slog.e(TAG, "Exception creating filler surface", e); |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 9458 | } |
| 9459 | } |
| 9460 | try { |
| 9461 | mBackgroundFillerSurface.setPosition(0, 0); |
| 9462 | mBackgroundFillerSurface.setSize(dw, dh); |
| 9463 | // Using the same layer as Dim because they will never be shown at the |
| 9464 | // same time. |
| 9465 | mBackgroundFillerSurface.setLayer(w.mAnimLayer - 1); |
| 9466 | mBackgroundFillerSurface.show(); |
| 9467 | } catch (RuntimeException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9468 | Slog.e(TAG, "Exception showing filler surface"); |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 9469 | } |
| 9470 | backgroundFillerShown = true; |
| 9471 | mBackgroundFillerShown = true; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9472 | } else if (canBeSeen && !obscured && |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9473 | (attrFlags&FLAG_BLUR_BEHIND|FLAG_DIM_BEHIND) != 0) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9474 | if (localLOGV) Slog.v(TAG, "Win " + w |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9475 | + ": blurring=" + blurring |
| 9476 | + " obscured=" + obscured |
| 9477 | + " displayed=" + displayed); |
| 9478 | if ((attrFlags&FLAG_DIM_BEHIND) != 0) { |
| 9479 | if (!dimming) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9480 | //Slog.i(TAG, "DIM BEHIND: " + w); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9481 | dimming = true; |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 9482 | if (mDimAnimator == null) { |
| 9483 | mDimAnimator = new DimAnimator(mFxSession); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9484 | } |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 9485 | mDimAnimator.show(dw, dh); |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 9486 | mDimAnimator.updateParameters(w, currentTime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9487 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9488 | } |
| 9489 | if ((attrFlags&FLAG_BLUR_BEHIND) != 0) { |
| 9490 | if (!blurring) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9491 | //Slog.i(TAG, "BLUR BEHIND: " + w); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9492 | blurring = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9493 | if (mBlurSurface == null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9494 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR " |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9495 | + mBlurSurface + ": CREATE"); |
| 9496 | try { |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9497 | mBlurSurface = new Surface(mFxSession, 0, |
Mathias Agopian | 5d26c1e | 2010-03-01 16:09:43 -0800 | [diff] [blame] | 9498 | "BlurSurface", |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9499 | -1, 16, 16, |
| 9500 | PixelFormat.OPAQUE, |
| 9501 | Surface.FX_SURFACE_BLUR); |
| 9502 | } catch (Exception e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9503 | Slog.e(TAG, "Exception creating Blur surface", e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9504 | } |
| 9505 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9506 | if (mBlurSurface != null) { |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 9507 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR " |
| 9508 | + mBlurSurface + ": pos=(0,0) (" + |
| 9509 | dw + "x" + dh + "), layer=" + (w.mAnimLayer-1)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9510 | mBlurSurface.setPosition(0, 0); |
| 9511 | mBlurSurface.setSize(dw, dh); |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 9512 | mBlurSurface.setLayer(w.mAnimLayer-2); |
| 9513 | if (!mBlurShown) { |
| 9514 | try { |
| 9515 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR " |
| 9516 | + mBlurSurface + ": SHOW"); |
| 9517 | mBlurSurface.show(); |
| 9518 | } catch (RuntimeException e) { |
| 9519 | Slog.w(TAG, "Failure showing blur surface", e); |
| 9520 | } |
| 9521 | mBlurShown = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9522 | } |
| 9523 | } |
| 9524 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9525 | } |
| 9526 | } |
| 9527 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9528 | |
Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 9529 | if (obscuredChanged && mWallpaperTarget == w) { |
| 9530 | // This is the wallpaper target and its obscured state |
| 9531 | // changed... make sure the current wallaper's visibility |
| 9532 | // has been updated accordingly. |
| 9533 | updateWallpaperVisibilityLocked(); |
| 9534 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9535 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9536 | |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 9537 | if (backgroundFillerShown == false && mBackgroundFillerShown) { |
| 9538 | mBackgroundFillerShown = false; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9539 | if (SHOW_TRANSACTIONS) Slog.d(TAG, "hiding background filler"); |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 9540 | try { |
| 9541 | mBackgroundFillerSurface.hide(); |
| 9542 | } catch (RuntimeException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9543 | Slog.e(TAG, "Exception hiding filler surface", e); |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 9544 | } |
| 9545 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9546 | |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 9547 | if (mDimAnimator != null && mDimAnimator.mDimShown) { |
Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 9548 | animating |= mDimAnimator.updateSurface(dimming, currentTime, |
| 9549 | mDisplayFrozen || !mPolicy.isScreenOn()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9550 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9551 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9552 | if (!blurring && mBlurShown) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9553 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR " + mBlurSurface |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9554 | + ": HIDE"); |
| 9555 | try { |
| 9556 | mBlurSurface.hide(); |
| 9557 | } catch (IllegalArgumentException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9558 | Slog.w(TAG, "Illegal argument exception hiding blur surface"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9559 | } |
| 9560 | mBlurShown = false; |
| 9561 | } |
| 9562 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9563 | if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9564 | } catch (RuntimeException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9565 | Slog.e(TAG, "Unhandled exception in Window Manager", e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9566 | } |
| 9567 | |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 9568 | mInputMonitor.updateInputWindowsLw(); |
| 9569 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9570 | Surface.closeTransaction(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9571 | |
Dianne Hackborn | b9fb170 | 2010-08-23 16:49:02 -0700 | [diff] [blame^] | 9572 | if (mWatermark != null) { |
| 9573 | mWatermark.drawIfNeeded(); |
| 9574 | } |
| 9575 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9576 | if (DEBUG_ORIENTATION && mDisplayFrozen) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9577 | "With display frozen, orientationChangeComplete=" |
| 9578 | + orientationChangeComplete); |
| 9579 | if (orientationChangeComplete) { |
| 9580 | if (mWindowsFreezingScreen) { |
| 9581 | mWindowsFreezingScreen = false; |
| 9582 | mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT); |
| 9583 | } |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 9584 | stopFreezingDisplayLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9585 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9586 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9587 | i = mResizingWindows.size(); |
| 9588 | if (i > 0) { |
| 9589 | do { |
| 9590 | i--; |
| 9591 | WindowState win = mResizingWindows.get(i); |
| 9592 | try { |
Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 9593 | if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG, |
| 9594 | "Reporting new frame to " + win + ": " + win.mFrame); |
Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 9595 | int diff = 0; |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 9596 | boolean configChanged = |
| 9597 | win.mConfiguration != mCurConfiguration |
| 9598 | && (win.mConfiguration == null |
Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 9599 | || (diff=mCurConfiguration.diff(win.mConfiguration)) != 0); |
| 9600 | if ((DEBUG_RESIZE || DEBUG_ORIENTATION || DEBUG_CONFIGURATION) |
| 9601 | && configChanged) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9602 | Slog.i(TAG, "Sending new config to window " + win + ": " |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 9603 | + win.mFrame.width() + "x" + win.mFrame.height() |
Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 9604 | + " / " + mCurConfiguration + " / 0x" |
| 9605 | + Integer.toHexString(diff)); |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 9606 | } |
Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 9607 | win.mConfiguration = mCurConfiguration; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9608 | win.mClient.resized(win.mFrame.width(), |
| 9609 | win.mFrame.height(), win.mLastContentInsets, |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 9610 | win.mLastVisibleInsets, win.mDrawPending, |
| 9611 | configChanged ? win.mConfiguration : null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9612 | win.mContentInsetsChanged = false; |
| 9613 | win.mVisibleInsetsChanged = false; |
Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 9614 | win.mSurfaceResized = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9615 | } catch (RemoteException e) { |
| 9616 | win.mOrientationChanging = false; |
| 9617 | } |
| 9618 | } while (i > 0); |
| 9619 | mResizingWindows.clear(); |
| 9620 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9621 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9622 | // Destroy the surface of any windows that are no longer visible. |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 9623 | boolean wallpaperDestroyed = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9624 | i = mDestroySurface.size(); |
| 9625 | if (i > 0) { |
| 9626 | do { |
| 9627 | i--; |
| 9628 | WindowState win = mDestroySurface.get(i); |
| 9629 | win.mDestroying = false; |
| 9630 | if (mInputMethodWindow == win) { |
| 9631 | mInputMethodWindow = null; |
| 9632 | } |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 9633 | if (win == mWallpaperTarget) { |
| 9634 | wallpaperDestroyed = true; |
| 9635 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9636 | win.destroySurfaceLocked(); |
| 9637 | } while (i > 0); |
| 9638 | mDestroySurface.clear(); |
| 9639 | } |
| 9640 | |
| 9641 | // Time to remove any exiting tokens? |
| 9642 | for (i=mExitingTokens.size()-1; i>=0; i--) { |
| 9643 | WindowToken token = mExitingTokens.get(i); |
| 9644 | if (!token.hasVisible) { |
| 9645 | mExitingTokens.remove(i); |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 9646 | if (token.windowType == TYPE_WALLPAPER) { |
| 9647 | mWallpaperTokens.remove(token); |
| 9648 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9649 | } |
| 9650 | } |
| 9651 | |
| 9652 | // Time to remove any exiting applications? |
| 9653 | for (i=mExitingAppTokens.size()-1; i>=0; i--) { |
| 9654 | AppWindowToken token = mExitingAppTokens.get(i); |
| 9655 | if (!token.hasVisible && !mClosingApps.contains(token)) { |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 9656 | // Make sure there is no animation running on this token, |
| 9657 | // so any windows associated with it will be removed as |
| 9658 | // soon as their animations are complete |
| 9659 | token.animation = null; |
| 9660 | token.animating = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9661 | mAppTokens.remove(token); |
| 9662 | mExitingAppTokens.remove(i); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9663 | if (mLastEnterAnimToken == token) { |
| 9664 | mLastEnterAnimToken = null; |
| 9665 | mLastEnterAnimParams = null; |
| 9666 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9667 | } |
| 9668 | } |
| 9669 | |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9670 | boolean needRelayout = false; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9671 | |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9672 | if (!animating && mAppTransitionRunning) { |
| 9673 | // We have finished the animation of an app transition. To do |
| 9674 | // this, we have delayed a lot of operations like showing and |
| 9675 | // hiding apps, moving apps in Z-order, etc. The app token list |
| 9676 | // reflects the correct Z-order, but the window list may now |
| 9677 | // be out of sync with it. So here we will just rebuild the |
| 9678 | // entire app window list. Fun! |
| 9679 | mAppTransitionRunning = false; |
| 9680 | needRelayout = true; |
| 9681 | rebuildAppWindowListLocked(); |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 9682 | assignLayersLocked(); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9683 | // Clear information about apps that were moving. |
| 9684 | mToBottomApps.clear(); |
| 9685 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9686 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9687 | if (focusDisplayed) { |
| 9688 | mH.sendEmptyMessage(H.REPORT_LOSING_FOCUS); |
| 9689 | } |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 9690 | if (wallpaperDestroyed) { |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 9691 | needRelayout = adjustWallpaperWindowsLocked() != 0; |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 9692 | } |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9693 | if (needRelayout) { |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 9694 | requestAnimationLocked(0); |
| 9695 | } else if (animating) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9696 | requestAnimationLocked(currentTime+(1000/60)-SystemClock.uptimeMillis()); |
| 9697 | } |
Dianne Hackborn | ce73c1e | 2010-04-12 23:11:38 -0700 | [diff] [blame] | 9698 | |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 9699 | mInputMonitor.updateInputWindowsLw(); |
| 9700 | |
Dianne Hackborn | ce73c1e | 2010-04-12 23:11:38 -0700 | [diff] [blame] | 9701 | if (DEBUG_FREEZE) Slog.v(TAG, "Layout: mDisplayFrozen=" + mDisplayFrozen |
| 9702 | + " holdScreen=" + holdScreen); |
| 9703 | if (!mDisplayFrozen) { |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 9704 | setHoldScreenLocked(holdScreen != null); |
Dianne Hackborn | ce73c1e | 2010-04-12 23:11:38 -0700 | [diff] [blame] | 9705 | if (screenBrightness < 0 || screenBrightness > 1.0f) { |
| 9706 | mPowerManager.setScreenBrightnessOverride(-1); |
| 9707 | } else { |
| 9708 | mPowerManager.setScreenBrightnessOverride((int) |
| 9709 | (screenBrightness * Power.BRIGHTNESS_ON)); |
| 9710 | } |
| 9711 | if (buttonBrightness < 0 || buttonBrightness > 1.0f) { |
| 9712 | mPowerManager.setButtonBrightnessOverride(-1); |
| 9713 | } else { |
| 9714 | mPowerManager.setButtonBrightnessOverride((int) |
| 9715 | (buttonBrightness * Power.BRIGHTNESS_ON)); |
| 9716 | } |
| 9717 | if (holdScreen != mHoldingScreenOn) { |
| 9718 | mHoldingScreenOn = holdScreen; |
| 9719 | Message m = mH.obtainMessage(H.HOLD_SCREEN_CHANGED, holdScreen); |
| 9720 | mH.sendMessage(m); |
| 9721 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9722 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9723 | |
Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 9724 | if (mTurnOnScreen) { |
Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 9725 | if (DEBUG_VISIBILITY) Slog.v(TAG, "Turning screen on after layout!"); |
Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 9726 | mPowerManager.userActivity(SystemClock.uptimeMillis(), false, |
| 9727 | LocalPowerManager.BUTTON_EVENT, true); |
| 9728 | mTurnOnScreen = false; |
| 9729 | } |
Dianne Hackborn | f3bea9c | 2009-12-09 18:26:21 -0800 | [diff] [blame] | 9730 | |
| 9731 | // Check to see if we are now in a state where the screen should |
| 9732 | // be enabled, because the window obscured flags have changed. |
| 9733 | enableScreenIfNeededLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9734 | } |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 9735 | |
| 9736 | /** |
| 9737 | * Must be called with the main window manager lock held. |
| 9738 | */ |
| 9739 | void setHoldScreenLocked(boolean holding) { |
| 9740 | boolean state = mHoldingScreenWakeLock.isHeld(); |
| 9741 | if (holding != state) { |
| 9742 | if (holding) { |
| 9743 | mHoldingScreenWakeLock.acquire(); |
| 9744 | } else { |
| 9745 | mPolicy.screenOnStoppedLw(); |
| 9746 | mHoldingScreenWakeLock.release(); |
| 9747 | } |
| 9748 | } |
| 9749 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9750 | |
| 9751 | void requestAnimationLocked(long delay) { |
| 9752 | if (!mAnimationPending) { |
| 9753 | mAnimationPending = true; |
| 9754 | mH.sendMessageDelayed(mH.obtainMessage(H.ANIMATE), delay); |
| 9755 | } |
| 9756 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9757 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9758 | /** |
| 9759 | * Have the surface flinger show a surface, robustly dealing with |
| 9760 | * error conditions. In particular, if there is not enough memory |
| 9761 | * to show the surface, then we will try to get rid of other surfaces |
| 9762 | * in order to succeed. |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9763 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9764 | * @return Returns true if the surface was successfully shown. |
| 9765 | */ |
| 9766 | boolean showSurfaceRobustlyLocked(WindowState win) { |
| 9767 | try { |
| 9768 | if (win.mSurface != null) { |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 9769 | win.mSurfaceShown = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9770 | win.mSurface.show(); |
Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 9771 | if (win.mTurnOnScreen) { |
Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 9772 | if (DEBUG_VISIBILITY) Slog.v(TAG, |
| 9773 | "Show surface turning screen on: " + win); |
Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 9774 | win.mTurnOnScreen = false; |
| 9775 | mTurnOnScreen = true; |
| 9776 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9777 | } |
| 9778 | return true; |
| 9779 | } catch (RuntimeException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9780 | 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] | 9781 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9782 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9783 | reclaimSomeSurfaceMemoryLocked(win, "show"); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9784 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9785 | return false; |
| 9786 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9787 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9788 | void reclaimSomeSurfaceMemoryLocked(WindowState win, String operation) { |
| 9789 | final Surface surface = win.mSurface; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9790 | |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9791 | EventLog.writeEvent(EventLogTags.WM_NO_SURFACE_MEMORY, win.toString(), |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9792 | win.mSession.mPid, operation); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9793 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9794 | if (mForceRemoves == null) { |
| 9795 | mForceRemoves = new ArrayList<WindowState>(); |
| 9796 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9797 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9798 | long callingIdentity = Binder.clearCallingIdentity(); |
| 9799 | try { |
| 9800 | // There was some problem... first, do a sanity check of the |
| 9801 | // window list to make sure we haven't left any dangling surfaces |
| 9802 | // around. |
| 9803 | int N = mWindows.size(); |
| 9804 | boolean leakedSurface = false; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9805 | 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] | 9806 | for (int i=0; i<N; i++) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 9807 | WindowState ws = mWindows.get(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9808 | if (ws.mSurface != null) { |
| 9809 | if (!mSessions.contains(ws.mSession)) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9810 | Slog.w(TAG, "LEAKED SURFACE (session doesn't exist): " |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9811 | + ws + " surface=" + ws.mSurface |
| 9812 | + " token=" + win.mToken |
| 9813 | + " pid=" + ws.mSession.mPid |
| 9814 | + " uid=" + ws.mSession.mUid); |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 9815 | ws.mSurface.destroy(); |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 9816 | ws.mSurfaceShown = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9817 | ws.mSurface = null; |
| 9818 | mForceRemoves.add(ws); |
| 9819 | i--; |
| 9820 | N--; |
| 9821 | leakedSurface = true; |
| 9822 | } else if (win.mAppToken != null && win.mAppToken.clientHidden) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9823 | Slog.w(TAG, "LEAKED SURFACE (app token hidden): " |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9824 | + ws + " surface=" + ws.mSurface |
| 9825 | + " token=" + win.mAppToken); |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 9826 | ws.mSurface.destroy(); |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 9827 | ws.mSurfaceShown = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9828 | ws.mSurface = null; |
| 9829 | leakedSurface = true; |
| 9830 | } |
| 9831 | } |
| 9832 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9833 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9834 | boolean killedApps = false; |
| 9835 | if (!leakedSurface) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9836 | Slog.w(TAG, "No leaked surfaces; killing applicatons!"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9837 | SparseIntArray pidCandidates = new SparseIntArray(); |
| 9838 | for (int i=0; i<N; i++) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 9839 | WindowState ws = mWindows.get(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9840 | if (ws.mSurface != null) { |
| 9841 | pidCandidates.append(ws.mSession.mPid, ws.mSession.mPid); |
| 9842 | } |
| 9843 | } |
| 9844 | if (pidCandidates.size() > 0) { |
| 9845 | int[] pids = new int[pidCandidates.size()]; |
| 9846 | for (int i=0; i<pids.length; i++) { |
| 9847 | pids[i] = pidCandidates.keyAt(i); |
| 9848 | } |
| 9849 | try { |
Suchi Amalapurapu | e99bb5f | 2010-03-19 14:36:49 -0700 | [diff] [blame] | 9850 | if (mActivityManager.killPids(pids, "Free memory")) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9851 | killedApps = true; |
| 9852 | } |
| 9853 | } catch (RemoteException e) { |
| 9854 | } |
| 9855 | } |
| 9856 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9857 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9858 | if (leakedSurface || killedApps) { |
| 9859 | // We managed to reclaim some memory, so get rid of the trouble |
| 9860 | // surface and ask the app to request another one. |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9861 | 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] | 9862 | if (surface != null) { |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 9863 | surface.destroy(); |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 9864 | win.mSurfaceShown = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9865 | win.mSurface = null; |
| 9866 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9867 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9868 | try { |
| 9869 | win.mClient.dispatchGetNewSurface(); |
| 9870 | } catch (RemoteException e) { |
| 9871 | } |
| 9872 | } |
| 9873 | } finally { |
| 9874 | Binder.restoreCallingIdentity(callingIdentity); |
| 9875 | } |
| 9876 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9877 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9878 | private boolean updateFocusedWindowLocked(int mode) { |
| 9879 | WindowState newFocus = computeFocusedWindowLocked(); |
| 9880 | if (mCurrentFocus != newFocus) { |
| 9881 | // This check makes sure that we don't already have the focus |
| 9882 | // change message pending. |
| 9883 | mH.removeMessages(H.REPORT_FOCUS_CHANGE); |
| 9884 | mH.sendEmptyMessage(H.REPORT_FOCUS_CHANGE); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9885 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9886 | TAG, "Changing focus from " + mCurrentFocus + " to " + newFocus); |
| 9887 | final WindowState oldFocus = mCurrentFocus; |
| 9888 | mCurrentFocus = newFocus; |
| 9889 | mLosingFocus.remove(newFocus); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9890 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9891 | final WindowState imWindow = mInputMethodWindow; |
| 9892 | if (newFocus != imWindow && oldFocus != imWindow) { |
The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 9893 | if (moveInputMethodWindowsIfNeededLocked( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9894 | mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS && |
The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 9895 | mode != UPDATE_FOCUS_WILL_PLACE_SURFACES)) { |
| 9896 | mLayoutNeeded = true; |
| 9897 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9898 | if (mode == UPDATE_FOCUS_PLACING_SURFACES) { |
| 9899 | performLayoutLockedInner(); |
The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 9900 | } else if (mode == UPDATE_FOCUS_WILL_PLACE_SURFACES) { |
| 9901 | // Client will do the layout, but we need to assign layers |
| 9902 | // for handleNewWindowLocked() below. |
| 9903 | assignLayersLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9904 | } |
| 9905 | } |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 9906 | |
| 9907 | if (mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS) { |
| 9908 | // If we defer assigning layers, then the caller is responsible for |
| 9909 | // doing this part. |
| 9910 | finishUpdateFocusedWindowAfterAssignLayersLocked(); |
The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 9911 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9912 | return true; |
| 9913 | } |
| 9914 | return false; |
| 9915 | } |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 9916 | |
| 9917 | private void finishUpdateFocusedWindowAfterAssignLayersLocked() { |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 9918 | mInputMonitor.setInputFocusLw(mCurrentFocus); |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 9919 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9920 | |
| 9921 | private WindowState computeFocusedWindowLocked() { |
| 9922 | WindowState result = null; |
| 9923 | WindowState win; |
| 9924 | |
| 9925 | int i = mWindows.size() - 1; |
| 9926 | int nextAppIndex = mAppTokens.size()-1; |
| 9927 | WindowToken nextApp = nextAppIndex >= 0 |
| 9928 | ? mAppTokens.get(nextAppIndex) : null; |
| 9929 | |
| 9930 | while (i >= 0) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 9931 | win = mWindows.get(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9932 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9933 | if (localLOGV || DEBUG_FOCUS) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9934 | TAG, "Looking for focus: " + i |
| 9935 | + " = " + win |
| 9936 | + ", flags=" + win.mAttrs.flags |
| 9937 | + ", canReceive=" + win.canReceiveKeys()); |
| 9938 | |
| 9939 | AppWindowToken thisApp = win.mAppToken; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9940 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9941 | // If this window's application has been removed, just skip it. |
| 9942 | if (thisApp != null && thisApp.removed) { |
| 9943 | i--; |
| 9944 | continue; |
| 9945 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9946 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9947 | // If there is a focused app, don't allow focus to go to any |
| 9948 | // windows below it. If this is an application window, step |
| 9949 | // through the app tokens until we find its app. |
| 9950 | if (thisApp != null && nextApp != null && thisApp != nextApp |
| 9951 | && win.mAttrs.type != TYPE_APPLICATION_STARTING) { |
| 9952 | int origAppIndex = nextAppIndex; |
| 9953 | while (nextAppIndex > 0) { |
| 9954 | if (nextApp == mFocusedApp) { |
| 9955 | // Whoops, we are below the focused app... no focus |
| 9956 | // for you! |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9957 | if (localLOGV || DEBUG_FOCUS) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9958 | TAG, "Reached focused app: " + mFocusedApp); |
| 9959 | return null; |
| 9960 | } |
| 9961 | nextAppIndex--; |
| 9962 | nextApp = mAppTokens.get(nextAppIndex); |
| 9963 | if (nextApp == thisApp) { |
| 9964 | break; |
| 9965 | } |
| 9966 | } |
| 9967 | if (thisApp != nextApp) { |
| 9968 | // Uh oh, the app token doesn't exist! This shouldn't |
| 9969 | // happen, but if it does we can get totally hosed... |
| 9970 | // so restart at the original app. |
| 9971 | nextAppIndex = origAppIndex; |
| 9972 | nextApp = mAppTokens.get(nextAppIndex); |
| 9973 | } |
| 9974 | } |
| 9975 | |
| 9976 | // Dispatch to this window if it is wants key events. |
| 9977 | if (win.canReceiveKeys()) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9978 | if (DEBUG_FOCUS) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9979 | TAG, "Found focus @ " + i + " = " + win); |
| 9980 | result = win; |
| 9981 | break; |
| 9982 | } |
| 9983 | |
| 9984 | i--; |
| 9985 | } |
| 9986 | |
| 9987 | return result; |
| 9988 | } |
| 9989 | |
| 9990 | private void startFreezingDisplayLocked() { |
| 9991 | if (mDisplayFrozen) { |
| 9992 | return; |
| 9993 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9994 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9995 | mScreenFrozenLock.acquire(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9996 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9997 | long now = SystemClock.uptimeMillis(); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9998 | //Slog.i(TAG, "Freezing, gc pending: " + mFreezeGcPending + ", now " + now); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9999 | if (mFreezeGcPending != 0) { |
| 10000 | if (now > (mFreezeGcPending+1000)) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10001 | //Slog.i(TAG, "Gc! " + now + " > " + (mFreezeGcPending+1000)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10002 | mH.removeMessages(H.FORCE_GC); |
| 10003 | Runtime.getRuntime().gc(); |
| 10004 | mFreezeGcPending = now; |
| 10005 | } |
| 10006 | } else { |
| 10007 | mFreezeGcPending = now; |
| 10008 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10009 | |
Dianne Hackborn | ce73c1e | 2010-04-12 23:11:38 -0700 | [diff] [blame] | 10010 | if (DEBUG_FREEZE) Slog.v(TAG, "*** FREEZING DISPLAY", new RuntimeException()); |
| 10011 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10012 | mDisplayFrozen = true; |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 10013 | |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 10014 | mInputMonitor.freezeInputDispatchingLw(); |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 10015 | |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 10016 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
| 10017 | mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10018 | mNextAppTransitionPackage = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10019 | mAppTransitionReady = true; |
| 10020 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10021 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10022 | if (PROFILE_ORIENTATION) { |
| 10023 | File file = new File("/data/system/frozen"); |
| 10024 | Debug.startMethodTracing(file.toString(), 8 * 1024 * 1024); |
| 10025 | } |
| 10026 | Surface.freezeDisplay(0); |
| 10027 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10028 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10029 | private void stopFreezingDisplayLocked() { |
| 10030 | if (!mDisplayFrozen) { |
| 10031 | return; |
| 10032 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10033 | |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 10034 | if (mWaitingForConfig || mAppsFreezingScreen > 0 || mWindowsFreezingScreen) { |
| 10035 | return; |
| 10036 | } |
| 10037 | |
Dianne Hackborn | ce73c1e | 2010-04-12 23:11:38 -0700 | [diff] [blame] | 10038 | if (DEBUG_FREEZE) Slog.v(TAG, "*** UNFREEZING DISPLAY", new RuntimeException()); |
| 10039 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10040 | mDisplayFrozen = false; |
| 10041 | mH.removeMessages(H.APP_FREEZE_TIMEOUT); |
| 10042 | if (PROFILE_ORIENTATION) { |
| 10043 | Debug.stopMethodTracing(); |
| 10044 | } |
| 10045 | Surface.unfreezeDisplay(0); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10046 | |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 10047 | mInputMonitor.thawInputDispatchingLw(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10048 | |
Christopher Tate | b696aee | 2010-04-02 19:08:30 -0700 | [diff] [blame] | 10049 | // While the display is frozen we don't re-compute the orientation |
| 10050 | // to avoid inconsistent states. However, something interesting |
| 10051 | // could have actually changed during that time so re-evaluate it |
| 10052 | // now to catch that. |
| 10053 | if (updateOrientationFromAppTokensLocked()) { |
| 10054 | mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION); |
| 10055 | } |
| 10056 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10057 | // A little kludge: a lot could have happened while the |
| 10058 | // display was frozen, so now that we are coming back we |
| 10059 | // do a gc so that any remote references the system |
| 10060 | // processes holds on others can be released if they are |
| 10061 | // no longer needed. |
| 10062 | mH.removeMessages(H.FORCE_GC); |
| 10063 | mH.sendMessageDelayed(mH.obtainMessage(H.FORCE_GC), |
| 10064 | 2000); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10065 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10066 | mScreenFrozenLock.release(); |
| 10067 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10068 | |
Dianne Hackborn | b9fb170 | 2010-08-23 16:49:02 -0700 | [diff] [blame^] | 10069 | static int getPropertyInt(String[] tokens, int index, int defUnits, int defDps, |
| 10070 | DisplayMetrics dm) { |
| 10071 | if (index < tokens.length) { |
| 10072 | String str = tokens[index]; |
| 10073 | if (str != null && str.length() > 0) { |
| 10074 | try { |
| 10075 | int val = Integer.parseInt(str); |
| 10076 | return val; |
| 10077 | } catch (Exception e) { |
| 10078 | } |
| 10079 | } |
Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 10080 | } |
| 10081 | if (defUnits == TypedValue.COMPLEX_UNIT_PX) { |
| 10082 | return defDps; |
| 10083 | } |
| 10084 | int val = (int)TypedValue.applyDimension(defUnits, defDps, dm); |
| 10085 | return val; |
| 10086 | } |
| 10087 | |
| 10088 | class Watermark { |
Dianne Hackborn | b9fb170 | 2010-08-23 16:49:02 -0700 | [diff] [blame^] | 10089 | final String[] mTokens; |
| 10090 | final String mText; |
| 10091 | final Paint mTextPaint; |
| 10092 | final int mTextWidth; |
| 10093 | final int mTextHeight; |
| 10094 | final int mTextAscent; |
| 10095 | final int mTextDescent; |
| 10096 | final int mDeltaX; |
| 10097 | final int mDeltaY; |
Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 10098 | |
Dianne Hackborn | b9fb170 | 2010-08-23 16:49:02 -0700 | [diff] [blame^] | 10099 | Surface mSurface; |
| 10100 | int mLastDW; |
| 10101 | int mLastDH; |
| 10102 | boolean mDrawNeeded; |
| 10103 | |
| 10104 | Watermark(SurfaceSession session, String[] tokens) { |
Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 10105 | final DisplayMetrics dm = new DisplayMetrics(); |
| 10106 | mDisplay.getMetrics(dm); |
| 10107 | |
Dianne Hackborn | b9fb170 | 2010-08-23 16:49:02 -0700 | [diff] [blame^] | 10108 | if (false) { |
| 10109 | Log.i(TAG, "*********************** WATERMARK"); |
| 10110 | for (int i=0; i<tokens.length; i++) { |
| 10111 | Log.i(TAG, " TOKEN #" + i + ": " + tokens[i]); |
| 10112 | } |
| 10113 | } |
Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 10114 | |
Dianne Hackborn | b9fb170 | 2010-08-23 16:49:02 -0700 | [diff] [blame^] | 10115 | mTokens = tokens; |
Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 10116 | |
Dianne Hackborn | b9fb170 | 2010-08-23 16:49:02 -0700 | [diff] [blame^] | 10117 | StringBuilder builder = new StringBuilder(32); |
| 10118 | int len = mTokens[0].length(); |
| 10119 | len = len & ~1; |
| 10120 | for (int i=0; i<len; i+=2) { |
| 10121 | int c1 = mTokens[0].charAt(i); |
| 10122 | int c2 = mTokens[0].charAt(i+1); |
| 10123 | if (c1 >= 'a' && c1 <= 'f') c1 = c1 - 'a' + 10; |
| 10124 | else if (c1 >= 'A' && c1 <= 'F') c1 = c1 - 'A' + 10; |
| 10125 | else c1 -= '0'; |
| 10126 | if (c2 >= 'a' && c2 <= 'f') c2 = c2 - 'a' + 10; |
| 10127 | else if (c2 >= 'A' && c2 <= 'F') c2 = c2 - 'A' + 10; |
| 10128 | else c2 -= '0'; |
| 10129 | builder.append((char)(255-((c1*16)+c2))); |
| 10130 | } |
| 10131 | mText = builder.toString(); |
| 10132 | if (false) { |
| 10133 | Log.i(TAG, "Final text: " + mText); |
| 10134 | } |
| 10135 | |
| 10136 | int fontSize = getPropertyInt(tokens, 1, |
| 10137 | TypedValue.COMPLEX_UNIT_DIP, 20, dm); |
| 10138 | |
| 10139 | mTextPaint = new Paint(Paint.ANTI_ALIAS_FLAG); |
| 10140 | mTextPaint.setTextSize(fontSize); |
| 10141 | mTextPaint.setTypeface(Typeface.create(Typeface.SANS_SERIF, Typeface.BOLD)); |
| 10142 | |
| 10143 | FontMetricsInt fm = mTextPaint.getFontMetricsInt(); |
| 10144 | mTextWidth = (int)mTextPaint.measureText(mText); |
| 10145 | mTextAscent = fm.ascent; |
| 10146 | mTextDescent = fm.descent; |
| 10147 | mTextHeight = fm.descent - fm.ascent; |
| 10148 | |
| 10149 | mDeltaX = getPropertyInt(tokens, 2, |
| 10150 | TypedValue.COMPLEX_UNIT_PX, mTextWidth*2, dm); |
| 10151 | mDeltaY = getPropertyInt(tokens, 3, |
| 10152 | TypedValue.COMPLEX_UNIT_PX, mTextHeight*3, dm); |
| 10153 | int shadowColor = getPropertyInt(tokens, 4, |
| 10154 | TypedValue.COMPLEX_UNIT_PX, 0xb0000000, dm); |
| 10155 | int color = getPropertyInt(tokens, 5, |
| 10156 | TypedValue.COMPLEX_UNIT_PX, 0x60ffffff, dm); |
| 10157 | int shadowRadius = getPropertyInt(tokens, 6, |
| 10158 | TypedValue.COMPLEX_UNIT_PX, 7, dm); |
| 10159 | int shadowDx = getPropertyInt(tokens, 8, |
| 10160 | TypedValue.COMPLEX_UNIT_PX, 0, dm); |
| 10161 | int shadowDy = getPropertyInt(tokens, 9, |
| 10162 | TypedValue.COMPLEX_UNIT_PX, 0, dm); |
| 10163 | |
| 10164 | mTextPaint.setColor(color); |
| 10165 | mTextPaint.setShadowLayer(shadowRadius, shadowDx, shadowDy, shadowColor); |
Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 10166 | |
| 10167 | try { |
| 10168 | mSurface = new Surface(session, 0, |
Dianne Hackborn | b9fb170 | 2010-08-23 16:49:02 -0700 | [diff] [blame^] | 10169 | "WatermarkSurface", -1, 1, 1, PixelFormat.TRANSLUCENT, 0); |
Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 10170 | mSurface.setLayer(TYPE_LAYER_MULTIPLIER*100); |
Dianne Hackborn | b9fb170 | 2010-08-23 16:49:02 -0700 | [diff] [blame^] | 10171 | mSurface.setPosition(0, 0); |
Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 10172 | mSurface.show(); |
| 10173 | } catch (OutOfResourcesException e) { |
| 10174 | } |
| 10175 | } |
| 10176 | |
| 10177 | void positionSurface(int dw, int dh) { |
Dianne Hackborn | b9fb170 | 2010-08-23 16:49:02 -0700 | [diff] [blame^] | 10178 | if (mLastDW != dw || mLastDH != dh) { |
| 10179 | mLastDW = dw; |
| 10180 | mLastDH = dh; |
| 10181 | mSurface.setSize(dw, dh); |
| 10182 | mDrawNeeded = true; |
| 10183 | } |
| 10184 | } |
| 10185 | |
| 10186 | void drawIfNeeded() { |
| 10187 | if (mDrawNeeded) { |
| 10188 | final int dw = mLastDW; |
| 10189 | final int dh = mLastDH; |
| 10190 | |
| 10191 | mDrawNeeded = false; |
| 10192 | Rect dirty = new Rect(0, 0, dw, dh); |
| 10193 | Canvas c = null; |
| 10194 | try { |
| 10195 | c = mSurface.lockCanvas(dirty); |
| 10196 | } catch (IllegalArgumentException e) { |
| 10197 | } catch (OutOfResourcesException e) { |
| 10198 | } |
| 10199 | if (c != null) { |
| 10200 | int deltaX = mDeltaX; |
| 10201 | int deltaY = mDeltaY; |
| 10202 | |
| 10203 | // deltaX shouldn't be close to a round fraction of our |
| 10204 | // x step, or else things will line up too much. |
| 10205 | int div = (dw+mTextWidth)/deltaX; |
| 10206 | int rem = (dw+mTextWidth) - (div*deltaX); |
| 10207 | int qdelta = deltaX/4; |
| 10208 | if (rem < qdelta || rem > (deltaX-qdelta)) { |
| 10209 | deltaX += deltaX/3; |
| 10210 | } |
| 10211 | |
| 10212 | int y = -mTextHeight; |
| 10213 | int x = -mTextWidth; |
| 10214 | while (y < (dh+mTextHeight)) { |
| 10215 | c.drawText(mText, x, y, mTextPaint); |
| 10216 | x += deltaX; |
| 10217 | if (x >= dw) { |
| 10218 | x -= (dw+mTextWidth); |
| 10219 | y += deltaY; |
| 10220 | } |
| 10221 | } |
| 10222 | mSurface.unlockCanvasAndPost(c); |
| 10223 | } |
| 10224 | } |
Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 10225 | } |
| 10226 | } |
| 10227 | |
| 10228 | void createWatermark() { |
| 10229 | if (mWatermark != null) { |
| 10230 | return; |
| 10231 | } |
| 10232 | |
Dianne Hackborn | b9fb170 | 2010-08-23 16:49:02 -0700 | [diff] [blame^] | 10233 | File file = new File("/system/etc/setup.conf"); |
| 10234 | FileInputStream in = null; |
| 10235 | try { |
| 10236 | in = new FileInputStream(file); |
| 10237 | DataInputStream ind = new DataInputStream(in); |
| 10238 | String line = ind.readLine(); |
| 10239 | if (line != null) { |
| 10240 | String[] toks = line.split("%"); |
| 10241 | if (toks != null && toks.length > 0) { |
| 10242 | mWatermark = new Watermark(mFxSession, toks); |
| 10243 | } |
| 10244 | } |
| 10245 | } catch (FileNotFoundException e) { |
| 10246 | } catch (IOException e) { |
| 10247 | } finally { |
| 10248 | if (in != null) { |
| 10249 | try { |
| 10250 | in.close(); |
| 10251 | } catch (IOException e) { |
| 10252 | } |
| 10253 | } |
Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 10254 | } |
Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 10255 | } |
| 10256 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10257 | @Override |
| 10258 | public void dump(FileDescriptor fd, PrintWriter pw, String[] args) { |
| 10259 | if (mContext.checkCallingOrSelfPermission("android.permission.DUMP") |
| 10260 | != PackageManager.PERMISSION_GRANTED) { |
| 10261 | pw.println("Permission Denial: can't dump WindowManager from from pid=" |
| 10262 | + Binder.getCallingPid() |
| 10263 | + ", uid=" + Binder.getCallingUid()); |
| 10264 | return; |
| 10265 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10266 | |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 10267 | mInputManager.dump(pw); |
Dianne Hackborn | a2e9226 | 2010-03-02 17:19:29 -0800 | [diff] [blame] | 10268 | pw.println(" "); |
| 10269 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10270 | synchronized(mWindowMap) { |
| 10271 | pw.println("Current Window Manager state:"); |
| 10272 | for (int i=mWindows.size()-1; i>=0; i--) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 10273 | WindowState w = mWindows.get(i); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10274 | pw.print(" Window #"); pw.print(i); pw.print(' '); |
| 10275 | pw.print(w); pw.println(":"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10276 | w.dump(pw, " "); |
| 10277 | } |
| 10278 | if (mInputMethodDialogs.size() > 0) { |
| 10279 | pw.println(" "); |
| 10280 | pw.println(" Input method dialogs:"); |
| 10281 | for (int i=mInputMethodDialogs.size()-1; i>=0; i--) { |
| 10282 | WindowState w = mInputMethodDialogs.get(i); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10283 | 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] | 10284 | } |
| 10285 | } |
| 10286 | if (mPendingRemove.size() > 0) { |
| 10287 | pw.println(" "); |
| 10288 | pw.println(" Remove pending for:"); |
| 10289 | for (int i=mPendingRemove.size()-1; i>=0; i--) { |
| 10290 | WindowState w = mPendingRemove.get(i); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10291 | pw.print(" Remove #"); pw.print(i); pw.print(' '); |
| 10292 | pw.print(w); pw.println(":"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10293 | w.dump(pw, " "); |
| 10294 | } |
| 10295 | } |
| 10296 | if (mForceRemoves != null && mForceRemoves.size() > 0) { |
| 10297 | pw.println(" "); |
| 10298 | pw.println(" Windows force removing:"); |
| 10299 | for (int i=mForceRemoves.size()-1; i>=0; i--) { |
| 10300 | WindowState w = mForceRemoves.get(i); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10301 | pw.print(" Removing #"); pw.print(i); pw.print(' '); |
| 10302 | pw.print(w); pw.println(":"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10303 | w.dump(pw, " "); |
| 10304 | } |
| 10305 | } |
| 10306 | if (mDestroySurface.size() > 0) { |
| 10307 | pw.println(" "); |
| 10308 | pw.println(" Windows waiting to destroy their surface:"); |
| 10309 | for (int i=mDestroySurface.size()-1; i>=0; i--) { |
| 10310 | WindowState w = mDestroySurface.get(i); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10311 | pw.print(" Destroy #"); pw.print(i); pw.print(' '); |
| 10312 | pw.print(w); pw.println(":"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10313 | w.dump(pw, " "); |
| 10314 | } |
| 10315 | } |
| 10316 | if (mLosingFocus.size() > 0) { |
| 10317 | pw.println(" "); |
| 10318 | pw.println(" Windows losing focus:"); |
| 10319 | for (int i=mLosingFocus.size()-1; i>=0; i--) { |
| 10320 | WindowState w = mLosingFocus.get(i); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10321 | pw.print(" Losing #"); pw.print(i); pw.print(' '); |
| 10322 | pw.print(w); pw.println(":"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10323 | w.dump(pw, " "); |
| 10324 | } |
| 10325 | } |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 10326 | if (mResizingWindows.size() > 0) { |
| 10327 | pw.println(" "); |
| 10328 | pw.println(" Windows waiting to resize:"); |
| 10329 | for (int i=mResizingWindows.size()-1; i>=0; i--) { |
| 10330 | WindowState w = mResizingWindows.get(i); |
| 10331 | pw.print(" Resizing #"); pw.print(i); pw.print(' '); |
| 10332 | pw.print(w); pw.println(":"); |
| 10333 | w.dump(pw, " "); |
| 10334 | } |
| 10335 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10336 | if (mSessions.size() > 0) { |
| 10337 | pw.println(" "); |
| 10338 | pw.println(" All active sessions:"); |
| 10339 | Iterator<Session> it = mSessions.iterator(); |
| 10340 | while (it.hasNext()) { |
| 10341 | Session s = it.next(); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10342 | pw.print(" Session "); pw.print(s); pw.println(':'); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10343 | s.dump(pw, " "); |
| 10344 | } |
| 10345 | } |
| 10346 | if (mTokenMap.size() > 0) { |
| 10347 | pw.println(" "); |
| 10348 | pw.println(" All tokens:"); |
| 10349 | Iterator<WindowToken> it = mTokenMap.values().iterator(); |
| 10350 | while (it.hasNext()) { |
| 10351 | WindowToken token = it.next(); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10352 | pw.print(" Token "); pw.print(token.token); pw.println(':'); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10353 | token.dump(pw, " "); |
| 10354 | } |
| 10355 | } |
| 10356 | if (mTokenList.size() > 0) { |
| 10357 | pw.println(" "); |
| 10358 | pw.println(" Window token list:"); |
| 10359 | for (int i=0; i<mTokenList.size(); i++) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10360 | pw.print(" #"); pw.print(i); pw.print(": "); |
| 10361 | pw.println(mTokenList.get(i)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10362 | } |
| 10363 | } |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 10364 | if (mWallpaperTokens.size() > 0) { |
| 10365 | pw.println(" "); |
| 10366 | pw.println(" Wallpaper tokens:"); |
| 10367 | for (int i=mWallpaperTokens.size()-1; i>=0; i--) { |
| 10368 | WindowToken token = mWallpaperTokens.get(i); |
| 10369 | pw.print(" Wallpaper #"); pw.print(i); |
| 10370 | pw.print(' '); pw.print(token); pw.println(':'); |
| 10371 | token.dump(pw, " "); |
| 10372 | } |
| 10373 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10374 | if (mAppTokens.size() > 0) { |
| 10375 | pw.println(" "); |
| 10376 | pw.println(" Application tokens in Z order:"); |
| 10377 | for (int i=mAppTokens.size()-1; i>=0; i--) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10378 | pw.print(" App #"); pw.print(i); pw.print(": "); |
| 10379 | pw.println(mAppTokens.get(i)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10380 | } |
| 10381 | } |
| 10382 | if (mFinishedStarting.size() > 0) { |
| 10383 | pw.println(" "); |
| 10384 | pw.println(" Finishing start of application tokens:"); |
| 10385 | for (int i=mFinishedStarting.size()-1; i>=0; i--) { |
| 10386 | WindowToken token = mFinishedStarting.get(i); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10387 | pw.print(" Finished Starting #"); pw.print(i); |
| 10388 | pw.print(' '); pw.print(token); pw.println(':'); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10389 | token.dump(pw, " "); |
| 10390 | } |
| 10391 | } |
| 10392 | if (mExitingTokens.size() > 0) { |
| 10393 | pw.println(" "); |
| 10394 | pw.println(" Exiting tokens:"); |
| 10395 | for (int i=mExitingTokens.size()-1; i>=0; i--) { |
| 10396 | WindowToken token = mExitingTokens.get(i); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10397 | pw.print(" Exiting #"); pw.print(i); |
| 10398 | pw.print(' '); pw.print(token); pw.println(':'); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10399 | token.dump(pw, " "); |
| 10400 | } |
| 10401 | } |
| 10402 | if (mExitingAppTokens.size() > 0) { |
| 10403 | pw.println(" "); |
| 10404 | pw.println(" Exiting application tokens:"); |
| 10405 | for (int i=mExitingAppTokens.size()-1; i>=0; i--) { |
| 10406 | WindowToken token = mExitingAppTokens.get(i); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10407 | pw.print(" Exiting App #"); pw.print(i); |
| 10408 | pw.print(' '); pw.print(token); pw.println(':'); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10409 | token.dump(pw, " "); |
| 10410 | } |
| 10411 | } |
| 10412 | pw.println(" "); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10413 | pw.print(" mCurrentFocus="); pw.println(mCurrentFocus); |
| 10414 | pw.print(" mLastFocus="); pw.println(mLastFocus); |
| 10415 | pw.print(" mFocusedApp="); pw.println(mFocusedApp); |
| 10416 | pw.print(" mInputMethodTarget="); pw.println(mInputMethodTarget); |
| 10417 | pw.print(" mInputMethodWindow="); pw.println(mInputMethodWindow); |
Dianne Hackborn | f21adf6 | 2009-08-13 10:20:21 -0700 | [diff] [blame] | 10418 | pw.print(" mWallpaperTarget="); pw.println(mWallpaperTarget); |
Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 10419 | if (mLowerWallpaperTarget != null && mUpperWallpaperTarget != null) { |
| 10420 | pw.print(" mLowerWallpaperTarget="); pw.println(mLowerWallpaperTarget); |
| 10421 | pw.print(" mUpperWallpaperTarget="); pw.println(mUpperWallpaperTarget); |
| 10422 | } |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 10423 | pw.print(" mCurConfiguration="); pw.println(this.mCurConfiguration); |
| 10424 | pw.print(" mInTouchMode="); pw.print(mInTouchMode); |
| 10425 | pw.print(" mLayoutSeq="); pw.println(mLayoutSeq); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10426 | pw.print(" mSystemBooted="); pw.print(mSystemBooted); |
| 10427 | pw.print(" mDisplayEnabled="); pw.println(mDisplayEnabled); |
| 10428 | pw.print(" mLayoutNeeded="); pw.print(mLayoutNeeded); |
| 10429 | pw.print(" mBlurShown="); pw.println(mBlurShown); |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 10430 | if (mDimAnimator != null) { |
| 10431 | mDimAnimator.printTo(pw); |
| 10432 | } else { |
Dianne Hackborn | a2e9226 | 2010-03-02 17:19:29 -0800 | [diff] [blame] | 10433 | pw.println( " no DimAnimator "); |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 10434 | } |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10435 | pw.print(" mInputMethodAnimLayerAdjustment="); |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 10436 | pw.print(mInputMethodAnimLayerAdjustment); |
| 10437 | pw.print(" mWallpaperAnimLayerAdjustment="); |
| 10438 | pw.println(mWallpaperAnimLayerAdjustment); |
Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 10439 | pw.print(" mLastWallpaperX="); pw.print(mLastWallpaperX); |
| 10440 | pw.print(" mLastWallpaperY="); pw.println(mLastWallpaperY); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10441 | pw.print(" mDisplayFrozen="); pw.print(mDisplayFrozen); |
| 10442 | pw.print(" mWindowsFreezingScreen="); pw.print(mWindowsFreezingScreen); |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 10443 | pw.print(" mAppsFreezingScreen="); pw.print(mAppsFreezingScreen); |
| 10444 | pw.print(" mWaitingForConfig="); pw.println(mWaitingForConfig); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10445 | pw.print(" mRotation="); pw.print(mRotation); |
| 10446 | pw.print(", mForcedAppOrientation="); pw.print(mForcedAppOrientation); |
| 10447 | pw.print(", mRequestedRotation="); pw.println(mRequestedRotation); |
| 10448 | pw.print(" mAnimationPending="); pw.print(mAnimationPending); |
| 10449 | pw.print(" mWindowAnimationScale="); pw.print(mWindowAnimationScale); |
| 10450 | pw.print(" mTransitionWindowAnimationScale="); pw.println(mTransitionAnimationScale); |
| 10451 | pw.print(" mNextAppTransition=0x"); |
| 10452 | pw.print(Integer.toHexString(mNextAppTransition)); |
| 10453 | pw.print(", mAppTransitionReady="); pw.print(mAppTransitionReady); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 10454 | pw.print(", mAppTransitionRunning="); pw.print(mAppTransitionRunning); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10455 | pw.print(", mAppTransitionTimeout="); pw.println( mAppTransitionTimeout); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10456 | if (mNextAppTransitionPackage != null) { |
| 10457 | pw.print(" mNextAppTransitionPackage="); |
| 10458 | pw.print(mNextAppTransitionPackage); |
| 10459 | pw.print(", mNextAppTransitionEnter=0x"); |
| 10460 | pw.print(Integer.toHexString(mNextAppTransitionEnter)); |
| 10461 | pw.print(", mNextAppTransitionExit=0x"); |
| 10462 | pw.print(Integer.toHexString(mNextAppTransitionExit)); |
| 10463 | } |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10464 | pw.print(" mStartingIconInTransition="); pw.print(mStartingIconInTransition); |
| 10465 | pw.print(", mSkipAppTransitionAnimation="); pw.println(mSkipAppTransitionAnimation); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10466 | if (mLastEnterAnimToken != null || mLastEnterAnimToken != null) { |
| 10467 | pw.print(" mLastEnterAnimToken="); pw.print(mLastEnterAnimToken); |
| 10468 | pw.print(", mLastEnterAnimParams="); pw.println(mLastEnterAnimParams); |
| 10469 | } |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10470 | if (mOpeningApps.size() > 0) { |
| 10471 | pw.print(" mOpeningApps="); pw.println(mOpeningApps); |
| 10472 | } |
| 10473 | if (mClosingApps.size() > 0) { |
| 10474 | pw.print(" mClosingApps="); pw.println(mClosingApps); |
| 10475 | } |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 10476 | if (mToTopApps.size() > 0) { |
| 10477 | pw.print(" mToTopApps="); pw.println(mToTopApps); |
| 10478 | } |
| 10479 | if (mToBottomApps.size() > 0) { |
| 10480 | pw.print(" mToBottomApps="); pw.println(mToBottomApps); |
| 10481 | } |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10482 | pw.print(" DisplayWidth="); pw.print(mDisplay.getWidth()); |
| 10483 | pw.print(" DisplayHeight="); pw.println(mDisplay.getHeight()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10484 | } |
| 10485 | } |
| 10486 | |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 10487 | // 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] | 10488 | public void monitor() { |
| 10489 | synchronized (mWindowMap) { } |
Mike Lockwood | 983ee09 | 2009-11-22 01:42:24 -0500 | [diff] [blame] | 10490 | synchronized (mKeyguardTokenWatcher) { } |
Dianne Hackborn | ddca3ee | 2009-07-23 19:01:31 -0700 | [diff] [blame] | 10491 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10492 | |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 10493 | /** |
| 10494 | * DimAnimator class that controls the dim animation. This holds the surface and |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10495 | * all state used for dim animation. |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 10496 | */ |
| 10497 | private static class DimAnimator { |
| 10498 | Surface mDimSurface; |
| 10499 | boolean mDimShown = false; |
| 10500 | float mDimCurrentAlpha; |
| 10501 | float mDimTargetAlpha; |
| 10502 | float mDimDeltaPerMs; |
| 10503 | long mLastDimAnimTime; |
Dianne Hackborn | f83c555 | 2010-03-31 22:19:32 -0700 | [diff] [blame] | 10504 | |
| 10505 | int mLastDimWidth, mLastDimHeight; |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 10506 | |
| 10507 | DimAnimator (SurfaceSession session) { |
| 10508 | if (mDimSurface == null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10509 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 10510 | + mDimSurface + ": CREATE"); |
| 10511 | try { |
Mathias Agopian | 5d26c1e | 2010-03-01 16:09:43 -0800 | [diff] [blame] | 10512 | mDimSurface = new Surface(session, 0, |
| 10513 | "DimSurface", |
| 10514 | -1, 16, 16, PixelFormat.OPAQUE, |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 10515 | Surface.FX_SURFACE_DIM); |
Maciej Białka | 9ee5c22 | 2010-03-24 10:25:40 +0100 | [diff] [blame] | 10516 | mDimSurface.setAlpha(0.0f); |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 10517 | } catch (Exception e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10518 | Slog.e(TAG, "Exception creating Dim surface", e); |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 10519 | } |
| 10520 | } |
| 10521 | } |
| 10522 | |
| 10523 | /** |
| 10524 | * Show the dim surface. |
| 10525 | */ |
| 10526 | void show(int dw, int dh) { |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 10527 | if (!mDimShown) { |
| 10528 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface + ": SHOW pos=(0,0) (" + |
| 10529 | dw + "x" + dh + ")"); |
| 10530 | mDimShown = true; |
| 10531 | try { |
Dianne Hackborn | f83c555 | 2010-03-31 22:19:32 -0700 | [diff] [blame] | 10532 | mLastDimWidth = dw; |
| 10533 | mLastDimHeight = dh; |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 10534 | mDimSurface.setPosition(0, 0); |
| 10535 | mDimSurface.setSize(dw, dh); |
| 10536 | mDimSurface.show(); |
| 10537 | } catch (RuntimeException e) { |
| 10538 | Slog.w(TAG, "Failure showing dim surface", e); |
| 10539 | } |
Dianne Hackborn | f83c555 | 2010-03-31 22:19:32 -0700 | [diff] [blame] | 10540 | } else if (mLastDimWidth != dw || mLastDimHeight != dh) { |
| 10541 | mLastDimWidth = dw; |
| 10542 | mLastDimHeight = dh; |
| 10543 | mDimSurface.setSize(dw, dh); |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 10544 | } |
| 10545 | } |
| 10546 | |
| 10547 | /** |
| 10548 | * Set's the dim surface's layer and update dim parameters that will be used in |
| 10549 | * {@link updateSurface} after all windows are examined. |
| 10550 | */ |
| 10551 | void updateParameters(WindowState w, long currentTime) { |
| 10552 | mDimSurface.setLayer(w.mAnimLayer-1); |
| 10553 | |
| 10554 | final float target = w.mExiting ? 0 : w.mAttrs.dimAmount; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10555 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 10556 | + ": layer=" + (w.mAnimLayer-1) + " target=" + target); |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 10557 | if (mDimTargetAlpha != target) { |
| 10558 | // If the desired dim level has changed, then |
| 10559 | // start an animation to it. |
| 10560 | mLastDimAnimTime = currentTime; |
| 10561 | long duration = (w.mAnimating && w.mAnimation != null) |
| 10562 | ? w.mAnimation.computeDurationHint() |
| 10563 | : DEFAULT_DIM_DURATION; |
| 10564 | if (target > mDimTargetAlpha) { |
| 10565 | // This is happening behind the activity UI, |
| 10566 | // so we can make it run a little longer to |
| 10567 | // give a stronger impression without disrupting |
| 10568 | // the user. |
| 10569 | duration *= DIM_DURATION_MULTIPLIER; |
| 10570 | } |
| 10571 | if (duration < 1) { |
| 10572 | // Don't divide by zero |
| 10573 | duration = 1; |
| 10574 | } |
| 10575 | mDimTargetAlpha = target; |
| 10576 | mDimDeltaPerMs = (mDimTargetAlpha-mDimCurrentAlpha) / duration; |
| 10577 | } |
| 10578 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10579 | |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 10580 | /** |
| 10581 | * Updating the surface's alpha. Returns true if the animation continues, or returns |
| 10582 | * false when the animation is finished and the dim surface is hidden. |
| 10583 | */ |
| 10584 | boolean updateSurface(boolean dimming, long currentTime, boolean displayFrozen) { |
| 10585 | if (!dimming) { |
| 10586 | if (mDimTargetAlpha != 0) { |
| 10587 | mLastDimAnimTime = currentTime; |
| 10588 | mDimTargetAlpha = 0; |
| 10589 | mDimDeltaPerMs = (-mDimCurrentAlpha) / DEFAULT_DIM_DURATION; |
| 10590 | } |
| 10591 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10592 | |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 10593 | boolean animating = false; |
| 10594 | if (mLastDimAnimTime != 0) { |
| 10595 | mDimCurrentAlpha += mDimDeltaPerMs |
| 10596 | * (currentTime-mLastDimAnimTime); |
| 10597 | boolean more = true; |
| 10598 | if (displayFrozen) { |
| 10599 | // If the display is frozen, there is no reason to animate. |
| 10600 | more = false; |
| 10601 | } else if (mDimDeltaPerMs > 0) { |
| 10602 | if (mDimCurrentAlpha > mDimTargetAlpha) { |
| 10603 | more = false; |
| 10604 | } |
| 10605 | } else if (mDimDeltaPerMs < 0) { |
| 10606 | if (mDimCurrentAlpha < mDimTargetAlpha) { |
| 10607 | more = false; |
| 10608 | } |
| 10609 | } else { |
| 10610 | more = false; |
| 10611 | } |
| 10612 | |
| 10613 | // Do we need to continue animating? |
| 10614 | if (more) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10615 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 10616 | + mDimSurface + ": alpha=" + mDimCurrentAlpha); |
| 10617 | mLastDimAnimTime = currentTime; |
| 10618 | mDimSurface.setAlpha(mDimCurrentAlpha); |
| 10619 | animating = true; |
| 10620 | } else { |
| 10621 | mDimCurrentAlpha = mDimTargetAlpha; |
| 10622 | mLastDimAnimTime = 0; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10623 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 10624 | + mDimSurface + ": final alpha=" + mDimCurrentAlpha); |
| 10625 | mDimSurface.setAlpha(mDimCurrentAlpha); |
| 10626 | if (!dimming) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10627 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 10628 | + ": HIDE"); |
| 10629 | try { |
| 10630 | mDimSurface.hide(); |
| 10631 | } catch (RuntimeException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10632 | Slog.w(TAG, "Illegal argument exception hiding dim surface"); |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 10633 | } |
| 10634 | mDimShown = false; |
| 10635 | } |
| 10636 | } |
| 10637 | } |
| 10638 | return animating; |
| 10639 | } |
| 10640 | |
| 10641 | public void printTo(PrintWriter pw) { |
| 10642 | pw.print(" mDimShown="); pw.print(mDimShown); |
| 10643 | pw.print(" current="); pw.print(mDimCurrentAlpha); |
| 10644 | pw.print(" target="); pw.print(mDimTargetAlpha); |
| 10645 | pw.print(" delta="); pw.print(mDimDeltaPerMs); |
| 10646 | pw.print(" lastAnimTime="); pw.println(mLastDimAnimTime); |
| 10647 | } |
| 10648 | } |
| 10649 | |
| 10650 | /** |
| 10651 | * Animation that fade in after 0.5 interpolate time, or fade out in reverse order. |
| 10652 | * This is used for opening/closing transition for apps in compatible mode. |
| 10653 | */ |
| 10654 | private static class FadeInOutAnimation extends Animation { |
| 10655 | int mWidth; |
| 10656 | boolean mFadeIn; |
| 10657 | |
| 10658 | public FadeInOutAnimation(boolean fadeIn) { |
| 10659 | setInterpolator(new AccelerateInterpolator()); |
| 10660 | setDuration(DEFAULT_FADE_IN_OUT_DURATION); |
| 10661 | mFadeIn = fadeIn; |
| 10662 | } |
| 10663 | |
| 10664 | @Override |
| 10665 | protected void applyTransformation(float interpolatedTime, Transformation t) { |
| 10666 | float x = interpolatedTime; |
| 10667 | if (!mFadeIn) { |
| 10668 | x = 1.0f - x; // reverse the interpolation for fade out |
| 10669 | } |
| 10670 | if (x < 0.5) { |
| 10671 | // move the window out of the screen. |
| 10672 | t.getMatrix().setTranslate(mWidth, 0); |
| 10673 | } else { |
| 10674 | t.getMatrix().setTranslate(0, 0);// show |
| 10675 | t.setAlpha((x - 0.5f) * 2); |
| 10676 | } |
| 10677 | } |
| 10678 | |
| 10679 | @Override |
| 10680 | public void initialize(int width, int height, int parentWidth, int parentHeight) { |
| 10681 | // width is the screen width {@see AppWindowToken#stepAnimatinoLocked} |
| 10682 | mWidth = width; |
| 10683 | } |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 10684 | |
| 10685 | @Override |
Mitsuru Oshima | 5a2b91d | 2009-07-16 16:30:02 -0700 | [diff] [blame] | 10686 | public int getZAdjustment() { |
| 10687 | return Animation.ZORDER_TOP; |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 10688 | } |
| 10689 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10690 | } |