| 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; |
| Joe Onorato | 9305647 | 2010-09-10 10:30:46 -0400 | [diff] [blame] | 26 | import static android.view.WindowManager.LayoutParams.FLAG_FULLSCREEN; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 27 | import static android.view.WindowManager.LayoutParams.FLAG_SYSTEM_ERROR; |
| 28 | import static android.view.WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE; |
| 29 | import static android.view.WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM; |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 30 | import static android.view.WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 31 | import static android.view.WindowManager.LayoutParams.LAST_APPLICATION_WINDOW; |
| 32 | import static android.view.WindowManager.LayoutParams.LAST_SUB_WINDOW; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 33 | import static android.view.WindowManager.LayoutParams.MEMORY_TYPE_PUSH_BUFFERS; |
| 34 | import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_STARTING; |
| 35 | import static android.view.WindowManager.LayoutParams.TYPE_BASE_APPLICATION; |
| 36 | import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD; |
| 37 | import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG; |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 38 | import static android.view.WindowManager.LayoutParams.TYPE_WALLPAPER; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 39 | |
| 40 | import com.android.internal.app.IBatteryStats; |
| 41 | import com.android.internal.policy.PolicyManager; |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 42 | import com.android.internal.policy.impl.PhoneWindowManager; |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 43 | import com.android.internal.view.BaseInputHandler; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 44 | import com.android.internal.view.IInputContext; |
| 45 | import com.android.internal.view.IInputMethodClient; |
| 46 | import com.android.internal.view.IInputMethodManager; |
| Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 47 | import com.android.internal.view.WindowManagerPolicyThread; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 48 | import com.android.server.am.BatteryStatsService; |
| 49 | |
| 50 | import android.Manifest; |
| 51 | import android.app.ActivityManagerNative; |
| 52 | import android.app.IActivityManager; |
| Jim Miller | d6b5705 | 2010-06-07 17:52:42 -0700 | [diff] [blame] | 53 | import android.app.admin.DevicePolicyManager; |
| Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 54 | import android.content.BroadcastReceiver; |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 55 | import android.content.ClipData; |
| 56 | import android.content.ClipDescription; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 57 | import android.content.Context; |
| Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 58 | import android.content.Intent; |
| 59 | import android.content.IntentFilter; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 60 | import android.content.pm.ActivityInfo; |
| 61 | import android.content.pm.PackageManager; |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 62 | import android.content.res.CompatibilityInfo; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 63 | import android.content.res.Configuration; |
| Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 64 | import android.graphics.Canvas; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 65 | import android.graphics.Matrix; |
| Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 66 | import android.graphics.Paint; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 67 | import android.graphics.PixelFormat; |
| 68 | import android.graphics.Rect; |
| 69 | import android.graphics.Region; |
| Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 70 | import android.graphics.Typeface; |
| 71 | import android.graphics.Paint.FontMetricsInt; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 72 | import android.os.BatteryStats; |
| 73 | import android.os.Binder; |
| Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 74 | import android.os.Bundle; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 75 | import android.os.Debug; |
| 76 | import android.os.Handler; |
| 77 | import android.os.IBinder; |
| 78 | import android.os.LocalPowerManager; |
| 79 | import android.os.Looper; |
| 80 | import android.os.Message; |
| 81 | import android.os.Parcel; |
| 82 | import android.os.ParcelFileDescriptor; |
| 83 | import android.os.Power; |
| 84 | import android.os.PowerManager; |
| 85 | import android.os.Process; |
| 86 | import android.os.RemoteException; |
| 87 | import android.os.ServiceManager; |
| 88 | import android.os.SystemClock; |
| 89 | import android.os.SystemProperties; |
| 90 | import android.os.TokenWatcher; |
| 91 | import android.provider.Settings; |
| Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 92 | import android.util.DisplayMetrics; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 93 | import android.util.EventLog; |
| Jim Miller | d6b5705 | 2010-06-07 17:52:42 -0700 | [diff] [blame] | 94 | import android.util.Log; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 95 | import android.util.Slog; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 96 | import android.util.SparseIntArray; |
| Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 97 | import android.util.TypedValue; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 98 | import android.view.Display; |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 99 | import android.view.DragEvent; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 100 | import android.view.Gravity; |
| Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 101 | import android.view.HapticFeedbackConstants; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 102 | import android.view.IApplicationToken; |
| 103 | import android.view.IOnKeyguardExitResult; |
| 104 | import android.view.IRotationWatcher; |
| 105 | import android.view.IWindow; |
| 106 | import android.view.IWindowManager; |
| 107 | import android.view.IWindowSession; |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 108 | import android.view.InputChannel; |
| Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 109 | import android.view.InputDevice; |
| Jeff Brown | bbda99d | 2010-07-28 15:48:59 -0700 | [diff] [blame] | 110 | import android.view.InputEvent; |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 111 | import android.view.InputHandler; |
| 112 | import android.view.InputQueue; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 113 | import android.view.KeyEvent; |
| 114 | import android.view.MotionEvent; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 115 | import android.view.Surface; |
| 116 | import android.view.SurfaceSession; |
| 117 | import android.view.View; |
| 118 | import android.view.ViewTreeObserver; |
| 119 | import android.view.WindowManager; |
| 120 | import android.view.WindowManagerImpl; |
| 121 | import android.view.WindowManagerPolicy; |
| Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 122 | import android.view.Surface.OutOfResourcesException; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 123 | import android.view.WindowManager.LayoutParams; |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 124 | import android.view.animation.AccelerateInterpolator; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 125 | import android.view.animation.Animation; |
| 126 | import android.view.animation.AnimationUtils; |
| 127 | import android.view.animation.Transformation; |
| 128 | |
| Dianne Hackborn | b9fb170 | 2010-08-23 16:49:02 -0700 | [diff] [blame] | 129 | import java.io.BufferedReader; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 130 | import java.io.BufferedWriter; |
| Dianne Hackborn | b9fb170 | 2010-08-23 16:49:02 -0700 | [diff] [blame] | 131 | import java.io.DataInputStream; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 132 | import java.io.File; |
| 133 | import java.io.FileDescriptor; |
| Dianne Hackborn | b9fb170 | 2010-08-23 16:49:02 -0700 | [diff] [blame] | 134 | import java.io.FileInputStream; |
| 135 | import java.io.FileNotFoundException; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 136 | import java.io.IOException; |
| 137 | import java.io.OutputStream; |
| 138 | import java.io.OutputStreamWriter; |
| 139 | import java.io.PrintWriter; |
| 140 | import java.io.StringWriter; |
| 141 | import java.net.Socket; |
| 142 | import java.util.ArrayList; |
| 143 | import java.util.HashMap; |
| 144 | import java.util.HashSet; |
| 145 | import java.util.Iterator; |
| 146 | import java.util.List; |
| 147 | |
| 148 | /** {@hide} */ |
| Dianne Hackborn | ddca3ee | 2009-07-23 19:01:31 -0700 | [diff] [blame] | 149 | public class WindowManagerService extends IWindowManager.Stub |
| Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 150 | implements Watchdog.Monitor { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 151 | static final String TAG = "WindowManager"; |
| 152 | static final boolean DEBUG = false; |
| 153 | static final boolean DEBUG_FOCUS = false; |
| 154 | static final boolean DEBUG_ANIM = false; |
| Dianne Hackborn | 9b52a21 | 2009-12-11 14:51:35 -0800 | [diff] [blame] | 155 | static final boolean DEBUG_LAYOUT = false; |
| Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 156 | static final boolean DEBUG_RESIZE = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 157 | static final boolean DEBUG_LAYERS = false; |
| 158 | static final boolean DEBUG_INPUT = false; |
| 159 | static final boolean DEBUG_INPUT_METHOD = false; |
| 160 | static final boolean DEBUG_VISIBILITY = false; |
| Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 161 | static final boolean DEBUG_WINDOW_MOVEMENT = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 162 | static final boolean DEBUG_ORIENTATION = false; |
| Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 163 | static final boolean DEBUG_CONFIGURATION = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 164 | static final boolean DEBUG_APP_TRANSITIONS = false; |
| 165 | static final boolean DEBUG_STARTING_WINDOW = false; |
| 166 | static final boolean DEBUG_REORDER = false; |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 167 | static final boolean DEBUG_WALLPAPER = false; |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 168 | static final boolean DEBUG_DRAG = true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 169 | static final boolean SHOW_TRANSACTIONS = false; |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 170 | static final boolean HIDE_STACK_CRAWLS = true; |
| Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 171 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 172 | static final boolean PROFILE_ORIENTATION = false; |
| 173 | static final boolean BLUR = true; |
| Dave Bort | cfe6524 | 2009-04-09 14:51:04 -0700 | [diff] [blame] | 174 | static final boolean localLOGV = DEBUG; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 175 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 176 | /** How much to multiply the policy's type layer, to reserve room |
| 177 | * for multiple windows of the same type and Z-ordering adjustment |
| 178 | * with TYPE_LAYER_OFFSET. */ |
| 179 | static final int TYPE_LAYER_MULTIPLIER = 10000; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 180 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 181 | /** Offset from TYPE_LAYER_MULTIPLIER for moving a group of windows above |
| 182 | * or below others in the same layer. */ |
| 183 | static final int TYPE_LAYER_OFFSET = 1000; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 184 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 185 | /** How much to increment the layer for each window, to reserve room |
| 186 | * for effect surfaces between them. |
| 187 | */ |
| 188 | static final int WINDOW_LAYER_MULTIPLIER = 5; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 189 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 190 | /** The maximum length we will accept for a loaded animation duration: |
| 191 | * this is 10 seconds. |
| 192 | */ |
| 193 | static final int MAX_ANIMATION_DURATION = 10*1000; |
| 194 | |
| 195 | /** Amount of time (in milliseconds) to animate the dim surface from one |
| 196 | * value to another, when no window animation is driving it. |
| 197 | */ |
| 198 | static final int DEFAULT_DIM_DURATION = 200; |
| 199 | |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 200 | /** Amount of time (in milliseconds) to animate the fade-in-out transition for |
| 201 | * compatible windows. |
| 202 | */ |
| 203 | static final int DEFAULT_FADE_IN_OUT_DURATION = 400; |
| 204 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 205 | /** Adjustment to time to perform a dim, to make it more dramatic. |
| 206 | */ |
| 207 | static final int DIM_DURATION_MULTIPLIER = 6; |
| Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 208 | |
| 209 | // Maximum number of milliseconds to wait for input event injection. |
| 210 | // FIXME is this value reasonable? |
| 211 | private static final int INJECTION_TIMEOUT_MILLIS = 30 * 1000; |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 212 | |
| 213 | // Default input dispatching timeout in nanoseconds. |
| 214 | private static final long DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS = 5000 * 1000000L; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 215 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 216 | static final int UPDATE_FOCUS_NORMAL = 0; |
| 217 | static final int UPDATE_FOCUS_WILL_ASSIGN_LAYERS = 1; |
| 218 | static final int UPDATE_FOCUS_PLACING_SURFACES = 2; |
| 219 | static final int UPDATE_FOCUS_WILL_PLACE_SURFACES = 3; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 220 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 221 | private static final String SYSTEM_SECURE = "ro.secure"; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 222 | private static final String SYSTEM_DEBUGGABLE = "ro.debuggable"; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 223 | |
| 224 | /** |
| 225 | * Condition waited on by {@link #reenableKeyguard} to know the call to |
| 226 | * the window policy has finished. |
| Mike Lockwood | 983ee09 | 2009-11-22 01:42:24 -0500 | [diff] [blame] | 227 | * This is set to true only if mKeyguardTokenWatcher.acquired() has |
| 228 | * actually disabled the keyguard. |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 229 | */ |
| Mike Lockwood | 983ee09 | 2009-11-22 01:42:24 -0500 | [diff] [blame] | 230 | private boolean mKeyguardDisabled = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 231 | |
| Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 232 | private static final int ALLOW_DISABLE_YES = 1; |
| 233 | private static final int ALLOW_DISABLE_NO = 0; |
| 234 | private static final int ALLOW_DISABLE_UNKNOWN = -1; // check with DevicePolicyManager |
| 235 | private int mAllowDisableKeyguard = ALLOW_DISABLE_UNKNOWN; // sync'd by mKeyguardTokenWatcher |
| 236 | |
| Mike Lockwood | 983ee09 | 2009-11-22 01:42:24 -0500 | [diff] [blame] | 237 | final TokenWatcher mKeyguardTokenWatcher = new TokenWatcher( |
| 238 | new Handler(), "WindowManagerService.mKeyguardTokenWatcher") { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 239 | public void acquired() { |
| Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 240 | if (shouldAllowDisableKeyguard()) { |
| 241 | mPolicy.enableKeyguard(false); |
| 242 | mKeyguardDisabled = true; |
| 243 | } else { |
| 244 | Log.v(TAG, "Not disabling keyguard since device policy is enforced"); |
| 245 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 246 | } |
| 247 | public void released() { |
| Dianne Hackborn | a33e3f7 | 2009-09-29 17:28:24 -0700 | [diff] [blame] | 248 | mPolicy.enableKeyguard(true); |
| Mike Lockwood | 983ee09 | 2009-11-22 01:42:24 -0500 | [diff] [blame] | 249 | synchronized (mKeyguardTokenWatcher) { |
| 250 | mKeyguardDisabled = false; |
| 251 | mKeyguardTokenWatcher.notifyAll(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 252 | } |
| 253 | } |
| 254 | }; |
| 255 | |
| Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 256 | final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() { |
| 257 | @Override |
| 258 | public void onReceive(Context context, Intent intent) { |
| 259 | mPolicy.enableKeyguard(true); |
| 260 | synchronized(mKeyguardTokenWatcher) { |
| 261 | // lazily evaluate this next time we're asked to disable keyguard |
| 262 | mAllowDisableKeyguard = ALLOW_DISABLE_UNKNOWN; |
| 263 | mKeyguardDisabled = false; |
| 264 | } |
| 265 | } |
| 266 | }; |
| 267 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 268 | final Context mContext; |
| 269 | |
| 270 | final boolean mHaveInputMethods; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 271 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 272 | final boolean mLimitedAlphaCompositing; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 273 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 274 | final WindowManagerPolicy mPolicy = PolicyManager.makeNewWindowManager(); |
| 275 | |
| 276 | final IActivityManager mActivityManager; |
| 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 | final IBatteryStats mBatteryStats; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 279 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 280 | /** |
| 281 | * All currently active sessions with clients. |
| 282 | */ |
| 283 | final HashSet<Session> mSessions = new HashSet<Session>(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 284 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 285 | /** |
| 286 | * Mapping from an IWindow IBinder to the server's Window object. |
| 287 | * This is also used as the lock for all of our state. |
| 288 | */ |
| 289 | final HashMap<IBinder, WindowState> mWindowMap = new HashMap<IBinder, WindowState>(); |
| 290 | |
| 291 | /** |
| 292 | * Mapping from a token IBinder to a WindowToken object. |
| 293 | */ |
| 294 | final HashMap<IBinder, WindowToken> mTokenMap = |
| 295 | new HashMap<IBinder, WindowToken>(); |
| 296 | |
| 297 | /** |
| 298 | * The same tokens as mTokenMap, stored in a list for efficient iteration |
| 299 | * over them. |
| 300 | */ |
| 301 | final ArrayList<WindowToken> mTokenList = new ArrayList<WindowToken>(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 302 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 303 | /** |
| 304 | * Window tokens that are in the process of exiting, but still |
| 305 | * on screen for animations. |
| 306 | */ |
| 307 | final ArrayList<WindowToken> mExitingTokens = new ArrayList<WindowToken>(); |
| 308 | |
| 309 | /** |
| 310 | * Z-ordered (bottom-most first) list of all application tokens, for |
| 311 | * controlling the ordering of windows in different applications. This |
| 312 | * contains WindowToken objects. |
| 313 | */ |
| 314 | final ArrayList<AppWindowToken> mAppTokens = new ArrayList<AppWindowToken>(); |
| 315 | |
| 316 | /** |
| 317 | * Application tokens that are in the process of exiting, but still |
| 318 | * on screen for animations. |
| 319 | */ |
| 320 | final ArrayList<AppWindowToken> mExitingAppTokens = new ArrayList<AppWindowToken>(); |
| 321 | |
| 322 | /** |
| 323 | * List of window tokens that have finished starting their application, |
| 324 | * and now need to have the policy remove their windows. |
| 325 | */ |
| 326 | final ArrayList<AppWindowToken> mFinishedStarting = new ArrayList<AppWindowToken>(); |
| 327 | |
| 328 | /** |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 329 | * This was the app token that was used to retrieve the last enter |
| 330 | * animation. It will be used for the next exit animation. |
| 331 | */ |
| 332 | AppWindowToken mLastEnterAnimToken; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 333 | |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 334 | /** |
| 335 | * These were the layout params used to retrieve the last enter animation. |
| 336 | * They will be used for the next exit animation. |
| 337 | */ |
| 338 | LayoutParams mLastEnterAnimParams; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 339 | |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 340 | /** |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 341 | * Z-ordered (bottom-most first) list of all Window objects. |
| 342 | */ |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 343 | final ArrayList<WindowState> mWindows = new ArrayList<WindowState>(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 344 | |
| 345 | /** |
| 346 | * Windows that are being resized. Used so we can tell the client about |
| 347 | * the resize after closing the transaction in which we resized the |
| 348 | * underlying surface. |
| 349 | */ |
| 350 | final ArrayList<WindowState> mResizingWindows = new ArrayList<WindowState>(); |
| 351 | |
| 352 | /** |
| 353 | * Windows whose animations have ended and now must be removed. |
| 354 | */ |
| 355 | final ArrayList<WindowState> mPendingRemove = new ArrayList<WindowState>(); |
| 356 | |
| 357 | /** |
| 358 | * Windows whose surface should be destroyed. |
| 359 | */ |
| 360 | final ArrayList<WindowState> mDestroySurface = new ArrayList<WindowState>(); |
| 361 | |
| 362 | /** |
| 363 | * Windows that have lost input focus and are waiting for the new |
| 364 | * focus window to be displayed before they are told about this. |
| 365 | */ |
| 366 | ArrayList<WindowState> mLosingFocus = new ArrayList<WindowState>(); |
| 367 | |
| 368 | /** |
| 369 | * This is set when we have run out of memory, and will either be an empty |
| 370 | * list or contain windows that need to be force removed. |
| 371 | */ |
| 372 | ArrayList<WindowState> mForceRemoves; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 373 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 374 | IInputMethodManager mInputMethodManager; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 375 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 376 | SurfaceSession mFxSession; |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 377 | private DimAnimator mDimAnimator = null; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 378 | Surface mBlurSurface; |
| 379 | boolean mBlurShown; |
| Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 380 | Watermark mWatermark; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 381 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 382 | int mTransactionSequence = 0; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 383 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 384 | final float[] mTmpFloats = new float[9]; |
| 385 | |
| 386 | boolean mSafeMode; |
| 387 | boolean mDisplayEnabled = false; |
| 388 | boolean mSystemBooted = false; |
| Christopher Tate | b696aee | 2010-04-02 19:08:30 -0700 | [diff] [blame] | 389 | int mInitialDisplayWidth = 0; |
| 390 | int mInitialDisplayHeight = 0; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 391 | int mRotation = 0; |
| 392 | int mRequestedRotation = 0; |
| 393 | int mForcedAppOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
| Dianne Hackborn | 321ae68 | 2009-03-27 16:16:03 -0700 | [diff] [blame] | 394 | int mLastRotationFlags; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 395 | ArrayList<IRotationWatcher> mRotationWatchers |
| 396 | = new ArrayList<IRotationWatcher>(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 397 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 398 | boolean mLayoutNeeded = true; |
| 399 | boolean mAnimationPending = false; |
| 400 | boolean mDisplayFrozen = false; |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 401 | boolean mWaitingForConfig = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 402 | boolean mWindowsFreezingScreen = false; |
| 403 | long mFreezeGcPending = 0; |
| 404 | int mAppsFreezingScreen = 0; |
| 405 | |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 406 | int mLayoutSeq = 0; |
| 407 | |
| Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 408 | // State while inside of layoutAndPlaceSurfacesLocked(). |
| 409 | boolean mFocusMayChange; |
| 410 | |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 411 | Configuration mCurConfiguration = new Configuration(); |
| 412 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 413 | // This is held as long as we have the screen frozen, to give us time to |
| 414 | // perform a rotation animation when turning off shows the lock screen which |
| 415 | // changes the orientation. |
| 416 | PowerManager.WakeLock mScreenFrozenLock; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 417 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 418 | // State management of app transitions. When we are preparing for a |
| 419 | // transition, mNextAppTransition will be the kind of transition to |
| 420 | // perform or TRANSIT_NONE if we are not waiting. If we are waiting, |
| 421 | // mOpeningApps and mClosingApps are the lists of tokens that will be |
| 422 | // made visible or hidden at the next transition. |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 423 | int mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 424 | String mNextAppTransitionPackage; |
| 425 | int mNextAppTransitionEnter; |
| 426 | int mNextAppTransitionExit; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 427 | boolean mAppTransitionReady = false; |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 428 | boolean mAppTransitionRunning = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 429 | boolean mAppTransitionTimeout = false; |
| 430 | boolean mStartingIconInTransition = false; |
| 431 | boolean mSkipAppTransitionAnimation = false; |
| 432 | final ArrayList<AppWindowToken> mOpeningApps = new ArrayList<AppWindowToken>(); |
| 433 | final ArrayList<AppWindowToken> mClosingApps = new ArrayList<AppWindowToken>(); |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 434 | final ArrayList<AppWindowToken> mToTopApps = new ArrayList<AppWindowToken>(); |
| 435 | final ArrayList<AppWindowToken> mToBottomApps = new ArrayList<AppWindowToken>(); |
| 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 | Display mDisplay; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 438 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 439 | H mH = new H(); |
| 440 | |
| 441 | WindowState mCurrentFocus = null; |
| 442 | WindowState mLastFocus = null; |
| 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 | // This just indicates the window the input method is on top of, not |
| 445 | // necessarily the window its input is going to. |
| 446 | WindowState mInputMethodTarget = null; |
| 447 | WindowState mUpcomingInputMethodTarget = null; |
| 448 | boolean mInputMethodTargetWaitingAnim; |
| 449 | int mInputMethodAnimLayerAdjustment; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 450 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 451 | WindowState mInputMethodWindow = null; |
| 452 | final ArrayList<WindowState> mInputMethodDialogs = new ArrayList<WindowState>(); |
| 453 | |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 454 | final ArrayList<WindowToken> mWallpaperTokens = new ArrayList<WindowToken>(); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 455 | |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 456 | // If non-null, this is the currently visible window that is associated |
| 457 | // with the wallpaper. |
| 458 | WindowState mWallpaperTarget = null; |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 459 | // If non-null, we are in the middle of animating from one wallpaper target |
| 460 | // to another, and this is the lower one in Z-order. |
| 461 | WindowState mLowerWallpaperTarget = null; |
| 462 | // If non-null, we are in the middle of animating from one wallpaper target |
| 463 | // to another, and this is the higher one in Z-order. |
| 464 | WindowState mUpperWallpaperTarget = null; |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 465 | int mWallpaperAnimLayerAdjustment; |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 466 | float mLastWallpaperX = -1; |
| 467 | float mLastWallpaperY = -1; |
| Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 468 | float mLastWallpaperXStep = -1; |
| 469 | float mLastWallpaperYStep = -1; |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 470 | // This is set when we are waiting for a wallpaper to tell us it is done |
| 471 | // changing its scroll position. |
| 472 | WindowState mWaitingOnWallpaper; |
| 473 | // The last time we had a timeout when waiting for a wallpaper. |
| 474 | long mLastWallpaperTimeoutTime; |
| 475 | // We give a wallpaper up to 150ms to finish scrolling. |
| 476 | static final long WALLPAPER_TIMEOUT = 150; |
| 477 | // Time we wait after a timeout before trying to wait again. |
| 478 | static final long WALLPAPER_TIMEOUT_RECOVERY = 10000; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 479 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 480 | AppWindowToken mFocusedApp = null; |
| 481 | |
| 482 | PowerManagerService mPowerManager; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 483 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 484 | float mWindowAnimationScale = 1.0f; |
| 485 | float mTransitionAnimationScale = 1.0f; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 486 | |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 487 | final InputManager mInputManager; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 488 | |
| 489 | // Who is holding the screen on. |
| 490 | Session mHoldingScreenOn; |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 491 | PowerManager.WakeLock mHoldingScreenWakeLock; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 492 | |
| Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 493 | boolean mTurnOnScreen; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 494 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 495 | /** |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 496 | * Drag/drop state |
| 497 | */ |
| 498 | class DragState { |
| 499 | IBinder mToken; |
| 500 | Surface mSurface; |
| 501 | boolean mLocalOnly; |
| 502 | ClipData mData; |
| 503 | ClipDescription mDataDescription; |
| Chris Tate | d4533f14 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 504 | boolean mDragResult; |
| Chris Tate | b478f46 | 2010-10-15 16:02:26 -0700 | [diff] [blame] | 505 | float mCurrentX, mCurrentY; |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 506 | float mThumbOffsetX, mThumbOffsetY; |
| 507 | InputChannel mServerChannel, mClientChannel; |
| 508 | WindowState mTargetWindow; |
| 509 | ArrayList<WindowState> mNotifiedWindows; |
| Christopher Tate | 5ada6cb | 2010-10-05 14:15:29 -0700 | [diff] [blame] | 510 | boolean mDragInProgress; |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 511 | |
| 512 | private final Rect tmpRect = new Rect(); |
| 513 | |
| 514 | DragState(IBinder token, Surface surface, boolean localOnly) { |
| 515 | mToken = token; |
| 516 | mSurface = surface; |
| 517 | mLocalOnly = localOnly; |
| 518 | mNotifiedWindows = new ArrayList<WindowState>(); |
| 519 | } |
| 520 | |
| 521 | void reset() { |
| 522 | if (mSurface != null) { |
| 523 | mSurface.destroy(); |
| 524 | } |
| 525 | mSurface = null; |
| 526 | mLocalOnly = false; |
| 527 | mToken = null; |
| 528 | mData = null; |
| 529 | mThumbOffsetX = mThumbOffsetY = 0; |
| 530 | mNotifiedWindows = null; |
| 531 | } |
| 532 | |
| 533 | void register() { |
| 534 | if (DEBUG_DRAG) Slog.d(TAG, "registering drag input channel"); |
| 535 | if (mClientChannel != null) { |
| 536 | Slog.e(TAG, "Duplicate register of drag input channel"); |
| 537 | } else { |
| 538 | InputChannel[] channels = InputChannel.openInputChannelPair("drag"); |
| 539 | mServerChannel = channels[0]; |
| 540 | mClientChannel = channels[1]; |
| 541 | mInputManager.registerInputChannel(mServerChannel); |
| 542 | InputQueue.registerInputChannel(mClientChannel, mDragInputHandler, |
| 543 | mH.getLooper().getQueue()); |
| 544 | } |
| 545 | } |
| 546 | |
| 547 | void unregister() { |
| 548 | if (DEBUG_DRAG) Slog.d(TAG, "unregistering drag input channel"); |
| 549 | if (mClientChannel == null) { |
| 550 | Slog.e(TAG, "Unregister of nonexistent drag input channel"); |
| 551 | } else { |
| 552 | mInputManager.unregisterInputChannel(mServerChannel); |
| 553 | InputQueue.unregisterInputChannel(mClientChannel); |
| 554 | mClientChannel.dispose(); |
| Chris Tate | ef70a07 | 2010-10-22 19:10:34 -0700 | [diff] [blame] | 555 | mServerChannel.dispose(); |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 556 | mClientChannel = null; |
| 557 | mServerChannel = null; |
| 558 | } |
| 559 | } |
| 560 | |
| Chris Tate | a32dcf7 | 2010-10-14 12:13:50 -0700 | [diff] [blame] | 561 | int getDragLayerLw() { |
| 562 | return mPolicy.windowTypeToLayerLw(WindowManager.LayoutParams.TYPE_DRAG) |
| 563 | * TYPE_LAYER_MULTIPLIER |
| 564 | + TYPE_LAYER_OFFSET; |
| 565 | } |
| 566 | |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 567 | /* call out to each visible window/session informing it about the drag |
| 568 | */ |
| Chris Tate | b8203e9 | 2010-10-12 14:23:21 -0700 | [diff] [blame] | 569 | void broadcastDragStartedLw(final float touchX, final float touchY) { |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 570 | // Cache a base-class instance of the clip metadata so that parceling |
| 571 | // works correctly in calling out to the apps. |
| Dianne Hackborn | f834dfa | 2010-10-26 12:43:57 -0700 | [diff] [blame] | 572 | mDataDescription = mData.getDescription(); |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 573 | mNotifiedWindows.clear(); |
| Christopher Tate | 5ada6cb | 2010-10-05 14:15:29 -0700 | [diff] [blame] | 574 | mDragInProgress = true; |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 575 | |
| 576 | if (DEBUG_DRAG) { |
| Chris Tate | b478f46 | 2010-10-15 16:02:26 -0700 | [diff] [blame] | 577 | Slog.d(TAG, "broadcasting DRAG_STARTED at (" + touchX + ", " + touchY + ")"); |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 578 | } |
| 579 | |
| Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 580 | final int N = mWindows.size(); |
| 581 | for (int i = 0; i < N; i++) { |
| Chris Tate | b478f46 | 2010-10-15 16:02:26 -0700 | [diff] [blame] | 582 | sendDragStartedLw(mWindows.get(i), touchX, touchY, mDataDescription); |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 583 | } |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 584 | } |
| 585 | |
| 586 | /* helper - send a caller-provided event, presumed to be DRAG_STARTED, if the |
| 587 | * designated window is potentially a drop recipient. There are race situations |
| 588 | * around DRAG_ENDED broadcast, so we make sure that once we've declared that |
| 589 | * the drag has ended, we never send out another DRAG_STARTED for this drag action. |
| Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 590 | * |
| 591 | * This method clones the 'event' parameter if it's being delivered to the same |
| 592 | * process, so it's safe for the caller to call recycle() on the event afterwards. |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 593 | */ |
| Chris Tate | b478f46 | 2010-10-15 16:02:26 -0700 | [diff] [blame] | 594 | private void sendDragStartedLw(WindowState newWin, float touchX, float touchY, |
| 595 | ClipDescription desc) { |
| Christopher Tate | 5ada6cb | 2010-10-05 14:15:29 -0700 | [diff] [blame] | 596 | if (mDragInProgress && newWin.isPotentialDragTarget()) { |
| Chris Tate | b478f46 | 2010-10-15 16:02:26 -0700 | [diff] [blame] | 597 | DragEvent event = DragEvent.obtain(DragEvent.ACTION_DRAG_STARTED, |
| 598 | touchX - newWin.mFrame.left, touchY - newWin.mFrame.top, |
| Chris Tate | d4533f14 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 599 | desc, null, false); |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 600 | try { |
| 601 | newWin.mClient.dispatchDragEvent(event); |
| 602 | // track each window that we've notified that the drag is starting |
| 603 | mNotifiedWindows.add(newWin); |
| 604 | } catch (RemoteException e) { |
| 605 | Slog.w(TAG, "Unable to drag-start window " + newWin); |
| Chris Tate | b478f46 | 2010-10-15 16:02:26 -0700 | [diff] [blame] | 606 | } finally { |
| 607 | // if the callee was local, the dispatch has already recycled the event |
| 608 | if (Process.myPid() != newWin.mSession.mPid) { |
| 609 | event.recycle(); |
| 610 | } |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 611 | } |
| 612 | } |
| 613 | } |
| 614 | |
| 615 | /* helper - construct and send a DRAG_STARTED event only if the window has not |
| 616 | * previously been notified, i.e. it became visible after the drag operation |
| 617 | * was begun. This is a rare case. |
| 618 | */ |
| 619 | private void sendDragStartedIfNeededLw(WindowState newWin) { |
| Christopher Tate | 5ada6cb | 2010-10-05 14:15:29 -0700 | [diff] [blame] | 620 | if (mDragInProgress) { |
| 621 | // If we have sent the drag-started, we needn't do so again |
| 622 | for (WindowState ws : mNotifiedWindows) { |
| 623 | if (ws == newWin) { |
| 624 | return; |
| 625 | } |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 626 | } |
| Christopher Tate | 5ada6cb | 2010-10-05 14:15:29 -0700 | [diff] [blame] | 627 | if (DEBUG_DRAG) { |
| Chris Tate | ef70a07 | 2010-10-22 19:10:34 -0700 | [diff] [blame] | 628 | Slog.d(TAG, "need to send DRAG_STARTED to new window " + newWin); |
| Christopher Tate | 5ada6cb | 2010-10-05 14:15:29 -0700 | [diff] [blame] | 629 | } |
| Chris Tate | b478f46 | 2010-10-15 16:02:26 -0700 | [diff] [blame] | 630 | sendDragStartedLw(newWin, mCurrentX, mCurrentY, mDataDescription); |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 631 | } |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 632 | } |
| 633 | |
| Chris Tate | d4533f14 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 634 | void broadcastDragEndedLw() { |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 635 | if (DEBUG_DRAG) { |
| 636 | Slog.d(TAG, "broadcasting DRAG_ENDED"); |
| 637 | } |
| Chris Tate | d4533f14 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 638 | DragEvent evt = DragEvent.obtain(DragEvent.ACTION_DRAG_ENDED, |
| 639 | 0, 0, null, null, mDragResult); |
| 640 | for (WindowState ws: mNotifiedWindows) { |
| 641 | try { |
| 642 | ws.mClient.dispatchDragEvent(evt); |
| 643 | } catch (RemoteException e) { |
| 644 | Slog.w(TAG, "Unable to drag-end window " + ws); |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 645 | } |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 646 | } |
| Chris Tate | d4533f14 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 647 | mNotifiedWindows.clear(); |
| 648 | mDragInProgress = false; |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 649 | evt.recycle(); |
| 650 | } |
| 651 | |
| Chris Tate | d4533f14 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 652 | void endDragLw() { |
| 653 | mDragState.broadcastDragEndedLw(); |
| 654 | |
| 655 | // stop intercepting input |
| 656 | mDragState.unregister(); |
| 657 | mInputMonitor.updateInputWindowsLw(); |
| 658 | |
| 659 | // free our resources and drop all the object references |
| 660 | mDragState.reset(); |
| 661 | mDragState = null; |
| 662 | } |
| 663 | |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 664 | void notifyMoveLw(float x, float y) { |
| Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 665 | final int myPid = Process.myPid(); |
| 666 | |
| 667 | // Move the surface to the given touch |
| 668 | mSurface.openTransaction(); |
| 669 | mSurface.setPosition((int)(x - mThumbOffsetX), (int)(y - mThumbOffsetY)); |
| 670 | mSurface.closeTransaction(); |
| 671 | |
| 672 | // Tell the affected window |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 673 | WindowState touchedWin = getTouchedWinAtPointLw(x, y); |
| 674 | try { |
| 675 | // have we dragged over a new window? |
| 676 | if ((touchedWin != mTargetWindow) && (mTargetWindow != null)) { |
| 677 | if (DEBUG_DRAG) { |
| 678 | Slog.d(TAG, "sending DRAG_EXITED to " + mTargetWindow); |
| 679 | } |
| 680 | // force DRAG_EXITED_EVENT if appropriate |
| 681 | DragEvent evt = DragEvent.obtain(DragEvent.ACTION_DRAG_EXITED, |
| Chris Tate | b478f46 | 2010-10-15 16:02:26 -0700 | [diff] [blame] | 682 | x - mTargetWindow.mFrame.left, y - mTargetWindow.mFrame.top, |
| Chris Tate | d4533f14 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 683 | null, null, false); |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 684 | mTargetWindow.mClient.dispatchDragEvent(evt); |
| Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 685 | if (myPid != mTargetWindow.mSession.mPid) { |
| 686 | evt.recycle(); |
| 687 | } |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 688 | } |
| 689 | if (touchedWin != null) { |
| Chris Tate | 9d1ab88 | 2010-11-02 15:55:39 -0700 | [diff] [blame^] | 690 | if (false && DEBUG_DRAG) { |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 691 | Slog.d(TAG, "sending DRAG_LOCATION to " + touchedWin); |
| 692 | } |
| 693 | DragEvent evt = DragEvent.obtain(DragEvent.ACTION_DRAG_LOCATION, |
| Chris Tate | b478f46 | 2010-10-15 16:02:26 -0700 | [diff] [blame] | 694 | x - touchedWin.mFrame.left, y - touchedWin.mFrame.top, |
| Chris Tate | d4533f14 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 695 | null, null, false); |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 696 | touchedWin.mClient.dispatchDragEvent(evt); |
| Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 697 | if (myPid != touchedWin.mSession.mPid) { |
| 698 | evt.recycle(); |
| 699 | } |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 700 | } |
| 701 | } catch (RemoteException e) { |
| 702 | Slog.w(TAG, "can't send drag notification to windows"); |
| 703 | } |
| 704 | mTargetWindow = touchedWin; |
| 705 | } |
| 706 | |
| Chris Tate | d4533f14 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 707 | // Tell the drop target about the data. Returns 'true' if we can immediately |
| 708 | // dispatch the global drag-ended message, 'false' if we need to wait for a |
| 709 | // result from the recipient. |
| 710 | boolean notifyDropLw(float x, float y) { |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 711 | WindowState touchedWin = getTouchedWinAtPointLw(x, y); |
| Chris Tate | d4533f14 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 712 | if (touchedWin == null) { |
| 713 | // "drop" outside a valid window -- no recipient to apply a |
| 714 | // timeout to, and we can send the drag-ended message immediately. |
| 715 | mDragResult = false; |
| 716 | return true; |
| 717 | } |
| 718 | |
| 719 | if (DEBUG_DRAG) { |
| 720 | Slog.d(TAG, "sending DROP to " + touchedWin); |
| 721 | } |
| 722 | final int myPid = Process.myPid(); |
| 723 | final IBinder token = touchedWin.mClient.asBinder(); |
| 724 | DragEvent evt = DragEvent.obtain(DragEvent.ACTION_DROP, |
| 725 | x - touchedWin.mFrame.left, y - touchedWin.mFrame.top, |
| 726 | null, mData, false); |
| 727 | try { |
| 728 | touchedWin.mClient.dispatchDragEvent(evt); |
| 729 | |
| 730 | // 5 second timeout for this window to respond to the drop |
| 731 | mH.removeMessages(H.DRAG_END_TIMEOUT, token); |
| 732 | Message msg = mH.obtainMessage(H.DRAG_END_TIMEOUT, token); |
| 733 | mH.sendMessageDelayed(msg, 5000); |
| 734 | } catch (RemoteException e) { |
| 735 | Slog.w(TAG, "can't send drop notification to win " + touchedWin); |
| 736 | return true; |
| 737 | } finally { |
| Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 738 | if (myPid != touchedWin.mSession.mPid) { |
| 739 | evt.recycle(); |
| 740 | } |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 741 | } |
| Chris Tate | d4533f14 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 742 | mToken = token; |
| 743 | return false; |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 744 | } |
| 745 | |
| 746 | // Find the visible, touch-deliverable window under the given point |
| 747 | private WindowState getTouchedWinAtPointLw(float xf, float yf) { |
| 748 | WindowState touchedWin = null; |
| 749 | final int x = (int) xf; |
| 750 | final int y = (int) yf; |
| 751 | final ArrayList<WindowState> windows = mWindows; |
| 752 | final int N = windows.size(); |
| 753 | for (int i = N - 1; i >= 0; i--) { |
| 754 | WindowState child = windows.get(i); |
| 755 | final int flags = child.mAttrs.flags; |
| 756 | if (!child.isVisibleLw()) { |
| 757 | // not visible == don't tell about drags |
| 758 | continue; |
| 759 | } |
| 760 | if ((flags & WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE) != 0) { |
| 761 | // not touchable == don't tell about drags |
| 762 | continue; |
| 763 | } |
| 764 | // account for the window's decor etc |
| 765 | tmpRect.set(child.mFrame); |
| 766 | if (child.mTouchableInsets == ViewTreeObserver |
| 767 | .InternalInsetsInfo.TOUCHABLE_INSETS_CONTENT) { |
| 768 | // The point is inside of the window if it is |
| 769 | // inside the frame, AND the content part of that |
| 770 | // frame that was given by the application. |
| 771 | tmpRect.left += child.mGivenContentInsets.left; |
| 772 | tmpRect.top += child.mGivenContentInsets.top; |
| 773 | tmpRect.right -= child.mGivenContentInsets.right; |
| 774 | tmpRect.bottom -= child.mGivenContentInsets.bottom; |
| 775 | } else if (child.mTouchableInsets == ViewTreeObserver |
| 776 | .InternalInsetsInfo.TOUCHABLE_INSETS_VISIBLE) { |
| 777 | // The point is inside of the window if it is |
| 778 | // inside the frame, AND the visible part of that |
| 779 | // frame that was given by the application. |
| 780 | tmpRect.left += child.mGivenVisibleInsets.left; |
| 781 | tmpRect.top += child.mGivenVisibleInsets.top; |
| 782 | tmpRect.right -= child.mGivenVisibleInsets.right; |
| 783 | tmpRect.bottom -= child.mGivenVisibleInsets.bottom; |
| 784 | } |
| 785 | final int touchFlags = flags & |
| 786 | (WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE |
| 787 | | WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL); |
| 788 | if (tmpRect.contains(x, y) || touchFlags == 0) { |
| 789 | // Found it |
| 790 | touchedWin = child; |
| 791 | break; |
| 792 | } |
| 793 | } |
| 794 | |
| 795 | return touchedWin; |
| 796 | } |
| 797 | } |
| 798 | |
| 799 | DragState mDragState = null; |
| 800 | private final InputHandler mDragInputHandler = new BaseInputHandler() { |
| 801 | @Override |
| 802 | public void handleMotion(MotionEvent event, Runnable finishedCallback) { |
| 803 | boolean endDrag = false; |
| 804 | final float newX = event.getRawX(); |
| 805 | final float newY = event.getRawY(); |
| 806 | |
| 807 | try { |
| 808 | if (mDragState != null) { |
| 809 | switch (event.getAction()) { |
| 810 | case MotionEvent.ACTION_DOWN: { |
| 811 | if (DEBUG_DRAG) { |
| 812 | Slog.w(TAG, "Unexpected ACTION_DOWN in drag layer"); |
| 813 | } |
| 814 | } break; |
| 815 | |
| 816 | case MotionEvent.ACTION_MOVE: { |
| 817 | synchronized (mWindowMap) { |
| Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 818 | // move the surface and tell the involved window(s) where we are |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 819 | mDragState.notifyMoveLw(newX, newY); |
| 820 | } |
| 821 | } break; |
| 822 | |
| 823 | case MotionEvent.ACTION_UP: { |
| 824 | if (DEBUG_DRAG) Slog.d(TAG, "Got UP on move channel; dropping at " |
| 825 | + newX + "," + newY); |
| 826 | synchronized (mWindowMap) { |
| Chris Tate | d4533f14 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 827 | endDrag = mDragState.notifyDropLw(newX, newY); |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 828 | } |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 829 | } break; |
| 830 | |
| 831 | case MotionEvent.ACTION_CANCEL: { |
| 832 | if (DEBUG_DRAG) Slog.d(TAG, "Drag cancelled!"); |
| 833 | endDrag = true; |
| 834 | } break; |
| 835 | } |
| 836 | |
| 837 | if (endDrag) { |
| 838 | if (DEBUG_DRAG) Slog.d(TAG, "Drag ended; tearing down state"); |
| 839 | // tell all the windows that the drag has ended |
| Chris Tate | 5994359 | 2010-10-11 20:33:44 -0700 | [diff] [blame] | 840 | synchronized (mWindowMap) { |
| Chris Tate | d4533f14 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 841 | mDragState.endDragLw(); |
| Chris Tate | 5994359 | 2010-10-11 20:33:44 -0700 | [diff] [blame] | 842 | } |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 843 | } |
| 844 | } |
| 845 | } catch (Exception e) { |
| 846 | Slog.e(TAG, "Exception caught by drag handleMotion", e); |
| 847 | } finally { |
| 848 | finishedCallback.run(); |
| 849 | } |
| 850 | } |
| 851 | }; |
| 852 | |
| 853 | /** |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 854 | * Whether the UI is currently running in touch mode (not showing |
| 855 | * navigational focus because the user is directly pressing the screen). |
| 856 | */ |
| 857 | boolean mInTouchMode = false; |
| 858 | |
| 859 | private ViewServer mViewServer; |
| Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 860 | private ArrayList<WindowChangeListener> mWindowChangeListeners = |
| 861 | new ArrayList<WindowChangeListener>(); |
| 862 | private boolean mWindowsChanged = false; |
| 863 | |
| 864 | public interface WindowChangeListener { |
| 865 | public void windowsChanged(); |
| Konstantin Lopyrev | 6e0f65f | 2010-07-14 14:55:33 -0700 | [diff] [blame] | 866 | public void focusChanged(); |
| Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 867 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 868 | |
| Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 869 | final Configuration mTempConfiguration = new Configuration(); |
| Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 870 | int mScreenLayout = Configuration.SCREENLAYOUT_SIZE_UNDEFINED; |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 871 | |
| 872 | // The frame use to limit the size of the app running in compatibility mode. |
| 873 | Rect mCompatibleScreenFrame = new Rect(); |
| 874 | // The surface used to fill the outer rim of the app running in compatibility mode. |
| 875 | Surface mBackgroundFillerSurface = null; |
| 876 | boolean mBackgroundFillerShown = false; |
| 877 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 878 | public static WindowManagerService main(Context context, |
| 879 | PowerManagerService pm, boolean haveInputMethods) { |
| 880 | WMThread thr = new WMThread(context, pm, haveInputMethods); |
| 881 | thr.start(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 882 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 883 | synchronized (thr) { |
| 884 | while (thr.mService == null) { |
| 885 | try { |
| 886 | thr.wait(); |
| 887 | } catch (InterruptedException e) { |
| 888 | } |
| 889 | } |
| 890 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 891 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 892 | return thr.mService; |
| 893 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 894 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 895 | static class WMThread extends Thread { |
| 896 | WindowManagerService mService; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 897 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 898 | private final Context mContext; |
| 899 | private final PowerManagerService mPM; |
| 900 | private final boolean mHaveInputMethods; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 901 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 902 | public WMThread(Context context, PowerManagerService pm, |
| 903 | boolean haveInputMethods) { |
| 904 | super("WindowManager"); |
| 905 | mContext = context; |
| 906 | mPM = pm; |
| 907 | mHaveInputMethods = haveInputMethods; |
| 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 | public void run() { |
| 911 | Looper.prepare(); |
| 912 | WindowManagerService s = new WindowManagerService(mContext, mPM, |
| 913 | mHaveInputMethods); |
| 914 | android.os.Process.setThreadPriority( |
| 915 | android.os.Process.THREAD_PRIORITY_DISPLAY); |
| Christopher Tate | 160edb3 | 2010-06-30 17:46:30 -0700 | [diff] [blame] | 916 | android.os.Process.setCanSelfBackground(false); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 917 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 918 | synchronized (this) { |
| 919 | mService = s; |
| 920 | notifyAll(); |
| 921 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 922 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 923 | Looper.loop(); |
| 924 | } |
| 925 | } |
| 926 | |
| 927 | static class PolicyThread extends Thread { |
| 928 | private final WindowManagerPolicy mPolicy; |
| 929 | private final WindowManagerService mService; |
| 930 | private final Context mContext; |
| 931 | private final PowerManagerService mPM; |
| 932 | boolean mRunning = false; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 933 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 934 | public PolicyThread(WindowManagerPolicy policy, |
| 935 | WindowManagerService service, Context context, |
| 936 | PowerManagerService pm) { |
| 937 | super("WindowManagerPolicy"); |
| 938 | mPolicy = policy; |
| 939 | mService = service; |
| 940 | mContext = context; |
| 941 | mPM = pm; |
| 942 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 943 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 944 | public void run() { |
| 945 | Looper.prepare(); |
| Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 946 | WindowManagerPolicyThread.set(this, Looper.myLooper()); |
| 947 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 948 | //Looper.myLooper().setMessageLogging(new LogPrinter( |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 949 | // Log.VERBOSE, "WindowManagerPolicy", Log.LOG_ID_SYSTEM)); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 950 | android.os.Process.setThreadPriority( |
| 951 | android.os.Process.THREAD_PRIORITY_FOREGROUND); |
| Christopher Tate | 160edb3 | 2010-06-30 17:46:30 -0700 | [diff] [blame] | 952 | android.os.Process.setCanSelfBackground(false); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 953 | mPolicy.init(mContext, mService, mPM); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 954 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 955 | synchronized (this) { |
| 956 | mRunning = true; |
| 957 | notifyAll(); |
| 958 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 959 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 960 | Looper.loop(); |
| 961 | } |
| 962 | } |
| 963 | |
| 964 | private WindowManagerService(Context context, PowerManagerService pm, |
| 965 | boolean haveInputMethods) { |
| 966 | mContext = context; |
| 967 | mHaveInputMethods = haveInputMethods; |
| 968 | mLimitedAlphaCompositing = context.getResources().getBoolean( |
| 969 | com.android.internal.R.bool.config_sf_limitedAlpha); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 970 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 971 | mPowerManager = pm; |
| 972 | mPowerManager.setPolicy(mPolicy); |
| 973 | PowerManager pmc = (PowerManager)context.getSystemService(Context.POWER_SERVICE); |
| 974 | mScreenFrozenLock = pmc.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, |
| 975 | "SCREEN_FROZEN"); |
| 976 | mScreenFrozenLock.setReferenceCounted(false); |
| 977 | |
| 978 | mActivityManager = ActivityManagerNative.getDefault(); |
| 979 | mBatteryStats = BatteryStatsService.getService(); |
| 980 | |
| 981 | // Get persisted window scale setting |
| 982 | mWindowAnimationScale = Settings.System.getFloat(context.getContentResolver(), |
| 983 | Settings.System.WINDOW_ANIMATION_SCALE, mWindowAnimationScale); |
| 984 | mTransitionAnimationScale = Settings.System.getFloat(context.getContentResolver(), |
| 985 | Settings.System.TRANSITION_ANIMATION_SCALE, mTransitionAnimationScale); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 986 | |
| Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 987 | // Track changes to DevicePolicyManager state so we can enable/disable keyguard. |
| 988 | IntentFilter filter = new IntentFilter(); |
| 989 | filter.addAction(DevicePolicyManager.ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED); |
| 990 | mContext.registerReceiver(mBroadcastReceiver, filter); |
| 991 | |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 992 | mHoldingScreenWakeLock = pmc.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK, |
| 993 | "KEEP_SCREEN_ON_FLAG"); |
| 994 | mHoldingScreenWakeLock.setReferenceCounted(false); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 995 | |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 996 | mInputManager = new InputManager(context, this); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 997 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 998 | PolicyThread thr = new PolicyThread(mPolicy, this, context, pm); |
| 999 | thr.start(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1000 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1001 | synchronized (thr) { |
| 1002 | while (!thr.mRunning) { |
| 1003 | try { |
| 1004 | thr.wait(); |
| 1005 | } catch (InterruptedException e) { |
| 1006 | } |
| 1007 | } |
| 1008 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1009 | |
| Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 1010 | mInputManager.start(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1011 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1012 | // Add ourself to the Watchdog monitors. |
| 1013 | Watchdog.getInstance().addMonitor(this); |
| 1014 | } |
| 1015 | |
| 1016 | @Override |
| 1017 | public boolean onTransact(int code, Parcel data, Parcel reply, int flags) |
| 1018 | throws RemoteException { |
| 1019 | try { |
| 1020 | return super.onTransact(code, data, reply, flags); |
| 1021 | } catch (RuntimeException e) { |
| 1022 | // The window manager only throws security exceptions, so let's |
| 1023 | // log all others. |
| 1024 | if (!(e instanceof SecurityException)) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1025 | Slog.e(TAG, "Window Manager Crash", e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1026 | } |
| 1027 | throw e; |
| 1028 | } |
| 1029 | } |
| 1030 | |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1031 | private void placeWindowAfter(WindowState pos, WindowState window) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1032 | final int i = mWindows.indexOf(pos); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1033 | if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1034 | TAG, "Adding window " + window + " at " |
| 1035 | + (i+1) + " of " + mWindows.size() + " (after " + pos + ")"); |
| 1036 | mWindows.add(i+1, window); |
| Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 1037 | mWindowsChanged = true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1038 | } |
| 1039 | |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1040 | private void placeWindowBefore(WindowState pos, WindowState window) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1041 | final int i = mWindows.indexOf(pos); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1042 | if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1043 | TAG, "Adding window " + window + " at " |
| 1044 | + i + " of " + mWindows.size() + " (before " + pos + ")"); |
| 1045 | mWindows.add(i, window); |
| Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 1046 | mWindowsChanged = true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1047 | } |
| 1048 | |
| 1049 | //This method finds out the index of a window that has the same app token as |
| 1050 | //win. used for z ordering the windows in mWindows |
| 1051 | private int findIdxBasedOnAppTokens(WindowState win) { |
| 1052 | //use a local variable to cache mWindows |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1053 | ArrayList<WindowState> localmWindows = mWindows; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1054 | int jmax = localmWindows.size(); |
| 1055 | if(jmax == 0) { |
| 1056 | return -1; |
| 1057 | } |
| 1058 | for(int j = (jmax-1); j >= 0; j--) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1059 | WindowState wentry = localmWindows.get(j); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1060 | if(wentry.mAppToken == win.mAppToken) { |
| 1061 | return j; |
| 1062 | } |
| 1063 | } |
| 1064 | return -1; |
| 1065 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1066 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1067 | private void addWindowToListInOrderLocked(WindowState win, boolean addToToken) { |
| 1068 | final IWindow client = win.mClient; |
| 1069 | final WindowToken token = win.mToken; |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1070 | final ArrayList<WindowState> localmWindows = mWindows; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1071 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1072 | final int N = localmWindows.size(); |
| 1073 | final WindowState attached = win.mAttachedWindow; |
| 1074 | int i; |
| 1075 | if (attached == null) { |
| 1076 | int tokenWindowsPos = token.windows.size(); |
| 1077 | if (token.appWindowToken != null) { |
| 1078 | int index = tokenWindowsPos-1; |
| 1079 | if (index >= 0) { |
| 1080 | // If this application has existing windows, we |
| 1081 | // simply place the new window on top of them... but |
| 1082 | // keep the starting window on top. |
| 1083 | if (win.mAttrs.type == TYPE_BASE_APPLICATION) { |
| 1084 | // Base windows go behind everything else. |
| 1085 | placeWindowBefore(token.windows.get(0), win); |
| 1086 | tokenWindowsPos = 0; |
| 1087 | } else { |
| 1088 | AppWindowToken atoken = win.mAppToken; |
| 1089 | if (atoken != null && |
| 1090 | token.windows.get(index) == atoken.startingWindow) { |
| 1091 | placeWindowBefore(token.windows.get(index), win); |
| 1092 | tokenWindowsPos--; |
| 1093 | } else { |
| 1094 | int newIdx = findIdxBasedOnAppTokens(win); |
| 1095 | if(newIdx != -1) { |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1096 | //there is a window above this one associated with the same |
| 1097 | //apptoken note that the window could be a floating window |
| 1098 | //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] | 1099 | //windows associated with this token. |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1100 | if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v( |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 1101 | TAG, "Adding window " + win + " at " |
| 1102 | + (newIdx+1) + " of " + N); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1103 | localmWindows.add(newIdx+1, win); |
| Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 1104 | mWindowsChanged = true; |
| 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 | } |
| 1107 | } |
| 1108 | } else { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1109 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1110 | TAG, "Figuring out where to add app window " |
| 1111 | + client.asBinder() + " (token=" + token + ")"); |
| 1112 | // Figure out where the window should go, based on the |
| 1113 | // order of applications. |
| 1114 | final int NA = mAppTokens.size(); |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1115 | WindowState pos = null; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1116 | for (i=NA-1; i>=0; i--) { |
| 1117 | AppWindowToken t = mAppTokens.get(i); |
| 1118 | if (t == token) { |
| 1119 | i--; |
| 1120 | break; |
| 1121 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1122 | |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 1123 | // We haven't reached the token yet; if this token |
| 1124 | // is not going to the bottom and has windows, we can |
| 1125 | // use it as an anchor for when we do reach the token. |
| 1126 | if (!t.sendingToBottom && t.windows.size() > 0) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1127 | pos = t.windows.get(0); |
| 1128 | } |
| 1129 | } |
| 1130 | // We now know the index into the apps. If we found |
| 1131 | // an app window above, that gives us the position; else |
| 1132 | // we need to look some more. |
| 1133 | if (pos != null) { |
| 1134 | // Move behind any windows attached to this one. |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1135 | WindowToken atoken = mTokenMap.get(pos.mClient.asBinder()); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1136 | if (atoken != null) { |
| 1137 | final int NC = atoken.windows.size(); |
| 1138 | if (NC > 0) { |
| 1139 | WindowState bottom = atoken.windows.get(0); |
| 1140 | if (bottom.mSubLayer < 0) { |
| 1141 | pos = bottom; |
| 1142 | } |
| 1143 | } |
| 1144 | } |
| 1145 | placeWindowBefore(pos, win); |
| 1146 | } else { |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 1147 | // Continue looking down until we find the first |
| 1148 | // token that has windows. |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1149 | while (i >= 0) { |
| 1150 | AppWindowToken t = mAppTokens.get(i); |
| 1151 | final int NW = t.windows.size(); |
| 1152 | if (NW > 0) { |
| 1153 | pos = t.windows.get(NW-1); |
| 1154 | break; |
| 1155 | } |
| 1156 | i--; |
| 1157 | } |
| 1158 | if (pos != null) { |
| 1159 | // Move in front of any windows attached to this |
| 1160 | // one. |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1161 | WindowToken atoken = mTokenMap.get(pos.mClient.asBinder()); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1162 | if (atoken != null) { |
| 1163 | final int NC = atoken.windows.size(); |
| 1164 | if (NC > 0) { |
| 1165 | WindowState top = atoken.windows.get(NC-1); |
| 1166 | if (top.mSubLayer >= 0) { |
| 1167 | pos = top; |
| 1168 | } |
| 1169 | } |
| 1170 | } |
| 1171 | placeWindowAfter(pos, win); |
| 1172 | } else { |
| 1173 | // Just search for the start of this layer. |
| 1174 | final int myLayer = win.mBaseLayer; |
| 1175 | for (i=0; i<N; i++) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1176 | WindowState w = localmWindows.get(i); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1177 | if (w.mBaseLayer > myLayer) { |
| 1178 | break; |
| 1179 | } |
| 1180 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1181 | if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v( |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 1182 | TAG, "Adding window " + win + " at " |
| 1183 | + i + " of " + N); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1184 | localmWindows.add(i, win); |
| Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 1185 | mWindowsChanged = true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1186 | } |
| 1187 | } |
| 1188 | } |
| 1189 | } else { |
| 1190 | // Figure out where window should go, based on layer. |
| 1191 | final int myLayer = win.mBaseLayer; |
| 1192 | for (i=N-1; i>=0; i--) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1193 | if (localmWindows.get(i).mBaseLayer <= myLayer) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1194 | i++; |
| 1195 | break; |
| 1196 | } |
| 1197 | } |
| 1198 | if (i < 0) i = 0; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1199 | if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v( |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 1200 | TAG, "Adding window " + win + " at " |
| 1201 | + i + " of " + N); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1202 | localmWindows.add(i, win); |
| Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 1203 | mWindowsChanged = true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1204 | } |
| 1205 | if (addToToken) { |
| 1206 | token.windows.add(tokenWindowsPos, win); |
| 1207 | } |
| 1208 | |
| 1209 | } else { |
| 1210 | // Figure out this window's ordering relative to the window |
| 1211 | // it is attached to. |
| 1212 | final int NA = token.windows.size(); |
| 1213 | final int sublayer = win.mSubLayer; |
| 1214 | int largestSublayer = Integer.MIN_VALUE; |
| 1215 | WindowState windowWithLargestSublayer = null; |
| 1216 | for (i=0; i<NA; i++) { |
| 1217 | WindowState w = token.windows.get(i); |
| 1218 | final int wSublayer = w.mSubLayer; |
| 1219 | if (wSublayer >= largestSublayer) { |
| 1220 | largestSublayer = wSublayer; |
| 1221 | windowWithLargestSublayer = w; |
| 1222 | } |
| 1223 | if (sublayer < 0) { |
| 1224 | // For negative sublayers, we go below all windows |
| 1225 | // in the same sublayer. |
| 1226 | if (wSublayer >= sublayer) { |
| 1227 | if (addToToken) { |
| 1228 | token.windows.add(i, win); |
| 1229 | } |
| 1230 | placeWindowBefore( |
| 1231 | wSublayer >= 0 ? attached : w, win); |
| 1232 | break; |
| 1233 | } |
| 1234 | } else { |
| 1235 | // For positive sublayers, we go above all windows |
| 1236 | // in the same sublayer. |
| 1237 | if (wSublayer > sublayer) { |
| 1238 | if (addToToken) { |
| 1239 | token.windows.add(i, win); |
| 1240 | } |
| 1241 | placeWindowBefore(w, win); |
| 1242 | break; |
| 1243 | } |
| 1244 | } |
| 1245 | } |
| 1246 | if (i >= NA) { |
| 1247 | if (addToToken) { |
| 1248 | token.windows.add(win); |
| 1249 | } |
| 1250 | if (sublayer < 0) { |
| 1251 | placeWindowBefore(attached, win); |
| 1252 | } else { |
| 1253 | placeWindowAfter(largestSublayer >= 0 |
| 1254 | ? windowWithLargestSublayer |
| 1255 | : attached, |
| 1256 | win); |
| 1257 | } |
| 1258 | } |
| 1259 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1260 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1261 | if (win.mAppToken != null && addToToken) { |
| 1262 | win.mAppToken.allAppWindows.add(win); |
| 1263 | } |
| 1264 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1265 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1266 | static boolean canBeImeTarget(WindowState w) { |
| 1267 | final int fl = w.mAttrs.flags |
| 1268 | & (FLAG_NOT_FOCUSABLE|FLAG_ALT_FOCUSABLE_IM); |
| 1269 | if (fl == 0 || fl == (FLAG_NOT_FOCUSABLE|FLAG_ALT_FOCUSABLE_IM)) { |
| 1270 | return w.isVisibleOrAdding(); |
| 1271 | } |
| 1272 | return false; |
| 1273 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1274 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1275 | int findDesiredInputMethodWindowIndexLocked(boolean willMove) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1276 | final ArrayList<WindowState> localmWindows = mWindows; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1277 | final int N = localmWindows.size(); |
| 1278 | WindowState w = null; |
| 1279 | int i = N; |
| 1280 | while (i > 0) { |
| 1281 | i--; |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1282 | w = localmWindows.get(i); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1283 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1284 | //Slog.i(TAG, "Checking window @" + i + " " + w + " fl=0x" |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1285 | // + Integer.toHexString(w.mAttrs.flags)); |
| 1286 | if (canBeImeTarget(w)) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1287 | //Slog.i(TAG, "Putting input method here!"); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1288 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1289 | // Yet more tricksyness! If this window is a "starting" |
| 1290 | // window, we do actually want to be on top of it, but |
| 1291 | // it is not -really- where input will go. So if the caller |
| 1292 | // is not actually looking to move the IME, look down below |
| 1293 | // for a real window to target... |
| 1294 | if (!willMove |
| 1295 | && w.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING |
| 1296 | && i > 0) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1297 | WindowState wb = localmWindows.get(i-1); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1298 | if (wb.mAppToken == w.mAppToken && canBeImeTarget(wb)) { |
| 1299 | i--; |
| 1300 | w = wb; |
| 1301 | } |
| 1302 | } |
| 1303 | break; |
| 1304 | } |
| 1305 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1306 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1307 | mUpcomingInputMethodTarget = w; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1308 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1309 | 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] | 1310 | + w + " willMove=" + willMove); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1311 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1312 | if (willMove && w != null) { |
| 1313 | final WindowState curTarget = mInputMethodTarget; |
| 1314 | if (curTarget != null && curTarget.mAppToken != null) { |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1315 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1316 | // Now some fun for dealing with window animations that |
| 1317 | // modify the Z order. We need to look at all windows below |
| 1318 | // the current target that are in this app, finding the highest |
| 1319 | // visible one in layering. |
| 1320 | AppWindowToken token = curTarget.mAppToken; |
| 1321 | WindowState highestTarget = null; |
| 1322 | int highestPos = 0; |
| 1323 | if (token.animating || token.animation != null) { |
| 1324 | int pos = 0; |
| 1325 | pos = localmWindows.indexOf(curTarget); |
| 1326 | while (pos >= 0) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1327 | WindowState win = localmWindows.get(pos); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1328 | if (win.mAppToken != token) { |
| 1329 | break; |
| 1330 | } |
| 1331 | if (!win.mRemoved) { |
| 1332 | if (highestTarget == null || win.mAnimLayer > |
| 1333 | highestTarget.mAnimLayer) { |
| 1334 | highestTarget = win; |
| 1335 | highestPos = pos; |
| 1336 | } |
| 1337 | } |
| 1338 | pos--; |
| 1339 | } |
| 1340 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1341 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1342 | if (highestTarget != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1343 | if (DEBUG_INPUT_METHOD) Slog.v(TAG, "mNextAppTransition=" |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1344 | + mNextAppTransition + " " + highestTarget |
| 1345 | + " animating=" + highestTarget.isAnimating() |
| 1346 | + " layer=" + highestTarget.mAnimLayer |
| 1347 | + " new layer=" + w.mAnimLayer); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1348 | |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 1349 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1350 | // If we are currently setting up for an animation, |
| 1351 | // hold everything until we can find out what will happen. |
| 1352 | mInputMethodTargetWaitingAnim = true; |
| 1353 | mInputMethodTarget = highestTarget; |
| 1354 | return highestPos + 1; |
| 1355 | } else if (highestTarget.isAnimating() && |
| 1356 | highestTarget.mAnimLayer > w.mAnimLayer) { |
| 1357 | // If the window we are currently targeting is involved |
| 1358 | // with an animation, and it is on top of the next target |
| 1359 | // we will be over, then hold off on moving until |
| 1360 | // that is done. |
| 1361 | mInputMethodTarget = highestTarget; |
| 1362 | return highestPos + 1; |
| 1363 | } |
| 1364 | } |
| 1365 | } |
| 1366 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1367 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1368 | //Slog.i(TAG, "Placing input method @" + (i+1)); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1369 | if (w != null) { |
| 1370 | if (willMove) { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 1371 | if (DEBUG_INPUT_METHOD) { |
| 1372 | RuntimeException e = null; |
| 1373 | if (!HIDE_STACK_CRAWLS) { |
| 1374 | e = new RuntimeException(); |
| 1375 | e.fillInStackTrace(); |
| 1376 | } |
| 1377 | Slog.w(TAG, "Moving IM target from " |
| 1378 | + mInputMethodTarget + " to " + w, e); |
| 1379 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1380 | mInputMethodTarget = w; |
| 1381 | if (w.mAppToken != null) { |
| 1382 | setInputMethodAnimLayerAdjustment(w.mAppToken.animLayerAdjustment); |
| 1383 | } else { |
| 1384 | setInputMethodAnimLayerAdjustment(0); |
| 1385 | } |
| 1386 | } |
| 1387 | return i+1; |
| 1388 | } |
| 1389 | if (willMove) { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 1390 | if (DEBUG_INPUT_METHOD) { |
| 1391 | RuntimeException e = null; |
| 1392 | if (!HIDE_STACK_CRAWLS) { |
| 1393 | e = new RuntimeException(); |
| 1394 | e.fillInStackTrace(); |
| 1395 | } |
| 1396 | Slog.w(TAG, "Moving IM target from " |
| 1397 | + mInputMethodTarget + " to null", e); |
| 1398 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1399 | mInputMethodTarget = null; |
| 1400 | setInputMethodAnimLayerAdjustment(0); |
| 1401 | } |
| 1402 | return -1; |
| 1403 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1404 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1405 | void addInputMethodWindowToListLocked(WindowState win) { |
| 1406 | int pos = findDesiredInputMethodWindowIndexLocked(true); |
| 1407 | if (pos >= 0) { |
| 1408 | win.mTargetAppToken = mInputMethodTarget.mAppToken; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1409 | if (DEBUG_WINDOW_MOVEMENT) Slog.v( |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 1410 | TAG, "Adding input method window " + win + " at " + pos); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1411 | mWindows.add(pos, win); |
| Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 1412 | mWindowsChanged = true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1413 | moveInputMethodDialogsLocked(pos+1); |
| 1414 | return; |
| 1415 | } |
| 1416 | win.mTargetAppToken = null; |
| 1417 | addWindowToListInOrderLocked(win, true); |
| 1418 | moveInputMethodDialogsLocked(pos); |
| 1419 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1420 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1421 | void setInputMethodAnimLayerAdjustment(int adj) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1422 | 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] | 1423 | mInputMethodAnimLayerAdjustment = adj; |
| 1424 | WindowState imw = mInputMethodWindow; |
| 1425 | if (imw != null) { |
| 1426 | imw.mAnimLayer = imw.mLayer + adj; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1427 | if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + imw |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1428 | + " anim layer: " + imw.mAnimLayer); |
| 1429 | int wi = imw.mChildWindows.size(); |
| 1430 | while (wi > 0) { |
| 1431 | wi--; |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1432 | WindowState cw = imw.mChildWindows.get(wi); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1433 | cw.mAnimLayer = cw.mLayer + adj; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1434 | if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + cw |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1435 | + " anim layer: " + cw.mAnimLayer); |
| 1436 | } |
| 1437 | } |
| 1438 | int di = mInputMethodDialogs.size(); |
| 1439 | while (di > 0) { |
| 1440 | di --; |
| 1441 | imw = mInputMethodDialogs.get(di); |
| 1442 | imw.mAnimLayer = imw.mLayer + adj; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1443 | if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + imw |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1444 | + " anim layer: " + imw.mAnimLayer); |
| 1445 | } |
| 1446 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1447 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1448 | private int tmpRemoveWindowLocked(int interestingPos, WindowState win) { |
| 1449 | int wpos = mWindows.indexOf(win); |
| 1450 | if (wpos >= 0) { |
| 1451 | if (wpos < interestingPos) interestingPos--; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1452 | 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] | 1453 | mWindows.remove(wpos); |
| Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 1454 | mWindowsChanged = true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1455 | int NC = win.mChildWindows.size(); |
| 1456 | while (NC > 0) { |
| 1457 | NC--; |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1458 | WindowState cw = win.mChildWindows.get(NC); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1459 | int cpos = mWindows.indexOf(cw); |
| 1460 | if (cpos >= 0) { |
| 1461 | if (cpos < interestingPos) interestingPos--; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1462 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Temp removing child at " |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 1463 | + cpos + ": " + cw); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1464 | mWindows.remove(cpos); |
| 1465 | } |
| 1466 | } |
| 1467 | } |
| 1468 | return interestingPos; |
| 1469 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1470 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1471 | private void reAddWindowToListInOrderLocked(WindowState win) { |
| 1472 | addWindowToListInOrderLocked(win, false); |
| 1473 | // This is a hack to get all of the child windows added as well |
| 1474 | // at the right position. Child windows should be rare and |
| 1475 | // this case should be rare, so it shouldn't be that big a deal. |
| 1476 | int wpos = mWindows.indexOf(win); |
| 1477 | if (wpos >= 0) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1478 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "ReAdd removing from " + wpos |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 1479 | + ": " + win); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1480 | mWindows.remove(wpos); |
| Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 1481 | mWindowsChanged = true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1482 | reAddWindowLocked(wpos, win); |
| 1483 | } |
| 1484 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1485 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1486 | void logWindowList(String prefix) { |
| 1487 | int N = mWindows.size(); |
| 1488 | while (N > 0) { |
| 1489 | N--; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1490 | Slog.v(TAG, prefix + "#" + N + ": " + mWindows.get(N)); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1491 | } |
| 1492 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1493 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1494 | void moveInputMethodDialogsLocked(int pos) { |
| 1495 | ArrayList<WindowState> dialogs = mInputMethodDialogs; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1496 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1497 | final int N = dialogs.size(); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1498 | 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] | 1499 | for (int i=0; i<N; i++) { |
| 1500 | pos = tmpRemoveWindowLocked(pos, dialogs.get(i)); |
| 1501 | } |
| 1502 | if (DEBUG_INPUT_METHOD) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1503 | Slog.v(TAG, "Window list w/pos=" + pos); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1504 | logWindowList(" "); |
| 1505 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1506 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1507 | if (pos >= 0) { |
| 1508 | final AppWindowToken targetAppToken = mInputMethodTarget.mAppToken; |
| 1509 | if (pos < mWindows.size()) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1510 | WindowState wp = mWindows.get(pos); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1511 | if (wp == mInputMethodWindow) { |
| 1512 | pos++; |
| 1513 | } |
| 1514 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1515 | 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] | 1516 | for (int i=0; i<N; i++) { |
| 1517 | WindowState win = dialogs.get(i); |
| 1518 | win.mTargetAppToken = targetAppToken; |
| 1519 | pos = reAddWindowLocked(pos, win); |
| 1520 | } |
| 1521 | if (DEBUG_INPUT_METHOD) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1522 | Slog.v(TAG, "Final window list:"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1523 | logWindowList(" "); |
| 1524 | } |
| 1525 | return; |
| 1526 | } |
| 1527 | for (int i=0; i<N; i++) { |
| 1528 | WindowState win = dialogs.get(i); |
| 1529 | win.mTargetAppToken = null; |
| 1530 | reAddWindowToListInOrderLocked(win); |
| 1531 | if (DEBUG_INPUT_METHOD) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1532 | Slog.v(TAG, "No IM target, final list:"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1533 | logWindowList(" "); |
| 1534 | } |
| 1535 | } |
| 1536 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1537 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1538 | boolean moveInputMethodWindowsIfNeededLocked(boolean needAssignLayers) { |
| 1539 | final WindowState imWin = mInputMethodWindow; |
| 1540 | final int DN = mInputMethodDialogs.size(); |
| 1541 | if (imWin == null && DN == 0) { |
| 1542 | return false; |
| 1543 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1544 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1545 | int imPos = findDesiredInputMethodWindowIndexLocked(true); |
| 1546 | if (imPos >= 0) { |
| 1547 | // In this case, the input method windows are to be placed |
| 1548 | // immediately above the window they are targeting. |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1549 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1550 | // First check to see if the input method windows are already |
| 1551 | // located here, and contiguous. |
| 1552 | final int N = mWindows.size(); |
| 1553 | WindowState firstImWin = imPos < N |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1554 | ? mWindows.get(imPos) : null; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1555 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1556 | // Figure out the actual input method window that should be |
| 1557 | // at the bottom of their stack. |
| 1558 | WindowState baseImWin = imWin != null |
| 1559 | ? imWin : mInputMethodDialogs.get(0); |
| 1560 | if (baseImWin.mChildWindows.size() > 0) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1561 | WindowState cw = baseImWin.mChildWindows.get(0); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1562 | if (cw.mSubLayer < 0) baseImWin = cw; |
| 1563 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1564 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1565 | if (firstImWin == baseImWin) { |
| 1566 | // The windows haven't moved... but are they still contiguous? |
| 1567 | // First find the top IM window. |
| 1568 | int pos = imPos+1; |
| 1569 | while (pos < N) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1570 | if (!(mWindows.get(pos)).mIsImWindow) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1571 | break; |
| 1572 | } |
| 1573 | pos++; |
| 1574 | } |
| 1575 | pos++; |
| 1576 | // Now there should be no more input method windows above. |
| 1577 | while (pos < N) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1578 | if ((mWindows.get(pos)).mIsImWindow) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1579 | break; |
| 1580 | } |
| 1581 | pos++; |
| 1582 | } |
| 1583 | if (pos >= N) { |
| 1584 | // All is good! |
| 1585 | return false; |
| 1586 | } |
| 1587 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1588 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1589 | if (imWin != null) { |
| 1590 | if (DEBUG_INPUT_METHOD) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1591 | Slog.v(TAG, "Moving IM from " + imPos); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1592 | logWindowList(" "); |
| 1593 | } |
| 1594 | imPos = tmpRemoveWindowLocked(imPos, imWin); |
| 1595 | if (DEBUG_INPUT_METHOD) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1596 | 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] | 1597 | logWindowList(" "); |
| 1598 | } |
| 1599 | imWin.mTargetAppToken = mInputMethodTarget.mAppToken; |
| 1600 | reAddWindowLocked(imPos, imWin); |
| 1601 | if (DEBUG_INPUT_METHOD) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1602 | Slog.v(TAG, "List after moving IM to " + imPos + ":"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1603 | logWindowList(" "); |
| 1604 | } |
| 1605 | if (DN > 0) moveInputMethodDialogsLocked(imPos+1); |
| 1606 | } else { |
| 1607 | moveInputMethodDialogsLocked(imPos); |
| 1608 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1609 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1610 | } else { |
| 1611 | // In this case, the input method windows go in a fixed layer, |
| 1612 | // because they aren't currently associated with a focus window. |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1613 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1614 | if (imWin != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1615 | 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] | 1616 | tmpRemoveWindowLocked(0, imWin); |
| 1617 | imWin.mTargetAppToken = null; |
| 1618 | reAddWindowToListInOrderLocked(imWin); |
| 1619 | if (DEBUG_INPUT_METHOD) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1620 | Slog.v(TAG, "List with no IM target:"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1621 | logWindowList(" "); |
| 1622 | } |
| 1623 | if (DN > 0) moveInputMethodDialogsLocked(-1);; |
| 1624 | } else { |
| 1625 | moveInputMethodDialogsLocked(-1);; |
| 1626 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1627 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1628 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1629 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1630 | if (needAssignLayers) { |
| 1631 | assignLayersLocked(); |
| 1632 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1633 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1634 | return true; |
| 1635 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1636 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1637 | void adjustInputMethodDialogsLocked() { |
| 1638 | moveInputMethodDialogsLocked(findDesiredInputMethodWindowIndexLocked(true)); |
| 1639 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1640 | |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 1641 | final boolean isWallpaperVisible(WindowState wallpaperTarget) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1642 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper vis: target obscured=" |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 1643 | + (wallpaperTarget != null ? Boolean.toString(wallpaperTarget.mObscured) : "??") |
| 1644 | + " anim=" + ((wallpaperTarget != null && wallpaperTarget.mAppToken != null) |
| 1645 | ? wallpaperTarget.mAppToken.animation : null) |
| 1646 | + " upper=" + mUpperWallpaperTarget |
| 1647 | + " lower=" + mLowerWallpaperTarget); |
| 1648 | return (wallpaperTarget != null |
| 1649 | && (!wallpaperTarget.mObscured || (wallpaperTarget.mAppToken != null |
| 1650 | && wallpaperTarget.mAppToken.animation != null))) |
| 1651 | || mUpperWallpaperTarget != null |
| 1652 | || mLowerWallpaperTarget != null; |
| 1653 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1654 | |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 1655 | static final int ADJUST_WALLPAPER_LAYERS_CHANGED = 1<<1; |
| 1656 | static final int ADJUST_WALLPAPER_VISIBILITY_CHANGED = 1<<2; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1657 | |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 1658 | int adjustWallpaperWindowsLocked() { |
| 1659 | int changed = 0; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1660 | |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1661 | final int dw = mDisplay.getWidth(); |
| 1662 | final int dh = mDisplay.getHeight(); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1663 | |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1664 | // First find top-most window that has asked to be on top of the |
| 1665 | // wallpaper; all wallpapers go behind it. |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1666 | final ArrayList<WindowState> localmWindows = mWindows; |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1667 | int N = localmWindows.size(); |
| 1668 | WindowState w = null; |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1669 | WindowState foundW = null; |
| 1670 | int foundI = 0; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1671 | WindowState topCurW = null; |
| 1672 | int topCurI = 0; |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1673 | int i = N; |
| 1674 | while (i > 0) { |
| 1675 | i--; |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1676 | w = localmWindows.get(i); |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1677 | if ((w.mAttrs.type == WindowManager.LayoutParams.TYPE_WALLPAPER)) { |
| 1678 | if (topCurW == null) { |
| 1679 | topCurW = w; |
| 1680 | topCurI = i; |
| 1681 | } |
| 1682 | continue; |
| 1683 | } |
| 1684 | topCurW = null; |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1685 | if (w.mAppToken != null) { |
| 1686 | // If this window's app token is hidden and not animating, |
| 1687 | // it is of no interest to us. |
| 1688 | if (w.mAppToken.hidden && w.mAppToken.animation == null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1689 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1690 | "Skipping hidden or animating token: " + w); |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1691 | topCurW = null; |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1692 | continue; |
| 1693 | } |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1694 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1695 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Win " + w + ": readyfordisplay=" |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1696 | + w.isReadyForDisplay() + " drawpending=" + w.mDrawPending |
| 1697 | + " commitdrawpending=" + w.mCommitDrawPending); |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1698 | if ((w.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0 && w.isReadyForDisplay() |
| Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 1699 | && (mWallpaperTarget == w |
| 1700 | || (!w.mDrawPending && !w.mCommitDrawPending))) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1701 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1702 | "Found wallpaper activity: #" + i + "=" + w); |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1703 | foundW = w; |
| 1704 | foundI = i; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1705 | if (w == mWallpaperTarget && ((w.mAppToken != null |
| 1706 | && w.mAppToken.animation != null) |
| 1707 | || w.mAnimation != null)) { |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1708 | // The current wallpaper target is animating, so we'll |
| 1709 | // look behind it for another possible target and figure |
| 1710 | // out what is going on below. |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1711 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Win " + w |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1712 | + ": token animating, looking behind."); |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1713 | continue; |
| 1714 | } |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1715 | break; |
| 1716 | } |
| 1717 | } |
| 1718 | |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 1719 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1720 | // If we are currently waiting for an app transition, and either |
| 1721 | // the current target or the next target are involved with it, |
| 1722 | // then hold off on doing anything with the wallpaper. |
| 1723 | // Note that we are checking here for just whether the target |
| 1724 | // is part of an app token... which is potentially overly aggressive |
| 1725 | // (the app token may not be involved in the transition), but good |
| 1726 | // enough (we'll just wait until whatever transition is pending |
| 1727 | // executes). |
| 1728 | if (mWallpaperTarget != null && mWallpaperTarget.mAppToken != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1729 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1730 | "Wallpaper not changing: waiting for app anim in current target"); |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 1731 | return 0; |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1732 | } |
| 1733 | if (foundW != null && foundW.mAppToken != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1734 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1735 | "Wallpaper not changing: waiting for app anim in found target"); |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 1736 | return 0; |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1737 | } |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1738 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1739 | |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1740 | if (mWallpaperTarget != foundW) { |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1741 | if (DEBUG_WALLPAPER) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1742 | Slog.v(TAG, "New wallpaper target: " + foundW |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1743 | + " oldTarget: " + mWallpaperTarget); |
| 1744 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1745 | |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1746 | mLowerWallpaperTarget = null; |
| 1747 | mUpperWallpaperTarget = null; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1748 | |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1749 | WindowState oldW = mWallpaperTarget; |
| 1750 | mWallpaperTarget = foundW; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1751 | |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1752 | // Now what is happening... if the current and new targets are |
| 1753 | // animating, then we are in our super special mode! |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1754 | if (foundW != null && oldW != null) { |
| 1755 | boolean oldAnim = oldW.mAnimation != null |
| 1756 | || (oldW.mAppToken != null && oldW.mAppToken.animation != null); |
| 1757 | boolean foundAnim = foundW.mAnimation != null |
| 1758 | || (foundW.mAppToken != null && foundW.mAppToken.animation != null); |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1759 | if (DEBUG_WALLPAPER) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1760 | Slog.v(TAG, "New animation: " + foundAnim |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1761 | + " old animation: " + oldAnim); |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1762 | } |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1763 | if (foundAnim && oldAnim) { |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1764 | int oldI = localmWindows.indexOf(oldW); |
| 1765 | if (DEBUG_WALLPAPER) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1766 | Slog.v(TAG, "New i: " + foundI + " old i: " + oldI); |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1767 | } |
| 1768 | if (oldI >= 0) { |
| 1769 | if (DEBUG_WALLPAPER) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1770 | Slog.v(TAG, "Animating wallpapers: old#" + oldI |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1771 | + "=" + oldW + "; new#" + foundI |
| 1772 | + "=" + foundW); |
| 1773 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1774 | |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1775 | // Set the new target correctly. |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1776 | if (foundW.mAppToken != null && foundW.mAppToken.hiddenRequested) { |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1777 | if (DEBUG_WALLPAPER) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1778 | Slog.v(TAG, "Old wallpaper still the target."); |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1779 | } |
| 1780 | mWallpaperTarget = oldW; |
| 1781 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1782 | |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1783 | // Now set the upper and lower wallpaper targets |
| 1784 | // correctly, and make sure that we are positioning |
| 1785 | // the wallpaper below the lower. |
| 1786 | if (foundI > oldI) { |
| 1787 | // The new target is on top of the old one. |
| 1788 | if (DEBUG_WALLPAPER) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1789 | Slog.v(TAG, "Found target above old target."); |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1790 | } |
| 1791 | mUpperWallpaperTarget = foundW; |
| 1792 | mLowerWallpaperTarget = oldW; |
| 1793 | foundW = oldW; |
| 1794 | foundI = oldI; |
| 1795 | } else { |
| 1796 | // The new target is below the old one. |
| 1797 | if (DEBUG_WALLPAPER) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1798 | Slog.v(TAG, "Found target below old target."); |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1799 | } |
| 1800 | mUpperWallpaperTarget = oldW; |
| 1801 | mLowerWallpaperTarget = foundW; |
| 1802 | } |
| 1803 | } |
| 1804 | } |
| 1805 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1806 | |
| Dianne Hackborn | 6b1cb35 | 2009-09-28 18:27:26 -0700 | [diff] [blame] | 1807 | } else if (mLowerWallpaperTarget != null) { |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1808 | // Is it time to stop animating? |
| Dianne Hackborn | 6b1cb35 | 2009-09-28 18:27:26 -0700 | [diff] [blame] | 1809 | boolean lowerAnimating = mLowerWallpaperTarget.mAnimation != null |
| 1810 | || (mLowerWallpaperTarget.mAppToken != null |
| 1811 | && mLowerWallpaperTarget.mAppToken.animation != null); |
| 1812 | boolean upperAnimating = mUpperWallpaperTarget.mAnimation != null |
| 1813 | || (mUpperWallpaperTarget.mAppToken != null |
| 1814 | && mUpperWallpaperTarget.mAppToken.animation != null); |
| 1815 | if (!lowerAnimating || !upperAnimating) { |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1816 | if (DEBUG_WALLPAPER) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1817 | Slog.v(TAG, "No longer animating wallpaper targets!"); |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1818 | } |
| 1819 | mLowerWallpaperTarget = null; |
| 1820 | mUpperWallpaperTarget = null; |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1821 | } |
| 1822 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1823 | |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1824 | boolean visible = foundW != null; |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 1825 | if (visible) { |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1826 | // The window is visible to the compositor... but is it visible |
| 1827 | // to the user? That is what the wallpaper cares about. |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 1828 | visible = isWallpaperVisible(foundW); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1829 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper visibility: " + visible); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1830 | |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1831 | // If the wallpaper target is animating, we may need to copy |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1832 | // its layer adjustment. Only do this if we are not transfering |
| 1833 | // between two wallpaper targets. |
| 1834 | mWallpaperAnimLayerAdjustment = |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1835 | (mLowerWallpaperTarget == null && foundW.mAppToken != null) |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1836 | ? foundW.mAppToken.animLayerAdjustment : 0; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1837 | |
| Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 1838 | final int maxLayer = mPolicy.getMaxWallpaperLayer() |
| 1839 | * TYPE_LAYER_MULTIPLIER |
| 1840 | + TYPE_LAYER_OFFSET; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1841 | |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1842 | // Now w is the window we are supposed to be behind... but we |
| 1843 | // 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] | 1844 | // AND any starting window associated with it, AND below the |
| 1845 | // maximum layer the policy allows for wallpapers. |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1846 | while (foundI > 0) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1847 | WindowState wb = localmWindows.get(foundI-1); |
| Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 1848 | if (wb.mBaseLayer < maxLayer && |
| 1849 | wb.mAttachedWindow != foundW && |
| Pal Szasz | 73dc259 | 2010-09-03 11:46:26 +0200 | [diff] [blame] | 1850 | wb.mAttachedWindow != foundW.mAttachedWindow && |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1851 | (wb.mAttrs.type != TYPE_APPLICATION_STARTING || |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1852 | wb.mToken != foundW.mToken)) { |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1853 | // This window is not related to the previous one in any |
| 1854 | // interesting way, so stop here. |
| 1855 | break; |
| 1856 | } |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1857 | foundW = wb; |
| 1858 | foundI--; |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1859 | } |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 1860 | } else { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1861 | if (DEBUG_WALLPAPER) Slog.v(TAG, "No wallpaper target"); |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1862 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1863 | |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1864 | if (foundW == null && topCurW != null) { |
| 1865 | // There is no wallpaper target, so it goes at the bottom. |
| 1866 | // We will assume it is the same place as last time, if known. |
| 1867 | foundW = topCurW; |
| 1868 | foundI = topCurI+1; |
| 1869 | } else { |
| 1870 | // Okay i is the position immediately above the wallpaper. Look at |
| 1871 | // what is below it for later. |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1872 | foundW = foundI > 0 ? localmWindows.get(foundI-1) : null; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1873 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1874 | |
| Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 1875 | if (visible) { |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1876 | if (mWallpaperTarget.mWallpaperX >= 0) { |
| 1877 | mLastWallpaperX = mWallpaperTarget.mWallpaperX; |
| Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 1878 | mLastWallpaperXStep = mWallpaperTarget.mWallpaperXStep; |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1879 | } |
| 1880 | if (mWallpaperTarget.mWallpaperY >= 0) { |
| 1881 | mLastWallpaperY = mWallpaperTarget.mWallpaperY; |
| Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 1882 | mLastWallpaperYStep = mWallpaperTarget.mWallpaperYStep; |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1883 | } |
| Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 1884 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1885 | |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1886 | // Start stepping backwards from here, ensuring that our wallpaper windows |
| 1887 | // are correctly placed. |
| 1888 | int curTokenIndex = mWallpaperTokens.size(); |
| 1889 | while (curTokenIndex > 0) { |
| 1890 | curTokenIndex--; |
| 1891 | WindowToken token = mWallpaperTokens.get(curTokenIndex); |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 1892 | if (token.hidden == visible) { |
| 1893 | changed |= ADJUST_WALLPAPER_VISIBILITY_CHANGED; |
| 1894 | token.hidden = !visible; |
| 1895 | // Need to do a layout to ensure the wallpaper now has the |
| 1896 | // correct size. |
| 1897 | mLayoutNeeded = true; |
| 1898 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1899 | |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1900 | int curWallpaperIndex = token.windows.size(); |
| 1901 | while (curWallpaperIndex > 0) { |
| 1902 | curWallpaperIndex--; |
| 1903 | WindowState wallpaper = token.windows.get(curWallpaperIndex); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1904 | |
| Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 1905 | if (visible) { |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1906 | updateWallpaperOffsetLocked(wallpaper, dw, dh, false); |
| Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 1907 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1908 | |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 1909 | // First, make sure the client has the current visibility |
| 1910 | // state. |
| 1911 | if (wallpaper.mWallpaperVisible != visible) { |
| 1912 | wallpaper.mWallpaperVisible = visible; |
| 1913 | try { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1914 | if (DEBUG_VISIBILITY || DEBUG_WALLPAPER) Slog.v(TAG, |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 1915 | "Setting visibility of wallpaper " + wallpaper |
| 1916 | + ": " + visible); |
| 1917 | wallpaper.mClient.dispatchAppVisibility(visible); |
| 1918 | } catch (RemoteException e) { |
| 1919 | } |
| 1920 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1921 | |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 1922 | wallpaper.mAnimLayer = wallpaper.mLayer + mWallpaperAnimLayerAdjustment; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1923 | if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper win " |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1924 | + wallpaper + " anim layer: " + wallpaper.mAnimLayer); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1925 | |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1926 | // First, if this window is at the current index, then all |
| 1927 | // is well. |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1928 | if (wallpaper == foundW) { |
| 1929 | foundI--; |
| 1930 | foundW = foundI > 0 |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1931 | ? localmWindows.get(foundI-1) : null; |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1932 | continue; |
| 1933 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1934 | |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1935 | // The window didn't match... the current wallpaper window, |
| 1936 | // wherever it is, is in the wrong place, so make sure it is |
| 1937 | // not in the list. |
| 1938 | int oldIndex = localmWindows.indexOf(wallpaper); |
| 1939 | if (oldIndex >= 0) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1940 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Wallpaper removing at " |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 1941 | + oldIndex + ": " + wallpaper); |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1942 | localmWindows.remove(oldIndex); |
| Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 1943 | mWindowsChanged = true; |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1944 | if (oldIndex < foundI) { |
| 1945 | foundI--; |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1946 | } |
| 1947 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1948 | |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1949 | // Now stick it in. |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1950 | if (DEBUG_WALLPAPER || DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 1951 | "Moving wallpaper " + wallpaper |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1952 | + " from " + oldIndex + " to " + foundI); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1953 | |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1954 | localmWindows.add(foundI, wallpaper); |
| Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 1955 | mWindowsChanged = true; |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 1956 | changed |= ADJUST_WALLPAPER_LAYERS_CHANGED; |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1957 | } |
| 1958 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1959 | |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1960 | return changed; |
| 1961 | } |
| 1962 | |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 1963 | void setWallpaperAnimLayerAdjustmentLocked(int adj) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1964 | if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG, |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1965 | "Setting wallpaper layer adj to " + adj); |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 1966 | mWallpaperAnimLayerAdjustment = adj; |
| 1967 | int curTokenIndex = mWallpaperTokens.size(); |
| 1968 | while (curTokenIndex > 0) { |
| 1969 | curTokenIndex--; |
| 1970 | WindowToken token = mWallpaperTokens.get(curTokenIndex); |
| 1971 | int curWallpaperIndex = token.windows.size(); |
| 1972 | while (curWallpaperIndex > 0) { |
| 1973 | curWallpaperIndex--; |
| 1974 | WindowState wallpaper = token.windows.get(curWallpaperIndex); |
| 1975 | wallpaper.mAnimLayer = wallpaper.mLayer + adj; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1976 | if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper win " |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1977 | + wallpaper + " anim layer: " + wallpaper.mAnimLayer); |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 1978 | } |
| 1979 | } |
| 1980 | } |
| 1981 | |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1982 | boolean updateWallpaperOffsetLocked(WindowState wallpaperWin, int dw, int dh, |
| 1983 | boolean sync) { |
| Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 1984 | boolean changed = false; |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1985 | boolean rawChanged = false; |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1986 | float wpx = mLastWallpaperX >= 0 ? mLastWallpaperX : 0.5f; |
| Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 1987 | float wpxs = mLastWallpaperXStep >= 0 ? mLastWallpaperXStep : -1.0f; |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1988 | int availw = wallpaperWin.mFrame.right-wallpaperWin.mFrame.left-dw; |
| 1989 | int offset = availw > 0 ? -(int)(availw*wpx+.5f) : 0; |
| 1990 | changed = wallpaperWin.mXOffset != offset; |
| 1991 | if (changed) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1992 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Update wallpaper " |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1993 | + wallpaperWin + " x: " + offset); |
| 1994 | wallpaperWin.mXOffset = offset; |
| 1995 | } |
| Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 1996 | if (wallpaperWin.mWallpaperX != wpx || wallpaperWin.mWallpaperXStep != wpxs) { |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1997 | wallpaperWin.mWallpaperX = wpx; |
| Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 1998 | wallpaperWin.mWallpaperXStep = wpxs; |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1999 | rawChanged = true; |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 2000 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2001 | |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 2002 | float wpy = mLastWallpaperY >= 0 ? mLastWallpaperY : 0.5f; |
| Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 2003 | float wpys = mLastWallpaperYStep >= 0 ? mLastWallpaperYStep : -1.0f; |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 2004 | int availh = wallpaperWin.mFrame.bottom-wallpaperWin.mFrame.top-dh; |
| 2005 | offset = availh > 0 ? -(int)(availh*wpy+.5f) : 0; |
| 2006 | if (wallpaperWin.mYOffset != offset) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2007 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Update wallpaper " |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 2008 | + wallpaperWin + " y: " + offset); |
| 2009 | changed = true; |
| 2010 | wallpaperWin.mYOffset = offset; |
| 2011 | } |
| Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 2012 | if (wallpaperWin.mWallpaperY != wpy || wallpaperWin.mWallpaperYStep != wpys) { |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 2013 | wallpaperWin.mWallpaperY = wpy; |
| Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 2014 | wallpaperWin.mWallpaperYStep = wpys; |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 2015 | rawChanged = true; |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 2016 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2017 | |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 2018 | if (rawChanged) { |
| Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 2019 | try { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2020 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Report new wp offset " |
| Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 2021 | + wallpaperWin + " x=" + wallpaperWin.mWallpaperX |
| 2022 | + " y=" + wallpaperWin.mWallpaperY); |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 2023 | if (sync) { |
| Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 2024 | mWaitingOnWallpaper = wallpaperWin; |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 2025 | } |
| Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 2026 | wallpaperWin.mClient.dispatchWallpaperOffsets( |
| Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 2027 | wallpaperWin.mWallpaperX, wallpaperWin.mWallpaperY, |
| 2028 | wallpaperWin.mWallpaperXStep, wallpaperWin.mWallpaperYStep, sync); |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 2029 | if (sync) { |
| Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 2030 | if (mWaitingOnWallpaper != null) { |
| 2031 | long start = SystemClock.uptimeMillis(); |
| 2032 | if ((mLastWallpaperTimeoutTime+WALLPAPER_TIMEOUT_RECOVERY) |
| 2033 | < start) { |
| 2034 | try { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2035 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
| Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 2036 | "Waiting for offset complete..."); |
| 2037 | mWindowMap.wait(WALLPAPER_TIMEOUT); |
| 2038 | } catch (InterruptedException e) { |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 2039 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2040 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Offset complete!"); |
| Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 2041 | if ((start+WALLPAPER_TIMEOUT) |
| 2042 | < SystemClock.uptimeMillis()) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2043 | Slog.i(TAG, "Timeout waiting for wallpaper to offset: " |
| Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 2044 | + wallpaperWin); |
| 2045 | mLastWallpaperTimeoutTime = start; |
| 2046 | } |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 2047 | } |
| Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 2048 | mWaitingOnWallpaper = null; |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 2049 | } |
| 2050 | } |
| Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 2051 | } catch (RemoteException e) { |
| 2052 | } |
| 2053 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2054 | |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 2055 | return changed; |
| 2056 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2057 | |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 2058 | void wallpaperOffsetsComplete(IBinder window) { |
| Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 2059 | synchronized (mWindowMap) { |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 2060 | if (mWaitingOnWallpaper != null && |
| 2061 | mWaitingOnWallpaper.mClient.asBinder() == window) { |
| 2062 | mWaitingOnWallpaper = null; |
| Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 2063 | mWindowMap.notifyAll(); |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 2064 | } |
| 2065 | } |
| 2066 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2067 | |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 2068 | boolean updateWallpaperOffsetLocked(WindowState changingTarget, boolean sync) { |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 2069 | final int dw = mDisplay.getWidth(); |
| 2070 | final int dh = mDisplay.getHeight(); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2071 | |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 2072 | boolean changed = false; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2073 | |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 2074 | WindowState target = mWallpaperTarget; |
| 2075 | if (target != null) { |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 2076 | if (target.mWallpaperX >= 0) { |
| 2077 | mLastWallpaperX = target.mWallpaperX; |
| 2078 | } else if (changingTarget.mWallpaperX >= 0) { |
| 2079 | mLastWallpaperX = changingTarget.mWallpaperX; |
| 2080 | } |
| 2081 | if (target.mWallpaperY >= 0) { |
| 2082 | mLastWallpaperY = target.mWallpaperY; |
| 2083 | } else if (changingTarget.mWallpaperY >= 0) { |
| 2084 | mLastWallpaperY = changingTarget.mWallpaperY; |
| 2085 | } |
| 2086 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2087 | |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 2088 | int curTokenIndex = mWallpaperTokens.size(); |
| 2089 | while (curTokenIndex > 0) { |
| 2090 | curTokenIndex--; |
| 2091 | WindowToken token = mWallpaperTokens.get(curTokenIndex); |
| 2092 | int curWallpaperIndex = token.windows.size(); |
| 2093 | while (curWallpaperIndex > 0) { |
| 2094 | curWallpaperIndex--; |
| 2095 | WindowState wallpaper = token.windows.get(curWallpaperIndex); |
| 2096 | if (updateWallpaperOffsetLocked(wallpaper, dw, dh, sync)) { |
| 2097 | wallpaper.computeShownFrameLocked(); |
| 2098 | changed = true; |
| 2099 | // We only want to be synchronous with one wallpaper. |
| 2100 | sync = false; |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 2101 | } |
| 2102 | } |
| 2103 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2104 | |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 2105 | return changed; |
| 2106 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2107 | |
| Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 2108 | void updateWallpaperVisibilityLocked() { |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 2109 | final boolean visible = isWallpaperVisible(mWallpaperTarget); |
| Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 2110 | final int dw = mDisplay.getWidth(); |
| 2111 | final int dh = mDisplay.getHeight(); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2112 | |
| Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 2113 | int curTokenIndex = mWallpaperTokens.size(); |
| 2114 | while (curTokenIndex > 0) { |
| 2115 | curTokenIndex--; |
| 2116 | WindowToken token = mWallpaperTokens.get(curTokenIndex); |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 2117 | if (token.hidden == visible) { |
| 2118 | token.hidden = !visible; |
| 2119 | // Need to do a layout to ensure the wallpaper now has the |
| 2120 | // correct size. |
| 2121 | mLayoutNeeded = true; |
| 2122 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2123 | |
| Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 2124 | int curWallpaperIndex = token.windows.size(); |
| 2125 | while (curWallpaperIndex > 0) { |
| 2126 | curWallpaperIndex--; |
| 2127 | WindowState wallpaper = token.windows.get(curWallpaperIndex); |
| 2128 | if (visible) { |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 2129 | updateWallpaperOffsetLocked(wallpaper, dw, dh, false); |
| Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 2130 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2131 | |
| Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 2132 | if (wallpaper.mWallpaperVisible != visible) { |
| 2133 | wallpaper.mWallpaperVisible = visible; |
| 2134 | try { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2135 | if (DEBUG_VISIBILITY || DEBUG_WALLPAPER) Slog.v(TAG, |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 2136 | "Updating visibility of wallpaper " + wallpaper |
| Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 2137 | + ": " + visible); |
| 2138 | wallpaper.mClient.dispatchAppVisibility(visible); |
| 2139 | } catch (RemoteException e) { |
| 2140 | } |
| 2141 | } |
| 2142 | } |
| 2143 | } |
| 2144 | } |
| Dianne Hackborn | 90d2db3 | 2010-02-11 22:19:06 -0800 | [diff] [blame] | 2145 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2146 | public int addWindow(Session session, IWindow client, |
| 2147 | WindowManager.LayoutParams attrs, int viewVisibility, |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 2148 | Rect outContentInsets, InputChannel outInputChannel) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2149 | int res = mPolicy.checkAddPermission(attrs); |
| 2150 | if (res != WindowManagerImpl.ADD_OKAY) { |
| 2151 | return res; |
| 2152 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2153 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2154 | boolean reportNewConfig = false; |
| 2155 | WindowState attachedWindow = null; |
| 2156 | WindowState win = null; |
| Dianne Hackborn | 5132b37 | 2010-07-29 12:51:35 -0700 | [diff] [blame] | 2157 | long origId; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2158 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2159 | synchronized(mWindowMap) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2160 | if (mDisplay == null) { |
| Dianne Hackborn | 5132b37 | 2010-07-29 12:51:35 -0700 | [diff] [blame] | 2161 | throw new IllegalStateException("Display has not been initialialized"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2162 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2163 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2164 | if (mWindowMap.containsKey(client.asBinder())) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2165 | Slog.w(TAG, "Window " + client + " is already added"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2166 | return WindowManagerImpl.ADD_DUPLICATE_ADD; |
| 2167 | } |
| 2168 | |
| 2169 | if (attrs.type >= FIRST_SUB_WINDOW && attrs.type <= LAST_SUB_WINDOW) { |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2170 | attachedWindow = windowForClientLocked(null, attrs.token, false); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2171 | if (attachedWindow == null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2172 | 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] | 2173 | + attrs.token + ". Aborting."); |
| 2174 | return WindowManagerImpl.ADD_BAD_SUBWINDOW_TOKEN; |
| 2175 | } |
| 2176 | if (attachedWindow.mAttrs.type >= FIRST_SUB_WINDOW |
| 2177 | && attachedWindow.mAttrs.type <= LAST_SUB_WINDOW) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2178 | 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] | 2179 | + attrs.token + ". Aborting."); |
| 2180 | return WindowManagerImpl.ADD_BAD_SUBWINDOW_TOKEN; |
| 2181 | } |
| 2182 | } |
| 2183 | |
| 2184 | boolean addToken = false; |
| 2185 | WindowToken token = mTokenMap.get(attrs.token); |
| 2186 | if (token == null) { |
| 2187 | if (attrs.type >= FIRST_APPLICATION_WINDOW |
| 2188 | && attrs.type <= LAST_APPLICATION_WINDOW) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2189 | 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] | 2190 | + attrs.token + ". Aborting."); |
| 2191 | return WindowManagerImpl.ADD_BAD_APP_TOKEN; |
| 2192 | } |
| 2193 | if (attrs.type == TYPE_INPUT_METHOD) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2194 | 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] | 2195 | + attrs.token + ". Aborting."); |
| 2196 | return WindowManagerImpl.ADD_BAD_APP_TOKEN; |
| 2197 | } |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2198 | if (attrs.type == TYPE_WALLPAPER) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2199 | Slog.w(TAG, "Attempted to add wallpaper window with unknown token " |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2200 | + attrs.token + ". Aborting."); |
| 2201 | return WindowManagerImpl.ADD_BAD_APP_TOKEN; |
| 2202 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2203 | token = new WindowToken(attrs.token, -1, false); |
| 2204 | addToken = true; |
| 2205 | } else if (attrs.type >= FIRST_APPLICATION_WINDOW |
| 2206 | && attrs.type <= LAST_APPLICATION_WINDOW) { |
| 2207 | AppWindowToken atoken = token.appWindowToken; |
| 2208 | if (atoken == null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2209 | 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] | 2210 | + token + ". Aborting."); |
| 2211 | return WindowManagerImpl.ADD_NOT_APP_TOKEN; |
| 2212 | } else if (atoken.removed) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2213 | 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] | 2214 | + token + ". Aborting."); |
| 2215 | return WindowManagerImpl.ADD_APP_EXITING; |
| 2216 | } |
| 2217 | if (attrs.type == TYPE_APPLICATION_STARTING && atoken.firstWindowDrawn) { |
| 2218 | // No need for this guy! |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2219 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2220 | TAG, "**** NO NEED TO START: " + attrs.getTitle()); |
| 2221 | return WindowManagerImpl.ADD_STARTING_NOT_NEEDED; |
| 2222 | } |
| 2223 | } else if (attrs.type == TYPE_INPUT_METHOD) { |
| 2224 | if (token.windowType != TYPE_INPUT_METHOD) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2225 | 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] | 2226 | + attrs.token + ". Aborting."); |
| 2227 | return WindowManagerImpl.ADD_BAD_APP_TOKEN; |
| 2228 | } |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2229 | } else if (attrs.type == TYPE_WALLPAPER) { |
| 2230 | if (token.windowType != TYPE_WALLPAPER) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2231 | Slog.w(TAG, "Attempted to add wallpaper window with bad token " |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2232 | + attrs.token + ". Aborting."); |
| 2233 | return WindowManagerImpl.ADD_BAD_APP_TOKEN; |
| 2234 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2235 | } |
| 2236 | |
| 2237 | win = new WindowState(session, client, token, |
| 2238 | attachedWindow, attrs, viewVisibility); |
| 2239 | if (win.mDeathRecipient == null) { |
| 2240 | // Client has apparently died, so there is no reason to |
| 2241 | // continue. |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2242 | Slog.w(TAG, "Adding window client " + client.asBinder() |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2243 | + " that is dead, aborting."); |
| 2244 | return WindowManagerImpl.ADD_APP_EXITING; |
| 2245 | } |
| 2246 | |
| 2247 | mPolicy.adjustWindowParamsLw(win.mAttrs); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2248 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2249 | res = mPolicy.prepareAddWindowLw(win, attrs); |
| 2250 | if (res != WindowManagerImpl.ADD_OKAY) { |
| 2251 | return res; |
| 2252 | } |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 2253 | |
| Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 2254 | if (outInputChannel != null) { |
| 2255 | String name = win.makeInputChannelName(); |
| 2256 | InputChannel[] inputChannels = InputChannel.openInputChannelPair(name); |
| 2257 | win.mInputChannel = inputChannels[0]; |
| 2258 | inputChannels[1].transferToBinderOutParameter(outInputChannel); |
| 2259 | |
| 2260 | mInputManager.registerInputChannel(win.mInputChannel); |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 2261 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2262 | |
| 2263 | // From now on, no exceptions or errors allowed! |
| 2264 | |
| 2265 | res = WindowManagerImpl.ADD_OKAY; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2266 | |
| Dianne Hackborn | 5132b37 | 2010-07-29 12:51:35 -0700 | [diff] [blame] | 2267 | origId = Binder.clearCallingIdentity(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2268 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2269 | if (addToken) { |
| 2270 | mTokenMap.put(attrs.token, token); |
| 2271 | mTokenList.add(token); |
| 2272 | } |
| 2273 | win.attach(); |
| 2274 | mWindowMap.put(client.asBinder(), win); |
| 2275 | |
| 2276 | if (attrs.type == TYPE_APPLICATION_STARTING && |
| 2277 | token.appWindowToken != null) { |
| 2278 | token.appWindowToken.startingWindow = win; |
| 2279 | } |
| 2280 | |
| 2281 | boolean imMayMove = true; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2282 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2283 | if (attrs.type == TYPE_INPUT_METHOD) { |
| 2284 | mInputMethodWindow = win; |
| 2285 | addInputMethodWindowToListLocked(win); |
| 2286 | imMayMove = false; |
| 2287 | } else if (attrs.type == TYPE_INPUT_METHOD_DIALOG) { |
| 2288 | mInputMethodDialogs.add(win); |
| 2289 | addWindowToListInOrderLocked(win, true); |
| 2290 | adjustInputMethodDialogsLocked(); |
| 2291 | imMayMove = false; |
| 2292 | } else { |
| 2293 | addWindowToListInOrderLocked(win, true); |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 2294 | if (attrs.type == TYPE_WALLPAPER) { |
| 2295 | mLastWallpaperTimeoutTime = 0; |
| 2296 | adjustWallpaperWindowsLocked(); |
| 2297 | } else if ((attrs.flags&FLAG_SHOW_WALLPAPER) != 0) { |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2298 | adjustWallpaperWindowsLocked(); |
| 2299 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2300 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2301 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2302 | win.mEnterAnimationPending = true; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2303 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2304 | mPolicy.getContentInsetHintLw(attrs, outContentInsets); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2305 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2306 | if (mInTouchMode) { |
| 2307 | res |= WindowManagerImpl.ADD_FLAG_IN_TOUCH_MODE; |
| 2308 | } |
| 2309 | if (win == null || win.mAppToken == null || !win.mAppToken.clientHidden) { |
| 2310 | res |= WindowManagerImpl.ADD_FLAG_APP_VISIBLE; |
| 2311 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2312 | |
| The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 2313 | boolean focusChanged = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2314 | if (win.canReceiveKeys()) { |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 2315 | focusChanged = updateFocusedWindowLocked(UPDATE_FOCUS_WILL_ASSIGN_LAYERS); |
| 2316 | if (focusChanged) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2317 | imMayMove = false; |
| 2318 | } |
| 2319 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2320 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2321 | if (imMayMove) { |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2322 | moveInputMethodWindowsIfNeededLocked(false); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2323 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2324 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2325 | assignLayersLocked(); |
| 2326 | // Don't do layout here, the window must call |
| 2327 | // relayout to be displayed, so we'll do it there. |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2328 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2329 | //dump(); |
| 2330 | |
| The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 2331 | if (focusChanged) { |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 2332 | finishUpdateFocusedWindowAfterAssignLayersLocked(); |
| The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 2333 | } |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 2334 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2335 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2336 | TAG, "New client " + client.asBinder() |
| 2337 | + ": window=" + win); |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2338 | |
| 2339 | if (win.isVisibleOrAdding() && updateOrientationFromAppTokensLocked()) { |
| 2340 | reportNewConfig = true; |
| 2341 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2342 | } |
| 2343 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2344 | if (reportNewConfig) { |
| 2345 | sendNewConfiguration(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2346 | } |
| Dianne Hackborn | 5132b37 | 2010-07-29 12:51:35 -0700 | [diff] [blame] | 2347 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2348 | Binder.restoreCallingIdentity(origId); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2349 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2350 | return res; |
| 2351 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2352 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2353 | public void removeWindow(Session session, IWindow client) { |
| 2354 | synchronized(mWindowMap) { |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2355 | WindowState win = windowForClientLocked(session, client, false); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2356 | if (win == null) { |
| 2357 | return; |
| 2358 | } |
| 2359 | removeWindowLocked(session, win); |
| 2360 | } |
| 2361 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2362 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2363 | public void removeWindowLocked(Session session, WindowState win) { |
| 2364 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2365 | if (localLOGV || DEBUG_FOCUS) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2366 | TAG, "Remove " + win + " client=" |
| 2367 | + Integer.toHexString(System.identityHashCode( |
| 2368 | win.mClient.asBinder())) |
| 2369 | + ", surface=" + win.mSurface); |
| 2370 | |
| 2371 | final long origId = Binder.clearCallingIdentity(); |
| Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 2372 | |
| 2373 | win.disposeInputChannel(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2374 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2375 | if (DEBUG_APP_TRANSITIONS) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2376 | TAG, "Remove " + win + ": mSurface=" + win.mSurface |
| 2377 | + " mExiting=" + win.mExiting |
| 2378 | + " isAnimating=" + win.isAnimating() |
| 2379 | + " app-animation=" |
| 2380 | + (win.mAppToken != null ? win.mAppToken.animation : null) |
| 2381 | + " inPendingTransaction=" |
| 2382 | + (win.mAppToken != null ? win.mAppToken.inPendingTransaction : false) |
| 2383 | + " mDisplayFrozen=" + mDisplayFrozen); |
| 2384 | // Visibility of the removed window. Will be used later to update orientation later on. |
| 2385 | boolean wasVisible = false; |
| 2386 | // First, see if we need to run an animation. If we do, we have |
| 2387 | // to hold off on removing the window until the animation is done. |
| 2388 | // If the display is frozen, just remove immediately, since the |
| 2389 | // animation wouldn't be seen. |
| Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 2390 | if (win.mSurface != null && !mDisplayFrozen && mPolicy.isScreenOn()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2391 | // If we are not currently running the exit animation, we |
| 2392 | // need to see about starting one. |
| 2393 | if (wasVisible=win.isWinVisibleLw()) { |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2394 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2395 | int transit = WindowManagerPolicy.TRANSIT_EXIT; |
| 2396 | if (win.getAttrs().type == TYPE_APPLICATION_STARTING) { |
| 2397 | transit = WindowManagerPolicy.TRANSIT_PREVIEW_DONE; |
| 2398 | } |
| 2399 | // Try starting an animation. |
| 2400 | if (applyAnimationLocked(win, transit, false)) { |
| 2401 | win.mExiting = true; |
| 2402 | } |
| 2403 | } |
| 2404 | if (win.mExiting || win.isAnimating()) { |
| 2405 | // The exit animation is running... wait for it! |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2406 | //Slog.i(TAG, "*** Running exit animation..."); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2407 | win.mExiting = true; |
| 2408 | win.mRemoveOnExit = true; |
| 2409 | mLayoutNeeded = true; |
| 2410 | updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES); |
| 2411 | performLayoutAndPlaceSurfacesLocked(); |
| 2412 | if (win.mAppToken != null) { |
| 2413 | win.mAppToken.updateReportedVisibilityLocked(); |
| 2414 | } |
| 2415 | //dump(); |
| 2416 | Binder.restoreCallingIdentity(origId); |
| 2417 | return; |
| 2418 | } |
| 2419 | } |
| 2420 | |
| 2421 | removeWindowInnerLocked(session, win); |
| 2422 | // Removing a visible window will effect the computed orientation |
| 2423 | // So just update orientation if needed. |
| The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 2424 | if (wasVisible && computeForcedAppOrientationLocked() |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2425 | != mForcedAppOrientation |
| 2426 | && updateOrientationFromAppTokensLocked()) { |
| 2427 | mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2428 | } |
| 2429 | updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL); |
| 2430 | Binder.restoreCallingIdentity(origId); |
| 2431 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2432 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2433 | private void removeWindowInnerLocked(Session session, WindowState win) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2434 | win.mRemoved = true; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2435 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2436 | if (mInputMethodTarget == win) { |
| 2437 | moveInputMethodWindowsIfNeededLocked(false); |
| 2438 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2439 | |
| Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 2440 | if (false) { |
| 2441 | RuntimeException e = new RuntimeException("here"); |
| 2442 | e.fillInStackTrace(); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2443 | Slog.w(TAG, "Removing window " + win, e); |
| Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 2444 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2445 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2446 | mPolicy.removeWindowLw(win); |
| 2447 | win.removeLocked(); |
| 2448 | |
| 2449 | mWindowMap.remove(win.mClient.asBinder()); |
| 2450 | mWindows.remove(win); |
| Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 2451 | mWindowsChanged = true; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2452 | 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] | 2453 | |
| 2454 | if (mInputMethodWindow == win) { |
| 2455 | mInputMethodWindow = null; |
| 2456 | } else if (win.mAttrs.type == TYPE_INPUT_METHOD_DIALOG) { |
| 2457 | mInputMethodDialogs.remove(win); |
| 2458 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2459 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2460 | final WindowToken token = win.mToken; |
| 2461 | final AppWindowToken atoken = win.mAppToken; |
| 2462 | token.windows.remove(win); |
| 2463 | if (atoken != null) { |
| 2464 | atoken.allAppWindows.remove(win); |
| 2465 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2466 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2467 | TAG, "**** Removing window " + win + ": count=" |
| 2468 | + token.windows.size()); |
| 2469 | if (token.windows.size() == 0) { |
| 2470 | if (!token.explicit) { |
| 2471 | mTokenMap.remove(token.token); |
| 2472 | mTokenList.remove(token); |
| 2473 | } else if (atoken != null) { |
| 2474 | atoken.firstWindowDrawn = false; |
| 2475 | } |
| 2476 | } |
| 2477 | |
| 2478 | if (atoken != null) { |
| 2479 | if (atoken.startingWindow == win) { |
| 2480 | atoken.startingWindow = null; |
| 2481 | } else if (atoken.allAppWindows.size() == 0 && atoken.startingData != null) { |
| 2482 | // If this is the last window and we had requested a starting |
| 2483 | // transition window, well there is no point now. |
| 2484 | atoken.startingData = null; |
| 2485 | } else if (atoken.allAppWindows.size() == 1 && atoken.startingView != null) { |
| 2486 | // If this is the last window except for a starting transition |
| 2487 | // window, we need to get rid of the starting transition. |
| 2488 | if (DEBUG_STARTING_WINDOW) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2489 | Slog.v(TAG, "Schedule remove starting " + token |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2490 | + ": no more real windows"); |
| 2491 | } |
| 2492 | Message m = mH.obtainMessage(H.REMOVE_STARTING, atoken); |
| 2493 | mH.sendMessage(m); |
| 2494 | } |
| 2495 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2496 | |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 2497 | if (win.mAttrs.type == TYPE_WALLPAPER) { |
| 2498 | mLastWallpaperTimeoutTime = 0; |
| 2499 | adjustWallpaperWindowsLocked(); |
| 2500 | } else if ((win.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0) { |
| Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 2501 | adjustWallpaperWindowsLocked(); |
| 2502 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2503 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2504 | if (!mInLayout) { |
| 2505 | assignLayersLocked(); |
| 2506 | mLayoutNeeded = true; |
| 2507 | performLayoutAndPlaceSurfacesLocked(); |
| 2508 | if (win.mAppToken != null) { |
| 2509 | win.mAppToken.updateReportedVisibilityLocked(); |
| 2510 | } |
| 2511 | } |
| Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 2512 | |
| 2513 | mInputMonitor.updateInputWindowsLw(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2514 | } |
| 2515 | |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 2516 | private static void logSurface(WindowState w, String msg, RuntimeException where) { |
| 2517 | String str = " SURFACE " + Integer.toHexString(w.hashCode()) |
| 2518 | + ": " + msg + " / " + w.mAttrs.getTitle(); |
| 2519 | if (where != null) { |
| 2520 | Slog.i(TAG, str, where); |
| 2521 | } else { |
| 2522 | Slog.i(TAG, str); |
| 2523 | } |
| 2524 | } |
| 2525 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2526 | private void setTransparentRegionWindow(Session session, IWindow client, Region region) { |
| 2527 | long origId = Binder.clearCallingIdentity(); |
| 2528 | try { |
| 2529 | synchronized (mWindowMap) { |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2530 | WindowState w = windowForClientLocked(session, client, false); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2531 | if ((w != null) && (w.mSurface != null)) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2532 | if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2533 | Surface.openTransaction(); |
| 2534 | try { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 2535 | if (SHOW_TRANSACTIONS) logSurface(w, |
| 2536 | "transparentRegionHint=" + region, null); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2537 | w.mSurface.setTransparentRegionHint(region); |
| 2538 | } finally { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2539 | if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2540 | Surface.closeTransaction(); |
| 2541 | } |
| 2542 | } |
| 2543 | } |
| 2544 | } finally { |
| 2545 | Binder.restoreCallingIdentity(origId); |
| 2546 | } |
| 2547 | } |
| 2548 | |
| 2549 | void setInsetsWindow(Session session, IWindow client, |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2550 | int touchableInsets, Rect contentInsets, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2551 | Rect visibleInsets) { |
| 2552 | long origId = Binder.clearCallingIdentity(); |
| 2553 | try { |
| 2554 | synchronized (mWindowMap) { |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2555 | WindowState w = windowForClientLocked(session, client, false); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2556 | if (w != null) { |
| 2557 | w.mGivenInsetsPending = false; |
| 2558 | w.mGivenContentInsets.set(contentInsets); |
| 2559 | w.mGivenVisibleInsets.set(visibleInsets); |
| 2560 | w.mTouchableInsets = touchableInsets; |
| 2561 | mLayoutNeeded = true; |
| 2562 | performLayoutAndPlaceSurfacesLocked(); |
| 2563 | } |
| 2564 | } |
| 2565 | } finally { |
| 2566 | Binder.restoreCallingIdentity(origId); |
| 2567 | } |
| 2568 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2569 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2570 | public void getWindowDisplayFrame(Session session, IWindow client, |
| 2571 | Rect outDisplayFrame) { |
| 2572 | synchronized(mWindowMap) { |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2573 | WindowState win = windowForClientLocked(session, client, false); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2574 | if (win == null) { |
| 2575 | outDisplayFrame.setEmpty(); |
| 2576 | return; |
| 2577 | } |
| 2578 | outDisplayFrame.set(win.mDisplayFrame); |
| 2579 | } |
| 2580 | } |
| 2581 | |
| Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 2582 | public void setWindowWallpaperPositionLocked(WindowState window, float x, float y, |
| 2583 | float xStep, float yStep) { |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 2584 | if (window.mWallpaperX != x || window.mWallpaperY != y) { |
| 2585 | window.mWallpaperX = x; |
| 2586 | window.mWallpaperY = y; |
| Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 2587 | window.mWallpaperXStep = xStep; |
| 2588 | window.mWallpaperYStep = yStep; |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 2589 | if (updateWallpaperOffsetLocked(window, true)) { |
| 2590 | performLayoutAndPlaceSurfacesLocked(); |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 2591 | } |
| 2592 | } |
| 2593 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2594 | |
| Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 2595 | void wallpaperCommandComplete(IBinder window, Bundle result) { |
| 2596 | synchronized (mWindowMap) { |
| 2597 | if (mWaitingOnWallpaper != null && |
| 2598 | mWaitingOnWallpaper.mClient.asBinder() == window) { |
| 2599 | mWaitingOnWallpaper = null; |
| 2600 | mWindowMap.notifyAll(); |
| 2601 | } |
| 2602 | } |
| 2603 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2604 | |
| Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 2605 | public Bundle sendWindowWallpaperCommandLocked(WindowState window, |
| 2606 | String action, int x, int y, int z, Bundle extras, boolean sync) { |
| 2607 | if (window == mWallpaperTarget || window == mLowerWallpaperTarget |
| 2608 | || window == mUpperWallpaperTarget) { |
| 2609 | boolean doWait = sync; |
| 2610 | int curTokenIndex = mWallpaperTokens.size(); |
| 2611 | while (curTokenIndex > 0) { |
| 2612 | curTokenIndex--; |
| 2613 | WindowToken token = mWallpaperTokens.get(curTokenIndex); |
| 2614 | int curWallpaperIndex = token.windows.size(); |
| 2615 | while (curWallpaperIndex > 0) { |
| 2616 | curWallpaperIndex--; |
| 2617 | WindowState wallpaper = token.windows.get(curWallpaperIndex); |
| 2618 | try { |
| 2619 | wallpaper.mClient.dispatchWallpaperCommand(action, |
| 2620 | x, y, z, extras, sync); |
| 2621 | // We only want to be synchronous with one wallpaper. |
| 2622 | sync = false; |
| 2623 | } catch (RemoteException e) { |
| 2624 | } |
| 2625 | } |
| 2626 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2627 | |
| Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 2628 | if (doWait) { |
| 2629 | // XXX Need to wait for result. |
| 2630 | } |
| 2631 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2632 | |
| Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 2633 | return null; |
| 2634 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2635 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2636 | public int relayoutWindow(Session session, IWindow client, |
| 2637 | WindowManager.LayoutParams attrs, int requestedWidth, |
| 2638 | int requestedHeight, int viewVisibility, boolean insetsPending, |
| 2639 | Rect outFrame, Rect outContentInsets, Rect outVisibleInsets, |
| Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 2640 | Configuration outConfig, Surface outSurface) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2641 | boolean displayed = false; |
| 2642 | boolean inTouchMode; |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2643 | boolean configChanged; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2644 | long origId = Binder.clearCallingIdentity(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2645 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2646 | synchronized(mWindowMap) { |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2647 | WindowState win = windowForClientLocked(session, client, false); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2648 | if (win == null) { |
| 2649 | return 0; |
| 2650 | } |
| 2651 | win.mRequestedWidth = requestedWidth; |
| 2652 | win.mRequestedHeight = requestedHeight; |
| 2653 | |
| 2654 | if (attrs != null) { |
| 2655 | mPolicy.adjustWindowParamsLw(attrs); |
| 2656 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2657 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2658 | int attrChanges = 0; |
| 2659 | int flagChanges = 0; |
| 2660 | if (attrs != null) { |
| 2661 | flagChanges = win.mAttrs.flags ^= attrs.flags; |
| 2662 | attrChanges = win.mAttrs.copyFrom(attrs); |
| 2663 | } |
| 2664 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2665 | 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] | 2666 | |
| 2667 | if ((attrChanges & WindowManager.LayoutParams.ALPHA_CHANGED) != 0) { |
| 2668 | win.mAlpha = attrs.alpha; |
| 2669 | } |
| 2670 | |
| 2671 | final boolean scaledWindow = |
| 2672 | ((win.mAttrs.flags & WindowManager.LayoutParams.FLAG_SCALED) != 0); |
| 2673 | |
| 2674 | if (scaledWindow) { |
| 2675 | // requested{Width|Height} Surface's physical size |
| 2676 | // attrs.{width|height} Size on screen |
| 2677 | win.mHScale = (attrs.width != requestedWidth) ? |
| 2678 | (attrs.width / (float)requestedWidth) : 1.0f; |
| 2679 | win.mVScale = (attrs.height != requestedHeight) ? |
| 2680 | (attrs.height / (float)requestedHeight) : 1.0f; |
| Dianne Hackborn | 9b52a21 | 2009-12-11 14:51:35 -0800 | [diff] [blame] | 2681 | } else { |
| 2682 | win.mHScale = win.mVScale = 1; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2683 | } |
| 2684 | |
| 2685 | boolean imMayMove = (flagChanges&( |
| 2686 | WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM | |
| 2687 | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE)) != 0; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2688 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2689 | boolean focusMayChange = win.mViewVisibility != viewVisibility |
| 2690 | || ((flagChanges&WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) != 0) |
| 2691 | || (!win.mRelayoutCalled); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2692 | |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2693 | boolean wallpaperMayMove = win.mViewVisibility != viewVisibility |
| 2694 | && (win.mAttrs.flags & FLAG_SHOW_WALLPAPER) != 0; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2695 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2696 | win.mRelayoutCalled = true; |
| 2697 | final int oldVisibility = win.mViewVisibility; |
| 2698 | win.mViewVisibility = viewVisibility; |
| 2699 | if (viewVisibility == View.VISIBLE && |
| 2700 | (win.mAppToken == null || !win.mAppToken.clientHidden)) { |
| 2701 | displayed = !win.isVisibleLw(); |
| 2702 | if (win.mExiting) { |
| 2703 | win.mExiting = false; |
| 2704 | win.mAnimation = null; |
| 2705 | } |
| 2706 | if (win.mDestroying) { |
| 2707 | win.mDestroying = false; |
| 2708 | mDestroySurface.remove(win); |
| 2709 | } |
| 2710 | if (oldVisibility == View.GONE) { |
| 2711 | win.mEnterAnimationPending = true; |
| 2712 | } |
| Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 2713 | if (displayed) { |
| 2714 | if (win.mSurface != null && !win.mDrawPending |
| 2715 | && !win.mCommitDrawPending && !mDisplayFrozen |
| 2716 | && mPolicy.isScreenOn()) { |
| 2717 | applyEnterAnimationLocked(win); |
| 2718 | } |
| 2719 | if ((win.mAttrs.flags |
| 2720 | & WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON) != 0) { |
| 2721 | if (DEBUG_VISIBILITY) Slog.v(TAG, |
| 2722 | "Relayout window turning screen on: " + win); |
| 2723 | win.mTurnOnScreen = true; |
| 2724 | } |
| 2725 | int diff = 0; |
| 2726 | if (win.mConfiguration != mCurConfiguration |
| 2727 | && (win.mConfiguration == null |
| 2728 | || (diff=mCurConfiguration.diff(win.mConfiguration)) != 0)) { |
| 2729 | win.mConfiguration = mCurConfiguration; |
| 2730 | if (DEBUG_CONFIGURATION) { |
| 2731 | Slog.i(TAG, "Window " + win + " visible with new config: " |
| 2732 | + win.mConfiguration + " / 0x" |
| 2733 | + Integer.toHexString(diff)); |
| 2734 | } |
| 2735 | outConfig.setTo(mCurConfiguration); |
| 2736 | } |
| Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 2737 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2738 | if ((attrChanges&WindowManager.LayoutParams.FORMAT_CHANGED) != 0) { |
| 2739 | // To change the format, we need to re-build the surface. |
| 2740 | win.destroySurfaceLocked(); |
| 2741 | displayed = true; |
| 2742 | } |
| 2743 | try { |
| 2744 | Surface surface = win.createSurfaceLocked(); |
| 2745 | if (surface != null) { |
| 2746 | outSurface.copyFrom(surface); |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2747 | win.mReportDestroySurface = false; |
| 2748 | win.mSurfacePendingDestroy = false; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2749 | if (SHOW_TRANSACTIONS) Slog.i(TAG, |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 2750 | " OUT SURFACE " + outSurface + ": copied"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2751 | } else { |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 2752 | // For some reason there isn't a surface. Clear the |
| 2753 | // caller's object so they see the same state. |
| 2754 | outSurface.release(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2755 | } |
| 2756 | } catch (Exception e) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 2757 | mInputMonitor.updateInputWindowsLw(); |
| 2758 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2759 | Slog.w(TAG, "Exception thrown when creating surface for client " |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 2760 | + client + " (" + win.mAttrs.getTitle() + ")", |
| 2761 | e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2762 | Binder.restoreCallingIdentity(origId); |
| 2763 | return 0; |
| 2764 | } |
| 2765 | if (displayed) { |
| 2766 | focusMayChange = true; |
| 2767 | } |
| 2768 | if (win.mAttrs.type == TYPE_INPUT_METHOD |
| 2769 | && mInputMethodWindow == null) { |
| 2770 | mInputMethodWindow = win; |
| 2771 | imMayMove = true; |
| 2772 | } |
| Dianne Hackborn | 558947c | 2009-12-18 16:02:50 -0800 | [diff] [blame] | 2773 | if (win.mAttrs.type == TYPE_BASE_APPLICATION |
| 2774 | && win.mAppToken != null |
| 2775 | && win.mAppToken.startingWindow != null) { |
| 2776 | // Special handling of starting window over the base |
| 2777 | // window of the app: propagate lock screen flags to it, |
| 2778 | // to provide the correct semantics while starting. |
| 2779 | final int mask = |
| 2780 | WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED |
| Mike Lockwood | ef73162 | 2010-01-27 17:51:34 -0500 | [diff] [blame] | 2781 | | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD |
| 2782 | | WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON; |
| Dianne Hackborn | 558947c | 2009-12-18 16:02:50 -0800 | [diff] [blame] | 2783 | WindowManager.LayoutParams sa = win.mAppToken.startingWindow.mAttrs; |
| 2784 | sa.flags = (sa.flags&~mask) | (win.mAttrs.flags&mask); |
| 2785 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2786 | } else { |
| 2787 | win.mEnterAnimationPending = false; |
| 2788 | if (win.mSurface != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2789 | if (DEBUG_VISIBILITY) Slog.i(TAG, "Relayout invis " + win |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2790 | + ": mExiting=" + win.mExiting |
| 2791 | + " mSurfacePendingDestroy=" + win.mSurfacePendingDestroy); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2792 | // If we are not currently running the exit animation, we |
| 2793 | // need to see about starting one. |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2794 | if (!win.mExiting || win.mSurfacePendingDestroy) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2795 | // Try starting an animation; if there isn't one, we |
| 2796 | // can destroy the surface right away. |
| 2797 | int transit = WindowManagerPolicy.TRANSIT_EXIT; |
| 2798 | if (win.getAttrs().type == TYPE_APPLICATION_STARTING) { |
| 2799 | transit = WindowManagerPolicy.TRANSIT_PREVIEW_DONE; |
| 2800 | } |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2801 | if (!win.mSurfacePendingDestroy && win.isWinVisibleLw() && |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2802 | applyAnimationLocked(win, transit, false)) { |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2803 | focusMayChange = true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2804 | win.mExiting = true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2805 | } else if (win.isAnimating()) { |
| 2806 | // Currently in a hide animation... turn this into |
| 2807 | // an exit. |
| 2808 | win.mExiting = true; |
| Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 2809 | } else if (win == mWallpaperTarget) { |
| 2810 | // If the wallpaper is currently behind this |
| 2811 | // window, we need to change both of them inside |
| 2812 | // of a transaction to avoid artifacts. |
| 2813 | win.mExiting = true; |
| 2814 | win.mAnimating = true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2815 | } else { |
| 2816 | if (mInputMethodWindow == win) { |
| 2817 | mInputMethodWindow = null; |
| 2818 | } |
| 2819 | win.destroySurfaceLocked(); |
| 2820 | } |
| 2821 | } |
| 2822 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2823 | |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2824 | if (win.mSurface == null || (win.getAttrs().flags |
| 2825 | & WindowManager.LayoutParams.FLAG_KEEP_SURFACE_WHILE_ANIMATING) == 0 |
| 2826 | || win.mSurfacePendingDestroy) { |
| 2827 | // We are being called from a local process, which |
| 2828 | // means outSurface holds its current surface. Ensure the |
| 2829 | // surface object is cleared, but we don't want it actually |
| 2830 | // destroyed at this point. |
| 2831 | win.mSurfacePendingDestroy = false; |
| 2832 | outSurface.release(); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2833 | if (DEBUG_VISIBILITY) Slog.i(TAG, "Releasing surface in: " + win); |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2834 | } else if (win.mSurface != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2835 | if (DEBUG_VISIBILITY) Slog.i(TAG, |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2836 | "Keeping surface, will report destroy: " + win); |
| 2837 | win.mReportDestroySurface = true; |
| 2838 | outSurface.copyFrom(win.mSurface); |
| 2839 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2840 | } |
| 2841 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2842 | if (focusMayChange) { |
| 2843 | //System.out.println("Focus may change: " + win.mAttrs.getTitle()); |
| 2844 | if (updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES)) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2845 | imMayMove = false; |
| 2846 | } |
| 2847 | //System.out.println("Relayout " + win + ": focus=" + mCurrentFocus); |
| 2848 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2849 | |
| The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 2850 | // updateFocusedWindowLocked() already assigned layers so we only need to |
| 2851 | // reassign them at this point if the IM window state gets shuffled |
| 2852 | boolean assignLayers = false; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2853 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2854 | if (imMayMove) { |
| Dianne Hackborn | 8abd5f0 | 2009-11-20 18:09:03 -0800 | [diff] [blame] | 2855 | if (moveInputMethodWindowsIfNeededLocked(false) || displayed) { |
| 2856 | // Little hack here -- we -should- be able to rely on the |
| 2857 | // function to return true if the IME has moved and needs |
| 2858 | // its layer recomputed. However, if the IME was hidden |
| 2859 | // and isn't actually moved in the list, its layer may be |
| 2860 | // 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] | 2861 | assignLayers = true; |
| 2862 | } |
| 2863 | } |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2864 | if (wallpaperMayMove) { |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 2865 | if ((adjustWallpaperWindowsLocked()&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) { |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2866 | assignLayers = true; |
| 2867 | } |
| 2868 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2869 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2870 | mLayoutNeeded = true; |
| 2871 | win.mGivenInsetsPending = insetsPending; |
| 2872 | if (assignLayers) { |
| 2873 | assignLayersLocked(); |
| 2874 | } |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2875 | configChanged = updateOrientationFromAppTokensLocked(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2876 | performLayoutAndPlaceSurfacesLocked(); |
| Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 2877 | if (displayed && win.mIsWallpaper) { |
| 2878 | updateWallpaperOffsetLocked(win, mDisplay.getWidth(), |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 2879 | mDisplay.getHeight(), false); |
| Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 2880 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2881 | if (win.mAppToken != null) { |
| 2882 | win.mAppToken.updateReportedVisibilityLocked(); |
| 2883 | } |
| 2884 | outFrame.set(win.mFrame); |
| 2885 | outContentInsets.set(win.mContentInsets); |
| 2886 | outVisibleInsets.set(win.mVisibleInsets); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2887 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2888 | TAG, "Relayout given client " + client.asBinder() |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2889 | + ", requestedWidth=" + requestedWidth |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2890 | + ", requestedHeight=" + requestedHeight |
| 2891 | + ", viewVisibility=" + viewVisibility |
| 2892 | + "\nRelayout returning frame=" + outFrame |
| 2893 | + ", surface=" + outSurface); |
| 2894 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2895 | if (localLOGV || DEBUG_FOCUS) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2896 | TAG, "Relayout of " + win + ": focusMayChange=" + focusMayChange); |
| 2897 | |
| 2898 | inTouchMode = mInTouchMode; |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 2899 | |
| 2900 | mInputMonitor.updateInputWindowsLw(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2901 | } |
| 2902 | |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2903 | if (configChanged) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2904 | sendNewConfiguration(); |
| 2905 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2906 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2907 | Binder.restoreCallingIdentity(origId); |
| 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 | return (inTouchMode ? WindowManagerImpl.RELAYOUT_IN_TOUCH_MODE : 0) |
| 2910 | | (displayed ? WindowManagerImpl.RELAYOUT_FIRST_TIME : 0); |
| 2911 | } |
| 2912 | |
| 2913 | public void finishDrawingWindow(Session session, IWindow client) { |
| 2914 | final long origId = Binder.clearCallingIdentity(); |
| 2915 | synchronized(mWindowMap) { |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2916 | WindowState win = windowForClientLocked(session, client, false); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2917 | if (win != null && win.finishDrawingLocked()) { |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 2918 | if ((win.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0) { |
| 2919 | adjustWallpaperWindowsLocked(); |
| 2920 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2921 | mLayoutNeeded = true; |
| 2922 | performLayoutAndPlaceSurfacesLocked(); |
| 2923 | } |
| 2924 | } |
| 2925 | Binder.restoreCallingIdentity(origId); |
| 2926 | } |
| 2927 | |
| 2928 | private AttributeCache.Entry getCachedAnimations(WindowManager.LayoutParams lp) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2929 | 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] | 2930 | + (lp != null ? lp.packageName : null) |
| 2931 | + " resId=0x" + (lp != null ? Integer.toHexString(lp.windowAnimations) : null)); |
| 2932 | if (lp != null && lp.windowAnimations != 0) { |
| 2933 | // If this is a system resource, don't try to load it from the |
| 2934 | // application resources. It is nice to avoid loading application |
| 2935 | // resources if we can. |
| 2936 | String packageName = lp.packageName != null ? lp.packageName : "android"; |
| 2937 | int resId = lp.windowAnimations; |
| 2938 | if ((resId&0xFF000000) == 0x01000000) { |
| 2939 | packageName = "android"; |
| 2940 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2941 | 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] | 2942 | + packageName); |
| 2943 | return AttributeCache.instance().get(packageName, resId, |
| 2944 | com.android.internal.R.styleable.WindowAnimation); |
| 2945 | } |
| 2946 | return null; |
| 2947 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2948 | |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2949 | private AttributeCache.Entry getCachedAnimations(String packageName, int resId) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2950 | if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: params package=" |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2951 | + packageName + " resId=0x" + Integer.toHexString(resId)); |
| 2952 | if (packageName != null) { |
| 2953 | if ((resId&0xFF000000) == 0x01000000) { |
| 2954 | packageName = "android"; |
| 2955 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2956 | if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: picked package=" |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2957 | + packageName); |
| 2958 | return AttributeCache.instance().get(packageName, resId, |
| 2959 | com.android.internal.R.styleable.WindowAnimation); |
| 2960 | } |
| 2961 | return null; |
| 2962 | } |
| 2963 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2964 | private void applyEnterAnimationLocked(WindowState win) { |
| 2965 | int transit = WindowManagerPolicy.TRANSIT_SHOW; |
| 2966 | if (win.mEnterAnimationPending) { |
| 2967 | win.mEnterAnimationPending = false; |
| 2968 | transit = WindowManagerPolicy.TRANSIT_ENTER; |
| 2969 | } |
| 2970 | |
| 2971 | applyAnimationLocked(win, transit, true); |
| 2972 | } |
| 2973 | |
| 2974 | private boolean applyAnimationLocked(WindowState win, |
| 2975 | int transit, boolean isEntrance) { |
| 2976 | if (win.mLocalAnimating && win.mAnimationIsEntrance == isEntrance) { |
| 2977 | // If we are trying to apply an animation, but already running |
| 2978 | // an animation of the same type, then just leave that one alone. |
| 2979 | return true; |
| 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 | // Only apply an animation if the display isn't frozen. If it is |
| 2983 | // frozen, there is no reason to animate and it can cause strange |
| 2984 | // artifacts when we unfreeze the display if some different animation |
| 2985 | // is running. |
| Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 2986 | if (!mDisplayFrozen && mPolicy.isScreenOn()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2987 | int anim = mPolicy.selectAnimationLw(win, transit); |
| 2988 | int attr = -1; |
| 2989 | Animation a = null; |
| 2990 | if (anim != 0) { |
| 2991 | a = AnimationUtils.loadAnimation(mContext, anim); |
| 2992 | } else { |
| 2993 | switch (transit) { |
| 2994 | case WindowManagerPolicy.TRANSIT_ENTER: |
| 2995 | attr = com.android.internal.R.styleable.WindowAnimation_windowEnterAnimation; |
| 2996 | break; |
| 2997 | case WindowManagerPolicy.TRANSIT_EXIT: |
| 2998 | attr = com.android.internal.R.styleable.WindowAnimation_windowExitAnimation; |
| 2999 | break; |
| 3000 | case WindowManagerPolicy.TRANSIT_SHOW: |
| 3001 | attr = com.android.internal.R.styleable.WindowAnimation_windowShowAnimation; |
| 3002 | break; |
| 3003 | case WindowManagerPolicy.TRANSIT_HIDE: |
| 3004 | attr = com.android.internal.R.styleable.WindowAnimation_windowHideAnimation; |
| 3005 | break; |
| 3006 | } |
| 3007 | if (attr >= 0) { |
| 3008 | a = loadAnimation(win.mAttrs, attr); |
| 3009 | } |
| 3010 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3011 | if (DEBUG_ANIM) Slog.v(TAG, "applyAnimation: win=" + win |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3012 | + " anim=" + anim + " attr=0x" + Integer.toHexString(attr) |
| 3013 | + " mAnimation=" + win.mAnimation |
| 3014 | + " isEntrance=" + isEntrance); |
| 3015 | if (a != null) { |
| 3016 | if (DEBUG_ANIM) { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 3017 | RuntimeException e = null; |
| 3018 | if (!HIDE_STACK_CRAWLS) { |
| 3019 | e = new RuntimeException(); |
| 3020 | e.fillInStackTrace(); |
| 3021 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3022 | Slog.v(TAG, "Loaded animation " + a + " for " + win, e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3023 | } |
| 3024 | win.setAnimation(a); |
| 3025 | win.mAnimationIsEntrance = isEntrance; |
| 3026 | } |
| 3027 | } else { |
| 3028 | win.clearAnimation(); |
| 3029 | } |
| 3030 | |
| 3031 | return win.mAnimation != null; |
| 3032 | } |
| 3033 | |
| 3034 | private Animation loadAnimation(WindowManager.LayoutParams lp, int animAttr) { |
| 3035 | int anim = 0; |
| 3036 | Context context = mContext; |
| 3037 | if (animAttr >= 0) { |
| 3038 | AttributeCache.Entry ent = getCachedAnimations(lp); |
| 3039 | if (ent != null) { |
| 3040 | context = ent.context; |
| 3041 | anim = ent.array.getResourceId(animAttr, 0); |
| 3042 | } |
| 3043 | } |
| 3044 | if (anim != 0) { |
| 3045 | return AnimationUtils.loadAnimation(context, anim); |
| 3046 | } |
| 3047 | return null; |
| 3048 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3049 | |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 3050 | private Animation loadAnimation(String packageName, int resId) { |
| 3051 | int anim = 0; |
| 3052 | Context context = mContext; |
| 3053 | if (resId >= 0) { |
| 3054 | AttributeCache.Entry ent = getCachedAnimations(packageName, resId); |
| 3055 | if (ent != null) { |
| 3056 | context = ent.context; |
| 3057 | anim = resId; |
| 3058 | } |
| 3059 | } |
| 3060 | if (anim != 0) { |
| 3061 | return AnimationUtils.loadAnimation(context, anim); |
| 3062 | } |
| 3063 | return null; |
| 3064 | } |
| 3065 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3066 | private boolean applyAnimationLocked(AppWindowToken wtoken, |
| 3067 | WindowManager.LayoutParams lp, int transit, boolean enter) { |
| 3068 | // Only apply an animation if the display isn't frozen. If it is |
| 3069 | // frozen, there is no reason to animate and it can cause strange |
| 3070 | // artifacts when we unfreeze the display if some different animation |
| 3071 | // is running. |
| Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 3072 | if (!mDisplayFrozen && mPolicy.isScreenOn()) { |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 3073 | Animation a; |
| Mitsuru Oshima | d2967e2 | 2009-07-20 14:01:43 -0700 | [diff] [blame] | 3074 | if (lp != null && (lp.flags & FLAG_COMPATIBLE_WINDOW) != 0) { |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 3075 | a = new FadeInOutAnimation(enter); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3076 | if (DEBUG_ANIM) Slog.v(TAG, |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 3077 | "applying FadeInOutAnimation for a window in compatibility mode"); |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 3078 | } else if (mNextAppTransitionPackage != null) { |
| 3079 | a = loadAnimation(mNextAppTransitionPackage, enter ? |
| 3080 | mNextAppTransitionEnter : mNextAppTransitionExit); |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 3081 | } else { |
| 3082 | int animAttr = 0; |
| 3083 | switch (transit) { |
| 3084 | case WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN: |
| 3085 | animAttr = enter |
| 3086 | ? com.android.internal.R.styleable.WindowAnimation_activityOpenEnterAnimation |
| 3087 | : com.android.internal.R.styleable.WindowAnimation_activityOpenExitAnimation; |
| 3088 | break; |
| 3089 | case WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE: |
| 3090 | animAttr = enter |
| 3091 | ? com.android.internal.R.styleable.WindowAnimation_activityCloseEnterAnimation |
| 3092 | : com.android.internal.R.styleable.WindowAnimation_activityCloseExitAnimation; |
| 3093 | break; |
| 3094 | case WindowManagerPolicy.TRANSIT_TASK_OPEN: |
| 3095 | animAttr = enter |
| 3096 | ? com.android.internal.R.styleable.WindowAnimation_taskOpenEnterAnimation |
| 3097 | : com.android.internal.R.styleable.WindowAnimation_taskOpenExitAnimation; |
| 3098 | break; |
| 3099 | case WindowManagerPolicy.TRANSIT_TASK_CLOSE: |
| 3100 | animAttr = enter |
| 3101 | ? com.android.internal.R.styleable.WindowAnimation_taskCloseEnterAnimation |
| 3102 | : com.android.internal.R.styleable.WindowAnimation_taskCloseExitAnimation; |
| 3103 | break; |
| 3104 | case WindowManagerPolicy.TRANSIT_TASK_TO_FRONT: |
| 3105 | animAttr = enter |
| 3106 | ? com.android.internal.R.styleable.WindowAnimation_taskToFrontEnterAnimation |
| 3107 | : com.android.internal.R.styleable.WindowAnimation_taskToFrontExitAnimation; |
| 3108 | break; |
| 3109 | case WindowManagerPolicy.TRANSIT_TASK_TO_BACK: |
| 3110 | animAttr = enter |
| Mitsuru Oshima | 5a2b91d | 2009-07-16 16:30:02 -0700 | [diff] [blame] | 3111 | ? com.android.internal.R.styleable.WindowAnimation_taskToBackEnterAnimation |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 3112 | : com.android.internal.R.styleable.WindowAnimation_taskToBackExitAnimation; |
| 3113 | break; |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 3114 | case WindowManagerPolicy.TRANSIT_WALLPAPER_OPEN: |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 3115 | animAttr = enter |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 3116 | ? com.android.internal.R.styleable.WindowAnimation_wallpaperOpenEnterAnimation |
| 3117 | : com.android.internal.R.styleable.WindowAnimation_wallpaperOpenExitAnimation; |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 3118 | break; |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 3119 | case WindowManagerPolicy.TRANSIT_WALLPAPER_CLOSE: |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 3120 | animAttr = enter |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 3121 | ? com.android.internal.R.styleable.WindowAnimation_wallpaperCloseEnterAnimation |
| 3122 | : com.android.internal.R.styleable.WindowAnimation_wallpaperCloseExitAnimation; |
| 3123 | break; |
| 3124 | case WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_OPEN: |
| 3125 | animAttr = enter |
| 3126 | ? com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenEnterAnimation |
| 3127 | : com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenExitAnimation; |
| 3128 | break; |
| 3129 | case WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_CLOSE: |
| 3130 | animAttr = enter |
| 3131 | ? com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseEnterAnimation |
| 3132 | : com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseExitAnimation; |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 3133 | break; |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 3134 | } |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 3135 | a = animAttr != 0 ? loadAnimation(lp, animAttr) : null; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3136 | if (DEBUG_ANIM) Slog.v(TAG, "applyAnimation: wtoken=" + wtoken |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 3137 | + " anim=" + a |
| 3138 | + " animAttr=0x" + Integer.toHexString(animAttr) |
| 3139 | + " transit=" + transit); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3140 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3141 | if (a != null) { |
| 3142 | if (DEBUG_ANIM) { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 3143 | RuntimeException e = null; |
| 3144 | if (!HIDE_STACK_CRAWLS) { |
| 3145 | e = new RuntimeException(); |
| 3146 | e.fillInStackTrace(); |
| 3147 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3148 | Slog.v(TAG, "Loaded animation " + a + " for " + wtoken, e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3149 | } |
| 3150 | wtoken.setAnimation(a); |
| 3151 | } |
| 3152 | } else { |
| 3153 | wtoken.clearAnimation(); |
| 3154 | } |
| 3155 | |
| 3156 | return wtoken.animation != null; |
| 3157 | } |
| 3158 | |
| 3159 | // ------------------------------------------------------------- |
| 3160 | // Application Window Tokens |
| 3161 | // ------------------------------------------------------------- |
| 3162 | |
| 3163 | public void validateAppTokens(List tokens) { |
| 3164 | int v = tokens.size()-1; |
| 3165 | int m = mAppTokens.size()-1; |
| 3166 | while (v >= 0 && m >= 0) { |
| 3167 | AppWindowToken wtoken = mAppTokens.get(m); |
| 3168 | if (wtoken.removed) { |
| 3169 | m--; |
| 3170 | continue; |
| 3171 | } |
| 3172 | if (tokens.get(v) != wtoken.token) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3173 | 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] | 3174 | + " @ " + v + ", internal is " + wtoken.token + " @ " + m); |
| 3175 | } |
| 3176 | v--; |
| 3177 | m--; |
| 3178 | } |
| 3179 | while (v >= 0) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3180 | 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] | 3181 | v--; |
| 3182 | } |
| 3183 | while (m >= 0) { |
| 3184 | AppWindowToken wtoken = mAppTokens.get(m); |
| 3185 | if (!wtoken.removed) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3186 | Slog.w(TAG, "Invalid internal token: " + wtoken.token + " @ " + m); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3187 | } |
| 3188 | m--; |
| 3189 | } |
| 3190 | } |
| 3191 | |
| 3192 | boolean checkCallingPermission(String permission, String func) { |
| 3193 | // Quick check: if the calling permission is me, it's all okay. |
| 3194 | if (Binder.getCallingPid() == Process.myPid()) { |
| 3195 | return true; |
| 3196 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3197 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3198 | if (mContext.checkCallingPermission(permission) |
| 3199 | == PackageManager.PERMISSION_GRANTED) { |
| 3200 | return true; |
| 3201 | } |
| 3202 | String msg = "Permission Denial: " + func + " from pid=" |
| 3203 | + Binder.getCallingPid() |
| 3204 | + ", uid=" + Binder.getCallingUid() |
| 3205 | + " requires " + permission; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3206 | Slog.w(TAG, msg); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3207 | return false; |
| 3208 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3209 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3210 | AppWindowToken findAppWindowToken(IBinder token) { |
| 3211 | WindowToken wtoken = mTokenMap.get(token); |
| 3212 | if (wtoken == null) { |
| 3213 | return null; |
| 3214 | } |
| 3215 | return wtoken.appWindowToken; |
| 3216 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3217 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3218 | public void addWindowToken(IBinder token, int type) { |
| 3219 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3220 | "addWindowToken()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3221 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3222 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3223 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3224 | synchronized(mWindowMap) { |
| 3225 | WindowToken wtoken = mTokenMap.get(token); |
| 3226 | if (wtoken != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3227 | 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] | 3228 | return; |
| 3229 | } |
| 3230 | wtoken = new WindowToken(token, type, true); |
| 3231 | mTokenMap.put(token, wtoken); |
| 3232 | mTokenList.add(wtoken); |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 3233 | if (type == TYPE_WALLPAPER) { |
| 3234 | mWallpaperTokens.add(wtoken); |
| 3235 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3236 | } |
| 3237 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3238 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3239 | public void removeWindowToken(IBinder token) { |
| 3240 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3241 | "removeWindowToken()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3242 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3243 | } |
| 3244 | |
| 3245 | final long origId = Binder.clearCallingIdentity(); |
| 3246 | synchronized(mWindowMap) { |
| 3247 | WindowToken wtoken = mTokenMap.remove(token); |
| 3248 | mTokenList.remove(wtoken); |
| 3249 | if (wtoken != null) { |
| 3250 | boolean delayed = false; |
| 3251 | if (!wtoken.hidden) { |
| 3252 | wtoken.hidden = true; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3253 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3254 | final int N = wtoken.windows.size(); |
| 3255 | boolean changed = false; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3256 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3257 | for (int i=0; i<N; i++) { |
| 3258 | WindowState win = wtoken.windows.get(i); |
| 3259 | |
| 3260 | if (win.isAnimating()) { |
| 3261 | delayed = true; |
| 3262 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3263 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3264 | if (win.isVisibleNow()) { |
| 3265 | applyAnimationLocked(win, |
| 3266 | WindowManagerPolicy.TRANSIT_EXIT, false); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3267 | changed = true; |
| 3268 | } |
| 3269 | } |
| 3270 | |
| 3271 | if (changed) { |
| 3272 | mLayoutNeeded = true; |
| 3273 | performLayoutAndPlaceSurfacesLocked(); |
| 3274 | updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL); |
| 3275 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3276 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3277 | if (delayed) { |
| 3278 | mExitingTokens.add(wtoken); |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 3279 | } else if (wtoken.windowType == TYPE_WALLPAPER) { |
| 3280 | mWallpaperTokens.remove(wtoken); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3281 | } |
| 3282 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3283 | |
| Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 3284 | mInputMonitor.updateInputWindowsLw(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3285 | } else { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3286 | 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] | 3287 | } |
| 3288 | } |
| 3289 | Binder.restoreCallingIdentity(origId); |
| 3290 | } |
| 3291 | |
| 3292 | public void addAppToken(int addPos, IApplicationToken token, |
| 3293 | int groupId, int requestedOrientation, boolean fullscreen) { |
| 3294 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3295 | "addAppToken()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3296 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3297 | } |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 3298 | |
| 3299 | // Get the dispatching timeout here while we are not holding any locks so that it |
| 3300 | // can be cached by the AppWindowToken. The timeout value is used later by the |
| 3301 | // input dispatcher in code that does hold locks. If we did not cache the value |
| 3302 | // here we would run the chance of introducing a deadlock between the window manager |
| 3303 | // (which holds locks while updating the input dispatcher state) and the activity manager |
| 3304 | // (which holds locks while querying the application token). |
| 3305 | long inputDispatchingTimeoutNanos; |
| 3306 | try { |
| 3307 | inputDispatchingTimeoutNanos = token.getKeyDispatchingTimeout() * 1000000L; |
| 3308 | } catch (RemoteException ex) { |
| 3309 | Slog.w(TAG, "Could not get dispatching timeout.", ex); |
| 3310 | inputDispatchingTimeoutNanos = DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS; |
| 3311 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3312 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3313 | synchronized(mWindowMap) { |
| 3314 | AppWindowToken wtoken = findAppWindowToken(token.asBinder()); |
| 3315 | if (wtoken != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3316 | 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] | 3317 | return; |
| 3318 | } |
| 3319 | wtoken = new AppWindowToken(token); |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 3320 | wtoken.inputDispatchingTimeoutNanos = inputDispatchingTimeoutNanos; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3321 | wtoken.groupId = groupId; |
| 3322 | wtoken.appFullscreen = fullscreen; |
| 3323 | wtoken.requestedOrientation = requestedOrientation; |
| 3324 | mAppTokens.add(addPos, wtoken); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3325 | 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] | 3326 | mTokenMap.put(token.asBinder(), wtoken); |
| 3327 | mTokenList.add(wtoken); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3328 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3329 | // Application tokens start out hidden. |
| 3330 | wtoken.hidden = true; |
| 3331 | wtoken.hiddenRequested = true; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3332 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3333 | //dump(); |
| 3334 | } |
| 3335 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3336 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3337 | public void setAppGroupId(IBinder token, int groupId) { |
| 3338 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3339 | "setAppStartingIcon()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3340 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3341 | } |
| 3342 | |
| 3343 | synchronized(mWindowMap) { |
| 3344 | AppWindowToken wtoken = findAppWindowToken(token); |
| 3345 | if (wtoken == null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3346 | 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] | 3347 | return; |
| 3348 | } |
| 3349 | wtoken.groupId = groupId; |
| 3350 | } |
| 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 | public int getOrientationFromWindowsLocked() { |
| 3354 | int pos = mWindows.size() - 1; |
| 3355 | while (pos >= 0) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 3356 | WindowState wtoken = mWindows.get(pos); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3357 | pos--; |
| 3358 | if (wtoken.mAppToken != null) { |
| 3359 | // We hit an application window. so the orientation will be determined by the |
| 3360 | // app window. No point in continuing further. |
| 3361 | return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
| 3362 | } |
| Christopher Tate | b696aee | 2010-04-02 19:08:30 -0700 | [diff] [blame] | 3363 | if (!wtoken.isVisibleLw() || !wtoken.mPolicyVisibilityAfterAnim) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3364 | continue; |
| 3365 | } |
| 3366 | int req = wtoken.mAttrs.screenOrientation; |
| 3367 | if((req == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) || |
| 3368 | (req == ActivityInfo.SCREEN_ORIENTATION_BEHIND)){ |
| 3369 | continue; |
| 3370 | } else { |
| 3371 | return req; |
| 3372 | } |
| 3373 | } |
| 3374 | return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
| 3375 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3376 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3377 | public int getOrientationFromAppTokensLocked() { |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3378 | int pos = mAppTokens.size() - 1; |
| 3379 | int curGroup = 0; |
| 3380 | int lastOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
| 3381 | boolean findingBehind = false; |
| 3382 | boolean haveGroup = false; |
| 3383 | boolean lastFullscreen = false; |
| 3384 | while (pos >= 0) { |
| 3385 | AppWindowToken wtoken = mAppTokens.get(pos); |
| 3386 | pos--; |
| 3387 | // if we're about to tear down this window and not seek for |
| 3388 | // the behind activity, don't use it for orientation |
| 3389 | if (!findingBehind |
| 3390 | && (!wtoken.hidden && wtoken.hiddenRequested)) { |
| 3391 | continue; |
| 3392 | } |
| 3393 | |
| 3394 | if (!haveGroup) { |
| 3395 | // We ignore any hidden applications on the top. |
| 3396 | if (wtoken.hiddenRequested || wtoken.willBeHidden) { |
| The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3397 | continue; |
| 3398 | } |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3399 | haveGroup = true; |
| 3400 | curGroup = wtoken.groupId; |
| 3401 | lastOrientation = wtoken.requestedOrientation; |
| 3402 | } else if (curGroup != wtoken.groupId) { |
| 3403 | // If we have hit a new application group, and the bottom |
| 3404 | // of the previous group didn't explicitly say to use |
| 3405 | // the orientation behind it, and the last app was |
| 3406 | // full screen, then we'll stick with the |
| 3407 | // user's orientation. |
| 3408 | if (lastOrientation != ActivityInfo.SCREEN_ORIENTATION_BEHIND |
| 3409 | && lastFullscreen) { |
| 3410 | return lastOrientation; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3411 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3412 | } |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3413 | int or = wtoken.requestedOrientation; |
| 3414 | // If this application is fullscreen, and didn't explicitly say |
| 3415 | // to use the orientation behind it, then just take whatever |
| 3416 | // orientation it has and ignores whatever is under it. |
| 3417 | lastFullscreen = wtoken.appFullscreen; |
| 3418 | if (lastFullscreen |
| 3419 | && or != ActivityInfo.SCREEN_ORIENTATION_BEHIND) { |
| 3420 | return or; |
| 3421 | } |
| 3422 | // If this application has requested an explicit orientation, |
| 3423 | // then use it. |
| Dianne Hackborn | e5439f2 | 2010-10-02 16:53:50 -0700 | [diff] [blame] | 3424 | if (or != ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED |
| 3425 | && or != ActivityInfo.SCREEN_ORIENTATION_BEHIND) { |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3426 | return or; |
| 3427 | } |
| 3428 | findingBehind |= (or == ActivityInfo.SCREEN_ORIENTATION_BEHIND); |
| 3429 | } |
| 3430 | return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3431 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3432 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3433 | public Configuration updateOrientationFromAppTokens( |
| The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3434 | Configuration currentConfig, IBinder freezeThisOneIfNeeded) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3435 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3436 | "updateOrientationFromAppTokens()")) { |
| 3437 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| 3438 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3439 | |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3440 | Configuration config = null; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3441 | long ident = Binder.clearCallingIdentity(); |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3442 | |
| 3443 | synchronized(mWindowMap) { |
| 3444 | if (updateOrientationFromAppTokensLocked()) { |
| 3445 | if (freezeThisOneIfNeeded != null) { |
| 3446 | AppWindowToken wtoken = findAppWindowToken( |
| 3447 | freezeThisOneIfNeeded); |
| 3448 | if (wtoken != null) { |
| 3449 | startAppFreezingScreenLocked(wtoken, |
| 3450 | ActivityInfo.CONFIG_ORIENTATION); |
| 3451 | } |
| 3452 | } |
| 3453 | config = computeNewConfigurationLocked(); |
| 3454 | |
| 3455 | } else if (currentConfig != null) { |
| 3456 | // No obvious action we need to take, but if our current |
| Casey Burkhardt | 0920ba5 | 2010-08-03 12:04:19 -0700 | [diff] [blame] | 3457 | // state mismatches the activity manager's, update it, |
| 3458 | // disregarding font scale, which should remain set to |
| 3459 | // the value of the previous configuration. |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3460 | mTempConfiguration.setToDefaults(); |
| Casey Burkhardt | 0920ba5 | 2010-08-03 12:04:19 -0700 | [diff] [blame] | 3461 | mTempConfiguration.fontScale = currentConfig.fontScale; |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3462 | if (computeNewConfigurationLocked(mTempConfiguration)) { |
| 3463 | if (currentConfig.diff(mTempConfiguration) != 0) { |
| 3464 | mWaitingForConfig = true; |
| 3465 | mLayoutNeeded = true; |
| 3466 | startFreezingDisplayLocked(); |
| 3467 | config = new Configuration(mTempConfiguration); |
| 3468 | } |
| 3469 | } |
| 3470 | } |
| 3471 | } |
| 3472 | |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3473 | Binder.restoreCallingIdentity(ident); |
| 3474 | return config; |
| 3475 | } |
| 3476 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3477 | /* |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3478 | * Determine the new desired orientation of the display, returning |
| 3479 | * a non-null new Configuration if it has changed from the current |
| 3480 | * orientation. IF TRUE IS RETURNED SOMEONE MUST CALL |
| 3481 | * setNewConfiguration() TO TELL THE WINDOW MANAGER IT CAN UNFREEZE THE |
| 3482 | * SCREEN. This will typically be done for you if you call |
| 3483 | * sendNewConfiguration(). |
| 3484 | * |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3485 | * The orientation is computed from non-application windows first. If none of |
| 3486 | * the non-application windows specify orientation, the orientation is computed from |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3487 | * application tokens. |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3488 | * @see android.view.IWindowManager#updateOrientationFromAppTokens( |
| 3489 | * android.os.IBinder) |
| 3490 | */ |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3491 | boolean updateOrientationFromAppTokensLocked() { |
| Christopher Tate | b696aee | 2010-04-02 19:08:30 -0700 | [diff] [blame] | 3492 | if (mDisplayFrozen) { |
| 3493 | // If the display is frozen, some activities may be in the middle |
| 3494 | // of restarting, and thus have removed their old window. If the |
| 3495 | // window has the flag to hide the lock screen, then the lock screen |
| 3496 | // can re-appear and inflict its own orientation on us. Keep the |
| 3497 | // orientation stable until this all settles down. |
| 3498 | return false; |
| 3499 | } |
| 3500 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3501 | boolean changed = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3502 | long ident = Binder.clearCallingIdentity(); |
| 3503 | try { |
| The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 3504 | int req = computeForcedAppOrientationLocked(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3505 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3506 | if (req != mForcedAppOrientation) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3507 | mForcedAppOrientation = req; |
| 3508 | //send a message to Policy indicating orientation change to take |
| 3509 | //action like disabling/enabling sensors etc., |
| The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 3510 | mPolicy.setCurrentOrientationLw(req); |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3511 | if (setRotationUncheckedLocked(WindowManagerPolicy.USE_LAST_ROTATION, |
| 3512 | mLastRotationFlags | Surface.FLAGS_ORIENTATION_ANIMATION_DISABLE)) { |
| 3513 | changed = true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3514 | } |
| 3515 | } |
| The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3516 | |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3517 | return changed; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3518 | } finally { |
| 3519 | Binder.restoreCallingIdentity(ident); |
| 3520 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3521 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3522 | |
| The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 3523 | int computeForcedAppOrientationLocked() { |
| 3524 | int req = getOrientationFromWindowsLocked(); |
| 3525 | if (req == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) { |
| 3526 | req = getOrientationFromAppTokensLocked(); |
| 3527 | } |
| 3528 | return req; |
| 3529 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3530 | |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3531 | public void setNewConfiguration(Configuration config) { |
| 3532 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3533 | "setNewConfiguration()")) { |
| 3534 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| 3535 | } |
| 3536 | |
| 3537 | synchronized(mWindowMap) { |
| 3538 | mCurConfiguration = new Configuration(config); |
| 3539 | mWaitingForConfig = false; |
| 3540 | performLayoutAndPlaceSurfacesLocked(); |
| 3541 | } |
| 3542 | } |
| 3543 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3544 | public void setAppOrientation(IApplicationToken token, int requestedOrientation) { |
| 3545 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3546 | "setAppOrientation()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3547 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3548 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3549 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3550 | synchronized(mWindowMap) { |
| 3551 | AppWindowToken wtoken = findAppWindowToken(token.asBinder()); |
| 3552 | if (wtoken == null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3553 | 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] | 3554 | return; |
| 3555 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3556 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3557 | wtoken.requestedOrientation = requestedOrientation; |
| 3558 | } |
| 3559 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3560 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3561 | public int getAppOrientation(IApplicationToken token) { |
| 3562 | synchronized(mWindowMap) { |
| 3563 | AppWindowToken wtoken = findAppWindowToken(token.asBinder()); |
| 3564 | if (wtoken == null) { |
| 3565 | return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
| 3566 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3567 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3568 | return wtoken.requestedOrientation; |
| 3569 | } |
| 3570 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3571 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3572 | public void setFocusedApp(IBinder token, boolean moveFocusNow) { |
| 3573 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3574 | "setFocusedApp()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3575 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3576 | } |
| 3577 | |
| 3578 | synchronized(mWindowMap) { |
| 3579 | boolean changed = false; |
| 3580 | if (token == null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3581 | 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] | 3582 | changed = mFocusedApp != null; |
| 3583 | mFocusedApp = null; |
| Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 3584 | if (changed) { |
| 3585 | mInputMonitor.setFocusedAppLw(null); |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 3586 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3587 | } else { |
| 3588 | AppWindowToken newFocus = findAppWindowToken(token); |
| 3589 | if (newFocus == null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3590 | 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] | 3591 | return; |
| 3592 | } |
| 3593 | changed = mFocusedApp != newFocus; |
| 3594 | mFocusedApp = newFocus; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3595 | if (DEBUG_FOCUS) Slog.v(TAG, "Set focused app to: " + mFocusedApp); |
| Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 3596 | if (changed) { |
| 3597 | mInputMonitor.setFocusedAppLw(newFocus); |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 3598 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3599 | } |
| 3600 | |
| 3601 | if (moveFocusNow && changed) { |
| 3602 | final long origId = Binder.clearCallingIdentity(); |
| 3603 | updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL); |
| 3604 | Binder.restoreCallingIdentity(origId); |
| 3605 | } |
| 3606 | } |
| 3607 | } |
| 3608 | |
| 3609 | public void prepareAppTransition(int transit) { |
| 3610 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3611 | "prepareAppTransition()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3612 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3613 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3614 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3615 | synchronized(mWindowMap) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3616 | if (DEBUG_APP_TRANSITIONS) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3617 | TAG, "Prepare app transition: transit=" + transit |
| 3618 | + " mNextAppTransition=" + mNextAppTransition); |
| Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 3619 | if (!mDisplayFrozen && mPolicy.isScreenOn()) { |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 3620 | if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET |
| 3621 | || mNextAppTransition == WindowManagerPolicy.TRANSIT_NONE) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3622 | mNextAppTransition = transit; |
| Dianne Hackborn | d7cd29d | 2009-07-01 11:22:45 -0700 | [diff] [blame] | 3623 | } else if (transit == WindowManagerPolicy.TRANSIT_TASK_OPEN |
| 3624 | && mNextAppTransition == WindowManagerPolicy.TRANSIT_TASK_CLOSE) { |
| 3625 | // Opening a new task always supersedes a close for the anim. |
| 3626 | mNextAppTransition = transit; |
| 3627 | } else if (transit == WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN |
| 3628 | && mNextAppTransition == WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE) { |
| 3629 | // Opening a new activity always supersedes a close for the anim. |
| 3630 | mNextAppTransition = transit; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3631 | } |
| 3632 | mAppTransitionReady = false; |
| 3633 | mAppTransitionTimeout = false; |
| 3634 | mStartingIconInTransition = false; |
| 3635 | mSkipAppTransitionAnimation = false; |
| 3636 | mH.removeMessages(H.APP_TRANSITION_TIMEOUT); |
| 3637 | mH.sendMessageDelayed(mH.obtainMessage(H.APP_TRANSITION_TIMEOUT), |
| 3638 | 5000); |
| 3639 | } |
| 3640 | } |
| 3641 | } |
| 3642 | |
| 3643 | public int getPendingAppTransition() { |
| 3644 | return mNextAppTransition; |
| 3645 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3646 | |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 3647 | public void overridePendingAppTransition(String packageName, |
| 3648 | int enterAnim, int exitAnim) { |
| Dianne Hackborn | 8b571a8 | 2009-09-25 16:09:43 -0700 | [diff] [blame] | 3649 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 3650 | mNextAppTransitionPackage = packageName; |
| 3651 | mNextAppTransitionEnter = enterAnim; |
| 3652 | mNextAppTransitionExit = exitAnim; |
| 3653 | } |
| 3654 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3655 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3656 | public void executeAppTransition() { |
| 3657 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3658 | "executeAppTransition()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3659 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3660 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3661 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3662 | synchronized(mWindowMap) { |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 3663 | if (DEBUG_APP_TRANSITIONS) { |
| 3664 | RuntimeException e = new RuntimeException("here"); |
| 3665 | e.fillInStackTrace(); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3666 | Slog.w(TAG, "Execute app transition: mNextAppTransition=" |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 3667 | + mNextAppTransition, e); |
| 3668 | } |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 3669 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3670 | mAppTransitionReady = true; |
| 3671 | final long origId = Binder.clearCallingIdentity(); |
| 3672 | performLayoutAndPlaceSurfacesLocked(); |
| 3673 | Binder.restoreCallingIdentity(origId); |
| 3674 | } |
| 3675 | } |
| 3676 | } |
| 3677 | |
| 3678 | public void setAppStartingWindow(IBinder token, String pkg, |
| 3679 | int theme, CharSequence nonLocalizedLabel, int labelRes, int icon, |
| 3680 | IBinder transferFrom, boolean createIfNeeded) { |
| 3681 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3682 | "setAppStartingIcon()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3683 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3684 | } |
| 3685 | |
| 3686 | synchronized(mWindowMap) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3687 | if (DEBUG_STARTING_WINDOW) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3688 | TAG, "setAppStartingIcon: token=" + token + " pkg=" + pkg |
| 3689 | + " transferFrom=" + transferFrom); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3690 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3691 | AppWindowToken wtoken = findAppWindowToken(token); |
| 3692 | if (wtoken == null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3693 | 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] | 3694 | return; |
| 3695 | } |
| 3696 | |
| 3697 | // If the display is frozen, we won't do anything until the |
| 3698 | // actual window is displayed so there is no reason to put in |
| 3699 | // the starting window. |
| Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 3700 | if (mDisplayFrozen || !mPolicy.isScreenOn()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3701 | return; |
| 3702 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3703 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3704 | if (wtoken.startingData != null) { |
| 3705 | return; |
| 3706 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3707 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3708 | if (transferFrom != null) { |
| 3709 | AppWindowToken ttoken = findAppWindowToken(transferFrom); |
| 3710 | if (ttoken != null) { |
| 3711 | WindowState startingWindow = ttoken.startingWindow; |
| 3712 | if (startingWindow != null) { |
| 3713 | if (mStartingIconInTransition) { |
| 3714 | // In this case, the starting icon has already |
| 3715 | // been displayed, so start letting windows get |
| 3716 | // shown immediately without any more transitions. |
| 3717 | mSkipAppTransitionAnimation = true; |
| 3718 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3719 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3720 | "Moving existing starting from " + ttoken |
| 3721 | + " to " + wtoken); |
| 3722 | final long origId = Binder.clearCallingIdentity(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3723 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3724 | // Transfer the starting window over to the new |
| 3725 | // token. |
| 3726 | wtoken.startingData = ttoken.startingData; |
| 3727 | wtoken.startingView = ttoken.startingView; |
| 3728 | wtoken.startingWindow = startingWindow; |
| 3729 | ttoken.startingData = null; |
| 3730 | ttoken.startingView = null; |
| 3731 | ttoken.startingWindow = null; |
| 3732 | ttoken.startingMoved = true; |
| 3733 | startingWindow.mToken = wtoken; |
| Dianne Hackborn | ef49c57 | 2009-03-24 19:27:32 -0700 | [diff] [blame] | 3734 | startingWindow.mRootToken = wtoken; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3735 | startingWindow.mAppToken = wtoken; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3736 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 3737 | "Removing starting window: " + startingWindow); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3738 | mWindows.remove(startingWindow); |
| Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 3739 | mWindowsChanged = true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3740 | ttoken.windows.remove(startingWindow); |
| 3741 | ttoken.allAppWindows.remove(startingWindow); |
| 3742 | addWindowToListInOrderLocked(startingWindow, true); |
| 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 | // Propagate other interesting state between the |
| 3745 | // tokens. If the old token is displayed, we should |
| 3746 | // immediately force the new one to be displayed. If |
| 3747 | // it is animating, we need to move that animation to |
| 3748 | // the new one. |
| 3749 | if (ttoken.allDrawn) { |
| 3750 | wtoken.allDrawn = true; |
| 3751 | } |
| 3752 | if (ttoken.firstWindowDrawn) { |
| 3753 | wtoken.firstWindowDrawn = true; |
| 3754 | } |
| 3755 | if (!ttoken.hidden) { |
| 3756 | wtoken.hidden = false; |
| 3757 | wtoken.hiddenRequested = false; |
| 3758 | wtoken.willBeHidden = false; |
| 3759 | } |
| 3760 | if (wtoken.clientHidden != ttoken.clientHidden) { |
| 3761 | wtoken.clientHidden = ttoken.clientHidden; |
| 3762 | wtoken.sendAppVisibilityToClients(); |
| 3763 | } |
| 3764 | if (ttoken.animation != null) { |
| 3765 | wtoken.animation = ttoken.animation; |
| 3766 | wtoken.animating = ttoken.animating; |
| 3767 | wtoken.animLayerAdjustment = ttoken.animLayerAdjustment; |
| 3768 | ttoken.animation = null; |
| 3769 | ttoken.animLayerAdjustment = 0; |
| 3770 | wtoken.updateLayers(); |
| 3771 | ttoken.updateLayers(); |
| 3772 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3773 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3774 | updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3775 | mLayoutNeeded = true; |
| 3776 | performLayoutAndPlaceSurfacesLocked(); |
| 3777 | Binder.restoreCallingIdentity(origId); |
| 3778 | return; |
| 3779 | } else if (ttoken.startingData != null) { |
| 3780 | // The previous app was getting ready to show a |
| 3781 | // starting window, but hasn't yet done so. Steal it! |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3782 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3783 | "Moving pending starting from " + ttoken |
| 3784 | + " to " + wtoken); |
| 3785 | wtoken.startingData = ttoken.startingData; |
| 3786 | ttoken.startingData = null; |
| 3787 | ttoken.startingMoved = true; |
| 3788 | Message m = mH.obtainMessage(H.ADD_STARTING, wtoken); |
| 3789 | // Note: we really want to do sendMessageAtFrontOfQueue() because we |
| 3790 | // want to process the message ASAP, before any other queued |
| 3791 | // messages. |
| 3792 | mH.sendMessageAtFrontOfQueue(m); |
| 3793 | return; |
| 3794 | } |
| 3795 | } |
| 3796 | } |
| 3797 | |
| 3798 | // There is no existing starting window, and the caller doesn't |
| 3799 | // want us to create one, so that's it! |
| 3800 | if (!createIfNeeded) { |
| 3801 | return; |
| 3802 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3803 | |
| Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 3804 | // If this is a translucent or wallpaper window, then don't |
| 3805 | // show a starting window -- the current effect (a full-screen |
| 3806 | // opaque starting window that fades away to the real contents |
| 3807 | // when it is ready) does not work for this. |
| 3808 | if (theme != 0) { |
| 3809 | AttributeCache.Entry ent = AttributeCache.instance().get(pkg, theme, |
| 3810 | com.android.internal.R.styleable.Window); |
| 3811 | if (ent.array.getBoolean( |
| 3812 | com.android.internal.R.styleable.Window_windowIsTranslucent, false)) { |
| 3813 | return; |
| 3814 | } |
| 3815 | if (ent.array.getBoolean( |
| Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 3816 | com.android.internal.R.styleable.Window_windowIsFloating, false)) { |
| 3817 | return; |
| 3818 | } |
| 3819 | if (ent.array.getBoolean( |
| Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 3820 | com.android.internal.R.styleable.Window_windowShowWallpaper, false)) { |
| 3821 | return; |
| 3822 | } |
| 3823 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3824 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3825 | mStartingIconInTransition = true; |
| 3826 | wtoken.startingData = new StartingData( |
| 3827 | pkg, theme, nonLocalizedLabel, |
| 3828 | labelRes, icon); |
| 3829 | Message m = mH.obtainMessage(H.ADD_STARTING, wtoken); |
| 3830 | // Note: we really want to do sendMessageAtFrontOfQueue() because we |
| 3831 | // want to process the message ASAP, before any other queued |
| 3832 | // messages. |
| 3833 | mH.sendMessageAtFrontOfQueue(m); |
| 3834 | } |
| 3835 | } |
| 3836 | |
| 3837 | public void setAppWillBeHidden(IBinder token) { |
| 3838 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3839 | "setAppWillBeHidden()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3840 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3841 | } |
| 3842 | |
| 3843 | AppWindowToken wtoken; |
| 3844 | |
| 3845 | synchronized(mWindowMap) { |
| 3846 | wtoken = findAppWindowToken(token); |
| 3847 | if (wtoken == null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3848 | 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] | 3849 | return; |
| 3850 | } |
| 3851 | wtoken.willBeHidden = true; |
| 3852 | } |
| 3853 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3854 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3855 | boolean setTokenVisibilityLocked(AppWindowToken wtoken, WindowManager.LayoutParams lp, |
| 3856 | boolean visible, int transit, boolean performLayout) { |
| 3857 | boolean delayed = false; |
| 3858 | |
| 3859 | if (wtoken.clientHidden == visible) { |
| 3860 | wtoken.clientHidden = !visible; |
| 3861 | wtoken.sendAppVisibilityToClients(); |
| 3862 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3863 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3864 | wtoken.willBeHidden = false; |
| 3865 | if (wtoken.hidden == visible) { |
| 3866 | final int N = wtoken.allAppWindows.size(); |
| 3867 | boolean changed = false; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3868 | if (DEBUG_APP_TRANSITIONS) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3869 | TAG, "Changing app " + wtoken + " hidden=" + wtoken.hidden |
| 3870 | + " performLayout=" + performLayout); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3871 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3872 | boolean runningAppAnimation = false; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3873 | |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 3874 | if (transit != WindowManagerPolicy.TRANSIT_UNSET) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3875 | if (wtoken.animation == sDummyAnimation) { |
| 3876 | wtoken.animation = null; |
| 3877 | } |
| 3878 | applyAnimationLocked(wtoken, lp, transit, visible); |
| 3879 | changed = true; |
| 3880 | if (wtoken.animation != null) { |
| 3881 | delayed = runningAppAnimation = true; |
| 3882 | } |
| 3883 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3884 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3885 | for (int i=0; i<N; i++) { |
| 3886 | WindowState win = wtoken.allAppWindows.get(i); |
| 3887 | if (win == wtoken.startingWindow) { |
| 3888 | continue; |
| 3889 | } |
| 3890 | |
| 3891 | if (win.isAnimating()) { |
| 3892 | delayed = true; |
| 3893 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3894 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3895 | //Slog.i(TAG, "Window " + win + ": vis=" + win.isVisible()); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3896 | //win.dump(" "); |
| 3897 | if (visible) { |
| 3898 | if (!win.isVisibleNow()) { |
| 3899 | if (!runningAppAnimation) { |
| 3900 | applyAnimationLocked(win, |
| 3901 | WindowManagerPolicy.TRANSIT_ENTER, true); |
| 3902 | } |
| 3903 | changed = true; |
| 3904 | } |
| 3905 | } else if (win.isVisibleNow()) { |
| 3906 | if (!runningAppAnimation) { |
| 3907 | applyAnimationLocked(win, |
| 3908 | WindowManagerPolicy.TRANSIT_EXIT, false); |
| 3909 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3910 | changed = true; |
| 3911 | } |
| 3912 | } |
| 3913 | |
| 3914 | wtoken.hidden = wtoken.hiddenRequested = !visible; |
| 3915 | if (!visible) { |
| 3916 | unsetAppFreezingScreenLocked(wtoken, true, true); |
| 3917 | } else { |
| 3918 | // If we are being set visible, and the starting window is |
| 3919 | // not yet displayed, then make sure it doesn't get displayed. |
| 3920 | WindowState swin = wtoken.startingWindow; |
| 3921 | if (swin != null && (swin.mDrawPending |
| 3922 | || swin.mCommitDrawPending)) { |
| 3923 | swin.mPolicyVisibility = false; |
| 3924 | swin.mPolicyVisibilityAfterAnim = false; |
| 3925 | } |
| 3926 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3927 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3928 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "setTokenVisibilityLocked: " + wtoken |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3929 | + ": hidden=" + wtoken.hidden + " hiddenRequested=" |
| 3930 | + wtoken.hiddenRequested); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3931 | |
| Dianne Hackborn | 9b52a21 | 2009-12-11 14:51:35 -0800 | [diff] [blame] | 3932 | if (changed) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3933 | mLayoutNeeded = true; |
| Dianne Hackborn | 9b52a21 | 2009-12-11 14:51:35 -0800 | [diff] [blame] | 3934 | if (performLayout) { |
| 3935 | updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES); |
| 3936 | performLayoutAndPlaceSurfacesLocked(); |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 3937 | } else { |
| 3938 | mInputMonitor.updateInputWindowsLw(); |
| Dianne Hackborn | 9b52a21 | 2009-12-11 14:51:35 -0800 | [diff] [blame] | 3939 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3940 | } |
| 3941 | } |
| 3942 | |
| 3943 | if (wtoken.animation != null) { |
| 3944 | delayed = true; |
| 3945 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3946 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3947 | return delayed; |
| 3948 | } |
| 3949 | |
| 3950 | public void setAppVisibility(IBinder token, boolean visible) { |
| 3951 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3952 | "setAppVisibility()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3953 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3954 | } |
| 3955 | |
| 3956 | AppWindowToken wtoken; |
| 3957 | |
| 3958 | synchronized(mWindowMap) { |
| 3959 | wtoken = findAppWindowToken(token); |
| 3960 | if (wtoken == null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3961 | 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] | 3962 | return; |
| 3963 | } |
| 3964 | |
| 3965 | if (DEBUG_APP_TRANSITIONS || DEBUG_ORIENTATION) { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 3966 | RuntimeException e = null; |
| 3967 | if (!HIDE_STACK_CRAWLS) { |
| 3968 | e = new RuntimeException(); |
| 3969 | e.fillInStackTrace(); |
| 3970 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3971 | Slog.v(TAG, "setAppVisibility(" + token + ", " + visible |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3972 | + "): mNextAppTransition=" + mNextAppTransition |
| 3973 | + " hidden=" + wtoken.hidden |
| 3974 | + " hiddenRequested=" + wtoken.hiddenRequested, e); |
| 3975 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3976 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3977 | // If we are preparing an app transition, then delay changing |
| 3978 | // the visibility of this token until we execute that transition. |
| Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 3979 | if (!mDisplayFrozen && mPolicy.isScreenOn() |
| 3980 | && mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3981 | // Already in requested state, don't do anything more. |
| 3982 | if (wtoken.hiddenRequested != visible) { |
| 3983 | return; |
| 3984 | } |
| 3985 | wtoken.hiddenRequested = !visible; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3986 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3987 | if (DEBUG_APP_TRANSITIONS) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3988 | TAG, "Setting dummy animation on: " + wtoken); |
| 3989 | wtoken.setDummyAnimation(); |
| 3990 | mOpeningApps.remove(wtoken); |
| 3991 | mClosingApps.remove(wtoken); |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 3992 | wtoken.waitingToShow = wtoken.waitingToHide = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3993 | wtoken.inPendingTransaction = true; |
| 3994 | if (visible) { |
| 3995 | mOpeningApps.add(wtoken); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3996 | wtoken.startingDisplayed = false; |
| 3997 | wtoken.startingMoved = false; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3998 | |
| Dianne Hackborn | 195f6a0 | 2009-11-24 11:26:00 -0800 | [diff] [blame] | 3999 | // If the token is currently hidden (should be the |
| 4000 | // common case), then we need to set up to wait for |
| 4001 | // its windows to be ready. |
| 4002 | if (wtoken.hidden) { |
| 4003 | wtoken.allDrawn = false; |
| 4004 | wtoken.waitingToShow = true; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 4005 | |
| Dianne Hackborn | 195f6a0 | 2009-11-24 11:26:00 -0800 | [diff] [blame] | 4006 | if (wtoken.clientHidden) { |
| 4007 | // In the case where we are making an app visible |
| 4008 | // but holding off for a transition, we still need |
| 4009 | // to tell the client to make its windows visible so |
| 4010 | // they get drawn. Otherwise, we will wait on |
| 4011 | // performing the transition until all windows have |
| 4012 | // been drawn, they never will be, and we are sad. |
| 4013 | wtoken.clientHidden = false; |
| 4014 | wtoken.sendAppVisibilityToClients(); |
| 4015 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4016 | } |
| 4017 | } else { |
| 4018 | mClosingApps.add(wtoken); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 4019 | |
| Dianne Hackborn | 195f6a0 | 2009-11-24 11:26:00 -0800 | [diff] [blame] | 4020 | // If the token is currently visible (should be the |
| 4021 | // common case), then set up to wait for it to be hidden. |
| 4022 | if (!wtoken.hidden) { |
| 4023 | wtoken.waitingToHide = true; |
| 4024 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4025 | } |
| 4026 | return; |
| 4027 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4028 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4029 | final long origId = Binder.clearCallingIdentity(); |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 4030 | setTokenVisibilityLocked(wtoken, null, visible, WindowManagerPolicy.TRANSIT_UNSET, true); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4031 | wtoken.updateReportedVisibilityLocked(); |
| 4032 | Binder.restoreCallingIdentity(origId); |
| 4033 | } |
| 4034 | } |
| 4035 | |
| 4036 | void unsetAppFreezingScreenLocked(AppWindowToken wtoken, |
| 4037 | boolean unfreezeSurfaceNow, boolean force) { |
| 4038 | if (wtoken.freezingScreen) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4039 | 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] | 4040 | + " force=" + force); |
| 4041 | final int N = wtoken.allAppWindows.size(); |
| 4042 | boolean unfrozeWindows = false; |
| 4043 | for (int i=0; i<N; i++) { |
| 4044 | WindowState w = wtoken.allAppWindows.get(i); |
| 4045 | if (w.mAppFreezing) { |
| 4046 | w.mAppFreezing = false; |
| 4047 | if (w.mSurface != null && !w.mOrientationChanging) { |
| 4048 | w.mOrientationChanging = true; |
| 4049 | } |
| 4050 | unfrozeWindows = true; |
| 4051 | } |
| 4052 | } |
| 4053 | if (force || unfrozeWindows) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4054 | 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] | 4055 | wtoken.freezingScreen = false; |
| 4056 | mAppsFreezingScreen--; |
| 4057 | } |
| 4058 | if (unfreezeSurfaceNow) { |
| 4059 | if (unfrozeWindows) { |
| 4060 | mLayoutNeeded = true; |
| 4061 | performLayoutAndPlaceSurfacesLocked(); |
| 4062 | } |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 4063 | stopFreezingDisplayLocked(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4064 | } |
| 4065 | } |
| 4066 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4067 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4068 | public void startAppFreezingScreenLocked(AppWindowToken wtoken, |
| 4069 | int configChanges) { |
| 4070 | if (DEBUG_ORIENTATION) { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 4071 | RuntimeException e = null; |
| 4072 | if (!HIDE_STACK_CRAWLS) { |
| 4073 | e = new RuntimeException(); |
| 4074 | e.fillInStackTrace(); |
| 4075 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4076 | Slog.i(TAG, "Set freezing of " + wtoken.appToken |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4077 | + ": hidden=" + wtoken.hidden + " freezing=" |
| 4078 | + wtoken.freezingScreen, e); |
| 4079 | } |
| 4080 | if (!wtoken.hiddenRequested) { |
| 4081 | if (!wtoken.freezingScreen) { |
| 4082 | wtoken.freezingScreen = true; |
| 4083 | mAppsFreezingScreen++; |
| 4084 | if (mAppsFreezingScreen == 1) { |
| 4085 | startFreezingDisplayLocked(); |
| 4086 | mH.removeMessages(H.APP_FREEZE_TIMEOUT); |
| 4087 | mH.sendMessageDelayed(mH.obtainMessage(H.APP_FREEZE_TIMEOUT), |
| 4088 | 5000); |
| 4089 | } |
| 4090 | } |
| 4091 | final int N = wtoken.allAppWindows.size(); |
| 4092 | for (int i=0; i<N; i++) { |
| 4093 | WindowState w = wtoken.allAppWindows.get(i); |
| 4094 | w.mAppFreezing = true; |
| 4095 | } |
| 4096 | } |
| 4097 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4098 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4099 | public void startAppFreezingScreen(IBinder token, int configChanges) { |
| 4100 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 4101 | "setAppFreezingScreen()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4102 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4103 | } |
| 4104 | |
| 4105 | synchronized(mWindowMap) { |
| Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 4106 | if (configChanges == 0 && !mDisplayFrozen && mPolicy.isScreenOn()) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4107 | 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] | 4108 | return; |
| 4109 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4110 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4111 | AppWindowToken wtoken = findAppWindowToken(token); |
| 4112 | if (wtoken == null || wtoken.appToken == null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4113 | 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] | 4114 | return; |
| 4115 | } |
| 4116 | final long origId = Binder.clearCallingIdentity(); |
| 4117 | startAppFreezingScreenLocked(wtoken, configChanges); |
| 4118 | Binder.restoreCallingIdentity(origId); |
| 4119 | } |
| 4120 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4121 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4122 | public void stopAppFreezingScreen(IBinder token, boolean force) { |
| 4123 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 4124 | "setAppFreezingScreen()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4125 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4126 | } |
| 4127 | |
| 4128 | synchronized(mWindowMap) { |
| 4129 | AppWindowToken wtoken = findAppWindowToken(token); |
| 4130 | if (wtoken == null || wtoken.appToken == null) { |
| 4131 | return; |
| 4132 | } |
| 4133 | final long origId = Binder.clearCallingIdentity(); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4134 | 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] | 4135 | + ": hidden=" + wtoken.hidden + " freezing=" + wtoken.freezingScreen); |
| 4136 | unsetAppFreezingScreenLocked(wtoken, true, force); |
| 4137 | Binder.restoreCallingIdentity(origId); |
| 4138 | } |
| 4139 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4140 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4141 | public void removeAppToken(IBinder token) { |
| 4142 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 4143 | "removeAppToken()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4144 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4145 | } |
| 4146 | |
| 4147 | AppWindowToken wtoken = null; |
| 4148 | AppWindowToken startingToken = null; |
| 4149 | boolean delayed = false; |
| 4150 | |
| 4151 | final long origId = Binder.clearCallingIdentity(); |
| 4152 | synchronized(mWindowMap) { |
| 4153 | WindowToken basewtoken = mTokenMap.remove(token); |
| 4154 | mTokenList.remove(basewtoken); |
| 4155 | if (basewtoken != null && (wtoken=basewtoken.appWindowToken) != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4156 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "Removing app token: " + wtoken); |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 4157 | delayed = setTokenVisibilityLocked(wtoken, null, false, WindowManagerPolicy.TRANSIT_UNSET, true); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4158 | wtoken.inPendingTransaction = false; |
| 4159 | mOpeningApps.remove(wtoken); |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4160 | wtoken.waitingToShow = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4161 | if (mClosingApps.contains(wtoken)) { |
| 4162 | delayed = true; |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 4163 | } else if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4164 | mClosingApps.add(wtoken); |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4165 | wtoken.waitingToHide = true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4166 | delayed = true; |
| 4167 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4168 | if (DEBUG_APP_TRANSITIONS) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4169 | TAG, "Removing app " + wtoken + " delayed=" + delayed |
| 4170 | + " animation=" + wtoken.animation |
| 4171 | + " animating=" + wtoken.animating); |
| 4172 | if (delayed) { |
| 4173 | // set the token aside because it has an active animation to be finished |
| 4174 | mExitingAppTokens.add(wtoken); |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 4175 | } else { |
| 4176 | // Make sure there is no animation running on this token, |
| 4177 | // so any windows associated with it will be removed as |
| 4178 | // soon as their animations are complete |
| 4179 | wtoken.animation = null; |
| 4180 | wtoken.animating = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4181 | } |
| 4182 | mAppTokens.remove(wtoken); |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 4183 | if (mLastEnterAnimToken == wtoken) { |
| 4184 | mLastEnterAnimToken = null; |
| 4185 | mLastEnterAnimParams = null; |
| 4186 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4187 | wtoken.removed = true; |
| 4188 | if (wtoken.startingData != null) { |
| 4189 | startingToken = wtoken; |
| 4190 | } |
| 4191 | unsetAppFreezingScreenLocked(wtoken, true, true); |
| 4192 | if (mFocusedApp == wtoken) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4193 | 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] | 4194 | mFocusedApp = null; |
| 4195 | updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL); |
| Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 4196 | mInputMonitor.setFocusedAppLw(null); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4197 | } |
| 4198 | } else { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4199 | 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] | 4200 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4201 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4202 | if (!delayed && wtoken != null) { |
| 4203 | wtoken.updateReportedVisibilityLocked(); |
| 4204 | } |
| 4205 | } |
| 4206 | Binder.restoreCallingIdentity(origId); |
| 4207 | |
| 4208 | if (startingToken != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4209 | 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] | 4210 | + startingToken + ": app token removed"); |
| 4211 | Message m = mH.obtainMessage(H.REMOVE_STARTING, startingToken); |
| 4212 | mH.sendMessage(m); |
| 4213 | } |
| 4214 | } |
| 4215 | |
| 4216 | private boolean tmpRemoveAppWindowsLocked(WindowToken token) { |
| 4217 | final int NW = token.windows.size(); |
| 4218 | for (int i=0; i<NW; i++) { |
| 4219 | WindowState win = token.windows.get(i); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4220 | 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] | 4221 | mWindows.remove(win); |
| Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 4222 | mWindowsChanged = true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4223 | int j = win.mChildWindows.size(); |
| 4224 | while (j > 0) { |
| 4225 | j--; |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 4226 | WindowState cwin = win.mChildWindows.get(j); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4227 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, |
| Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 4228 | "Tmp removing child window " + cwin); |
| 4229 | mWindows.remove(cwin); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4230 | } |
| 4231 | } |
| 4232 | return NW > 0; |
| 4233 | } |
| 4234 | |
| 4235 | void dumpAppTokensLocked() { |
| 4236 | for (int i=mAppTokens.size()-1; i>=0; i--) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4237 | Slog.v(TAG, " #" + i + ": " + mAppTokens.get(i).token); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4238 | } |
| 4239 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4240 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4241 | void dumpWindowsLocked() { |
| 4242 | for (int i=mWindows.size()-1; i>=0; i--) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4243 | Slog.v(TAG, " #" + i + ": " + mWindows.get(i)); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4244 | } |
| 4245 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4246 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4247 | private int findWindowOffsetLocked(int tokenPos) { |
| 4248 | final int NW = mWindows.size(); |
| 4249 | |
| 4250 | if (tokenPos >= mAppTokens.size()) { |
| 4251 | int i = NW; |
| 4252 | while (i > 0) { |
| 4253 | i--; |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 4254 | WindowState win = mWindows.get(i); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4255 | if (win.getAppToken() != null) { |
| 4256 | return i+1; |
| 4257 | } |
| 4258 | } |
| 4259 | } |
| 4260 | |
| 4261 | while (tokenPos > 0) { |
| 4262 | // Find the first app token below the new position that has |
| 4263 | // a window displayed. |
| 4264 | final AppWindowToken wtoken = mAppTokens.get(tokenPos-1); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4265 | 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] | 4266 | + tokenPos + " -- " + wtoken.token); |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4267 | if (wtoken.sendingToBottom) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4268 | if (DEBUG_REORDER) Slog.v(TAG, |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4269 | "Skipping token -- currently sending to bottom"); |
| 4270 | tokenPos--; |
| 4271 | continue; |
| 4272 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4273 | int i = wtoken.windows.size(); |
| 4274 | while (i > 0) { |
| 4275 | i--; |
| 4276 | WindowState win = wtoken.windows.get(i); |
| 4277 | int j = win.mChildWindows.size(); |
| 4278 | while (j > 0) { |
| 4279 | j--; |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 4280 | WindowState cwin = win.mChildWindows.get(j); |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4281 | if (cwin.mSubLayer >= 0) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4282 | for (int pos=NW-1; pos>=0; pos--) { |
| 4283 | if (mWindows.get(pos) == cwin) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4284 | if (DEBUG_REORDER) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4285 | "Found child win @" + (pos+1)); |
| 4286 | return pos+1; |
| 4287 | } |
| 4288 | } |
| 4289 | } |
| 4290 | } |
| 4291 | for (int pos=NW-1; pos>=0; pos--) { |
| 4292 | if (mWindows.get(pos) == win) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4293 | 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] | 4294 | return pos+1; |
| 4295 | } |
| 4296 | } |
| 4297 | } |
| 4298 | tokenPos--; |
| 4299 | } |
| 4300 | |
| 4301 | return 0; |
| 4302 | } |
| 4303 | |
| 4304 | private final int reAddWindowLocked(int index, WindowState win) { |
| 4305 | final int NCW = win.mChildWindows.size(); |
| 4306 | boolean added = false; |
| 4307 | for (int j=0; j<NCW; j++) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 4308 | WindowState cwin = win.mChildWindows.get(j); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4309 | if (!added && cwin.mSubLayer >= 0) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4310 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding child window at " |
| Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 4311 | + index + ": " + cwin); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4312 | mWindows.add(index, win); |
| 4313 | index++; |
| 4314 | added = true; |
| 4315 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4316 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding window at " |
| Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 4317 | + index + ": " + cwin); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4318 | mWindows.add(index, cwin); |
| 4319 | index++; |
| 4320 | } |
| 4321 | if (!added) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4322 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding window at " |
| Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 4323 | + index + ": " + win); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4324 | mWindows.add(index, win); |
| 4325 | index++; |
| 4326 | } |
| Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 4327 | mWindowsChanged = true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4328 | return index; |
| 4329 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4330 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4331 | private final int reAddAppWindowsLocked(int index, WindowToken token) { |
| 4332 | final int NW = token.windows.size(); |
| 4333 | for (int i=0; i<NW; i++) { |
| 4334 | index = reAddWindowLocked(index, token.windows.get(i)); |
| 4335 | } |
| 4336 | return index; |
| 4337 | } |
| 4338 | |
| 4339 | public void moveAppToken(int index, IBinder token) { |
| 4340 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 4341 | "moveAppToken()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4342 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4343 | } |
| 4344 | |
| 4345 | synchronized(mWindowMap) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4346 | if (DEBUG_REORDER) Slog.v(TAG, "Initial app tokens:"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4347 | if (DEBUG_REORDER) dumpAppTokensLocked(); |
| 4348 | final AppWindowToken wtoken = findAppWindowToken(token); |
| 4349 | if (wtoken == null || !mAppTokens.remove(wtoken)) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4350 | 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] | 4351 | + token + " (" + wtoken + ")"); |
| 4352 | return; |
| 4353 | } |
| 4354 | mAppTokens.add(index, wtoken); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4355 | 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] | 4356 | if (DEBUG_REORDER) dumpAppTokensLocked(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4357 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4358 | final long origId = Binder.clearCallingIdentity(); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4359 | 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] | 4360 | if (DEBUG_REORDER) dumpWindowsLocked(); |
| 4361 | if (tmpRemoveAppWindowsLocked(wtoken)) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4362 | 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] | 4363 | if (DEBUG_REORDER) dumpWindowsLocked(); |
| 4364 | reAddAppWindowsLocked(findWindowOffsetLocked(index), wtoken); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4365 | if (DEBUG_REORDER) Slog.v(TAG, "Final window list:"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4366 | if (DEBUG_REORDER) dumpWindowsLocked(); |
| 4367 | updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4368 | mLayoutNeeded = true; |
| 4369 | performLayoutAndPlaceSurfacesLocked(); |
| 4370 | } |
| 4371 | Binder.restoreCallingIdentity(origId); |
| 4372 | } |
| 4373 | } |
| 4374 | |
| 4375 | private void removeAppTokensLocked(List<IBinder> tokens) { |
| 4376 | // XXX This should be done more efficiently! |
| 4377 | // (take advantage of the fact that both lists should be |
| 4378 | // ordered in the same way.) |
| 4379 | int N = tokens.size(); |
| 4380 | for (int i=0; i<N; i++) { |
| 4381 | IBinder token = tokens.get(i); |
| 4382 | final AppWindowToken wtoken = findAppWindowToken(token); |
| 4383 | if (!mAppTokens.remove(wtoken)) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4384 | 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] | 4385 | + token + " (" + wtoken + ")"); |
| 4386 | i--; |
| 4387 | N--; |
| 4388 | } |
| 4389 | } |
| 4390 | } |
| 4391 | |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4392 | private void moveAppWindowsLocked(AppWindowToken wtoken, int tokenPos, |
| 4393 | boolean updateFocusAndLayout) { |
| 4394 | // First remove all of the windows from the list. |
| 4395 | tmpRemoveAppWindowsLocked(wtoken); |
| 4396 | |
| 4397 | // Where to start adding? |
| 4398 | int pos = findWindowOffsetLocked(tokenPos); |
| 4399 | |
| 4400 | // And now add them back at the correct place. |
| 4401 | pos = reAddAppWindowsLocked(pos, wtoken); |
| 4402 | |
| 4403 | if (updateFocusAndLayout) { |
| 4404 | if (!updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES)) { |
| 4405 | assignLayersLocked(); |
| 4406 | } |
| 4407 | mLayoutNeeded = true; |
| 4408 | performLayoutAndPlaceSurfacesLocked(); |
| 4409 | } |
| 4410 | } |
| 4411 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4412 | private void moveAppWindowsLocked(List<IBinder> tokens, int tokenPos) { |
| 4413 | // First remove all of the windows from the list. |
| 4414 | final int N = tokens.size(); |
| 4415 | int i; |
| 4416 | for (i=0; i<N; i++) { |
| 4417 | WindowToken token = mTokenMap.get(tokens.get(i)); |
| 4418 | if (token != null) { |
| 4419 | tmpRemoveAppWindowsLocked(token); |
| 4420 | } |
| 4421 | } |
| 4422 | |
| 4423 | // Where to start adding? |
| 4424 | int pos = findWindowOffsetLocked(tokenPos); |
| 4425 | |
| 4426 | // And now add them back at the correct place. |
| 4427 | for (i=0; i<N; i++) { |
| 4428 | WindowToken token = mTokenMap.get(tokens.get(i)); |
| 4429 | if (token != null) { |
| 4430 | pos = reAddAppWindowsLocked(pos, token); |
| 4431 | } |
| 4432 | } |
| 4433 | |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4434 | if (!updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES)) { |
| 4435 | assignLayersLocked(); |
| 4436 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4437 | mLayoutNeeded = true; |
| 4438 | performLayoutAndPlaceSurfacesLocked(); |
| 4439 | |
| 4440 | //dump(); |
| 4441 | } |
| 4442 | |
| 4443 | public void moveAppTokensToTop(List<IBinder> tokens) { |
| 4444 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 4445 | "moveAppTokensToTop()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4446 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4447 | } |
| 4448 | |
| 4449 | final long origId = Binder.clearCallingIdentity(); |
| 4450 | synchronized(mWindowMap) { |
| 4451 | removeAppTokensLocked(tokens); |
| 4452 | final int N = tokens.size(); |
| 4453 | for (int i=0; i<N; i++) { |
| 4454 | AppWindowToken wt = findAppWindowToken(tokens.get(i)); |
| 4455 | if (wt != null) { |
| 4456 | mAppTokens.add(wt); |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 4457 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4458 | mToTopApps.remove(wt); |
| 4459 | mToBottomApps.remove(wt); |
| 4460 | mToTopApps.add(wt); |
| 4461 | wt.sendingToBottom = false; |
| 4462 | wt.sendingToTop = true; |
| 4463 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4464 | } |
| 4465 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 4466 | |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 4467 | if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET) { |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4468 | moveAppWindowsLocked(tokens, mAppTokens.size()); |
| 4469 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4470 | } |
| 4471 | Binder.restoreCallingIdentity(origId); |
| 4472 | } |
| 4473 | |
| 4474 | public void moveAppTokensToBottom(List<IBinder> tokens) { |
| 4475 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 4476 | "moveAppTokensToBottom()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4477 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4478 | } |
| 4479 | |
| 4480 | final long origId = Binder.clearCallingIdentity(); |
| 4481 | synchronized(mWindowMap) { |
| 4482 | removeAppTokensLocked(tokens); |
| 4483 | final int N = tokens.size(); |
| 4484 | int pos = 0; |
| 4485 | for (int i=0; i<N; i++) { |
| 4486 | AppWindowToken wt = findAppWindowToken(tokens.get(i)); |
| 4487 | if (wt != null) { |
| 4488 | mAppTokens.add(pos, wt); |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 4489 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4490 | mToTopApps.remove(wt); |
| 4491 | mToBottomApps.remove(wt); |
| 4492 | mToBottomApps.add(i, wt); |
| 4493 | wt.sendingToTop = false; |
| 4494 | wt.sendingToBottom = true; |
| 4495 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4496 | pos++; |
| 4497 | } |
| 4498 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 4499 | |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 4500 | if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET) { |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4501 | moveAppWindowsLocked(tokens, 0); |
| 4502 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4503 | } |
| 4504 | Binder.restoreCallingIdentity(origId); |
| 4505 | } |
| 4506 | |
| 4507 | // ------------------------------------------------------------- |
| 4508 | // Misc IWindowSession methods |
| 4509 | // ------------------------------------------------------------- |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4510 | |
| Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 4511 | private boolean shouldAllowDisableKeyguard() |
| Jim Miller | d6b5705 | 2010-06-07 17:52:42 -0700 | [diff] [blame] | 4512 | { |
| Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 4513 | // We fail safe and prevent disabling keyguard in the unlikely event this gets |
| 4514 | // called before DevicePolicyManagerService has started. |
| 4515 | if (mAllowDisableKeyguard == ALLOW_DISABLE_UNKNOWN) { |
| 4516 | DevicePolicyManager dpm = (DevicePolicyManager) mContext.getSystemService( |
| 4517 | Context.DEVICE_POLICY_SERVICE); |
| 4518 | if (dpm != null) { |
| 4519 | mAllowDisableKeyguard = dpm.getPasswordQuality(null) |
| 4520 | == DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED ? |
| 4521 | ALLOW_DISABLE_YES : ALLOW_DISABLE_NO; |
| 4522 | } |
| Jim Miller | d6b5705 | 2010-06-07 17:52:42 -0700 | [diff] [blame] | 4523 | } |
| Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 4524 | return mAllowDisableKeyguard == ALLOW_DISABLE_YES; |
| Jim Miller | d6b5705 | 2010-06-07 17:52:42 -0700 | [diff] [blame] | 4525 | } |
| 4526 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4527 | public void disableKeyguard(IBinder token, String tag) { |
| Mike Lockwood | 733fdf3 | 2009-09-28 19:08:53 -0400 | [diff] [blame] | 4528 | if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD) |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4529 | != PackageManager.PERMISSION_GRANTED) { |
| 4530 | throw new SecurityException("Requires DISABLE_KEYGUARD permission"); |
| 4531 | } |
| Jim Miller | d6b5705 | 2010-06-07 17:52:42 -0700 | [diff] [blame] | 4532 | |
| Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 4533 | synchronized (mKeyguardTokenWatcher) { |
| 4534 | mKeyguardTokenWatcher.acquire(token, tag); |
| Mike Lockwood | dd88468 | 2009-10-11 16:57:08 -0400 | [diff] [blame] | 4535 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4536 | } |
| 4537 | |
| 4538 | public void reenableKeyguard(IBinder token) { |
| Mike Lockwood | 733fdf3 | 2009-09-28 19:08:53 -0400 | [diff] [blame] | 4539 | if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD) |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4540 | != PackageManager.PERMISSION_GRANTED) { |
| 4541 | throw new SecurityException("Requires DISABLE_KEYGUARD permission"); |
| 4542 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4543 | |
| Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 4544 | synchronized (mKeyguardTokenWatcher) { |
| 4545 | mKeyguardTokenWatcher.release(token); |
| Jim Miller | d6b5705 | 2010-06-07 17:52:42 -0700 | [diff] [blame] | 4546 | |
| Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 4547 | if (!mKeyguardTokenWatcher.isAcquired()) { |
| 4548 | // If we are the last one to reenable the keyguard wait until |
| 4549 | // we have actually finished reenabling until returning. |
| 4550 | // It is possible that reenableKeyguard() can be called before |
| 4551 | // the previous disableKeyguard() is handled, in which case |
| 4552 | // neither mKeyguardTokenWatcher.acquired() or released() would |
| 4553 | // be called. In that case mKeyguardDisabled will be false here |
| 4554 | // and we have nothing to wait for. |
| 4555 | while (mKeyguardDisabled) { |
| 4556 | try { |
| 4557 | mKeyguardTokenWatcher.wait(); |
| 4558 | } catch (InterruptedException e) { |
| 4559 | Thread.currentThread().interrupt(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4560 | } |
| 4561 | } |
| 4562 | } |
| 4563 | } |
| 4564 | } |
| 4565 | |
| 4566 | /** |
| 4567 | * @see android.app.KeyguardManager#exitKeyguardSecurely |
| 4568 | */ |
| 4569 | public void exitKeyguardSecurely(final IOnKeyguardExitResult callback) { |
| Mike Lockwood | 733fdf3 | 2009-09-28 19:08:53 -0400 | [diff] [blame] | 4570 | if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD) |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4571 | != PackageManager.PERMISSION_GRANTED) { |
| 4572 | throw new SecurityException("Requires DISABLE_KEYGUARD permission"); |
| 4573 | } |
| 4574 | mPolicy.exitKeyguardSecurely(new WindowManagerPolicy.OnKeyguardExitResult() { |
| 4575 | public void onKeyguardExitResult(boolean success) { |
| 4576 | try { |
| 4577 | callback.onKeyguardExitResult(success); |
| 4578 | } catch (RemoteException e) { |
| 4579 | // Client has died, we don't care. |
| 4580 | } |
| 4581 | } |
| 4582 | }); |
| 4583 | } |
| 4584 | |
| 4585 | public boolean inKeyguardRestrictedInputMode() { |
| 4586 | return mPolicy.inKeyguardRestrictedKeyInputMode(); |
| 4587 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4588 | |
| Dianne Hackborn | ffa4248 | 2009-09-23 22:20:11 -0700 | [diff] [blame] | 4589 | public void closeSystemDialogs(String reason) { |
| 4590 | synchronized(mWindowMap) { |
| 4591 | for (int i=mWindows.size()-1; i>=0; i--) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 4592 | WindowState w = mWindows.get(i); |
| Dianne Hackborn | ffa4248 | 2009-09-23 22:20:11 -0700 | [diff] [blame] | 4593 | if (w.mSurface != null) { |
| 4594 | try { |
| 4595 | w.mClient.closeSystemDialogs(reason); |
| 4596 | } catch (RemoteException e) { |
| 4597 | } |
| 4598 | } |
| 4599 | } |
| 4600 | } |
| 4601 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 4602 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4603 | static float fixScale(float scale) { |
| 4604 | if (scale < 0) scale = 0; |
| 4605 | else if (scale > 20) scale = 20; |
| 4606 | return Math.abs(scale); |
| 4607 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4608 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4609 | public void setAnimationScale(int which, float scale) { |
| 4610 | if (!checkCallingPermission(android.Manifest.permission.SET_ANIMATION_SCALE, |
| 4611 | "setAnimationScale()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4612 | throw new SecurityException("Requires SET_ANIMATION_SCALE permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4613 | } |
| 4614 | |
| 4615 | if (scale < 0) scale = 0; |
| 4616 | else if (scale > 20) scale = 20; |
| 4617 | scale = Math.abs(scale); |
| 4618 | switch (which) { |
| 4619 | case 0: mWindowAnimationScale = fixScale(scale); break; |
| 4620 | case 1: mTransitionAnimationScale = fixScale(scale); break; |
| 4621 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4622 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4623 | // Persist setting |
| 4624 | mH.obtainMessage(H.PERSIST_ANIMATION_SCALE).sendToTarget(); |
| 4625 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4626 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4627 | public void setAnimationScales(float[] scales) { |
| 4628 | if (!checkCallingPermission(android.Manifest.permission.SET_ANIMATION_SCALE, |
| 4629 | "setAnimationScale()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4630 | throw new SecurityException("Requires SET_ANIMATION_SCALE permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4631 | } |
| 4632 | |
| 4633 | if (scales != null) { |
| 4634 | if (scales.length >= 1) { |
| 4635 | mWindowAnimationScale = fixScale(scales[0]); |
| 4636 | } |
| 4637 | if (scales.length >= 2) { |
| 4638 | mTransitionAnimationScale = fixScale(scales[1]); |
| 4639 | } |
| 4640 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4641 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4642 | // Persist setting |
| 4643 | mH.obtainMessage(H.PERSIST_ANIMATION_SCALE).sendToTarget(); |
| 4644 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4645 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4646 | public float getAnimationScale(int which) { |
| 4647 | switch (which) { |
| 4648 | case 0: return mWindowAnimationScale; |
| 4649 | case 1: return mTransitionAnimationScale; |
| 4650 | } |
| 4651 | return 0; |
| 4652 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4653 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4654 | public float[] getAnimationScales() { |
| 4655 | return new float[] { mWindowAnimationScale, mTransitionAnimationScale }; |
| 4656 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4657 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4658 | public int getSwitchState(int sw) { |
| 4659 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4660 | "getSwitchState()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4661 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4662 | } |
| Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 4663 | return mInputManager.getSwitchState(-1, InputDevice.SOURCE_ANY, sw); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4664 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4665 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4666 | public int getSwitchStateForDevice(int devid, int sw) { |
| 4667 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4668 | "getSwitchStateForDevice()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4669 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4670 | } |
| Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 4671 | return mInputManager.getSwitchState(devid, InputDevice.SOURCE_ANY, sw); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4672 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4673 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4674 | public int getScancodeState(int sw) { |
| 4675 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4676 | "getScancodeState()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4677 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4678 | } |
| Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 4679 | return mInputManager.getScanCodeState(-1, InputDevice.SOURCE_ANY, sw); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4680 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4681 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4682 | public int getScancodeStateForDevice(int devid, int sw) { |
| 4683 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4684 | "getScancodeStateForDevice()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4685 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4686 | } |
| Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 4687 | return mInputManager.getScanCodeState(devid, InputDevice.SOURCE_ANY, sw); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4688 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4689 | |
| Dianne Hackborn | 1d62ea9 | 2009-11-17 12:49:50 -0800 | [diff] [blame] | 4690 | public int getTrackballScancodeState(int sw) { |
| 4691 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4692 | "getTrackballScancodeState()")) { |
| 4693 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
| 4694 | } |
| Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 4695 | return mInputManager.getScanCodeState(-1, InputDevice.SOURCE_TRACKBALL, sw); |
| Dianne Hackborn | 1d62ea9 | 2009-11-17 12:49:50 -0800 | [diff] [blame] | 4696 | } |
| 4697 | |
| 4698 | public int getDPadScancodeState(int sw) { |
| 4699 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4700 | "getDPadScancodeState()")) { |
| 4701 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
| 4702 | } |
| Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 4703 | return mInputManager.getScanCodeState(-1, InputDevice.SOURCE_DPAD, sw); |
| Dianne Hackborn | 1d62ea9 | 2009-11-17 12:49:50 -0800 | [diff] [blame] | 4704 | } |
| 4705 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4706 | public int getKeycodeState(int sw) { |
| 4707 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4708 | "getKeycodeState()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4709 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4710 | } |
| Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 4711 | return mInputManager.getKeyCodeState(-1, InputDevice.SOURCE_ANY, sw); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4712 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4713 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4714 | public int getKeycodeStateForDevice(int devid, int sw) { |
| 4715 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4716 | "getKeycodeStateForDevice()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4717 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4718 | } |
| Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 4719 | return mInputManager.getKeyCodeState(devid, InputDevice.SOURCE_ANY, sw); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4720 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4721 | |
| Dianne Hackborn | 1d62ea9 | 2009-11-17 12:49:50 -0800 | [diff] [blame] | 4722 | public int getTrackballKeycodeState(int sw) { |
| 4723 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4724 | "getTrackballKeycodeState()")) { |
| 4725 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
| 4726 | } |
| Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 4727 | return mInputManager.getKeyCodeState(-1, InputDevice.SOURCE_TRACKBALL, sw); |
| Dianne Hackborn | 1d62ea9 | 2009-11-17 12:49:50 -0800 | [diff] [blame] | 4728 | } |
| 4729 | |
| 4730 | public int getDPadKeycodeState(int sw) { |
| 4731 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4732 | "getDPadKeycodeState()")) { |
| 4733 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
| 4734 | } |
| Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 4735 | return mInputManager.getKeyCodeState(-1, InputDevice.SOURCE_DPAD, sw); |
| Dianne Hackborn | 1d62ea9 | 2009-11-17 12:49:50 -0800 | [diff] [blame] | 4736 | } |
| Jeff Brown | a41ca77 | 2010-08-11 14:46:32 -0700 | [diff] [blame] | 4737 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4738 | public boolean hasKeys(int[] keycodes, boolean[] keyExists) { |
| Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 4739 | return mInputManager.hasKeys(-1, InputDevice.SOURCE_ANY, keycodes, keyExists); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4740 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4741 | |
| Jeff Brown | a41ca77 | 2010-08-11 14:46:32 -0700 | [diff] [blame] | 4742 | public InputChannel monitorInput(String inputChannelName) { |
| 4743 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4744 | "monitorInput()")) { |
| 4745 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
| 4746 | } |
| 4747 | return mInputManager.monitorInput(inputChannelName); |
| 4748 | } |
| 4749 | |
| Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 4750 | public InputDevice getInputDevice(int deviceId) { |
| 4751 | return mInputManager.getInputDevice(deviceId); |
| 4752 | } |
| 4753 | |
| 4754 | public int[] getInputDeviceIds() { |
| 4755 | return mInputManager.getInputDeviceIds(); |
| 4756 | } |
| 4757 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4758 | public void enableScreenAfterBoot() { |
| 4759 | synchronized(mWindowMap) { |
| 4760 | if (mSystemBooted) { |
| 4761 | return; |
| 4762 | } |
| 4763 | mSystemBooted = true; |
| 4764 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4765 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4766 | performEnableScreen(); |
| 4767 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4768 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4769 | public void enableScreenIfNeededLocked() { |
| 4770 | if (mDisplayEnabled) { |
| 4771 | return; |
| 4772 | } |
| 4773 | if (!mSystemBooted) { |
| 4774 | return; |
| 4775 | } |
| 4776 | mH.sendMessage(mH.obtainMessage(H.ENABLE_SCREEN)); |
| 4777 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4778 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4779 | public void performEnableScreen() { |
| 4780 | synchronized(mWindowMap) { |
| 4781 | if (mDisplayEnabled) { |
| 4782 | return; |
| 4783 | } |
| 4784 | if (!mSystemBooted) { |
| 4785 | return; |
| 4786 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4787 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4788 | // Don't enable the screen until all existing windows |
| 4789 | // have been drawn. |
| 4790 | final int N = mWindows.size(); |
| 4791 | for (int i=0; i<N; i++) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 4792 | WindowState w = mWindows.get(i); |
| Dianne Hackborn | f3bea9c | 2009-12-09 18:26:21 -0800 | [diff] [blame] | 4793 | if (w.isVisibleLw() && !w.mObscured && !w.isDrawnLw()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4794 | return; |
| 4795 | } |
| 4796 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4797 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4798 | mDisplayEnabled = true; |
| 4799 | if (false) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4800 | Slog.i(TAG, "ENABLING SCREEN!"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4801 | StringWriter sw = new StringWriter(); |
| 4802 | PrintWriter pw = new PrintWriter(sw); |
| 4803 | this.dump(null, pw, null); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4804 | Slog.i(TAG, sw.toString()); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4805 | } |
| 4806 | try { |
| 4807 | IBinder surfaceFlinger = ServiceManager.getService("SurfaceFlinger"); |
| 4808 | if (surfaceFlinger != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4809 | //Slog.i(TAG, "******* TELLING SURFACE FLINGER WE ARE BOOTED!"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4810 | Parcel data = Parcel.obtain(); |
| 4811 | data.writeInterfaceToken("android.ui.ISurfaceComposer"); |
| 4812 | surfaceFlinger.transact(IBinder.FIRST_CALL_TRANSACTION, |
| 4813 | data, null, 0); |
| 4814 | data.recycle(); |
| 4815 | } |
| 4816 | } catch (RemoteException ex) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4817 | Slog.e(TAG, "Boot completed: SurfaceFlinger is dead!"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4818 | } |
| 4819 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4820 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4821 | mPolicy.enableScreenAfterBoot(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4822 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4823 | // Make sure the last requested orientation has been applied. |
| Dianne Hackborn | 321ae68 | 2009-03-27 16:16:03 -0700 | [diff] [blame] | 4824 | setRotationUnchecked(WindowManagerPolicy.USE_LAST_ROTATION, false, |
| 4825 | mLastRotationFlags | Surface.FLAGS_ORIENTATION_ANIMATION_DISABLE); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4826 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4827 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4828 | public void setInTouchMode(boolean mode) { |
| 4829 | synchronized(mWindowMap) { |
| 4830 | mInTouchMode = mode; |
| 4831 | } |
| 4832 | } |
| 4833 | |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4834 | public void setRotation(int rotation, |
| Dianne Hackborn | 1e880db | 2009-03-27 16:04:08 -0700 | [diff] [blame] | 4835 | boolean alwaysSendConfiguration, int animFlags) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4836 | if (!checkCallingPermission(android.Manifest.permission.SET_ORIENTATION, |
| Dianne Hackborn | 1e880db | 2009-03-27 16:04:08 -0700 | [diff] [blame] | 4837 | "setRotation()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4838 | throw new SecurityException("Requires SET_ORIENTATION permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4839 | } |
| 4840 | |
| Dianne Hackborn | 1e880db | 2009-03-27 16:04:08 -0700 | [diff] [blame] | 4841 | setRotationUnchecked(rotation, alwaysSendConfiguration, animFlags); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4842 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4843 | |
| Dianne Hackborn | 1e880db | 2009-03-27 16:04:08 -0700 | [diff] [blame] | 4844 | public void setRotationUnchecked(int rotation, |
| 4845 | boolean alwaysSendConfiguration, int animFlags) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4846 | if(DEBUG_ORIENTATION) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4847 | "alwaysSendConfiguration set to "+alwaysSendConfiguration); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4848 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4849 | long origId = Binder.clearCallingIdentity(); |
| 4850 | boolean changed; |
| 4851 | synchronized(mWindowMap) { |
| Dianne Hackborn | 1e880db | 2009-03-27 16:04:08 -0700 | [diff] [blame] | 4852 | changed = setRotationUncheckedLocked(rotation, animFlags); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4853 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4854 | |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 4855 | if (changed || alwaysSendConfiguration) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4856 | sendNewConfiguration(); |
| 4857 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4858 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4859 | Binder.restoreCallingIdentity(origId); |
| 4860 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4861 | |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 4862 | /** |
| 4863 | * Apply a new rotation to the screen, respecting the requests of |
| 4864 | * applications. Use WindowManagerPolicy.USE_LAST_ROTATION to simply |
| 4865 | * re-evaluate the desired rotation. |
| 4866 | * |
| 4867 | * Returns null if the rotation has been changed. In this case YOU |
| 4868 | * MUST CALL setNewConfiguration() TO UNFREEZE THE SCREEN. |
| 4869 | */ |
| Dianne Hackborn | 1e880db | 2009-03-27 16:04:08 -0700 | [diff] [blame] | 4870 | public boolean setRotationUncheckedLocked(int rotation, int animFlags) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4871 | boolean changed; |
| 4872 | if (rotation == WindowManagerPolicy.USE_LAST_ROTATION) { |
| 4873 | rotation = mRequestedRotation; |
| 4874 | } else { |
| 4875 | mRequestedRotation = rotation; |
| Dianne Hackborn | 321ae68 | 2009-03-27 16:16:03 -0700 | [diff] [blame] | 4876 | mLastRotationFlags = animFlags; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4877 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4878 | 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] | 4879 | rotation = mPolicy.rotationForOrientationLw(mForcedAppOrientation, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4880 | mRotation, mDisplayEnabled); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4881 | 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] | 4882 | changed = mDisplayEnabled && mRotation != rotation; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4883 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4884 | if (changed) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4885 | if (DEBUG_ORIENTATION) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4886 | "Rotation changed to " + rotation |
| 4887 | + " from " + mRotation |
| 4888 | + " (forceApp=" + mForcedAppOrientation |
| 4889 | + ", req=" + mRequestedRotation + ")"); |
| 4890 | mRotation = rotation; |
| 4891 | mWindowsFreezingScreen = true; |
| 4892 | mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT); |
| 4893 | mH.sendMessageDelayed(mH.obtainMessage(H.WINDOW_FREEZE_TIMEOUT), |
| 4894 | 2000); |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 4895 | mWaitingForConfig = true; |
| 4896 | mLayoutNeeded = true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4897 | startFreezingDisplayLocked(); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4898 | Slog.i(TAG, "Setting rotation to " + rotation + ", animFlags=" + animFlags); |
| Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 4899 | mInputManager.setDisplayOrientation(0, rotation); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4900 | if (mDisplayEnabled) { |
| Dianne Hackborn | 321ae68 | 2009-03-27 16:16:03 -0700 | [diff] [blame] | 4901 | Surface.setOrientation(0, rotation, animFlags); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4902 | } |
| 4903 | for (int i=mWindows.size()-1; i>=0; i--) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 4904 | WindowState w = mWindows.get(i); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4905 | if (w.mSurface != null) { |
| 4906 | w.mOrientationChanging = true; |
| 4907 | } |
| 4908 | } |
| 4909 | for (int i=mRotationWatchers.size()-1; i>=0; i--) { |
| 4910 | try { |
| 4911 | mRotationWatchers.get(i).onRotationChanged(rotation); |
| 4912 | } catch (RemoteException e) { |
| 4913 | } |
| 4914 | } |
| 4915 | } //end if changed |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4916 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4917 | return changed; |
| 4918 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4919 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4920 | public int getRotation() { |
| 4921 | return mRotation; |
| 4922 | } |
| 4923 | |
| 4924 | public int watchRotation(IRotationWatcher watcher) { |
| 4925 | final IBinder watcherBinder = watcher.asBinder(); |
| 4926 | IBinder.DeathRecipient dr = new IBinder.DeathRecipient() { |
| 4927 | public void binderDied() { |
| 4928 | synchronized (mWindowMap) { |
| 4929 | for (int i=0; i<mRotationWatchers.size(); i++) { |
| 4930 | if (watcherBinder == mRotationWatchers.get(i).asBinder()) { |
| Suchi Amalapurapu | fff2fda | 2009-06-30 21:36:16 -0700 | [diff] [blame] | 4931 | IRotationWatcher removed = mRotationWatchers.remove(i); |
| 4932 | if (removed != null) { |
| 4933 | removed.asBinder().unlinkToDeath(this, 0); |
| 4934 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4935 | i--; |
| 4936 | } |
| 4937 | } |
| 4938 | } |
| 4939 | } |
| 4940 | }; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4941 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4942 | synchronized (mWindowMap) { |
| 4943 | try { |
| 4944 | watcher.asBinder().linkToDeath(dr, 0); |
| 4945 | mRotationWatchers.add(watcher); |
| 4946 | } catch (RemoteException e) { |
| 4947 | // Client died, no cleanup needed. |
| 4948 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4949 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4950 | return mRotation; |
| 4951 | } |
| 4952 | } |
| 4953 | |
| 4954 | /** |
| 4955 | * Starts the view server on the specified port. |
| 4956 | * |
| 4957 | * @param port The port to listener to. |
| 4958 | * |
| 4959 | * @return True if the server was successfully started, false otherwise. |
| 4960 | * |
| 4961 | * @see com.android.server.ViewServer |
| 4962 | * @see com.android.server.ViewServer#VIEW_SERVER_DEFAULT_PORT |
| 4963 | */ |
| 4964 | public boolean startViewServer(int port) { |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4965 | if (isSystemSecure()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4966 | return false; |
| 4967 | } |
| 4968 | |
| 4969 | if (!checkCallingPermission(Manifest.permission.DUMP, "startViewServer")) { |
| 4970 | return false; |
| 4971 | } |
| 4972 | |
| 4973 | if (port < 1024) { |
| 4974 | return false; |
| 4975 | } |
| 4976 | |
| 4977 | if (mViewServer != null) { |
| 4978 | if (!mViewServer.isRunning()) { |
| 4979 | try { |
| 4980 | return mViewServer.start(); |
| 4981 | } catch (IOException e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4982 | Slog.w(TAG, "View server did not start"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4983 | } |
| 4984 | } |
| 4985 | return false; |
| 4986 | } |
| 4987 | |
| 4988 | try { |
| 4989 | mViewServer = new ViewServer(this, port); |
| 4990 | return mViewServer.start(); |
| 4991 | } catch (IOException e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4992 | Slog.w(TAG, "View server did not start"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4993 | } |
| 4994 | return false; |
| 4995 | } |
| 4996 | |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4997 | private boolean isSystemSecure() { |
| 4998 | return "1".equals(SystemProperties.get(SYSTEM_SECURE, "1")) && |
| 4999 | "0".equals(SystemProperties.get(SYSTEM_DEBUGGABLE, "0")); |
| 5000 | } |
| 5001 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5002 | /** |
| 5003 | * Stops the view server if it exists. |
| 5004 | * |
| 5005 | * @return True if the server stopped, false if it wasn't started or |
| 5006 | * couldn't be stopped. |
| 5007 | * |
| 5008 | * @see com.android.server.ViewServer |
| 5009 | */ |
| 5010 | public boolean stopViewServer() { |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5011 | if (isSystemSecure()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5012 | return false; |
| 5013 | } |
| 5014 | |
| 5015 | if (!checkCallingPermission(Manifest.permission.DUMP, "stopViewServer")) { |
| 5016 | return false; |
| 5017 | } |
| 5018 | |
| 5019 | if (mViewServer != null) { |
| 5020 | return mViewServer.stop(); |
| 5021 | } |
| 5022 | return false; |
| 5023 | } |
| 5024 | |
| 5025 | /** |
| 5026 | * Indicates whether the view server is running. |
| 5027 | * |
| 5028 | * @return True if the server is running, false otherwise. |
| 5029 | * |
| 5030 | * @see com.android.server.ViewServer |
| 5031 | */ |
| 5032 | public boolean isViewServerRunning() { |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5033 | if (isSystemSecure()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5034 | return false; |
| 5035 | } |
| 5036 | |
| 5037 | if (!checkCallingPermission(Manifest.permission.DUMP, "isViewServerRunning")) { |
| 5038 | return false; |
| 5039 | } |
| 5040 | |
| 5041 | return mViewServer != null && mViewServer.isRunning(); |
| 5042 | } |
| 5043 | |
| 5044 | /** |
| 5045 | * Lists all availble windows in the system. The listing is written in the |
| 5046 | * specified Socket's output stream with the following syntax: |
| 5047 | * windowHashCodeInHexadecimal windowName |
| 5048 | * Each line of the ouput represents a different window. |
| 5049 | * |
| 5050 | * @param client The remote client to send the listing to. |
| 5051 | * @return False if an error occured, true otherwise. |
| 5052 | */ |
| 5053 | boolean viewServerListWindows(Socket client) { |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5054 | if (isSystemSecure()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5055 | return false; |
| 5056 | } |
| 5057 | |
| 5058 | boolean result = true; |
| 5059 | |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 5060 | WindowState[] windows; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5061 | synchronized (mWindowMap) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5062 | //noinspection unchecked |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 5063 | windows = mWindows.toArray(new WindowState[mWindows.size()]); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5064 | } |
| 5065 | |
| 5066 | BufferedWriter out = null; |
| 5067 | |
| 5068 | // Any uncaught exception will crash the system process |
| 5069 | try { |
| 5070 | OutputStream clientStream = client.getOutputStream(); |
| 5071 | out = new BufferedWriter(new OutputStreamWriter(clientStream), 8 * 1024); |
| 5072 | |
| 5073 | final int count = windows.length; |
| 5074 | for (int i = 0; i < count; i++) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 5075 | final WindowState w = windows[i]; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5076 | out.write(Integer.toHexString(System.identityHashCode(w))); |
| 5077 | out.write(' '); |
| 5078 | out.append(w.mAttrs.getTitle()); |
| 5079 | out.write('\n'); |
| 5080 | } |
| 5081 | |
| 5082 | out.write("DONE.\n"); |
| 5083 | out.flush(); |
| 5084 | } catch (Exception e) { |
| 5085 | result = false; |
| 5086 | } finally { |
| 5087 | if (out != null) { |
| 5088 | try { |
| 5089 | out.close(); |
| 5090 | } catch (IOException e) { |
| 5091 | result = false; |
| 5092 | } |
| 5093 | } |
| 5094 | } |
| 5095 | |
| 5096 | return result; |
| 5097 | } |
| 5098 | |
| 5099 | /** |
| Konstantin Lopyrev | f962476 | 2010-07-14 17:02:37 -0700 | [diff] [blame] | 5100 | * Returns the focused window in the following format: |
| 5101 | * windowHashCodeInHexadecimal windowName |
| 5102 | * |
| 5103 | * @param client The remote client to send the listing to. |
| 5104 | * @return False if an error occurred, true otherwise. |
| 5105 | */ |
| 5106 | boolean viewServerGetFocusedWindow(Socket client) { |
| 5107 | if (isSystemSecure()) { |
| 5108 | return false; |
| 5109 | } |
| 5110 | |
| 5111 | boolean result = true; |
| 5112 | |
| 5113 | WindowState focusedWindow = getFocusedWindow(); |
| 5114 | |
| 5115 | BufferedWriter out = null; |
| 5116 | |
| 5117 | // Any uncaught exception will crash the system process |
| 5118 | try { |
| 5119 | OutputStream clientStream = client.getOutputStream(); |
| 5120 | out = new BufferedWriter(new OutputStreamWriter(clientStream), 8 * 1024); |
| 5121 | |
| 5122 | if(focusedWindow != null) { |
| 5123 | out.write(Integer.toHexString(System.identityHashCode(focusedWindow))); |
| 5124 | out.write(' '); |
| 5125 | out.append(focusedWindow.mAttrs.getTitle()); |
| 5126 | } |
| 5127 | out.write('\n'); |
| 5128 | out.flush(); |
| 5129 | } catch (Exception e) { |
| 5130 | result = false; |
| 5131 | } finally { |
| 5132 | if (out != null) { |
| 5133 | try { |
| 5134 | out.close(); |
| 5135 | } catch (IOException e) { |
| 5136 | result = false; |
| 5137 | } |
| 5138 | } |
| 5139 | } |
| 5140 | |
| 5141 | return result; |
| 5142 | } |
| 5143 | |
| 5144 | /** |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5145 | * Sends a command to a target window. The result of the command, if any, will be |
| 5146 | * written in the output stream of the specified socket. |
| 5147 | * |
| 5148 | * The parameters must follow this syntax: |
| 5149 | * windowHashcode extra |
| 5150 | * |
| 5151 | * Where XX is the length in characeters of the windowTitle. |
| 5152 | * |
| 5153 | * The first parameter is the target window. The window with the specified hashcode |
| 5154 | * will be the target. If no target can be found, nothing happens. The extra parameters |
| 5155 | * will be delivered to the target window and as parameters to the command itself. |
| 5156 | * |
| 5157 | * @param client The remote client to sent the result, if any, to. |
| 5158 | * @param command The command to execute. |
| 5159 | * @param parameters The command parameters. |
| 5160 | * |
| 5161 | * @return True if the command was successfully delivered, false otherwise. This does |
| 5162 | * not indicate whether the command itself was successful. |
| 5163 | */ |
| 5164 | boolean viewServerWindowCommand(Socket client, String command, String parameters) { |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5165 | if (isSystemSecure()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5166 | return false; |
| 5167 | } |
| 5168 | |
| 5169 | boolean success = true; |
| 5170 | Parcel data = null; |
| 5171 | Parcel reply = null; |
| 5172 | |
| Konstantin Lopyrev | 43b9b48 | 2010-08-24 22:00:12 -0700 | [diff] [blame] | 5173 | BufferedWriter out = null; |
| 5174 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5175 | // Any uncaught exception will crash the system process |
| 5176 | try { |
| 5177 | // Find the hashcode of the window |
| 5178 | int index = parameters.indexOf(' '); |
| 5179 | if (index == -1) { |
| 5180 | index = parameters.length(); |
| 5181 | } |
| 5182 | final String code = parameters.substring(0, index); |
| Romain Guy | 236092a | 2009-12-14 15:31:48 -0800 | [diff] [blame] | 5183 | int hashCode = (int) Long.parseLong(code, 16); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5184 | |
| 5185 | // Extract the command's parameter after the window description |
| 5186 | if (index < parameters.length()) { |
| 5187 | parameters = parameters.substring(index + 1); |
| 5188 | } else { |
| 5189 | parameters = ""; |
| 5190 | } |
| 5191 | |
| 5192 | final WindowManagerService.WindowState window = findWindow(hashCode); |
| 5193 | if (window == null) { |
| 5194 | return false; |
| 5195 | } |
| 5196 | |
| 5197 | data = Parcel.obtain(); |
| 5198 | data.writeInterfaceToken("android.view.IWindow"); |
| 5199 | data.writeString(command); |
| 5200 | data.writeString(parameters); |
| 5201 | data.writeInt(1); |
| 5202 | ParcelFileDescriptor.fromSocket(client).writeToParcel(data, 0); |
| 5203 | |
| 5204 | reply = Parcel.obtain(); |
| 5205 | |
| 5206 | final IBinder binder = window.mClient.asBinder(); |
| 5207 | // TODO: GET THE TRANSACTION CODE IN A SAFER MANNER |
| 5208 | binder.transact(IBinder.FIRST_CALL_TRANSACTION, data, reply, 0); |
| 5209 | |
| 5210 | reply.readException(); |
| 5211 | |
| Konstantin Lopyrev | 43b9b48 | 2010-08-24 22:00:12 -0700 | [diff] [blame] | 5212 | if (!client.isOutputShutdown()) { |
| 5213 | out = new BufferedWriter(new OutputStreamWriter(client.getOutputStream())); |
| 5214 | out.write("DONE\n"); |
| 5215 | out.flush(); |
| 5216 | } |
| 5217 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5218 | } catch (Exception e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5219 | 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] | 5220 | success = false; |
| 5221 | } finally { |
| 5222 | if (data != null) { |
| 5223 | data.recycle(); |
| 5224 | } |
| 5225 | if (reply != null) { |
| 5226 | reply.recycle(); |
| 5227 | } |
| Konstantin Lopyrev | 43b9b48 | 2010-08-24 22:00:12 -0700 | [diff] [blame] | 5228 | if (out != null) { |
| 5229 | try { |
| 5230 | out.close(); |
| 5231 | } catch (IOException e) { |
| 5232 | |
| 5233 | } |
| 5234 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5235 | } |
| 5236 | |
| 5237 | return success; |
| 5238 | } |
| 5239 | |
| Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 5240 | public void addWindowChangeListener(WindowChangeListener listener) { |
| 5241 | synchronized(mWindowMap) { |
| 5242 | mWindowChangeListeners.add(listener); |
| 5243 | } |
| 5244 | } |
| 5245 | |
| 5246 | public void removeWindowChangeListener(WindowChangeListener listener) { |
| 5247 | synchronized(mWindowMap) { |
| 5248 | mWindowChangeListeners.remove(listener); |
| 5249 | } |
| 5250 | } |
| 5251 | |
| 5252 | private void notifyWindowsChanged() { |
| 5253 | WindowChangeListener[] windowChangeListeners; |
| 5254 | synchronized(mWindowMap) { |
| 5255 | if(mWindowChangeListeners.isEmpty()) { |
| 5256 | return; |
| 5257 | } |
| 5258 | windowChangeListeners = new WindowChangeListener[mWindowChangeListeners.size()]; |
| 5259 | windowChangeListeners = mWindowChangeListeners.toArray(windowChangeListeners); |
| 5260 | } |
| 5261 | int N = windowChangeListeners.length; |
| 5262 | for(int i = 0; i < N; i++) { |
| 5263 | windowChangeListeners[i].windowsChanged(); |
| 5264 | } |
| 5265 | } |
| 5266 | |
| Konstantin Lopyrev | 6e0f65f | 2010-07-14 14:55:33 -0700 | [diff] [blame] | 5267 | private void notifyFocusChanged() { |
| 5268 | WindowChangeListener[] windowChangeListeners; |
| 5269 | synchronized(mWindowMap) { |
| 5270 | if(mWindowChangeListeners.isEmpty()) { |
| 5271 | return; |
| 5272 | } |
| 5273 | windowChangeListeners = new WindowChangeListener[mWindowChangeListeners.size()]; |
| 5274 | windowChangeListeners = mWindowChangeListeners.toArray(windowChangeListeners); |
| 5275 | } |
| 5276 | int N = windowChangeListeners.length; |
| 5277 | for(int i = 0; i < N; i++) { |
| 5278 | windowChangeListeners[i].focusChanged(); |
| 5279 | } |
| 5280 | } |
| 5281 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5282 | private WindowState findWindow(int hashCode) { |
| 5283 | if (hashCode == -1) { |
| 5284 | return getFocusedWindow(); |
| 5285 | } |
| 5286 | |
| 5287 | synchronized (mWindowMap) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 5288 | final ArrayList<WindowState> windows = mWindows; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5289 | final int count = windows.size(); |
| 5290 | |
| 5291 | for (int i = 0; i < count; i++) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 5292 | WindowState w = windows.get(i); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5293 | if (System.identityHashCode(w) == hashCode) { |
| 5294 | return w; |
| 5295 | } |
| 5296 | } |
| 5297 | } |
| 5298 | |
| 5299 | return null; |
| 5300 | } |
| 5301 | |
| 5302 | /* |
| 5303 | * Instruct the Activity Manager to fetch the current configuration and broadcast |
| 5304 | * that to config-changed listeners if appropriate. |
| 5305 | */ |
| 5306 | void sendNewConfiguration() { |
| 5307 | try { |
| 5308 | mActivityManager.updateConfiguration(null); |
| 5309 | } catch (RemoteException e) { |
| 5310 | } |
| 5311 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5312 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5313 | public Configuration computeNewConfiguration() { |
| 5314 | synchronized (mWindowMap) { |
| Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 5315 | return computeNewConfigurationLocked(); |
| 5316 | } |
| 5317 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5318 | |
| Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 5319 | Configuration computeNewConfigurationLocked() { |
| 5320 | Configuration config = new Configuration(); |
| 5321 | if (!computeNewConfigurationLocked(config)) { |
| 5322 | return null; |
| 5323 | } |
| Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 5324 | return config; |
| 5325 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5326 | |
| Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 5327 | boolean computeNewConfigurationLocked(Configuration config) { |
| 5328 | if (mDisplay == null) { |
| 5329 | return false; |
| 5330 | } |
| Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 5331 | |
| 5332 | mInputManager.getInputConfiguration(config); |
| Christopher Tate | b696aee | 2010-04-02 19:08:30 -0700 | [diff] [blame] | 5333 | |
| 5334 | // Use the effective "visual" dimensions based on current rotation |
| 5335 | final boolean rotated = (mRotation == Surface.ROTATION_90 |
| 5336 | || mRotation == Surface.ROTATION_270); |
| 5337 | final int dw = rotated ? mInitialDisplayHeight : mInitialDisplayWidth; |
| 5338 | final int dh = rotated ? mInitialDisplayWidth : mInitialDisplayHeight; |
| 5339 | |
| Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 5340 | int orientation = Configuration.ORIENTATION_SQUARE; |
| 5341 | if (dw < dh) { |
| 5342 | orientation = Configuration.ORIENTATION_PORTRAIT; |
| 5343 | } else if (dw > dh) { |
| 5344 | orientation = Configuration.ORIENTATION_LANDSCAPE; |
| 5345 | } |
| 5346 | config.orientation = orientation; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 5347 | |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 5348 | DisplayMetrics dm = new DisplayMetrics(); |
| 5349 | mDisplay.getMetrics(dm); |
| 5350 | CompatibilityInfo.updateCompatibleScreenFrame(dm, orientation, mCompatibleScreenFrame); |
| 5351 | |
| Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 5352 | if (mScreenLayout == Configuration.SCREENLAYOUT_SIZE_UNDEFINED) { |
| Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 5353 | // Note we only do this once because at this point we don't |
| 5354 | // expect the screen to change in this way at runtime, and want |
| 5355 | // to avoid all of this computation for every config change. |
| Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 5356 | int longSize = dw; |
| 5357 | int shortSize = dh; |
| 5358 | if (longSize < shortSize) { |
| 5359 | int tmp = longSize; |
| 5360 | longSize = shortSize; |
| 5361 | shortSize = tmp; |
| 5362 | } |
| 5363 | longSize = (int)(longSize/dm.density); |
| 5364 | shortSize = (int)(shortSize/dm.density); |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 5365 | |
| Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 5366 | // These semi-magic numbers define our compatibility modes for |
| 5367 | // applications with different screens. Don't change unless you |
| 5368 | // make sure to test lots and lots of apps! |
| 5369 | if (longSize < 470) { |
| 5370 | // This is shorter than an HVGA normal density screen (which |
| 5371 | // is 480 pixels on its long side). |
| Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 5372 | mScreenLayout = Configuration.SCREENLAYOUT_SIZE_SMALL |
| 5373 | | Configuration.SCREENLAYOUT_LONG_NO; |
| Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 5374 | } else { |
| Dianne Hackborn | 14cee9f | 2010-04-23 17:51:26 -0700 | [diff] [blame] | 5375 | // What size is this screen screen? |
| 5376 | if (longSize >= 800 && shortSize >= 600) { |
| 5377 | // SVGA or larger screens at medium density are the point |
| 5378 | // at which we consider it to be an extra large screen. |
| 5379 | mScreenLayout = Configuration.SCREENLAYOUT_SIZE_XLARGE; |
| Dianne Hackborn | b51dc0f | 2010-10-21 15:34:47 -0700 | [diff] [blame] | 5380 | } else if (longSize >= 530 && shortSize >= 400) { |
| 5381 | // SVGA or larger screens at high density are the point |
| Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 5382 | // at which we consider it to be a large screen. |
| 5383 | mScreenLayout = Configuration.SCREENLAYOUT_SIZE_LARGE; |
| 5384 | } else { |
| 5385 | mScreenLayout = Configuration.SCREENLAYOUT_SIZE_NORMAL; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 5386 | |
| Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 5387 | // If this screen is wider than normal HVGA, or taller |
| 5388 | // than FWVGA, then for old apps we want to run in size |
| 5389 | // compatibility mode. |
| 5390 | if (shortSize > 321 || longSize > 570) { |
| 5391 | mScreenLayout |= Configuration.SCREENLAYOUT_COMPAT_NEEDED; |
| 5392 | } |
| 5393 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 5394 | |
| Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 5395 | // Is this a long screen? |
| 5396 | if (((longSize*3)/5) >= (shortSize-1)) { |
| 5397 | // Anything wider than WVGA (5:3) is considering to be long. |
| 5398 | mScreenLayout |= Configuration.SCREENLAYOUT_LONG_YES; |
| 5399 | } else { |
| 5400 | mScreenLayout |= Configuration.SCREENLAYOUT_LONG_NO; |
| 5401 | } |
| Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 5402 | } |
| 5403 | } |
| Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 5404 | config.screenLayout = mScreenLayout; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 5405 | |
| Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 5406 | config.keyboardHidden = Configuration.KEYBOARDHIDDEN_NO; |
| 5407 | config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_NO; |
| 5408 | mPolicy.adjustConfigurationLw(config); |
| 5409 | return true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5410 | } |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5411 | |
| 5412 | // ------------------------------------------------------------- |
| 5413 | // Drag and drop |
| 5414 | // ------------------------------------------------------------- |
| 5415 | |
| 5416 | IBinder prepareDragSurface(IWindow window, SurfaceSession session, |
| 5417 | boolean localOnly, int width, int height, Surface outSurface) { |
| 5418 | if (DEBUG_DRAG) { |
| 5419 | Slog.d(TAG, "prepare drag surface: w=" + width + " h=" + height |
| 5420 | + " local=" + localOnly + " win=" + window |
| 5421 | + " asbinder=" + window.asBinder()); |
| 5422 | } |
| 5423 | |
| 5424 | final int callerPid = Binder.getCallingPid(); |
| 5425 | final long origId = Binder.clearCallingIdentity(); |
| 5426 | IBinder token = null; |
| 5427 | |
| 5428 | try { |
| 5429 | synchronized (mWindowMap) { |
| 5430 | try { |
| 5431 | // !!! TODO: fail if the given window does not currently have touch focus? |
| 5432 | |
| 5433 | if (mDragState == null) { |
| 5434 | Surface surface = new Surface(session, callerPid, "drag surface", 0, |
| 5435 | width, height, PixelFormat.TRANSLUCENT, Surface.HIDDEN); |
| 5436 | outSurface.copyFrom(surface); |
| 5437 | token = new Binder(); |
| 5438 | mDragState = new DragState(token, surface, localOnly); |
| 5439 | mDragState.mSurface = surface; |
| 5440 | mDragState.mLocalOnly = localOnly; |
| 5441 | token = mDragState.mToken = new Binder(); |
| 5442 | |
| 5443 | // 5 second timeout for this window to actually begin the drag |
| 5444 | mH.removeMessages(H.DRAG_START_TIMEOUT, window); |
| 5445 | Message msg = mH.obtainMessage(H.DRAG_START_TIMEOUT, window.asBinder()); |
| 5446 | mH.sendMessageDelayed(msg, 5000); |
| 5447 | } else { |
| 5448 | Slog.w(TAG, "Drag already in progress"); |
| 5449 | } |
| 5450 | } catch (Surface.OutOfResourcesException e) { |
| 5451 | Slog.e(TAG, "Can't allocate drag surface w=" + width + " h=" + height, e); |
| 5452 | if (mDragState != null) { |
| 5453 | mDragState.reset(); |
| 5454 | mDragState = null; |
| 5455 | } |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5456 | } |
| 5457 | } |
| 5458 | } finally { |
| 5459 | Binder.restoreCallingIdentity(origId); |
| 5460 | } |
| 5461 | |
| 5462 | return token; |
| 5463 | } |
| 5464 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5465 | // ------------------------------------------------------------- |
| 5466 | // Input Events and Focus Management |
| 5467 | // ------------------------------------------------------------- |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5468 | |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5469 | InputMonitor mInputMonitor = new InputMonitor(); |
| 5470 | |
| 5471 | /* Tracks the progress of input dispatch and ensures that input dispatch state |
| 5472 | * is kept in sync with changes in window focus, visibility, registration, and |
| 5473 | * other relevant Window Manager state transitions. */ |
| 5474 | final class InputMonitor { |
| 5475 | // Current window with input focus for keys and other non-touch events. May be null. |
| 5476 | private WindowState mInputFocus; |
| 5477 | |
| 5478 | // When true, prevents input dispatch from proceeding until set to false again. |
| 5479 | private boolean mInputDispatchFrozen; |
| 5480 | |
| 5481 | // When true, input dispatch proceeds normally. Otherwise all events are dropped. |
| 5482 | private boolean mInputDispatchEnabled = true; |
| 5483 | |
| 5484 | // Temporary list of windows information to provide to the input dispatcher. |
| 5485 | private InputWindowList mTempInputWindows = new InputWindowList(); |
| 5486 | |
| 5487 | // Temporary input application object to provide to the input dispatcher. |
| 5488 | private InputApplication mTempInputApplication = new InputApplication(); |
| 5489 | |
| 5490 | /* Notifies the window manager about a broken input channel. |
| 5491 | * |
| 5492 | * Called by the InputManager. |
| 5493 | */ |
| 5494 | public void notifyInputChannelBroken(InputChannel inputChannel) { |
| 5495 | synchronized (mWindowMap) { |
| 5496 | WindowState windowState = getWindowStateForInputChannelLocked(inputChannel); |
| 5497 | if (windowState == null) { |
| 5498 | return; // irrelevant |
| 5499 | } |
| 5500 | |
| 5501 | Slog.i(TAG, "WINDOW DIED " + windowState); |
| 5502 | removeWindowLocked(windowState.mSession, windowState); |
| Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 5503 | } |
| 5504 | } |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5505 | |
| Jeff Brown | 519e024 | 2010-09-15 15:18:56 -0700 | [diff] [blame] | 5506 | /* Notifies the window manager about an application that is not responding. |
| Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 5507 | * Returns a new timeout to continue waiting in nanoseconds, or 0 to abort dispatch. |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5508 | * |
| 5509 | * Called by the InputManager. |
| 5510 | */ |
| Jeff Brown | 519e024 | 2010-09-15 15:18:56 -0700 | [diff] [blame] | 5511 | public long notifyANR(Object token, InputChannel inputChannel) { |
| 5512 | AppWindowToken appWindowToken = null; |
| 5513 | if (inputChannel != null) { |
| 5514 | synchronized (mWindowMap) { |
| 5515 | WindowState windowState = getWindowStateForInputChannelLocked(inputChannel); |
| 5516 | if (windowState != null) { |
| 5517 | Slog.i(TAG, "Input event dispatching timed out sending to " |
| 5518 | + windowState.mAttrs.getTitle()); |
| 5519 | appWindowToken = windowState.mAppToken; |
| 5520 | } |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5521 | } |
| Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 5522 | } |
| 5523 | |
| Jeff Brown | 519e024 | 2010-09-15 15:18:56 -0700 | [diff] [blame] | 5524 | if (appWindowToken == null && token != null) { |
| 5525 | appWindowToken = (AppWindowToken) token; |
| 5526 | Slog.i(TAG, "Input event dispatching timed out sending to application " |
| 5527 | + appWindowToken.stringName); |
| 5528 | } |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5529 | |
| Jeff Brown | 519e024 | 2010-09-15 15:18:56 -0700 | [diff] [blame] | 5530 | if (appWindowToken != null && appWindowToken.appToken != null) { |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5531 | try { |
| 5532 | // Notify the activity manager about the timeout and let it decide whether |
| 5533 | // to abort dispatching or keep waiting. |
| Jeff Brown | 519e024 | 2010-09-15 15:18:56 -0700 | [diff] [blame] | 5534 | boolean abort = appWindowToken.appToken.keyDispatchingTimedOut(); |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5535 | if (! abort) { |
| 5536 | // The activity manager declined to abort dispatching. |
| 5537 | // Wait a bit longer and timeout again later. |
| Jeff Brown | 519e024 | 2010-09-15 15:18:56 -0700 | [diff] [blame] | 5538 | return appWindowToken.inputDispatchingTimeoutNanos; |
| Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 5539 | } |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5540 | } catch (RemoteException ex) { |
| Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 5541 | } |
| 5542 | } |
| Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 5543 | return 0; // abort dispatching |
| Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 5544 | } |
| 5545 | |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5546 | private WindowState getWindowStateForInputChannel(InputChannel inputChannel) { |
| 5547 | synchronized (mWindowMap) { |
| 5548 | return getWindowStateForInputChannelLocked(inputChannel); |
| 5549 | } |
| 5550 | } |
| 5551 | |
| 5552 | private WindowState getWindowStateForInputChannelLocked(InputChannel inputChannel) { |
| 5553 | int windowCount = mWindows.size(); |
| 5554 | for (int i = 0; i < windowCount; i++) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 5555 | WindowState windowState = mWindows.get(i); |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5556 | if (windowState.mInputChannel == inputChannel) { |
| 5557 | return windowState; |
| 5558 | } |
| Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 5559 | } |
| 5560 | |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5561 | return null; |
| Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 5562 | } |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5563 | |
| Chris Tate | a32dcf7 | 2010-10-14 12:13:50 -0700 | [diff] [blame] | 5564 | private void addDragInputWindowLw(InputWindowList windowList) { |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5565 | final InputWindow inputWindow = windowList.add(); |
| 5566 | inputWindow.inputChannel = mDragState.mServerChannel; |
| 5567 | inputWindow.name = "drag"; |
| 5568 | inputWindow.layoutParamsFlags = 0; |
| 5569 | inputWindow.layoutParamsType = WindowManager.LayoutParams.TYPE_DRAG; |
| 5570 | inputWindow.dispatchingTimeoutNanos = DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS; |
| 5571 | inputWindow.visible = true; |
| 5572 | inputWindow.canReceiveKeys = false; |
| 5573 | inputWindow.hasFocus = true; |
| 5574 | inputWindow.hasWallpaper = false; |
| 5575 | inputWindow.paused = false; |
| Chris Tate | a32dcf7 | 2010-10-14 12:13:50 -0700 | [diff] [blame] | 5576 | inputWindow.layer = mDragState.getDragLayerLw(); |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5577 | inputWindow.ownerPid = Process.myPid(); |
| 5578 | inputWindow.ownerUid = Process.myUid(); |
| 5579 | |
| 5580 | // The drag window covers the entire display |
| 5581 | inputWindow.frameLeft = 0; |
| 5582 | inputWindow.frameTop = 0; |
| 5583 | inputWindow.frameRight = mDisplay.getWidth(); |
| 5584 | inputWindow.frameBottom = mDisplay.getHeight(); |
| Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 5585 | |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5586 | inputWindow.visibleFrameLeft = inputWindow.frameLeft; |
| 5587 | inputWindow.visibleFrameTop = inputWindow.frameTop; |
| 5588 | inputWindow.visibleFrameRight = inputWindow.frameRight; |
| 5589 | inputWindow.visibleFrameBottom = inputWindow.frameBottom; |
| 5590 | |
| 5591 | inputWindow.touchableAreaLeft = inputWindow.frameLeft; |
| 5592 | inputWindow.touchableAreaTop = inputWindow.frameTop; |
| 5593 | inputWindow.touchableAreaRight = inputWindow.frameRight; |
| 5594 | inputWindow.touchableAreaBottom = inputWindow.frameBottom; |
| 5595 | } |
| 5596 | |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5597 | /* Updates the cached window information provided to the input dispatcher. */ |
| 5598 | public void updateInputWindowsLw() { |
| 5599 | // Populate the input window list with information about all of the windows that |
| 5600 | // could potentially receive input. |
| 5601 | // As an optimization, we could try to prune the list of windows but this turns |
| 5602 | // out to be difficult because only the native code knows for sure which window |
| 5603 | // currently has touch focus. |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 5604 | final ArrayList<WindowState> windows = mWindows; |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5605 | |
| 5606 | // If there's a drag in flight, provide a pseudowindow to catch drag input |
| 5607 | final boolean inDrag = (mDragState != null); |
| 5608 | if (inDrag) { |
| 5609 | if (DEBUG_DRAG) { |
| 5610 | Log.d(TAG, "Inserting drag window"); |
| 5611 | } |
| Chris Tate | a32dcf7 | 2010-10-14 12:13:50 -0700 | [diff] [blame] | 5612 | addDragInputWindowLw(mTempInputWindows); |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5613 | } |
| 5614 | |
| Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 5615 | final int N = windows.size(); |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5616 | for (int i = N - 1; i >= 0; i--) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 5617 | final WindowState child = windows.get(i); |
| Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 5618 | if (child.mInputChannel == null || child.mRemoved) { |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5619 | // Skip this window because it cannot possibly receive input. |
| Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 5620 | continue; |
| 5621 | } |
| 5622 | |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5623 | final int flags = child.mAttrs.flags; |
| 5624 | final int type = child.mAttrs.type; |
| 5625 | |
| 5626 | final boolean hasFocus = (child == mInputFocus); |
| 5627 | final boolean isVisible = child.isVisibleLw(); |
| 5628 | final boolean hasWallpaper = (child == mWallpaperTarget) |
| 5629 | && (type != WindowManager.LayoutParams.TYPE_KEYGUARD); |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5630 | |
| 5631 | // If there's a drag in progress and 'child' is a potential drop target, |
| 5632 | // make sure it's been told about the drag |
| 5633 | if (inDrag && isVisible) { |
| 5634 | mDragState.sendDragStartedIfNeededLw(child); |
| 5635 | } |
| 5636 | |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5637 | // Add a window to our list of input windows. |
| 5638 | final InputWindow inputWindow = mTempInputWindows.add(); |
| 5639 | inputWindow.inputChannel = child.mInputChannel; |
| Jeff Brown | 519e024 | 2010-09-15 15:18:56 -0700 | [diff] [blame] | 5640 | inputWindow.name = child.toString(); |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5641 | inputWindow.layoutParamsFlags = flags; |
| 5642 | inputWindow.layoutParamsType = type; |
| 5643 | inputWindow.dispatchingTimeoutNanos = child.getInputDispatchingTimeoutNanos(); |
| 5644 | inputWindow.visible = isVisible; |
| Jeff Brown | 519e024 | 2010-09-15 15:18:56 -0700 | [diff] [blame] | 5645 | inputWindow.canReceiveKeys = child.canReceiveKeys(); |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5646 | inputWindow.hasFocus = hasFocus; |
| 5647 | inputWindow.hasWallpaper = hasWallpaper; |
| 5648 | inputWindow.paused = child.mAppToken != null ? child.mAppToken.paused : false; |
| Jeff Brown | 519e024 | 2010-09-15 15:18:56 -0700 | [diff] [blame] | 5649 | inputWindow.layer = child.mLayer; |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5650 | inputWindow.ownerPid = child.mSession.mPid; |
| 5651 | inputWindow.ownerUid = child.mSession.mUid; |
| 5652 | |
| 5653 | final Rect frame = child.mFrame; |
| 5654 | inputWindow.frameLeft = frame.left; |
| 5655 | inputWindow.frameTop = frame.top; |
| Jeff Brown | 85a3176 | 2010-09-01 17:01:00 -0700 | [diff] [blame] | 5656 | inputWindow.frameRight = frame.right; |
| 5657 | inputWindow.frameBottom = frame.bottom; |
| 5658 | |
| 5659 | final Rect visibleFrame = child.mVisibleFrame; |
| 5660 | inputWindow.visibleFrameLeft = visibleFrame.left; |
| 5661 | inputWindow.visibleFrameTop = visibleFrame.top; |
| 5662 | inputWindow.visibleFrameRight = visibleFrame.right; |
| 5663 | inputWindow.visibleFrameBottom = visibleFrame.bottom; |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5664 | |
| 5665 | switch (child.mTouchableInsets) { |
| 5666 | default: |
| 5667 | case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME: |
| 5668 | inputWindow.touchableAreaLeft = frame.left; |
| 5669 | inputWindow.touchableAreaTop = frame.top; |
| 5670 | inputWindow.touchableAreaRight = frame.right; |
| 5671 | inputWindow.touchableAreaBottom = frame.bottom; |
| 5672 | break; |
| 5673 | |
| 5674 | case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_CONTENT: { |
| 5675 | Rect inset = child.mGivenContentInsets; |
| 5676 | inputWindow.touchableAreaLeft = frame.left + inset.left; |
| 5677 | inputWindow.touchableAreaTop = frame.top + inset.top; |
| 5678 | inputWindow.touchableAreaRight = frame.right - inset.right; |
| 5679 | inputWindow.touchableAreaBottom = frame.bottom - inset.bottom; |
| 5680 | break; |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5681 | } |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5682 | |
| 5683 | case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_VISIBLE: { |
| 5684 | Rect inset = child.mGivenVisibleInsets; |
| 5685 | inputWindow.touchableAreaLeft = frame.left + inset.left; |
| 5686 | inputWindow.touchableAreaTop = frame.top + inset.top; |
| 5687 | inputWindow.touchableAreaRight = frame.right - inset.right; |
| 5688 | inputWindow.touchableAreaBottom = frame.bottom - inset.bottom; |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5689 | break; |
| 5690 | } |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5691 | } |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5692 | } |
| Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 5693 | |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5694 | // Send windows to native code. |
| 5695 | mInputManager.setInputWindows(mTempInputWindows.toNullTerminatedArray()); |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5696 | |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5697 | // Clear the list in preparation for the next round. |
| 5698 | // Also avoids keeping InputChannel objects referenced unnecessarily. |
| 5699 | mTempInputWindows.clear(); |
| 5700 | } |
| 5701 | |
| Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 5702 | /* Notifies that the lid switch changed state. */ |
| 5703 | public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen) { |
| 5704 | mPolicy.notifyLidSwitchChanged(whenNanos, lidOpen); |
| 5705 | } |
| 5706 | |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5707 | /* Provides an opportunity for the window manager policy to intercept early key |
| 5708 | * processing as soon as the key has been read from the device. */ |
| Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 5709 | public int interceptKeyBeforeQueueing(long whenNanos, int action, int flags, |
| 5710 | int keyCode, int scanCode, int policyFlags, boolean isScreenOn) { |
| 5711 | return mPolicy.interceptKeyBeforeQueueing(whenNanos, action, flags, |
| 5712 | keyCode, scanCode, policyFlags, isScreenOn); |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5713 | } |
| 5714 | |
| 5715 | /* Provides an opportunity for the window manager policy to process a key before |
| 5716 | * ordinary dispatch. */ |
| Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 5717 | public boolean interceptKeyBeforeDispatching(InputChannel focus, |
| Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 5718 | int action, int flags, int keyCode, int scanCode, int metaState, int repeatCount, |
| Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 5719 | int policyFlags) { |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5720 | WindowState windowState = getWindowStateForInputChannel(focus); |
| Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 5721 | return mPolicy.interceptKeyBeforeDispatching(windowState, action, flags, |
| Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 5722 | keyCode, scanCode, metaState, repeatCount, policyFlags); |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5723 | } |
| 5724 | |
| 5725 | /* Called when the current input focus changes. |
| 5726 | * Layer assignment is assumed to be complete by the time this is called. |
| 5727 | */ |
| 5728 | public void setInputFocusLw(WindowState newWindow) { |
| 5729 | if (DEBUG_INPUT) { |
| 5730 | Slog.d(TAG, "Input focus has changed to " + newWindow); |
| 5731 | } |
| 5732 | |
| 5733 | if (newWindow != mInputFocus) { |
| 5734 | if (newWindow != null && newWindow.canReceiveKeys()) { |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5735 | // Displaying a window implicitly causes dispatching to be unpaused. |
| 5736 | // This is to protect against bugs if someone pauses dispatching but |
| 5737 | // forgets to resume. |
| 5738 | newWindow.mToken.paused = false; |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5739 | } |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5740 | |
| 5741 | mInputFocus = newWindow; |
| 5742 | updateInputWindowsLw(); |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5743 | } |
| 5744 | } |
| 5745 | |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5746 | public void setFocusedAppLw(AppWindowToken newApp) { |
| 5747 | // Focused app has changed. |
| 5748 | if (newApp == null) { |
| 5749 | mInputManager.setFocusedApplication(null); |
| 5750 | } else { |
| 5751 | mTempInputApplication.name = newApp.toString(); |
| 5752 | mTempInputApplication.dispatchingTimeoutNanos = |
| 5753 | newApp.inputDispatchingTimeoutNanos; |
| 5754 | mTempInputApplication.token = newApp; |
| 5755 | |
| 5756 | mInputManager.setFocusedApplication(mTempInputApplication); |
| 5757 | } |
| 5758 | } |
| 5759 | |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5760 | public void pauseDispatchingLw(WindowToken window) { |
| 5761 | if (! window.paused) { |
| 5762 | if (DEBUG_INPUT) { |
| 5763 | Slog.v(TAG, "Pausing WindowToken " + window); |
| 5764 | } |
| 5765 | |
| 5766 | window.paused = true; |
| 5767 | updateInputWindowsLw(); |
| 5768 | } |
| 5769 | } |
| 5770 | |
| 5771 | public void resumeDispatchingLw(WindowToken window) { |
| 5772 | if (window.paused) { |
| 5773 | if (DEBUG_INPUT) { |
| 5774 | Slog.v(TAG, "Resuming WindowToken " + window); |
| 5775 | } |
| 5776 | |
| 5777 | window.paused = false; |
| 5778 | updateInputWindowsLw(); |
| 5779 | } |
| 5780 | } |
| 5781 | |
| 5782 | public void freezeInputDispatchingLw() { |
| 5783 | if (! mInputDispatchFrozen) { |
| 5784 | if (DEBUG_INPUT) { |
| 5785 | Slog.v(TAG, "Freezing input dispatching"); |
| 5786 | } |
| 5787 | |
| 5788 | mInputDispatchFrozen = true; |
| 5789 | updateInputDispatchModeLw(); |
| 5790 | } |
| 5791 | } |
| 5792 | |
| 5793 | public void thawInputDispatchingLw() { |
| 5794 | if (mInputDispatchFrozen) { |
| 5795 | if (DEBUG_INPUT) { |
| 5796 | Slog.v(TAG, "Thawing input dispatching"); |
| 5797 | } |
| 5798 | |
| 5799 | mInputDispatchFrozen = false; |
| 5800 | updateInputDispatchModeLw(); |
| 5801 | } |
| 5802 | } |
| 5803 | |
| 5804 | public void setEventDispatchingLw(boolean enabled) { |
| 5805 | if (mInputDispatchEnabled != enabled) { |
| 5806 | if (DEBUG_INPUT) { |
| 5807 | Slog.v(TAG, "Setting event dispatching to " + enabled); |
| 5808 | } |
| 5809 | |
| 5810 | mInputDispatchEnabled = enabled; |
| 5811 | updateInputDispatchModeLw(); |
| 5812 | } |
| 5813 | } |
| 5814 | |
| 5815 | private void updateInputDispatchModeLw() { |
| 5816 | mInputManager.setInputDispatchMode(mInputDispatchEnabled, mInputDispatchFrozen); |
| 5817 | } |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5818 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5819 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5820 | public void pauseKeyDispatching(IBinder _token) { |
| 5821 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 5822 | "pauseKeyDispatching()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5823 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5824 | } |
| 5825 | |
| 5826 | synchronized (mWindowMap) { |
| 5827 | WindowToken token = mTokenMap.get(_token); |
| 5828 | if (token != null) { |
| Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 5829 | mInputMonitor.pauseDispatchingLw(token); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5830 | } |
| 5831 | } |
| 5832 | } |
| 5833 | |
| 5834 | public void resumeKeyDispatching(IBinder _token) { |
| 5835 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 5836 | "resumeKeyDispatching()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5837 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5838 | } |
| 5839 | |
| 5840 | synchronized (mWindowMap) { |
| 5841 | WindowToken token = mTokenMap.get(_token); |
| 5842 | if (token != null) { |
| Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 5843 | mInputMonitor.resumeDispatchingLw(token); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5844 | } |
| 5845 | } |
| 5846 | } |
| 5847 | |
| 5848 | public void setEventDispatching(boolean enabled) { |
| 5849 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 5850 | "resumeKeyDispatching()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5851 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5852 | } |
| 5853 | |
| 5854 | synchronized (mWindowMap) { |
| Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 5855 | mInputMonitor.setEventDispatchingLw(enabled); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5856 | } |
| 5857 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5858 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5859 | /** |
| 5860 | * Injects a keystroke event into the UI. |
| Jeff Brown | bbda99d | 2010-07-28 15:48:59 -0700 | [diff] [blame] | 5861 | * Even when sync is false, this method may block while waiting for current |
| 5862 | * input events to be dispatched. |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5863 | * |
| 5864 | * @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] | 5865 | * {@link SystemClock#uptimeMillis()} as the timebase.) |
| 5866 | * @param sync If true, wait for the event to be completed before returning to the caller. |
| 5867 | * @return Returns true if event was dispatched, false if it was dropped for any reason |
| 5868 | */ |
| 5869 | public boolean injectKeyEvent(KeyEvent ev, boolean sync) { |
| 5870 | long downTime = ev.getDownTime(); |
| 5871 | long eventTime = ev.getEventTime(); |
| 5872 | |
| 5873 | int action = ev.getAction(); |
| 5874 | int code = ev.getKeyCode(); |
| 5875 | int repeatCount = ev.getRepeatCount(); |
| 5876 | int metaState = ev.getMetaState(); |
| 5877 | int deviceId = ev.getDeviceId(); |
| 5878 | int scancode = ev.getScanCode(); |
| Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 5879 | int source = ev.getSource(); |
| 5880 | |
| 5881 | if (source == InputDevice.SOURCE_UNKNOWN) { |
| 5882 | source = InputDevice.SOURCE_KEYBOARD; |
| 5883 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5884 | |
| 5885 | if (eventTime == 0) eventTime = SystemClock.uptimeMillis(); |
| 5886 | if (downTime == 0) downTime = eventTime; |
| 5887 | |
| 5888 | KeyEvent newEvent = new KeyEvent(downTime, eventTime, action, code, repeatCount, metaState, |
| Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 5889 | deviceId, scancode, KeyEvent.FLAG_FROM_SYSTEM, source); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5890 | |
| Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5891 | final int pid = Binder.getCallingPid(); |
| 5892 | final int uid = Binder.getCallingUid(); |
| 5893 | final long ident = Binder.clearCallingIdentity(); |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5894 | |
| Jeff Brown | bbda99d | 2010-07-28 15:48:59 -0700 | [diff] [blame] | 5895 | final int result = mInputManager.injectInputEvent(newEvent, pid, uid, |
| 5896 | sync ? InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH |
| 5897 | : InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT, |
| 5898 | INJECTION_TIMEOUT_MILLIS); |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5899 | |
| Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5900 | Binder.restoreCallingIdentity(ident); |
| Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 5901 | return reportInjectionResult(result); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5902 | } |
| 5903 | |
| 5904 | /** |
| 5905 | * Inject a pointer (touch) event into the UI. |
| Jeff Brown | bbda99d | 2010-07-28 15:48:59 -0700 | [diff] [blame] | 5906 | * Even when sync is false, this method may block while waiting for current |
| 5907 | * input events to be dispatched. |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5908 | * |
| 5909 | * @param ev A motion event describing the pointer (touch) action. (As noted in |
| 5910 | * {@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] | 5911 | * {@link SystemClock#uptimeMillis()} as the timebase.) |
| 5912 | * @param sync If true, wait for the event to be completed before returning to the caller. |
| 5913 | * @return Returns true if event was dispatched, false if it was dropped for any reason |
| 5914 | */ |
| 5915 | public boolean injectPointerEvent(MotionEvent ev, boolean sync) { |
| Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5916 | final int pid = Binder.getCallingPid(); |
| 5917 | final int uid = Binder.getCallingUid(); |
| 5918 | final long ident = Binder.clearCallingIdentity(); |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5919 | |
| Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 5920 | MotionEvent newEvent = MotionEvent.obtain(ev); |
| 5921 | if ((newEvent.getSource() & InputDevice.SOURCE_CLASS_POINTER) == 0) { |
| 5922 | newEvent.setSource(InputDevice.SOURCE_TOUCHSCREEN); |
| 5923 | } |
| 5924 | |
| Jeff Brown | bbda99d | 2010-07-28 15:48:59 -0700 | [diff] [blame] | 5925 | final int result = mInputManager.injectInputEvent(newEvent, pid, uid, |
| 5926 | sync ? InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH |
| 5927 | : InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT, |
| 5928 | INJECTION_TIMEOUT_MILLIS); |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5929 | |
| Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5930 | Binder.restoreCallingIdentity(ident); |
| Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 5931 | return reportInjectionResult(result); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5932 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5933 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5934 | /** |
| 5935 | * Inject a trackball (navigation device) event into the UI. |
| Jeff Brown | bbda99d | 2010-07-28 15:48:59 -0700 | [diff] [blame] | 5936 | * Even when sync is false, this method may block while waiting for current |
| 5937 | * input events to be dispatched. |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5938 | * |
| 5939 | * @param ev A motion event describing the trackball action. (As noted in |
| 5940 | * {@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] | 5941 | * {@link SystemClock#uptimeMillis()} as the timebase.) |
| 5942 | * @param sync If true, wait for the event to be completed before returning to the caller. |
| 5943 | * @return Returns true if event was dispatched, false if it was dropped for any reason |
| 5944 | */ |
| 5945 | public boolean injectTrackballEvent(MotionEvent ev, boolean sync) { |
| Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5946 | final int pid = Binder.getCallingPid(); |
| 5947 | final int uid = Binder.getCallingUid(); |
| 5948 | final long ident = Binder.clearCallingIdentity(); |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5949 | |
| Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 5950 | MotionEvent newEvent = MotionEvent.obtain(ev); |
| 5951 | if ((newEvent.getSource() & InputDevice.SOURCE_CLASS_TRACKBALL) == 0) { |
| 5952 | newEvent.setSource(InputDevice.SOURCE_TRACKBALL); |
| 5953 | } |
| 5954 | |
| Jeff Brown | bbda99d | 2010-07-28 15:48:59 -0700 | [diff] [blame] | 5955 | final int result = mInputManager.injectInputEvent(newEvent, pid, uid, |
| 5956 | sync ? InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH |
| 5957 | : InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT, |
| 5958 | INJECTION_TIMEOUT_MILLIS); |
| 5959 | |
| 5960 | Binder.restoreCallingIdentity(ident); |
| 5961 | return reportInjectionResult(result); |
| 5962 | } |
| 5963 | |
| 5964 | /** |
| 5965 | * Inject an input event into the UI without waiting for dispatch to commence. |
| 5966 | * This variant is useful for fire-and-forget input event injection. It does not |
| 5967 | * block any longer than it takes to enqueue the input event. |
| 5968 | * |
| 5969 | * @param ev An input event. (Be sure to set the input source correctly.) |
| 5970 | * @return Returns true if event was dispatched, false if it was dropped for any reason |
| 5971 | */ |
| 5972 | public boolean injectInputEventNoWait(InputEvent ev) { |
| 5973 | final int pid = Binder.getCallingPid(); |
| 5974 | final int uid = Binder.getCallingUid(); |
| 5975 | final long ident = Binder.clearCallingIdentity(); |
| 5976 | |
| 5977 | final int result = mInputManager.injectInputEvent(ev, pid, uid, |
| 5978 | InputManager.INPUT_EVENT_INJECTION_SYNC_NONE, |
| 5979 | INJECTION_TIMEOUT_MILLIS); |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5980 | |
| Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5981 | Binder.restoreCallingIdentity(ident); |
| Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 5982 | return reportInjectionResult(result); |
| 5983 | } |
| 5984 | |
| 5985 | private boolean reportInjectionResult(int result) { |
| Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 5986 | switch (result) { |
| 5987 | case InputManager.INPUT_EVENT_INJECTION_PERMISSION_DENIED: |
| 5988 | Slog.w(TAG, "Input event injection permission denied."); |
| 5989 | throw new SecurityException( |
| 5990 | "Injecting to another application requires INJECT_EVENTS permission"); |
| 5991 | case InputManager.INPUT_EVENT_INJECTION_SUCCEEDED: |
| Christopher Tate | 09e85dc | 2010-08-02 11:54:41 -0700 | [diff] [blame] | 5992 | //Slog.v(TAG, "Input event injection succeeded."); |
| Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 5993 | return true; |
| 5994 | case InputManager.INPUT_EVENT_INJECTION_TIMED_OUT: |
| 5995 | Slog.w(TAG, "Input event injection timed out."); |
| 5996 | return false; |
| 5997 | case InputManager.INPUT_EVENT_INJECTION_FAILED: |
| 5998 | default: |
| 5999 | Slog.w(TAG, "Input event injection failed."); |
| 6000 | return false; |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 6001 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6002 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6003 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6004 | private WindowState getFocusedWindow() { |
| 6005 | synchronized (mWindowMap) { |
| 6006 | return getFocusedWindowLocked(); |
| 6007 | } |
| 6008 | } |
| 6009 | |
| 6010 | private WindowState getFocusedWindowLocked() { |
| 6011 | return mCurrentFocus; |
| 6012 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6013 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6014 | public boolean detectSafeMode() { |
| 6015 | mSafeMode = mPolicy.detectSafeMode(); |
| 6016 | return mSafeMode; |
| 6017 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6018 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6019 | public void systemReady() { |
| Dianne Hackborn | 5132b37 | 2010-07-29 12:51:35 -0700 | [diff] [blame] | 6020 | synchronized(mWindowMap) { |
| 6021 | if (mDisplay != null) { |
| 6022 | throw new IllegalStateException("Display already initialized"); |
| 6023 | } |
| 6024 | WindowManager wm = (WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE); |
| 6025 | mDisplay = wm.getDefaultDisplay(); |
| 6026 | mInitialDisplayWidth = mDisplay.getWidth(); |
| 6027 | mInitialDisplayHeight = mDisplay.getHeight(); |
| 6028 | mInputManager.setDisplaySize(0, mInitialDisplayWidth, mInitialDisplayHeight); |
| 6029 | } |
| 6030 | |
| 6031 | try { |
| 6032 | mActivityManager.updateConfiguration(null); |
| 6033 | } catch (RemoteException e) { |
| 6034 | } |
| Dianne Hackborn | 154db5f | 2010-07-29 19:15:19 -0700 | [diff] [blame] | 6035 | |
| 6036 | mPolicy.systemReady(); |
| Dianne Hackborn | 5132b37 | 2010-07-29 12:51:35 -0700 | [diff] [blame] | 6037 | } |
| 6038 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6039 | // ------------------------------------------------------------- |
| 6040 | // Client Session State |
| 6041 | // ------------------------------------------------------------- |
| 6042 | |
| 6043 | private final class Session extends IWindowSession.Stub |
| 6044 | implements IBinder.DeathRecipient { |
| 6045 | final IInputMethodClient mClient; |
| 6046 | final IInputContext mInputContext; |
| 6047 | final int mUid; |
| 6048 | final int mPid; |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 6049 | final String mStringName; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6050 | SurfaceSession mSurfaceSession; |
| 6051 | int mNumWindow = 0; |
| 6052 | boolean mClientDead = false; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6053 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6054 | public Session(IInputMethodClient client, IInputContext inputContext) { |
| 6055 | mClient = client; |
| 6056 | mInputContext = inputContext; |
| 6057 | mUid = Binder.getCallingUid(); |
| 6058 | mPid = Binder.getCallingPid(); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 6059 | StringBuilder sb = new StringBuilder(); |
| 6060 | sb.append("Session{"); |
| 6061 | sb.append(Integer.toHexString(System.identityHashCode(this))); |
| 6062 | sb.append(" uid "); |
| 6063 | sb.append(mUid); |
| 6064 | sb.append("}"); |
| 6065 | mStringName = sb.toString(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6066 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6067 | synchronized (mWindowMap) { |
| 6068 | if (mInputMethodManager == null && mHaveInputMethods) { |
| 6069 | IBinder b = ServiceManager.getService( |
| 6070 | Context.INPUT_METHOD_SERVICE); |
| 6071 | mInputMethodManager = IInputMethodManager.Stub.asInterface(b); |
| 6072 | } |
| 6073 | } |
| 6074 | long ident = Binder.clearCallingIdentity(); |
| 6075 | try { |
| 6076 | // Note: it is safe to call in to the input method manager |
| 6077 | // here because we are not holding our lock. |
| 6078 | if (mInputMethodManager != null) { |
| 6079 | mInputMethodManager.addClient(client, inputContext, |
| 6080 | mUid, mPid); |
| 6081 | } else { |
| 6082 | client.setUsingInputMethod(false); |
| 6083 | } |
| 6084 | client.asBinder().linkToDeath(this, 0); |
| 6085 | } catch (RemoteException e) { |
| 6086 | // The caller has died, so we can just forget about this. |
| 6087 | try { |
| 6088 | if (mInputMethodManager != null) { |
| 6089 | mInputMethodManager.removeClient(client); |
| 6090 | } |
| 6091 | } catch (RemoteException ee) { |
| 6092 | } |
| 6093 | } finally { |
| 6094 | Binder.restoreCallingIdentity(ident); |
| 6095 | } |
| 6096 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6097 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6098 | @Override |
| 6099 | public boolean onTransact(int code, Parcel data, Parcel reply, int flags) |
| 6100 | throws RemoteException { |
| 6101 | try { |
| 6102 | return super.onTransact(code, data, reply, flags); |
| 6103 | } catch (RuntimeException e) { |
| 6104 | // Log all 'real' exceptions thrown to the caller |
| 6105 | if (!(e instanceof SecurityException)) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6106 | Slog.e(TAG, "Window Session Crash", e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6107 | } |
| 6108 | throw e; |
| 6109 | } |
| 6110 | } |
| 6111 | |
| 6112 | public void binderDied() { |
| 6113 | // Note: it is safe to call in to the input method manager |
| 6114 | // here because we are not holding our lock. |
| 6115 | try { |
| 6116 | if (mInputMethodManager != null) { |
| 6117 | mInputMethodManager.removeClient(mClient); |
| 6118 | } |
| 6119 | } catch (RemoteException e) { |
| 6120 | } |
| 6121 | synchronized(mWindowMap) { |
| Suchi Amalapurapu | fff2fda | 2009-06-30 21:36:16 -0700 | [diff] [blame] | 6122 | mClient.asBinder().unlinkToDeath(this, 0); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6123 | mClientDead = true; |
| 6124 | killSessionLocked(); |
| 6125 | } |
| 6126 | } |
| 6127 | |
| 6128 | public int add(IWindow window, WindowManager.LayoutParams attrs, |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 6129 | int viewVisibility, Rect outContentInsets, InputChannel outInputChannel) { |
| 6130 | return addWindow(this, window, attrs, viewVisibility, outContentInsets, |
| 6131 | outInputChannel); |
| 6132 | } |
| 6133 | |
| 6134 | public int addWithoutInputChannel(IWindow window, WindowManager.LayoutParams attrs, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6135 | int viewVisibility, Rect outContentInsets) { |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 6136 | return addWindow(this, window, attrs, viewVisibility, outContentInsets, null); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6137 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6138 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6139 | public void remove(IWindow window) { |
| 6140 | removeWindow(this, window); |
| 6141 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6142 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6143 | public int relayout(IWindow window, WindowManager.LayoutParams attrs, |
| 6144 | int requestedWidth, int requestedHeight, int viewFlags, |
| 6145 | boolean insetsPending, Rect outFrame, Rect outContentInsets, |
| Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 6146 | Rect outVisibleInsets, Configuration outConfig, Surface outSurface) { |
| Dianne Hackborn | f123e49 | 2010-09-24 11:16:23 -0700 | [diff] [blame] | 6147 | //Log.d(TAG, ">>>>>> ENTERED relayout from " + Binder.getCallingPid()); |
| 6148 | int res = relayoutWindow(this, window, attrs, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6149 | requestedWidth, requestedHeight, viewFlags, insetsPending, |
| Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 6150 | outFrame, outContentInsets, outVisibleInsets, outConfig, outSurface); |
| Dianne Hackborn | f123e49 | 2010-09-24 11:16:23 -0700 | [diff] [blame] | 6151 | //Log.d(TAG, "<<<<<< EXITING relayout to " + Binder.getCallingPid()); |
| 6152 | return res; |
| 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 | public void setTransparentRegion(IWindow window, Region region) { |
| 6156 | setTransparentRegionWindow(this, window, region); |
| 6157 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6158 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6159 | public void setInsets(IWindow window, int touchableInsets, |
| 6160 | Rect contentInsets, Rect visibleInsets) { |
| 6161 | setInsetsWindow(this, window, touchableInsets, contentInsets, |
| 6162 | visibleInsets); |
| 6163 | } |
| 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 | public void getDisplayFrame(IWindow window, Rect outDisplayFrame) { |
| 6166 | getWindowDisplayFrame(this, window, outDisplayFrame); |
| 6167 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6168 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6169 | public void finishDrawing(IWindow window) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6170 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6171 | TAG, "IWindow finishDrawing called for " + window); |
| 6172 | finishDrawingWindow(this, window); |
| 6173 | } |
| 6174 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6175 | public void setInTouchMode(boolean mode) { |
| 6176 | synchronized(mWindowMap) { |
| 6177 | mInTouchMode = mode; |
| 6178 | } |
| 6179 | } |
| 6180 | |
| 6181 | public boolean getInTouchMode() { |
| 6182 | synchronized(mWindowMap) { |
| 6183 | return mInTouchMode; |
| 6184 | } |
| 6185 | } |
| 6186 | |
| 6187 | public boolean performHapticFeedback(IWindow window, int effectId, |
| 6188 | boolean always) { |
| 6189 | synchronized(mWindowMap) { |
| 6190 | long ident = Binder.clearCallingIdentity(); |
| 6191 | try { |
| The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 6192 | return mPolicy.performHapticFeedbackLw( |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 6193 | windowForClientLocked(this, window, true), |
| 6194 | effectId, always); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6195 | } finally { |
| 6196 | Binder.restoreCallingIdentity(ident); |
| 6197 | } |
| 6198 | } |
| 6199 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6200 | |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 6201 | /* Drag/drop */ |
| 6202 | public IBinder prepareDrag(IWindow window, boolean localOnly, |
| 6203 | int width, int height, Surface outSurface) { |
| 6204 | return prepareDragSurface(window, mSurfaceSession, localOnly, |
| 6205 | width, height, outSurface); |
| 6206 | } |
| 6207 | |
| 6208 | public boolean performDrag(IWindow window, IBinder dragToken, |
| 6209 | float touchX, float touchY, float thumbCenterX, float thumbCenterY, |
| 6210 | ClipData data) { |
| 6211 | if (DEBUG_DRAG) { |
| 6212 | Slog.d(TAG, "perform drag: win=" + window + " data=" + data); |
| 6213 | } |
| 6214 | |
| 6215 | synchronized (mWindowMap) { |
| 6216 | if (mDragState == null) { |
| 6217 | Slog.w(TAG, "No drag prepared"); |
| 6218 | throw new IllegalStateException("performDrag() without prepareDrag()"); |
| 6219 | } |
| 6220 | |
| 6221 | if (dragToken != mDragState.mToken) { |
| 6222 | Slog.w(TAG, "Performing mismatched drag"); |
| 6223 | throw new IllegalStateException("performDrag() does not match prepareDrag()"); |
| 6224 | } |
| 6225 | |
| 6226 | WindowState callingWin = windowForClientLocked(null, window, false); |
| 6227 | if (callingWin == null) { |
| 6228 | Slog.w(TAG, "Bad requesting window " + window); |
| 6229 | return false; // !!! TODO: throw here? |
| 6230 | } |
| 6231 | |
| 6232 | // !!! TODO: if input is not still focused on the initiating window, fail |
| 6233 | // the drag initiation (e.g. an alarm window popped up just as the application |
| 6234 | // called performDrag() |
| 6235 | |
| 6236 | mH.removeMessages(H.DRAG_START_TIMEOUT, window.asBinder()); |
| 6237 | |
| Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 6238 | // !!! TODO: extract the current touch (x, y) in screen coordinates. That |
| 6239 | // will let us eliminate the (touchX,touchY) parameters from the API. |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 6240 | |
| Chris Tate | b478f46 | 2010-10-15 16:02:26 -0700 | [diff] [blame] | 6241 | // !!! FIXME: put all this heavy stuff onto the mH looper, as well as |
| 6242 | // the actual drag event dispatch stuff in the dragstate |
| 6243 | |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 6244 | mDragState.register(); |
| 6245 | mInputMonitor.updateInputWindowsLw(); |
| Chris Tate | ef70a07 | 2010-10-22 19:10:34 -0700 | [diff] [blame] | 6246 | if (!mInputManager.transferTouchFocus(callingWin.mInputChannel, |
| 6247 | mDragState.mServerChannel)) { |
| 6248 | Slog.e(TAG, "Unable to transfer touch focus"); |
| 6249 | mDragState.unregister(); |
| 6250 | mDragState = null; |
| 6251 | mInputMonitor.updateInputWindowsLw(); |
| 6252 | return false; |
| 6253 | } |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 6254 | |
| 6255 | mDragState.mData = data; |
| Chris Tate | b478f46 | 2010-10-15 16:02:26 -0700 | [diff] [blame] | 6256 | mDragState.mCurrentX = touchX; |
| 6257 | mDragState.mCurrentY = touchY; |
| Chris Tate | b8203e9 | 2010-10-12 14:23:21 -0700 | [diff] [blame] | 6258 | mDragState.broadcastDragStartedLw(touchX, touchY); |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 6259 | |
| 6260 | // remember the thumb offsets for later |
| 6261 | mDragState.mThumbOffsetX = thumbCenterX; |
| 6262 | mDragState.mThumbOffsetY = thumbCenterY; |
| 6263 | |
| 6264 | // Make the surface visible at the proper location |
| 6265 | final Surface surface = mDragState.mSurface; |
| Chris Tate | b478f46 | 2010-10-15 16:02:26 -0700 | [diff] [blame] | 6266 | Surface.openTransaction(); |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 6267 | try { |
| 6268 | surface.setPosition((int)(touchX - thumbCenterX), |
| 6269 | (int)(touchY - thumbCenterY)); |
| Chris Tate | b478f46 | 2010-10-15 16:02:26 -0700 | [diff] [blame] | 6270 | surface.setAlpha(.7071f); |
| Chris Tate | a32dcf7 | 2010-10-14 12:13:50 -0700 | [diff] [blame] | 6271 | surface.setLayer(mDragState.getDragLayerLw()); |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 6272 | surface.show(); |
| 6273 | } finally { |
| Chris Tate | b478f46 | 2010-10-15 16:02:26 -0700 | [diff] [blame] | 6274 | Surface.closeTransaction(); |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 6275 | } |
| 6276 | } |
| 6277 | |
| 6278 | return true; // success! |
| 6279 | } |
| 6280 | |
| Chris Tate | d4533f14 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 6281 | public void reportDropResult(IWindow window, boolean consumed) { |
| 6282 | IBinder token = window.asBinder(); |
| 6283 | if (DEBUG_DRAG) { |
| 6284 | Slog.d(TAG, "Drop result=" + consumed + " reported by " + token); |
| 6285 | } |
| 6286 | |
| 6287 | synchronized (mWindowMap) { |
| 6288 | if (mDragState.mToken != token) { |
| 6289 | Slog.w(TAG, "Invalid drop-result claim by " + window); |
| 6290 | throw new IllegalStateException("reportDropResult() by non-recipient"); |
| 6291 | } |
| 6292 | |
| 6293 | // The right window has responded, even if it's no longer around, |
| 6294 | // so be sure to halt the timeout even if the later WindowState |
| 6295 | // lookup fails. |
| 6296 | mH.removeMessages(H.DRAG_END_TIMEOUT, window.asBinder()); |
| 6297 | |
| 6298 | WindowState callingWin = windowForClientLocked(null, window, false); |
| 6299 | if (callingWin == null) { |
| 6300 | Slog.w(TAG, "Bad result-reporting window " + window); |
| 6301 | return; // !!! TODO: throw here? |
| 6302 | } |
| 6303 | |
| 6304 | mDragState.mDragResult = consumed; |
| 6305 | mDragState.endDragLw(); |
| 6306 | } |
| 6307 | } |
| 6308 | |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 6309 | public void dragRecipientEntered(IWindow window) { |
| 6310 | if (DEBUG_DRAG) { |
| Chris Tate | d4533f14 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 6311 | Slog.d(TAG, "Drag into new candidate view @ " + window.asBinder()); |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 6312 | } |
| 6313 | } |
| 6314 | |
| 6315 | public void dragRecipientExited(IWindow window) { |
| 6316 | if (DEBUG_DRAG) { |
| Chris Tate | d4533f14 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 6317 | Slog.d(TAG, "Drag from old candidate view @ " + window.asBinder()); |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 6318 | } |
| 6319 | } |
| 6320 | |
| Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 6321 | 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] | 6322 | synchronized(mWindowMap) { |
| 6323 | long ident = Binder.clearCallingIdentity(); |
| 6324 | try { |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 6325 | setWindowWallpaperPositionLocked( |
| 6326 | windowForClientLocked(this, window, true), |
| Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 6327 | x, y, xStep, yStep); |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 6328 | } finally { |
| 6329 | Binder.restoreCallingIdentity(ident); |
| 6330 | } |
| 6331 | } |
| 6332 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6333 | |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 6334 | public void wallpaperOffsetsComplete(IBinder window) { |
| 6335 | WindowManagerService.this.wallpaperOffsetsComplete(window); |
| 6336 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6337 | |
| Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 6338 | public Bundle sendWallpaperCommand(IBinder window, String action, int x, int y, |
| 6339 | int z, Bundle extras, boolean sync) { |
| 6340 | synchronized(mWindowMap) { |
| 6341 | long ident = Binder.clearCallingIdentity(); |
| 6342 | try { |
| 6343 | return sendWindowWallpaperCommandLocked( |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 6344 | windowForClientLocked(this, window, true), |
| Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 6345 | action, x, y, z, extras, sync); |
| 6346 | } finally { |
| 6347 | Binder.restoreCallingIdentity(ident); |
| 6348 | } |
| 6349 | } |
| 6350 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6351 | |
| Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 6352 | public void wallpaperCommandComplete(IBinder window, Bundle result) { |
| 6353 | WindowManagerService.this.wallpaperCommandComplete(window, result); |
| 6354 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6355 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6356 | void windowAddedLocked() { |
| 6357 | if (mSurfaceSession == null) { |
| 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, "First window added to " + this + ", creating SurfaceSession"); |
| 6360 | mSurfaceSession = new SurfaceSession(); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6361 | if (SHOW_TRANSACTIONS) Slog.i( |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 6362 | TAG, " NEW SURFACE SESSION " + mSurfaceSession); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6363 | mSessions.add(this); |
| 6364 | } |
| 6365 | mNumWindow++; |
| 6366 | } |
| 6367 | |
| 6368 | void windowRemovedLocked() { |
| 6369 | mNumWindow--; |
| 6370 | killSessionLocked(); |
| 6371 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6372 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6373 | void killSessionLocked() { |
| 6374 | if (mNumWindow <= 0 && mClientDead) { |
| 6375 | mSessions.remove(this); |
| 6376 | if (mSurfaceSession != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6377 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6378 | TAG, "Last window removed from " + this |
| 6379 | + ", destroying " + mSurfaceSession); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6380 | if (SHOW_TRANSACTIONS) Slog.i( |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 6381 | TAG, " KILL SURFACE SESSION " + mSurfaceSession); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6382 | try { |
| 6383 | mSurfaceSession.kill(); |
| 6384 | } catch (Exception e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6385 | Slog.w(TAG, "Exception thrown when killing surface session " |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6386 | + mSurfaceSession + " in session " + this |
| 6387 | + ": " + e.toString()); |
| 6388 | } |
| 6389 | mSurfaceSession = null; |
| 6390 | } |
| 6391 | } |
| 6392 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6393 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6394 | void dump(PrintWriter pw, String prefix) { |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 6395 | pw.print(prefix); pw.print("mNumWindow="); pw.print(mNumWindow); |
| 6396 | pw.print(" mClientDead="); pw.print(mClientDead); |
| 6397 | pw.print(" mSurfaceSession="); pw.println(mSurfaceSession); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6398 | } |
| 6399 | |
| 6400 | @Override |
| 6401 | public String toString() { |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 6402 | return mStringName; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6403 | } |
| 6404 | } |
| 6405 | |
| 6406 | // ------------------------------------------------------------- |
| 6407 | // Client Window State |
| 6408 | // ------------------------------------------------------------- |
| 6409 | |
| 6410 | private final class WindowState implements WindowManagerPolicy.WindowState { |
| 6411 | final Session mSession; |
| 6412 | final IWindow mClient; |
| 6413 | WindowToken mToken; |
| The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 6414 | WindowToken mRootToken; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6415 | AppWindowToken mAppToken; |
| 6416 | AppWindowToken mTargetAppToken; |
| 6417 | final WindowManager.LayoutParams mAttrs = new WindowManager.LayoutParams(); |
| 6418 | final DeathRecipient mDeathRecipient; |
| 6419 | final WindowState mAttachedWindow; |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 6420 | final ArrayList<WindowState> mChildWindows = new ArrayList<WindowState>(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6421 | final int mBaseLayer; |
| 6422 | final int mSubLayer; |
| 6423 | final boolean mLayoutAttached; |
| 6424 | final boolean mIsImWindow; |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 6425 | final boolean mIsWallpaper; |
| 6426 | final boolean mIsFloatingLayer; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6427 | int mViewVisibility; |
| 6428 | boolean mPolicyVisibility = true; |
| 6429 | boolean mPolicyVisibilityAfterAnim = true; |
| 6430 | boolean mAppFreezing; |
| 6431 | Surface mSurface; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 6432 | boolean mReportDestroySurface; |
| 6433 | boolean mSurfacePendingDestroy; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6434 | boolean mAttachedHidden; // is our parent window hidden? |
| 6435 | boolean mLastHidden; // was this window last hidden? |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 6436 | boolean mWallpaperVisible; // for wallpaper, what was last vis report? |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6437 | int mRequestedWidth; |
| 6438 | int mRequestedHeight; |
| 6439 | int mLastRequestedWidth; |
| 6440 | int mLastRequestedHeight; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6441 | int mLayer; |
| 6442 | int mAnimLayer; |
| 6443 | int mLastLayer; |
| 6444 | boolean mHaveFrame; |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 6445 | boolean mObscured; |
| Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 6446 | boolean mTurnOnScreen; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6447 | |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 6448 | int mLayoutSeq = -1; |
| 6449 | |
| 6450 | Configuration mConfiguration = null; |
| 6451 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6452 | // Actual frame shown on-screen (may be modified by animation) |
| 6453 | final Rect mShownFrame = new Rect(); |
| 6454 | final Rect mLastShownFrame = new Rect(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6455 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6456 | /** |
| Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 6457 | * Set when we have changed the size of the surface, to know that |
| 6458 | * we must tell them application to resize (and thus redraw itself). |
| 6459 | */ |
| 6460 | boolean mSurfaceResized; |
| 6461 | |
| 6462 | /** |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6463 | * Insets that determine the actually visible area |
| 6464 | */ |
| 6465 | final Rect mVisibleInsets = new Rect(); |
| 6466 | final Rect mLastVisibleInsets = new Rect(); |
| 6467 | boolean mVisibleInsetsChanged; |
| 6468 | |
| 6469 | /** |
| 6470 | * Insets that are covered by system windows |
| 6471 | */ |
| 6472 | final Rect mContentInsets = new Rect(); |
| 6473 | final Rect mLastContentInsets = new Rect(); |
| 6474 | boolean mContentInsetsChanged; |
| 6475 | |
| 6476 | /** |
| 6477 | * Set to true if we are waiting for this window to receive its |
| 6478 | * given internal insets before laying out other windows based on it. |
| 6479 | */ |
| 6480 | boolean mGivenInsetsPending; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6481 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6482 | /** |
| 6483 | * These are the content insets that were given during layout for |
| 6484 | * this window, to be applied to windows behind it. |
| 6485 | */ |
| 6486 | final Rect mGivenContentInsets = new Rect(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6487 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6488 | /** |
| 6489 | * These are the visible insets that were given during layout for |
| 6490 | * this window, to be applied to windows behind it. |
| 6491 | */ |
| 6492 | final Rect mGivenVisibleInsets = new Rect(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6493 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6494 | /** |
| 6495 | * Flag indicating whether the touchable region should be adjusted by |
| 6496 | * the visible insets; if false the area outside the visible insets is |
| 6497 | * NOT touchable, so we must use those to adjust the frame during hit |
| 6498 | * tests. |
| 6499 | */ |
| 6500 | int mTouchableInsets = ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6501 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6502 | // Current transformation being applied. |
| 6503 | float mDsDx=1, mDtDx=0, mDsDy=0, mDtDy=1; |
| 6504 | float mLastDsDx=1, mLastDtDx=0, mLastDsDy=0, mLastDtDy=1; |
| 6505 | float mHScale=1, mVScale=1; |
| 6506 | float mLastHScale=1, mLastVScale=1; |
| 6507 | final Matrix mTmpMatrix = new Matrix(); |
| 6508 | |
| 6509 | // "Real" frame that the application sees. |
| 6510 | final Rect mFrame = new Rect(); |
| 6511 | final Rect mLastFrame = new Rect(); |
| 6512 | |
| 6513 | final Rect mContainingFrame = new Rect(); |
| 6514 | final Rect mDisplayFrame = new Rect(); |
| 6515 | final Rect mContentFrame = new Rect(); |
| 6516 | final Rect mVisibleFrame = new Rect(); |
| 6517 | |
| 6518 | float mShownAlpha = 1; |
| 6519 | float mAlpha = 1; |
| 6520 | float mLastAlpha = 1; |
| 6521 | |
| 6522 | // Set to true if, when the window gets displayed, it should perform |
| 6523 | // an enter animation. |
| 6524 | boolean mEnterAnimationPending; |
| 6525 | |
| 6526 | // Currently running animation. |
| 6527 | boolean mAnimating; |
| 6528 | boolean mLocalAnimating; |
| 6529 | Animation mAnimation; |
| 6530 | boolean mAnimationIsEntrance; |
| 6531 | boolean mHasTransformation; |
| 6532 | boolean mHasLocalTransformation; |
| 6533 | final Transformation mTransformation = new Transformation(); |
| 6534 | |
| Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 6535 | // If a window showing a wallpaper: the requested offset for the |
| 6536 | // wallpaper; if a wallpaper window: the currently applied offset. |
| 6537 | float mWallpaperX = -1; |
| 6538 | float mWallpaperY = -1; |
| Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 6539 | |
| 6540 | // If a window showing a wallpaper: what fraction of the offset |
| 6541 | // range corresponds to a full virtual screen. |
| 6542 | float mWallpaperXStep = -1; |
| 6543 | float mWallpaperYStep = -1; |
| 6544 | |
| Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 6545 | // Wallpaper windows: pixels offset based on above variables. |
| 6546 | int mXOffset; |
| 6547 | int mYOffset; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6548 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6549 | // This is set after IWindowSession.relayout() has been called at |
| 6550 | // least once for the window. It allows us to detect the situation |
| 6551 | // where we don't yet have a surface, but should have one soon, so |
| 6552 | // we can give the window focus before waiting for the relayout. |
| 6553 | boolean mRelayoutCalled; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6554 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6555 | // This is set after the Surface has been created but before the |
| 6556 | // window has been drawn. During this time the surface is hidden. |
| 6557 | boolean mDrawPending; |
| 6558 | |
| 6559 | // This is set after the window has finished drawing for the first |
| 6560 | // time but before its surface is shown. The surface will be |
| 6561 | // displayed when the next layout is run. |
| 6562 | boolean mCommitDrawPending; |
| 6563 | |
| 6564 | // This is set during the time after the window's drawing has been |
| 6565 | // committed, and before its surface is actually shown. It is used |
| 6566 | // to delay showing the surface until all windows in a token are ready |
| 6567 | // to be shown. |
| 6568 | boolean mReadyToShow; |
| 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 | // Set when the window has been shown in the screen the first time. |
| 6571 | boolean mHasDrawn; |
| 6572 | |
| 6573 | // Currently running an exit animation? |
| 6574 | boolean mExiting; |
| 6575 | |
| 6576 | // Currently on the mDestroySurface list? |
| 6577 | boolean mDestroying; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6578 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6579 | // Completely remove from window manager after exit animation? |
| 6580 | boolean mRemoveOnExit; |
| 6581 | |
| 6582 | // Set when the orientation is changing and this window has not yet |
| 6583 | // been updated for the new orientation. |
| 6584 | boolean mOrientationChanging; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6585 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6586 | // Is this window now (or just being) removed? |
| 6587 | boolean mRemoved; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6588 | |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 6589 | // For debugging, this is the last information given to the surface flinger. |
| 6590 | boolean mSurfaceShown; |
| 6591 | int mSurfaceX, mSurfaceY, mSurfaceW, mSurfaceH; |
| 6592 | int mSurfaceLayer; |
| 6593 | float mSurfaceAlpha; |
| 6594 | |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 6595 | // Input channel |
| 6596 | InputChannel mInputChannel; |
| 6597 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6598 | WindowState(Session s, IWindow c, WindowToken token, |
| 6599 | WindowState attachedWindow, WindowManager.LayoutParams a, |
| 6600 | int viewVisibility) { |
| 6601 | mSession = s; |
| 6602 | mClient = c; |
| 6603 | mToken = token; |
| 6604 | mAttrs.copyFrom(a); |
| 6605 | mViewVisibility = viewVisibility; |
| 6606 | DeathRecipient deathRecipient = new DeathRecipient(); |
| 6607 | mAlpha = a.alpha; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6608 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6609 | TAG, "Window " + this + " client=" + c.asBinder() |
| 6610 | + " token=" + token + " (" + mAttrs.token + ")"); |
| 6611 | try { |
| 6612 | c.asBinder().linkToDeath(deathRecipient, 0); |
| 6613 | } catch (RemoteException e) { |
| 6614 | mDeathRecipient = null; |
| 6615 | mAttachedWindow = null; |
| 6616 | mLayoutAttached = false; |
| 6617 | mIsImWindow = false; |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 6618 | mIsWallpaper = false; |
| 6619 | mIsFloatingLayer = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6620 | mBaseLayer = 0; |
| 6621 | mSubLayer = 0; |
| 6622 | return; |
| 6623 | } |
| 6624 | mDeathRecipient = deathRecipient; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6625 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6626 | if ((mAttrs.type >= FIRST_SUB_WINDOW && |
| 6627 | mAttrs.type <= LAST_SUB_WINDOW)) { |
| 6628 | // The multiplier here is to reserve space for multiple |
| 6629 | // windows in the same type layer. |
| 6630 | mBaseLayer = mPolicy.windowTypeToLayerLw( |
| 6631 | attachedWindow.mAttrs.type) * TYPE_LAYER_MULTIPLIER |
| 6632 | + TYPE_LAYER_OFFSET; |
| 6633 | mSubLayer = mPolicy.subWindowTypeToLayerLw(a.type); |
| 6634 | mAttachedWindow = attachedWindow; |
| 6635 | mAttachedWindow.mChildWindows.add(this); |
| 6636 | mLayoutAttached = mAttrs.type != |
| 6637 | WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG; |
| 6638 | mIsImWindow = attachedWindow.mAttrs.type == TYPE_INPUT_METHOD |
| 6639 | || attachedWindow.mAttrs.type == TYPE_INPUT_METHOD_DIALOG; |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 6640 | mIsWallpaper = attachedWindow.mAttrs.type == TYPE_WALLPAPER; |
| 6641 | mIsFloatingLayer = mIsImWindow || mIsWallpaper; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6642 | } else { |
| 6643 | // The multiplier here is to reserve space for multiple |
| 6644 | // windows in the same type layer. |
| 6645 | mBaseLayer = mPolicy.windowTypeToLayerLw(a.type) |
| 6646 | * TYPE_LAYER_MULTIPLIER |
| 6647 | + TYPE_LAYER_OFFSET; |
| 6648 | mSubLayer = 0; |
| 6649 | mAttachedWindow = null; |
| 6650 | mLayoutAttached = false; |
| 6651 | mIsImWindow = mAttrs.type == TYPE_INPUT_METHOD |
| 6652 | || mAttrs.type == TYPE_INPUT_METHOD_DIALOG; |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 6653 | mIsWallpaper = mAttrs.type == TYPE_WALLPAPER; |
| 6654 | mIsFloatingLayer = mIsImWindow || mIsWallpaper; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6655 | } |
| 6656 | |
| 6657 | WindowState appWin = this; |
| 6658 | while (appWin.mAttachedWindow != null) { |
| 6659 | appWin = mAttachedWindow; |
| 6660 | } |
| 6661 | WindowToken appToken = appWin.mToken; |
| 6662 | while (appToken.appWindowToken == null) { |
| 6663 | WindowToken parent = mTokenMap.get(appToken.token); |
| 6664 | if (parent == null || appToken == parent) { |
| 6665 | break; |
| 6666 | } |
| 6667 | appToken = parent; |
| 6668 | } |
| The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 6669 | mRootToken = appToken; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6670 | mAppToken = appToken.appWindowToken; |
| 6671 | |
| 6672 | mSurface = null; |
| 6673 | mRequestedWidth = 0; |
| 6674 | mRequestedHeight = 0; |
| 6675 | mLastRequestedWidth = 0; |
| 6676 | mLastRequestedHeight = 0; |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 6677 | mXOffset = 0; |
| 6678 | mYOffset = 0; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6679 | mLayer = 0; |
| 6680 | mAnimLayer = 0; |
| 6681 | mLastLayer = 0; |
| 6682 | } |
| 6683 | |
| 6684 | void attach() { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6685 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6686 | TAG, "Attaching " + this + " token=" + mToken |
| 6687 | + ", list=" + mToken.windows); |
| 6688 | mSession.windowAddedLocked(); |
| 6689 | } |
| 6690 | |
| 6691 | public void computeFrameLw(Rect pf, Rect df, Rect cf, Rect vf) { |
| 6692 | mHaveFrame = true; |
| 6693 | |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 6694 | final Rect container = mContainingFrame; |
| 6695 | container.set(pf); |
| 6696 | |
| 6697 | final Rect display = mDisplayFrame; |
| 6698 | display.set(df); |
| 6699 | |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 6700 | if ((mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0) { |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 6701 | container.intersect(mCompatibleScreenFrame); |
| Mitsuru Oshima | d2967e2 | 2009-07-20 14:01:43 -0700 | [diff] [blame] | 6702 | if ((mAttrs.flags & FLAG_LAYOUT_NO_LIMITS) == 0) { |
| 6703 | display.intersect(mCompatibleScreenFrame); |
| 6704 | } |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 6705 | } |
| 6706 | |
| 6707 | final int pw = container.right - container.left; |
| 6708 | final int ph = container.bottom - container.top; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6709 | |
| 6710 | int w,h; |
| 6711 | if ((mAttrs.flags & mAttrs.FLAG_SCALED) != 0) { |
| 6712 | w = mAttrs.width < 0 ? pw : mAttrs.width; |
| 6713 | h = mAttrs.height< 0 ? ph : mAttrs.height; |
| 6714 | } else { |
| Romain Guy | 980a938 | 2010-01-08 15:06:28 -0800 | [diff] [blame] | 6715 | w = mAttrs.width == mAttrs.MATCH_PARENT ? pw : mRequestedWidth; |
| 6716 | h = mAttrs.height== mAttrs.MATCH_PARENT ? ph : mRequestedHeight; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6717 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6718 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6719 | final Rect content = mContentFrame; |
| 6720 | content.set(cf); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6721 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6722 | final Rect visible = mVisibleFrame; |
| 6723 | visible.set(vf); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6724 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6725 | final Rect frame = mFrame; |
| Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 6726 | final int fw = frame.width(); |
| 6727 | final int fh = frame.height(); |
| 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 | //System.out.println("In: w=" + w + " h=" + h + " container=" + |
| 6730 | // container + " x=" + mAttrs.x + " y=" + mAttrs.y); |
| 6731 | |
| 6732 | Gravity.apply(mAttrs.gravity, w, h, container, |
| 6733 | (int) (mAttrs.x + mAttrs.horizontalMargin * pw), |
| 6734 | (int) (mAttrs.y + mAttrs.verticalMargin * ph), frame); |
| 6735 | |
| 6736 | //System.out.println("Out: " + mFrame); |
| 6737 | |
| 6738 | // Now make sure the window fits in the overall display. |
| 6739 | Gravity.applyDisplay(mAttrs.gravity, df, frame); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6740 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6741 | // Make sure the content and visible frames are inside of the |
| 6742 | // final window frame. |
| 6743 | if (content.left < frame.left) content.left = frame.left; |
| 6744 | if (content.top < frame.top) content.top = frame.top; |
| 6745 | if (content.right > frame.right) content.right = frame.right; |
| 6746 | if (content.bottom > frame.bottom) content.bottom = frame.bottom; |
| 6747 | if (visible.left < frame.left) visible.left = frame.left; |
| 6748 | if (visible.top < frame.top) visible.top = frame.top; |
| 6749 | if (visible.right > frame.right) visible.right = frame.right; |
| 6750 | if (visible.bottom > frame.bottom) visible.bottom = frame.bottom; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6751 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6752 | final Rect contentInsets = mContentInsets; |
| 6753 | contentInsets.left = content.left-frame.left; |
| 6754 | contentInsets.top = content.top-frame.top; |
| 6755 | contentInsets.right = frame.right-content.right; |
| 6756 | contentInsets.bottom = frame.bottom-content.bottom; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6757 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6758 | final Rect visibleInsets = mVisibleInsets; |
| 6759 | visibleInsets.left = visible.left-frame.left; |
| 6760 | visibleInsets.top = visible.top-frame.top; |
| 6761 | visibleInsets.right = frame.right-visible.right; |
| 6762 | visibleInsets.bottom = frame.bottom-visible.bottom; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6763 | |
| Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 6764 | if (mIsWallpaper && (fw != frame.width() || fh != frame.height())) { |
| 6765 | updateWallpaperOffsetLocked(this, mDisplay.getWidth(), |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 6766 | mDisplay.getHeight(), false); |
| Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -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 (localLOGV) { |
| 6770 | //if ("com.google.android.youtube".equals(mAttrs.packageName) |
| 6771 | // && mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_PANEL) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6772 | Slog.v(TAG, "Resolving (mRequestedWidth=" |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6773 | + mRequestedWidth + ", mRequestedheight=" |
| 6774 | + mRequestedHeight + ") to" + " (pw=" + pw + ", ph=" + ph |
| 6775 | + "): frame=" + mFrame.toShortString() |
| 6776 | + " ci=" + contentInsets.toShortString() |
| 6777 | + " vi=" + visibleInsets.toShortString()); |
| 6778 | //} |
| 6779 | } |
| 6780 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6781 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6782 | public Rect getFrameLw() { |
| 6783 | return mFrame; |
| 6784 | } |
| 6785 | |
| 6786 | public Rect getShownFrameLw() { |
| 6787 | return mShownFrame; |
| 6788 | } |
| 6789 | |
| 6790 | public Rect getDisplayFrameLw() { |
| 6791 | return mDisplayFrame; |
| 6792 | } |
| 6793 | |
| 6794 | public Rect getContentFrameLw() { |
| 6795 | return mContentFrame; |
| 6796 | } |
| 6797 | |
| 6798 | public Rect getVisibleFrameLw() { |
| 6799 | return mVisibleFrame; |
| 6800 | } |
| 6801 | |
| 6802 | public boolean getGivenInsetsPendingLw() { |
| 6803 | return mGivenInsetsPending; |
| 6804 | } |
| 6805 | |
| 6806 | public Rect getGivenContentInsetsLw() { |
| 6807 | return mGivenContentInsets; |
| 6808 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6809 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6810 | public Rect getGivenVisibleInsetsLw() { |
| 6811 | return mGivenVisibleInsets; |
| 6812 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6813 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6814 | public WindowManager.LayoutParams getAttrs() { |
| 6815 | return mAttrs; |
| 6816 | } |
| 6817 | |
| 6818 | public int getSurfaceLayer() { |
| 6819 | return mLayer; |
| 6820 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6821 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6822 | public IApplicationToken getAppToken() { |
| 6823 | return mAppToken != null ? mAppToken.appToken : null; |
| 6824 | } |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 6825 | |
| 6826 | public long getInputDispatchingTimeoutNanos() { |
| 6827 | return mAppToken != null |
| 6828 | ? mAppToken.inputDispatchingTimeoutNanos |
| 6829 | : DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS; |
| 6830 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6831 | |
| 6832 | public boolean hasAppShownWindows() { |
| 6833 | return mAppToken != null ? mAppToken.firstWindowDrawn : false; |
| 6834 | } |
| 6835 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6836 | public void setAnimation(Animation anim) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6837 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6838 | TAG, "Setting animation in " + this + ": " + anim); |
| 6839 | mAnimating = false; |
| 6840 | mLocalAnimating = false; |
| 6841 | mAnimation = anim; |
| 6842 | mAnimation.restrictDuration(MAX_ANIMATION_DURATION); |
| 6843 | mAnimation.scaleCurrentDuration(mWindowAnimationScale); |
| 6844 | } |
| 6845 | |
| 6846 | public void clearAnimation() { |
| 6847 | if (mAnimation != null) { |
| 6848 | mAnimating = true; |
| 6849 | mLocalAnimating = false; |
| 6850 | mAnimation = null; |
| 6851 | } |
| 6852 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6853 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6854 | Surface createSurfaceLocked() { |
| 6855 | if (mSurface == null) { |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 6856 | mReportDestroySurface = false; |
| 6857 | mSurfacePendingDestroy = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6858 | mDrawPending = true; |
| 6859 | mCommitDrawPending = false; |
| 6860 | mReadyToShow = false; |
| 6861 | if (mAppToken != null) { |
| 6862 | mAppToken.allDrawn = false; |
| 6863 | } |
| 6864 | |
| 6865 | int flags = 0; |
| Mathias Agopian | 317a628 | 2009-08-13 17:29:02 -0700 | [diff] [blame] | 6866 | if (mAttrs.memoryType == MEMORY_TYPE_PUSH_BUFFERS) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6867 | flags |= Surface.PUSH_BUFFERS; |
| 6868 | } |
| 6869 | |
| 6870 | if ((mAttrs.flags&WindowManager.LayoutParams.FLAG_SECURE) != 0) { |
| 6871 | flags |= Surface.SECURE; |
| 6872 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6873 | if (DEBUG_VISIBILITY) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6874 | TAG, "Creating surface in session " |
| 6875 | + mSession.mSurfaceSession + " window " + this |
| 6876 | + " w=" + mFrame.width() |
| 6877 | + " h=" + mFrame.height() + " format=" |
| 6878 | + mAttrs.format + " flags=" + flags); |
| 6879 | |
| 6880 | int w = mFrame.width(); |
| 6881 | int h = mFrame.height(); |
| 6882 | if ((mAttrs.flags & LayoutParams.FLAG_SCALED) != 0) { |
| 6883 | // for a scaled surface, we always want the requested |
| 6884 | // size. |
| 6885 | w = mRequestedWidth; |
| 6886 | h = mRequestedHeight; |
| 6887 | } |
| 6888 | |
| Romain Guy | 9825ec6 | 2009-10-01 00:58:09 -0700 | [diff] [blame] | 6889 | // Something is wrong and SurfaceFlinger will not like this, |
| 6890 | // try to revert to sane values |
| 6891 | if (w <= 0) w = 1; |
| 6892 | if (h <= 0) h = 1; |
| 6893 | |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 6894 | mSurfaceShown = false; |
| 6895 | mSurfaceLayer = 0; |
| 6896 | mSurfaceAlpha = 1; |
| 6897 | mSurfaceX = 0; |
| 6898 | mSurfaceY = 0; |
| 6899 | mSurfaceW = w; |
| 6900 | mSurfaceH = h; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6901 | try { |
| Romain Guy | d10cd57 | 2010-10-10 13:33:22 -0700 | [diff] [blame] | 6902 | final boolean isHwAccelerated = (mAttrs.flags & |
| 6903 | WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED) != 0; |
| 6904 | final int format = isHwAccelerated ? PixelFormat.TRANSLUCENT : mAttrs.format; |
| 6905 | if (isHwAccelerated && mAttrs.format == PixelFormat.OPAQUE) { |
| 6906 | flags |= Surface.OPAQUE; |
| 6907 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6908 | mSurface = new Surface( |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6909 | mSession.mSurfaceSession, mSession.mPid, |
| Mathias Agopian | 5d26c1e | 2010-03-01 16:09:43 -0800 | [diff] [blame] | 6910 | mAttrs.getTitle().toString(), |
| Romain Guy | d10cd57 | 2010-10-10 13:33:22 -0700 | [diff] [blame] | 6911 | 0, w, h, format, flags); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6912 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " CREATE SURFACE " |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 6913 | + mSurface + " IN SESSION " |
| 6914 | + mSession.mSurfaceSession |
| 6915 | + ": pid=" + mSession.mPid + " format=" |
| 6916 | + mAttrs.format + " flags=0x" |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 6917 | + Integer.toHexString(flags) |
| 6918 | + " / " + this); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6919 | } catch (Surface.OutOfResourcesException e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6920 | Slog.w(TAG, "OutOfResourcesException creating surface"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6921 | reclaimSomeSurfaceMemoryLocked(this, "create"); |
| 6922 | return null; |
| 6923 | } catch (Exception e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6924 | Slog.e(TAG, "Exception creating surface", e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6925 | return null; |
| 6926 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6927 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6928 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6929 | TAG, "Got surface: " + mSurface |
| 6930 | + ", set left=" + mFrame.left + " top=" + mFrame.top |
| 6931 | + ", animLayer=" + mAnimLayer); |
| 6932 | if (SHOW_TRANSACTIONS) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6933 | Slog.i(TAG, ">>> OPEN TRANSACTION"); |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 6934 | if (SHOW_TRANSACTIONS) logSurface(this, |
| 6935 | "CREATE pos=(" + mFrame.left + "," + mFrame.top + ") (" + |
| 6936 | mFrame.width() + "x" + mFrame.height() + "), layer=" + |
| 6937 | mAnimLayer + " HIDE", null); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6938 | } |
| 6939 | Surface.openTransaction(); |
| 6940 | try { |
| 6941 | try { |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 6942 | mSurfaceX = mFrame.left + mXOffset; |
| Dianne Hackborn | 529bef6 | 2010-03-25 11:48:43 -0700 | [diff] [blame] | 6943 | mSurfaceY = mFrame.top + mYOffset; |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 6944 | mSurface.setPosition(mSurfaceX, mSurfaceY); |
| 6945 | mSurfaceLayer = mAnimLayer; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6946 | mSurface.setLayer(mAnimLayer); |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 6947 | mSurfaceShown = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6948 | mSurface.hide(); |
| 6949 | if ((mAttrs.flags&WindowManager.LayoutParams.FLAG_DITHER) != 0) { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 6950 | if (SHOW_TRANSACTIONS) logSurface(this, "DITHER", null); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6951 | mSurface.setFlags(Surface.SURFACE_DITHER, |
| 6952 | Surface.SURFACE_DITHER); |
| 6953 | } |
| 6954 | } catch (RuntimeException e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6955 | Slog.w(TAG, "Error creating surface in " + w, e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6956 | reclaimSomeSurfaceMemoryLocked(this, "create-init"); |
| 6957 | } |
| 6958 | mLastHidden = true; |
| 6959 | } finally { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6960 | if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6961 | Surface.closeTransaction(); |
| 6962 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6963 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6964 | TAG, "Created surface " + this); |
| 6965 | } |
| 6966 | return mSurface; |
| 6967 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6968 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6969 | void destroySurfaceLocked() { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6970 | if (mAppToken != null && this == mAppToken.startingWindow) { |
| 6971 | mAppToken.startingDisplayed = false; |
| 6972 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6973 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6974 | if (mSurface != null) { |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 6975 | mDrawPending = false; |
| 6976 | mCommitDrawPending = false; |
| 6977 | mReadyToShow = false; |
| 6978 | |
| 6979 | int i = mChildWindows.size(); |
| 6980 | while (i > 0) { |
| 6981 | i--; |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 6982 | WindowState c = mChildWindows.get(i); |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 6983 | c.mAttachedHidden = true; |
| 6984 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6985 | |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 6986 | if (mReportDestroySurface) { |
| 6987 | mReportDestroySurface = false; |
| 6988 | mSurfacePendingDestroy = true; |
| 6989 | try { |
| 6990 | mClient.dispatchGetNewSurface(); |
| 6991 | // We'll really destroy on the next time around. |
| 6992 | return; |
| 6993 | } catch (RemoteException e) { |
| 6994 | } |
| 6995 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6996 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6997 | try { |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 6998 | if (DEBUG_VISIBILITY) { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 6999 | RuntimeException e = null; |
| 7000 | if (!HIDE_STACK_CRAWLS) { |
| 7001 | e = new RuntimeException(); |
| 7002 | e.fillInStackTrace(); |
| 7003 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7004 | Slog.w(TAG, "Window " + this + " destroying surface " |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 7005 | + mSurface + ", session " + mSession, e); |
| 7006 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7007 | if (SHOW_TRANSACTIONS) { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 7008 | RuntimeException e = null; |
| 7009 | if (!HIDE_STACK_CRAWLS) { |
| 7010 | e = new RuntimeException(); |
| 7011 | e.fillInStackTrace(); |
| 7012 | } |
| 7013 | if (SHOW_TRANSACTIONS) logSurface(this, "DESTROY", e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7014 | } |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 7015 | mSurface.destroy(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7016 | } catch (RuntimeException e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7017 | Slog.w(TAG, "Exception thrown when destroying Window " + this |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7018 | + " surface " + mSurface + " session " + mSession |
| 7019 | + ": " + e.toString()); |
| 7020 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7021 | |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 7022 | mSurfaceShown = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7023 | mSurface = null; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7024 | } |
| 7025 | } |
| 7026 | |
| 7027 | boolean finishDrawingLocked() { |
| 7028 | if (mDrawPending) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7029 | if (SHOW_TRANSACTIONS || DEBUG_ORIENTATION) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7030 | TAG, "finishDrawingLocked: " + mSurface); |
| 7031 | mCommitDrawPending = true; |
| 7032 | mDrawPending = false; |
| 7033 | return true; |
| 7034 | } |
| 7035 | return false; |
| 7036 | } |
| 7037 | |
| 7038 | // This must be called while inside a transaction. |
| Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 7039 | boolean commitFinishDrawingLocked(long currentTime) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7040 | //Slog.i(TAG, "commitFinishDrawingLocked: " + mSurface); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7041 | if (!mCommitDrawPending) { |
| Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 7042 | return false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7043 | } |
| 7044 | mCommitDrawPending = false; |
| 7045 | mReadyToShow = true; |
| 7046 | final boolean starting = mAttrs.type == TYPE_APPLICATION_STARTING; |
| 7047 | final AppWindowToken atoken = mAppToken; |
| 7048 | if (atoken == null || atoken.allDrawn || starting) { |
| 7049 | performShowLocked(); |
| 7050 | } |
| Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 7051 | return true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7052 | } |
| 7053 | |
| 7054 | // This must be called while inside a transaction. |
| 7055 | boolean performShowLocked() { |
| 7056 | if (DEBUG_VISIBILITY) { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 7057 | RuntimeException e = null; |
| 7058 | if (!HIDE_STACK_CRAWLS) { |
| 7059 | e = new RuntimeException(); |
| 7060 | e.fillInStackTrace(); |
| 7061 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7062 | Slog.v(TAG, "performShow on " + this |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7063 | + ": readyToShow=" + mReadyToShow + " readyForDisplay=" + isReadyForDisplay() |
| 7064 | + " starting=" + (mAttrs.type == TYPE_APPLICATION_STARTING), e); |
| 7065 | } |
| 7066 | if (mReadyToShow && isReadyForDisplay()) { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 7067 | if (SHOW_TRANSACTIONS || DEBUG_ORIENTATION) logSurface(this, |
| 7068 | "SHOW (performShowLocked)", null); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7069 | if (DEBUG_VISIBILITY) Slog.v(TAG, "Showing " + this |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7070 | + " during animation: policyVis=" + mPolicyVisibility |
| 7071 | + " attHidden=" + mAttachedHidden |
| 7072 | + " tok.hiddenRequested=" |
| 7073 | + (mAppToken != null ? mAppToken.hiddenRequested : false) |
| Dianne Hackborn | 248b188 | 2009-09-16 16:46:44 -0700 | [diff] [blame] | 7074 | + " tok.hidden=" |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7075 | + (mAppToken != null ? mAppToken.hidden : false) |
| 7076 | + " animating=" + mAnimating |
| 7077 | + " tok animating=" |
| 7078 | + (mAppToken != null ? mAppToken.animating : false)); |
| 7079 | if (!showSurfaceRobustlyLocked(this)) { |
| 7080 | return false; |
| 7081 | } |
| 7082 | mLastAlpha = -1; |
| 7083 | mHasDrawn = true; |
| 7084 | mLastHidden = false; |
| 7085 | mReadyToShow = false; |
| 7086 | enableScreenIfNeededLocked(); |
| 7087 | |
| 7088 | applyEnterAnimationLocked(this); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7089 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7090 | int i = mChildWindows.size(); |
| 7091 | while (i > 0) { |
| 7092 | i--; |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 7093 | WindowState c = mChildWindows.get(i); |
| Dianne Hackborn | f09c1a2 | 2010-04-22 15:59:21 -0700 | [diff] [blame] | 7094 | if (c.mAttachedHidden) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7095 | c.mAttachedHidden = false; |
| Dianne Hackborn | f09c1a2 | 2010-04-22 15:59:21 -0700 | [diff] [blame] | 7096 | if (c.mSurface != null) { |
| 7097 | c.performShowLocked(); |
| 7098 | // It hadn't been shown, which means layout not |
| 7099 | // performed on it, so now we want to make sure to |
| 7100 | // do a layout. If called from within the transaction |
| 7101 | // loop, this will cause it to restart with a new |
| 7102 | // layout. |
| 7103 | mLayoutNeeded = true; |
| 7104 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7105 | } |
| 7106 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7107 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7108 | if (mAttrs.type != TYPE_APPLICATION_STARTING |
| 7109 | && mAppToken != null) { |
| 7110 | mAppToken.firstWindowDrawn = true; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7111 | |
| Dianne Hackborn | 248b188 | 2009-09-16 16:46:44 -0700 | [diff] [blame] | 7112 | if (mAppToken.startingData != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7113 | if (DEBUG_STARTING_WINDOW || DEBUG_ANIM) Slog.v(TAG, |
| Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 7114 | "Finish starting " + mToken |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7115 | + ": first real window is shown, no animation"); |
| Dianne Hackborn | 248b188 | 2009-09-16 16:46:44 -0700 | [diff] [blame] | 7116 | // If this initial window is animating, stop it -- we |
| 7117 | // will do an animation to reveal it from behind the |
| 7118 | // starting window, so there is no need for it to also |
| 7119 | // be doing its own stuff. |
| 7120 | if (mAnimation != null) { |
| 7121 | mAnimation = null; |
| 7122 | // Make sure we clean up the animation. |
| 7123 | mAnimating = true; |
| 7124 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7125 | mFinishedStarting.add(mAppToken); |
| 7126 | mH.sendEmptyMessage(H.FINISHED_STARTING); |
| 7127 | } |
| 7128 | mAppToken.updateReportedVisibilityLocked(); |
| 7129 | } |
| 7130 | } |
| 7131 | return true; |
| 7132 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7133 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7134 | // This must be called while inside a transaction. Returns true if |
| 7135 | // there is more animation to run. |
| 7136 | boolean stepAnimationLocked(long currentTime, int dw, int dh) { |
| Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 7137 | if (!mDisplayFrozen && mPolicy.isScreenOn()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7138 | // We will run animations as long as the display isn't frozen. |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7139 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7140 | if (!mDrawPending && !mCommitDrawPending && mAnimation != null) { |
| 7141 | mHasTransformation = true; |
| 7142 | mHasLocalTransformation = true; |
| 7143 | if (!mLocalAnimating) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7144 | if (DEBUG_ANIM) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7145 | TAG, "Starting animation in " + this + |
| 7146 | " @ " + currentTime + ": ww=" + mFrame.width() + " wh=" + mFrame.height() + |
| 7147 | " dw=" + dw + " dh=" + dh + " scale=" + mWindowAnimationScale); |
| 7148 | mAnimation.initialize(mFrame.width(), mFrame.height(), dw, dh); |
| 7149 | mAnimation.setStartTime(currentTime); |
| 7150 | mLocalAnimating = true; |
| 7151 | mAnimating = true; |
| 7152 | } |
| 7153 | mTransformation.clear(); |
| 7154 | final boolean more = mAnimation.getTransformation( |
| 7155 | currentTime, mTransformation); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7156 | if (DEBUG_ANIM) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7157 | TAG, "Stepped animation in " + this + |
| 7158 | ": more=" + more + ", xform=" + mTransformation); |
| 7159 | if (more) { |
| 7160 | // we're not done! |
| 7161 | return true; |
| 7162 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7163 | if (DEBUG_ANIM) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7164 | TAG, "Finished animation in " + this + |
| 7165 | " @ " + currentTime); |
| 7166 | mAnimation = null; |
| 7167 | //WindowManagerService.this.dump(); |
| 7168 | } |
| 7169 | mHasLocalTransformation = false; |
| 7170 | if ((!mLocalAnimating || mAnimationIsEntrance) && mAppToken != null |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 7171 | && mAppToken.animation != null) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7172 | // When our app token is animating, we kind-of pretend like |
| 7173 | // we are as well. Note the mLocalAnimating mAnimationIsEntrance |
| 7174 | // part of this check means that we will only do this if |
| 7175 | // our window is not currently exiting, or it is not |
| 7176 | // locally animating itself. The idea being that one that |
| 7177 | // is exiting and doing a local animation should be removed |
| 7178 | // once that animation is done. |
| 7179 | mAnimating = true; |
| 7180 | mHasTransformation = true; |
| 7181 | mTransformation.clear(); |
| 7182 | return false; |
| 7183 | } else if (mHasTransformation) { |
| 7184 | // Little trick to get through the path below to act like |
| 7185 | // we have finished an animation. |
| 7186 | mAnimating = true; |
| 7187 | } else if (isAnimating()) { |
| 7188 | mAnimating = true; |
| 7189 | } |
| 7190 | } else if (mAnimation != null) { |
| 7191 | // If the display is frozen, and there is a pending animation, |
| 7192 | // clear it and make sure we run the cleanup code. |
| 7193 | mAnimating = true; |
| 7194 | mLocalAnimating = true; |
| 7195 | mAnimation = null; |
| 7196 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7197 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7198 | if (!mAnimating && !mLocalAnimating) { |
| 7199 | return false; |
| 7200 | } |
| 7201 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7202 | if (DEBUG_ANIM) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7203 | TAG, "Animation done in " + this + ": exiting=" + mExiting |
| 7204 | + ", reportedVisible=" |
| 7205 | + (mAppToken != null ? mAppToken.reportedVisible : false)); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7206 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7207 | mAnimating = false; |
| 7208 | mLocalAnimating = false; |
| 7209 | mAnimation = null; |
| 7210 | mAnimLayer = mLayer; |
| 7211 | if (mIsImWindow) { |
| 7212 | mAnimLayer += mInputMethodAnimLayerAdjustment; |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 7213 | } else if (mIsWallpaper) { |
| 7214 | mAnimLayer += mWallpaperAnimLayerAdjustment; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7215 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7216 | if (DEBUG_LAYERS) Slog.v(TAG, "Stepping win " + this |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7217 | + " anim layer: " + mAnimLayer); |
| 7218 | mHasTransformation = false; |
| 7219 | mHasLocalTransformation = false; |
| Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 7220 | if (mPolicyVisibility != mPolicyVisibilityAfterAnim) { |
| 7221 | if (DEBUG_VISIBILITY) { |
| 7222 | Slog.v(TAG, "Policy visibility changing after anim in " + this + ": " |
| 7223 | + mPolicyVisibilityAfterAnim); |
| 7224 | } |
| 7225 | mPolicyVisibility = mPolicyVisibilityAfterAnim; |
| 7226 | if (!mPolicyVisibility) { |
| 7227 | if (mCurrentFocus == this) { |
| 7228 | mFocusMayChange = true; |
| 7229 | } |
| 7230 | // Window is no longer visible -- make sure if we were waiting |
| 7231 | // for it to be displayed before enabling the display, that |
| 7232 | // we allow the display to be enabled now. |
| 7233 | enableScreenIfNeededLocked(); |
| 7234 | } |
| Dianne Hackborn | f3bea9c | 2009-12-09 18:26:21 -0800 | [diff] [blame] | 7235 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7236 | mTransformation.clear(); |
| 7237 | if (mHasDrawn |
| 7238 | && mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING |
| 7239 | && mAppToken != null |
| 7240 | && mAppToken.firstWindowDrawn |
| 7241 | && mAppToken.startingData != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7242 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Finish starting " |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7243 | + mToken + ": first real window done animating"); |
| 7244 | mFinishedStarting.add(mAppToken); |
| 7245 | mH.sendEmptyMessage(H.FINISHED_STARTING); |
| 7246 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7247 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7248 | finishExit(); |
| 7249 | |
| 7250 | if (mAppToken != null) { |
| 7251 | mAppToken.updateReportedVisibilityLocked(); |
| 7252 | } |
| 7253 | |
| 7254 | return false; |
| 7255 | } |
| 7256 | |
| 7257 | void finishExit() { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7258 | if (DEBUG_ANIM) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7259 | TAG, "finishExit in " + this |
| 7260 | + ": exiting=" + mExiting |
| 7261 | + " remove=" + mRemoveOnExit |
| 7262 | + " windowAnimating=" + isWindowAnimating()); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7263 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7264 | final int N = mChildWindows.size(); |
| 7265 | for (int i=0; i<N; i++) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 7266 | mChildWindows.get(i).finishExit(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7267 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7268 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7269 | if (!mExiting) { |
| 7270 | return; |
| 7271 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7272 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7273 | if (isWindowAnimating()) { |
| 7274 | return; |
| 7275 | } |
| 7276 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7277 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7278 | TAG, "Exit animation finished in " + this |
| 7279 | + ": remove=" + mRemoveOnExit); |
| 7280 | if (mSurface != null) { |
| 7281 | mDestroySurface.add(this); |
| 7282 | mDestroying = true; |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 7283 | if (SHOW_TRANSACTIONS) logSurface(this, "HIDE (finishExit)", null); |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 7284 | mSurfaceShown = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7285 | try { |
| 7286 | mSurface.hide(); |
| 7287 | } catch (RuntimeException e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7288 | Slog.w(TAG, "Error hiding surface in " + this, e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7289 | } |
| 7290 | mLastHidden = true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7291 | } |
| 7292 | mExiting = false; |
| 7293 | if (mRemoveOnExit) { |
| 7294 | mPendingRemove.add(this); |
| 7295 | mRemoveOnExit = false; |
| 7296 | } |
| 7297 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7298 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7299 | boolean isIdentityMatrix(float dsdx, float dtdx, float dsdy, float dtdy) { |
| 7300 | if (dsdx < .99999f || dsdx > 1.00001f) return false; |
| 7301 | if (dtdy < .99999f || dtdy > 1.00001f) return false; |
| 7302 | if (dtdx < -.000001f || dtdx > .000001f) return false; |
| 7303 | if (dsdy < -.000001f || dsdy > .000001f) return false; |
| 7304 | return true; |
| 7305 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7306 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7307 | void computeShownFrameLocked() { |
| 7308 | final boolean selfTransformation = mHasLocalTransformation; |
| 7309 | Transformation attachedTransformation = |
| 7310 | (mAttachedWindow != null && mAttachedWindow.mHasLocalTransformation) |
| 7311 | ? mAttachedWindow.mTransformation : null; |
| 7312 | Transformation appTransformation = |
| 7313 | (mAppToken != null && mAppToken.hasTransformation) |
| 7314 | ? mAppToken.transformation : null; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7315 | |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 7316 | // Wallpapers are animated based on the "real" window they |
| 7317 | // are currently targeting. |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 7318 | if (mAttrs.type == TYPE_WALLPAPER && mLowerWallpaperTarget == null |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 7319 | && mWallpaperTarget != null) { |
| Dianne Hackborn | 5baba16 | 2009-09-23 17:01:12 -0700 | [diff] [blame] | 7320 | if (mWallpaperTarget.mHasLocalTransformation && |
| 7321 | mWallpaperTarget.mAnimation != null && |
| 7322 | !mWallpaperTarget.mAnimation.getDetachWallpaper()) { |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 7323 | attachedTransformation = mWallpaperTarget.mTransformation; |
| Dianne Hackborn | 5baba16 | 2009-09-23 17:01:12 -0700 | [diff] [blame] | 7324 | if (DEBUG_WALLPAPER && attachedTransformation != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7325 | Slog.v(TAG, "WP target attached xform: " + attachedTransformation); |
| Dianne Hackborn | 5baba16 | 2009-09-23 17:01:12 -0700 | [diff] [blame] | 7326 | } |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 7327 | } |
| 7328 | if (mWallpaperTarget.mAppToken != null && |
| Dianne Hackborn | 5baba16 | 2009-09-23 17:01:12 -0700 | [diff] [blame] | 7329 | mWallpaperTarget.mAppToken.hasTransformation && |
| 7330 | mWallpaperTarget.mAppToken.animation != null && |
| 7331 | !mWallpaperTarget.mAppToken.animation.getDetachWallpaper()) { |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 7332 | appTransformation = mWallpaperTarget.mAppToken.transformation; |
| Dianne Hackborn | 5baba16 | 2009-09-23 17:01:12 -0700 | [diff] [blame] | 7333 | if (DEBUG_WALLPAPER && appTransformation != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7334 | Slog.v(TAG, "WP target app xform: " + appTransformation); |
| Dianne Hackborn | 5baba16 | 2009-09-23 17:01:12 -0700 | [diff] [blame] | 7335 | } |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 7336 | } |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 7337 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7338 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7339 | if (selfTransformation || attachedTransformation != null |
| 7340 | || appTransformation != null) { |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7341 | // cache often used attributes locally |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7342 | final Rect frame = mFrame; |
| 7343 | final float tmpFloats[] = mTmpFloats; |
| 7344 | final Matrix tmpMatrix = mTmpMatrix; |
| 7345 | |
| 7346 | // Compute the desired transformation. |
| Dianne Hackborn | 65c2387 | 2009-09-18 17:47:02 -0700 | [diff] [blame] | 7347 | tmpMatrix.setTranslate(0, 0); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7348 | if (selfTransformation) { |
| Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 7349 | tmpMatrix.postConcat(mTransformation.getMatrix()); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7350 | } |
| Dianne Hackborn | 65c2387 | 2009-09-18 17:47:02 -0700 | [diff] [blame] | 7351 | tmpMatrix.postTranslate(frame.left, frame.top); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7352 | if (attachedTransformation != null) { |
| Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 7353 | tmpMatrix.postConcat(attachedTransformation.getMatrix()); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7354 | } |
| 7355 | if (appTransformation != null) { |
| Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 7356 | tmpMatrix.postConcat(appTransformation.getMatrix()); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7357 | } |
| 7358 | |
| 7359 | // "convert" it into SurfaceFlinger's format |
| 7360 | // (a 2x2 matrix + an offset) |
| 7361 | // Here we must not transform the position of the surface |
| 7362 | // since it is already included in the transformation. |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7363 | //Slog.i(TAG, "Transform: " + matrix); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7364 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7365 | tmpMatrix.getValues(tmpFloats); |
| 7366 | mDsDx = tmpFloats[Matrix.MSCALE_X]; |
| 7367 | mDtDx = tmpFloats[Matrix.MSKEW_X]; |
| 7368 | mDsDy = tmpFloats[Matrix.MSKEW_Y]; |
| 7369 | mDtDy = tmpFloats[Matrix.MSCALE_Y]; |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 7370 | int x = (int)tmpFloats[Matrix.MTRANS_X] + mXOffset; |
| 7371 | int y = (int)tmpFloats[Matrix.MTRANS_Y] + mYOffset; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7372 | int w = frame.width(); |
| 7373 | int h = frame.height(); |
| 7374 | mShownFrame.set(x, y, x+w, y+h); |
| 7375 | |
| 7376 | // Now set the alpha... but because our current hardware |
| 7377 | // can't do alpha transformation on a non-opaque surface, |
| 7378 | // turn it off if we are running an animation that is also |
| 7379 | // transforming since it is more important to have that |
| 7380 | // animation be smooth. |
| 7381 | mShownAlpha = mAlpha; |
| 7382 | if (!mLimitedAlphaCompositing |
| 7383 | || (!PixelFormat.formatHasAlpha(mAttrs.format) |
| 7384 | || (isIdentityMatrix(mDsDx, mDtDx, mDsDy, mDtDy) |
| 7385 | && x == frame.left && y == frame.top))) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7386 | //Slog.i(TAG, "Applying alpha transform"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7387 | if (selfTransformation) { |
| 7388 | mShownAlpha *= mTransformation.getAlpha(); |
| 7389 | } |
| 7390 | if (attachedTransformation != null) { |
| 7391 | mShownAlpha *= attachedTransformation.getAlpha(); |
| 7392 | } |
| 7393 | if (appTransformation != null) { |
| 7394 | mShownAlpha *= appTransformation.getAlpha(); |
| 7395 | } |
| 7396 | } else { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7397 | //Slog.i(TAG, "Not applying alpha transform"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7398 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7399 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7400 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7401 | TAG, "Continuing animation in " + this + |
| 7402 | ": " + mShownFrame + |
| 7403 | ", alpha=" + mTransformation.getAlpha()); |
| 7404 | return; |
| 7405 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7406 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7407 | mShownFrame.set(mFrame); |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 7408 | if (mXOffset != 0 || mYOffset != 0) { |
| 7409 | mShownFrame.offset(mXOffset, mYOffset); |
| 7410 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7411 | mShownAlpha = mAlpha; |
| 7412 | mDsDx = 1; |
| 7413 | mDtDx = 0; |
| 7414 | mDsDy = 0; |
| 7415 | mDtDy = 1; |
| 7416 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7417 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7418 | /** |
| 7419 | * Is this window visible? It is not visible if there is no |
| 7420 | * surface, or we are in the process of running an exit animation |
| 7421 | * that will remove the surface, or its app token has been hidden. |
| 7422 | */ |
| 7423 | public boolean isVisibleLw() { |
| 7424 | final AppWindowToken atoken = mAppToken; |
| 7425 | return mSurface != null && mPolicyVisibility && !mAttachedHidden |
| 7426 | && (atoken == null || !atoken.hiddenRequested) |
| 7427 | && !mExiting && !mDestroying; |
| 7428 | } |
| 7429 | |
| 7430 | /** |
| Dianne Hackborn | 3d163f07 | 2009-10-07 21:26:57 -0700 | [diff] [blame] | 7431 | * Like {@link #isVisibleLw}, but also counts a window that is currently |
| 7432 | * "hidden" behind the keyguard as visible. This allows us to apply |
| 7433 | * things like window flags that impact the keyguard. |
| 7434 | * XXX I am starting to think we need to have ANOTHER visibility flag |
| 7435 | * for this "hidden behind keyguard" state rather than overloading |
| 7436 | * mPolicyVisibility. Ungh. |
| 7437 | */ |
| 7438 | public boolean isVisibleOrBehindKeyguardLw() { |
| 7439 | final AppWindowToken atoken = mAppToken; |
| 7440 | return mSurface != null && !mAttachedHidden |
| 7441 | && (atoken == null ? mPolicyVisibility : !atoken.hiddenRequested) |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 7442 | && !mDrawPending && !mCommitDrawPending |
| Dianne Hackborn | 3d163f07 | 2009-10-07 21:26:57 -0700 | [diff] [blame] | 7443 | && !mExiting && !mDestroying; |
| 7444 | } |
| 7445 | |
| 7446 | /** |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7447 | * Is this window visible, ignoring its app token? It is not visible |
| 7448 | * if there is no surface, or we are in the process of running an exit animation |
| 7449 | * that will remove the surface. |
| 7450 | */ |
| 7451 | public boolean isWinVisibleLw() { |
| 7452 | final AppWindowToken atoken = mAppToken; |
| 7453 | return mSurface != null && mPolicyVisibility && !mAttachedHidden |
| 7454 | && (atoken == null || !atoken.hiddenRequested || atoken.animating) |
| 7455 | && !mExiting && !mDestroying; |
| 7456 | } |
| 7457 | |
| 7458 | /** |
| 7459 | * The same as isVisible(), but follows the current hidden state of |
| 7460 | * the associated app token, not the pending requested hidden state. |
| 7461 | */ |
| 7462 | boolean isVisibleNow() { |
| 7463 | return mSurface != null && mPolicyVisibility && !mAttachedHidden |
| The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 7464 | && !mRootToken.hidden && !mExiting && !mDestroying; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7465 | } |
| 7466 | |
| 7467 | /** |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 7468 | * Can this window possibly be a drag/drop target? The test here is |
| 7469 | * a combination of the above "visible now" with the check that the |
| 7470 | * Input Manager uses when discarding windows from input consideration. |
| 7471 | */ |
| 7472 | boolean isPotentialDragTarget() { |
| 7473 | return isVisibleNow() && (mInputChannel != null) && !mRemoved; |
| 7474 | } |
| 7475 | |
| 7476 | /** |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7477 | * Same as isVisible(), but we also count it as visible between the |
| 7478 | * call to IWindowSession.add() and the first relayout(). |
| 7479 | */ |
| 7480 | boolean isVisibleOrAdding() { |
| 7481 | final AppWindowToken atoken = mAppToken; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 7482 | return ((mSurface != null && !mReportDestroySurface) |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7483 | || (!mRelayoutCalled && mViewVisibility == View.VISIBLE)) |
| 7484 | && mPolicyVisibility && !mAttachedHidden |
| 7485 | && (atoken == null || !atoken.hiddenRequested) |
| 7486 | && !mExiting && !mDestroying; |
| 7487 | } |
| 7488 | |
| 7489 | /** |
| 7490 | * Is this window currently on-screen? It is on-screen either if it |
| 7491 | * is visible or it is currently running an animation before no longer |
| 7492 | * being visible. |
| 7493 | */ |
| 7494 | boolean isOnScreen() { |
| 7495 | final AppWindowToken atoken = mAppToken; |
| 7496 | if (atoken != null) { |
| 7497 | return mSurface != null && mPolicyVisibility && !mDestroying |
| 7498 | && ((!mAttachedHidden && !atoken.hiddenRequested) |
| Dianne Hackborn | 0cd4887 | 2009-08-13 18:51:59 -0700 | [diff] [blame] | 7499 | || mAnimation != null || atoken.animation != null); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7500 | } else { |
| 7501 | return mSurface != null && mPolicyVisibility && !mDestroying |
| Dianne Hackborn | 0cd4887 | 2009-08-13 18:51:59 -0700 | [diff] [blame] | 7502 | && (!mAttachedHidden || mAnimation != null); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7503 | } |
| 7504 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7505 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7506 | /** |
| 7507 | * Like isOnScreen(), but we don't return true if the window is part |
| 7508 | * of a transition that has not yet been started. |
| 7509 | */ |
| 7510 | boolean isReadyForDisplay() { |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 7511 | if (mRootToken.waitingToShow && |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 7512 | mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 7513 | return false; |
| 7514 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7515 | final AppWindowToken atoken = mAppToken; |
| Dianne Hackborn | 0cd4887 | 2009-08-13 18:51:59 -0700 | [diff] [blame] | 7516 | final boolean animating = atoken != null |
| 7517 | ? (atoken.animation != null) : false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7518 | return mSurface != null && mPolicyVisibility && !mDestroying |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 7519 | && ((!mAttachedHidden && mViewVisibility == View.VISIBLE |
| 7520 | && !mRootToken.hidden) |
| Dianne Hackborn | 0cd4887 | 2009-08-13 18:51:59 -0700 | [diff] [blame] | 7521 | || mAnimation != null || animating); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7522 | } |
| 7523 | |
| 7524 | /** Is the window or its container currently animating? */ |
| 7525 | boolean isAnimating() { |
| 7526 | final WindowState attached = mAttachedWindow; |
| 7527 | final AppWindowToken atoken = mAppToken; |
| 7528 | return mAnimation != null |
| 7529 | || (attached != null && attached.mAnimation != null) |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7530 | || (atoken != null && |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7531 | (atoken.animation != null |
| 7532 | || atoken.inPendingTransaction)); |
| 7533 | } |
| 7534 | |
| 7535 | /** Is this window currently animating? */ |
| 7536 | boolean isWindowAnimating() { |
| 7537 | return mAnimation != null; |
| 7538 | } |
| 7539 | |
| 7540 | /** |
| 7541 | * Like isOnScreen, but returns false if the surface hasn't yet |
| 7542 | * been drawn. |
| 7543 | */ |
| 7544 | public boolean isDisplayedLw() { |
| 7545 | final AppWindowToken atoken = mAppToken; |
| 7546 | return mSurface != null && mPolicyVisibility && !mDestroying |
| 7547 | && !mDrawPending && !mCommitDrawPending |
| 7548 | && ((!mAttachedHidden && |
| 7549 | (atoken == null || !atoken.hiddenRequested)) |
| 7550 | || mAnimating); |
| 7551 | } |
| 7552 | |
| Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 7553 | /** |
| 7554 | * Returns true if the window has a surface that it has drawn a |
| 7555 | * complete UI in to. |
| 7556 | */ |
| 7557 | public boolean isDrawnLw() { |
| 7558 | final AppWindowToken atoken = mAppToken; |
| 7559 | return mSurface != null && !mDestroying |
| 7560 | && !mDrawPending && !mCommitDrawPending; |
| 7561 | } |
| 7562 | |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 7563 | /** |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 7564 | * Return true if the window is opaque and fully drawn. This indicates |
| 7565 | * it may obscure windows behind it. |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 7566 | */ |
| 7567 | boolean isOpaqueDrawn() { |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 7568 | return (mAttrs.format == PixelFormat.OPAQUE |
| 7569 | || mAttrs.type == TYPE_WALLPAPER) |
| 7570 | && mSurface != null && mAnimation == null |
| 7571 | && (mAppToken == null || mAppToken.animation == null) |
| 7572 | && !mDrawPending && !mCommitDrawPending; |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 7573 | } |
| 7574 | |
| 7575 | boolean needsBackgroundFiller(int screenWidth, int screenHeight) { |
| 7576 | return |
| 7577 | // only if the application is requesting compatible window |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 7578 | (mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0 && |
| 7579 | // only if it's visible |
| 7580 | mHasDrawn && mViewVisibility == View.VISIBLE && |
| Mitsuru Oshima | d2967e2 | 2009-07-20 14:01:43 -0700 | [diff] [blame] | 7581 | // and only if the application fills the compatible screen |
| 7582 | mFrame.left <= mCompatibleScreenFrame.left && |
| 7583 | mFrame.top <= mCompatibleScreenFrame.top && |
| 7584 | mFrame.right >= mCompatibleScreenFrame.right && |
| 7585 | mFrame.bottom >= mCompatibleScreenFrame.bottom && |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 7586 | // and starting window do not need background filler |
| Mitsuru Oshima | d2967e2 | 2009-07-20 14:01:43 -0700 | [diff] [blame] | 7587 | mAttrs.type != mAttrs.TYPE_APPLICATION_STARTING; |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 7588 | } |
| 7589 | |
| 7590 | boolean isFullscreen(int screenWidth, int screenHeight) { |
| 7591 | return mFrame.left <= 0 && mFrame.top <= 0 && |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 7592 | mFrame.right >= screenWidth && mFrame.bottom >= screenHeight; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7593 | } |
| 7594 | |
| 7595 | void removeLocked() { |
| Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 7596 | disposeInputChannel(); |
| 7597 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7598 | if (mAttachedWindow != null) { |
| 7599 | mAttachedWindow.mChildWindows.remove(this); |
| 7600 | } |
| 7601 | destroySurfaceLocked(); |
| 7602 | mSession.windowRemovedLocked(); |
| 7603 | try { |
| 7604 | mClient.asBinder().unlinkToDeath(mDeathRecipient, 0); |
| 7605 | } catch (RuntimeException e) { |
| 7606 | // Ignore if it has already been removed (usually because |
| 7607 | // we are doing this as part of processing a death note.) |
| 7608 | } |
| Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 7609 | } |
| 7610 | |
| 7611 | void disposeInputChannel() { |
| Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 7612 | if (mInputChannel != null) { |
| 7613 | mInputManager.unregisterInputChannel(mInputChannel); |
| 7614 | |
| 7615 | mInputChannel.dispose(); |
| 7616 | mInputChannel = null; |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 7617 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7618 | } |
| 7619 | |
| 7620 | private class DeathRecipient implements IBinder.DeathRecipient { |
| 7621 | public void binderDied() { |
| 7622 | try { |
| 7623 | synchronized(mWindowMap) { |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 7624 | WindowState win = windowForClientLocked(mSession, mClient, false); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7625 | Slog.i(TAG, "WIN DEATH: " + win); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7626 | if (win != null) { |
| 7627 | removeWindowLocked(mSession, win); |
| 7628 | } |
| 7629 | } |
| 7630 | } catch (IllegalArgumentException ex) { |
| 7631 | // This will happen if the window has already been |
| 7632 | // removed. |
| 7633 | } |
| 7634 | } |
| 7635 | } |
| 7636 | |
| 7637 | /** Returns true if this window desires key events. */ |
| 7638 | public final boolean canReceiveKeys() { |
| 7639 | return isVisibleOrAdding() |
| 7640 | && (mViewVisibility == View.VISIBLE) |
| 7641 | && ((mAttrs.flags & WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) == 0); |
| 7642 | } |
| 7643 | |
| 7644 | public boolean hasDrawnLw() { |
| 7645 | return mHasDrawn; |
| 7646 | } |
| 7647 | |
| 7648 | public boolean showLw(boolean doAnimation) { |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 7649 | return showLw(doAnimation, true); |
| 7650 | } |
| 7651 | |
| 7652 | boolean showLw(boolean doAnimation, boolean requestAnim) { |
| 7653 | if (mPolicyVisibility && mPolicyVisibilityAfterAnim) { |
| 7654 | return false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7655 | } |
| Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 7656 | if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility true: " + this); |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 7657 | if (doAnimation) { |
| 7658 | if (DEBUG_VISIBILITY) Slog.v(TAG, "doAnimation: mPolicyVisibility=" |
| 7659 | + mPolicyVisibility + " mAnimation=" + mAnimation); |
| 7660 | if (mDisplayFrozen || !mPolicy.isScreenOn()) { |
| 7661 | doAnimation = false; |
| 7662 | } else if (mPolicyVisibility && mAnimation == null) { |
| 7663 | // Check for the case where we are currently visible and |
| 7664 | // not animating; we do not want to do animation at such a |
| 7665 | // point to become visible when we already are. |
| 7666 | doAnimation = false; |
| 7667 | } |
| 7668 | } |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 7669 | mPolicyVisibility = true; |
| 7670 | mPolicyVisibilityAfterAnim = true; |
| 7671 | if (doAnimation) { |
| 7672 | applyAnimationLocked(this, WindowManagerPolicy.TRANSIT_ENTER, true); |
| 7673 | } |
| 7674 | if (requestAnim) { |
| 7675 | requestAnimationLocked(0); |
| 7676 | } |
| 7677 | return true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7678 | } |
| 7679 | |
| 7680 | public boolean hideLw(boolean doAnimation) { |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 7681 | return hideLw(doAnimation, true); |
| 7682 | } |
| 7683 | |
| 7684 | boolean hideLw(boolean doAnimation, boolean requestAnim) { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 7685 | if (doAnimation) { |
| 7686 | if (mDisplayFrozen || !mPolicy.isScreenOn()) { |
| 7687 | doAnimation = false; |
| 7688 | } |
| 7689 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7690 | boolean current = doAnimation ? mPolicyVisibilityAfterAnim |
| 7691 | : mPolicyVisibility; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 7692 | if (!current) { |
| 7693 | return false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7694 | } |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 7695 | if (doAnimation) { |
| 7696 | applyAnimationLocked(this, WindowManagerPolicy.TRANSIT_EXIT, false); |
| 7697 | if (mAnimation == null) { |
| 7698 | doAnimation = false; |
| 7699 | } |
| 7700 | } |
| 7701 | if (doAnimation) { |
| 7702 | mPolicyVisibilityAfterAnim = false; |
| 7703 | } else { |
| Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 7704 | if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility false: " + this); |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 7705 | mPolicyVisibilityAfterAnim = false; |
| 7706 | mPolicyVisibility = false; |
| Dianne Hackborn | f3bea9c | 2009-12-09 18:26:21 -0800 | [diff] [blame] | 7707 | // Window is no longer visible -- make sure if we were waiting |
| 7708 | // for it to be displayed before enabling the display, that |
| 7709 | // we allow the display to be enabled now. |
| 7710 | enableScreenIfNeededLocked(); |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 7711 | if (mCurrentFocus == this) { |
| 7712 | mFocusMayChange = true; |
| 7713 | } |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 7714 | } |
| 7715 | if (requestAnim) { |
| 7716 | requestAnimationLocked(0); |
| 7717 | } |
| 7718 | return true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7719 | } |
| 7720 | |
| 7721 | void dump(PrintWriter pw, String prefix) { |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7722 | pw.print(prefix); pw.print("mSession="); pw.print(mSession); |
| 7723 | pw.print(" mClient="); pw.println(mClient.asBinder()); |
| 7724 | pw.print(prefix); pw.print("mAttrs="); pw.println(mAttrs); |
| 7725 | if (mAttachedWindow != null || mLayoutAttached) { |
| 7726 | pw.print(prefix); pw.print("mAttachedWindow="); pw.print(mAttachedWindow); |
| 7727 | pw.print(" mLayoutAttached="); pw.println(mLayoutAttached); |
| 7728 | } |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 7729 | if (mIsImWindow || mIsWallpaper || mIsFloatingLayer) { |
| 7730 | pw.print(prefix); pw.print("mIsImWindow="); pw.print(mIsImWindow); |
| 7731 | pw.print(" mIsWallpaper="); pw.print(mIsWallpaper); |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 7732 | pw.print(" mIsFloatingLayer="); pw.print(mIsFloatingLayer); |
| 7733 | pw.print(" mWallpaperVisible="); pw.println(mWallpaperVisible); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7734 | } |
| 7735 | pw.print(prefix); pw.print("mBaseLayer="); pw.print(mBaseLayer); |
| 7736 | pw.print(" mSubLayer="); pw.print(mSubLayer); |
| 7737 | pw.print(" mAnimLayer="); pw.print(mLayer); pw.print("+"); |
| 7738 | pw.print((mTargetAppToken != null ? mTargetAppToken.animLayerAdjustment |
| 7739 | : (mAppToken != null ? mAppToken.animLayerAdjustment : 0))); |
| 7740 | pw.print("="); pw.print(mAnimLayer); |
| 7741 | pw.print(" mLastLayer="); pw.println(mLastLayer); |
| 7742 | if (mSurface != null) { |
| 7743 | pw.print(prefix); pw.print("mSurface="); pw.println(mSurface); |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 7744 | pw.print(prefix); pw.print("Surface: shown="); pw.print(mSurfaceShown); |
| 7745 | pw.print(" layer="); pw.print(mSurfaceLayer); |
| 7746 | pw.print(" alpha="); pw.print(mSurfaceAlpha); |
| 7747 | pw.print(" rect=("); pw.print(mSurfaceX); |
| 7748 | pw.print(","); pw.print(mSurfaceY); |
| 7749 | pw.print(") "); pw.print(mSurfaceW); |
| 7750 | pw.print(" x "); pw.println(mSurfaceH); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7751 | } |
| 7752 | pw.print(prefix); pw.print("mToken="); pw.println(mToken); |
| 7753 | pw.print(prefix); pw.print("mRootToken="); pw.println(mRootToken); |
| 7754 | if (mAppToken != null) { |
| 7755 | pw.print(prefix); pw.print("mAppToken="); pw.println(mAppToken); |
| 7756 | } |
| 7757 | if (mTargetAppToken != null) { |
| 7758 | pw.print(prefix); pw.print("mTargetAppToken="); pw.println(mTargetAppToken); |
| 7759 | } |
| 7760 | pw.print(prefix); pw.print("mViewVisibility=0x"); |
| 7761 | pw.print(Integer.toHexString(mViewVisibility)); |
| 7762 | pw.print(" mLastHidden="); pw.print(mLastHidden); |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 7763 | pw.print(" mHaveFrame="); pw.print(mHaveFrame); |
| 7764 | pw.print(" mObscured="); pw.println(mObscured); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7765 | if (!mPolicyVisibility || !mPolicyVisibilityAfterAnim || mAttachedHidden) { |
| 7766 | pw.print(prefix); pw.print("mPolicyVisibility="); |
| 7767 | pw.print(mPolicyVisibility); |
| 7768 | pw.print(" mPolicyVisibilityAfterAnim="); |
| 7769 | pw.print(mPolicyVisibilityAfterAnim); |
| 7770 | pw.print(" mAttachedHidden="); pw.println(mAttachedHidden); |
| 7771 | } |
| Dianne Hackborn | 9b52a21 | 2009-12-11 14:51:35 -0800 | [diff] [blame] | 7772 | if (!mRelayoutCalled) { |
| 7773 | pw.print(prefix); pw.print("mRelayoutCalled="); pw.println(mRelayoutCalled); |
| 7774 | } |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7775 | pw.print(prefix); pw.print("Requested w="); pw.print(mRequestedWidth); |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 7776 | pw.print(" h="); pw.print(mRequestedHeight); |
| 7777 | pw.print(" mLayoutSeq="); pw.println(mLayoutSeq); |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 7778 | if (mXOffset != 0 || mYOffset != 0) { |
| 7779 | pw.print(prefix); pw.print("Offsets x="); pw.print(mXOffset); |
| 7780 | pw.print(" y="); pw.println(mYOffset); |
| 7781 | } |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7782 | pw.print(prefix); pw.print("mGivenContentInsets="); |
| 7783 | mGivenContentInsets.printShortString(pw); |
| 7784 | pw.print(" mGivenVisibleInsets="); |
| 7785 | mGivenVisibleInsets.printShortString(pw); |
| 7786 | pw.println(); |
| 7787 | if (mTouchableInsets != 0 || mGivenInsetsPending) { |
| 7788 | pw.print(prefix); pw.print("mTouchableInsets="); pw.print(mTouchableInsets); |
| 7789 | pw.print(" mGivenInsetsPending="); pw.println(mGivenInsetsPending); |
| 7790 | } |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 7791 | pw.print(prefix); pw.print("mConfiguration="); pw.println(mConfiguration); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7792 | pw.print(prefix); pw.print("mShownFrame="); |
| 7793 | mShownFrame.printShortString(pw); |
| 7794 | pw.print(" last="); mLastShownFrame.printShortString(pw); |
| 7795 | pw.println(); |
| 7796 | pw.print(prefix); pw.print("mFrame="); mFrame.printShortString(pw); |
| 7797 | pw.print(" last="); mLastFrame.printShortString(pw); |
| 7798 | pw.println(); |
| 7799 | pw.print(prefix); pw.print("mContainingFrame="); |
| 7800 | mContainingFrame.printShortString(pw); |
| 7801 | pw.print(" mDisplayFrame="); |
| 7802 | mDisplayFrame.printShortString(pw); |
| 7803 | pw.println(); |
| 7804 | pw.print(prefix); pw.print("mContentFrame="); mContentFrame.printShortString(pw); |
| 7805 | pw.print(" mVisibleFrame="); mVisibleFrame.printShortString(pw); |
| 7806 | pw.println(); |
| 7807 | pw.print(prefix); pw.print("mContentInsets="); mContentInsets.printShortString(pw); |
| 7808 | pw.print(" last="); mLastContentInsets.printShortString(pw); |
| 7809 | pw.print(" mVisibleInsets="); mVisibleInsets.printShortString(pw); |
| 7810 | pw.print(" last="); mLastVisibleInsets.printShortString(pw); |
| 7811 | pw.println(); |
| 7812 | if (mShownAlpha != 1 || mAlpha != 1 || mLastAlpha != 1) { |
| 7813 | pw.print(prefix); pw.print("mShownAlpha="); pw.print(mShownAlpha); |
| 7814 | pw.print(" mAlpha="); pw.print(mAlpha); |
| 7815 | pw.print(" mLastAlpha="); pw.println(mLastAlpha); |
| 7816 | } |
| 7817 | if (mAnimating || mLocalAnimating || mAnimationIsEntrance |
| 7818 | || mAnimation != null) { |
| 7819 | pw.print(prefix); pw.print("mAnimating="); pw.print(mAnimating); |
| 7820 | pw.print(" mLocalAnimating="); pw.print(mLocalAnimating); |
| 7821 | pw.print(" mAnimationIsEntrance="); pw.print(mAnimationIsEntrance); |
| 7822 | pw.print(" mAnimation="); pw.println(mAnimation); |
| 7823 | } |
| 7824 | if (mHasTransformation || mHasLocalTransformation) { |
| 7825 | pw.print(prefix); pw.print("XForm: has="); |
| 7826 | pw.print(mHasTransformation); |
| 7827 | pw.print(" hasLocal="); pw.print(mHasLocalTransformation); |
| 7828 | pw.print(" "); mTransformation.printShortString(pw); |
| 7829 | pw.println(); |
| 7830 | } |
| 7831 | pw.print(prefix); pw.print("mDrawPending="); pw.print(mDrawPending); |
| 7832 | pw.print(" mCommitDrawPending="); pw.print(mCommitDrawPending); |
| 7833 | pw.print(" mReadyToShow="); pw.print(mReadyToShow); |
| 7834 | pw.print(" mHasDrawn="); pw.println(mHasDrawn); |
| 7835 | if (mExiting || mRemoveOnExit || mDestroying || mRemoved) { |
| 7836 | pw.print(prefix); pw.print("mExiting="); pw.print(mExiting); |
| 7837 | pw.print(" mRemoveOnExit="); pw.print(mRemoveOnExit); |
| 7838 | pw.print(" mDestroying="); pw.print(mDestroying); |
| 7839 | pw.print(" mRemoved="); pw.println(mRemoved); |
| 7840 | } |
| Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 7841 | if (mOrientationChanging || mAppFreezing || mTurnOnScreen) { |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7842 | pw.print(prefix); pw.print("mOrientationChanging="); |
| 7843 | pw.print(mOrientationChanging); |
| Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 7844 | pw.print(" mAppFreezing="); pw.print(mAppFreezing); |
| 7845 | pw.print(" mTurnOnScreen="); pw.println(mTurnOnScreen); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7846 | } |
| Mitsuru Oshima | 589cebe | 2009-07-22 20:38:58 -0700 | [diff] [blame] | 7847 | if (mHScale != 1 || mVScale != 1) { |
| 7848 | pw.print(prefix); pw.print("mHScale="); pw.print(mHScale); |
| 7849 | pw.print(" mVScale="); pw.println(mVScale); |
| 7850 | } |
| Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 7851 | if (mWallpaperX != -1 || mWallpaperY != -1) { |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 7852 | pw.print(prefix); pw.print("mWallpaperX="); pw.print(mWallpaperX); |
| 7853 | pw.print(" mWallpaperY="); pw.println(mWallpaperY); |
| 7854 | } |
| Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 7855 | if (mWallpaperXStep != -1 || mWallpaperYStep != -1) { |
| 7856 | pw.print(prefix); pw.print("mWallpaperXStep="); pw.print(mWallpaperXStep); |
| 7857 | pw.print(" mWallpaperYStep="); pw.println(mWallpaperYStep); |
| 7858 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7859 | } |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 7860 | |
| 7861 | String makeInputChannelName() { |
| 7862 | return Integer.toHexString(System.identityHashCode(this)) |
| 7863 | + " " + mAttrs.getTitle(); |
| 7864 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7865 | |
| 7866 | @Override |
| 7867 | public String toString() { |
| 7868 | return "Window{" |
| 7869 | + Integer.toHexString(System.identityHashCode(this)) |
| 7870 | + " " + mAttrs.getTitle() + " paused=" + mToken.paused + "}"; |
| 7871 | } |
| 7872 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7873 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7874 | // ------------------------------------------------------------- |
| 7875 | // Window Token State |
| 7876 | // ------------------------------------------------------------- |
| 7877 | |
| 7878 | class WindowToken { |
| 7879 | // The actual token. |
| 7880 | final IBinder token; |
| 7881 | |
| 7882 | // The type of window this token is for, as per WindowManager.LayoutParams. |
| 7883 | final int windowType; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7884 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7885 | // Set if this token was explicitly added by a client, so should |
| 7886 | // not be removed when all windows are removed. |
| 7887 | final boolean explicit; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7888 | |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7889 | // For printing. |
| 7890 | String stringName; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7891 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7892 | // If this is an AppWindowToken, this is non-null. |
| 7893 | AppWindowToken appWindowToken; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7894 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7895 | // All of the windows associated with this token. |
| 7896 | final ArrayList<WindowState> windows = new ArrayList<WindowState>(); |
| 7897 | |
| 7898 | // Is key dispatching paused for this token? |
| 7899 | boolean paused = false; |
| 7900 | |
| 7901 | // Should this token's windows be hidden? |
| 7902 | boolean hidden; |
| 7903 | |
| 7904 | // Temporary for finding which tokens no longer have visible windows. |
| 7905 | boolean hasVisible; |
| 7906 | |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 7907 | // Set to true when this token is in a pending transaction where it |
| 7908 | // will be shown. |
| 7909 | boolean waitingToShow; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7910 | |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 7911 | // Set to true when this token is in a pending transaction where it |
| 7912 | // will be hidden. |
| 7913 | boolean waitingToHide; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7914 | |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 7915 | // Set to true when this token is in a pending transaction where its |
| 7916 | // windows will be put to the bottom of the list. |
| 7917 | boolean sendingToBottom; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7918 | |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 7919 | // Set to true when this token is in a pending transaction where its |
| 7920 | // windows will be put to the top of the list. |
| 7921 | boolean sendingToTop; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7922 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7923 | WindowToken(IBinder _token, int type, boolean _explicit) { |
| 7924 | token = _token; |
| 7925 | windowType = type; |
| 7926 | explicit = _explicit; |
| 7927 | } |
| 7928 | |
| 7929 | void dump(PrintWriter pw, String prefix) { |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7930 | pw.print(prefix); pw.print("token="); pw.println(token); |
| 7931 | pw.print(prefix); pw.print("windows="); pw.println(windows); |
| 7932 | pw.print(prefix); pw.print("windowType="); pw.print(windowType); |
| 7933 | pw.print(" hidden="); pw.print(hidden); |
| 7934 | pw.print(" hasVisible="); pw.println(hasVisible); |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 7935 | if (waitingToShow || waitingToHide || sendingToBottom || sendingToTop) { |
| 7936 | pw.print(prefix); pw.print("waitingToShow="); pw.print(waitingToShow); |
| 7937 | pw.print(" waitingToHide="); pw.print(waitingToHide); |
| 7938 | pw.print(" sendingToBottom="); pw.print(sendingToBottom); |
| 7939 | pw.print(" sendingToTop="); pw.println(sendingToTop); |
| 7940 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7941 | } |
| 7942 | |
| 7943 | @Override |
| 7944 | public String toString() { |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7945 | if (stringName == null) { |
| 7946 | StringBuilder sb = new StringBuilder(); |
| 7947 | sb.append("WindowToken{"); |
| 7948 | sb.append(Integer.toHexString(System.identityHashCode(this))); |
| 7949 | sb.append(" token="); sb.append(token); sb.append('}'); |
| 7950 | stringName = sb.toString(); |
| 7951 | } |
| 7952 | return stringName; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7953 | } |
| 7954 | }; |
| 7955 | |
| 7956 | class AppWindowToken extends WindowToken { |
| 7957 | // Non-null only for application tokens. |
| 7958 | final IApplicationToken appToken; |
| 7959 | |
| 7960 | // All of the windows and child windows that are included in this |
| 7961 | // application token. Note this list is NOT sorted! |
| 7962 | final ArrayList<WindowState> allAppWindows = new ArrayList<WindowState>(); |
| 7963 | |
| 7964 | int groupId = -1; |
| 7965 | boolean appFullscreen; |
| 7966 | int requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 7967 | |
| 7968 | // The input dispatching timeout for this application token in nanoseconds. |
| 7969 | long inputDispatchingTimeoutNanos; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7970 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7971 | // These are used for determining when all windows associated with |
| 7972 | // an activity have been drawn, so they can be made visible together |
| 7973 | // at the same time. |
| 7974 | int lastTransactionSequence = mTransactionSequence-1; |
| 7975 | int numInterestingWindows; |
| 7976 | int numDrawnWindows; |
| 7977 | boolean inPendingTransaction; |
| 7978 | boolean allDrawn; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7979 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7980 | // Is this token going to be hidden in a little while? If so, it |
| 7981 | // won't be taken into account for setting the screen orientation. |
| 7982 | boolean willBeHidden; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7983 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7984 | // Is this window's surface needed? This is almost like hidden, except |
| 7985 | // it will sometimes be true a little earlier: when the token has |
| 7986 | // been shown, but is still waiting for its app transition to execute |
| 7987 | // before making its windows shown. |
| 7988 | boolean hiddenRequested; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7989 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7990 | // Have we told the window clients to hide themselves? |
| 7991 | boolean clientHidden; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7992 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7993 | // Last visibility state we reported to the app token. |
| 7994 | boolean reportedVisible; |
| 7995 | |
| 7996 | // Set to true when the token has been removed from the window mgr. |
| 7997 | boolean removed; |
| 7998 | |
| 7999 | // Have we been asked to have this token keep the screen frozen? |
| 8000 | boolean freezingScreen; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8001 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8002 | boolean animating; |
| 8003 | Animation animation; |
| 8004 | boolean hasTransformation; |
| 8005 | final Transformation transformation = new Transformation(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8006 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8007 | // Offset to the window of all layers in the token, for use by |
| 8008 | // AppWindowToken animations. |
| 8009 | int animLayerAdjustment; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8010 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8011 | // Information about an application starting window if displayed. |
| 8012 | StartingData startingData; |
| 8013 | WindowState startingWindow; |
| 8014 | View startingView; |
| 8015 | boolean startingDisplayed; |
| 8016 | boolean startingMoved; |
| 8017 | boolean firstWindowDrawn; |
| 8018 | |
| 8019 | AppWindowToken(IApplicationToken _token) { |
| 8020 | super(_token.asBinder(), |
| 8021 | WindowManager.LayoutParams.TYPE_APPLICATION, true); |
| 8022 | appWindowToken = this; |
| 8023 | appToken = _token; |
| 8024 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8025 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8026 | public void setAnimation(Animation anim) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8027 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8028 | TAG, "Setting animation in " + this + ": " + anim); |
| 8029 | animation = anim; |
| 8030 | animating = false; |
| 8031 | anim.restrictDuration(MAX_ANIMATION_DURATION); |
| 8032 | anim.scaleCurrentDuration(mTransitionAnimationScale); |
| 8033 | int zorder = anim.getZAdjustment(); |
| 8034 | int adj = 0; |
| 8035 | if (zorder == Animation.ZORDER_TOP) { |
| 8036 | adj = TYPE_LAYER_OFFSET; |
| 8037 | } else if (zorder == Animation.ZORDER_BOTTOM) { |
| 8038 | adj = -TYPE_LAYER_OFFSET; |
| 8039 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8040 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8041 | if (animLayerAdjustment != adj) { |
| 8042 | animLayerAdjustment = adj; |
| 8043 | updateLayers(); |
| 8044 | } |
| 8045 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8046 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8047 | public void setDummyAnimation() { |
| 8048 | if (animation == null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8049 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8050 | TAG, "Setting dummy animation in " + this); |
| 8051 | animation = sDummyAnimation; |
| 8052 | } |
| 8053 | } |
| 8054 | |
| 8055 | public void clearAnimation() { |
| 8056 | if (animation != null) { |
| 8057 | animation = null; |
| 8058 | animating = true; |
| 8059 | } |
| 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 | void updateLayers() { |
| 8063 | final int N = allAppWindows.size(); |
| 8064 | final int adj = animLayerAdjustment; |
| 8065 | for (int i=0; i<N; i++) { |
| 8066 | WindowState w = allAppWindows.get(i); |
| 8067 | w.mAnimLayer = w.mLayer + adj; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8068 | if (DEBUG_LAYERS) Slog.v(TAG, "Updating layer " + w + ": " |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8069 | + w.mAnimLayer); |
| 8070 | if (w == mInputMethodTarget) { |
| 8071 | setInputMethodAnimLayerAdjustment(adj); |
| 8072 | } |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 8073 | if (w == mWallpaperTarget && mLowerWallpaperTarget == null) { |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 8074 | setWallpaperAnimLayerAdjustmentLocked(adj); |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 8075 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8076 | } |
| 8077 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8078 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8079 | void sendAppVisibilityToClients() { |
| 8080 | final int N = allAppWindows.size(); |
| 8081 | for (int i=0; i<N; i++) { |
| 8082 | WindowState win = allAppWindows.get(i); |
| 8083 | if (win == startingWindow && clientHidden) { |
| 8084 | // Don't hide the starting window. |
| 8085 | continue; |
| 8086 | } |
| 8087 | try { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8088 | if (DEBUG_VISIBILITY) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8089 | "Setting visibility of " + win + ": " + (!clientHidden)); |
| 8090 | win.mClient.dispatchAppVisibility(!clientHidden); |
| 8091 | } catch (RemoteException e) { |
| 8092 | } |
| 8093 | } |
| 8094 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8095 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8096 | void showAllWindowsLocked() { |
| 8097 | final int NW = allAppWindows.size(); |
| 8098 | for (int i=0; i<NW; i++) { |
| 8099 | WindowState w = allAppWindows.get(i); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8100 | if (DEBUG_VISIBILITY) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8101 | "performing show on: " + w); |
| 8102 | w.performShowLocked(); |
| 8103 | } |
| 8104 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8105 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8106 | // This must be called while inside a transaction. |
| 8107 | boolean stepAnimationLocked(long currentTime, int dw, int dh) { |
| Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 8108 | if (!mDisplayFrozen && mPolicy.isScreenOn()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8109 | // We will run animations as long as the display isn't frozen. |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8110 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8111 | if (animation == sDummyAnimation) { |
| 8112 | // This guy is going to animate, but not yet. For now count |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 8113 | // it as not animating for purposes of scheduling transactions; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8114 | // when it is really time to animate, this will be set to |
| 8115 | // a real animation and the next call will execute normally. |
| 8116 | return false; |
| 8117 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8118 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8119 | if ((allDrawn || animating || startingDisplayed) && animation != null) { |
| 8120 | if (!animating) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8121 | if (DEBUG_ANIM) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8122 | TAG, "Starting animation in " + this + |
| 8123 | " @ " + currentTime + ": dw=" + dw + " dh=" + dh |
| 8124 | + " scale=" + mTransitionAnimationScale |
| 8125 | + " allDrawn=" + allDrawn + " animating=" + animating); |
| 8126 | animation.initialize(dw, dh, dw, dh); |
| 8127 | animation.setStartTime(currentTime); |
| 8128 | animating = true; |
| 8129 | } |
| 8130 | transformation.clear(); |
| 8131 | final boolean more = animation.getTransformation( |
| 8132 | currentTime, transformation); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8133 | if (DEBUG_ANIM) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8134 | TAG, "Stepped animation in " + this + |
| 8135 | ": more=" + more + ", xform=" + transformation); |
| 8136 | if (more) { |
| 8137 | // we're done! |
| 8138 | hasTransformation = true; |
| 8139 | return true; |
| 8140 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8141 | if (DEBUG_ANIM) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8142 | TAG, "Finished animation in " + this + |
| 8143 | " @ " + currentTime); |
| 8144 | animation = null; |
| 8145 | } |
| 8146 | } else if (animation != null) { |
| 8147 | // If the display is frozen, and there is a pending animation, |
| 8148 | // clear it and make sure we run the cleanup code. |
| 8149 | animating = true; |
| 8150 | animation = null; |
| 8151 | } |
| 8152 | |
| 8153 | hasTransformation = false; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8154 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8155 | if (!animating) { |
| 8156 | return false; |
| 8157 | } |
| 8158 | |
| 8159 | clearAnimation(); |
| 8160 | animating = false; |
| 8161 | if (mInputMethodTarget != null && mInputMethodTarget.mAppToken == this) { |
| 8162 | moveInputMethodWindowsIfNeededLocked(true); |
| 8163 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8164 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8165 | if (DEBUG_ANIM) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8166 | TAG, "Animation done in " + this |
| 8167 | + ": reportedVisible=" + reportedVisible); |
| 8168 | |
| 8169 | transformation.clear(); |
| 8170 | if (animLayerAdjustment != 0) { |
| 8171 | animLayerAdjustment = 0; |
| 8172 | updateLayers(); |
| 8173 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8174 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8175 | final int N = windows.size(); |
| 8176 | for (int i=0; i<N; i++) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 8177 | windows.get(i).finishExit(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8178 | } |
| 8179 | updateReportedVisibilityLocked(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8180 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8181 | return false; |
| 8182 | } |
| 8183 | |
| 8184 | void updateReportedVisibilityLocked() { |
| 8185 | if (appToken == null) { |
| 8186 | return; |
| 8187 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8188 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8189 | int numInteresting = 0; |
| 8190 | int numVisible = 0; |
| 8191 | boolean nowGone = true; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8192 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8193 | 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] | 8194 | final int N = allAppWindows.size(); |
| 8195 | for (int i=0; i<N; i++) { |
| 8196 | WindowState win = allAppWindows.get(i); |
| Dianne Hackborn | 6cf67fa | 2009-12-21 16:46:34 -0800 | [diff] [blame] | 8197 | if (win == startingWindow || win.mAppFreezing |
| The Android Open Source Project | 727cec0 | 2010-04-08 11:35:37 -0700 | [diff] [blame] | 8198 | || win.mViewVisibility != View.VISIBLE |
| Ulf Rosdahl | 3935770 | 2010-09-29 12:34:38 +0200 | [diff] [blame] | 8199 | || win.mAttrs.type == TYPE_APPLICATION_STARTING |
| 8200 | || win.mDestroying) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8201 | continue; |
| 8202 | } |
| 8203 | if (DEBUG_VISIBILITY) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8204 | Slog.v(TAG, "Win " + win + ": isDrawn=" |
| Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 8205 | + win.isDrawnLw() |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8206 | + ", isAnimating=" + win.isAnimating()); |
| Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 8207 | if (!win.isDrawnLw()) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8208 | Slog.v(TAG, "Not displayed: s=" + win.mSurface |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8209 | + " pv=" + win.mPolicyVisibility |
| 8210 | + " dp=" + win.mDrawPending |
| 8211 | + " cdp=" + win.mCommitDrawPending |
| 8212 | + " ah=" + win.mAttachedHidden |
| 8213 | + " th=" |
| 8214 | + (win.mAppToken != null |
| 8215 | ? win.mAppToken.hiddenRequested : false) |
| 8216 | + " a=" + win.mAnimating); |
| 8217 | } |
| 8218 | } |
| 8219 | numInteresting++; |
| Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 8220 | if (win.isDrawnLw()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8221 | if (!win.isAnimating()) { |
| 8222 | numVisible++; |
| 8223 | } |
| 8224 | nowGone = false; |
| 8225 | } else if (win.isAnimating()) { |
| 8226 | nowGone = false; |
| 8227 | } |
| 8228 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8229 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8230 | boolean nowVisible = numInteresting > 0 && numVisible >= numInteresting; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8231 | if (DEBUG_VISIBILITY) Slog.v(TAG, "VIS " + this + ": interesting=" |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8232 | + numInteresting + " visible=" + numVisible); |
| 8233 | if (nowVisible != reportedVisible) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8234 | if (DEBUG_VISIBILITY) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8235 | TAG, "Visibility changed in " + this |
| 8236 | + ": vis=" + nowVisible); |
| 8237 | reportedVisible = nowVisible; |
| 8238 | Message m = mH.obtainMessage( |
| 8239 | H.REPORT_APPLICATION_TOKEN_WINDOWS, |
| 8240 | nowVisible ? 1 : 0, |
| 8241 | nowGone ? 1 : 0, |
| 8242 | this); |
| 8243 | mH.sendMessage(m); |
| 8244 | } |
| 8245 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8246 | |
| Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 8247 | WindowState findMainWindow() { |
| 8248 | int j = windows.size(); |
| 8249 | while (j > 0) { |
| 8250 | j--; |
| 8251 | WindowState win = windows.get(j); |
| 8252 | if (win.mAttrs.type == WindowManager.LayoutParams.TYPE_BASE_APPLICATION |
| 8253 | || win.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING) { |
| 8254 | return win; |
| 8255 | } |
| 8256 | } |
| 8257 | return null; |
| 8258 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8259 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8260 | void dump(PrintWriter pw, String prefix) { |
| 8261 | super.dump(pw, prefix); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8262 | if (appToken != null) { |
| 8263 | pw.print(prefix); pw.println("app=true"); |
| 8264 | } |
| 8265 | if (allAppWindows.size() > 0) { |
| 8266 | pw.print(prefix); pw.print("allAppWindows="); pw.println(allAppWindows); |
| 8267 | } |
| 8268 | pw.print(prefix); pw.print("groupId="); pw.print(groupId); |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8269 | pw.print(" appFullscreen="); pw.print(appFullscreen); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8270 | pw.print(" requestedOrientation="); pw.println(requestedOrientation); |
| 8271 | pw.print(prefix); pw.print("hiddenRequested="); pw.print(hiddenRequested); |
| 8272 | pw.print(" clientHidden="); pw.print(clientHidden); |
| 8273 | pw.print(" willBeHidden="); pw.print(willBeHidden); |
| 8274 | pw.print(" reportedVisible="); pw.println(reportedVisible); |
| 8275 | if (paused || freezingScreen) { |
| 8276 | pw.print(prefix); pw.print("paused="); pw.print(paused); |
| 8277 | pw.print(" freezingScreen="); pw.println(freezingScreen); |
| 8278 | } |
| 8279 | if (numInterestingWindows != 0 || numDrawnWindows != 0 |
| 8280 | || inPendingTransaction || allDrawn) { |
| 8281 | pw.print(prefix); pw.print("numInterestingWindows="); |
| 8282 | pw.print(numInterestingWindows); |
| 8283 | pw.print(" numDrawnWindows="); pw.print(numDrawnWindows); |
| 8284 | pw.print(" inPendingTransaction="); pw.print(inPendingTransaction); |
| 8285 | pw.print(" allDrawn="); pw.println(allDrawn); |
| 8286 | } |
| 8287 | if (animating || animation != null) { |
| 8288 | pw.print(prefix); pw.print("animating="); pw.print(animating); |
| 8289 | pw.print(" animation="); pw.println(animation); |
| 8290 | } |
| 8291 | if (animLayerAdjustment != 0) { |
| 8292 | pw.print(prefix); pw.print("animLayerAdjustment="); pw.println(animLayerAdjustment); |
| 8293 | } |
| 8294 | if (hasTransformation) { |
| 8295 | pw.print(prefix); pw.print("hasTransformation="); pw.print(hasTransformation); |
| 8296 | pw.print(" transformation="); transformation.printShortString(pw); |
| 8297 | pw.println(); |
| 8298 | } |
| 8299 | if (startingData != null || removed || firstWindowDrawn) { |
| 8300 | pw.print(prefix); pw.print("startingData="); pw.print(startingData); |
| 8301 | pw.print(" removed="); pw.print(removed); |
| 8302 | pw.print(" firstWindowDrawn="); pw.println(firstWindowDrawn); |
| 8303 | } |
| 8304 | if (startingWindow != null || startingView != null |
| 8305 | || startingDisplayed || startingMoved) { |
| 8306 | pw.print(prefix); pw.print("startingWindow="); pw.print(startingWindow); |
| 8307 | pw.print(" startingView="); pw.print(startingView); |
| 8308 | pw.print(" startingDisplayed="); pw.print(startingDisplayed); |
| 8309 | pw.print(" startingMoved"); pw.println(startingMoved); |
| 8310 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8311 | } |
| 8312 | |
| 8313 | @Override |
| 8314 | public String toString() { |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8315 | if (stringName == null) { |
| 8316 | StringBuilder sb = new StringBuilder(); |
| 8317 | sb.append("AppWindowToken{"); |
| 8318 | sb.append(Integer.toHexString(System.identityHashCode(this))); |
| 8319 | sb.append(" token="); sb.append(token); sb.append('}'); |
| 8320 | stringName = sb.toString(); |
| 8321 | } |
| 8322 | return stringName; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8323 | } |
| 8324 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8325 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8326 | // ------------------------------------------------------------- |
| 8327 | // DummyAnimation |
| 8328 | // ------------------------------------------------------------- |
| 8329 | |
| 8330 | // This is an animation that does nothing: it just immediately finishes |
| 8331 | // itself every time it is called. It is used as a stub animation in cases |
| 8332 | // where we want to synchronize multiple things that may be animating. |
| 8333 | static final class DummyAnimation extends Animation { |
| 8334 | public boolean getTransformation(long currentTime, Transformation outTransformation) { |
| 8335 | return false; |
| 8336 | } |
| 8337 | } |
| 8338 | static final Animation sDummyAnimation = new DummyAnimation(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8339 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8340 | // ------------------------------------------------------------- |
| 8341 | // Async Handler |
| 8342 | // ------------------------------------------------------------- |
| 8343 | |
| 8344 | static final class StartingData { |
| 8345 | final String pkg; |
| 8346 | final int theme; |
| 8347 | final CharSequence nonLocalizedLabel; |
| 8348 | final int labelRes; |
| 8349 | final int icon; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8350 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8351 | StartingData(String _pkg, int _theme, CharSequence _nonLocalizedLabel, |
| 8352 | int _labelRes, int _icon) { |
| 8353 | pkg = _pkg; |
| 8354 | theme = _theme; |
| 8355 | nonLocalizedLabel = _nonLocalizedLabel; |
| 8356 | labelRes = _labelRes; |
| 8357 | icon = _icon; |
| 8358 | } |
| 8359 | } |
| 8360 | |
| 8361 | private final class H extends Handler { |
| 8362 | public static final int REPORT_FOCUS_CHANGE = 2; |
| 8363 | public static final int REPORT_LOSING_FOCUS = 3; |
| 8364 | public static final int ANIMATE = 4; |
| 8365 | public static final int ADD_STARTING = 5; |
| 8366 | public static final int REMOVE_STARTING = 6; |
| 8367 | public static final int FINISHED_STARTING = 7; |
| 8368 | public static final int REPORT_APPLICATION_TOKEN_WINDOWS = 8; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8369 | public static final int WINDOW_FREEZE_TIMEOUT = 11; |
| 8370 | public static final int HOLD_SCREEN_CHANGED = 12; |
| 8371 | public static final int APP_TRANSITION_TIMEOUT = 13; |
| 8372 | public static final int PERSIST_ANIMATION_SCALE = 14; |
| 8373 | public static final int FORCE_GC = 15; |
| 8374 | public static final int ENABLE_SCREEN = 16; |
| 8375 | public static final int APP_FREEZE_TIMEOUT = 17; |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 8376 | public static final int SEND_NEW_CONFIGURATION = 18; |
| Konstantin Lopyrev | 6e0f65f | 2010-07-14 14:55:33 -0700 | [diff] [blame] | 8377 | public static final int REPORT_WINDOWS_CHANGE = 19; |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 8378 | public static final int DRAG_START_TIMEOUT = 20; |
| Chris Tate | d4533f14 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 8379 | public static final int DRAG_END_TIMEOUT = 21; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8380 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8381 | private Session mLastReportedHold; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8382 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8383 | public H() { |
| 8384 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8385 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8386 | @Override |
| 8387 | public void handleMessage(Message msg) { |
| 8388 | switch (msg.what) { |
| 8389 | case REPORT_FOCUS_CHANGE: { |
| 8390 | WindowState lastFocus; |
| 8391 | WindowState newFocus; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8392 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8393 | synchronized(mWindowMap) { |
| 8394 | lastFocus = mLastFocus; |
| 8395 | newFocus = mCurrentFocus; |
| 8396 | if (lastFocus == newFocus) { |
| 8397 | // Focus is not changing, so nothing to do. |
| 8398 | return; |
| 8399 | } |
| 8400 | mLastFocus = newFocus; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8401 | //Slog.i(TAG, "Focus moving from " + lastFocus |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8402 | // + " to " + newFocus); |
| 8403 | if (newFocus != null && lastFocus != null |
| 8404 | && !newFocus.isDisplayedLw()) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8405 | //Slog.i(TAG, "Delaying loss of focus..."); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8406 | mLosingFocus.add(lastFocus); |
| 8407 | lastFocus = null; |
| 8408 | } |
| 8409 | } |
| 8410 | |
| 8411 | if (lastFocus != newFocus) { |
| 8412 | //System.out.println("Changing focus from " + lastFocus |
| 8413 | // + " to " + newFocus); |
| 8414 | if (newFocus != null) { |
| 8415 | try { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8416 | //Slog.i(TAG, "Gaining focus: " + newFocus); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8417 | newFocus.mClient.windowFocusChanged(true, mInTouchMode); |
| 8418 | } catch (RemoteException e) { |
| 8419 | // Ignore if process has died. |
| 8420 | } |
| Konstantin Lopyrev | 5e7833a | 2010-08-09 17:01:11 -0700 | [diff] [blame] | 8421 | notifyFocusChanged(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8422 | } |
| 8423 | |
| 8424 | if (lastFocus != null) { |
| 8425 | try { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8426 | //Slog.i(TAG, "Losing focus: " + lastFocus); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8427 | lastFocus.mClient.windowFocusChanged(false, mInTouchMode); |
| 8428 | } catch (RemoteException e) { |
| 8429 | // Ignore if process has died. |
| 8430 | } |
| 8431 | } |
| 8432 | } |
| 8433 | } break; |
| 8434 | |
| 8435 | case REPORT_LOSING_FOCUS: { |
| 8436 | ArrayList<WindowState> losers; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8437 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8438 | synchronized(mWindowMap) { |
| 8439 | losers = mLosingFocus; |
| 8440 | mLosingFocus = new ArrayList<WindowState>(); |
| 8441 | } |
| 8442 | |
| 8443 | final int N = losers.size(); |
| 8444 | for (int i=0; i<N; i++) { |
| 8445 | try { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8446 | //Slog.i(TAG, "Losing delayed focus: " + losers.get(i)); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8447 | losers.get(i).mClient.windowFocusChanged(false, mInTouchMode); |
| 8448 | } catch (RemoteException e) { |
| 8449 | // Ignore if process has died. |
| 8450 | } |
| 8451 | } |
| 8452 | } break; |
| 8453 | |
| 8454 | case ANIMATE: { |
| 8455 | synchronized(mWindowMap) { |
| 8456 | mAnimationPending = false; |
| 8457 | performLayoutAndPlaceSurfacesLocked(); |
| 8458 | } |
| 8459 | } break; |
| 8460 | |
| 8461 | case ADD_STARTING: { |
| 8462 | final AppWindowToken wtoken = (AppWindowToken)msg.obj; |
| 8463 | final StartingData sd = wtoken.startingData; |
| 8464 | |
| 8465 | if (sd == null) { |
| 8466 | // Animation has been canceled... do nothing. |
| 8467 | return; |
| 8468 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8469 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8470 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Add starting " |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8471 | + wtoken + ": pkg=" + sd.pkg); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8472 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8473 | View view = null; |
| 8474 | try { |
| 8475 | view = mPolicy.addStartingWindow( |
| 8476 | wtoken.token, sd.pkg, |
| 8477 | sd.theme, sd.nonLocalizedLabel, sd.labelRes, |
| 8478 | sd.icon); |
| 8479 | } catch (Exception e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8480 | Slog.w(TAG, "Exception when adding starting window", e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8481 | } |
| 8482 | |
| 8483 | if (view != null) { |
| 8484 | boolean abort = false; |
| 8485 | |
| 8486 | synchronized(mWindowMap) { |
| 8487 | if (wtoken.removed || wtoken.startingData == null) { |
| 8488 | // If the window was successfully added, then |
| 8489 | // we need to remove it. |
| 8490 | if (wtoken.startingWindow != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8491 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8492 | "Aborted starting " + wtoken |
| 8493 | + ": removed=" + wtoken.removed |
| 8494 | + " startingData=" + wtoken.startingData); |
| 8495 | wtoken.startingWindow = null; |
| 8496 | wtoken.startingData = null; |
| 8497 | abort = true; |
| 8498 | } |
| 8499 | } else { |
| 8500 | wtoken.startingView = view; |
| 8501 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8502 | if (DEBUG_STARTING_WINDOW && !abort) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8503 | "Added starting " + wtoken |
| 8504 | + ": startingWindow=" |
| 8505 | + wtoken.startingWindow + " startingView=" |
| 8506 | + wtoken.startingView); |
| 8507 | } |
| 8508 | |
| 8509 | if (abort) { |
| 8510 | try { |
| 8511 | mPolicy.removeStartingWindow(wtoken.token, view); |
| 8512 | } catch (Exception e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8513 | Slog.w(TAG, "Exception when removing starting window", e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8514 | } |
| 8515 | } |
| 8516 | } |
| 8517 | } break; |
| 8518 | |
| 8519 | case REMOVE_STARTING: { |
| 8520 | final AppWindowToken wtoken = (AppWindowToken)msg.obj; |
| 8521 | IBinder token = null; |
| 8522 | View view = null; |
| 8523 | synchronized (mWindowMap) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8524 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Remove starting " |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8525 | + wtoken + ": startingWindow=" |
| 8526 | + wtoken.startingWindow + " startingView=" |
| 8527 | + wtoken.startingView); |
| 8528 | if (wtoken.startingWindow != null) { |
| 8529 | view = wtoken.startingView; |
| 8530 | token = wtoken.token; |
| 8531 | wtoken.startingData = null; |
| 8532 | wtoken.startingView = null; |
| 8533 | wtoken.startingWindow = null; |
| 8534 | } |
| 8535 | } |
| 8536 | if (view != null) { |
| 8537 | try { |
| 8538 | mPolicy.removeStartingWindow(token, view); |
| 8539 | } catch (Exception e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8540 | Slog.w(TAG, "Exception when removing starting window", e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8541 | } |
| 8542 | } |
| 8543 | } break; |
| 8544 | |
| 8545 | case FINISHED_STARTING: { |
| 8546 | IBinder token = null; |
| 8547 | View view = null; |
| 8548 | while (true) { |
| 8549 | synchronized (mWindowMap) { |
| 8550 | final int N = mFinishedStarting.size(); |
| 8551 | if (N <= 0) { |
| 8552 | break; |
| 8553 | } |
| 8554 | AppWindowToken wtoken = mFinishedStarting.remove(N-1); |
| 8555 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8556 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8557 | "Finished starting " + wtoken |
| 8558 | + ": startingWindow=" + wtoken.startingWindow |
| 8559 | + " startingView=" + wtoken.startingView); |
| 8560 | |
| 8561 | if (wtoken.startingWindow == null) { |
| 8562 | continue; |
| 8563 | } |
| 8564 | |
| 8565 | view = wtoken.startingView; |
| 8566 | token = wtoken.token; |
| 8567 | wtoken.startingData = null; |
| 8568 | wtoken.startingView = null; |
| 8569 | wtoken.startingWindow = null; |
| 8570 | } |
| 8571 | |
| 8572 | try { |
| 8573 | mPolicy.removeStartingWindow(token, view); |
| 8574 | } catch (Exception e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8575 | Slog.w(TAG, "Exception when removing starting window", e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8576 | } |
| 8577 | } |
| 8578 | } break; |
| 8579 | |
| 8580 | case REPORT_APPLICATION_TOKEN_WINDOWS: { |
| 8581 | final AppWindowToken wtoken = (AppWindowToken)msg.obj; |
| 8582 | |
| 8583 | boolean nowVisible = msg.arg1 != 0; |
| 8584 | boolean nowGone = msg.arg2 != 0; |
| 8585 | |
| 8586 | try { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8587 | if (DEBUG_VISIBILITY) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8588 | TAG, "Reporting visible in " + wtoken |
| 8589 | + " visible=" + nowVisible |
| 8590 | + " gone=" + nowGone); |
| 8591 | if (nowVisible) { |
| 8592 | wtoken.appToken.windowsVisible(); |
| 8593 | } else { |
| 8594 | wtoken.appToken.windowsGone(); |
| 8595 | } |
| 8596 | } catch (RemoteException ex) { |
| 8597 | } |
| 8598 | } break; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8599 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8600 | case WINDOW_FREEZE_TIMEOUT: { |
| 8601 | synchronized (mWindowMap) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8602 | Slog.w(TAG, "Window freeze timeout expired."); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8603 | int i = mWindows.size(); |
| 8604 | while (i > 0) { |
| 8605 | i--; |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 8606 | WindowState w = mWindows.get(i); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8607 | if (w.mOrientationChanging) { |
| 8608 | w.mOrientationChanging = false; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8609 | Slog.w(TAG, "Force clearing orientation change: " + w); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8610 | } |
| 8611 | } |
| 8612 | performLayoutAndPlaceSurfacesLocked(); |
| 8613 | } |
| 8614 | break; |
| 8615 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8616 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8617 | case HOLD_SCREEN_CHANGED: { |
| 8618 | Session oldHold; |
| 8619 | Session newHold; |
| 8620 | synchronized (mWindowMap) { |
| 8621 | oldHold = mLastReportedHold; |
| 8622 | newHold = (Session)msg.obj; |
| 8623 | mLastReportedHold = newHold; |
| 8624 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8625 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8626 | if (oldHold != newHold) { |
| 8627 | try { |
| 8628 | if (oldHold != null) { |
| Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 8629 | mBatteryStats.noteStopWakelock(oldHold.mUid, -1, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8630 | "window", |
| 8631 | BatteryStats.WAKE_TYPE_WINDOW); |
| 8632 | } |
| 8633 | if (newHold != null) { |
| Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 8634 | mBatteryStats.noteStartWakelock(newHold.mUid, -1, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8635 | "window", |
| 8636 | BatteryStats.WAKE_TYPE_WINDOW); |
| 8637 | } |
| 8638 | } catch (RemoteException e) { |
| 8639 | } |
| 8640 | } |
| 8641 | break; |
| 8642 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8643 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8644 | case APP_TRANSITION_TIMEOUT: { |
| 8645 | synchronized (mWindowMap) { |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 8646 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8647 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8648 | "*** APP TRANSITION TIMEOUT"); |
| 8649 | mAppTransitionReady = true; |
| 8650 | mAppTransitionTimeout = true; |
| 8651 | performLayoutAndPlaceSurfacesLocked(); |
| 8652 | } |
| 8653 | } |
| 8654 | break; |
| 8655 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8656 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8657 | case PERSIST_ANIMATION_SCALE: { |
| 8658 | Settings.System.putFloat(mContext.getContentResolver(), |
| 8659 | Settings.System.WINDOW_ANIMATION_SCALE, mWindowAnimationScale); |
| 8660 | Settings.System.putFloat(mContext.getContentResolver(), |
| 8661 | Settings.System.TRANSITION_ANIMATION_SCALE, mTransitionAnimationScale); |
| 8662 | break; |
| 8663 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8664 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8665 | case FORCE_GC: { |
| 8666 | synchronized(mWindowMap) { |
| 8667 | if (mAnimationPending) { |
| 8668 | // If we are animating, don't do the gc now but |
| 8669 | // delay a bit so we don't interrupt the animation. |
| 8670 | mH.sendMessageDelayed(mH.obtainMessage(H.FORCE_GC), |
| 8671 | 2000); |
| 8672 | return; |
| 8673 | } |
| 8674 | // If we are currently rotating the display, it will |
| 8675 | // schedule a new message when done. |
| 8676 | if (mDisplayFrozen) { |
| 8677 | return; |
| 8678 | } |
| 8679 | mFreezeGcPending = 0; |
| 8680 | } |
| 8681 | Runtime.getRuntime().gc(); |
| 8682 | break; |
| 8683 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8684 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8685 | case ENABLE_SCREEN: { |
| 8686 | performEnableScreen(); |
| 8687 | break; |
| 8688 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8689 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8690 | case APP_FREEZE_TIMEOUT: { |
| 8691 | synchronized (mWindowMap) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8692 | Slog.w(TAG, "App freeze timeout expired."); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8693 | int i = mAppTokens.size(); |
| 8694 | while (i > 0) { |
| 8695 | i--; |
| 8696 | AppWindowToken tok = mAppTokens.get(i); |
| 8697 | if (tok.freezingScreen) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8698 | Slog.w(TAG, "Force clearing freeze: " + tok); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8699 | unsetAppFreezingScreenLocked(tok, true, true); |
| 8700 | } |
| 8701 | } |
| 8702 | } |
| 8703 | break; |
| 8704 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8705 | |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 8706 | case SEND_NEW_CONFIGURATION: { |
| 8707 | removeMessages(SEND_NEW_CONFIGURATION); |
| 8708 | sendNewConfiguration(); |
| The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 8709 | break; |
| 8710 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8711 | |
| Konstantin Lopyrev | 6e0f65f | 2010-07-14 14:55:33 -0700 | [diff] [blame] | 8712 | case REPORT_WINDOWS_CHANGE: { |
| Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 8713 | if (mWindowsChanged) { |
| 8714 | synchronized (mWindowMap) { |
| 8715 | mWindowsChanged = false; |
| 8716 | } |
| 8717 | notifyWindowsChanged(); |
| 8718 | } |
| 8719 | break; |
| 8720 | } |
| 8721 | |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 8722 | case DRAG_START_TIMEOUT: { |
| 8723 | IBinder win = (IBinder)msg.obj; |
| 8724 | if (DEBUG_DRAG) { |
| 8725 | Slog.w(TAG, "Timeout starting drag by win " + win); |
| 8726 | } |
| 8727 | synchronized (mWindowMap) { |
| 8728 | // !!! TODO: ANR the app that has failed to start the drag in time |
| 8729 | if (mDragState != null) { |
| Chris Tate | d4533f14 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 8730 | mDragState.unregister(); |
| 8731 | mInputMonitor.updateInputWindowsLw(); |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 8732 | mDragState.reset(); |
| 8733 | mDragState = null; |
| 8734 | } |
| 8735 | } |
| Chris Tate | d4533f14 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 8736 | break; |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 8737 | } |
| 8738 | |
| Chris Tate | d4533f14 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 8739 | case DRAG_END_TIMEOUT: { |
| 8740 | IBinder win = (IBinder)msg.obj; |
| 8741 | if (DEBUG_DRAG) { |
| 8742 | Slog.w(TAG, "Timeout ending drag to win " + win); |
| 8743 | } |
| 8744 | synchronized (mWindowMap) { |
| 8745 | // !!! TODO: ANR the drag-receiving app |
| 8746 | mDragState.mDragResult = false; |
| 8747 | mDragState.endDragLw(); |
| 8748 | } |
| 8749 | break; |
| 8750 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8751 | } |
| 8752 | } |
| 8753 | } |
| 8754 | |
| 8755 | // ------------------------------------------------------------- |
| 8756 | // IWindowManager API |
| 8757 | // ------------------------------------------------------------- |
| 8758 | |
| 8759 | public IWindowSession openSession(IInputMethodClient client, |
| 8760 | IInputContext inputContext) { |
| 8761 | if (client == null) throw new IllegalArgumentException("null client"); |
| 8762 | if (inputContext == null) throw new IllegalArgumentException("null inputContext"); |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 8763 | Session session = new Session(client, inputContext); |
| 8764 | return session; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8765 | } |
| 8766 | |
| 8767 | public boolean inputMethodClientHasFocus(IInputMethodClient client) { |
| 8768 | synchronized (mWindowMap) { |
| 8769 | // The focus for the client is the window immediately below |
| 8770 | // where we would place the input method window. |
| 8771 | int idx = findDesiredInputMethodWindowIndexLocked(false); |
| 8772 | WindowState imFocus; |
| 8773 | if (idx > 0) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 8774 | imFocus = mWindows.get(idx-1); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8775 | if (imFocus != null) { |
| 8776 | if (imFocus.mSession.mClient != null && |
| 8777 | imFocus.mSession.mClient.asBinder() == client.asBinder()) { |
| 8778 | return true; |
| 8779 | } |
| 8780 | } |
| 8781 | } |
| 8782 | } |
| 8783 | return false; |
| 8784 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8785 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8786 | // ------------------------------------------------------------- |
| 8787 | // Internals |
| 8788 | // ------------------------------------------------------------- |
| 8789 | |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 8790 | final WindowState windowForClientLocked(Session session, IWindow client, |
| 8791 | boolean throwOnError) { |
| 8792 | return windowForClientLocked(session, client.asBinder(), throwOnError); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8793 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8794 | |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 8795 | final WindowState windowForClientLocked(Session session, IBinder client, |
| 8796 | boolean throwOnError) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8797 | WindowState win = mWindowMap.get(client); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8798 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8799 | TAG, "Looking up client " + client + ": " + win); |
| 8800 | if (win == null) { |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 8801 | RuntimeException ex = new IllegalArgumentException( |
| 8802 | "Requested window " + client + " does not exist"); |
| 8803 | if (throwOnError) { |
| 8804 | throw ex; |
| 8805 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8806 | Slog.w(TAG, "Failed looking up window", ex); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8807 | return null; |
| 8808 | } |
| 8809 | if (session != null && win.mSession != session) { |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 8810 | RuntimeException ex = new IllegalArgumentException( |
| 8811 | "Requested window " + client + " is in session " + |
| 8812 | win.mSession + ", not " + session); |
| 8813 | if (throwOnError) { |
| 8814 | throw ex; |
| 8815 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8816 | Slog.w(TAG, "Failed looking up window", ex); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8817 | return null; |
| 8818 | } |
| 8819 | |
| 8820 | return win; |
| 8821 | } |
| 8822 | |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8823 | final void rebuildAppWindowListLocked() { |
| 8824 | int NW = mWindows.size(); |
| 8825 | int i; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8826 | int lastWallpaper = -1; |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 8827 | int numRemoved = 0; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8828 | |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8829 | // First remove all existing app windows. |
| 8830 | i=0; |
| 8831 | while (i < NW) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 8832 | WindowState w = mWindows.get(i); |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8833 | if (w.mAppToken != null) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 8834 | WindowState win = mWindows.remove(i); |
| Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 8835 | mWindowsChanged = true; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8836 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, |
| Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 8837 | "Rebuild removing window: " + win); |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8838 | NW--; |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 8839 | numRemoved++; |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8840 | continue; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8841 | } else if (w.mAttrs.type == WindowManager.LayoutParams.TYPE_WALLPAPER |
| 8842 | && lastWallpaper == i-1) { |
| 8843 | lastWallpaper = i; |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8844 | } |
| 8845 | i++; |
| 8846 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8847 | |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8848 | // The wallpaper window(s) typically live at the bottom of the stack, |
| 8849 | // so skip them before adding app tokens. |
| 8850 | lastWallpaper++; |
| 8851 | i = lastWallpaper; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8852 | |
| Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 8853 | // First add all of the exiting app tokens... these are no longer |
| 8854 | // in the main app list, but still have windows shown. We put them |
| 8855 | // in the back because now that the animation is over we no longer |
| 8856 | // will care about them. |
| 8857 | int NT = mExitingAppTokens.size(); |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8858 | for (int j=0; j<NT; j++) { |
| Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 8859 | i = reAddAppWindowsLocked(i, mExitingAppTokens.get(j)); |
| 8860 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8861 | |
| Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 8862 | // And add in the still active app tokens in Z order. |
| 8863 | NT = mAppTokens.size(); |
| 8864 | for (int j=0; j<NT; j++) { |
| 8865 | i = reAddAppWindowsLocked(i, mAppTokens.get(j)); |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8866 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8867 | |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8868 | i -= lastWallpaper; |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 8869 | if (i != numRemoved) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8870 | Slog.w(TAG, "Rebuild removed " + numRemoved |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 8871 | + " windows but added " + i); |
| 8872 | } |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8873 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8874 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8875 | private final void assignLayersLocked() { |
| 8876 | int N = mWindows.size(); |
| 8877 | int curBaseLayer = 0; |
| 8878 | int curLayer = 0; |
| 8879 | int i; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8880 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8881 | for (i=0; i<N; i++) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 8882 | WindowState w = mWindows.get(i); |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 8883 | if (w.mBaseLayer == curBaseLayer || w.mIsImWindow |
| 8884 | || (i > 0 && w.mIsWallpaper)) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8885 | curLayer += WINDOW_LAYER_MULTIPLIER; |
| 8886 | w.mLayer = curLayer; |
| 8887 | } else { |
| 8888 | curBaseLayer = curLayer = w.mBaseLayer; |
| 8889 | w.mLayer = curLayer; |
| 8890 | } |
| 8891 | if (w.mTargetAppToken != null) { |
| 8892 | w.mAnimLayer = w.mLayer + w.mTargetAppToken.animLayerAdjustment; |
| 8893 | } else if (w.mAppToken != null) { |
| 8894 | w.mAnimLayer = w.mLayer + w.mAppToken.animLayerAdjustment; |
| 8895 | } else { |
| 8896 | w.mAnimLayer = w.mLayer; |
| 8897 | } |
| 8898 | if (w.mIsImWindow) { |
| 8899 | w.mAnimLayer += mInputMethodAnimLayerAdjustment; |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 8900 | } else if (w.mIsWallpaper) { |
| 8901 | w.mAnimLayer += mWallpaperAnimLayerAdjustment; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8902 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8903 | if (DEBUG_LAYERS) Slog.v(TAG, "Assign layer " + w + ": " |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8904 | + w.mAnimLayer); |
| 8905 | //System.out.println( |
| 8906 | // "Assigned layer " + curLayer + " to " + w.mClient.asBinder()); |
| 8907 | } |
| 8908 | } |
| 8909 | |
| 8910 | private boolean mInLayout = false; |
| 8911 | private final void performLayoutAndPlaceSurfacesLocked() { |
| 8912 | if (mInLayout) { |
| Dave Bort | cfe6524 | 2009-04-09 14:51:04 -0700 | [diff] [blame] | 8913 | if (DEBUG) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8914 | throw new RuntimeException("Recursive call!"); |
| 8915 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8916 | Slog.w(TAG, "performLayoutAndPlaceSurfacesLocked called while in layout"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8917 | return; |
| 8918 | } |
| 8919 | |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 8920 | if (mWaitingForConfig) { |
| 8921 | // Our configuration has changed (most likely rotation), but we |
| 8922 | // don't yet have the complete configuration to report to |
| 8923 | // applications. Don't do any window layout until we have it. |
| 8924 | return; |
| 8925 | } |
| 8926 | |
| Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 8927 | if (mDisplay == null) { |
| 8928 | // Not yet initialized, nothing to do. |
| 8929 | return; |
| 8930 | } |
| 8931 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8932 | boolean recoveringMemory = false; |
| 8933 | if (mForceRemoves != null) { |
| 8934 | recoveringMemory = true; |
| 8935 | // Wait a little it for things to settle down, and off we go. |
| 8936 | for (int i=0; i<mForceRemoves.size(); i++) { |
| 8937 | WindowState ws = mForceRemoves.get(i); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8938 | Slog.i(TAG, "Force removing: " + ws); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8939 | removeWindowInnerLocked(ws.mSession, ws); |
| 8940 | } |
| 8941 | mForceRemoves = null; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8942 | 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] | 8943 | Object tmp = new Object(); |
| 8944 | synchronized (tmp) { |
| 8945 | try { |
| 8946 | tmp.wait(250); |
| 8947 | } catch (InterruptedException e) { |
| 8948 | } |
| 8949 | } |
| 8950 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8951 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8952 | mInLayout = true; |
| 8953 | try { |
| 8954 | performLayoutAndPlaceSurfacesLockedInner(recoveringMemory); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8955 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8956 | int i = mPendingRemove.size()-1; |
| 8957 | if (i >= 0) { |
| 8958 | while (i >= 0) { |
| 8959 | WindowState w = mPendingRemove.get(i); |
| 8960 | removeWindowInnerLocked(w.mSession, w); |
| 8961 | i--; |
| 8962 | } |
| 8963 | mPendingRemove.clear(); |
| 8964 | |
| 8965 | mInLayout = false; |
| 8966 | assignLayersLocked(); |
| 8967 | mLayoutNeeded = true; |
| 8968 | performLayoutAndPlaceSurfacesLocked(); |
| 8969 | |
| 8970 | } else { |
| 8971 | mInLayout = false; |
| 8972 | if (mLayoutNeeded) { |
| 8973 | requestAnimationLocked(0); |
| 8974 | } |
| 8975 | } |
| Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 8976 | if (mWindowsChanged && !mWindowChangeListeners.isEmpty()) { |
| Konstantin Lopyrev | 6e0f65f | 2010-07-14 14:55:33 -0700 | [diff] [blame] | 8977 | mH.removeMessages(H.REPORT_WINDOWS_CHANGE); |
| 8978 | mH.sendMessage(mH.obtainMessage(H.REPORT_WINDOWS_CHANGE)); |
| Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 8979 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8980 | } catch (RuntimeException e) { |
| 8981 | mInLayout = false; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8982 | 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] | 8983 | } |
| 8984 | } |
| 8985 | |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 8986 | private final int performLayoutLockedInner() { |
| 8987 | if (!mLayoutNeeded) { |
| 8988 | return 0; |
| 8989 | } |
| 8990 | |
| 8991 | mLayoutNeeded = false; |
| 8992 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8993 | final int dw = mDisplay.getWidth(); |
| 8994 | final int dh = mDisplay.getHeight(); |
| 8995 | |
| 8996 | final int N = mWindows.size(); |
| 8997 | int i; |
| 8998 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8999 | if (DEBUG_LAYOUT) Slog.v(TAG, "performLayout: needed=" |
| Dianne Hackborn | 9b52a21 | 2009-12-11 14:51:35 -0800 | [diff] [blame] | 9000 | + mLayoutNeeded + " dw=" + dw + " dh=" + dh); |
| 9001 | |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9002 | mPolicy.beginLayoutLw(dw, dh); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9003 | |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9004 | int seq = mLayoutSeq+1; |
| 9005 | if (seq < 0) seq = 0; |
| 9006 | mLayoutSeq = seq; |
| 9007 | |
| 9008 | // First perform layout of any root windows (not attached |
| 9009 | // to another window). |
| 9010 | int topAttached = -1; |
| 9011 | for (i = N-1; i >= 0; i--) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 9012 | WindowState win = mWindows.get(i); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9013 | |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9014 | // Don't do layout of a window if it is not visible, or |
| 9015 | // soon won't be visible, to avoid wasting time and funky |
| 9016 | // changes while a window is animating away. |
| 9017 | final AppWindowToken atoken = win.mAppToken; |
| 9018 | final boolean gone = win.mViewVisibility == View.GONE |
| 9019 | || !win.mRelayoutCalled |
| 9020 | || win.mRootToken.hidden |
| 9021 | || (atoken != null && atoken.hiddenRequested) |
| 9022 | || win.mAttachedHidden |
| 9023 | || win.mExiting || win.mDestroying; |
| 9024 | |
| 9025 | if (!win.mLayoutAttached) { |
| 9026 | if (DEBUG_LAYOUT) Slog.v(TAG, "First pass " + win |
| 9027 | + ": gone=" + gone + " mHaveFrame=" + win.mHaveFrame |
| 9028 | + " mLayoutAttached=" + win.mLayoutAttached); |
| 9029 | if (DEBUG_LAYOUT && gone) Slog.v(TAG, " (mViewVisibility=" |
| 9030 | + win.mViewVisibility + " mRelayoutCalled=" |
| 9031 | + win.mRelayoutCalled + " hidden=" |
| 9032 | + win.mRootToken.hidden + " hiddenRequested=" |
| 9033 | + (atoken != null && atoken.hiddenRequested) |
| 9034 | + " mAttachedHidden=" + win.mAttachedHidden); |
| 9035 | } |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 9036 | |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9037 | // If this view is GONE, then skip it -- keep the current |
| 9038 | // frame, and let the caller know so they can ignore it |
| 9039 | // if they want. (We do the normal layout for INVISIBLE |
| 9040 | // windows, since that means "perform layout as normal, |
| 9041 | // just don't display"). |
| 9042 | if (!gone || !win.mHaveFrame) { |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 9043 | if (!win.mLayoutAttached) { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9044 | mPolicy.layoutWindowLw(win, win.mAttrs, null); |
| 9045 | win.mLayoutSeq = seq; |
| 9046 | if (DEBUG_LAYOUT) Slog.v(TAG, "-> mFrame=" |
| 9047 | + win.mFrame + " mContainingFrame=" |
| 9048 | + win.mContainingFrame + " mDisplayFrame=" |
| 9049 | + win.mDisplayFrame); |
| 9050 | } else { |
| 9051 | if (topAttached < 0) topAttached = i; |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 9052 | } |
| Dianne Hackborn | 958b9ad | 2009-03-31 18:00:36 -0700 | [diff] [blame] | 9053 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9054 | } |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9055 | |
| 9056 | // Now perform layout of attached windows, which usually |
| 9057 | // depend on the position of the window they are attached to. |
| 9058 | // XXX does not deal with windows that are attached to windows |
| 9059 | // that are themselves attached. |
| 9060 | for (i = topAttached; i >= 0; i--) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 9061 | WindowState win = mWindows.get(i); |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9062 | |
| 9063 | // If this view is GONE, then skip it -- keep the current |
| 9064 | // frame, and let the caller know so they can ignore it |
| 9065 | // if they want. (We do the normal layout for INVISIBLE |
| 9066 | // windows, since that means "perform layout as normal, |
| 9067 | // just don't display"). |
| 9068 | if (win.mLayoutAttached) { |
| 9069 | if (DEBUG_LAYOUT) Slog.v(TAG, "Second pass " + win |
| 9070 | + " mHaveFrame=" + win.mHaveFrame |
| 9071 | + " mViewVisibility=" + win.mViewVisibility |
| 9072 | + " mRelayoutCalled=" + win.mRelayoutCalled); |
| 9073 | if ((win.mViewVisibility != View.GONE && win.mRelayoutCalled) |
| 9074 | || !win.mHaveFrame) { |
| 9075 | mPolicy.layoutWindowLw(win, win.mAttrs, win.mAttachedWindow); |
| 9076 | win.mLayoutSeq = seq; |
| 9077 | if (DEBUG_LAYOUT) Slog.v(TAG, "-> mFrame=" |
| 9078 | + win.mFrame + " mContainingFrame=" |
| 9079 | + win.mContainingFrame + " mDisplayFrame=" |
| 9080 | + win.mDisplayFrame); |
| 9081 | } |
| 9082 | } |
| 9083 | } |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 9084 | |
| 9085 | // Window frames may have changed. Tell the input dispatcher about it. |
| Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 9086 | mInputMonitor.updateInputWindowsLw(); |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9087 | |
| 9088 | return mPolicy.finishLayoutLw(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9089 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9090 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9091 | private final void performLayoutAndPlaceSurfacesLockedInner( |
| 9092 | boolean recoveringMemory) { |
| Joe Onorato | 34bcebc | 2010-07-07 18:05:01 -0400 | [diff] [blame] | 9093 | if (mDisplay == null) { |
| 9094 | Slog.i(TAG, "skipping performLayoutAndPlaceSurfacesLockedInner with no mDisplay"); |
| 9095 | return; |
| 9096 | } |
| 9097 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9098 | final long currentTime = SystemClock.uptimeMillis(); |
| 9099 | final int dw = mDisplay.getWidth(); |
| 9100 | final int dh = mDisplay.getHeight(); |
| 9101 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9102 | int i; |
| 9103 | |
| Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 9104 | if (mFocusMayChange) { |
| 9105 | mFocusMayChange = false; |
| 9106 | updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES); |
| 9107 | } |
| 9108 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9109 | // Initialize state of exiting tokens. |
| 9110 | for (i=mExitingTokens.size()-1; i>=0; i--) { |
| 9111 | mExitingTokens.get(i).hasVisible = false; |
| 9112 | } |
| 9113 | |
| 9114 | // Initialize state of exiting applications. |
| 9115 | for (i=mExitingAppTokens.size()-1; i>=0; i--) { |
| 9116 | mExitingAppTokens.get(i).hasVisible = false; |
| 9117 | } |
| 9118 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9119 | boolean orientationChangeComplete = true; |
| 9120 | Session holdScreen = null; |
| 9121 | float screenBrightness = -1; |
| Mike Lockwood | fb73f79 | 2009-11-20 11:31:18 -0500 | [diff] [blame] | 9122 | float buttonBrightness = -1; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9123 | boolean focusDisplayed = false; |
| 9124 | boolean animating = false; |
| Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 9125 | boolean createWatermark = false; |
| 9126 | |
| 9127 | if (mFxSession == null) { |
| 9128 | mFxSession = new SurfaceSession(); |
| 9129 | createWatermark = true; |
| 9130 | } |
| 9131 | |
| 9132 | if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9133 | |
| 9134 | Surface.openTransaction(); |
| Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 9135 | |
| 9136 | if (createWatermark) { |
| 9137 | createWatermark(); |
| 9138 | } |
| 9139 | if (mWatermark != null) { |
| 9140 | mWatermark.positionSurface(dw, dh); |
| 9141 | } |
| 9142 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9143 | try { |
| Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 9144 | boolean wallpaperForceHidingChanged = false; |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9145 | int repeats = 0; |
| 9146 | int changes = 0; |
| 9147 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9148 | do { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9149 | repeats++; |
| 9150 | if (repeats > 6) { |
| 9151 | Slog.w(TAG, "Animation repeat aborted after too many iterations"); |
| 9152 | mLayoutNeeded = false; |
| 9153 | break; |
| 9154 | } |
| 9155 | |
| 9156 | if ((changes&(WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER |
| 9157 | | WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG |
| 9158 | | WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT)) != 0) { |
| 9159 | if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER) != 0) { |
| 9160 | if ((adjustWallpaperWindowsLocked()&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) { |
| 9161 | assignLayersLocked(); |
| 9162 | mLayoutNeeded = true; |
| 9163 | } |
| 9164 | } |
| 9165 | if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG) != 0) { |
| 9166 | if (DEBUG_LAYOUT) Slog.v(TAG, "Computing new config from layout"); |
| 9167 | if (updateOrientationFromAppTokensLocked()) { |
| 9168 | mLayoutNeeded = true; |
| 9169 | mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION); |
| 9170 | } |
| 9171 | } |
| 9172 | if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT) != 0) { |
| 9173 | mLayoutNeeded = true; |
| 9174 | } |
| 9175 | } |
| 9176 | |
| 9177 | // FIRST LOOP: Perform a layout, if needed. |
| 9178 | if (repeats < 4) { |
| 9179 | changes = performLayoutLockedInner(); |
| 9180 | if (changes != 0) { |
| 9181 | continue; |
| 9182 | } |
| 9183 | } else { |
| 9184 | Slog.w(TAG, "Layout repeat skipped after too many iterations"); |
| 9185 | changes = 0; |
| 9186 | } |
| 9187 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9188 | final int transactionSequence = ++mTransactionSequence; |
| 9189 | |
| 9190 | // Update animations of all applications, including those |
| 9191 | // associated with exiting/removed apps |
| 9192 | boolean tokensAnimating = false; |
| 9193 | final int NAT = mAppTokens.size(); |
| 9194 | for (i=0; i<NAT; i++) { |
| 9195 | if (mAppTokens.get(i).stepAnimationLocked(currentTime, dw, dh)) { |
| 9196 | tokensAnimating = true; |
| 9197 | } |
| 9198 | } |
| 9199 | final int NEAT = mExitingAppTokens.size(); |
| 9200 | for (i=0; i<NEAT; i++) { |
| 9201 | if (mExitingAppTokens.get(i).stepAnimationLocked(currentTime, dw, dh)) { |
| 9202 | tokensAnimating = true; |
| 9203 | } |
| 9204 | } |
| 9205 | |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9206 | // SECOND LOOP: Execute animations and update visibility of windows. |
| 9207 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9208 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "*** ANIM STEP: seq=" |
| Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 9209 | + transactionSequence + " tokensAnimating=" |
| 9210 | + tokensAnimating); |
| 9211 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9212 | animating = tokensAnimating; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9213 | |
| 9214 | boolean tokenMayBeDrawn = false; |
| Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 9215 | boolean wallpaperMayChange = false; |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9216 | boolean forceHiding = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9217 | |
| 9218 | mPolicy.beginAnimationLw(dw, dh); |
| 9219 | |
| Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 9220 | final int N = mWindows.size(); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9221 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9222 | for (i=N-1; i>=0; i--) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 9223 | WindowState w = mWindows.get(i); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9224 | |
| 9225 | final WindowManager.LayoutParams attrs = w.mAttrs; |
| 9226 | |
| 9227 | if (w.mSurface != null) { |
| 9228 | // Execute animation. |
| Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 9229 | if (w.commitFinishDrawingLocked(currentTime)) { |
| 9230 | if ((w.mAttrs.flags |
| 9231 | & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER) != 0) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9232 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 9233 | "First draw done in potential wallpaper target " + w); |
| Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 9234 | wallpaperMayChange = true; |
| 9235 | } |
| 9236 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9237 | |
| Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 9238 | boolean wasAnimating = w.mAnimating; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9239 | if (w.stepAnimationLocked(currentTime, dw, dh)) { |
| 9240 | animating = true; |
| 9241 | //w.dump(" "); |
| 9242 | } |
| Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 9243 | if (wasAnimating && !w.mAnimating && mWallpaperTarget == w) { |
| 9244 | wallpaperMayChange = true; |
| 9245 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9246 | |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9247 | if (mPolicy.doesForceHide(w, attrs)) { |
| 9248 | if (!wasAnimating && animating) { |
| Dianne Hackborn | 20cb56e | 2010-03-04 00:58:29 -0800 | [diff] [blame] | 9249 | if (DEBUG_VISIBILITY) Slog.v(TAG, |
| 9250 | "Animation done that could impact force hide: " |
| 9251 | + w); |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9252 | wallpaperForceHidingChanged = true; |
| Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 9253 | mFocusMayChange = true; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9254 | } else if (w.isReadyForDisplay() && w.mAnimation == null) { |
| 9255 | forceHiding = true; |
| 9256 | } |
| 9257 | } else if (mPolicy.canBeForceHidden(w, attrs)) { |
| 9258 | boolean changed; |
| 9259 | if (forceHiding) { |
| 9260 | changed = w.hideLw(false, false); |
| Dianne Hackborn | 20cb56e | 2010-03-04 00:58:29 -0800 | [diff] [blame] | 9261 | if (DEBUG_VISIBILITY && changed) Slog.v(TAG, |
| 9262 | "Now policy hidden: " + w); |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9263 | } else { |
| 9264 | changed = w.showLw(false, false); |
| Dianne Hackborn | 20cb56e | 2010-03-04 00:58:29 -0800 | [diff] [blame] | 9265 | if (DEBUG_VISIBILITY && changed) Slog.v(TAG, |
| 9266 | "Now policy shown: " + w); |
| 9267 | if (changed) { |
| 9268 | if (wallpaperForceHidingChanged |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9269 | && w.isVisibleNow() /*w.isReadyForDisplay()*/) { |
| Dianne Hackborn | 20cb56e | 2010-03-04 00:58:29 -0800 | [diff] [blame] | 9270 | // Assume we will need to animate. If |
| 9271 | // we don't (because the wallpaper will |
| 9272 | // stay with the lock screen), then we will |
| 9273 | // clean up later. |
| 9274 | Animation a = mPolicy.createForceHideEnterAnimation(); |
| 9275 | if (a != null) { |
| 9276 | w.setAnimation(a); |
| 9277 | } |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9278 | } |
| Dianne Hackborn | 20cb56e | 2010-03-04 00:58:29 -0800 | [diff] [blame] | 9279 | if (mCurrentFocus == null || |
| 9280 | mCurrentFocus.mLayer < w.mLayer) { |
| 9281 | // We are showing on to of the current |
| 9282 | // focus, so re-evaluate focus to make |
| 9283 | // sure it is correct. |
| 9284 | mFocusMayChange = true; |
| 9285 | } |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9286 | } |
| 9287 | } |
| 9288 | if (changed && (attrs.flags |
| 9289 | & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER) != 0) { |
| 9290 | wallpaperMayChange = true; |
| 9291 | } |
| 9292 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9293 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9294 | mPolicy.animatingWindowLw(w, attrs); |
| 9295 | } |
| 9296 | |
| 9297 | final AppWindowToken atoken = w.mAppToken; |
| 9298 | if (atoken != null && (!atoken.allDrawn || atoken.freezingScreen)) { |
| 9299 | if (atoken.lastTransactionSequence != transactionSequence) { |
| 9300 | atoken.lastTransactionSequence = transactionSequence; |
| 9301 | atoken.numInterestingWindows = atoken.numDrawnWindows = 0; |
| 9302 | atoken.startingDisplayed = false; |
| 9303 | } |
| 9304 | if ((w.isOnScreen() || w.mAttrs.type |
| 9305 | == WindowManager.LayoutParams.TYPE_BASE_APPLICATION) |
| 9306 | && !w.mExiting && !w.mDestroying) { |
| 9307 | if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9308 | Slog.v(TAG, "Eval win " + w + ": isDrawn=" |
| Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 9309 | + w.isDrawnLw() |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9310 | + ", isAnimating=" + w.isAnimating()); |
| Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 9311 | if (!w.isDrawnLw()) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9312 | Slog.v(TAG, "Not displayed: s=" + w.mSurface |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9313 | + " pv=" + w.mPolicyVisibility |
| 9314 | + " dp=" + w.mDrawPending |
| 9315 | + " cdp=" + w.mCommitDrawPending |
| 9316 | + " ah=" + w.mAttachedHidden |
| 9317 | + " th=" + atoken.hiddenRequested |
| 9318 | + " a=" + w.mAnimating); |
| 9319 | } |
| 9320 | } |
| 9321 | if (w != atoken.startingWindow) { |
| 9322 | if (!atoken.freezingScreen || !w.mAppFreezing) { |
| 9323 | atoken.numInterestingWindows++; |
| Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 9324 | if (w.isDrawnLw()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9325 | atoken.numDrawnWindows++; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9326 | if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9327 | "tokenMayBeDrawn: " + atoken |
| 9328 | + " freezingScreen=" + atoken.freezingScreen |
| 9329 | + " mAppFreezing=" + w.mAppFreezing); |
| 9330 | tokenMayBeDrawn = true; |
| 9331 | } |
| 9332 | } |
| Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 9333 | } else if (w.isDrawnLw()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9334 | atoken.startingDisplayed = true; |
| 9335 | } |
| 9336 | } |
| 9337 | } else if (w.mReadyToShow) { |
| 9338 | w.performShowLocked(); |
| 9339 | } |
| 9340 | } |
| 9341 | |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9342 | changes |= mPolicy.finishAnimationLw(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9343 | |
| 9344 | if (tokenMayBeDrawn) { |
| 9345 | // See if any windows have been drawn, so they (and others |
| 9346 | // associated with them) can now be shown. |
| 9347 | final int NT = mTokenList.size(); |
| 9348 | for (i=0; i<NT; i++) { |
| 9349 | AppWindowToken wtoken = mTokenList.get(i).appWindowToken; |
| 9350 | if (wtoken == null) { |
| 9351 | continue; |
| 9352 | } |
| 9353 | if (wtoken.freezingScreen) { |
| 9354 | int numInteresting = wtoken.numInterestingWindows; |
| 9355 | if (numInteresting > 0 && wtoken.numDrawnWindows >= numInteresting) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9356 | if (DEBUG_VISIBILITY) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9357 | "allDrawn: " + wtoken |
| 9358 | + " interesting=" + numInteresting |
| 9359 | + " drawn=" + wtoken.numDrawnWindows); |
| 9360 | wtoken.showAllWindowsLocked(); |
| 9361 | unsetAppFreezingScreenLocked(wtoken, false, true); |
| 9362 | orientationChangeComplete = true; |
| 9363 | } |
| 9364 | } else if (!wtoken.allDrawn) { |
| 9365 | int numInteresting = wtoken.numInterestingWindows; |
| 9366 | if (numInteresting > 0 && wtoken.numDrawnWindows >= numInteresting) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9367 | if (DEBUG_VISIBILITY) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9368 | "allDrawn: " + wtoken |
| 9369 | + " interesting=" + numInteresting |
| 9370 | + " drawn=" + wtoken.numDrawnWindows); |
| 9371 | wtoken.allDrawn = true; |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9372 | changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9373 | |
| 9374 | // We can now show all of the drawn windows! |
| 9375 | if (!mOpeningApps.contains(wtoken)) { |
| 9376 | wtoken.showAllWindowsLocked(); |
| 9377 | } |
| 9378 | } |
| 9379 | } |
| 9380 | } |
| 9381 | } |
| 9382 | |
| 9383 | // If we are ready to perform an app transition, check through |
| 9384 | // all of the app tokens to be shown and see if they are ready |
| 9385 | // to go. |
| 9386 | if (mAppTransitionReady) { |
| 9387 | int NN = mOpeningApps.size(); |
| 9388 | boolean goodToGo = true; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9389 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9390 | "Checking " + NN + " opening apps (frozen=" |
| 9391 | + mDisplayFrozen + " timeout=" |
| 9392 | + mAppTransitionTimeout + ")..."); |
| 9393 | if (!mDisplayFrozen && !mAppTransitionTimeout) { |
| 9394 | // If the display isn't frozen, wait to do anything until |
| 9395 | // all of the apps are ready. Otherwise just go because |
| 9396 | // we'll unfreeze the display when everyone is ready. |
| 9397 | for (i=0; i<NN && goodToGo; i++) { |
| 9398 | AppWindowToken wtoken = mOpeningApps.get(i); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9399 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9400 | "Check opening app" + wtoken + ": allDrawn=" |
| 9401 | + wtoken.allDrawn + " startingDisplayed=" |
| 9402 | + wtoken.startingDisplayed); |
| 9403 | if (!wtoken.allDrawn && !wtoken.startingDisplayed |
| 9404 | && !wtoken.startingMoved) { |
| 9405 | goodToGo = false; |
| 9406 | } |
| 9407 | } |
| 9408 | } |
| 9409 | if (goodToGo) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9410 | 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] | 9411 | int transit = mNextAppTransition; |
| 9412 | if (mSkipAppTransitionAnimation) { |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 9413 | transit = WindowManagerPolicy.TRANSIT_UNSET; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9414 | } |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 9415 | mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9416 | mAppTransitionReady = false; |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9417 | mAppTransitionRunning = true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9418 | mAppTransitionTimeout = false; |
| 9419 | mStartingIconInTransition = false; |
| 9420 | mSkipAppTransitionAnimation = false; |
| 9421 | |
| 9422 | mH.removeMessages(H.APP_TRANSITION_TIMEOUT); |
| 9423 | |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9424 | // If there are applications waiting to come to the |
| 9425 | // top of the stack, now is the time to move their windows. |
| 9426 | // (Note that we don't do apps going to the bottom |
| 9427 | // here -- we want to keep their windows in the old |
| 9428 | // Z-order until the animation completes.) |
| 9429 | if (mToTopApps.size() > 0) { |
| 9430 | NN = mAppTokens.size(); |
| 9431 | for (i=0; i<NN; i++) { |
| 9432 | AppWindowToken wtoken = mAppTokens.get(i); |
| 9433 | if (wtoken.sendingToTop) { |
| 9434 | wtoken.sendingToTop = false; |
| 9435 | moveAppWindowsLocked(wtoken, NN, false); |
| 9436 | } |
| 9437 | } |
| 9438 | mToTopApps.clear(); |
| 9439 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9440 | |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 9441 | WindowState oldWallpaper = mWallpaperTarget; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9442 | |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 9443 | adjustWallpaperWindowsLocked(); |
| Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 9444 | wallpaperMayChange = false; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9445 | |
| Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 9446 | // The top-most window will supply the layout params, |
| 9447 | // and we will determine it below. |
| 9448 | LayoutParams animLp = null; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9449 | AppWindowToken animToken = null; |
| Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 9450 | int bestAnimLayer = -1; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9451 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9452 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 9453 | "New wallpaper target=" + mWallpaperTarget |
| 9454 | + ", lower target=" + mLowerWallpaperTarget |
| 9455 | + ", upper target=" + mUpperWallpaperTarget); |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 9456 | int foundWallpapers = 0; |
| Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 9457 | // Do a first pass through the tokens for two |
| 9458 | // things: |
| 9459 | // (1) Determine if both the closing and opening |
| 9460 | // app token sets are wallpaper targets, in which |
| 9461 | // case special animations are needed |
| 9462 | // (since the wallpaper needs to stay static |
| 9463 | // behind them). |
| 9464 | // (2) Find the layout params of the top-most |
| 9465 | // application window in the tokens, which is |
| 9466 | // what will control the animation theme. |
| 9467 | final int NC = mClosingApps.size(); |
| 9468 | NN = NC + mOpeningApps.size(); |
| 9469 | for (i=0; i<NN; i++) { |
| 9470 | AppWindowToken wtoken; |
| 9471 | int mode; |
| 9472 | if (i < NC) { |
| 9473 | wtoken = mClosingApps.get(i); |
| 9474 | mode = 1; |
| 9475 | } else { |
| 9476 | wtoken = mOpeningApps.get(i-NC); |
| 9477 | mode = 2; |
| 9478 | } |
| 9479 | if (mLowerWallpaperTarget != null) { |
| 9480 | if (mLowerWallpaperTarget.mAppToken == wtoken |
| 9481 | || mUpperWallpaperTarget.mAppToken == wtoken) { |
| 9482 | foundWallpapers |= mode; |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 9483 | } |
| 9484 | } |
| Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 9485 | if (wtoken.appFullscreen) { |
| 9486 | WindowState ws = wtoken.findMainWindow(); |
| 9487 | if (ws != null) { |
| 9488 | // If this is a compatibility mode |
| 9489 | // window, we will always use its anim. |
| 9490 | if ((ws.mAttrs.flags&FLAG_COMPATIBLE_WINDOW) != 0) { |
| 9491 | animLp = ws.mAttrs; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9492 | animToken = ws.mAppToken; |
| Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 9493 | bestAnimLayer = Integer.MAX_VALUE; |
| 9494 | } else if (ws.mLayer > bestAnimLayer) { |
| 9495 | animLp = ws.mAttrs; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9496 | animToken = ws.mAppToken; |
| Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 9497 | bestAnimLayer = ws.mLayer; |
| 9498 | } |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 9499 | } |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 9500 | } |
| 9501 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9502 | |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 9503 | if (foundWallpapers == 3) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9504 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 9505 | "Wallpaper animation!"); |
| 9506 | switch (transit) { |
| 9507 | case WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN: |
| 9508 | case WindowManagerPolicy.TRANSIT_TASK_OPEN: |
| 9509 | case WindowManagerPolicy.TRANSIT_TASK_TO_FRONT: |
| 9510 | transit = WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_OPEN; |
| 9511 | break; |
| 9512 | case WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE: |
| 9513 | case WindowManagerPolicy.TRANSIT_TASK_CLOSE: |
| 9514 | case WindowManagerPolicy.TRANSIT_TASK_TO_BACK: |
| 9515 | transit = WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_CLOSE; |
| 9516 | break; |
| 9517 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9518 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 9519 | "New transit: " + transit); |
| 9520 | } else if (oldWallpaper != null) { |
| 9521 | // We are transitioning from an activity with |
| 9522 | // a wallpaper to one without. |
| 9523 | transit = WindowManagerPolicy.TRANSIT_WALLPAPER_CLOSE; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9524 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 9525 | "New transit away from wallpaper: " + transit); |
| 9526 | } else if (mWallpaperTarget != null) { |
| 9527 | // We are transitioning from an activity without |
| 9528 | // a wallpaper to now showing the wallpaper |
| 9529 | transit = WindowManagerPolicy.TRANSIT_WALLPAPER_OPEN; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9530 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 9531 | "New transit into wallpaper: " + transit); |
| 9532 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9533 | |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9534 | if ((transit&WindowManagerPolicy.TRANSIT_ENTER_MASK) != 0) { |
| 9535 | mLastEnterAnimToken = animToken; |
| 9536 | mLastEnterAnimParams = animLp; |
| 9537 | } else if (mLastEnterAnimParams != null) { |
| 9538 | animLp = mLastEnterAnimParams; |
| 9539 | mLastEnterAnimToken = null; |
| 9540 | mLastEnterAnimParams = null; |
| 9541 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9542 | |
| Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 9543 | // If all closing windows are obscured, then there is |
| 9544 | // no need to do an animation. This is the case, for |
| 9545 | // example, when this transition is being done behind |
| 9546 | // the lock screen. |
| 9547 | if (!mPolicy.allowAppAnimationsLw()) { |
| 9548 | animLp = null; |
| 9549 | } |
| 9550 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9551 | NN = mOpeningApps.size(); |
| 9552 | for (i=0; i<NN; i++) { |
| 9553 | AppWindowToken wtoken = mOpeningApps.get(i); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9554 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9555 | "Now opening app" + wtoken); |
| 9556 | wtoken.reportedVisible = false; |
| 9557 | wtoken.inPendingTransaction = false; |
| Dianne Hackborn | 83360b3 | 2009-08-24 18:43:32 -0700 | [diff] [blame] | 9558 | wtoken.animation = null; |
| Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 9559 | setTokenVisibilityLocked(wtoken, animLp, true, transit, false); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9560 | wtoken.updateReportedVisibilityLocked(); |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9561 | wtoken.waitingToShow = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9562 | wtoken.showAllWindowsLocked(); |
| 9563 | } |
| 9564 | NN = mClosingApps.size(); |
| 9565 | for (i=0; i<NN; i++) { |
| 9566 | AppWindowToken wtoken = mClosingApps.get(i); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9567 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9568 | "Now closing app" + wtoken); |
| 9569 | wtoken.inPendingTransaction = false; |
| Dianne Hackborn | 83360b3 | 2009-08-24 18:43:32 -0700 | [diff] [blame] | 9570 | wtoken.animation = null; |
| Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 9571 | setTokenVisibilityLocked(wtoken, animLp, false, transit, false); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9572 | wtoken.updateReportedVisibilityLocked(); |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9573 | wtoken.waitingToHide = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9574 | // Force the allDrawn flag, because we want to start |
| 9575 | // this guy's animations regardless of whether it's |
| 9576 | // gotten drawn. |
| 9577 | wtoken.allDrawn = true; |
| 9578 | } |
| 9579 | |
| Dianne Hackborn | 8b571a8 | 2009-09-25 16:09:43 -0700 | [diff] [blame] | 9580 | mNextAppTransitionPackage = null; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9581 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9582 | mOpeningApps.clear(); |
| 9583 | mClosingApps.clear(); |
| 9584 | |
| 9585 | // This has changed the visibility of windows, so perform |
| 9586 | // a new layout to get them all up-to-date. |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9587 | changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9588 | mLayoutNeeded = true; |
| Dianne Hackborn | 20583ff | 2009-07-27 21:51:05 -0700 | [diff] [blame] | 9589 | if (!moveInputMethodWindowsIfNeededLocked(true)) { |
| 9590 | assignLayersLocked(); |
| 9591 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9592 | updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES); |
| Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 9593 | mFocusMayChange = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9594 | } |
| 9595 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9596 | |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 9597 | int adjResult = 0; |
| 9598 | |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9599 | if (!animating && mAppTransitionRunning) { |
| 9600 | // We have finished the animation of an app transition. To do |
| 9601 | // this, we have delayed a lot of operations like showing and |
| 9602 | // hiding apps, moving apps in Z-order, etc. The app token list |
| 9603 | // reflects the correct Z-order, but the window list may now |
| 9604 | // be out of sync with it. So here we will just rebuild the |
| 9605 | // entire app window list. Fun! |
| 9606 | mAppTransitionRunning = false; |
| 9607 | // Clear information about apps that were moving. |
| 9608 | mToBottomApps.clear(); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9609 | |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9610 | rebuildAppWindowListLocked(); |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9611 | changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT; |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 9612 | adjResult |= ADJUST_WALLPAPER_LAYERS_CHANGED; |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9613 | moveInputMethodWindowsIfNeededLocked(false); |
| 9614 | wallpaperMayChange = true; |
| Suchi Amalapurapu | c9568e3 | 2009-11-05 18:51:16 -0800 | [diff] [blame] | 9615 | // Since the window list has been rebuilt, focus might |
| 9616 | // have to be recomputed since the actual order of windows |
| 9617 | // might have changed again. |
| Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 9618 | mFocusMayChange = true; |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9619 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9620 | |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9621 | if (wallpaperForceHidingChanged && changes == 0 && !mAppTransitionReady) { |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9622 | // At this point, there was a window with a wallpaper that |
| 9623 | // was force hiding other windows behind it, but now it |
| 9624 | // is going away. This may be simple -- just animate |
| 9625 | // away the wallpaper and its window -- or it may be |
| 9626 | // hard -- the wallpaper now needs to be shown behind |
| 9627 | // something that was hidden. |
| 9628 | WindowState oldWallpaper = mWallpaperTarget; |
| Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 9629 | if (mLowerWallpaperTarget != null |
| 9630 | && mLowerWallpaperTarget.mAppToken != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9631 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
| Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 9632 | "wallpaperForceHiding changed with lower=" |
| 9633 | + mLowerWallpaperTarget); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9634 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
| Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 9635 | "hidden=" + mLowerWallpaperTarget.mAppToken.hidden + |
| 9636 | " hiddenRequested=" + mLowerWallpaperTarget.mAppToken.hiddenRequested); |
| 9637 | if (mLowerWallpaperTarget.mAppToken.hidden) { |
| 9638 | // The lower target has become hidden before we |
| 9639 | // actually started the animation... let's completely |
| 9640 | // re-evaluate everything. |
| 9641 | mLowerWallpaperTarget = mUpperWallpaperTarget = null; |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9642 | changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM; |
| Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 9643 | } |
| 9644 | } |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 9645 | adjResult |= adjustWallpaperWindowsLocked(); |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9646 | wallpaperMayChange = false; |
| Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 9647 | wallpaperForceHidingChanged = false; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9648 | if (DEBUG_WALLPAPER) Slog.v(TAG, "****** OLD: " + oldWallpaper |
| Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 9649 | + " NEW: " + mWallpaperTarget |
| 9650 | + " LOWER: " + mLowerWallpaperTarget); |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9651 | if (mLowerWallpaperTarget == null) { |
| 9652 | // Whoops, we don't need a special wallpaper animation. |
| 9653 | // Clear them out. |
| 9654 | forceHiding = false; |
| 9655 | for (i=N-1; i>=0; i--) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 9656 | WindowState w = mWindows.get(i); |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9657 | if (w.mSurface != null) { |
| 9658 | final WindowManager.LayoutParams attrs = w.mAttrs; |
| Suchi Amalapurapu | c03d28b | 2009-10-28 14:32:05 -0700 | [diff] [blame] | 9659 | if (mPolicy.doesForceHide(w, attrs) && w.isVisibleLw()) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9660 | if (DEBUG_FOCUS) Slog.i(TAG, "win=" + w + " force hides other windows"); |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9661 | forceHiding = true; |
| 9662 | } else if (mPolicy.canBeForceHidden(w, attrs)) { |
| 9663 | if (!w.mAnimating) { |
| 9664 | // We set the animation above so it |
| 9665 | // is not yet running. |
| 9666 | w.clearAnimation(); |
| 9667 | } |
| 9668 | } |
| 9669 | } |
| 9670 | } |
| 9671 | } |
| 9672 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9673 | |
| Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 9674 | if (wallpaperMayChange) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9675 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 9676 | "Wallpaper may change! Adjusting"); |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 9677 | adjResult |= adjustWallpaperWindowsLocked(); |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9678 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9679 | |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9680 | if ((adjResult&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9681 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9682 | "Wallpaper layer changed: assigning layers + relayout"); |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9683 | changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9684 | assignLayersLocked(); |
| 9685 | } else if ((adjResult&ADJUST_WALLPAPER_VISIBILITY_CHANGED) != 0) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9686 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9687 | "Wallpaper visibility changed: relayout"); |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9688 | changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9689 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9690 | |
| Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 9691 | if (mFocusMayChange) { |
| 9692 | mFocusMayChange = false; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9693 | if (updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES)) { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9694 | changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9695 | adjResult = 0; |
| Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 9696 | } |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9697 | } |
| 9698 | |
| 9699 | if (mLayoutNeeded) { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9700 | changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT; |
| Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 9701 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9702 | |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9703 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "*** ANIM STEP: changes=0x" |
| 9704 | + Integer.toHexString(changes)); |
| Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 9705 | |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 9706 | mInputMonitor.updateInputWindowsLw(); |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9707 | } while (changes != 0); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9708 | |
| 9709 | // THIRD LOOP: Update the surfaces of all windows. |
| 9710 | |
| 9711 | final boolean someoneLosingFocus = mLosingFocus.size() != 0; |
| 9712 | |
| 9713 | boolean obscured = false; |
| 9714 | boolean blurring = false; |
| 9715 | boolean dimming = false; |
| 9716 | boolean covered = false; |
| Dianne Hackborn | 9ed4a4b | 2009-03-25 17:10:37 -0700 | [diff] [blame] | 9717 | boolean syswin = false; |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 9718 | boolean backgroundFillerShown = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9719 | |
| Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 9720 | final int N = mWindows.size(); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9721 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9722 | for (i=N-1; i>=0; i--) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 9723 | WindowState w = mWindows.get(i); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9724 | |
| 9725 | boolean displayed = false; |
| 9726 | final WindowManager.LayoutParams attrs = w.mAttrs; |
| 9727 | final int attrFlags = attrs.flags; |
| 9728 | |
| 9729 | if (w.mSurface != null) { |
| Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 9730 | // XXX NOTE: The logic here could be improved. We have |
| 9731 | // the decision about whether to resize a window separated |
| 9732 | // from whether to hide the surface. This can cause us to |
| 9733 | // resize a surface even if we are going to hide it. You |
| 9734 | // can see this by (1) holding device in landscape mode on |
| 9735 | // home screen; (2) tapping browser icon (device will rotate |
| 9736 | // to landscape; (3) tap home. The wallpaper will be resized |
| 9737 | // in step 2 but then immediately hidden, causing us to |
| 9738 | // have to resize and then redraw it again in step 3. It |
| 9739 | // would be nice to figure out how to avoid this, but it is |
| 9740 | // difficult because we do need to resize surfaces in some |
| 9741 | // cases while they are hidden such as when first showing a |
| 9742 | // window. |
| 9743 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9744 | w.computeShownFrameLocked(); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9745 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9746 | TAG, "Placing surface #" + i + " " + w.mSurface |
| 9747 | + ": new=" + w.mShownFrame + ", old=" |
| 9748 | + w.mLastShownFrame); |
| 9749 | |
| 9750 | boolean resize; |
| 9751 | int width, height; |
| 9752 | if ((w.mAttrs.flags & w.mAttrs.FLAG_SCALED) != 0) { |
| 9753 | resize = w.mLastRequestedWidth != w.mRequestedWidth || |
| 9754 | w.mLastRequestedHeight != w.mRequestedHeight; |
| 9755 | // for a scaled surface, we just want to use |
| 9756 | // the requested size. |
| 9757 | width = w.mRequestedWidth; |
| 9758 | height = w.mRequestedHeight; |
| 9759 | w.mLastRequestedWidth = width; |
| 9760 | w.mLastRequestedHeight = height; |
| 9761 | w.mLastShownFrame.set(w.mShownFrame); |
| 9762 | try { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9763 | if (SHOW_TRANSACTIONS) logSurface(w, |
| 9764 | "POS " + w.mShownFrame.left |
| 9765 | + ", " + w.mShownFrame.top, null); |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 9766 | w.mSurfaceX = w.mShownFrame.left; |
| 9767 | w.mSurfaceY = w.mShownFrame.top; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9768 | w.mSurface.setPosition(w.mShownFrame.left, w.mShownFrame.top); |
| 9769 | } catch (RuntimeException e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9770 | Slog.w(TAG, "Error positioning surface in " + w, e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9771 | if (!recoveringMemory) { |
| 9772 | reclaimSomeSurfaceMemoryLocked(w, "position"); |
| 9773 | } |
| 9774 | } |
| 9775 | } else { |
| 9776 | resize = !w.mLastShownFrame.equals(w.mShownFrame); |
| 9777 | width = w.mShownFrame.width(); |
| 9778 | height = w.mShownFrame.height(); |
| 9779 | w.mLastShownFrame.set(w.mShownFrame); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9780 | } |
| 9781 | |
| 9782 | if (resize) { |
| 9783 | if (width < 1) width = 1; |
| 9784 | if (height < 1) height = 1; |
| 9785 | if (w.mSurface != null) { |
| 9786 | try { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9787 | if (SHOW_TRANSACTIONS) logSurface(w, |
| 9788 | "POS " + w.mShownFrame.left + "," |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 9789 | + w.mShownFrame.top + " SIZE " |
| 9790 | + w.mShownFrame.width() + "x" |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9791 | + w.mShownFrame.height(), null); |
| Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 9792 | w.mSurfaceResized = true; |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 9793 | w.mSurfaceW = width; |
| 9794 | w.mSurfaceH = height; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9795 | w.mSurface.setSize(width, height); |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 9796 | w.mSurfaceX = w.mShownFrame.left; |
| 9797 | w.mSurfaceY = w.mShownFrame.top; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9798 | w.mSurface.setPosition(w.mShownFrame.left, |
| 9799 | w.mShownFrame.top); |
| 9800 | } catch (RuntimeException e) { |
| 9801 | // If something goes wrong with the surface (such |
| 9802 | // as running out of memory), don't take down the |
| 9803 | // entire system. |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9804 | Slog.e(TAG, "Failure updating surface of " + w |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9805 | + "size=(" + width + "x" + height |
| 9806 | + "), pos=(" + w.mShownFrame.left |
| 9807 | + "," + w.mShownFrame.top + ")", e); |
| 9808 | if (!recoveringMemory) { |
| 9809 | reclaimSomeSurfaceMemoryLocked(w, "size"); |
| 9810 | } |
| 9811 | } |
| 9812 | } |
| 9813 | } |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 9814 | if (!w.mAppFreezing && w.mLayoutSeq == mLayoutSeq) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9815 | w.mContentInsetsChanged = |
| 9816 | !w.mLastContentInsets.equals(w.mContentInsets); |
| 9817 | w.mVisibleInsetsChanged = |
| 9818 | !w.mLastVisibleInsets.equals(w.mVisibleInsets); |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 9819 | boolean configChanged = |
| 9820 | w.mConfiguration != mCurConfiguration |
| 9821 | && (w.mConfiguration == null |
| 9822 | || mCurConfiguration.diff(w.mConfiguration) != 0); |
| Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 9823 | if (DEBUG_CONFIGURATION && configChanged) { |
| 9824 | Slog.v(TAG, "Win " + w + " config changed: " |
| 9825 | + mCurConfiguration); |
| 9826 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9827 | if (localLOGV) Slog.v(TAG, "Resizing " + w |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 9828 | + ": configChanged=" + configChanged |
| 9829 | + " last=" + w.mLastFrame + " frame=" + w.mFrame); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9830 | if (!w.mLastFrame.equals(w.mFrame) |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9831 | || w.mContentInsetsChanged |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 9832 | || w.mVisibleInsetsChanged |
| Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 9833 | || w.mSurfaceResized |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 9834 | || configChanged) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9835 | w.mLastFrame.set(w.mFrame); |
| 9836 | w.mLastContentInsets.set(w.mContentInsets); |
| 9837 | w.mLastVisibleInsets.set(w.mVisibleInsets); |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 9838 | // If the screen is currently frozen, then keep |
| 9839 | // it frozen until this window draws at its new |
| 9840 | // orientation. |
| 9841 | if (mDisplayFrozen) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9842 | if (DEBUG_ORIENTATION) Slog.v(TAG, |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 9843 | "Resizing while display frozen: " + w); |
| 9844 | w.mOrientationChanging = true; |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 9845 | if (!mWindowsFreezingScreen) { |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 9846 | mWindowsFreezingScreen = true; |
| 9847 | // XXX should probably keep timeout from |
| 9848 | // when we first froze the display. |
| 9849 | mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT); |
| 9850 | mH.sendMessageDelayed(mH.obtainMessage( |
| 9851 | H.WINDOW_FREEZE_TIMEOUT), 2000); |
| 9852 | } |
| 9853 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9854 | // If the orientation is changing, then we need to |
| 9855 | // hold off on unfreezing the display until this |
| 9856 | // window has been redrawn; to do that, we need |
| 9857 | // to go through the process of getting informed |
| 9858 | // by the application when it has finished drawing. |
| 9859 | if (w.mOrientationChanging) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9860 | if (DEBUG_ORIENTATION) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9861 | "Orientation start waiting for draw in " |
| 9862 | + w + ", surface " + w.mSurface); |
| 9863 | w.mDrawPending = true; |
| 9864 | w.mCommitDrawPending = false; |
| 9865 | w.mReadyToShow = false; |
| 9866 | if (w.mAppToken != null) { |
| 9867 | w.mAppToken.allDrawn = false; |
| 9868 | } |
| 9869 | } |
| Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 9870 | if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9871 | "Resizing window " + w + " to " + w.mFrame); |
| 9872 | mResizingWindows.add(w); |
| 9873 | } else if (w.mOrientationChanging) { |
| 9874 | if (!w.mDrawPending && !w.mCommitDrawPending) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9875 | if (DEBUG_ORIENTATION) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9876 | "Orientation not waiting for draw in " |
| 9877 | + w + ", surface " + w.mSurface); |
| 9878 | w.mOrientationChanging = false; |
| 9879 | } |
| 9880 | } |
| 9881 | } |
| 9882 | |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9883 | if (w.mAttachedHidden || !w.isReadyForDisplay()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9884 | if (!w.mLastHidden) { |
| 9885 | //dump(); |
| 9886 | w.mLastHidden = true; |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9887 | if (SHOW_TRANSACTIONS) logSurface(w, |
| 9888 | "HIDE (performLayout)", null); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9889 | if (w.mSurface != null) { |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 9890 | w.mSurfaceShown = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9891 | try { |
| 9892 | w.mSurface.hide(); |
| 9893 | } catch (RuntimeException e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9894 | Slog.w(TAG, "Exception hiding surface in " + w); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9895 | } |
| 9896 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9897 | } |
| 9898 | // If we are waiting for this window to handle an |
| 9899 | // orientation change, well, it is hidden, so |
| 9900 | // doesn't really matter. Note that this does |
| 9901 | // introduce a potential glitch if the window |
| 9902 | // becomes unhidden before it has drawn for the |
| 9903 | // new orientation. |
| 9904 | if (w.mOrientationChanging) { |
| 9905 | w.mOrientationChanging = false; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9906 | if (DEBUG_ORIENTATION) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9907 | "Orientation change skips hidden " + w); |
| 9908 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9909 | } else if (w.mLastLayer != w.mAnimLayer |
| 9910 | || w.mLastAlpha != w.mShownAlpha |
| 9911 | || w.mLastDsDx != w.mDsDx |
| 9912 | || w.mLastDtDx != w.mDtDx |
| 9913 | || w.mLastDsDy != w.mDsDy |
| 9914 | || w.mLastDtDy != w.mDtDy |
| 9915 | || w.mLastHScale != w.mHScale |
| 9916 | || w.mLastVScale != w.mVScale |
| 9917 | || w.mLastHidden) { |
| 9918 | displayed = true; |
| 9919 | w.mLastAlpha = w.mShownAlpha; |
| 9920 | w.mLastLayer = w.mAnimLayer; |
| 9921 | w.mLastDsDx = w.mDsDx; |
| 9922 | w.mLastDtDx = w.mDtDx; |
| 9923 | w.mLastDsDy = w.mDsDy; |
| 9924 | w.mLastDtDy = w.mDtDy; |
| 9925 | w.mLastHScale = w.mHScale; |
| 9926 | w.mLastVScale = w.mVScale; |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9927 | if (SHOW_TRANSACTIONS) logSurface(w, |
| 9928 | "alpha=" + w.mShownAlpha + " layer=" + w.mAnimLayer |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 9929 | + " matrix=[" + (w.mDsDx*w.mHScale) |
| 9930 | + "," + (w.mDtDx*w.mVScale) |
| 9931 | + "][" + (w.mDsDy*w.mHScale) |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9932 | + "," + (w.mDtDy*w.mVScale) + "]", null); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9933 | if (w.mSurface != null) { |
| 9934 | try { |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 9935 | w.mSurfaceAlpha = w.mShownAlpha; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9936 | w.mSurface.setAlpha(w.mShownAlpha); |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 9937 | w.mSurfaceLayer = w.mAnimLayer; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9938 | w.mSurface.setLayer(w.mAnimLayer); |
| 9939 | w.mSurface.setMatrix( |
| 9940 | w.mDsDx*w.mHScale, w.mDtDx*w.mVScale, |
| 9941 | w.mDsDy*w.mHScale, w.mDtDy*w.mVScale); |
| 9942 | } catch (RuntimeException e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9943 | Slog.w(TAG, "Error updating surface in " + w, e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9944 | if (!recoveringMemory) { |
| 9945 | reclaimSomeSurfaceMemoryLocked(w, "update"); |
| 9946 | } |
| 9947 | } |
| 9948 | } |
| 9949 | |
| 9950 | if (w.mLastHidden && !w.mDrawPending |
| 9951 | && !w.mCommitDrawPending |
| 9952 | && !w.mReadyToShow) { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9953 | if (SHOW_TRANSACTIONS) logSurface(w, |
| 9954 | "SHOW (performLayout)", null); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9955 | if (DEBUG_VISIBILITY) Slog.v(TAG, "Showing " + w |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9956 | + " during relayout"); |
| 9957 | if (showSurfaceRobustlyLocked(w)) { |
| 9958 | w.mHasDrawn = true; |
| 9959 | w.mLastHidden = false; |
| 9960 | } else { |
| 9961 | w.mOrientationChanging = false; |
| 9962 | } |
| 9963 | } |
| 9964 | if (w.mSurface != null) { |
| 9965 | w.mToken.hasVisible = true; |
| 9966 | } |
| 9967 | } else { |
| 9968 | displayed = true; |
| 9969 | } |
| 9970 | |
| 9971 | if (displayed) { |
| 9972 | if (!covered) { |
| Romain Guy | 980a938 | 2010-01-08 15:06:28 -0800 | [diff] [blame] | 9973 | if (attrs.width == LayoutParams.MATCH_PARENT |
| 9974 | && attrs.height == LayoutParams.MATCH_PARENT) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9975 | covered = true; |
| 9976 | } |
| 9977 | } |
| 9978 | if (w.mOrientationChanging) { |
| 9979 | if (w.mDrawPending || w.mCommitDrawPending) { |
| 9980 | orientationChangeComplete = false; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9981 | if (DEBUG_ORIENTATION) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9982 | "Orientation continue waiting for draw in " + w); |
| 9983 | } else { |
| 9984 | w.mOrientationChanging = false; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9985 | if (DEBUG_ORIENTATION) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9986 | "Orientation change complete in " + w); |
| 9987 | } |
| 9988 | } |
| 9989 | w.mToken.hasVisible = true; |
| 9990 | } |
| 9991 | } else if (w.mOrientationChanging) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9992 | if (DEBUG_ORIENTATION) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9993 | "Orientation change skips hidden " + w); |
| 9994 | w.mOrientationChanging = false; |
| 9995 | } |
| 9996 | |
| 9997 | final boolean canBeSeen = w.isDisplayedLw(); |
| 9998 | |
| 9999 | if (someoneLosingFocus && w == mCurrentFocus && canBeSeen) { |
| 10000 | focusDisplayed = true; |
| 10001 | } |
| 10002 | |
| Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 10003 | final boolean obscuredChanged = w.mObscured != obscured; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10004 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10005 | // Update effect. |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 10006 | if (!(w.mObscured=obscured)) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10007 | if (w.mSurface != null) { |
| 10008 | if ((attrFlags&FLAG_KEEP_SCREEN_ON) != 0) { |
| 10009 | holdScreen = w.mSession; |
| 10010 | } |
| Dianne Hackborn | 9ed4a4b | 2009-03-25 17:10:37 -0700 | [diff] [blame] | 10011 | if (!syswin && w.mAttrs.screenBrightness >= 0 |
| 10012 | && screenBrightness < 0) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10013 | screenBrightness = w.mAttrs.screenBrightness; |
| 10014 | } |
| Mike Lockwood | fb73f79 | 2009-11-20 11:31:18 -0500 | [diff] [blame] | 10015 | if (!syswin && w.mAttrs.buttonBrightness >= 0 |
| 10016 | && buttonBrightness < 0) { |
| 10017 | buttonBrightness = w.mAttrs.buttonBrightness; |
| 10018 | } |
| Mike Lockwood | 46af6a8 | 2010-03-09 08:28:22 -0500 | [diff] [blame] | 10019 | if (canBeSeen |
| 10020 | && (attrs.type == WindowManager.LayoutParams.TYPE_SYSTEM_DIALOG |
| 10021 | || attrs.type == WindowManager.LayoutParams.TYPE_KEYGUARD |
| 10022 | || attrs.type == WindowManager.LayoutParams.TYPE_SYSTEM_ERROR)) { |
| Dianne Hackborn | 9ed4a4b | 2009-03-25 17:10:37 -0700 | [diff] [blame] | 10023 | syswin = true; |
| 10024 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10025 | } |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 10026 | |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 10027 | boolean opaqueDrawn = canBeSeen && w.isOpaqueDrawn(); |
| 10028 | if (opaqueDrawn && w.isFullscreen(dw, dh)) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10029 | // This window completely covers everything behind it, |
| 10030 | // so we want to leave all of them as unblurred (for |
| 10031 | // performance reasons). |
| 10032 | obscured = true; |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 10033 | } else if (opaqueDrawn && w.needsBackgroundFiller(dw, dh)) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10034 | if (SHOW_TRANSACTIONS) Slog.d(TAG, "showing background filler"); |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 10035 | // This window is in compatibility mode, and needs background filler. |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 10036 | obscured = true; |
| 10037 | if (mBackgroundFillerSurface == null) { |
| 10038 | try { |
| 10039 | mBackgroundFillerSurface = new Surface(mFxSession, 0, |
| Mathias Agopian | 5d26c1e | 2010-03-01 16:09:43 -0800 | [diff] [blame] | 10040 | "BackGroundFiller", |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 10041 | 0, dw, dh, |
| 10042 | PixelFormat.OPAQUE, |
| 10043 | Surface.FX_SURFACE_NORMAL); |
| 10044 | } catch (Exception e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10045 | Slog.e(TAG, "Exception creating filler surface", e); |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 10046 | } |
| 10047 | } |
| 10048 | try { |
| 10049 | mBackgroundFillerSurface.setPosition(0, 0); |
| 10050 | mBackgroundFillerSurface.setSize(dw, dh); |
| 10051 | // Using the same layer as Dim because they will never be shown at the |
| 10052 | // same time. |
| 10053 | mBackgroundFillerSurface.setLayer(w.mAnimLayer - 1); |
| 10054 | mBackgroundFillerSurface.show(); |
| 10055 | } catch (RuntimeException e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10056 | Slog.e(TAG, "Exception showing filler surface"); |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 10057 | } |
| 10058 | backgroundFillerShown = true; |
| 10059 | mBackgroundFillerShown = true; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10060 | } else if (canBeSeen && !obscured && |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10061 | (attrFlags&FLAG_BLUR_BEHIND|FLAG_DIM_BEHIND) != 0) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10062 | if (localLOGV) Slog.v(TAG, "Win " + w |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10063 | + ": blurring=" + blurring |
| 10064 | + " obscured=" + obscured |
| 10065 | + " displayed=" + displayed); |
| 10066 | if ((attrFlags&FLAG_DIM_BEHIND) != 0) { |
| 10067 | if (!dimming) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10068 | //Slog.i(TAG, "DIM BEHIND: " + w); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10069 | dimming = true; |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 10070 | if (mDimAnimator == null) { |
| 10071 | mDimAnimator = new DimAnimator(mFxSession); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10072 | } |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 10073 | mDimAnimator.show(dw, dh); |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 10074 | mDimAnimator.updateParameters(w, currentTime); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10075 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10076 | } |
| 10077 | if ((attrFlags&FLAG_BLUR_BEHIND) != 0) { |
| 10078 | if (!blurring) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10079 | //Slog.i(TAG, "BLUR BEHIND: " + w); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10080 | blurring = true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10081 | if (mBlurSurface == null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10082 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR " |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10083 | + mBlurSurface + ": CREATE"); |
| 10084 | try { |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10085 | mBlurSurface = new Surface(mFxSession, 0, |
| Mathias Agopian | 5d26c1e | 2010-03-01 16:09:43 -0800 | [diff] [blame] | 10086 | "BlurSurface", |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10087 | -1, 16, 16, |
| 10088 | PixelFormat.OPAQUE, |
| 10089 | Surface.FX_SURFACE_BLUR); |
| 10090 | } catch (Exception e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10091 | Slog.e(TAG, "Exception creating Blur surface", e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10092 | } |
| 10093 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10094 | if (mBlurSurface != null) { |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 10095 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR " |
| 10096 | + mBlurSurface + ": pos=(0,0) (" + |
| 10097 | dw + "x" + dh + "), layer=" + (w.mAnimLayer-1)); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10098 | mBlurSurface.setPosition(0, 0); |
| 10099 | mBlurSurface.setSize(dw, dh); |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 10100 | mBlurSurface.setLayer(w.mAnimLayer-2); |
| 10101 | if (!mBlurShown) { |
| 10102 | try { |
| 10103 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR " |
| 10104 | + mBlurSurface + ": SHOW"); |
| 10105 | mBlurSurface.show(); |
| 10106 | } catch (RuntimeException e) { |
| 10107 | Slog.w(TAG, "Failure showing blur surface", e); |
| 10108 | } |
| 10109 | mBlurShown = true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10110 | } |
| 10111 | } |
| 10112 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10113 | } |
| 10114 | } |
| 10115 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10116 | |
| Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 10117 | if (obscuredChanged && mWallpaperTarget == w) { |
| 10118 | // This is the wallpaper target and its obscured state |
| 10119 | // changed... make sure the current wallaper's visibility |
| 10120 | // has been updated accordingly. |
| 10121 | updateWallpaperVisibilityLocked(); |
| 10122 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10123 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10124 | |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 10125 | if (backgroundFillerShown == false && mBackgroundFillerShown) { |
| 10126 | mBackgroundFillerShown = false; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10127 | if (SHOW_TRANSACTIONS) Slog.d(TAG, "hiding background filler"); |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 10128 | try { |
| 10129 | mBackgroundFillerSurface.hide(); |
| 10130 | } catch (RuntimeException e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10131 | Slog.e(TAG, "Exception hiding filler surface", e); |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 10132 | } |
| 10133 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10134 | |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 10135 | if (mDimAnimator != null && mDimAnimator.mDimShown) { |
| Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 10136 | animating |= mDimAnimator.updateSurface(dimming, currentTime, |
| 10137 | mDisplayFrozen || !mPolicy.isScreenOn()); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10138 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10139 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10140 | if (!blurring && mBlurShown) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10141 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR " + mBlurSurface |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10142 | + ": HIDE"); |
| 10143 | try { |
| 10144 | mBlurSurface.hide(); |
| 10145 | } catch (IllegalArgumentException e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10146 | Slog.w(TAG, "Illegal argument exception hiding blur surface"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10147 | } |
| 10148 | mBlurShown = false; |
| 10149 | } |
| 10150 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10151 | if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10152 | } catch (RuntimeException e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10153 | Slog.e(TAG, "Unhandled exception in Window Manager", e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10154 | } |
| 10155 | |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 10156 | mInputMonitor.updateInputWindowsLw(); |
| 10157 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10158 | Surface.closeTransaction(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10159 | |
| Dianne Hackborn | b9fb170 | 2010-08-23 16:49:02 -0700 | [diff] [blame] | 10160 | if (mWatermark != null) { |
| 10161 | mWatermark.drawIfNeeded(); |
| 10162 | } |
| 10163 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10164 | if (DEBUG_ORIENTATION && mDisplayFrozen) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10165 | "With display frozen, orientationChangeComplete=" |
| 10166 | + orientationChangeComplete); |
| 10167 | if (orientationChangeComplete) { |
| 10168 | if (mWindowsFreezingScreen) { |
| 10169 | mWindowsFreezingScreen = false; |
| 10170 | mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT); |
| 10171 | } |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 10172 | stopFreezingDisplayLocked(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10173 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10174 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10175 | i = mResizingWindows.size(); |
| 10176 | if (i > 0) { |
| 10177 | do { |
| 10178 | i--; |
| 10179 | WindowState win = mResizingWindows.get(i); |
| 10180 | try { |
| Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 10181 | if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG, |
| 10182 | "Reporting new frame to " + win + ": " + win.mFrame); |
| Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 10183 | int diff = 0; |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 10184 | boolean configChanged = |
| 10185 | win.mConfiguration != mCurConfiguration |
| 10186 | && (win.mConfiguration == null |
| Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 10187 | || (diff=mCurConfiguration.diff(win.mConfiguration)) != 0); |
| 10188 | if ((DEBUG_RESIZE || DEBUG_ORIENTATION || DEBUG_CONFIGURATION) |
| 10189 | && configChanged) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10190 | Slog.i(TAG, "Sending new config to window " + win + ": " |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 10191 | + win.mFrame.width() + "x" + win.mFrame.height() |
| Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 10192 | + " / " + mCurConfiguration + " / 0x" |
| 10193 | + Integer.toHexString(diff)); |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 10194 | } |
| Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 10195 | win.mConfiguration = mCurConfiguration; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10196 | win.mClient.resized(win.mFrame.width(), |
| 10197 | win.mFrame.height(), win.mLastContentInsets, |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 10198 | win.mLastVisibleInsets, win.mDrawPending, |
| 10199 | configChanged ? win.mConfiguration : null); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10200 | win.mContentInsetsChanged = false; |
| 10201 | win.mVisibleInsetsChanged = false; |
| Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 10202 | win.mSurfaceResized = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10203 | } catch (RemoteException e) { |
| 10204 | win.mOrientationChanging = false; |
| 10205 | } |
| 10206 | } while (i > 0); |
| 10207 | mResizingWindows.clear(); |
| 10208 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10209 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10210 | // Destroy the surface of any windows that are no longer visible. |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 10211 | boolean wallpaperDestroyed = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10212 | i = mDestroySurface.size(); |
| 10213 | if (i > 0) { |
| 10214 | do { |
| 10215 | i--; |
| 10216 | WindowState win = mDestroySurface.get(i); |
| 10217 | win.mDestroying = false; |
| 10218 | if (mInputMethodWindow == win) { |
| 10219 | mInputMethodWindow = null; |
| 10220 | } |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 10221 | if (win == mWallpaperTarget) { |
| 10222 | wallpaperDestroyed = true; |
| 10223 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10224 | win.destroySurfaceLocked(); |
| 10225 | } while (i > 0); |
| 10226 | mDestroySurface.clear(); |
| 10227 | } |
| 10228 | |
| 10229 | // Time to remove any exiting tokens? |
| 10230 | for (i=mExitingTokens.size()-1; i>=0; i--) { |
| 10231 | WindowToken token = mExitingTokens.get(i); |
| 10232 | if (!token.hasVisible) { |
| 10233 | mExitingTokens.remove(i); |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 10234 | if (token.windowType == TYPE_WALLPAPER) { |
| 10235 | mWallpaperTokens.remove(token); |
| 10236 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10237 | } |
| 10238 | } |
| 10239 | |
| 10240 | // Time to remove any exiting applications? |
| 10241 | for (i=mExitingAppTokens.size()-1; i>=0; i--) { |
| 10242 | AppWindowToken token = mExitingAppTokens.get(i); |
| 10243 | if (!token.hasVisible && !mClosingApps.contains(token)) { |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 10244 | // Make sure there is no animation running on this token, |
| 10245 | // so any windows associated with it will be removed as |
| 10246 | // soon as their animations are complete |
| 10247 | token.animation = null; |
| 10248 | token.animating = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10249 | mAppTokens.remove(token); |
| 10250 | mExitingAppTokens.remove(i); |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10251 | if (mLastEnterAnimToken == token) { |
| 10252 | mLastEnterAnimToken = null; |
| 10253 | mLastEnterAnimParams = null; |
| 10254 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10255 | } |
| 10256 | } |
| 10257 | |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 10258 | boolean needRelayout = false; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10259 | |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 10260 | if (!animating && mAppTransitionRunning) { |
| 10261 | // We have finished the animation of an app transition. To do |
| 10262 | // this, we have delayed a lot of operations like showing and |
| 10263 | // hiding apps, moving apps in Z-order, etc. The app token list |
| 10264 | // reflects the correct Z-order, but the window list may now |
| 10265 | // be out of sync with it. So here we will just rebuild the |
| 10266 | // entire app window list. Fun! |
| 10267 | mAppTransitionRunning = false; |
| 10268 | needRelayout = true; |
| 10269 | rebuildAppWindowListLocked(); |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 10270 | assignLayersLocked(); |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 10271 | // Clear information about apps that were moving. |
| 10272 | mToBottomApps.clear(); |
| 10273 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10274 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10275 | if (focusDisplayed) { |
| 10276 | mH.sendEmptyMessage(H.REPORT_LOSING_FOCUS); |
| 10277 | } |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 10278 | if (wallpaperDestroyed) { |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 10279 | needRelayout = adjustWallpaperWindowsLocked() != 0; |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 10280 | } |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 10281 | if (needRelayout) { |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 10282 | requestAnimationLocked(0); |
| 10283 | } else if (animating) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10284 | requestAnimationLocked(currentTime+(1000/60)-SystemClock.uptimeMillis()); |
| 10285 | } |
| Jeff Brown | eb857f1 | 2010-07-16 10:06:33 -0700 | [diff] [blame] | 10286 | |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 10287 | mInputMonitor.updateInputWindowsLw(); |
| Jeff Brown | eb857f1 | 2010-07-16 10:06:33 -0700 | [diff] [blame] | 10288 | |
| Jeff Brown | 8e03b75 | 2010-06-13 19:16:55 -0700 | [diff] [blame] | 10289 | setHoldScreenLocked(holdScreen != null); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10290 | if (screenBrightness < 0 || screenBrightness > 1.0f) { |
| 10291 | mPowerManager.setScreenBrightnessOverride(-1); |
| 10292 | } else { |
| 10293 | mPowerManager.setScreenBrightnessOverride((int) |
| 10294 | (screenBrightness * Power.BRIGHTNESS_ON)); |
| 10295 | } |
| Mike Lockwood | fb73f79 | 2009-11-20 11:31:18 -0500 | [diff] [blame] | 10296 | if (buttonBrightness < 0 || buttonBrightness > 1.0f) { |
| 10297 | mPowerManager.setButtonBrightnessOverride(-1); |
| 10298 | } else { |
| 10299 | mPowerManager.setButtonBrightnessOverride((int) |
| 10300 | (buttonBrightness * Power.BRIGHTNESS_ON)); |
| 10301 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10302 | if (holdScreen != mHoldingScreenOn) { |
| 10303 | mHoldingScreenOn = holdScreen; |
| 10304 | Message m = mH.obtainMessage(H.HOLD_SCREEN_CHANGED, holdScreen); |
| 10305 | mH.sendMessage(m); |
| 10306 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10307 | |
| Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 10308 | if (mTurnOnScreen) { |
| Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 10309 | if (DEBUG_VISIBILITY) Slog.v(TAG, "Turning screen on after layout!"); |
| Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 10310 | mPowerManager.userActivity(SystemClock.uptimeMillis(), false, |
| 10311 | LocalPowerManager.BUTTON_EVENT, true); |
| 10312 | mTurnOnScreen = false; |
| 10313 | } |
| Dianne Hackborn | f3bea9c | 2009-12-09 18:26:21 -0800 | [diff] [blame] | 10314 | |
| 10315 | // Check to see if we are now in a state where the screen should |
| 10316 | // be enabled, because the window obscured flags have changed. |
| 10317 | enableScreenIfNeededLocked(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10318 | } |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 10319 | |
| 10320 | /** |
| 10321 | * Must be called with the main window manager lock held. |
| 10322 | */ |
| 10323 | void setHoldScreenLocked(boolean holding) { |
| 10324 | boolean state = mHoldingScreenWakeLock.isHeld(); |
| 10325 | if (holding != state) { |
| 10326 | if (holding) { |
| 10327 | mHoldingScreenWakeLock.acquire(); |
| 10328 | } else { |
| 10329 | mPolicy.screenOnStoppedLw(); |
| 10330 | mHoldingScreenWakeLock.release(); |
| 10331 | } |
| 10332 | } |
| 10333 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10334 | |
| 10335 | void requestAnimationLocked(long delay) { |
| 10336 | if (!mAnimationPending) { |
| 10337 | mAnimationPending = true; |
| 10338 | mH.sendMessageDelayed(mH.obtainMessage(H.ANIMATE), delay); |
| 10339 | } |
| 10340 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10341 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10342 | /** |
| 10343 | * Have the surface flinger show a surface, robustly dealing with |
| 10344 | * error conditions. In particular, if there is not enough memory |
| 10345 | * to show the surface, then we will try to get rid of other surfaces |
| 10346 | * in order to succeed. |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10347 | * |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10348 | * @return Returns true if the surface was successfully shown. |
| 10349 | */ |
| 10350 | boolean showSurfaceRobustlyLocked(WindowState win) { |
| 10351 | try { |
| 10352 | if (win.mSurface != null) { |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 10353 | win.mSurfaceShown = true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10354 | win.mSurface.show(); |
| Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 10355 | if (win.mTurnOnScreen) { |
| Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 10356 | if (DEBUG_VISIBILITY) Slog.v(TAG, |
| 10357 | "Show surface turning screen on: " + win); |
| Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 10358 | win.mTurnOnScreen = false; |
| 10359 | mTurnOnScreen = true; |
| 10360 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10361 | } |
| 10362 | return true; |
| 10363 | } catch (RuntimeException e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10364 | 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] | 10365 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10366 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10367 | reclaimSomeSurfaceMemoryLocked(win, "show"); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10368 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10369 | return false; |
| 10370 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10371 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10372 | void reclaimSomeSurfaceMemoryLocked(WindowState win, String operation) { |
| 10373 | final Surface surface = win.mSurface; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10374 | |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10375 | EventLog.writeEvent(EventLogTags.WM_NO_SURFACE_MEMORY, win.toString(), |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10376 | win.mSession.mPid, operation); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10377 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10378 | if (mForceRemoves == null) { |
| 10379 | mForceRemoves = new ArrayList<WindowState>(); |
| 10380 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10381 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10382 | long callingIdentity = Binder.clearCallingIdentity(); |
| 10383 | try { |
| 10384 | // There was some problem... first, do a sanity check of the |
| 10385 | // window list to make sure we haven't left any dangling surfaces |
| 10386 | // around. |
| 10387 | int N = mWindows.size(); |
| 10388 | boolean leakedSurface = false; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10389 | 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] | 10390 | for (int i=0; i<N; i++) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 10391 | WindowState ws = mWindows.get(i); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10392 | if (ws.mSurface != null) { |
| 10393 | if (!mSessions.contains(ws.mSession)) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10394 | Slog.w(TAG, "LEAKED SURFACE (session doesn't exist): " |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10395 | + ws + " surface=" + ws.mSurface |
| 10396 | + " token=" + win.mToken |
| 10397 | + " pid=" + ws.mSession.mPid |
| 10398 | + " uid=" + ws.mSession.mUid); |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 10399 | ws.mSurface.destroy(); |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 10400 | ws.mSurfaceShown = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10401 | ws.mSurface = null; |
| 10402 | mForceRemoves.add(ws); |
| 10403 | i--; |
| 10404 | N--; |
| 10405 | leakedSurface = true; |
| 10406 | } else if (win.mAppToken != null && win.mAppToken.clientHidden) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10407 | Slog.w(TAG, "LEAKED SURFACE (app token hidden): " |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10408 | + ws + " surface=" + ws.mSurface |
| 10409 | + " token=" + win.mAppToken); |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 10410 | ws.mSurface.destroy(); |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 10411 | ws.mSurfaceShown = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10412 | ws.mSurface = null; |
| 10413 | leakedSurface = true; |
| 10414 | } |
| 10415 | } |
| 10416 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10417 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10418 | boolean killedApps = false; |
| 10419 | if (!leakedSurface) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10420 | Slog.w(TAG, "No leaked surfaces; killing applicatons!"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10421 | SparseIntArray pidCandidates = new SparseIntArray(); |
| 10422 | for (int i=0; i<N; i++) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 10423 | WindowState ws = mWindows.get(i); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10424 | if (ws.mSurface != null) { |
| 10425 | pidCandidates.append(ws.mSession.mPid, ws.mSession.mPid); |
| 10426 | } |
| 10427 | } |
| 10428 | if (pidCandidates.size() > 0) { |
| 10429 | int[] pids = new int[pidCandidates.size()]; |
| 10430 | for (int i=0; i<pids.length; i++) { |
| 10431 | pids[i] = pidCandidates.keyAt(i); |
| 10432 | } |
| 10433 | try { |
| Suchi Amalapurapu | e99bb5f | 2010-03-19 14:36:49 -0700 | [diff] [blame] | 10434 | if (mActivityManager.killPids(pids, "Free memory")) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10435 | killedApps = true; |
| 10436 | } |
| 10437 | } catch (RemoteException e) { |
| 10438 | } |
| 10439 | } |
| 10440 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10441 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10442 | if (leakedSurface || killedApps) { |
| 10443 | // We managed to reclaim some memory, so get rid of the trouble |
| 10444 | // surface and ask the app to request another one. |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10445 | 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] | 10446 | if (surface != null) { |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 10447 | surface.destroy(); |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 10448 | win.mSurfaceShown = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10449 | win.mSurface = null; |
| 10450 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10451 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10452 | try { |
| 10453 | win.mClient.dispatchGetNewSurface(); |
| 10454 | } catch (RemoteException e) { |
| 10455 | } |
| 10456 | } |
| 10457 | } finally { |
| 10458 | Binder.restoreCallingIdentity(callingIdentity); |
| 10459 | } |
| 10460 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10461 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10462 | private boolean updateFocusedWindowLocked(int mode) { |
| 10463 | WindowState newFocus = computeFocusedWindowLocked(); |
| 10464 | if (mCurrentFocus != newFocus) { |
| 10465 | // This check makes sure that we don't already have the focus |
| 10466 | // change message pending. |
| 10467 | mH.removeMessages(H.REPORT_FOCUS_CHANGE); |
| 10468 | mH.sendEmptyMessage(H.REPORT_FOCUS_CHANGE); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10469 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10470 | TAG, "Changing focus from " + mCurrentFocus + " to " + newFocus); |
| 10471 | final WindowState oldFocus = mCurrentFocus; |
| 10472 | mCurrentFocus = newFocus; |
| 10473 | mLosingFocus.remove(newFocus); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10474 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10475 | final WindowState imWindow = mInputMethodWindow; |
| 10476 | if (newFocus != imWindow && oldFocus != imWindow) { |
| The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 10477 | if (moveInputMethodWindowsIfNeededLocked( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10478 | mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS && |
| The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 10479 | mode != UPDATE_FOCUS_WILL_PLACE_SURFACES)) { |
| 10480 | mLayoutNeeded = true; |
| 10481 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10482 | if (mode == UPDATE_FOCUS_PLACING_SURFACES) { |
| 10483 | performLayoutLockedInner(); |
| The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 10484 | } else if (mode == UPDATE_FOCUS_WILL_PLACE_SURFACES) { |
| 10485 | // Client will do the layout, but we need to assign layers |
| 10486 | // for handleNewWindowLocked() below. |
| 10487 | assignLayersLocked(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10488 | } |
| 10489 | } |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 10490 | |
| 10491 | if (mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS) { |
| 10492 | // If we defer assigning layers, then the caller is responsible for |
| 10493 | // doing this part. |
| 10494 | finishUpdateFocusedWindowAfterAssignLayersLocked(); |
| The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 10495 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10496 | return true; |
| 10497 | } |
| 10498 | return false; |
| 10499 | } |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 10500 | |
| 10501 | private void finishUpdateFocusedWindowAfterAssignLayersLocked() { |
| Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 10502 | mInputMonitor.setInputFocusLw(mCurrentFocus); |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 10503 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10504 | |
| 10505 | private WindowState computeFocusedWindowLocked() { |
| 10506 | WindowState result = null; |
| 10507 | WindowState win; |
| 10508 | |
| 10509 | int i = mWindows.size() - 1; |
| 10510 | int nextAppIndex = mAppTokens.size()-1; |
| 10511 | WindowToken nextApp = nextAppIndex >= 0 |
| 10512 | ? mAppTokens.get(nextAppIndex) : null; |
| 10513 | |
| 10514 | while (i >= 0) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 10515 | win = mWindows.get(i); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10516 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10517 | if (localLOGV || DEBUG_FOCUS) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10518 | TAG, "Looking for focus: " + i |
| 10519 | + " = " + win |
| 10520 | + ", flags=" + win.mAttrs.flags |
| 10521 | + ", canReceive=" + win.canReceiveKeys()); |
| 10522 | |
| 10523 | AppWindowToken thisApp = win.mAppToken; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10524 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10525 | // If this window's application has been removed, just skip it. |
| 10526 | if (thisApp != null && thisApp.removed) { |
| 10527 | i--; |
| 10528 | continue; |
| 10529 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10530 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10531 | // If there is a focused app, don't allow focus to go to any |
| 10532 | // windows below it. If this is an application window, step |
| 10533 | // through the app tokens until we find its app. |
| 10534 | if (thisApp != null && nextApp != null && thisApp != nextApp |
| 10535 | && win.mAttrs.type != TYPE_APPLICATION_STARTING) { |
| 10536 | int origAppIndex = nextAppIndex; |
| 10537 | while (nextAppIndex > 0) { |
| 10538 | if (nextApp == mFocusedApp) { |
| 10539 | // Whoops, we are below the focused app... no focus |
| 10540 | // for you! |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10541 | if (localLOGV || DEBUG_FOCUS) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10542 | TAG, "Reached focused app: " + mFocusedApp); |
| 10543 | return null; |
| 10544 | } |
| 10545 | nextAppIndex--; |
| 10546 | nextApp = mAppTokens.get(nextAppIndex); |
| 10547 | if (nextApp == thisApp) { |
| 10548 | break; |
| 10549 | } |
| 10550 | } |
| 10551 | if (thisApp != nextApp) { |
| 10552 | // Uh oh, the app token doesn't exist! This shouldn't |
| 10553 | // happen, but if it does we can get totally hosed... |
| 10554 | // so restart at the original app. |
| 10555 | nextAppIndex = origAppIndex; |
| 10556 | nextApp = mAppTokens.get(nextAppIndex); |
| 10557 | } |
| 10558 | } |
| 10559 | |
| 10560 | // Dispatch to this window if it is wants key events. |
| 10561 | if (win.canReceiveKeys()) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10562 | if (DEBUG_FOCUS) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10563 | TAG, "Found focus @ " + i + " = " + win); |
| 10564 | result = win; |
| 10565 | break; |
| 10566 | } |
| 10567 | |
| 10568 | i--; |
| 10569 | } |
| 10570 | |
| 10571 | return result; |
| 10572 | } |
| 10573 | |
| 10574 | private void startFreezingDisplayLocked() { |
| 10575 | if (mDisplayFrozen) { |
| 10576 | return; |
| 10577 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10578 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10579 | mScreenFrozenLock.acquire(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10580 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10581 | long now = SystemClock.uptimeMillis(); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10582 | //Slog.i(TAG, "Freezing, gc pending: " + mFreezeGcPending + ", now " + now); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10583 | if (mFreezeGcPending != 0) { |
| 10584 | if (now > (mFreezeGcPending+1000)) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10585 | //Slog.i(TAG, "Gc! " + now + " > " + (mFreezeGcPending+1000)); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10586 | mH.removeMessages(H.FORCE_GC); |
| 10587 | Runtime.getRuntime().gc(); |
| 10588 | mFreezeGcPending = now; |
| 10589 | } |
| 10590 | } else { |
| 10591 | mFreezeGcPending = now; |
| 10592 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10593 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10594 | mDisplayFrozen = true; |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 10595 | |
| Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 10596 | mInputMonitor.freezeInputDispatchingLw(); |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 10597 | |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 10598 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
| 10599 | mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10600 | mNextAppTransitionPackage = null; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10601 | mAppTransitionReady = true; |
| 10602 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10603 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10604 | if (PROFILE_ORIENTATION) { |
| 10605 | File file = new File("/data/system/frozen"); |
| 10606 | Debug.startMethodTracing(file.toString(), 8 * 1024 * 1024); |
| 10607 | } |
| 10608 | Surface.freezeDisplay(0); |
| 10609 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10610 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10611 | private void stopFreezingDisplayLocked() { |
| 10612 | if (!mDisplayFrozen) { |
| 10613 | return; |
| 10614 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10615 | |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 10616 | if (mWaitingForConfig || mAppsFreezingScreen > 0 || mWindowsFreezingScreen) { |
| 10617 | return; |
| 10618 | } |
| 10619 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10620 | mDisplayFrozen = false; |
| 10621 | mH.removeMessages(H.APP_FREEZE_TIMEOUT); |
| 10622 | if (PROFILE_ORIENTATION) { |
| 10623 | Debug.stopMethodTracing(); |
| 10624 | } |
| 10625 | Surface.unfreezeDisplay(0); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10626 | |
| Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 10627 | mInputMonitor.thawInputDispatchingLw(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10628 | |
| Christopher Tate | b696aee | 2010-04-02 19:08:30 -0700 | [diff] [blame] | 10629 | // While the display is frozen we don't re-compute the orientation |
| 10630 | // to avoid inconsistent states. However, something interesting |
| 10631 | // could have actually changed during that time so re-evaluate it |
| 10632 | // now to catch that. |
| 10633 | if (updateOrientationFromAppTokensLocked()) { |
| 10634 | mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION); |
| 10635 | } |
| 10636 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10637 | // A little kludge: a lot could have happened while the |
| 10638 | // display was frozen, so now that we are coming back we |
| 10639 | // do a gc so that any remote references the system |
| 10640 | // processes holds on others can be released if they are |
| 10641 | // no longer needed. |
| 10642 | mH.removeMessages(H.FORCE_GC); |
| 10643 | mH.sendMessageDelayed(mH.obtainMessage(H.FORCE_GC), |
| 10644 | 2000); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10645 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10646 | mScreenFrozenLock.release(); |
| 10647 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10648 | |
| Dianne Hackborn | b9fb170 | 2010-08-23 16:49:02 -0700 | [diff] [blame] | 10649 | static int getPropertyInt(String[] tokens, int index, int defUnits, int defDps, |
| 10650 | DisplayMetrics dm) { |
| 10651 | if (index < tokens.length) { |
| 10652 | String str = tokens[index]; |
| 10653 | if (str != null && str.length() > 0) { |
| 10654 | try { |
| 10655 | int val = Integer.parseInt(str); |
| 10656 | return val; |
| 10657 | } catch (Exception e) { |
| 10658 | } |
| 10659 | } |
| Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 10660 | } |
| 10661 | if (defUnits == TypedValue.COMPLEX_UNIT_PX) { |
| 10662 | return defDps; |
| 10663 | } |
| 10664 | int val = (int)TypedValue.applyDimension(defUnits, defDps, dm); |
| 10665 | return val; |
| 10666 | } |
| 10667 | |
| 10668 | class Watermark { |
| Dianne Hackborn | b9fb170 | 2010-08-23 16:49:02 -0700 | [diff] [blame] | 10669 | final String[] mTokens; |
| 10670 | final String mText; |
| 10671 | final Paint mTextPaint; |
| 10672 | final int mTextWidth; |
| 10673 | final int mTextHeight; |
| 10674 | final int mTextAscent; |
| 10675 | final int mTextDescent; |
| 10676 | final int mDeltaX; |
| 10677 | final int mDeltaY; |
| Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 10678 | |
| Dianne Hackborn | b9fb170 | 2010-08-23 16:49:02 -0700 | [diff] [blame] | 10679 | Surface mSurface; |
| 10680 | int mLastDW; |
| 10681 | int mLastDH; |
| 10682 | boolean mDrawNeeded; |
| 10683 | |
| 10684 | Watermark(SurfaceSession session, String[] tokens) { |
| Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 10685 | final DisplayMetrics dm = new DisplayMetrics(); |
| 10686 | mDisplay.getMetrics(dm); |
| 10687 | |
| Dianne Hackborn | b9fb170 | 2010-08-23 16:49:02 -0700 | [diff] [blame] | 10688 | if (false) { |
| 10689 | Log.i(TAG, "*********************** WATERMARK"); |
| 10690 | for (int i=0; i<tokens.length; i++) { |
| 10691 | Log.i(TAG, " TOKEN #" + i + ": " + tokens[i]); |
| 10692 | } |
| 10693 | } |
| Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 10694 | |
| Dianne Hackborn | b9fb170 | 2010-08-23 16:49:02 -0700 | [diff] [blame] | 10695 | mTokens = tokens; |
| Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 10696 | |
| Dianne Hackborn | b9fb170 | 2010-08-23 16:49:02 -0700 | [diff] [blame] | 10697 | StringBuilder builder = new StringBuilder(32); |
| 10698 | int len = mTokens[0].length(); |
| 10699 | len = len & ~1; |
| 10700 | for (int i=0; i<len; i+=2) { |
| 10701 | int c1 = mTokens[0].charAt(i); |
| 10702 | int c2 = mTokens[0].charAt(i+1); |
| 10703 | if (c1 >= 'a' && c1 <= 'f') c1 = c1 - 'a' + 10; |
| 10704 | else if (c1 >= 'A' && c1 <= 'F') c1 = c1 - 'A' + 10; |
| 10705 | else c1 -= '0'; |
| 10706 | if (c2 >= 'a' && c2 <= 'f') c2 = c2 - 'a' + 10; |
| 10707 | else if (c2 >= 'A' && c2 <= 'F') c2 = c2 - 'A' + 10; |
| 10708 | else c2 -= '0'; |
| 10709 | builder.append((char)(255-((c1*16)+c2))); |
| 10710 | } |
| 10711 | mText = builder.toString(); |
| 10712 | if (false) { |
| 10713 | Log.i(TAG, "Final text: " + mText); |
| 10714 | } |
| 10715 | |
| 10716 | int fontSize = getPropertyInt(tokens, 1, |
| 10717 | TypedValue.COMPLEX_UNIT_DIP, 20, dm); |
| 10718 | |
| 10719 | mTextPaint = new Paint(Paint.ANTI_ALIAS_FLAG); |
| 10720 | mTextPaint.setTextSize(fontSize); |
| 10721 | mTextPaint.setTypeface(Typeface.create(Typeface.SANS_SERIF, Typeface.BOLD)); |
| 10722 | |
| 10723 | FontMetricsInt fm = mTextPaint.getFontMetricsInt(); |
| 10724 | mTextWidth = (int)mTextPaint.measureText(mText); |
| 10725 | mTextAscent = fm.ascent; |
| 10726 | mTextDescent = fm.descent; |
| 10727 | mTextHeight = fm.descent - fm.ascent; |
| 10728 | |
| 10729 | mDeltaX = getPropertyInt(tokens, 2, |
| 10730 | TypedValue.COMPLEX_UNIT_PX, mTextWidth*2, dm); |
| 10731 | mDeltaY = getPropertyInt(tokens, 3, |
| 10732 | TypedValue.COMPLEX_UNIT_PX, mTextHeight*3, dm); |
| 10733 | int shadowColor = getPropertyInt(tokens, 4, |
| 10734 | TypedValue.COMPLEX_UNIT_PX, 0xb0000000, dm); |
| 10735 | int color = getPropertyInt(tokens, 5, |
| 10736 | TypedValue.COMPLEX_UNIT_PX, 0x60ffffff, dm); |
| 10737 | int shadowRadius = getPropertyInt(tokens, 6, |
| 10738 | TypedValue.COMPLEX_UNIT_PX, 7, dm); |
| 10739 | int shadowDx = getPropertyInt(tokens, 8, |
| 10740 | TypedValue.COMPLEX_UNIT_PX, 0, dm); |
| 10741 | int shadowDy = getPropertyInt(tokens, 9, |
| 10742 | TypedValue.COMPLEX_UNIT_PX, 0, dm); |
| 10743 | |
| 10744 | mTextPaint.setColor(color); |
| 10745 | mTextPaint.setShadowLayer(shadowRadius, shadowDx, shadowDy, shadowColor); |
| Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 10746 | |
| 10747 | try { |
| 10748 | mSurface = new Surface(session, 0, |
| Dianne Hackborn | b9fb170 | 2010-08-23 16:49:02 -0700 | [diff] [blame] | 10749 | "WatermarkSurface", -1, 1, 1, PixelFormat.TRANSLUCENT, 0); |
| Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 10750 | mSurface.setLayer(TYPE_LAYER_MULTIPLIER*100); |
| Dianne Hackborn | b9fb170 | 2010-08-23 16:49:02 -0700 | [diff] [blame] | 10751 | mSurface.setPosition(0, 0); |
| Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 10752 | mSurface.show(); |
| 10753 | } catch (OutOfResourcesException e) { |
| 10754 | } |
| 10755 | } |
| 10756 | |
| 10757 | void positionSurface(int dw, int dh) { |
| Dianne Hackborn | b9fb170 | 2010-08-23 16:49:02 -0700 | [diff] [blame] | 10758 | if (mLastDW != dw || mLastDH != dh) { |
| 10759 | mLastDW = dw; |
| 10760 | mLastDH = dh; |
| 10761 | mSurface.setSize(dw, dh); |
| 10762 | mDrawNeeded = true; |
| 10763 | } |
| 10764 | } |
| 10765 | |
| 10766 | void drawIfNeeded() { |
| 10767 | if (mDrawNeeded) { |
| 10768 | final int dw = mLastDW; |
| 10769 | final int dh = mLastDH; |
| 10770 | |
| 10771 | mDrawNeeded = false; |
| 10772 | Rect dirty = new Rect(0, 0, dw, dh); |
| 10773 | Canvas c = null; |
| 10774 | try { |
| 10775 | c = mSurface.lockCanvas(dirty); |
| 10776 | } catch (IllegalArgumentException e) { |
| 10777 | } catch (OutOfResourcesException e) { |
| 10778 | } |
| 10779 | if (c != null) { |
| 10780 | int deltaX = mDeltaX; |
| 10781 | int deltaY = mDeltaY; |
| 10782 | |
| 10783 | // deltaX shouldn't be close to a round fraction of our |
| 10784 | // x step, or else things will line up too much. |
| 10785 | int div = (dw+mTextWidth)/deltaX; |
| 10786 | int rem = (dw+mTextWidth) - (div*deltaX); |
| 10787 | int qdelta = deltaX/4; |
| 10788 | if (rem < qdelta || rem > (deltaX-qdelta)) { |
| 10789 | deltaX += deltaX/3; |
| 10790 | } |
| 10791 | |
| 10792 | int y = -mTextHeight; |
| 10793 | int x = -mTextWidth; |
| 10794 | while (y < (dh+mTextHeight)) { |
| 10795 | c.drawText(mText, x, y, mTextPaint); |
| 10796 | x += deltaX; |
| 10797 | if (x >= dw) { |
| 10798 | x -= (dw+mTextWidth); |
| 10799 | y += deltaY; |
| 10800 | } |
| 10801 | } |
| 10802 | mSurface.unlockCanvasAndPost(c); |
| 10803 | } |
| 10804 | } |
| Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 10805 | } |
| 10806 | } |
| 10807 | |
| 10808 | void createWatermark() { |
| 10809 | if (mWatermark != null) { |
| 10810 | return; |
| 10811 | } |
| 10812 | |
| Dianne Hackborn | b9fb170 | 2010-08-23 16:49:02 -0700 | [diff] [blame] | 10813 | File file = new File("/system/etc/setup.conf"); |
| 10814 | FileInputStream in = null; |
| 10815 | try { |
| 10816 | in = new FileInputStream(file); |
| 10817 | DataInputStream ind = new DataInputStream(in); |
| 10818 | String line = ind.readLine(); |
| 10819 | if (line != null) { |
| 10820 | String[] toks = line.split("%"); |
| 10821 | if (toks != null && toks.length > 0) { |
| 10822 | mWatermark = new Watermark(mFxSession, toks); |
| 10823 | } |
| 10824 | } |
| 10825 | } catch (FileNotFoundException e) { |
| 10826 | } catch (IOException e) { |
| 10827 | } finally { |
| 10828 | if (in != null) { |
| 10829 | try { |
| 10830 | in.close(); |
| 10831 | } catch (IOException e) { |
| 10832 | } |
| 10833 | } |
| Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 10834 | } |
| Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 10835 | } |
| 10836 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10837 | @Override |
| 10838 | public void dump(FileDescriptor fd, PrintWriter pw, String[] args) { |
| 10839 | if (mContext.checkCallingOrSelfPermission("android.permission.DUMP") |
| 10840 | != PackageManager.PERMISSION_GRANTED) { |
| 10841 | pw.println("Permission Denial: can't dump WindowManager from from pid=" |
| 10842 | + Binder.getCallingPid() |
| 10843 | + ", uid=" + Binder.getCallingUid()); |
| 10844 | return; |
| 10845 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10846 | |
| Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 10847 | mInputManager.dump(pw); |
| Dianne Hackborn | a2e9226 | 2010-03-02 17:19:29 -0800 | [diff] [blame] | 10848 | pw.println(" "); |
| 10849 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10850 | synchronized(mWindowMap) { |
| 10851 | pw.println("Current Window Manager state:"); |
| 10852 | for (int i=mWindows.size()-1; i>=0; i--) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 10853 | WindowState w = mWindows.get(i); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10854 | pw.print(" Window #"); pw.print(i); pw.print(' '); |
| 10855 | pw.print(w); pw.println(":"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10856 | w.dump(pw, " "); |
| 10857 | } |
| 10858 | if (mInputMethodDialogs.size() > 0) { |
| 10859 | pw.println(" "); |
| 10860 | pw.println(" Input method dialogs:"); |
| 10861 | for (int i=mInputMethodDialogs.size()-1; i>=0; i--) { |
| 10862 | WindowState w = mInputMethodDialogs.get(i); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10863 | 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] | 10864 | } |
| 10865 | } |
| 10866 | if (mPendingRemove.size() > 0) { |
| 10867 | pw.println(" "); |
| 10868 | pw.println(" Remove pending for:"); |
| 10869 | for (int i=mPendingRemove.size()-1; i>=0; i--) { |
| 10870 | WindowState w = mPendingRemove.get(i); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10871 | pw.print(" Remove #"); pw.print(i); pw.print(' '); |
| 10872 | pw.print(w); pw.println(":"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10873 | w.dump(pw, " "); |
| 10874 | } |
| 10875 | } |
| 10876 | if (mForceRemoves != null && mForceRemoves.size() > 0) { |
| 10877 | pw.println(" "); |
| 10878 | pw.println(" Windows force removing:"); |
| 10879 | for (int i=mForceRemoves.size()-1; i>=0; i--) { |
| 10880 | WindowState w = mForceRemoves.get(i); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10881 | pw.print(" Removing #"); pw.print(i); pw.print(' '); |
| 10882 | pw.print(w); pw.println(":"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10883 | w.dump(pw, " "); |
| 10884 | } |
| 10885 | } |
| 10886 | if (mDestroySurface.size() > 0) { |
| 10887 | pw.println(" "); |
| 10888 | pw.println(" Windows waiting to destroy their surface:"); |
| 10889 | for (int i=mDestroySurface.size()-1; i>=0; i--) { |
| 10890 | WindowState w = mDestroySurface.get(i); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10891 | pw.print(" Destroy #"); pw.print(i); pw.print(' '); |
| 10892 | pw.print(w); pw.println(":"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10893 | w.dump(pw, " "); |
| 10894 | } |
| 10895 | } |
| 10896 | if (mLosingFocus.size() > 0) { |
| 10897 | pw.println(" "); |
| 10898 | pw.println(" Windows losing focus:"); |
| 10899 | for (int i=mLosingFocus.size()-1; i>=0; i--) { |
| 10900 | WindowState w = mLosingFocus.get(i); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10901 | pw.print(" Losing #"); pw.print(i); pw.print(' '); |
| 10902 | pw.print(w); pw.println(":"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10903 | w.dump(pw, " "); |
| 10904 | } |
| 10905 | } |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 10906 | if (mResizingWindows.size() > 0) { |
| 10907 | pw.println(" "); |
| 10908 | pw.println(" Windows waiting to resize:"); |
| 10909 | for (int i=mResizingWindows.size()-1; i>=0; i--) { |
| 10910 | WindowState w = mResizingWindows.get(i); |
| 10911 | pw.print(" Resizing #"); pw.print(i); pw.print(' '); |
| 10912 | pw.print(w); pw.println(":"); |
| 10913 | w.dump(pw, " "); |
| 10914 | } |
| 10915 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10916 | if (mSessions.size() > 0) { |
| 10917 | pw.println(" "); |
| 10918 | pw.println(" All active sessions:"); |
| 10919 | Iterator<Session> it = mSessions.iterator(); |
| 10920 | while (it.hasNext()) { |
| 10921 | Session s = it.next(); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10922 | pw.print(" Session "); pw.print(s); pw.println(':'); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10923 | s.dump(pw, " "); |
| 10924 | } |
| 10925 | } |
| 10926 | if (mTokenMap.size() > 0) { |
| 10927 | pw.println(" "); |
| 10928 | pw.println(" All tokens:"); |
| 10929 | Iterator<WindowToken> it = mTokenMap.values().iterator(); |
| 10930 | while (it.hasNext()) { |
| 10931 | WindowToken token = it.next(); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10932 | pw.print(" Token "); pw.print(token.token); pw.println(':'); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10933 | token.dump(pw, " "); |
| 10934 | } |
| 10935 | } |
| 10936 | if (mTokenList.size() > 0) { |
| 10937 | pw.println(" "); |
| 10938 | pw.println(" Window token list:"); |
| 10939 | for (int i=0; i<mTokenList.size(); i++) { |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10940 | pw.print(" #"); pw.print(i); pw.print(": "); |
| 10941 | pw.println(mTokenList.get(i)); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10942 | } |
| 10943 | } |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 10944 | if (mWallpaperTokens.size() > 0) { |
| 10945 | pw.println(" "); |
| 10946 | pw.println(" Wallpaper tokens:"); |
| 10947 | for (int i=mWallpaperTokens.size()-1; i>=0; i--) { |
| 10948 | WindowToken token = mWallpaperTokens.get(i); |
| 10949 | pw.print(" Wallpaper #"); pw.print(i); |
| 10950 | pw.print(' '); pw.print(token); pw.println(':'); |
| 10951 | token.dump(pw, " "); |
| 10952 | } |
| 10953 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10954 | if (mAppTokens.size() > 0) { |
| 10955 | pw.println(" "); |
| 10956 | pw.println(" Application tokens in Z order:"); |
| 10957 | for (int i=mAppTokens.size()-1; i>=0; i--) { |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10958 | pw.print(" App #"); pw.print(i); pw.print(": "); |
| 10959 | pw.println(mAppTokens.get(i)); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10960 | } |
| 10961 | } |
| 10962 | if (mFinishedStarting.size() > 0) { |
| 10963 | pw.println(" "); |
| 10964 | pw.println(" Finishing start of application tokens:"); |
| 10965 | for (int i=mFinishedStarting.size()-1; i>=0; i--) { |
| 10966 | WindowToken token = mFinishedStarting.get(i); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10967 | pw.print(" Finished Starting #"); pw.print(i); |
| 10968 | pw.print(' '); pw.print(token); pw.println(':'); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10969 | token.dump(pw, " "); |
| 10970 | } |
| 10971 | } |
| 10972 | if (mExitingTokens.size() > 0) { |
| 10973 | pw.println(" "); |
| 10974 | pw.println(" Exiting tokens:"); |
| 10975 | for (int i=mExitingTokens.size()-1; i>=0; i--) { |
| 10976 | WindowToken token = mExitingTokens.get(i); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10977 | pw.print(" Exiting #"); pw.print(i); |
| 10978 | pw.print(' '); pw.print(token); pw.println(':'); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10979 | token.dump(pw, " "); |
| 10980 | } |
| 10981 | } |
| 10982 | if (mExitingAppTokens.size() > 0) { |
| 10983 | pw.println(" "); |
| 10984 | pw.println(" Exiting application tokens:"); |
| 10985 | for (int i=mExitingAppTokens.size()-1; i>=0; i--) { |
| 10986 | WindowToken token = mExitingAppTokens.get(i); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10987 | pw.print(" Exiting App #"); pw.print(i); |
| 10988 | pw.print(' '); pw.print(token); pw.println(':'); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10989 | token.dump(pw, " "); |
| 10990 | } |
| 10991 | } |
| 10992 | pw.println(" "); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10993 | pw.print(" mCurrentFocus="); pw.println(mCurrentFocus); |
| 10994 | pw.print(" mLastFocus="); pw.println(mLastFocus); |
| 10995 | pw.print(" mFocusedApp="); pw.println(mFocusedApp); |
| 10996 | pw.print(" mInputMethodTarget="); pw.println(mInputMethodTarget); |
| 10997 | pw.print(" mInputMethodWindow="); pw.println(mInputMethodWindow); |
| Dianne Hackborn | f21adf6 | 2009-08-13 10:20:21 -0700 | [diff] [blame] | 10998 | pw.print(" mWallpaperTarget="); pw.println(mWallpaperTarget); |
| Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 10999 | if (mLowerWallpaperTarget != null && mUpperWallpaperTarget != null) { |
| 11000 | pw.print(" mLowerWallpaperTarget="); pw.println(mLowerWallpaperTarget); |
| 11001 | pw.print(" mUpperWallpaperTarget="); pw.println(mUpperWallpaperTarget); |
| 11002 | } |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 11003 | pw.print(" mCurConfiguration="); pw.println(this.mCurConfiguration); |
| 11004 | pw.print(" mInTouchMode="); pw.print(mInTouchMode); |
| 11005 | pw.print(" mLayoutSeq="); pw.println(mLayoutSeq); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11006 | pw.print(" mSystemBooted="); pw.print(mSystemBooted); |
| 11007 | pw.print(" mDisplayEnabled="); pw.println(mDisplayEnabled); |
| 11008 | pw.print(" mLayoutNeeded="); pw.print(mLayoutNeeded); |
| 11009 | pw.print(" mBlurShown="); pw.println(mBlurShown); |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11010 | if (mDimAnimator != null) { |
| 11011 | mDimAnimator.printTo(pw); |
| 11012 | } else { |
| Dianne Hackborn | a2e9226 | 2010-03-02 17:19:29 -0800 | [diff] [blame] | 11013 | pw.println( " no DimAnimator "); |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11014 | } |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11015 | pw.print(" mInputMethodAnimLayerAdjustment="); |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 11016 | pw.print(mInputMethodAnimLayerAdjustment); |
| 11017 | pw.print(" mWallpaperAnimLayerAdjustment="); |
| 11018 | pw.println(mWallpaperAnimLayerAdjustment); |
| Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 11019 | pw.print(" mLastWallpaperX="); pw.print(mLastWallpaperX); |
| 11020 | pw.print(" mLastWallpaperY="); pw.println(mLastWallpaperY); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11021 | pw.print(" mDisplayFrozen="); pw.print(mDisplayFrozen); |
| 11022 | pw.print(" mWindowsFreezingScreen="); pw.print(mWindowsFreezingScreen); |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 11023 | pw.print(" mAppsFreezingScreen="); pw.print(mAppsFreezingScreen); |
| 11024 | pw.print(" mWaitingForConfig="); pw.println(mWaitingForConfig); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11025 | pw.print(" mRotation="); pw.print(mRotation); |
| 11026 | pw.print(", mForcedAppOrientation="); pw.print(mForcedAppOrientation); |
| 11027 | pw.print(", mRequestedRotation="); pw.println(mRequestedRotation); |
| 11028 | pw.print(" mAnimationPending="); pw.print(mAnimationPending); |
| 11029 | pw.print(" mWindowAnimationScale="); pw.print(mWindowAnimationScale); |
| 11030 | pw.print(" mTransitionWindowAnimationScale="); pw.println(mTransitionAnimationScale); |
| 11031 | pw.print(" mNextAppTransition=0x"); |
| 11032 | pw.print(Integer.toHexString(mNextAppTransition)); |
| 11033 | pw.print(", mAppTransitionReady="); pw.print(mAppTransitionReady); |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 11034 | pw.print(", mAppTransitionRunning="); pw.print(mAppTransitionRunning); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11035 | pw.print(", mAppTransitionTimeout="); pw.println( mAppTransitionTimeout); |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 11036 | if (mNextAppTransitionPackage != null) { |
| 11037 | pw.print(" mNextAppTransitionPackage="); |
| 11038 | pw.print(mNextAppTransitionPackage); |
| 11039 | pw.print(", mNextAppTransitionEnter=0x"); |
| 11040 | pw.print(Integer.toHexString(mNextAppTransitionEnter)); |
| 11041 | pw.print(", mNextAppTransitionExit=0x"); |
| 11042 | pw.print(Integer.toHexString(mNextAppTransitionExit)); |
| 11043 | } |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11044 | pw.print(" mStartingIconInTransition="); pw.print(mStartingIconInTransition); |
| 11045 | pw.print(", mSkipAppTransitionAnimation="); pw.println(mSkipAppTransitionAnimation); |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 11046 | if (mLastEnterAnimToken != null || mLastEnterAnimToken != null) { |
| 11047 | pw.print(" mLastEnterAnimToken="); pw.print(mLastEnterAnimToken); |
| 11048 | pw.print(", mLastEnterAnimParams="); pw.println(mLastEnterAnimParams); |
| 11049 | } |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11050 | if (mOpeningApps.size() > 0) { |
| 11051 | pw.print(" mOpeningApps="); pw.println(mOpeningApps); |
| 11052 | } |
| 11053 | if (mClosingApps.size() > 0) { |
| 11054 | pw.print(" mClosingApps="); pw.println(mClosingApps); |
| 11055 | } |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 11056 | if (mToTopApps.size() > 0) { |
| 11057 | pw.print(" mToTopApps="); pw.println(mToTopApps); |
| 11058 | } |
| 11059 | if (mToBottomApps.size() > 0) { |
| 11060 | pw.print(" mToBottomApps="); pw.println(mToBottomApps); |
| 11061 | } |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11062 | pw.print(" DisplayWidth="); pw.print(mDisplay.getWidth()); |
| 11063 | pw.print(" DisplayHeight="); pw.println(mDisplay.getHeight()); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11064 | } |
| 11065 | } |
| 11066 | |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 11067 | // 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] | 11068 | public void monitor() { |
| 11069 | synchronized (mWindowMap) { } |
| Mike Lockwood | 983ee09 | 2009-11-22 01:42:24 -0500 | [diff] [blame] | 11070 | synchronized (mKeyguardTokenWatcher) { } |
| Dianne Hackborn | ddca3ee | 2009-07-23 19:01:31 -0700 | [diff] [blame] | 11071 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 11072 | |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11073 | /** |
| 11074 | * DimAnimator class that controls the dim animation. This holds the surface and |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 11075 | * all state used for dim animation. |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11076 | */ |
| 11077 | private static class DimAnimator { |
| 11078 | Surface mDimSurface; |
| 11079 | boolean mDimShown = false; |
| 11080 | float mDimCurrentAlpha; |
| 11081 | float mDimTargetAlpha; |
| 11082 | float mDimDeltaPerMs; |
| 11083 | long mLastDimAnimTime; |
| Dianne Hackborn | f83c555 | 2010-03-31 22:19:32 -0700 | [diff] [blame] | 11084 | |
| 11085 | int mLastDimWidth, mLastDimHeight; |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11086 | |
| 11087 | DimAnimator (SurfaceSession session) { |
| 11088 | if (mDimSurface == null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 11089 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11090 | + mDimSurface + ": CREATE"); |
| 11091 | try { |
| Mathias Agopian | 5d26c1e | 2010-03-01 16:09:43 -0800 | [diff] [blame] | 11092 | mDimSurface = new Surface(session, 0, |
| 11093 | "DimSurface", |
| 11094 | -1, 16, 16, PixelFormat.OPAQUE, |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11095 | Surface.FX_SURFACE_DIM); |
| Maciej Białka | 9ee5c22 | 2010-03-24 10:25:40 +0100 | [diff] [blame] | 11096 | mDimSurface.setAlpha(0.0f); |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11097 | } catch (Exception e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 11098 | Slog.e(TAG, "Exception creating Dim surface", e); |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11099 | } |
| 11100 | } |
| 11101 | } |
| 11102 | |
| 11103 | /** |
| 11104 | * Show the dim surface. |
| 11105 | */ |
| 11106 | void show(int dw, int dh) { |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 11107 | if (!mDimShown) { |
| 11108 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface + ": SHOW pos=(0,0) (" + |
| 11109 | dw + "x" + dh + ")"); |
| 11110 | mDimShown = true; |
| 11111 | try { |
| Dianne Hackborn | f83c555 | 2010-03-31 22:19:32 -0700 | [diff] [blame] | 11112 | mLastDimWidth = dw; |
| 11113 | mLastDimHeight = dh; |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 11114 | mDimSurface.setPosition(0, 0); |
| 11115 | mDimSurface.setSize(dw, dh); |
| 11116 | mDimSurface.show(); |
| 11117 | } catch (RuntimeException e) { |
| 11118 | Slog.w(TAG, "Failure showing dim surface", e); |
| 11119 | } |
| Dianne Hackborn | f83c555 | 2010-03-31 22:19:32 -0700 | [diff] [blame] | 11120 | } else if (mLastDimWidth != dw || mLastDimHeight != dh) { |
| 11121 | mLastDimWidth = dw; |
| 11122 | mLastDimHeight = dh; |
| 11123 | mDimSurface.setSize(dw, dh); |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11124 | } |
| 11125 | } |
| 11126 | |
| 11127 | /** |
| 11128 | * Set's the dim surface's layer and update dim parameters that will be used in |
| 11129 | * {@link updateSurface} after all windows are examined. |
| 11130 | */ |
| 11131 | void updateParameters(WindowState w, long currentTime) { |
| 11132 | mDimSurface.setLayer(w.mAnimLayer-1); |
| 11133 | |
| 11134 | final float target = w.mExiting ? 0 : w.mAttrs.dimAmount; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 11135 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 11136 | + ": layer=" + (w.mAnimLayer-1) + " target=" + target); |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11137 | if (mDimTargetAlpha != target) { |
| 11138 | // If the desired dim level has changed, then |
| 11139 | // start an animation to it. |
| 11140 | mLastDimAnimTime = currentTime; |
| 11141 | long duration = (w.mAnimating && w.mAnimation != null) |
| 11142 | ? w.mAnimation.computeDurationHint() |
| 11143 | : DEFAULT_DIM_DURATION; |
| 11144 | if (target > mDimTargetAlpha) { |
| 11145 | // This is happening behind the activity UI, |
| 11146 | // so we can make it run a little longer to |
| 11147 | // give a stronger impression without disrupting |
| 11148 | // the user. |
| 11149 | duration *= DIM_DURATION_MULTIPLIER; |
| 11150 | } |
| 11151 | if (duration < 1) { |
| 11152 | // Don't divide by zero |
| 11153 | duration = 1; |
| 11154 | } |
| 11155 | mDimTargetAlpha = target; |
| 11156 | mDimDeltaPerMs = (mDimTargetAlpha-mDimCurrentAlpha) / duration; |
| 11157 | } |
| 11158 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 11159 | |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11160 | /** |
| 11161 | * Updating the surface's alpha. Returns true if the animation continues, or returns |
| 11162 | * false when the animation is finished and the dim surface is hidden. |
| 11163 | */ |
| 11164 | boolean updateSurface(boolean dimming, long currentTime, boolean displayFrozen) { |
| 11165 | if (!dimming) { |
| 11166 | if (mDimTargetAlpha != 0) { |
| 11167 | mLastDimAnimTime = currentTime; |
| 11168 | mDimTargetAlpha = 0; |
| 11169 | mDimDeltaPerMs = (-mDimCurrentAlpha) / DEFAULT_DIM_DURATION; |
| 11170 | } |
| 11171 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 11172 | |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11173 | boolean animating = false; |
| 11174 | if (mLastDimAnimTime != 0) { |
| 11175 | mDimCurrentAlpha += mDimDeltaPerMs |
| 11176 | * (currentTime-mLastDimAnimTime); |
| 11177 | boolean more = true; |
| 11178 | if (displayFrozen) { |
| 11179 | // If the display is frozen, there is no reason to animate. |
| 11180 | more = false; |
| 11181 | } else if (mDimDeltaPerMs > 0) { |
| 11182 | if (mDimCurrentAlpha > mDimTargetAlpha) { |
| 11183 | more = false; |
| 11184 | } |
| 11185 | } else if (mDimDeltaPerMs < 0) { |
| 11186 | if (mDimCurrentAlpha < mDimTargetAlpha) { |
| 11187 | more = false; |
| 11188 | } |
| 11189 | } else { |
| 11190 | more = false; |
| 11191 | } |
| 11192 | |
| 11193 | // Do we need to continue animating? |
| 11194 | if (more) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 11195 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11196 | + mDimSurface + ": alpha=" + mDimCurrentAlpha); |
| 11197 | mLastDimAnimTime = currentTime; |
| 11198 | mDimSurface.setAlpha(mDimCurrentAlpha); |
| 11199 | animating = true; |
| 11200 | } else { |
| 11201 | mDimCurrentAlpha = mDimTargetAlpha; |
| 11202 | mLastDimAnimTime = 0; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 11203 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11204 | + mDimSurface + ": final alpha=" + mDimCurrentAlpha); |
| 11205 | mDimSurface.setAlpha(mDimCurrentAlpha); |
| 11206 | if (!dimming) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 11207 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11208 | + ": HIDE"); |
| 11209 | try { |
| 11210 | mDimSurface.hide(); |
| 11211 | } catch (RuntimeException e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 11212 | Slog.w(TAG, "Illegal argument exception hiding dim surface"); |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11213 | } |
| 11214 | mDimShown = false; |
| 11215 | } |
| 11216 | } |
| 11217 | } |
| 11218 | return animating; |
| 11219 | } |
| 11220 | |
| 11221 | public void printTo(PrintWriter pw) { |
| 11222 | pw.print(" mDimShown="); pw.print(mDimShown); |
| 11223 | pw.print(" current="); pw.print(mDimCurrentAlpha); |
| 11224 | pw.print(" target="); pw.print(mDimTargetAlpha); |
| 11225 | pw.print(" delta="); pw.print(mDimDeltaPerMs); |
| 11226 | pw.print(" lastAnimTime="); pw.println(mLastDimAnimTime); |
| 11227 | } |
| 11228 | } |
| 11229 | |
| 11230 | /** |
| 11231 | * Animation that fade in after 0.5 interpolate time, or fade out in reverse order. |
| 11232 | * This is used for opening/closing transition for apps in compatible mode. |
| 11233 | */ |
| 11234 | private static class FadeInOutAnimation extends Animation { |
| 11235 | int mWidth; |
| 11236 | boolean mFadeIn; |
| 11237 | |
| 11238 | public FadeInOutAnimation(boolean fadeIn) { |
| 11239 | setInterpolator(new AccelerateInterpolator()); |
| 11240 | setDuration(DEFAULT_FADE_IN_OUT_DURATION); |
| 11241 | mFadeIn = fadeIn; |
| 11242 | } |
| 11243 | |
| 11244 | @Override |
| 11245 | protected void applyTransformation(float interpolatedTime, Transformation t) { |
| 11246 | float x = interpolatedTime; |
| 11247 | if (!mFadeIn) { |
| 11248 | x = 1.0f - x; // reverse the interpolation for fade out |
| 11249 | } |
| 11250 | if (x < 0.5) { |
| 11251 | // move the window out of the screen. |
| 11252 | t.getMatrix().setTranslate(mWidth, 0); |
| 11253 | } else { |
| 11254 | t.getMatrix().setTranslate(0, 0);// show |
| 11255 | t.setAlpha((x - 0.5f) * 2); |
| 11256 | } |
| 11257 | } |
| 11258 | |
| 11259 | @Override |
| 11260 | public void initialize(int width, int height, int parentWidth, int parentHeight) { |
| 11261 | // width is the screen width {@see AppWindowToken#stepAnimatinoLocked} |
| 11262 | mWidth = width; |
| 11263 | } |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11264 | |
| 11265 | @Override |
| Mitsuru Oshima | 5a2b91d | 2009-07-16 16:30:02 -0700 | [diff] [blame] | 11266 | public int getZAdjustment() { |
| 11267 | return Animation.ZORDER_TOP; |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11268 | } |
| 11269 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11270 | } |