| 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; |
| 504 | float mThumbOffsetX, mThumbOffsetY; |
| 505 | InputChannel mServerChannel, mClientChannel; |
| 506 | WindowState mTargetWindow; |
| 507 | ArrayList<WindowState> mNotifiedWindows; |
| Christopher Tate | 5ada6cb | 2010-10-05 14:15:29 -0700 | [diff] [blame^] | 508 | boolean mDragInProgress; |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 509 | |
| 510 | private final Rect tmpRect = new Rect(); |
| 511 | |
| 512 | DragState(IBinder token, Surface surface, boolean localOnly) { |
| 513 | mToken = token; |
| 514 | mSurface = surface; |
| 515 | mLocalOnly = localOnly; |
| 516 | mNotifiedWindows = new ArrayList<WindowState>(); |
| 517 | } |
| 518 | |
| 519 | void reset() { |
| 520 | if (mSurface != null) { |
| 521 | mSurface.destroy(); |
| 522 | } |
| 523 | mSurface = null; |
| 524 | mLocalOnly = false; |
| 525 | mToken = null; |
| 526 | mData = null; |
| 527 | mThumbOffsetX = mThumbOffsetY = 0; |
| 528 | mNotifiedWindows = null; |
| 529 | } |
| 530 | |
| 531 | void register() { |
| 532 | if (DEBUG_DRAG) Slog.d(TAG, "registering drag input channel"); |
| 533 | if (mClientChannel != null) { |
| 534 | Slog.e(TAG, "Duplicate register of drag input channel"); |
| 535 | } else { |
| 536 | InputChannel[] channels = InputChannel.openInputChannelPair("drag"); |
| 537 | mServerChannel = channels[0]; |
| 538 | mClientChannel = channels[1]; |
| 539 | mInputManager.registerInputChannel(mServerChannel); |
| 540 | InputQueue.registerInputChannel(mClientChannel, mDragInputHandler, |
| 541 | mH.getLooper().getQueue()); |
| 542 | } |
| 543 | } |
| 544 | |
| 545 | void unregister() { |
| 546 | if (DEBUG_DRAG) Slog.d(TAG, "unregistering drag input channel"); |
| 547 | if (mClientChannel == null) { |
| 548 | Slog.e(TAG, "Unregister of nonexistent drag input channel"); |
| 549 | } else { |
| 550 | mInputManager.unregisterInputChannel(mServerChannel); |
| 551 | InputQueue.unregisterInputChannel(mClientChannel); |
| 552 | mClientChannel.dispose(); |
| 553 | mClientChannel = null; |
| 554 | mServerChannel = null; |
| 555 | } |
| 556 | } |
| 557 | |
| 558 | /* call out to each visible window/session informing it about the drag |
| 559 | */ |
| 560 | void broadcastDragStartedLw() { |
| 561 | // Cache a base-class instance of the clip metadata so that parceling |
| 562 | // works correctly in calling out to the apps. |
| 563 | mDataDescription = new ClipDescription(mData); |
| 564 | mNotifiedWindows.clear(); |
| Christopher Tate | 5ada6cb | 2010-10-05 14:15:29 -0700 | [diff] [blame^] | 565 | mDragInProgress = true; |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 566 | |
| 567 | if (DEBUG_DRAG) { |
| 568 | Slog.d(TAG, "broadcasting DRAG_STARTED of " + mDataDescription); |
| 569 | } |
| 570 | |
| 571 | DragEvent evt = DragEvent.obtain(DragEvent.ACTION_DRAG_STARTED, 0, 0, |
| 572 | mDataDescription, null); |
| Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 573 | final int N = mWindows.size(); |
| 574 | for (int i = 0; i < N; i++) { |
| 575 | // sendDragStartedLw() clones evt for local-process dispatch |
| 576 | sendDragStartedLw(mWindows.get(i), evt); |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 577 | } |
| 578 | evt.recycle(); |
| 579 | } |
| 580 | |
| 581 | /* helper - send a caller-provided event, presumed to be DRAG_STARTED, if the |
| 582 | * designated window is potentially a drop recipient. There are race situations |
| 583 | * around DRAG_ENDED broadcast, so we make sure that once we've declared that |
| 584 | * 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] | 585 | * |
| 586 | * This method clones the 'event' parameter if it's being delivered to the same |
| 587 | * 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] | 588 | */ |
| Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 589 | private void sendDragStartedLw(WindowState newWin, DragEvent event) { |
| Christopher Tate | 5ada6cb | 2010-10-05 14:15:29 -0700 | [diff] [blame^] | 590 | if (mDragInProgress && newWin.isPotentialDragTarget()) { |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 591 | try { |
| Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 592 | // clone for local callees since dispatch will recycle the event |
| 593 | if (Process.myPid() == newWin.mSession.mPid) { |
| 594 | event = DragEvent.obtain(event); |
| 595 | } |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 596 | newWin.mClient.dispatchDragEvent(event); |
| 597 | // track each window that we've notified that the drag is starting |
| 598 | mNotifiedWindows.add(newWin); |
| 599 | } catch (RemoteException e) { |
| 600 | Slog.w(TAG, "Unable to drag-start window " + newWin); |
| 601 | } |
| 602 | } |
| 603 | } |
| 604 | |
| 605 | /* helper - construct and send a DRAG_STARTED event only if the window has not |
| 606 | * previously been notified, i.e. it became visible after the drag operation |
| 607 | * was begun. This is a rare case. |
| 608 | */ |
| 609 | private void sendDragStartedIfNeededLw(WindowState newWin) { |
| Christopher Tate | 5ada6cb | 2010-10-05 14:15:29 -0700 | [diff] [blame^] | 610 | if (mDragInProgress) { |
| 611 | // If we have sent the drag-started, we needn't do so again |
| 612 | for (WindowState ws : mNotifiedWindows) { |
| 613 | if (ws == newWin) { |
| 614 | return; |
| 615 | } |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 616 | } |
| Christopher Tate | 5ada6cb | 2010-10-05 14:15:29 -0700 | [diff] [blame^] | 617 | if (DEBUG_DRAG) { |
| 618 | Slog.d(TAG, "sending DRAG_STARTED to new window " + newWin); |
| 619 | } |
| 620 | DragEvent event = DragEvent.obtain(DragEvent.ACTION_DRAG_STARTED, 0, 0, |
| 621 | mDataDescription, null); |
| 622 | // sendDragStartedLw() clones 'event' if the window is process-local |
| 623 | sendDragStartedLw(newWin, event); |
| 624 | event.recycle(); |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 625 | } |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 626 | } |
| 627 | |
| 628 | void broadcastDragEnded() { |
| 629 | if (DEBUG_DRAG) { |
| 630 | Slog.d(TAG, "broadcasting DRAG_ENDED"); |
| 631 | } |
| 632 | DragEvent evt = DragEvent.obtain(DragEvent.ACTION_DRAG_ENDED, 0, 0, null, null); |
| 633 | synchronized (mWindowMap) { |
| 634 | for (WindowState ws: mNotifiedWindows) { |
| 635 | try { |
| 636 | ws.mClient.dispatchDragEvent(evt); |
| 637 | } catch (RemoteException e) { |
| 638 | Slog.w(TAG, "Unable to drag-end window " + ws); |
| 639 | } |
| 640 | } |
| 641 | mNotifiedWindows.clear(); |
| Christopher Tate | 5ada6cb | 2010-10-05 14:15:29 -0700 | [diff] [blame^] | 642 | mDragInProgress = false; |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 643 | } |
| 644 | evt.recycle(); |
| 645 | } |
| 646 | |
| 647 | void notifyMoveLw(float x, float y) { |
| Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 648 | final int myPid = Process.myPid(); |
| 649 | |
| 650 | // Move the surface to the given touch |
| 651 | mSurface.openTransaction(); |
| 652 | mSurface.setPosition((int)(x - mThumbOffsetX), (int)(y - mThumbOffsetY)); |
| 653 | mSurface.closeTransaction(); |
| 654 | |
| 655 | // Tell the affected window |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 656 | WindowState touchedWin = getTouchedWinAtPointLw(x, y); |
| 657 | try { |
| 658 | // have we dragged over a new window? |
| 659 | if ((touchedWin != mTargetWindow) && (mTargetWindow != null)) { |
| 660 | if (DEBUG_DRAG) { |
| 661 | Slog.d(TAG, "sending DRAG_EXITED to " + mTargetWindow); |
| 662 | } |
| 663 | // force DRAG_EXITED_EVENT if appropriate |
| 664 | DragEvent evt = DragEvent.obtain(DragEvent.ACTION_DRAG_EXITED, |
| 665 | 0, 0, null, null); |
| 666 | mTargetWindow.mClient.dispatchDragEvent(evt); |
| Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 667 | if (myPid != mTargetWindow.mSession.mPid) { |
| 668 | evt.recycle(); |
| 669 | } |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 670 | } |
| 671 | if (touchedWin != null) { |
| 672 | if (DEBUG_DRAG) { |
| 673 | Slog.d(TAG, "sending DRAG_LOCATION to " + touchedWin); |
| 674 | } |
| 675 | DragEvent evt = DragEvent.obtain(DragEvent.ACTION_DRAG_LOCATION, |
| 676 | x, y, null, null); |
| 677 | touchedWin.mClient.dispatchDragEvent(evt); |
| Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 678 | if (myPid != touchedWin.mSession.mPid) { |
| 679 | evt.recycle(); |
| 680 | } |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 681 | } |
| 682 | } catch (RemoteException e) { |
| 683 | Slog.w(TAG, "can't send drag notification to windows"); |
| 684 | } |
| 685 | mTargetWindow = touchedWin; |
| 686 | } |
| 687 | |
| 688 | // Tell the drop target about the data, and then broadcast the drag-ended notification |
| 689 | void notifyDropLw(float x, float y) { |
| 690 | WindowState touchedWin = getTouchedWinAtPointLw(x, y); |
| 691 | if (touchedWin != null) { |
| 692 | if (DEBUG_DRAG) { |
| 693 | Slog.d(TAG, "sending DROP to " + touchedWin); |
| 694 | } |
| Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 695 | final int myPid = Process.myPid(); |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 696 | DragEvent evt = DragEvent.obtain(DragEvent.ACTION_DROP, x, y, null, mData); |
| 697 | try { |
| 698 | touchedWin.mClient.dispatchDragEvent(evt); |
| 699 | } catch (RemoteException e) { |
| 700 | Slog.w(TAG, "can't send drop notification to win " + touchedWin); |
| 701 | } |
| Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 702 | if (myPid != touchedWin.mSession.mPid) { |
| 703 | evt.recycle(); |
| 704 | } |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 705 | } |
| 706 | } |
| 707 | |
| 708 | // Find the visible, touch-deliverable window under the given point |
| 709 | private WindowState getTouchedWinAtPointLw(float xf, float yf) { |
| 710 | WindowState touchedWin = null; |
| 711 | final int x = (int) xf; |
| 712 | final int y = (int) yf; |
| 713 | final ArrayList<WindowState> windows = mWindows; |
| 714 | final int N = windows.size(); |
| 715 | for (int i = N - 1; i >= 0; i--) { |
| 716 | WindowState child = windows.get(i); |
| 717 | final int flags = child.mAttrs.flags; |
| 718 | if (!child.isVisibleLw()) { |
| 719 | // not visible == don't tell about drags |
| 720 | continue; |
| 721 | } |
| 722 | if ((flags & WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE) != 0) { |
| 723 | // not touchable == don't tell about drags |
| 724 | continue; |
| 725 | } |
| 726 | // account for the window's decor etc |
| 727 | tmpRect.set(child.mFrame); |
| 728 | if (child.mTouchableInsets == ViewTreeObserver |
| 729 | .InternalInsetsInfo.TOUCHABLE_INSETS_CONTENT) { |
| 730 | // The point is inside of the window if it is |
| 731 | // inside the frame, AND the content part of that |
| 732 | // frame that was given by the application. |
| 733 | tmpRect.left += child.mGivenContentInsets.left; |
| 734 | tmpRect.top += child.mGivenContentInsets.top; |
| 735 | tmpRect.right -= child.mGivenContentInsets.right; |
| 736 | tmpRect.bottom -= child.mGivenContentInsets.bottom; |
| 737 | } else if (child.mTouchableInsets == ViewTreeObserver |
| 738 | .InternalInsetsInfo.TOUCHABLE_INSETS_VISIBLE) { |
| 739 | // The point is inside of the window if it is |
| 740 | // inside the frame, AND the visible part of that |
| 741 | // frame that was given by the application. |
| 742 | tmpRect.left += child.mGivenVisibleInsets.left; |
| 743 | tmpRect.top += child.mGivenVisibleInsets.top; |
| 744 | tmpRect.right -= child.mGivenVisibleInsets.right; |
| 745 | tmpRect.bottom -= child.mGivenVisibleInsets.bottom; |
| 746 | } |
| 747 | final int touchFlags = flags & |
| 748 | (WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE |
| 749 | | WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL); |
| 750 | if (tmpRect.contains(x, y) || touchFlags == 0) { |
| 751 | // Found it |
| 752 | touchedWin = child; |
| 753 | break; |
| 754 | } |
| 755 | } |
| 756 | |
| 757 | return touchedWin; |
| 758 | } |
| 759 | } |
| 760 | |
| 761 | DragState mDragState = null; |
| 762 | private final InputHandler mDragInputHandler = new BaseInputHandler() { |
| 763 | @Override |
| 764 | public void handleMotion(MotionEvent event, Runnable finishedCallback) { |
| 765 | boolean endDrag = false; |
| 766 | final float newX = event.getRawX(); |
| 767 | final float newY = event.getRawY(); |
| 768 | |
| 769 | try { |
| 770 | if (mDragState != null) { |
| 771 | switch (event.getAction()) { |
| 772 | case MotionEvent.ACTION_DOWN: { |
| 773 | if (DEBUG_DRAG) { |
| 774 | Slog.w(TAG, "Unexpected ACTION_DOWN in drag layer"); |
| 775 | } |
| 776 | } break; |
| 777 | |
| 778 | case MotionEvent.ACTION_MOVE: { |
| 779 | synchronized (mWindowMap) { |
| Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 780 | // move the surface and tell the involved window(s) where we are |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 781 | mDragState.notifyMoveLw(newX, newY); |
| 782 | } |
| 783 | } break; |
| 784 | |
| 785 | case MotionEvent.ACTION_UP: { |
| 786 | if (DEBUG_DRAG) Slog.d(TAG, "Got UP on move channel; dropping at " |
| 787 | + newX + "," + newY); |
| 788 | synchronized (mWindowMap) { |
| 789 | mDragState.notifyDropLw(newX, newY); |
| 790 | } |
| 791 | endDrag = true; |
| 792 | } break; |
| 793 | |
| 794 | case MotionEvent.ACTION_CANCEL: { |
| 795 | if (DEBUG_DRAG) Slog.d(TAG, "Drag cancelled!"); |
| 796 | endDrag = true; |
| 797 | } break; |
| 798 | } |
| 799 | |
| 800 | if (endDrag) { |
| 801 | if (DEBUG_DRAG) Slog.d(TAG, "Drag ended; tearing down state"); |
| 802 | // tell all the windows that the drag has ended |
| 803 | mDragState.broadcastDragEnded(); |
| 804 | |
| 805 | // stop intercepting input |
| 806 | mDragState.unregister(); |
| 807 | mInputMonitor.updateInputWindowsLw(); |
| 808 | |
| 809 | // free our resources and drop all the object references |
| 810 | mDragState.reset(); |
| 811 | mDragState = null; |
| 812 | } |
| 813 | } |
| 814 | } catch (Exception e) { |
| 815 | Slog.e(TAG, "Exception caught by drag handleMotion", e); |
| 816 | } finally { |
| 817 | finishedCallback.run(); |
| 818 | } |
| 819 | } |
| 820 | }; |
| 821 | |
| 822 | /** |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 823 | * Whether the UI is currently running in touch mode (not showing |
| 824 | * navigational focus because the user is directly pressing the screen). |
| 825 | */ |
| 826 | boolean mInTouchMode = false; |
| 827 | |
| 828 | private ViewServer mViewServer; |
| Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 829 | private ArrayList<WindowChangeListener> mWindowChangeListeners = |
| 830 | new ArrayList<WindowChangeListener>(); |
| 831 | private boolean mWindowsChanged = false; |
| 832 | |
| 833 | public interface WindowChangeListener { |
| 834 | public void windowsChanged(); |
| Konstantin Lopyrev | 6e0f65f | 2010-07-14 14:55:33 -0700 | [diff] [blame] | 835 | public void focusChanged(); |
| Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 836 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 837 | |
| Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 838 | final Configuration mTempConfiguration = new Configuration(); |
| Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 839 | int mScreenLayout = Configuration.SCREENLAYOUT_SIZE_UNDEFINED; |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 840 | |
| 841 | // The frame use to limit the size of the app running in compatibility mode. |
| 842 | Rect mCompatibleScreenFrame = new Rect(); |
| 843 | // The surface used to fill the outer rim of the app running in compatibility mode. |
| 844 | Surface mBackgroundFillerSurface = null; |
| 845 | boolean mBackgroundFillerShown = false; |
| 846 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 847 | public static WindowManagerService main(Context context, |
| 848 | PowerManagerService pm, boolean haveInputMethods) { |
| 849 | WMThread thr = new WMThread(context, pm, haveInputMethods); |
| 850 | thr.start(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 851 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 852 | synchronized (thr) { |
| 853 | while (thr.mService == null) { |
| 854 | try { |
| 855 | thr.wait(); |
| 856 | } catch (InterruptedException e) { |
| 857 | } |
| 858 | } |
| 859 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 860 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 861 | return thr.mService; |
| 862 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 863 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 864 | static class WMThread extends Thread { |
| 865 | WindowManagerService mService; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 866 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 867 | private final Context mContext; |
| 868 | private final PowerManagerService mPM; |
| 869 | private final boolean mHaveInputMethods; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 870 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 871 | public WMThread(Context context, PowerManagerService pm, |
| 872 | boolean haveInputMethods) { |
| 873 | super("WindowManager"); |
| 874 | mContext = context; |
| 875 | mPM = pm; |
| 876 | mHaveInputMethods = haveInputMethods; |
| 877 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 878 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 879 | public void run() { |
| 880 | Looper.prepare(); |
| 881 | WindowManagerService s = new WindowManagerService(mContext, mPM, |
| 882 | mHaveInputMethods); |
| 883 | android.os.Process.setThreadPriority( |
| 884 | android.os.Process.THREAD_PRIORITY_DISPLAY); |
| Christopher Tate | 160edb3 | 2010-06-30 17:46:30 -0700 | [diff] [blame] | 885 | android.os.Process.setCanSelfBackground(false); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 886 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 887 | synchronized (this) { |
| 888 | mService = s; |
| 889 | notifyAll(); |
| 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 | Looper.loop(); |
| 893 | } |
| 894 | } |
| 895 | |
| 896 | static class PolicyThread extends Thread { |
| 897 | private final WindowManagerPolicy mPolicy; |
| 898 | private final WindowManagerService mService; |
| 899 | private final Context mContext; |
| 900 | private final PowerManagerService mPM; |
| 901 | boolean mRunning = false; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 902 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 903 | public PolicyThread(WindowManagerPolicy policy, |
| 904 | WindowManagerService service, Context context, |
| 905 | PowerManagerService pm) { |
| 906 | super("WindowManagerPolicy"); |
| 907 | mPolicy = policy; |
| 908 | mService = service; |
| 909 | mContext = context; |
| 910 | mPM = pm; |
| 911 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 912 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 913 | public void run() { |
| 914 | Looper.prepare(); |
| Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 915 | WindowManagerPolicyThread.set(this, Looper.myLooper()); |
| 916 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 917 | //Looper.myLooper().setMessageLogging(new LogPrinter( |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 918 | // Log.VERBOSE, "WindowManagerPolicy", Log.LOG_ID_SYSTEM)); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 919 | android.os.Process.setThreadPriority( |
| 920 | android.os.Process.THREAD_PRIORITY_FOREGROUND); |
| Christopher Tate | 160edb3 | 2010-06-30 17:46:30 -0700 | [diff] [blame] | 921 | android.os.Process.setCanSelfBackground(false); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 922 | mPolicy.init(mContext, mService, mPM); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 923 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 924 | synchronized (this) { |
| 925 | mRunning = true; |
| 926 | notifyAll(); |
| 927 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 928 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 929 | Looper.loop(); |
| 930 | } |
| 931 | } |
| 932 | |
| 933 | private WindowManagerService(Context context, PowerManagerService pm, |
| 934 | boolean haveInputMethods) { |
| 935 | mContext = context; |
| 936 | mHaveInputMethods = haveInputMethods; |
| 937 | mLimitedAlphaCompositing = context.getResources().getBoolean( |
| 938 | com.android.internal.R.bool.config_sf_limitedAlpha); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 939 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 940 | mPowerManager = pm; |
| 941 | mPowerManager.setPolicy(mPolicy); |
| 942 | PowerManager pmc = (PowerManager)context.getSystemService(Context.POWER_SERVICE); |
| 943 | mScreenFrozenLock = pmc.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, |
| 944 | "SCREEN_FROZEN"); |
| 945 | mScreenFrozenLock.setReferenceCounted(false); |
| 946 | |
| 947 | mActivityManager = ActivityManagerNative.getDefault(); |
| 948 | mBatteryStats = BatteryStatsService.getService(); |
| 949 | |
| 950 | // Get persisted window scale setting |
| 951 | mWindowAnimationScale = Settings.System.getFloat(context.getContentResolver(), |
| 952 | Settings.System.WINDOW_ANIMATION_SCALE, mWindowAnimationScale); |
| 953 | mTransitionAnimationScale = Settings.System.getFloat(context.getContentResolver(), |
| 954 | Settings.System.TRANSITION_ANIMATION_SCALE, mTransitionAnimationScale); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 955 | |
| Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 956 | // Track changes to DevicePolicyManager state so we can enable/disable keyguard. |
| 957 | IntentFilter filter = new IntentFilter(); |
| 958 | filter.addAction(DevicePolicyManager.ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED); |
| 959 | mContext.registerReceiver(mBroadcastReceiver, filter); |
| 960 | |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 961 | mHoldingScreenWakeLock = pmc.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK, |
| 962 | "KEEP_SCREEN_ON_FLAG"); |
| 963 | mHoldingScreenWakeLock.setReferenceCounted(false); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 964 | |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 965 | mInputManager = new InputManager(context, this); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 966 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 967 | PolicyThread thr = new PolicyThread(mPolicy, this, context, pm); |
| 968 | thr.start(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 969 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 970 | synchronized (thr) { |
| 971 | while (!thr.mRunning) { |
| 972 | try { |
| 973 | thr.wait(); |
| 974 | } catch (InterruptedException e) { |
| 975 | } |
| 976 | } |
| 977 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 978 | |
| Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 979 | mInputManager.start(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 980 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 981 | // Add ourself to the Watchdog monitors. |
| 982 | Watchdog.getInstance().addMonitor(this); |
| 983 | } |
| 984 | |
| 985 | @Override |
| 986 | public boolean onTransact(int code, Parcel data, Parcel reply, int flags) |
| 987 | throws RemoteException { |
| 988 | try { |
| 989 | return super.onTransact(code, data, reply, flags); |
| 990 | } catch (RuntimeException e) { |
| 991 | // The window manager only throws security exceptions, so let's |
| 992 | // log all others. |
| 993 | if (!(e instanceof SecurityException)) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 994 | Slog.e(TAG, "Window Manager Crash", e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 995 | } |
| 996 | throw e; |
| 997 | } |
| 998 | } |
| 999 | |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1000 | private void placeWindowAfter(WindowState pos, WindowState window) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1001 | final int i = mWindows.indexOf(pos); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1002 | if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1003 | TAG, "Adding window " + window + " at " |
| 1004 | + (i+1) + " of " + mWindows.size() + " (after " + pos + ")"); |
| 1005 | mWindows.add(i+1, window); |
| Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 1006 | mWindowsChanged = true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1007 | } |
| 1008 | |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1009 | private void placeWindowBefore(WindowState pos, WindowState window) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1010 | final int i = mWindows.indexOf(pos); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1011 | if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1012 | TAG, "Adding window " + window + " at " |
| 1013 | + i + " of " + mWindows.size() + " (before " + pos + ")"); |
| 1014 | mWindows.add(i, window); |
| Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 1015 | mWindowsChanged = true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1016 | } |
| 1017 | |
| 1018 | //This method finds out the index of a window that has the same app token as |
| 1019 | //win. used for z ordering the windows in mWindows |
| 1020 | private int findIdxBasedOnAppTokens(WindowState win) { |
| 1021 | //use a local variable to cache mWindows |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1022 | ArrayList<WindowState> localmWindows = mWindows; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1023 | int jmax = localmWindows.size(); |
| 1024 | if(jmax == 0) { |
| 1025 | return -1; |
| 1026 | } |
| 1027 | for(int j = (jmax-1); j >= 0; j--) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1028 | WindowState wentry = localmWindows.get(j); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1029 | if(wentry.mAppToken == win.mAppToken) { |
| 1030 | return j; |
| 1031 | } |
| 1032 | } |
| 1033 | return -1; |
| 1034 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1035 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1036 | private void addWindowToListInOrderLocked(WindowState win, boolean addToToken) { |
| 1037 | final IWindow client = win.mClient; |
| 1038 | final WindowToken token = win.mToken; |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1039 | final ArrayList<WindowState> localmWindows = mWindows; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1040 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1041 | final int N = localmWindows.size(); |
| 1042 | final WindowState attached = win.mAttachedWindow; |
| 1043 | int i; |
| 1044 | if (attached == null) { |
| 1045 | int tokenWindowsPos = token.windows.size(); |
| 1046 | if (token.appWindowToken != null) { |
| 1047 | int index = tokenWindowsPos-1; |
| 1048 | if (index >= 0) { |
| 1049 | // If this application has existing windows, we |
| 1050 | // simply place the new window on top of them... but |
| 1051 | // keep the starting window on top. |
| 1052 | if (win.mAttrs.type == TYPE_BASE_APPLICATION) { |
| 1053 | // Base windows go behind everything else. |
| 1054 | placeWindowBefore(token.windows.get(0), win); |
| 1055 | tokenWindowsPos = 0; |
| 1056 | } else { |
| 1057 | AppWindowToken atoken = win.mAppToken; |
| 1058 | if (atoken != null && |
| 1059 | token.windows.get(index) == atoken.startingWindow) { |
| 1060 | placeWindowBefore(token.windows.get(index), win); |
| 1061 | tokenWindowsPos--; |
| 1062 | } else { |
| 1063 | int newIdx = findIdxBasedOnAppTokens(win); |
| 1064 | if(newIdx != -1) { |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1065 | //there is a window above this one associated with the same |
| 1066 | //apptoken note that the window could be a floating window |
| 1067 | //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] | 1068 | //windows associated with this token. |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1069 | if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v( |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 1070 | TAG, "Adding window " + win + " at " |
| 1071 | + (newIdx+1) + " of " + N); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1072 | localmWindows.add(newIdx+1, win); |
| Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 1073 | mWindowsChanged = true; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1074 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1075 | } |
| 1076 | } |
| 1077 | } else { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1078 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1079 | TAG, "Figuring out where to add app window " |
| 1080 | + client.asBinder() + " (token=" + token + ")"); |
| 1081 | // Figure out where the window should go, based on the |
| 1082 | // order of applications. |
| 1083 | final int NA = mAppTokens.size(); |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1084 | WindowState pos = null; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1085 | for (i=NA-1; i>=0; i--) { |
| 1086 | AppWindowToken t = mAppTokens.get(i); |
| 1087 | if (t == token) { |
| 1088 | i--; |
| 1089 | break; |
| 1090 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1091 | |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 1092 | // We haven't reached the token yet; if this token |
| 1093 | // is not going to the bottom and has windows, we can |
| 1094 | // use it as an anchor for when we do reach the token. |
| 1095 | if (!t.sendingToBottom && t.windows.size() > 0) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1096 | pos = t.windows.get(0); |
| 1097 | } |
| 1098 | } |
| 1099 | // We now know the index into the apps. If we found |
| 1100 | // an app window above, that gives us the position; else |
| 1101 | // we need to look some more. |
| 1102 | if (pos != null) { |
| 1103 | // Move behind any windows attached to this one. |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1104 | WindowToken atoken = mTokenMap.get(pos.mClient.asBinder()); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1105 | if (atoken != null) { |
| 1106 | final int NC = atoken.windows.size(); |
| 1107 | if (NC > 0) { |
| 1108 | WindowState bottom = atoken.windows.get(0); |
| 1109 | if (bottom.mSubLayer < 0) { |
| 1110 | pos = bottom; |
| 1111 | } |
| 1112 | } |
| 1113 | } |
| 1114 | placeWindowBefore(pos, win); |
| 1115 | } else { |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 1116 | // Continue looking down until we find the first |
| 1117 | // token that has windows. |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1118 | while (i >= 0) { |
| 1119 | AppWindowToken t = mAppTokens.get(i); |
| 1120 | final int NW = t.windows.size(); |
| 1121 | if (NW > 0) { |
| 1122 | pos = t.windows.get(NW-1); |
| 1123 | break; |
| 1124 | } |
| 1125 | i--; |
| 1126 | } |
| 1127 | if (pos != null) { |
| 1128 | // Move in front of any windows attached to this |
| 1129 | // one. |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1130 | WindowToken atoken = mTokenMap.get(pos.mClient.asBinder()); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1131 | if (atoken != null) { |
| 1132 | final int NC = atoken.windows.size(); |
| 1133 | if (NC > 0) { |
| 1134 | WindowState top = atoken.windows.get(NC-1); |
| 1135 | if (top.mSubLayer >= 0) { |
| 1136 | pos = top; |
| 1137 | } |
| 1138 | } |
| 1139 | } |
| 1140 | placeWindowAfter(pos, win); |
| 1141 | } else { |
| 1142 | // Just search for the start of this layer. |
| 1143 | final int myLayer = win.mBaseLayer; |
| 1144 | for (i=0; i<N; i++) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1145 | WindowState w = localmWindows.get(i); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1146 | if (w.mBaseLayer > myLayer) { |
| 1147 | break; |
| 1148 | } |
| 1149 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1150 | if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v( |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 1151 | TAG, "Adding window " + win + " at " |
| 1152 | + i + " of " + N); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1153 | localmWindows.add(i, win); |
| Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 1154 | mWindowsChanged = true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1155 | } |
| 1156 | } |
| 1157 | } |
| 1158 | } else { |
| 1159 | // Figure out where window should go, based on layer. |
| 1160 | final int myLayer = win.mBaseLayer; |
| 1161 | for (i=N-1; i>=0; i--) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1162 | if (localmWindows.get(i).mBaseLayer <= myLayer) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1163 | i++; |
| 1164 | break; |
| 1165 | } |
| 1166 | } |
| 1167 | if (i < 0) i = 0; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1168 | if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v( |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 1169 | TAG, "Adding window " + win + " at " |
| 1170 | + i + " of " + N); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1171 | localmWindows.add(i, win); |
| Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 1172 | mWindowsChanged = true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1173 | } |
| 1174 | if (addToToken) { |
| 1175 | token.windows.add(tokenWindowsPos, win); |
| 1176 | } |
| 1177 | |
| 1178 | } else { |
| 1179 | // Figure out this window's ordering relative to the window |
| 1180 | // it is attached to. |
| 1181 | final int NA = token.windows.size(); |
| 1182 | final int sublayer = win.mSubLayer; |
| 1183 | int largestSublayer = Integer.MIN_VALUE; |
| 1184 | WindowState windowWithLargestSublayer = null; |
| 1185 | for (i=0; i<NA; i++) { |
| 1186 | WindowState w = token.windows.get(i); |
| 1187 | final int wSublayer = w.mSubLayer; |
| 1188 | if (wSublayer >= largestSublayer) { |
| 1189 | largestSublayer = wSublayer; |
| 1190 | windowWithLargestSublayer = w; |
| 1191 | } |
| 1192 | if (sublayer < 0) { |
| 1193 | // For negative sublayers, we go below all windows |
| 1194 | // in the same sublayer. |
| 1195 | if (wSublayer >= sublayer) { |
| 1196 | if (addToToken) { |
| 1197 | token.windows.add(i, win); |
| 1198 | } |
| 1199 | placeWindowBefore( |
| 1200 | wSublayer >= 0 ? attached : w, win); |
| 1201 | break; |
| 1202 | } |
| 1203 | } else { |
| 1204 | // For positive sublayers, we go above all windows |
| 1205 | // in the same sublayer. |
| 1206 | if (wSublayer > sublayer) { |
| 1207 | if (addToToken) { |
| 1208 | token.windows.add(i, win); |
| 1209 | } |
| 1210 | placeWindowBefore(w, win); |
| 1211 | break; |
| 1212 | } |
| 1213 | } |
| 1214 | } |
| 1215 | if (i >= NA) { |
| 1216 | if (addToToken) { |
| 1217 | token.windows.add(win); |
| 1218 | } |
| 1219 | if (sublayer < 0) { |
| 1220 | placeWindowBefore(attached, win); |
| 1221 | } else { |
| 1222 | placeWindowAfter(largestSublayer >= 0 |
| 1223 | ? windowWithLargestSublayer |
| 1224 | : attached, |
| 1225 | win); |
| 1226 | } |
| 1227 | } |
| 1228 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1229 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1230 | if (win.mAppToken != null && addToToken) { |
| 1231 | win.mAppToken.allAppWindows.add(win); |
| 1232 | } |
| 1233 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1234 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1235 | static boolean canBeImeTarget(WindowState w) { |
| 1236 | final int fl = w.mAttrs.flags |
| 1237 | & (FLAG_NOT_FOCUSABLE|FLAG_ALT_FOCUSABLE_IM); |
| 1238 | if (fl == 0 || fl == (FLAG_NOT_FOCUSABLE|FLAG_ALT_FOCUSABLE_IM)) { |
| 1239 | return w.isVisibleOrAdding(); |
| 1240 | } |
| 1241 | return false; |
| 1242 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1243 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1244 | int findDesiredInputMethodWindowIndexLocked(boolean willMove) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1245 | final ArrayList<WindowState> localmWindows = mWindows; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1246 | final int N = localmWindows.size(); |
| 1247 | WindowState w = null; |
| 1248 | int i = N; |
| 1249 | while (i > 0) { |
| 1250 | i--; |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1251 | w = localmWindows.get(i); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1252 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1253 | //Slog.i(TAG, "Checking window @" + i + " " + w + " fl=0x" |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1254 | // + Integer.toHexString(w.mAttrs.flags)); |
| 1255 | if (canBeImeTarget(w)) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1256 | //Slog.i(TAG, "Putting input method here!"); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1257 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1258 | // Yet more tricksyness! If this window is a "starting" |
| 1259 | // window, we do actually want to be on top of it, but |
| 1260 | // it is not -really- where input will go. So if the caller |
| 1261 | // is not actually looking to move the IME, look down below |
| 1262 | // for a real window to target... |
| 1263 | if (!willMove |
| 1264 | && w.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING |
| 1265 | && i > 0) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1266 | WindowState wb = localmWindows.get(i-1); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1267 | if (wb.mAppToken == w.mAppToken && canBeImeTarget(wb)) { |
| 1268 | i--; |
| 1269 | w = wb; |
| 1270 | } |
| 1271 | } |
| 1272 | break; |
| 1273 | } |
| 1274 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1275 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1276 | mUpcomingInputMethodTarget = w; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1277 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1278 | 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] | 1279 | + w + " willMove=" + willMove); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1280 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1281 | if (willMove && w != null) { |
| 1282 | final WindowState curTarget = mInputMethodTarget; |
| 1283 | if (curTarget != null && curTarget.mAppToken != null) { |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1284 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1285 | // Now some fun for dealing with window animations that |
| 1286 | // modify the Z order. We need to look at all windows below |
| 1287 | // the current target that are in this app, finding the highest |
| 1288 | // visible one in layering. |
| 1289 | AppWindowToken token = curTarget.mAppToken; |
| 1290 | WindowState highestTarget = null; |
| 1291 | int highestPos = 0; |
| 1292 | if (token.animating || token.animation != null) { |
| 1293 | int pos = 0; |
| 1294 | pos = localmWindows.indexOf(curTarget); |
| 1295 | while (pos >= 0) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1296 | WindowState win = localmWindows.get(pos); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1297 | if (win.mAppToken != token) { |
| 1298 | break; |
| 1299 | } |
| 1300 | if (!win.mRemoved) { |
| 1301 | if (highestTarget == null || win.mAnimLayer > |
| 1302 | highestTarget.mAnimLayer) { |
| 1303 | highestTarget = win; |
| 1304 | highestPos = pos; |
| 1305 | } |
| 1306 | } |
| 1307 | pos--; |
| 1308 | } |
| 1309 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1310 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1311 | if (highestTarget != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1312 | if (DEBUG_INPUT_METHOD) Slog.v(TAG, "mNextAppTransition=" |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1313 | + mNextAppTransition + " " + highestTarget |
| 1314 | + " animating=" + highestTarget.isAnimating() |
| 1315 | + " layer=" + highestTarget.mAnimLayer |
| 1316 | + " new layer=" + w.mAnimLayer); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1317 | |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 1318 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1319 | // If we are currently setting up for an animation, |
| 1320 | // hold everything until we can find out what will happen. |
| 1321 | mInputMethodTargetWaitingAnim = true; |
| 1322 | mInputMethodTarget = highestTarget; |
| 1323 | return highestPos + 1; |
| 1324 | } else if (highestTarget.isAnimating() && |
| 1325 | highestTarget.mAnimLayer > w.mAnimLayer) { |
| 1326 | // If the window we are currently targeting is involved |
| 1327 | // with an animation, and it is on top of the next target |
| 1328 | // we will be over, then hold off on moving until |
| 1329 | // that is done. |
| 1330 | mInputMethodTarget = highestTarget; |
| 1331 | return highestPos + 1; |
| 1332 | } |
| 1333 | } |
| 1334 | } |
| 1335 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1336 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1337 | //Slog.i(TAG, "Placing input method @" + (i+1)); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1338 | if (w != null) { |
| 1339 | if (willMove) { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 1340 | if (DEBUG_INPUT_METHOD) { |
| 1341 | RuntimeException e = null; |
| 1342 | if (!HIDE_STACK_CRAWLS) { |
| 1343 | e = new RuntimeException(); |
| 1344 | e.fillInStackTrace(); |
| 1345 | } |
| 1346 | Slog.w(TAG, "Moving IM target from " |
| 1347 | + mInputMethodTarget + " to " + w, e); |
| 1348 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1349 | mInputMethodTarget = w; |
| 1350 | if (w.mAppToken != null) { |
| 1351 | setInputMethodAnimLayerAdjustment(w.mAppToken.animLayerAdjustment); |
| 1352 | } else { |
| 1353 | setInputMethodAnimLayerAdjustment(0); |
| 1354 | } |
| 1355 | } |
| 1356 | return i+1; |
| 1357 | } |
| 1358 | if (willMove) { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 1359 | if (DEBUG_INPUT_METHOD) { |
| 1360 | RuntimeException e = null; |
| 1361 | if (!HIDE_STACK_CRAWLS) { |
| 1362 | e = new RuntimeException(); |
| 1363 | e.fillInStackTrace(); |
| 1364 | } |
| 1365 | Slog.w(TAG, "Moving IM target from " |
| 1366 | + mInputMethodTarget + " to null", e); |
| 1367 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1368 | mInputMethodTarget = null; |
| 1369 | setInputMethodAnimLayerAdjustment(0); |
| 1370 | } |
| 1371 | return -1; |
| 1372 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1373 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1374 | void addInputMethodWindowToListLocked(WindowState win) { |
| 1375 | int pos = findDesiredInputMethodWindowIndexLocked(true); |
| 1376 | if (pos >= 0) { |
| 1377 | win.mTargetAppToken = mInputMethodTarget.mAppToken; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1378 | if (DEBUG_WINDOW_MOVEMENT) Slog.v( |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 1379 | TAG, "Adding input method window " + win + " at " + pos); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1380 | mWindows.add(pos, win); |
| Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 1381 | mWindowsChanged = true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1382 | moveInputMethodDialogsLocked(pos+1); |
| 1383 | return; |
| 1384 | } |
| 1385 | win.mTargetAppToken = null; |
| 1386 | addWindowToListInOrderLocked(win, true); |
| 1387 | moveInputMethodDialogsLocked(pos); |
| 1388 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1389 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1390 | void setInputMethodAnimLayerAdjustment(int adj) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1391 | 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] | 1392 | mInputMethodAnimLayerAdjustment = adj; |
| 1393 | WindowState imw = mInputMethodWindow; |
| 1394 | if (imw != null) { |
| 1395 | imw.mAnimLayer = imw.mLayer + adj; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1396 | if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + imw |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1397 | + " anim layer: " + imw.mAnimLayer); |
| 1398 | int wi = imw.mChildWindows.size(); |
| 1399 | while (wi > 0) { |
| 1400 | wi--; |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1401 | WindowState cw = imw.mChildWindows.get(wi); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1402 | cw.mAnimLayer = cw.mLayer + adj; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1403 | if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + cw |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1404 | + " anim layer: " + cw.mAnimLayer); |
| 1405 | } |
| 1406 | } |
| 1407 | int di = mInputMethodDialogs.size(); |
| 1408 | while (di > 0) { |
| 1409 | di --; |
| 1410 | imw = mInputMethodDialogs.get(di); |
| 1411 | imw.mAnimLayer = imw.mLayer + adj; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1412 | if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + imw |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1413 | + " anim layer: " + imw.mAnimLayer); |
| 1414 | } |
| 1415 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1416 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1417 | private int tmpRemoveWindowLocked(int interestingPos, WindowState win) { |
| 1418 | int wpos = mWindows.indexOf(win); |
| 1419 | if (wpos >= 0) { |
| 1420 | if (wpos < interestingPos) interestingPos--; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1421 | 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] | 1422 | mWindows.remove(wpos); |
| Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 1423 | mWindowsChanged = true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1424 | int NC = win.mChildWindows.size(); |
| 1425 | while (NC > 0) { |
| 1426 | NC--; |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1427 | WindowState cw = win.mChildWindows.get(NC); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1428 | int cpos = mWindows.indexOf(cw); |
| 1429 | if (cpos >= 0) { |
| 1430 | if (cpos < interestingPos) interestingPos--; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1431 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Temp removing child at " |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 1432 | + cpos + ": " + cw); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1433 | mWindows.remove(cpos); |
| 1434 | } |
| 1435 | } |
| 1436 | } |
| 1437 | return interestingPos; |
| 1438 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1439 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1440 | private void reAddWindowToListInOrderLocked(WindowState win) { |
| 1441 | addWindowToListInOrderLocked(win, false); |
| 1442 | // This is a hack to get all of the child windows added as well |
| 1443 | // at the right position. Child windows should be rare and |
| 1444 | // this case should be rare, so it shouldn't be that big a deal. |
| 1445 | int wpos = mWindows.indexOf(win); |
| 1446 | if (wpos >= 0) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1447 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "ReAdd removing from " + wpos |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 1448 | + ": " + win); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1449 | mWindows.remove(wpos); |
| Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 1450 | mWindowsChanged = true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1451 | reAddWindowLocked(wpos, win); |
| 1452 | } |
| 1453 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1454 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1455 | void logWindowList(String prefix) { |
| 1456 | int N = mWindows.size(); |
| 1457 | while (N > 0) { |
| 1458 | N--; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1459 | Slog.v(TAG, prefix + "#" + N + ": " + mWindows.get(N)); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1460 | } |
| 1461 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1462 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1463 | void moveInputMethodDialogsLocked(int pos) { |
| 1464 | ArrayList<WindowState> dialogs = mInputMethodDialogs; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1465 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1466 | final int N = dialogs.size(); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1467 | 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] | 1468 | for (int i=0; i<N; i++) { |
| 1469 | pos = tmpRemoveWindowLocked(pos, dialogs.get(i)); |
| 1470 | } |
| 1471 | if (DEBUG_INPUT_METHOD) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1472 | Slog.v(TAG, "Window list w/pos=" + pos); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1473 | logWindowList(" "); |
| 1474 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1475 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1476 | if (pos >= 0) { |
| 1477 | final AppWindowToken targetAppToken = mInputMethodTarget.mAppToken; |
| 1478 | if (pos < mWindows.size()) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1479 | WindowState wp = mWindows.get(pos); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1480 | if (wp == mInputMethodWindow) { |
| 1481 | pos++; |
| 1482 | } |
| 1483 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1484 | 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] | 1485 | for (int i=0; i<N; i++) { |
| 1486 | WindowState win = dialogs.get(i); |
| 1487 | win.mTargetAppToken = targetAppToken; |
| 1488 | pos = reAddWindowLocked(pos, win); |
| 1489 | } |
| 1490 | if (DEBUG_INPUT_METHOD) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1491 | Slog.v(TAG, "Final window list:"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1492 | logWindowList(" "); |
| 1493 | } |
| 1494 | return; |
| 1495 | } |
| 1496 | for (int i=0; i<N; i++) { |
| 1497 | WindowState win = dialogs.get(i); |
| 1498 | win.mTargetAppToken = null; |
| 1499 | reAddWindowToListInOrderLocked(win); |
| 1500 | if (DEBUG_INPUT_METHOD) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1501 | Slog.v(TAG, "No IM target, final list:"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1502 | logWindowList(" "); |
| 1503 | } |
| 1504 | } |
| 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 | boolean moveInputMethodWindowsIfNeededLocked(boolean needAssignLayers) { |
| 1508 | final WindowState imWin = mInputMethodWindow; |
| 1509 | final int DN = mInputMethodDialogs.size(); |
| 1510 | if (imWin == null && DN == 0) { |
| 1511 | return false; |
| 1512 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1513 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1514 | int imPos = findDesiredInputMethodWindowIndexLocked(true); |
| 1515 | if (imPos >= 0) { |
| 1516 | // In this case, the input method windows are to be placed |
| 1517 | // immediately above the window they are targeting. |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1518 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1519 | // First check to see if the input method windows are already |
| 1520 | // located here, and contiguous. |
| 1521 | final int N = mWindows.size(); |
| 1522 | WindowState firstImWin = imPos < N |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1523 | ? mWindows.get(imPos) : null; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1524 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1525 | // Figure out the actual input method window that should be |
| 1526 | // at the bottom of their stack. |
| 1527 | WindowState baseImWin = imWin != null |
| 1528 | ? imWin : mInputMethodDialogs.get(0); |
| 1529 | if (baseImWin.mChildWindows.size() > 0) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1530 | WindowState cw = baseImWin.mChildWindows.get(0); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1531 | if (cw.mSubLayer < 0) baseImWin = cw; |
| 1532 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1533 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1534 | if (firstImWin == baseImWin) { |
| 1535 | // The windows haven't moved... but are they still contiguous? |
| 1536 | // First find the top IM window. |
| 1537 | int pos = imPos+1; |
| 1538 | while (pos < N) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1539 | if (!(mWindows.get(pos)).mIsImWindow) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1540 | break; |
| 1541 | } |
| 1542 | pos++; |
| 1543 | } |
| 1544 | pos++; |
| 1545 | // Now there should be no more input method windows above. |
| 1546 | while (pos < N) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1547 | if ((mWindows.get(pos)).mIsImWindow) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1548 | break; |
| 1549 | } |
| 1550 | pos++; |
| 1551 | } |
| 1552 | if (pos >= N) { |
| 1553 | // All is good! |
| 1554 | return false; |
| 1555 | } |
| 1556 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1557 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1558 | if (imWin != null) { |
| 1559 | if (DEBUG_INPUT_METHOD) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1560 | Slog.v(TAG, "Moving IM from " + imPos); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1561 | logWindowList(" "); |
| 1562 | } |
| 1563 | imPos = tmpRemoveWindowLocked(imPos, imWin); |
| 1564 | if (DEBUG_INPUT_METHOD) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1565 | 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] | 1566 | logWindowList(" "); |
| 1567 | } |
| 1568 | imWin.mTargetAppToken = mInputMethodTarget.mAppToken; |
| 1569 | reAddWindowLocked(imPos, imWin); |
| 1570 | if (DEBUG_INPUT_METHOD) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1571 | Slog.v(TAG, "List after moving IM to " + imPos + ":"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1572 | logWindowList(" "); |
| 1573 | } |
| 1574 | if (DN > 0) moveInputMethodDialogsLocked(imPos+1); |
| 1575 | } else { |
| 1576 | moveInputMethodDialogsLocked(imPos); |
| 1577 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1578 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1579 | } else { |
| 1580 | // In this case, the input method windows go in a fixed layer, |
| 1581 | // because they aren't currently associated with a focus window. |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1582 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1583 | if (imWin != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1584 | 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] | 1585 | tmpRemoveWindowLocked(0, imWin); |
| 1586 | imWin.mTargetAppToken = null; |
| 1587 | reAddWindowToListInOrderLocked(imWin); |
| 1588 | if (DEBUG_INPUT_METHOD) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1589 | Slog.v(TAG, "List with no IM target:"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1590 | logWindowList(" "); |
| 1591 | } |
| 1592 | if (DN > 0) moveInputMethodDialogsLocked(-1);; |
| 1593 | } else { |
| 1594 | moveInputMethodDialogsLocked(-1);; |
| 1595 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1596 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1597 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1598 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1599 | if (needAssignLayers) { |
| 1600 | assignLayersLocked(); |
| 1601 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1602 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1603 | return true; |
| 1604 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1605 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1606 | void adjustInputMethodDialogsLocked() { |
| 1607 | moveInputMethodDialogsLocked(findDesiredInputMethodWindowIndexLocked(true)); |
| 1608 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1609 | |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 1610 | final boolean isWallpaperVisible(WindowState wallpaperTarget) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1611 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper vis: target obscured=" |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 1612 | + (wallpaperTarget != null ? Boolean.toString(wallpaperTarget.mObscured) : "??") |
| 1613 | + " anim=" + ((wallpaperTarget != null && wallpaperTarget.mAppToken != null) |
| 1614 | ? wallpaperTarget.mAppToken.animation : null) |
| 1615 | + " upper=" + mUpperWallpaperTarget |
| 1616 | + " lower=" + mLowerWallpaperTarget); |
| 1617 | return (wallpaperTarget != null |
| 1618 | && (!wallpaperTarget.mObscured || (wallpaperTarget.mAppToken != null |
| 1619 | && wallpaperTarget.mAppToken.animation != null))) |
| 1620 | || mUpperWallpaperTarget != null |
| 1621 | || mLowerWallpaperTarget != null; |
| 1622 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1623 | |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 1624 | static final int ADJUST_WALLPAPER_LAYERS_CHANGED = 1<<1; |
| 1625 | static final int ADJUST_WALLPAPER_VISIBILITY_CHANGED = 1<<2; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1626 | |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 1627 | int adjustWallpaperWindowsLocked() { |
| 1628 | int changed = 0; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1629 | |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1630 | final int dw = mDisplay.getWidth(); |
| 1631 | final int dh = mDisplay.getHeight(); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1632 | |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1633 | // First find top-most window that has asked to be on top of the |
| 1634 | // wallpaper; all wallpapers go behind it. |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1635 | final ArrayList<WindowState> localmWindows = mWindows; |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1636 | int N = localmWindows.size(); |
| 1637 | WindowState w = null; |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1638 | WindowState foundW = null; |
| 1639 | int foundI = 0; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1640 | WindowState topCurW = null; |
| 1641 | int topCurI = 0; |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1642 | int i = N; |
| 1643 | while (i > 0) { |
| 1644 | i--; |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1645 | w = localmWindows.get(i); |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1646 | if ((w.mAttrs.type == WindowManager.LayoutParams.TYPE_WALLPAPER)) { |
| 1647 | if (topCurW == null) { |
| 1648 | topCurW = w; |
| 1649 | topCurI = i; |
| 1650 | } |
| 1651 | continue; |
| 1652 | } |
| 1653 | topCurW = null; |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1654 | if (w.mAppToken != null) { |
| 1655 | // If this window's app token is hidden and not animating, |
| 1656 | // it is of no interest to us. |
| 1657 | if (w.mAppToken.hidden && w.mAppToken.animation == null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1658 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1659 | "Skipping hidden or animating token: " + w); |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1660 | topCurW = null; |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1661 | continue; |
| 1662 | } |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1663 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1664 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Win " + w + ": readyfordisplay=" |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1665 | + w.isReadyForDisplay() + " drawpending=" + w.mDrawPending |
| 1666 | + " commitdrawpending=" + w.mCommitDrawPending); |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1667 | if ((w.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0 && w.isReadyForDisplay() |
| Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 1668 | && (mWallpaperTarget == w |
| 1669 | || (!w.mDrawPending && !w.mCommitDrawPending))) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1670 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1671 | "Found wallpaper activity: #" + i + "=" + w); |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1672 | foundW = w; |
| 1673 | foundI = i; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1674 | if (w == mWallpaperTarget && ((w.mAppToken != null |
| 1675 | && w.mAppToken.animation != null) |
| 1676 | || w.mAnimation != null)) { |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1677 | // The current wallpaper target is animating, so we'll |
| 1678 | // look behind it for another possible target and figure |
| 1679 | // out what is going on below. |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1680 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Win " + w |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1681 | + ": token animating, looking behind."); |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1682 | continue; |
| 1683 | } |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1684 | break; |
| 1685 | } |
| 1686 | } |
| 1687 | |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 1688 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1689 | // If we are currently waiting for an app transition, and either |
| 1690 | // the current target or the next target are involved with it, |
| 1691 | // then hold off on doing anything with the wallpaper. |
| 1692 | // Note that we are checking here for just whether the target |
| 1693 | // is part of an app token... which is potentially overly aggressive |
| 1694 | // (the app token may not be involved in the transition), but good |
| 1695 | // enough (we'll just wait until whatever transition is pending |
| 1696 | // executes). |
| 1697 | if (mWallpaperTarget != null && mWallpaperTarget.mAppToken != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1698 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1699 | "Wallpaper not changing: waiting for app anim in current target"); |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 1700 | return 0; |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1701 | } |
| 1702 | if (foundW != null && foundW.mAppToken != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1703 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1704 | "Wallpaper not changing: waiting for app anim in found target"); |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 1705 | return 0; |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1706 | } |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1707 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1708 | |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1709 | if (mWallpaperTarget != foundW) { |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1710 | if (DEBUG_WALLPAPER) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1711 | Slog.v(TAG, "New wallpaper target: " + foundW |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1712 | + " oldTarget: " + mWallpaperTarget); |
| 1713 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1714 | |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1715 | mLowerWallpaperTarget = null; |
| 1716 | mUpperWallpaperTarget = null; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1717 | |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1718 | WindowState oldW = mWallpaperTarget; |
| 1719 | mWallpaperTarget = foundW; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1720 | |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1721 | // Now what is happening... if the current and new targets are |
| 1722 | // animating, then we are in our super special mode! |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1723 | if (foundW != null && oldW != null) { |
| 1724 | boolean oldAnim = oldW.mAnimation != null |
| 1725 | || (oldW.mAppToken != null && oldW.mAppToken.animation != null); |
| 1726 | boolean foundAnim = foundW.mAnimation != null |
| 1727 | || (foundW.mAppToken != null && foundW.mAppToken.animation != null); |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1728 | if (DEBUG_WALLPAPER) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1729 | Slog.v(TAG, "New animation: " + foundAnim |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1730 | + " old animation: " + oldAnim); |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1731 | } |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1732 | if (foundAnim && oldAnim) { |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1733 | int oldI = localmWindows.indexOf(oldW); |
| 1734 | if (DEBUG_WALLPAPER) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1735 | Slog.v(TAG, "New i: " + foundI + " old i: " + oldI); |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1736 | } |
| 1737 | if (oldI >= 0) { |
| 1738 | if (DEBUG_WALLPAPER) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1739 | Slog.v(TAG, "Animating wallpapers: old#" + oldI |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1740 | + "=" + oldW + "; new#" + foundI |
| 1741 | + "=" + foundW); |
| 1742 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1743 | |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1744 | // Set the new target correctly. |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1745 | if (foundW.mAppToken != null && foundW.mAppToken.hiddenRequested) { |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1746 | if (DEBUG_WALLPAPER) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1747 | Slog.v(TAG, "Old wallpaper still the target."); |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1748 | } |
| 1749 | mWallpaperTarget = oldW; |
| 1750 | } |
| 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 set the upper and lower wallpaper targets |
| 1753 | // correctly, and make sure that we are positioning |
| 1754 | // the wallpaper below the lower. |
| 1755 | if (foundI > oldI) { |
| 1756 | // The new target is on top of the old one. |
| 1757 | if (DEBUG_WALLPAPER) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1758 | Slog.v(TAG, "Found target above old target."); |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1759 | } |
| 1760 | mUpperWallpaperTarget = foundW; |
| 1761 | mLowerWallpaperTarget = oldW; |
| 1762 | foundW = oldW; |
| 1763 | foundI = oldI; |
| 1764 | } else { |
| 1765 | // The new target is below the old one. |
| 1766 | if (DEBUG_WALLPAPER) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1767 | Slog.v(TAG, "Found target below old target."); |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1768 | } |
| 1769 | mUpperWallpaperTarget = oldW; |
| 1770 | mLowerWallpaperTarget = foundW; |
| 1771 | } |
| 1772 | } |
| 1773 | } |
| 1774 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1775 | |
| Dianne Hackborn | 6b1cb35 | 2009-09-28 18:27:26 -0700 | [diff] [blame] | 1776 | } else if (mLowerWallpaperTarget != null) { |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1777 | // Is it time to stop animating? |
| Dianne Hackborn | 6b1cb35 | 2009-09-28 18:27:26 -0700 | [diff] [blame] | 1778 | boolean lowerAnimating = mLowerWallpaperTarget.mAnimation != null |
| 1779 | || (mLowerWallpaperTarget.mAppToken != null |
| 1780 | && mLowerWallpaperTarget.mAppToken.animation != null); |
| 1781 | boolean upperAnimating = mUpperWallpaperTarget.mAnimation != null |
| 1782 | || (mUpperWallpaperTarget.mAppToken != null |
| 1783 | && mUpperWallpaperTarget.mAppToken.animation != null); |
| 1784 | if (!lowerAnimating || !upperAnimating) { |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1785 | if (DEBUG_WALLPAPER) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1786 | Slog.v(TAG, "No longer animating wallpaper targets!"); |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1787 | } |
| 1788 | mLowerWallpaperTarget = null; |
| 1789 | mUpperWallpaperTarget = null; |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1790 | } |
| 1791 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1792 | |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1793 | boolean visible = foundW != null; |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 1794 | if (visible) { |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1795 | // The window is visible to the compositor... but is it visible |
| 1796 | // to the user? That is what the wallpaper cares about. |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 1797 | visible = isWallpaperVisible(foundW); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1798 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper visibility: " + visible); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1799 | |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1800 | // If the wallpaper target is animating, we may need to copy |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1801 | // its layer adjustment. Only do this if we are not transfering |
| 1802 | // between two wallpaper targets. |
| 1803 | mWallpaperAnimLayerAdjustment = |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1804 | (mLowerWallpaperTarget == null && foundW.mAppToken != null) |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1805 | ? foundW.mAppToken.animLayerAdjustment : 0; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1806 | |
| Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 1807 | final int maxLayer = mPolicy.getMaxWallpaperLayer() |
| 1808 | * TYPE_LAYER_MULTIPLIER |
| 1809 | + TYPE_LAYER_OFFSET; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1810 | |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1811 | // Now w is the window we are supposed to be behind... but we |
| 1812 | // 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] | 1813 | // AND any starting window associated with it, AND below the |
| 1814 | // maximum layer the policy allows for wallpapers. |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1815 | while (foundI > 0) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1816 | WindowState wb = localmWindows.get(foundI-1); |
| Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 1817 | if (wb.mBaseLayer < maxLayer && |
| 1818 | wb.mAttachedWindow != foundW && |
| Pal Szasz | 73dc259 | 2010-09-03 11:46:26 +0200 | [diff] [blame] | 1819 | wb.mAttachedWindow != foundW.mAttachedWindow && |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1820 | (wb.mAttrs.type != TYPE_APPLICATION_STARTING || |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1821 | wb.mToken != foundW.mToken)) { |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1822 | // This window is not related to the previous one in any |
| 1823 | // interesting way, so stop here. |
| 1824 | break; |
| 1825 | } |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1826 | foundW = wb; |
| 1827 | foundI--; |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1828 | } |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 1829 | } else { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1830 | if (DEBUG_WALLPAPER) Slog.v(TAG, "No wallpaper target"); |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1831 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1832 | |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1833 | if (foundW == null && topCurW != null) { |
| 1834 | // There is no wallpaper target, so it goes at the bottom. |
| 1835 | // We will assume it is the same place as last time, if known. |
| 1836 | foundW = topCurW; |
| 1837 | foundI = topCurI+1; |
| 1838 | } else { |
| 1839 | // Okay i is the position immediately above the wallpaper. Look at |
| 1840 | // what is below it for later. |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1841 | foundW = foundI > 0 ? localmWindows.get(foundI-1) : null; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1842 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1843 | |
| Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 1844 | if (visible) { |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1845 | if (mWallpaperTarget.mWallpaperX >= 0) { |
| 1846 | mLastWallpaperX = mWallpaperTarget.mWallpaperX; |
| Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 1847 | mLastWallpaperXStep = mWallpaperTarget.mWallpaperXStep; |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1848 | } |
| 1849 | if (mWallpaperTarget.mWallpaperY >= 0) { |
| 1850 | mLastWallpaperY = mWallpaperTarget.mWallpaperY; |
| Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 1851 | mLastWallpaperYStep = mWallpaperTarget.mWallpaperYStep; |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1852 | } |
| Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 1853 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1854 | |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1855 | // Start stepping backwards from here, ensuring that our wallpaper windows |
| 1856 | // are correctly placed. |
| 1857 | int curTokenIndex = mWallpaperTokens.size(); |
| 1858 | while (curTokenIndex > 0) { |
| 1859 | curTokenIndex--; |
| 1860 | WindowToken token = mWallpaperTokens.get(curTokenIndex); |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 1861 | if (token.hidden == visible) { |
| 1862 | changed |= ADJUST_WALLPAPER_VISIBILITY_CHANGED; |
| 1863 | token.hidden = !visible; |
| 1864 | // Need to do a layout to ensure the wallpaper now has the |
| 1865 | // correct size. |
| 1866 | mLayoutNeeded = true; |
| 1867 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1868 | |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1869 | int curWallpaperIndex = token.windows.size(); |
| 1870 | while (curWallpaperIndex > 0) { |
| 1871 | curWallpaperIndex--; |
| 1872 | WindowState wallpaper = token.windows.get(curWallpaperIndex); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1873 | |
| Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 1874 | if (visible) { |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1875 | updateWallpaperOffsetLocked(wallpaper, dw, dh, false); |
| Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 1876 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1877 | |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 1878 | // First, make sure the client has the current visibility |
| 1879 | // state. |
| 1880 | if (wallpaper.mWallpaperVisible != visible) { |
| 1881 | wallpaper.mWallpaperVisible = visible; |
| 1882 | try { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1883 | if (DEBUG_VISIBILITY || DEBUG_WALLPAPER) Slog.v(TAG, |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 1884 | "Setting visibility of wallpaper " + wallpaper |
| 1885 | + ": " + visible); |
| 1886 | wallpaper.mClient.dispatchAppVisibility(visible); |
| 1887 | } catch (RemoteException e) { |
| 1888 | } |
| 1889 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1890 | |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 1891 | wallpaper.mAnimLayer = wallpaper.mLayer + mWallpaperAnimLayerAdjustment; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1892 | if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper win " |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1893 | + wallpaper + " anim layer: " + wallpaper.mAnimLayer); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1894 | |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1895 | // First, if this window is at the current index, then all |
| 1896 | // is well. |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1897 | if (wallpaper == foundW) { |
| 1898 | foundI--; |
| 1899 | foundW = foundI > 0 |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1900 | ? localmWindows.get(foundI-1) : null; |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1901 | continue; |
| 1902 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1903 | |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1904 | // The window didn't match... the current wallpaper window, |
| 1905 | // wherever it is, is in the wrong place, so make sure it is |
| 1906 | // not in the list. |
| 1907 | int oldIndex = localmWindows.indexOf(wallpaper); |
| 1908 | if (oldIndex >= 0) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1909 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Wallpaper removing at " |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 1910 | + oldIndex + ": " + wallpaper); |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1911 | localmWindows.remove(oldIndex); |
| Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 1912 | mWindowsChanged = true; |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1913 | if (oldIndex < foundI) { |
| 1914 | foundI--; |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1915 | } |
| 1916 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1917 | |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1918 | // Now stick it in. |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1919 | if (DEBUG_WALLPAPER || DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 1920 | "Moving wallpaper " + wallpaper |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1921 | + " from " + oldIndex + " to " + foundI); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1922 | |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1923 | localmWindows.add(foundI, wallpaper); |
| Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 1924 | mWindowsChanged = true; |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 1925 | changed |= ADJUST_WALLPAPER_LAYERS_CHANGED; |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1926 | } |
| 1927 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1928 | |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1929 | return changed; |
| 1930 | } |
| 1931 | |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 1932 | void setWallpaperAnimLayerAdjustmentLocked(int adj) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1933 | if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG, |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1934 | "Setting wallpaper layer adj to " + adj); |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 1935 | mWallpaperAnimLayerAdjustment = adj; |
| 1936 | int curTokenIndex = mWallpaperTokens.size(); |
| 1937 | while (curTokenIndex > 0) { |
| 1938 | curTokenIndex--; |
| 1939 | WindowToken token = mWallpaperTokens.get(curTokenIndex); |
| 1940 | int curWallpaperIndex = token.windows.size(); |
| 1941 | while (curWallpaperIndex > 0) { |
| 1942 | curWallpaperIndex--; |
| 1943 | WindowState wallpaper = token.windows.get(curWallpaperIndex); |
| 1944 | wallpaper.mAnimLayer = wallpaper.mLayer + adj; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1945 | if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper win " |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1946 | + wallpaper + " anim layer: " + wallpaper.mAnimLayer); |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 1947 | } |
| 1948 | } |
| 1949 | } |
| 1950 | |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1951 | boolean updateWallpaperOffsetLocked(WindowState wallpaperWin, int dw, int dh, |
| 1952 | boolean sync) { |
| Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 1953 | boolean changed = false; |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1954 | boolean rawChanged = false; |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1955 | float wpx = mLastWallpaperX >= 0 ? mLastWallpaperX : 0.5f; |
| Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 1956 | float wpxs = mLastWallpaperXStep >= 0 ? mLastWallpaperXStep : -1.0f; |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1957 | int availw = wallpaperWin.mFrame.right-wallpaperWin.mFrame.left-dw; |
| 1958 | int offset = availw > 0 ? -(int)(availw*wpx+.5f) : 0; |
| 1959 | changed = wallpaperWin.mXOffset != offset; |
| 1960 | if (changed) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1961 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Update wallpaper " |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1962 | + wallpaperWin + " x: " + offset); |
| 1963 | wallpaperWin.mXOffset = offset; |
| 1964 | } |
| Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 1965 | if (wallpaperWin.mWallpaperX != wpx || wallpaperWin.mWallpaperXStep != wpxs) { |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1966 | wallpaperWin.mWallpaperX = wpx; |
| Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 1967 | wallpaperWin.mWallpaperXStep = wpxs; |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1968 | rawChanged = true; |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 1969 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1970 | |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1971 | float wpy = mLastWallpaperY >= 0 ? mLastWallpaperY : 0.5f; |
| Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 1972 | float wpys = mLastWallpaperYStep >= 0 ? mLastWallpaperYStep : -1.0f; |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1973 | int availh = wallpaperWin.mFrame.bottom-wallpaperWin.mFrame.top-dh; |
| 1974 | offset = availh > 0 ? -(int)(availh*wpy+.5f) : 0; |
| 1975 | if (wallpaperWin.mYOffset != offset) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1976 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Update wallpaper " |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1977 | + wallpaperWin + " y: " + offset); |
| 1978 | changed = true; |
| 1979 | wallpaperWin.mYOffset = offset; |
| 1980 | } |
| Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 1981 | if (wallpaperWin.mWallpaperY != wpy || wallpaperWin.mWallpaperYStep != wpys) { |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1982 | wallpaperWin.mWallpaperY = wpy; |
| Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 1983 | wallpaperWin.mWallpaperYStep = wpys; |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1984 | rawChanged = true; |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 1985 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1986 | |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1987 | if (rawChanged) { |
| Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 1988 | try { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1989 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Report new wp offset " |
| Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 1990 | + wallpaperWin + " x=" + wallpaperWin.mWallpaperX |
| 1991 | + " y=" + wallpaperWin.mWallpaperY); |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1992 | if (sync) { |
| Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 1993 | mWaitingOnWallpaper = wallpaperWin; |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1994 | } |
| Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 1995 | wallpaperWin.mClient.dispatchWallpaperOffsets( |
| Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 1996 | wallpaperWin.mWallpaperX, wallpaperWin.mWallpaperY, |
| 1997 | wallpaperWin.mWallpaperXStep, wallpaperWin.mWallpaperYStep, sync); |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1998 | if (sync) { |
| Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 1999 | if (mWaitingOnWallpaper != null) { |
| 2000 | long start = SystemClock.uptimeMillis(); |
| 2001 | if ((mLastWallpaperTimeoutTime+WALLPAPER_TIMEOUT_RECOVERY) |
| 2002 | < start) { |
| 2003 | try { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2004 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
| Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 2005 | "Waiting for offset complete..."); |
| 2006 | mWindowMap.wait(WALLPAPER_TIMEOUT); |
| 2007 | } catch (InterruptedException e) { |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 2008 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2009 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Offset complete!"); |
| Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 2010 | if ((start+WALLPAPER_TIMEOUT) |
| 2011 | < SystemClock.uptimeMillis()) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2012 | Slog.i(TAG, "Timeout waiting for wallpaper to offset: " |
| Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 2013 | + wallpaperWin); |
| 2014 | mLastWallpaperTimeoutTime = start; |
| 2015 | } |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 2016 | } |
| Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 2017 | mWaitingOnWallpaper = null; |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 2018 | } |
| 2019 | } |
| Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 2020 | } catch (RemoteException e) { |
| 2021 | } |
| 2022 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2023 | |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 2024 | return changed; |
| 2025 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2026 | |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 2027 | void wallpaperOffsetsComplete(IBinder window) { |
| Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 2028 | synchronized (mWindowMap) { |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 2029 | if (mWaitingOnWallpaper != null && |
| 2030 | mWaitingOnWallpaper.mClient.asBinder() == window) { |
| 2031 | mWaitingOnWallpaper = null; |
| Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 2032 | mWindowMap.notifyAll(); |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 2033 | } |
| 2034 | } |
| 2035 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2036 | |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 2037 | boolean updateWallpaperOffsetLocked(WindowState changingTarget, boolean sync) { |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 2038 | final int dw = mDisplay.getWidth(); |
| 2039 | final int dh = mDisplay.getHeight(); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2040 | |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 2041 | boolean changed = false; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2042 | |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 2043 | WindowState target = mWallpaperTarget; |
| 2044 | if (target != null) { |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 2045 | if (target.mWallpaperX >= 0) { |
| 2046 | mLastWallpaperX = target.mWallpaperX; |
| 2047 | } else if (changingTarget.mWallpaperX >= 0) { |
| 2048 | mLastWallpaperX = changingTarget.mWallpaperX; |
| 2049 | } |
| 2050 | if (target.mWallpaperY >= 0) { |
| 2051 | mLastWallpaperY = target.mWallpaperY; |
| 2052 | } else if (changingTarget.mWallpaperY >= 0) { |
| 2053 | mLastWallpaperY = changingTarget.mWallpaperY; |
| 2054 | } |
| 2055 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2056 | |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 2057 | int curTokenIndex = mWallpaperTokens.size(); |
| 2058 | while (curTokenIndex > 0) { |
| 2059 | curTokenIndex--; |
| 2060 | WindowToken token = mWallpaperTokens.get(curTokenIndex); |
| 2061 | int curWallpaperIndex = token.windows.size(); |
| 2062 | while (curWallpaperIndex > 0) { |
| 2063 | curWallpaperIndex--; |
| 2064 | WindowState wallpaper = token.windows.get(curWallpaperIndex); |
| 2065 | if (updateWallpaperOffsetLocked(wallpaper, dw, dh, sync)) { |
| 2066 | wallpaper.computeShownFrameLocked(); |
| 2067 | changed = true; |
| 2068 | // We only want to be synchronous with one wallpaper. |
| 2069 | sync = false; |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 2070 | } |
| 2071 | } |
| 2072 | } |
| 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 | return changed; |
| 2075 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2076 | |
| Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 2077 | void updateWallpaperVisibilityLocked() { |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 2078 | final boolean visible = isWallpaperVisible(mWallpaperTarget); |
| Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 2079 | final int dw = mDisplay.getWidth(); |
| 2080 | final int dh = mDisplay.getHeight(); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2081 | |
| Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 2082 | int curTokenIndex = mWallpaperTokens.size(); |
| 2083 | while (curTokenIndex > 0) { |
| 2084 | curTokenIndex--; |
| 2085 | WindowToken token = mWallpaperTokens.get(curTokenIndex); |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 2086 | if (token.hidden == visible) { |
| 2087 | token.hidden = !visible; |
| 2088 | // Need to do a layout to ensure the wallpaper now has the |
| 2089 | // correct size. |
| 2090 | mLayoutNeeded = true; |
| 2091 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2092 | |
| Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 2093 | int curWallpaperIndex = token.windows.size(); |
| 2094 | while (curWallpaperIndex > 0) { |
| 2095 | curWallpaperIndex--; |
| 2096 | WindowState wallpaper = token.windows.get(curWallpaperIndex); |
| 2097 | if (visible) { |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 2098 | updateWallpaperOffsetLocked(wallpaper, dw, dh, false); |
| Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 2099 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2100 | |
| Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 2101 | if (wallpaper.mWallpaperVisible != visible) { |
| 2102 | wallpaper.mWallpaperVisible = visible; |
| 2103 | try { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2104 | if (DEBUG_VISIBILITY || DEBUG_WALLPAPER) Slog.v(TAG, |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 2105 | "Updating visibility of wallpaper " + wallpaper |
| Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 2106 | + ": " + visible); |
| 2107 | wallpaper.mClient.dispatchAppVisibility(visible); |
| 2108 | } catch (RemoteException e) { |
| 2109 | } |
| 2110 | } |
| 2111 | } |
| 2112 | } |
| 2113 | } |
| Dianne Hackborn | 90d2db3 | 2010-02-11 22:19:06 -0800 | [diff] [blame] | 2114 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2115 | public int addWindow(Session session, IWindow client, |
| 2116 | WindowManager.LayoutParams attrs, int viewVisibility, |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 2117 | Rect outContentInsets, InputChannel outInputChannel) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2118 | int res = mPolicy.checkAddPermission(attrs); |
| 2119 | if (res != WindowManagerImpl.ADD_OKAY) { |
| 2120 | return res; |
| 2121 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2122 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2123 | boolean reportNewConfig = false; |
| 2124 | WindowState attachedWindow = null; |
| 2125 | WindowState win = null; |
| Dianne Hackborn | 5132b37 | 2010-07-29 12:51:35 -0700 | [diff] [blame] | 2126 | long origId; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2127 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2128 | synchronized(mWindowMap) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2129 | if (mDisplay == null) { |
| Dianne Hackborn | 5132b37 | 2010-07-29 12:51:35 -0700 | [diff] [blame] | 2130 | throw new IllegalStateException("Display has not been initialialized"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2131 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2132 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2133 | if (mWindowMap.containsKey(client.asBinder())) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2134 | Slog.w(TAG, "Window " + client + " is already added"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2135 | return WindowManagerImpl.ADD_DUPLICATE_ADD; |
| 2136 | } |
| 2137 | |
| 2138 | if (attrs.type >= FIRST_SUB_WINDOW && attrs.type <= LAST_SUB_WINDOW) { |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2139 | attachedWindow = windowForClientLocked(null, attrs.token, false); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2140 | if (attachedWindow == null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2141 | 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] | 2142 | + attrs.token + ". Aborting."); |
| 2143 | return WindowManagerImpl.ADD_BAD_SUBWINDOW_TOKEN; |
| 2144 | } |
| 2145 | if (attachedWindow.mAttrs.type >= FIRST_SUB_WINDOW |
| 2146 | && attachedWindow.mAttrs.type <= LAST_SUB_WINDOW) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2147 | 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] | 2148 | + attrs.token + ". Aborting."); |
| 2149 | return WindowManagerImpl.ADD_BAD_SUBWINDOW_TOKEN; |
| 2150 | } |
| 2151 | } |
| 2152 | |
| 2153 | boolean addToken = false; |
| 2154 | WindowToken token = mTokenMap.get(attrs.token); |
| 2155 | if (token == null) { |
| 2156 | if (attrs.type >= FIRST_APPLICATION_WINDOW |
| 2157 | && attrs.type <= LAST_APPLICATION_WINDOW) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2158 | 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] | 2159 | + attrs.token + ". Aborting."); |
| 2160 | return WindowManagerImpl.ADD_BAD_APP_TOKEN; |
| 2161 | } |
| 2162 | if (attrs.type == TYPE_INPUT_METHOD) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2163 | 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] | 2164 | + attrs.token + ". Aborting."); |
| 2165 | return WindowManagerImpl.ADD_BAD_APP_TOKEN; |
| 2166 | } |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2167 | if (attrs.type == TYPE_WALLPAPER) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2168 | Slog.w(TAG, "Attempted to add wallpaper window with unknown token " |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2169 | + attrs.token + ". Aborting."); |
| 2170 | return WindowManagerImpl.ADD_BAD_APP_TOKEN; |
| 2171 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2172 | token = new WindowToken(attrs.token, -1, false); |
| 2173 | addToken = true; |
| 2174 | } else if (attrs.type >= FIRST_APPLICATION_WINDOW |
| 2175 | && attrs.type <= LAST_APPLICATION_WINDOW) { |
| 2176 | AppWindowToken atoken = token.appWindowToken; |
| 2177 | if (atoken == null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2178 | 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] | 2179 | + token + ". Aborting."); |
| 2180 | return WindowManagerImpl.ADD_NOT_APP_TOKEN; |
| 2181 | } else if (atoken.removed) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2182 | 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] | 2183 | + token + ". Aborting."); |
| 2184 | return WindowManagerImpl.ADD_APP_EXITING; |
| 2185 | } |
| 2186 | if (attrs.type == TYPE_APPLICATION_STARTING && atoken.firstWindowDrawn) { |
| 2187 | // No need for this guy! |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2188 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2189 | TAG, "**** NO NEED TO START: " + attrs.getTitle()); |
| 2190 | return WindowManagerImpl.ADD_STARTING_NOT_NEEDED; |
| 2191 | } |
| 2192 | } else if (attrs.type == TYPE_INPUT_METHOD) { |
| 2193 | if (token.windowType != 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 bad 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 | } else if (attrs.type == TYPE_WALLPAPER) { |
| 2199 | if (token.windowType != TYPE_WALLPAPER) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2200 | Slog.w(TAG, "Attempted to add wallpaper window with bad token " |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2201 | + attrs.token + ". Aborting."); |
| 2202 | return WindowManagerImpl.ADD_BAD_APP_TOKEN; |
| 2203 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2204 | } |
| 2205 | |
| 2206 | win = new WindowState(session, client, token, |
| 2207 | attachedWindow, attrs, viewVisibility); |
| 2208 | if (win.mDeathRecipient == null) { |
| 2209 | // Client has apparently died, so there is no reason to |
| 2210 | // continue. |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2211 | Slog.w(TAG, "Adding window client " + client.asBinder() |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2212 | + " that is dead, aborting."); |
| 2213 | return WindowManagerImpl.ADD_APP_EXITING; |
| 2214 | } |
| 2215 | |
| 2216 | mPolicy.adjustWindowParamsLw(win.mAttrs); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2217 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2218 | res = mPolicy.prepareAddWindowLw(win, attrs); |
| 2219 | if (res != WindowManagerImpl.ADD_OKAY) { |
| 2220 | return res; |
| 2221 | } |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 2222 | |
| Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 2223 | if (outInputChannel != null) { |
| 2224 | String name = win.makeInputChannelName(); |
| 2225 | InputChannel[] inputChannels = InputChannel.openInputChannelPair(name); |
| 2226 | win.mInputChannel = inputChannels[0]; |
| 2227 | inputChannels[1].transferToBinderOutParameter(outInputChannel); |
| 2228 | |
| 2229 | mInputManager.registerInputChannel(win.mInputChannel); |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 2230 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2231 | |
| 2232 | // From now on, no exceptions or errors allowed! |
| 2233 | |
| 2234 | res = WindowManagerImpl.ADD_OKAY; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2235 | |
| Dianne Hackborn | 5132b37 | 2010-07-29 12:51:35 -0700 | [diff] [blame] | 2236 | origId = Binder.clearCallingIdentity(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2237 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2238 | if (addToken) { |
| 2239 | mTokenMap.put(attrs.token, token); |
| 2240 | mTokenList.add(token); |
| 2241 | } |
| 2242 | win.attach(); |
| 2243 | mWindowMap.put(client.asBinder(), win); |
| 2244 | |
| 2245 | if (attrs.type == TYPE_APPLICATION_STARTING && |
| 2246 | token.appWindowToken != null) { |
| 2247 | token.appWindowToken.startingWindow = win; |
| 2248 | } |
| 2249 | |
| 2250 | boolean imMayMove = true; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2251 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2252 | if (attrs.type == TYPE_INPUT_METHOD) { |
| 2253 | mInputMethodWindow = win; |
| 2254 | addInputMethodWindowToListLocked(win); |
| 2255 | imMayMove = false; |
| 2256 | } else if (attrs.type == TYPE_INPUT_METHOD_DIALOG) { |
| 2257 | mInputMethodDialogs.add(win); |
| 2258 | addWindowToListInOrderLocked(win, true); |
| 2259 | adjustInputMethodDialogsLocked(); |
| 2260 | imMayMove = false; |
| 2261 | } else { |
| 2262 | addWindowToListInOrderLocked(win, true); |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 2263 | if (attrs.type == TYPE_WALLPAPER) { |
| 2264 | mLastWallpaperTimeoutTime = 0; |
| 2265 | adjustWallpaperWindowsLocked(); |
| 2266 | } else if ((attrs.flags&FLAG_SHOW_WALLPAPER) != 0) { |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2267 | adjustWallpaperWindowsLocked(); |
| 2268 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2269 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2270 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2271 | win.mEnterAnimationPending = true; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2272 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2273 | mPolicy.getContentInsetHintLw(attrs, outContentInsets); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2274 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2275 | if (mInTouchMode) { |
| 2276 | res |= WindowManagerImpl.ADD_FLAG_IN_TOUCH_MODE; |
| 2277 | } |
| 2278 | if (win == null || win.mAppToken == null || !win.mAppToken.clientHidden) { |
| 2279 | res |= WindowManagerImpl.ADD_FLAG_APP_VISIBLE; |
| 2280 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2281 | |
| The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 2282 | boolean focusChanged = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2283 | if (win.canReceiveKeys()) { |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 2284 | focusChanged = updateFocusedWindowLocked(UPDATE_FOCUS_WILL_ASSIGN_LAYERS); |
| 2285 | if (focusChanged) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2286 | imMayMove = false; |
| 2287 | } |
| 2288 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2289 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2290 | if (imMayMove) { |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2291 | moveInputMethodWindowsIfNeededLocked(false); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2292 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2293 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2294 | assignLayersLocked(); |
| 2295 | // Don't do layout here, the window must call |
| 2296 | // relayout to be displayed, so we'll do it there. |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2297 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2298 | //dump(); |
| 2299 | |
| The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 2300 | if (focusChanged) { |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 2301 | finishUpdateFocusedWindowAfterAssignLayersLocked(); |
| The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 2302 | } |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 2303 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2304 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2305 | TAG, "New client " + client.asBinder() |
| 2306 | + ": window=" + win); |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2307 | |
| 2308 | if (win.isVisibleOrAdding() && updateOrientationFromAppTokensLocked()) { |
| 2309 | reportNewConfig = true; |
| 2310 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2311 | } |
| 2312 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2313 | if (reportNewConfig) { |
| 2314 | sendNewConfiguration(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2315 | } |
| Dianne Hackborn | 5132b37 | 2010-07-29 12:51:35 -0700 | [diff] [blame] | 2316 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2317 | Binder.restoreCallingIdentity(origId); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2318 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2319 | return res; |
| 2320 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2321 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2322 | public void removeWindow(Session session, IWindow client) { |
| 2323 | synchronized(mWindowMap) { |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2324 | WindowState win = windowForClientLocked(session, client, false); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2325 | if (win == null) { |
| 2326 | return; |
| 2327 | } |
| 2328 | removeWindowLocked(session, win); |
| 2329 | } |
| 2330 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2331 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2332 | public void removeWindowLocked(Session session, WindowState win) { |
| 2333 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2334 | if (localLOGV || DEBUG_FOCUS) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2335 | TAG, "Remove " + win + " client=" |
| 2336 | + Integer.toHexString(System.identityHashCode( |
| 2337 | win.mClient.asBinder())) |
| 2338 | + ", surface=" + win.mSurface); |
| 2339 | |
| 2340 | final long origId = Binder.clearCallingIdentity(); |
| Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 2341 | |
| 2342 | win.disposeInputChannel(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2343 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2344 | if (DEBUG_APP_TRANSITIONS) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2345 | TAG, "Remove " + win + ": mSurface=" + win.mSurface |
| 2346 | + " mExiting=" + win.mExiting |
| 2347 | + " isAnimating=" + win.isAnimating() |
| 2348 | + " app-animation=" |
| 2349 | + (win.mAppToken != null ? win.mAppToken.animation : null) |
| 2350 | + " inPendingTransaction=" |
| 2351 | + (win.mAppToken != null ? win.mAppToken.inPendingTransaction : false) |
| 2352 | + " mDisplayFrozen=" + mDisplayFrozen); |
| 2353 | // Visibility of the removed window. Will be used later to update orientation later on. |
| 2354 | boolean wasVisible = false; |
| 2355 | // First, see if we need to run an animation. If we do, we have |
| 2356 | // to hold off on removing the window until the animation is done. |
| 2357 | // If the display is frozen, just remove immediately, since the |
| 2358 | // animation wouldn't be seen. |
| Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 2359 | if (win.mSurface != null && !mDisplayFrozen && mPolicy.isScreenOn()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2360 | // If we are not currently running the exit animation, we |
| 2361 | // need to see about starting one. |
| 2362 | if (wasVisible=win.isWinVisibleLw()) { |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2363 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2364 | int transit = WindowManagerPolicy.TRANSIT_EXIT; |
| 2365 | if (win.getAttrs().type == TYPE_APPLICATION_STARTING) { |
| 2366 | transit = WindowManagerPolicy.TRANSIT_PREVIEW_DONE; |
| 2367 | } |
| 2368 | // Try starting an animation. |
| 2369 | if (applyAnimationLocked(win, transit, false)) { |
| 2370 | win.mExiting = true; |
| 2371 | } |
| 2372 | } |
| 2373 | if (win.mExiting || win.isAnimating()) { |
| 2374 | // The exit animation is running... wait for it! |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2375 | //Slog.i(TAG, "*** Running exit animation..."); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2376 | win.mExiting = true; |
| 2377 | win.mRemoveOnExit = true; |
| 2378 | mLayoutNeeded = true; |
| 2379 | updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES); |
| 2380 | performLayoutAndPlaceSurfacesLocked(); |
| 2381 | if (win.mAppToken != null) { |
| 2382 | win.mAppToken.updateReportedVisibilityLocked(); |
| 2383 | } |
| 2384 | //dump(); |
| 2385 | Binder.restoreCallingIdentity(origId); |
| 2386 | return; |
| 2387 | } |
| 2388 | } |
| 2389 | |
| 2390 | removeWindowInnerLocked(session, win); |
| 2391 | // Removing a visible window will effect the computed orientation |
| 2392 | // So just update orientation if needed. |
| The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 2393 | if (wasVisible && computeForcedAppOrientationLocked() |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2394 | != mForcedAppOrientation |
| 2395 | && updateOrientationFromAppTokensLocked()) { |
| 2396 | mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2397 | } |
| 2398 | updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL); |
| 2399 | Binder.restoreCallingIdentity(origId); |
| 2400 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2401 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2402 | private void removeWindowInnerLocked(Session session, WindowState win) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2403 | win.mRemoved = true; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2404 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2405 | if (mInputMethodTarget == win) { |
| 2406 | moveInputMethodWindowsIfNeededLocked(false); |
| 2407 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2408 | |
| Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 2409 | if (false) { |
| 2410 | RuntimeException e = new RuntimeException("here"); |
| 2411 | e.fillInStackTrace(); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2412 | Slog.w(TAG, "Removing window " + win, e); |
| Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 2413 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2414 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2415 | mPolicy.removeWindowLw(win); |
| 2416 | win.removeLocked(); |
| 2417 | |
| 2418 | mWindowMap.remove(win.mClient.asBinder()); |
| 2419 | mWindows.remove(win); |
| Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 2420 | mWindowsChanged = true; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2421 | 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] | 2422 | |
| 2423 | if (mInputMethodWindow == win) { |
| 2424 | mInputMethodWindow = null; |
| 2425 | } else if (win.mAttrs.type == TYPE_INPUT_METHOD_DIALOG) { |
| 2426 | mInputMethodDialogs.remove(win); |
| 2427 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2428 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2429 | final WindowToken token = win.mToken; |
| 2430 | final AppWindowToken atoken = win.mAppToken; |
| 2431 | token.windows.remove(win); |
| 2432 | if (atoken != null) { |
| 2433 | atoken.allAppWindows.remove(win); |
| 2434 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2435 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2436 | TAG, "**** Removing window " + win + ": count=" |
| 2437 | + token.windows.size()); |
| 2438 | if (token.windows.size() == 0) { |
| 2439 | if (!token.explicit) { |
| 2440 | mTokenMap.remove(token.token); |
| 2441 | mTokenList.remove(token); |
| 2442 | } else if (atoken != null) { |
| 2443 | atoken.firstWindowDrawn = false; |
| 2444 | } |
| 2445 | } |
| 2446 | |
| 2447 | if (atoken != null) { |
| 2448 | if (atoken.startingWindow == win) { |
| 2449 | atoken.startingWindow = null; |
| 2450 | } else if (atoken.allAppWindows.size() == 0 && atoken.startingData != null) { |
| 2451 | // If this is the last window and we had requested a starting |
| 2452 | // transition window, well there is no point now. |
| 2453 | atoken.startingData = null; |
| 2454 | } else if (atoken.allAppWindows.size() == 1 && atoken.startingView != null) { |
| 2455 | // If this is the last window except for a starting transition |
| 2456 | // window, we need to get rid of the starting transition. |
| 2457 | if (DEBUG_STARTING_WINDOW) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2458 | Slog.v(TAG, "Schedule remove starting " + token |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2459 | + ": no more real windows"); |
| 2460 | } |
| 2461 | Message m = mH.obtainMessage(H.REMOVE_STARTING, atoken); |
| 2462 | mH.sendMessage(m); |
| 2463 | } |
| 2464 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2465 | |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 2466 | if (win.mAttrs.type == TYPE_WALLPAPER) { |
| 2467 | mLastWallpaperTimeoutTime = 0; |
| 2468 | adjustWallpaperWindowsLocked(); |
| 2469 | } else if ((win.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0) { |
| Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 2470 | adjustWallpaperWindowsLocked(); |
| 2471 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2472 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2473 | if (!mInLayout) { |
| 2474 | assignLayersLocked(); |
| 2475 | mLayoutNeeded = true; |
| 2476 | performLayoutAndPlaceSurfacesLocked(); |
| 2477 | if (win.mAppToken != null) { |
| 2478 | win.mAppToken.updateReportedVisibilityLocked(); |
| 2479 | } |
| 2480 | } |
| Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 2481 | |
| 2482 | mInputMonitor.updateInputWindowsLw(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2483 | } |
| 2484 | |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 2485 | private static void logSurface(WindowState w, String msg, RuntimeException where) { |
| 2486 | String str = " SURFACE " + Integer.toHexString(w.hashCode()) |
| 2487 | + ": " + msg + " / " + w.mAttrs.getTitle(); |
| 2488 | if (where != null) { |
| 2489 | Slog.i(TAG, str, where); |
| 2490 | } else { |
| 2491 | Slog.i(TAG, str); |
| 2492 | } |
| 2493 | } |
| 2494 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2495 | private void setTransparentRegionWindow(Session session, IWindow client, Region region) { |
| 2496 | long origId = Binder.clearCallingIdentity(); |
| 2497 | try { |
| 2498 | synchronized (mWindowMap) { |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2499 | WindowState w = windowForClientLocked(session, client, false); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2500 | if ((w != null) && (w.mSurface != null)) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2501 | if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2502 | Surface.openTransaction(); |
| 2503 | try { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 2504 | if (SHOW_TRANSACTIONS) logSurface(w, |
| 2505 | "transparentRegionHint=" + region, null); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2506 | w.mSurface.setTransparentRegionHint(region); |
| 2507 | } finally { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2508 | if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2509 | Surface.closeTransaction(); |
| 2510 | } |
| 2511 | } |
| 2512 | } |
| 2513 | } finally { |
| 2514 | Binder.restoreCallingIdentity(origId); |
| 2515 | } |
| 2516 | } |
| 2517 | |
| 2518 | void setInsetsWindow(Session session, IWindow client, |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2519 | int touchableInsets, Rect contentInsets, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2520 | Rect visibleInsets) { |
| 2521 | long origId = Binder.clearCallingIdentity(); |
| 2522 | try { |
| 2523 | synchronized (mWindowMap) { |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2524 | WindowState w = windowForClientLocked(session, client, false); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2525 | if (w != null) { |
| 2526 | w.mGivenInsetsPending = false; |
| 2527 | w.mGivenContentInsets.set(contentInsets); |
| 2528 | w.mGivenVisibleInsets.set(visibleInsets); |
| 2529 | w.mTouchableInsets = touchableInsets; |
| 2530 | mLayoutNeeded = true; |
| 2531 | performLayoutAndPlaceSurfacesLocked(); |
| 2532 | } |
| 2533 | } |
| 2534 | } finally { |
| 2535 | Binder.restoreCallingIdentity(origId); |
| 2536 | } |
| 2537 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2538 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2539 | public void getWindowDisplayFrame(Session session, IWindow client, |
| 2540 | Rect outDisplayFrame) { |
| 2541 | synchronized(mWindowMap) { |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2542 | WindowState win = windowForClientLocked(session, client, false); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2543 | if (win == null) { |
| 2544 | outDisplayFrame.setEmpty(); |
| 2545 | return; |
| 2546 | } |
| 2547 | outDisplayFrame.set(win.mDisplayFrame); |
| 2548 | } |
| 2549 | } |
| 2550 | |
| Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 2551 | public void setWindowWallpaperPositionLocked(WindowState window, float x, float y, |
| 2552 | float xStep, float yStep) { |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 2553 | if (window.mWallpaperX != x || window.mWallpaperY != y) { |
| 2554 | window.mWallpaperX = x; |
| 2555 | window.mWallpaperY = y; |
| Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 2556 | window.mWallpaperXStep = xStep; |
| 2557 | window.mWallpaperYStep = yStep; |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 2558 | if (updateWallpaperOffsetLocked(window, true)) { |
| 2559 | performLayoutAndPlaceSurfacesLocked(); |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 2560 | } |
| 2561 | } |
| 2562 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2563 | |
| Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 2564 | void wallpaperCommandComplete(IBinder window, Bundle result) { |
| 2565 | synchronized (mWindowMap) { |
| 2566 | if (mWaitingOnWallpaper != null && |
| 2567 | mWaitingOnWallpaper.mClient.asBinder() == window) { |
| 2568 | mWaitingOnWallpaper = null; |
| 2569 | mWindowMap.notifyAll(); |
| 2570 | } |
| 2571 | } |
| 2572 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2573 | |
| Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 2574 | public Bundle sendWindowWallpaperCommandLocked(WindowState window, |
| 2575 | String action, int x, int y, int z, Bundle extras, boolean sync) { |
| 2576 | if (window == mWallpaperTarget || window == mLowerWallpaperTarget |
| 2577 | || window == mUpperWallpaperTarget) { |
| 2578 | boolean doWait = sync; |
| 2579 | int curTokenIndex = mWallpaperTokens.size(); |
| 2580 | while (curTokenIndex > 0) { |
| 2581 | curTokenIndex--; |
| 2582 | WindowToken token = mWallpaperTokens.get(curTokenIndex); |
| 2583 | int curWallpaperIndex = token.windows.size(); |
| 2584 | while (curWallpaperIndex > 0) { |
| 2585 | curWallpaperIndex--; |
| 2586 | WindowState wallpaper = token.windows.get(curWallpaperIndex); |
| 2587 | try { |
| 2588 | wallpaper.mClient.dispatchWallpaperCommand(action, |
| 2589 | x, y, z, extras, sync); |
| 2590 | // We only want to be synchronous with one wallpaper. |
| 2591 | sync = false; |
| 2592 | } catch (RemoteException e) { |
| 2593 | } |
| 2594 | } |
| 2595 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2596 | |
| Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 2597 | if (doWait) { |
| 2598 | // XXX Need to wait for result. |
| 2599 | } |
| 2600 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2601 | |
| Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 2602 | return null; |
| 2603 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2604 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2605 | public int relayoutWindow(Session session, IWindow client, |
| 2606 | WindowManager.LayoutParams attrs, int requestedWidth, |
| 2607 | int requestedHeight, int viewVisibility, boolean insetsPending, |
| 2608 | Rect outFrame, Rect outContentInsets, Rect outVisibleInsets, |
| Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 2609 | Configuration outConfig, Surface outSurface) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2610 | boolean displayed = false; |
| 2611 | boolean inTouchMode; |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2612 | boolean configChanged; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2613 | long origId = Binder.clearCallingIdentity(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2614 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2615 | synchronized(mWindowMap) { |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2616 | WindowState win = windowForClientLocked(session, client, false); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2617 | if (win == null) { |
| 2618 | return 0; |
| 2619 | } |
| 2620 | win.mRequestedWidth = requestedWidth; |
| 2621 | win.mRequestedHeight = requestedHeight; |
| 2622 | |
| 2623 | if (attrs != null) { |
| 2624 | mPolicy.adjustWindowParamsLw(attrs); |
| 2625 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2626 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2627 | int attrChanges = 0; |
| 2628 | int flagChanges = 0; |
| 2629 | if (attrs != null) { |
| 2630 | flagChanges = win.mAttrs.flags ^= attrs.flags; |
| 2631 | attrChanges = win.mAttrs.copyFrom(attrs); |
| 2632 | } |
| 2633 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2634 | 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] | 2635 | |
| 2636 | if ((attrChanges & WindowManager.LayoutParams.ALPHA_CHANGED) != 0) { |
| 2637 | win.mAlpha = attrs.alpha; |
| 2638 | } |
| 2639 | |
| 2640 | final boolean scaledWindow = |
| 2641 | ((win.mAttrs.flags & WindowManager.LayoutParams.FLAG_SCALED) != 0); |
| 2642 | |
| 2643 | if (scaledWindow) { |
| 2644 | // requested{Width|Height} Surface's physical size |
| 2645 | // attrs.{width|height} Size on screen |
| 2646 | win.mHScale = (attrs.width != requestedWidth) ? |
| 2647 | (attrs.width / (float)requestedWidth) : 1.0f; |
| 2648 | win.mVScale = (attrs.height != requestedHeight) ? |
| 2649 | (attrs.height / (float)requestedHeight) : 1.0f; |
| Dianne Hackborn | 9b52a21 | 2009-12-11 14:51:35 -0800 | [diff] [blame] | 2650 | } else { |
| 2651 | win.mHScale = win.mVScale = 1; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2652 | } |
| 2653 | |
| 2654 | boolean imMayMove = (flagChanges&( |
| 2655 | WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM | |
| 2656 | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE)) != 0; |
| 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 | boolean focusMayChange = win.mViewVisibility != viewVisibility |
| 2659 | || ((flagChanges&WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) != 0) |
| 2660 | || (!win.mRelayoutCalled); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2661 | |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2662 | boolean wallpaperMayMove = win.mViewVisibility != viewVisibility |
| 2663 | && (win.mAttrs.flags & FLAG_SHOW_WALLPAPER) != 0; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2664 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2665 | win.mRelayoutCalled = true; |
| 2666 | final int oldVisibility = win.mViewVisibility; |
| 2667 | win.mViewVisibility = viewVisibility; |
| 2668 | if (viewVisibility == View.VISIBLE && |
| 2669 | (win.mAppToken == null || !win.mAppToken.clientHidden)) { |
| 2670 | displayed = !win.isVisibleLw(); |
| 2671 | if (win.mExiting) { |
| 2672 | win.mExiting = false; |
| 2673 | win.mAnimation = null; |
| 2674 | } |
| 2675 | if (win.mDestroying) { |
| 2676 | win.mDestroying = false; |
| 2677 | mDestroySurface.remove(win); |
| 2678 | } |
| 2679 | if (oldVisibility == View.GONE) { |
| 2680 | win.mEnterAnimationPending = true; |
| 2681 | } |
| Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 2682 | if (displayed) { |
| 2683 | if (win.mSurface != null && !win.mDrawPending |
| 2684 | && !win.mCommitDrawPending && !mDisplayFrozen |
| 2685 | && mPolicy.isScreenOn()) { |
| 2686 | applyEnterAnimationLocked(win); |
| 2687 | } |
| 2688 | if ((win.mAttrs.flags |
| 2689 | & WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON) != 0) { |
| 2690 | if (DEBUG_VISIBILITY) Slog.v(TAG, |
| 2691 | "Relayout window turning screen on: " + win); |
| 2692 | win.mTurnOnScreen = true; |
| 2693 | } |
| 2694 | int diff = 0; |
| 2695 | if (win.mConfiguration != mCurConfiguration |
| 2696 | && (win.mConfiguration == null |
| 2697 | || (diff=mCurConfiguration.diff(win.mConfiguration)) != 0)) { |
| 2698 | win.mConfiguration = mCurConfiguration; |
| 2699 | if (DEBUG_CONFIGURATION) { |
| 2700 | Slog.i(TAG, "Window " + win + " visible with new config: " |
| 2701 | + win.mConfiguration + " / 0x" |
| 2702 | + Integer.toHexString(diff)); |
| 2703 | } |
| 2704 | outConfig.setTo(mCurConfiguration); |
| 2705 | } |
| Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 2706 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2707 | if ((attrChanges&WindowManager.LayoutParams.FORMAT_CHANGED) != 0) { |
| 2708 | // To change the format, we need to re-build the surface. |
| 2709 | win.destroySurfaceLocked(); |
| 2710 | displayed = true; |
| 2711 | } |
| 2712 | try { |
| 2713 | Surface surface = win.createSurfaceLocked(); |
| 2714 | if (surface != null) { |
| 2715 | outSurface.copyFrom(surface); |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2716 | win.mReportDestroySurface = false; |
| 2717 | win.mSurfacePendingDestroy = false; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2718 | if (SHOW_TRANSACTIONS) Slog.i(TAG, |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 2719 | " OUT SURFACE " + outSurface + ": copied"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2720 | } else { |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 2721 | // For some reason there isn't a surface. Clear the |
| 2722 | // caller's object so they see the same state. |
| 2723 | outSurface.release(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2724 | } |
| 2725 | } catch (Exception e) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 2726 | mInputMonitor.updateInputWindowsLw(); |
| 2727 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2728 | Slog.w(TAG, "Exception thrown when creating surface for client " |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 2729 | + client + " (" + win.mAttrs.getTitle() + ")", |
| 2730 | e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2731 | Binder.restoreCallingIdentity(origId); |
| 2732 | return 0; |
| 2733 | } |
| 2734 | if (displayed) { |
| 2735 | focusMayChange = true; |
| 2736 | } |
| 2737 | if (win.mAttrs.type == TYPE_INPUT_METHOD |
| 2738 | && mInputMethodWindow == null) { |
| 2739 | mInputMethodWindow = win; |
| 2740 | imMayMove = true; |
| 2741 | } |
| Dianne Hackborn | 558947c | 2009-12-18 16:02:50 -0800 | [diff] [blame] | 2742 | if (win.mAttrs.type == TYPE_BASE_APPLICATION |
| 2743 | && win.mAppToken != null |
| 2744 | && win.mAppToken.startingWindow != null) { |
| 2745 | // Special handling of starting window over the base |
| 2746 | // window of the app: propagate lock screen flags to it, |
| 2747 | // to provide the correct semantics while starting. |
| 2748 | final int mask = |
| 2749 | WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED |
| Mike Lockwood | ef73162 | 2010-01-27 17:51:34 -0500 | [diff] [blame] | 2750 | | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD |
| 2751 | | WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON; |
| Dianne Hackborn | 558947c | 2009-12-18 16:02:50 -0800 | [diff] [blame] | 2752 | WindowManager.LayoutParams sa = win.mAppToken.startingWindow.mAttrs; |
| 2753 | sa.flags = (sa.flags&~mask) | (win.mAttrs.flags&mask); |
| 2754 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2755 | } else { |
| 2756 | win.mEnterAnimationPending = false; |
| 2757 | if (win.mSurface != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2758 | if (DEBUG_VISIBILITY) Slog.i(TAG, "Relayout invis " + win |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2759 | + ": mExiting=" + win.mExiting |
| 2760 | + " mSurfacePendingDestroy=" + win.mSurfacePendingDestroy); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2761 | // If we are not currently running the exit animation, we |
| 2762 | // need to see about starting one. |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2763 | if (!win.mExiting || win.mSurfacePendingDestroy) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2764 | // Try starting an animation; if there isn't one, we |
| 2765 | // can destroy the surface right away. |
| 2766 | int transit = WindowManagerPolicy.TRANSIT_EXIT; |
| 2767 | if (win.getAttrs().type == TYPE_APPLICATION_STARTING) { |
| 2768 | transit = WindowManagerPolicy.TRANSIT_PREVIEW_DONE; |
| 2769 | } |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2770 | if (!win.mSurfacePendingDestroy && win.isWinVisibleLw() && |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2771 | applyAnimationLocked(win, transit, false)) { |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2772 | focusMayChange = true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2773 | win.mExiting = true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2774 | } else if (win.isAnimating()) { |
| 2775 | // Currently in a hide animation... turn this into |
| 2776 | // an exit. |
| 2777 | win.mExiting = true; |
| Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 2778 | } else if (win == mWallpaperTarget) { |
| 2779 | // If the wallpaper is currently behind this |
| 2780 | // window, we need to change both of them inside |
| 2781 | // of a transaction to avoid artifacts. |
| 2782 | win.mExiting = true; |
| 2783 | win.mAnimating = true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2784 | } else { |
| 2785 | if (mInputMethodWindow == win) { |
| 2786 | mInputMethodWindow = null; |
| 2787 | } |
| 2788 | win.destroySurfaceLocked(); |
| 2789 | } |
| 2790 | } |
| 2791 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2792 | |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2793 | if (win.mSurface == null || (win.getAttrs().flags |
| 2794 | & WindowManager.LayoutParams.FLAG_KEEP_SURFACE_WHILE_ANIMATING) == 0 |
| 2795 | || win.mSurfacePendingDestroy) { |
| 2796 | // We are being called from a local process, which |
| 2797 | // means outSurface holds its current surface. Ensure the |
| 2798 | // surface object is cleared, but we don't want it actually |
| 2799 | // destroyed at this point. |
| 2800 | win.mSurfacePendingDestroy = false; |
| 2801 | outSurface.release(); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2802 | if (DEBUG_VISIBILITY) Slog.i(TAG, "Releasing surface in: " + win); |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2803 | } else if (win.mSurface != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2804 | if (DEBUG_VISIBILITY) Slog.i(TAG, |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2805 | "Keeping surface, will report destroy: " + win); |
| 2806 | win.mReportDestroySurface = true; |
| 2807 | outSurface.copyFrom(win.mSurface); |
| 2808 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2809 | } |
| 2810 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2811 | if (focusMayChange) { |
| 2812 | //System.out.println("Focus may change: " + win.mAttrs.getTitle()); |
| 2813 | if (updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES)) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2814 | imMayMove = false; |
| 2815 | } |
| 2816 | //System.out.println("Relayout " + win + ": focus=" + mCurrentFocus); |
| 2817 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2818 | |
| The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 2819 | // updateFocusedWindowLocked() already assigned layers so we only need to |
| 2820 | // reassign them at this point if the IM window state gets shuffled |
| 2821 | boolean assignLayers = false; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2822 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2823 | if (imMayMove) { |
| Dianne Hackborn | 8abd5f0 | 2009-11-20 18:09:03 -0800 | [diff] [blame] | 2824 | if (moveInputMethodWindowsIfNeededLocked(false) || displayed) { |
| 2825 | // Little hack here -- we -should- be able to rely on the |
| 2826 | // function to return true if the IME has moved and needs |
| 2827 | // its layer recomputed. However, if the IME was hidden |
| 2828 | // and isn't actually moved in the list, its layer may be |
| 2829 | // 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] | 2830 | assignLayers = true; |
| 2831 | } |
| 2832 | } |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2833 | if (wallpaperMayMove) { |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 2834 | if ((adjustWallpaperWindowsLocked()&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) { |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2835 | assignLayers = true; |
| 2836 | } |
| 2837 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2838 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2839 | mLayoutNeeded = true; |
| 2840 | win.mGivenInsetsPending = insetsPending; |
| 2841 | if (assignLayers) { |
| 2842 | assignLayersLocked(); |
| 2843 | } |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2844 | configChanged = updateOrientationFromAppTokensLocked(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2845 | performLayoutAndPlaceSurfacesLocked(); |
| Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 2846 | if (displayed && win.mIsWallpaper) { |
| 2847 | updateWallpaperOffsetLocked(win, mDisplay.getWidth(), |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 2848 | mDisplay.getHeight(), false); |
| Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 2849 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2850 | if (win.mAppToken != null) { |
| 2851 | win.mAppToken.updateReportedVisibilityLocked(); |
| 2852 | } |
| 2853 | outFrame.set(win.mFrame); |
| 2854 | outContentInsets.set(win.mContentInsets); |
| 2855 | outVisibleInsets.set(win.mVisibleInsets); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2856 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2857 | TAG, "Relayout given client " + client.asBinder() |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2858 | + ", requestedWidth=" + requestedWidth |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2859 | + ", requestedHeight=" + requestedHeight |
| 2860 | + ", viewVisibility=" + viewVisibility |
| 2861 | + "\nRelayout returning frame=" + outFrame |
| 2862 | + ", surface=" + outSurface); |
| 2863 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2864 | if (localLOGV || DEBUG_FOCUS) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2865 | TAG, "Relayout of " + win + ": focusMayChange=" + focusMayChange); |
| 2866 | |
| 2867 | inTouchMode = mInTouchMode; |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 2868 | |
| 2869 | mInputMonitor.updateInputWindowsLw(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2870 | } |
| 2871 | |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2872 | if (configChanged) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2873 | sendNewConfiguration(); |
| 2874 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2875 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2876 | Binder.restoreCallingIdentity(origId); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2877 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2878 | return (inTouchMode ? WindowManagerImpl.RELAYOUT_IN_TOUCH_MODE : 0) |
| 2879 | | (displayed ? WindowManagerImpl.RELAYOUT_FIRST_TIME : 0); |
| 2880 | } |
| 2881 | |
| 2882 | public void finishDrawingWindow(Session session, IWindow client) { |
| 2883 | final long origId = Binder.clearCallingIdentity(); |
| 2884 | synchronized(mWindowMap) { |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2885 | WindowState win = windowForClientLocked(session, client, false); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2886 | if (win != null && win.finishDrawingLocked()) { |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 2887 | if ((win.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0) { |
| 2888 | adjustWallpaperWindowsLocked(); |
| 2889 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2890 | mLayoutNeeded = true; |
| 2891 | performLayoutAndPlaceSurfacesLocked(); |
| 2892 | } |
| 2893 | } |
| 2894 | Binder.restoreCallingIdentity(origId); |
| 2895 | } |
| 2896 | |
| 2897 | private AttributeCache.Entry getCachedAnimations(WindowManager.LayoutParams lp) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2898 | 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] | 2899 | + (lp != null ? lp.packageName : null) |
| 2900 | + " resId=0x" + (lp != null ? Integer.toHexString(lp.windowAnimations) : null)); |
| 2901 | if (lp != null && lp.windowAnimations != 0) { |
| 2902 | // If this is a system resource, don't try to load it from the |
| 2903 | // application resources. It is nice to avoid loading application |
| 2904 | // resources if we can. |
| 2905 | String packageName = lp.packageName != null ? lp.packageName : "android"; |
| 2906 | int resId = lp.windowAnimations; |
| 2907 | if ((resId&0xFF000000) == 0x01000000) { |
| 2908 | packageName = "android"; |
| 2909 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2910 | 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] | 2911 | + packageName); |
| 2912 | return AttributeCache.instance().get(packageName, resId, |
| 2913 | com.android.internal.R.styleable.WindowAnimation); |
| 2914 | } |
| 2915 | return null; |
| 2916 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2917 | |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2918 | private AttributeCache.Entry getCachedAnimations(String packageName, int resId) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2919 | if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: params package=" |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2920 | + packageName + " resId=0x" + Integer.toHexString(resId)); |
| 2921 | if (packageName != null) { |
| 2922 | if ((resId&0xFF000000) == 0x01000000) { |
| 2923 | packageName = "android"; |
| 2924 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2925 | if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: picked package=" |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2926 | + packageName); |
| 2927 | return AttributeCache.instance().get(packageName, resId, |
| 2928 | com.android.internal.R.styleable.WindowAnimation); |
| 2929 | } |
| 2930 | return null; |
| 2931 | } |
| 2932 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2933 | private void applyEnterAnimationLocked(WindowState win) { |
| 2934 | int transit = WindowManagerPolicy.TRANSIT_SHOW; |
| 2935 | if (win.mEnterAnimationPending) { |
| 2936 | win.mEnterAnimationPending = false; |
| 2937 | transit = WindowManagerPolicy.TRANSIT_ENTER; |
| 2938 | } |
| 2939 | |
| 2940 | applyAnimationLocked(win, transit, true); |
| 2941 | } |
| 2942 | |
| 2943 | private boolean applyAnimationLocked(WindowState win, |
| 2944 | int transit, boolean isEntrance) { |
| 2945 | if (win.mLocalAnimating && win.mAnimationIsEntrance == isEntrance) { |
| 2946 | // If we are trying to apply an animation, but already running |
| 2947 | // an animation of the same type, then just leave that one alone. |
| 2948 | return true; |
| 2949 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2950 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2951 | // Only apply an animation if the display isn't frozen. If it is |
| 2952 | // frozen, there is no reason to animate and it can cause strange |
| 2953 | // artifacts when we unfreeze the display if some different animation |
| 2954 | // is running. |
| Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 2955 | if (!mDisplayFrozen && mPolicy.isScreenOn()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2956 | int anim = mPolicy.selectAnimationLw(win, transit); |
| 2957 | int attr = -1; |
| 2958 | Animation a = null; |
| 2959 | if (anim != 0) { |
| 2960 | a = AnimationUtils.loadAnimation(mContext, anim); |
| 2961 | } else { |
| 2962 | switch (transit) { |
| 2963 | case WindowManagerPolicy.TRANSIT_ENTER: |
| 2964 | attr = com.android.internal.R.styleable.WindowAnimation_windowEnterAnimation; |
| 2965 | break; |
| 2966 | case WindowManagerPolicy.TRANSIT_EXIT: |
| 2967 | attr = com.android.internal.R.styleable.WindowAnimation_windowExitAnimation; |
| 2968 | break; |
| 2969 | case WindowManagerPolicy.TRANSIT_SHOW: |
| 2970 | attr = com.android.internal.R.styleable.WindowAnimation_windowShowAnimation; |
| 2971 | break; |
| 2972 | case WindowManagerPolicy.TRANSIT_HIDE: |
| 2973 | attr = com.android.internal.R.styleable.WindowAnimation_windowHideAnimation; |
| 2974 | break; |
| 2975 | } |
| 2976 | if (attr >= 0) { |
| 2977 | a = loadAnimation(win.mAttrs, attr); |
| 2978 | } |
| 2979 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2980 | if (DEBUG_ANIM) Slog.v(TAG, "applyAnimation: win=" + win |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2981 | + " anim=" + anim + " attr=0x" + Integer.toHexString(attr) |
| 2982 | + " mAnimation=" + win.mAnimation |
| 2983 | + " isEntrance=" + isEntrance); |
| 2984 | if (a != null) { |
| 2985 | if (DEBUG_ANIM) { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 2986 | RuntimeException e = null; |
| 2987 | if (!HIDE_STACK_CRAWLS) { |
| 2988 | e = new RuntimeException(); |
| 2989 | e.fillInStackTrace(); |
| 2990 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2991 | Slog.v(TAG, "Loaded animation " + a + " for " + win, e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2992 | } |
| 2993 | win.setAnimation(a); |
| 2994 | win.mAnimationIsEntrance = isEntrance; |
| 2995 | } |
| 2996 | } else { |
| 2997 | win.clearAnimation(); |
| 2998 | } |
| 2999 | |
| 3000 | return win.mAnimation != null; |
| 3001 | } |
| 3002 | |
| 3003 | private Animation loadAnimation(WindowManager.LayoutParams lp, int animAttr) { |
| 3004 | int anim = 0; |
| 3005 | Context context = mContext; |
| 3006 | if (animAttr >= 0) { |
| 3007 | AttributeCache.Entry ent = getCachedAnimations(lp); |
| 3008 | if (ent != null) { |
| 3009 | context = ent.context; |
| 3010 | anim = ent.array.getResourceId(animAttr, 0); |
| 3011 | } |
| 3012 | } |
| 3013 | if (anim != 0) { |
| 3014 | return AnimationUtils.loadAnimation(context, anim); |
| 3015 | } |
| 3016 | return null; |
| 3017 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3018 | |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 3019 | private Animation loadAnimation(String packageName, int resId) { |
| 3020 | int anim = 0; |
| 3021 | Context context = mContext; |
| 3022 | if (resId >= 0) { |
| 3023 | AttributeCache.Entry ent = getCachedAnimations(packageName, resId); |
| 3024 | if (ent != null) { |
| 3025 | context = ent.context; |
| 3026 | anim = resId; |
| 3027 | } |
| 3028 | } |
| 3029 | if (anim != 0) { |
| 3030 | return AnimationUtils.loadAnimation(context, anim); |
| 3031 | } |
| 3032 | return null; |
| 3033 | } |
| 3034 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3035 | private boolean applyAnimationLocked(AppWindowToken wtoken, |
| 3036 | WindowManager.LayoutParams lp, int transit, boolean enter) { |
| 3037 | // Only apply an animation if the display isn't frozen. If it is |
| 3038 | // frozen, there is no reason to animate and it can cause strange |
| 3039 | // artifacts when we unfreeze the display if some different animation |
| 3040 | // is running. |
| Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 3041 | if (!mDisplayFrozen && mPolicy.isScreenOn()) { |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 3042 | Animation a; |
| Mitsuru Oshima | d2967e2 | 2009-07-20 14:01:43 -0700 | [diff] [blame] | 3043 | if (lp != null && (lp.flags & FLAG_COMPATIBLE_WINDOW) != 0) { |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 3044 | a = new FadeInOutAnimation(enter); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3045 | if (DEBUG_ANIM) Slog.v(TAG, |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 3046 | "applying FadeInOutAnimation for a window in compatibility mode"); |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 3047 | } else if (mNextAppTransitionPackage != null) { |
| 3048 | a = loadAnimation(mNextAppTransitionPackage, enter ? |
| 3049 | mNextAppTransitionEnter : mNextAppTransitionExit); |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 3050 | } else { |
| 3051 | int animAttr = 0; |
| 3052 | switch (transit) { |
| 3053 | case WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN: |
| 3054 | animAttr = enter |
| 3055 | ? com.android.internal.R.styleable.WindowAnimation_activityOpenEnterAnimation |
| 3056 | : com.android.internal.R.styleable.WindowAnimation_activityOpenExitAnimation; |
| 3057 | break; |
| 3058 | case WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE: |
| 3059 | animAttr = enter |
| 3060 | ? com.android.internal.R.styleable.WindowAnimation_activityCloseEnterAnimation |
| 3061 | : com.android.internal.R.styleable.WindowAnimation_activityCloseExitAnimation; |
| 3062 | break; |
| 3063 | case WindowManagerPolicy.TRANSIT_TASK_OPEN: |
| 3064 | animAttr = enter |
| 3065 | ? com.android.internal.R.styleable.WindowAnimation_taskOpenEnterAnimation |
| 3066 | : com.android.internal.R.styleable.WindowAnimation_taskOpenExitAnimation; |
| 3067 | break; |
| 3068 | case WindowManagerPolicy.TRANSIT_TASK_CLOSE: |
| 3069 | animAttr = enter |
| 3070 | ? com.android.internal.R.styleable.WindowAnimation_taskCloseEnterAnimation |
| 3071 | : com.android.internal.R.styleable.WindowAnimation_taskCloseExitAnimation; |
| 3072 | break; |
| 3073 | case WindowManagerPolicy.TRANSIT_TASK_TO_FRONT: |
| 3074 | animAttr = enter |
| 3075 | ? com.android.internal.R.styleable.WindowAnimation_taskToFrontEnterAnimation |
| 3076 | : com.android.internal.R.styleable.WindowAnimation_taskToFrontExitAnimation; |
| 3077 | break; |
| 3078 | case WindowManagerPolicy.TRANSIT_TASK_TO_BACK: |
| 3079 | animAttr = enter |
| Mitsuru Oshima | 5a2b91d | 2009-07-16 16:30:02 -0700 | [diff] [blame] | 3080 | ? com.android.internal.R.styleable.WindowAnimation_taskToBackEnterAnimation |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 3081 | : com.android.internal.R.styleable.WindowAnimation_taskToBackExitAnimation; |
| 3082 | break; |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 3083 | case WindowManagerPolicy.TRANSIT_WALLPAPER_OPEN: |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 3084 | animAttr = enter |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 3085 | ? com.android.internal.R.styleable.WindowAnimation_wallpaperOpenEnterAnimation |
| 3086 | : com.android.internal.R.styleable.WindowAnimation_wallpaperOpenExitAnimation; |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 3087 | break; |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 3088 | case WindowManagerPolicy.TRANSIT_WALLPAPER_CLOSE: |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 3089 | animAttr = enter |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 3090 | ? com.android.internal.R.styleable.WindowAnimation_wallpaperCloseEnterAnimation |
| 3091 | : com.android.internal.R.styleable.WindowAnimation_wallpaperCloseExitAnimation; |
| 3092 | break; |
| 3093 | case WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_OPEN: |
| 3094 | animAttr = enter |
| 3095 | ? com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenEnterAnimation |
| 3096 | : com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenExitAnimation; |
| 3097 | break; |
| 3098 | case WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_CLOSE: |
| 3099 | animAttr = enter |
| 3100 | ? com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseEnterAnimation |
| 3101 | : com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseExitAnimation; |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 3102 | break; |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 3103 | } |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 3104 | a = animAttr != 0 ? loadAnimation(lp, animAttr) : null; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3105 | if (DEBUG_ANIM) Slog.v(TAG, "applyAnimation: wtoken=" + wtoken |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 3106 | + " anim=" + a |
| 3107 | + " animAttr=0x" + Integer.toHexString(animAttr) |
| 3108 | + " transit=" + transit); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3109 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3110 | if (a != null) { |
| 3111 | if (DEBUG_ANIM) { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 3112 | RuntimeException e = null; |
| 3113 | if (!HIDE_STACK_CRAWLS) { |
| 3114 | e = new RuntimeException(); |
| 3115 | e.fillInStackTrace(); |
| 3116 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3117 | Slog.v(TAG, "Loaded animation " + a + " for " + wtoken, e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3118 | } |
| 3119 | wtoken.setAnimation(a); |
| 3120 | } |
| 3121 | } else { |
| 3122 | wtoken.clearAnimation(); |
| 3123 | } |
| 3124 | |
| 3125 | return wtoken.animation != null; |
| 3126 | } |
| 3127 | |
| 3128 | // ------------------------------------------------------------- |
| 3129 | // Application Window Tokens |
| 3130 | // ------------------------------------------------------------- |
| 3131 | |
| 3132 | public void validateAppTokens(List tokens) { |
| 3133 | int v = tokens.size()-1; |
| 3134 | int m = mAppTokens.size()-1; |
| 3135 | while (v >= 0 && m >= 0) { |
| 3136 | AppWindowToken wtoken = mAppTokens.get(m); |
| 3137 | if (wtoken.removed) { |
| 3138 | m--; |
| 3139 | continue; |
| 3140 | } |
| 3141 | if (tokens.get(v) != wtoken.token) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3142 | 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] | 3143 | + " @ " + v + ", internal is " + wtoken.token + " @ " + m); |
| 3144 | } |
| 3145 | v--; |
| 3146 | m--; |
| 3147 | } |
| 3148 | while (v >= 0) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3149 | 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] | 3150 | v--; |
| 3151 | } |
| 3152 | while (m >= 0) { |
| 3153 | AppWindowToken wtoken = mAppTokens.get(m); |
| 3154 | if (!wtoken.removed) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3155 | Slog.w(TAG, "Invalid internal token: " + wtoken.token + " @ " + m); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3156 | } |
| 3157 | m--; |
| 3158 | } |
| 3159 | } |
| 3160 | |
| 3161 | boolean checkCallingPermission(String permission, String func) { |
| 3162 | // Quick check: if the calling permission is me, it's all okay. |
| 3163 | if (Binder.getCallingPid() == Process.myPid()) { |
| 3164 | return true; |
| 3165 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3166 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3167 | if (mContext.checkCallingPermission(permission) |
| 3168 | == PackageManager.PERMISSION_GRANTED) { |
| 3169 | return true; |
| 3170 | } |
| 3171 | String msg = "Permission Denial: " + func + " from pid=" |
| 3172 | + Binder.getCallingPid() |
| 3173 | + ", uid=" + Binder.getCallingUid() |
| 3174 | + " requires " + permission; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3175 | Slog.w(TAG, msg); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3176 | return false; |
| 3177 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3178 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3179 | AppWindowToken findAppWindowToken(IBinder token) { |
| 3180 | WindowToken wtoken = mTokenMap.get(token); |
| 3181 | if (wtoken == null) { |
| 3182 | return null; |
| 3183 | } |
| 3184 | return wtoken.appWindowToken; |
| 3185 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3186 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3187 | public void addWindowToken(IBinder token, int type) { |
| 3188 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3189 | "addWindowToken()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3190 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3191 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3192 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3193 | synchronized(mWindowMap) { |
| 3194 | WindowToken wtoken = mTokenMap.get(token); |
| 3195 | if (wtoken != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3196 | 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] | 3197 | return; |
| 3198 | } |
| 3199 | wtoken = new WindowToken(token, type, true); |
| 3200 | mTokenMap.put(token, wtoken); |
| 3201 | mTokenList.add(wtoken); |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 3202 | if (type == TYPE_WALLPAPER) { |
| 3203 | mWallpaperTokens.add(wtoken); |
| 3204 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3205 | } |
| 3206 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3207 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3208 | public void removeWindowToken(IBinder token) { |
| 3209 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3210 | "removeWindowToken()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3211 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3212 | } |
| 3213 | |
| 3214 | final long origId = Binder.clearCallingIdentity(); |
| 3215 | synchronized(mWindowMap) { |
| 3216 | WindowToken wtoken = mTokenMap.remove(token); |
| 3217 | mTokenList.remove(wtoken); |
| 3218 | if (wtoken != null) { |
| 3219 | boolean delayed = false; |
| 3220 | if (!wtoken.hidden) { |
| 3221 | wtoken.hidden = true; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3222 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3223 | final int N = wtoken.windows.size(); |
| 3224 | boolean changed = false; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3225 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3226 | for (int i=0; i<N; i++) { |
| 3227 | WindowState win = wtoken.windows.get(i); |
| 3228 | |
| 3229 | if (win.isAnimating()) { |
| 3230 | delayed = true; |
| 3231 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3232 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3233 | if (win.isVisibleNow()) { |
| 3234 | applyAnimationLocked(win, |
| 3235 | WindowManagerPolicy.TRANSIT_EXIT, false); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3236 | changed = true; |
| 3237 | } |
| 3238 | } |
| 3239 | |
| 3240 | if (changed) { |
| 3241 | mLayoutNeeded = true; |
| 3242 | performLayoutAndPlaceSurfacesLocked(); |
| 3243 | updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL); |
| 3244 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3245 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3246 | if (delayed) { |
| 3247 | mExitingTokens.add(wtoken); |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 3248 | } else if (wtoken.windowType == TYPE_WALLPAPER) { |
| 3249 | mWallpaperTokens.remove(wtoken); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3250 | } |
| 3251 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3252 | |
| Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 3253 | mInputMonitor.updateInputWindowsLw(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3254 | } else { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3255 | 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] | 3256 | } |
| 3257 | } |
| 3258 | Binder.restoreCallingIdentity(origId); |
| 3259 | } |
| 3260 | |
| 3261 | public void addAppToken(int addPos, IApplicationToken token, |
| 3262 | int groupId, int requestedOrientation, boolean fullscreen) { |
| 3263 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3264 | "addAppToken()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3265 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3266 | } |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 3267 | |
| 3268 | // Get the dispatching timeout here while we are not holding any locks so that it |
| 3269 | // can be cached by the AppWindowToken. The timeout value is used later by the |
| 3270 | // input dispatcher in code that does hold locks. If we did not cache the value |
| 3271 | // here we would run the chance of introducing a deadlock between the window manager |
| 3272 | // (which holds locks while updating the input dispatcher state) and the activity manager |
| 3273 | // (which holds locks while querying the application token). |
| 3274 | long inputDispatchingTimeoutNanos; |
| 3275 | try { |
| 3276 | inputDispatchingTimeoutNanos = token.getKeyDispatchingTimeout() * 1000000L; |
| 3277 | } catch (RemoteException ex) { |
| 3278 | Slog.w(TAG, "Could not get dispatching timeout.", ex); |
| 3279 | inputDispatchingTimeoutNanos = DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS; |
| 3280 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3281 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3282 | synchronized(mWindowMap) { |
| 3283 | AppWindowToken wtoken = findAppWindowToken(token.asBinder()); |
| 3284 | if (wtoken != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3285 | 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] | 3286 | return; |
| 3287 | } |
| 3288 | wtoken = new AppWindowToken(token); |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 3289 | wtoken.inputDispatchingTimeoutNanos = inputDispatchingTimeoutNanos; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3290 | wtoken.groupId = groupId; |
| 3291 | wtoken.appFullscreen = fullscreen; |
| 3292 | wtoken.requestedOrientation = requestedOrientation; |
| 3293 | mAppTokens.add(addPos, wtoken); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3294 | 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] | 3295 | mTokenMap.put(token.asBinder(), wtoken); |
| 3296 | mTokenList.add(wtoken); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3297 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3298 | // Application tokens start out hidden. |
| 3299 | wtoken.hidden = true; |
| 3300 | wtoken.hiddenRequested = true; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3301 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3302 | //dump(); |
| 3303 | } |
| 3304 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3305 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3306 | public void setAppGroupId(IBinder token, int groupId) { |
| 3307 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3308 | "setAppStartingIcon()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3309 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3310 | } |
| 3311 | |
| 3312 | synchronized(mWindowMap) { |
| 3313 | AppWindowToken wtoken = findAppWindowToken(token); |
| 3314 | if (wtoken == null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3315 | 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] | 3316 | return; |
| 3317 | } |
| 3318 | wtoken.groupId = groupId; |
| 3319 | } |
| 3320 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3321 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3322 | public int getOrientationFromWindowsLocked() { |
| 3323 | int pos = mWindows.size() - 1; |
| 3324 | while (pos >= 0) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 3325 | WindowState wtoken = mWindows.get(pos); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3326 | pos--; |
| 3327 | if (wtoken.mAppToken != null) { |
| 3328 | // We hit an application window. so the orientation will be determined by the |
| 3329 | // app window. No point in continuing further. |
| 3330 | return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
| 3331 | } |
| Christopher Tate | b696aee | 2010-04-02 19:08:30 -0700 | [diff] [blame] | 3332 | if (!wtoken.isVisibleLw() || !wtoken.mPolicyVisibilityAfterAnim) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3333 | continue; |
| 3334 | } |
| 3335 | int req = wtoken.mAttrs.screenOrientation; |
| 3336 | if((req == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) || |
| 3337 | (req == ActivityInfo.SCREEN_ORIENTATION_BEHIND)){ |
| 3338 | continue; |
| 3339 | } else { |
| 3340 | return req; |
| 3341 | } |
| 3342 | } |
| 3343 | return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
| 3344 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3345 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3346 | public int getOrientationFromAppTokensLocked() { |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3347 | int pos = mAppTokens.size() - 1; |
| 3348 | int curGroup = 0; |
| 3349 | int lastOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
| 3350 | boolean findingBehind = false; |
| 3351 | boolean haveGroup = false; |
| 3352 | boolean lastFullscreen = false; |
| 3353 | while (pos >= 0) { |
| 3354 | AppWindowToken wtoken = mAppTokens.get(pos); |
| 3355 | pos--; |
| 3356 | // if we're about to tear down this window and not seek for |
| 3357 | // the behind activity, don't use it for orientation |
| 3358 | if (!findingBehind |
| 3359 | && (!wtoken.hidden && wtoken.hiddenRequested)) { |
| 3360 | continue; |
| 3361 | } |
| 3362 | |
| 3363 | if (!haveGroup) { |
| 3364 | // We ignore any hidden applications on the top. |
| 3365 | if (wtoken.hiddenRequested || wtoken.willBeHidden) { |
| The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3366 | continue; |
| 3367 | } |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3368 | haveGroup = true; |
| 3369 | curGroup = wtoken.groupId; |
| 3370 | lastOrientation = wtoken.requestedOrientation; |
| 3371 | } else if (curGroup != wtoken.groupId) { |
| 3372 | // If we have hit a new application group, and the bottom |
| 3373 | // of the previous group didn't explicitly say to use |
| 3374 | // the orientation behind it, and the last app was |
| 3375 | // full screen, then we'll stick with the |
| 3376 | // user's orientation. |
| 3377 | if (lastOrientation != ActivityInfo.SCREEN_ORIENTATION_BEHIND |
| 3378 | && lastFullscreen) { |
| 3379 | return lastOrientation; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3380 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3381 | } |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3382 | int or = wtoken.requestedOrientation; |
| 3383 | // If this application is fullscreen, and didn't explicitly say |
| 3384 | // to use the orientation behind it, then just take whatever |
| 3385 | // orientation it has and ignores whatever is under it. |
| 3386 | lastFullscreen = wtoken.appFullscreen; |
| 3387 | if (lastFullscreen |
| 3388 | && or != ActivityInfo.SCREEN_ORIENTATION_BEHIND) { |
| 3389 | return or; |
| 3390 | } |
| 3391 | // If this application has requested an explicit orientation, |
| 3392 | // then use it. |
| Dianne Hackborn | e5439f2 | 2010-10-02 16:53:50 -0700 | [diff] [blame] | 3393 | if (or != ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED |
| 3394 | && or != ActivityInfo.SCREEN_ORIENTATION_BEHIND) { |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3395 | return or; |
| 3396 | } |
| 3397 | findingBehind |= (or == ActivityInfo.SCREEN_ORIENTATION_BEHIND); |
| 3398 | } |
| 3399 | return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3400 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3401 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3402 | public Configuration updateOrientationFromAppTokens( |
| The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3403 | Configuration currentConfig, IBinder freezeThisOneIfNeeded) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3404 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3405 | "updateOrientationFromAppTokens()")) { |
| 3406 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| 3407 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3408 | |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3409 | Configuration config = null; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3410 | long ident = Binder.clearCallingIdentity(); |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3411 | |
| 3412 | synchronized(mWindowMap) { |
| 3413 | if (updateOrientationFromAppTokensLocked()) { |
| 3414 | if (freezeThisOneIfNeeded != null) { |
| 3415 | AppWindowToken wtoken = findAppWindowToken( |
| 3416 | freezeThisOneIfNeeded); |
| 3417 | if (wtoken != null) { |
| 3418 | startAppFreezingScreenLocked(wtoken, |
| 3419 | ActivityInfo.CONFIG_ORIENTATION); |
| 3420 | } |
| 3421 | } |
| 3422 | config = computeNewConfigurationLocked(); |
| 3423 | |
| 3424 | } else if (currentConfig != null) { |
| 3425 | // No obvious action we need to take, but if our current |
| Casey Burkhardt | 0920ba5 | 2010-08-03 12:04:19 -0700 | [diff] [blame] | 3426 | // state mismatches the activity manager's, update it, |
| 3427 | // disregarding font scale, which should remain set to |
| 3428 | // the value of the previous configuration. |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3429 | mTempConfiguration.setToDefaults(); |
| Casey Burkhardt | 0920ba5 | 2010-08-03 12:04:19 -0700 | [diff] [blame] | 3430 | mTempConfiguration.fontScale = currentConfig.fontScale; |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3431 | if (computeNewConfigurationLocked(mTempConfiguration)) { |
| 3432 | if (currentConfig.diff(mTempConfiguration) != 0) { |
| 3433 | mWaitingForConfig = true; |
| 3434 | mLayoutNeeded = true; |
| 3435 | startFreezingDisplayLocked(); |
| 3436 | config = new Configuration(mTempConfiguration); |
| 3437 | } |
| 3438 | } |
| 3439 | } |
| 3440 | } |
| 3441 | |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3442 | Binder.restoreCallingIdentity(ident); |
| 3443 | return config; |
| 3444 | } |
| 3445 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3446 | /* |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3447 | * Determine the new desired orientation of the display, returning |
| 3448 | * a non-null new Configuration if it has changed from the current |
| 3449 | * orientation. IF TRUE IS RETURNED SOMEONE MUST CALL |
| 3450 | * setNewConfiguration() TO TELL THE WINDOW MANAGER IT CAN UNFREEZE THE |
| 3451 | * SCREEN. This will typically be done for you if you call |
| 3452 | * sendNewConfiguration(). |
| 3453 | * |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3454 | * The orientation is computed from non-application windows first. If none of |
| 3455 | * the non-application windows specify orientation, the orientation is computed from |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3456 | * application tokens. |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3457 | * @see android.view.IWindowManager#updateOrientationFromAppTokens( |
| 3458 | * android.os.IBinder) |
| 3459 | */ |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3460 | boolean updateOrientationFromAppTokensLocked() { |
| Christopher Tate | b696aee | 2010-04-02 19:08:30 -0700 | [diff] [blame] | 3461 | if (mDisplayFrozen) { |
| 3462 | // If the display is frozen, some activities may be in the middle |
| 3463 | // of restarting, and thus have removed their old window. If the |
| 3464 | // window has the flag to hide the lock screen, then the lock screen |
| 3465 | // can re-appear and inflict its own orientation on us. Keep the |
| 3466 | // orientation stable until this all settles down. |
| 3467 | return false; |
| 3468 | } |
| 3469 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3470 | boolean changed = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3471 | long ident = Binder.clearCallingIdentity(); |
| 3472 | try { |
| The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 3473 | int req = computeForcedAppOrientationLocked(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3474 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3475 | if (req != mForcedAppOrientation) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3476 | mForcedAppOrientation = req; |
| 3477 | //send a message to Policy indicating orientation change to take |
| 3478 | //action like disabling/enabling sensors etc., |
| The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 3479 | mPolicy.setCurrentOrientationLw(req); |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3480 | if (setRotationUncheckedLocked(WindowManagerPolicy.USE_LAST_ROTATION, |
| 3481 | mLastRotationFlags | Surface.FLAGS_ORIENTATION_ANIMATION_DISABLE)) { |
| 3482 | changed = true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3483 | } |
| 3484 | } |
| The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3485 | |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3486 | return changed; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3487 | } finally { |
| 3488 | Binder.restoreCallingIdentity(ident); |
| 3489 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3490 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3491 | |
| The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 3492 | int computeForcedAppOrientationLocked() { |
| 3493 | int req = getOrientationFromWindowsLocked(); |
| 3494 | if (req == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) { |
| 3495 | req = getOrientationFromAppTokensLocked(); |
| 3496 | } |
| 3497 | return req; |
| 3498 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3499 | |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3500 | public void setNewConfiguration(Configuration config) { |
| 3501 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3502 | "setNewConfiguration()")) { |
| 3503 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| 3504 | } |
| 3505 | |
| 3506 | synchronized(mWindowMap) { |
| 3507 | mCurConfiguration = new Configuration(config); |
| 3508 | mWaitingForConfig = false; |
| 3509 | performLayoutAndPlaceSurfacesLocked(); |
| 3510 | } |
| 3511 | } |
| 3512 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3513 | public void setAppOrientation(IApplicationToken token, int requestedOrientation) { |
| 3514 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3515 | "setAppOrientation()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3516 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3517 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3518 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3519 | synchronized(mWindowMap) { |
| 3520 | AppWindowToken wtoken = findAppWindowToken(token.asBinder()); |
| 3521 | if (wtoken == null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3522 | 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] | 3523 | return; |
| 3524 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3525 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3526 | wtoken.requestedOrientation = requestedOrientation; |
| 3527 | } |
| 3528 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3529 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3530 | public int getAppOrientation(IApplicationToken token) { |
| 3531 | synchronized(mWindowMap) { |
| 3532 | AppWindowToken wtoken = findAppWindowToken(token.asBinder()); |
| 3533 | if (wtoken == null) { |
| 3534 | return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
| 3535 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3536 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3537 | return wtoken.requestedOrientation; |
| 3538 | } |
| 3539 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3540 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3541 | public void setFocusedApp(IBinder token, boolean moveFocusNow) { |
| 3542 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3543 | "setFocusedApp()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3544 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3545 | } |
| 3546 | |
| 3547 | synchronized(mWindowMap) { |
| 3548 | boolean changed = false; |
| 3549 | if (token == null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3550 | 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] | 3551 | changed = mFocusedApp != null; |
| 3552 | mFocusedApp = null; |
| Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 3553 | if (changed) { |
| 3554 | mInputMonitor.setFocusedAppLw(null); |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 3555 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3556 | } else { |
| 3557 | AppWindowToken newFocus = findAppWindowToken(token); |
| 3558 | if (newFocus == null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3559 | 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] | 3560 | return; |
| 3561 | } |
| 3562 | changed = mFocusedApp != newFocus; |
| 3563 | mFocusedApp = newFocus; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3564 | if (DEBUG_FOCUS) Slog.v(TAG, "Set focused app to: " + mFocusedApp); |
| Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 3565 | if (changed) { |
| 3566 | mInputMonitor.setFocusedAppLw(newFocus); |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 3567 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3568 | } |
| 3569 | |
| 3570 | if (moveFocusNow && changed) { |
| 3571 | final long origId = Binder.clearCallingIdentity(); |
| 3572 | updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL); |
| 3573 | Binder.restoreCallingIdentity(origId); |
| 3574 | } |
| 3575 | } |
| 3576 | } |
| 3577 | |
| 3578 | public void prepareAppTransition(int transit) { |
| 3579 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3580 | "prepareAppTransition()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3581 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3582 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3583 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3584 | synchronized(mWindowMap) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3585 | if (DEBUG_APP_TRANSITIONS) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3586 | TAG, "Prepare app transition: transit=" + transit |
| 3587 | + " mNextAppTransition=" + mNextAppTransition); |
| Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 3588 | if (!mDisplayFrozen && mPolicy.isScreenOn()) { |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 3589 | if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET |
| 3590 | || mNextAppTransition == WindowManagerPolicy.TRANSIT_NONE) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3591 | mNextAppTransition = transit; |
| Dianne Hackborn | d7cd29d | 2009-07-01 11:22:45 -0700 | [diff] [blame] | 3592 | } else if (transit == WindowManagerPolicy.TRANSIT_TASK_OPEN |
| 3593 | && mNextAppTransition == WindowManagerPolicy.TRANSIT_TASK_CLOSE) { |
| 3594 | // Opening a new task always supersedes a close for the anim. |
| 3595 | mNextAppTransition = transit; |
| 3596 | } else if (transit == WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN |
| 3597 | && mNextAppTransition == WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE) { |
| 3598 | // Opening a new activity always supersedes a close for the anim. |
| 3599 | mNextAppTransition = transit; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3600 | } |
| 3601 | mAppTransitionReady = false; |
| 3602 | mAppTransitionTimeout = false; |
| 3603 | mStartingIconInTransition = false; |
| 3604 | mSkipAppTransitionAnimation = false; |
| 3605 | mH.removeMessages(H.APP_TRANSITION_TIMEOUT); |
| 3606 | mH.sendMessageDelayed(mH.obtainMessage(H.APP_TRANSITION_TIMEOUT), |
| 3607 | 5000); |
| 3608 | } |
| 3609 | } |
| 3610 | } |
| 3611 | |
| 3612 | public int getPendingAppTransition() { |
| 3613 | return mNextAppTransition; |
| 3614 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3615 | |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 3616 | public void overridePendingAppTransition(String packageName, |
| 3617 | int enterAnim, int exitAnim) { |
| Dianne Hackborn | 8b571a8 | 2009-09-25 16:09:43 -0700 | [diff] [blame] | 3618 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 3619 | mNextAppTransitionPackage = packageName; |
| 3620 | mNextAppTransitionEnter = enterAnim; |
| 3621 | mNextAppTransitionExit = exitAnim; |
| 3622 | } |
| 3623 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3624 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3625 | public void executeAppTransition() { |
| 3626 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3627 | "executeAppTransition()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3628 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3629 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3630 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3631 | synchronized(mWindowMap) { |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 3632 | if (DEBUG_APP_TRANSITIONS) { |
| 3633 | RuntimeException e = new RuntimeException("here"); |
| 3634 | e.fillInStackTrace(); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3635 | Slog.w(TAG, "Execute app transition: mNextAppTransition=" |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 3636 | + mNextAppTransition, e); |
| 3637 | } |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 3638 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3639 | mAppTransitionReady = true; |
| 3640 | final long origId = Binder.clearCallingIdentity(); |
| 3641 | performLayoutAndPlaceSurfacesLocked(); |
| 3642 | Binder.restoreCallingIdentity(origId); |
| 3643 | } |
| 3644 | } |
| 3645 | } |
| 3646 | |
| 3647 | public void setAppStartingWindow(IBinder token, String pkg, |
| 3648 | int theme, CharSequence nonLocalizedLabel, int labelRes, int icon, |
| 3649 | IBinder transferFrom, boolean createIfNeeded) { |
| 3650 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3651 | "setAppStartingIcon()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3652 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3653 | } |
| 3654 | |
| 3655 | synchronized(mWindowMap) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3656 | if (DEBUG_STARTING_WINDOW) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3657 | TAG, "setAppStartingIcon: token=" + token + " pkg=" + pkg |
| 3658 | + " transferFrom=" + transferFrom); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3659 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3660 | AppWindowToken wtoken = findAppWindowToken(token); |
| 3661 | if (wtoken == null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3662 | 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] | 3663 | return; |
| 3664 | } |
| 3665 | |
| 3666 | // If the display is frozen, we won't do anything until the |
| 3667 | // actual window is displayed so there is no reason to put in |
| 3668 | // the starting window. |
| Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 3669 | if (mDisplayFrozen || !mPolicy.isScreenOn()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3670 | return; |
| 3671 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3672 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3673 | if (wtoken.startingData != null) { |
| 3674 | return; |
| 3675 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3676 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3677 | if (transferFrom != null) { |
| 3678 | AppWindowToken ttoken = findAppWindowToken(transferFrom); |
| 3679 | if (ttoken != null) { |
| 3680 | WindowState startingWindow = ttoken.startingWindow; |
| 3681 | if (startingWindow != null) { |
| 3682 | if (mStartingIconInTransition) { |
| 3683 | // In this case, the starting icon has already |
| 3684 | // been displayed, so start letting windows get |
| 3685 | // shown immediately without any more transitions. |
| 3686 | mSkipAppTransitionAnimation = true; |
| 3687 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3688 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3689 | "Moving existing starting from " + ttoken |
| 3690 | + " to " + wtoken); |
| 3691 | final long origId = Binder.clearCallingIdentity(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3692 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3693 | // Transfer the starting window over to the new |
| 3694 | // token. |
| 3695 | wtoken.startingData = ttoken.startingData; |
| 3696 | wtoken.startingView = ttoken.startingView; |
| 3697 | wtoken.startingWindow = startingWindow; |
| 3698 | ttoken.startingData = null; |
| 3699 | ttoken.startingView = null; |
| 3700 | ttoken.startingWindow = null; |
| 3701 | ttoken.startingMoved = true; |
| 3702 | startingWindow.mToken = wtoken; |
| Dianne Hackborn | ef49c57 | 2009-03-24 19:27:32 -0700 | [diff] [blame] | 3703 | startingWindow.mRootToken = wtoken; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3704 | startingWindow.mAppToken = wtoken; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3705 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 3706 | "Removing starting window: " + startingWindow); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3707 | mWindows.remove(startingWindow); |
| Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 3708 | mWindowsChanged = true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3709 | ttoken.windows.remove(startingWindow); |
| 3710 | ttoken.allAppWindows.remove(startingWindow); |
| 3711 | addWindowToListInOrderLocked(startingWindow, true); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3712 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3713 | // Propagate other interesting state between the |
| 3714 | // tokens. If the old token is displayed, we should |
| 3715 | // immediately force the new one to be displayed. If |
| 3716 | // it is animating, we need to move that animation to |
| 3717 | // the new one. |
| 3718 | if (ttoken.allDrawn) { |
| 3719 | wtoken.allDrawn = true; |
| 3720 | } |
| 3721 | if (ttoken.firstWindowDrawn) { |
| 3722 | wtoken.firstWindowDrawn = true; |
| 3723 | } |
| 3724 | if (!ttoken.hidden) { |
| 3725 | wtoken.hidden = false; |
| 3726 | wtoken.hiddenRequested = false; |
| 3727 | wtoken.willBeHidden = false; |
| 3728 | } |
| 3729 | if (wtoken.clientHidden != ttoken.clientHidden) { |
| 3730 | wtoken.clientHidden = ttoken.clientHidden; |
| 3731 | wtoken.sendAppVisibilityToClients(); |
| 3732 | } |
| 3733 | if (ttoken.animation != null) { |
| 3734 | wtoken.animation = ttoken.animation; |
| 3735 | wtoken.animating = ttoken.animating; |
| 3736 | wtoken.animLayerAdjustment = ttoken.animLayerAdjustment; |
| 3737 | ttoken.animation = null; |
| 3738 | ttoken.animLayerAdjustment = 0; |
| 3739 | wtoken.updateLayers(); |
| 3740 | ttoken.updateLayers(); |
| 3741 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3742 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3743 | updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3744 | mLayoutNeeded = true; |
| 3745 | performLayoutAndPlaceSurfacesLocked(); |
| 3746 | Binder.restoreCallingIdentity(origId); |
| 3747 | return; |
| 3748 | } else if (ttoken.startingData != null) { |
| 3749 | // The previous app was getting ready to show a |
| 3750 | // starting window, but hasn't yet done so. Steal it! |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3751 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3752 | "Moving pending starting from " + ttoken |
| 3753 | + " to " + wtoken); |
| 3754 | wtoken.startingData = ttoken.startingData; |
| 3755 | ttoken.startingData = null; |
| 3756 | ttoken.startingMoved = true; |
| 3757 | Message m = mH.obtainMessage(H.ADD_STARTING, wtoken); |
| 3758 | // Note: we really want to do sendMessageAtFrontOfQueue() because we |
| 3759 | // want to process the message ASAP, before any other queued |
| 3760 | // messages. |
| 3761 | mH.sendMessageAtFrontOfQueue(m); |
| 3762 | return; |
| 3763 | } |
| 3764 | } |
| 3765 | } |
| 3766 | |
| 3767 | // There is no existing starting window, and the caller doesn't |
| 3768 | // want us to create one, so that's it! |
| 3769 | if (!createIfNeeded) { |
| 3770 | return; |
| 3771 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3772 | |
| Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 3773 | // If this is a translucent or wallpaper window, then don't |
| 3774 | // show a starting window -- the current effect (a full-screen |
| 3775 | // opaque starting window that fades away to the real contents |
| 3776 | // when it is ready) does not work for this. |
| 3777 | if (theme != 0) { |
| 3778 | AttributeCache.Entry ent = AttributeCache.instance().get(pkg, theme, |
| 3779 | com.android.internal.R.styleable.Window); |
| 3780 | if (ent.array.getBoolean( |
| 3781 | com.android.internal.R.styleable.Window_windowIsTranslucent, false)) { |
| 3782 | return; |
| 3783 | } |
| 3784 | if (ent.array.getBoolean( |
| Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 3785 | com.android.internal.R.styleable.Window_windowIsFloating, false)) { |
| 3786 | return; |
| 3787 | } |
| 3788 | if (ent.array.getBoolean( |
| Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 3789 | com.android.internal.R.styleable.Window_windowShowWallpaper, false)) { |
| 3790 | return; |
| 3791 | } |
| 3792 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3793 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3794 | mStartingIconInTransition = true; |
| 3795 | wtoken.startingData = new StartingData( |
| 3796 | pkg, theme, nonLocalizedLabel, |
| 3797 | labelRes, icon); |
| 3798 | Message m = mH.obtainMessage(H.ADD_STARTING, wtoken); |
| 3799 | // Note: we really want to do sendMessageAtFrontOfQueue() because we |
| 3800 | // want to process the message ASAP, before any other queued |
| 3801 | // messages. |
| 3802 | mH.sendMessageAtFrontOfQueue(m); |
| 3803 | } |
| 3804 | } |
| 3805 | |
| 3806 | public void setAppWillBeHidden(IBinder token) { |
| 3807 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3808 | "setAppWillBeHidden()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3809 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3810 | } |
| 3811 | |
| 3812 | AppWindowToken wtoken; |
| 3813 | |
| 3814 | synchronized(mWindowMap) { |
| 3815 | wtoken = findAppWindowToken(token); |
| 3816 | if (wtoken == null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3817 | 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] | 3818 | return; |
| 3819 | } |
| 3820 | wtoken.willBeHidden = true; |
| 3821 | } |
| 3822 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3823 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3824 | boolean setTokenVisibilityLocked(AppWindowToken wtoken, WindowManager.LayoutParams lp, |
| 3825 | boolean visible, int transit, boolean performLayout) { |
| 3826 | boolean delayed = false; |
| 3827 | |
| 3828 | if (wtoken.clientHidden == visible) { |
| 3829 | wtoken.clientHidden = !visible; |
| 3830 | wtoken.sendAppVisibilityToClients(); |
| 3831 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3832 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3833 | wtoken.willBeHidden = false; |
| 3834 | if (wtoken.hidden == visible) { |
| 3835 | final int N = wtoken.allAppWindows.size(); |
| 3836 | boolean changed = false; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3837 | if (DEBUG_APP_TRANSITIONS) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3838 | TAG, "Changing app " + wtoken + " hidden=" + wtoken.hidden |
| 3839 | + " performLayout=" + performLayout); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3840 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3841 | boolean runningAppAnimation = false; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3842 | |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 3843 | if (transit != WindowManagerPolicy.TRANSIT_UNSET) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3844 | if (wtoken.animation == sDummyAnimation) { |
| 3845 | wtoken.animation = null; |
| 3846 | } |
| 3847 | applyAnimationLocked(wtoken, lp, transit, visible); |
| 3848 | changed = true; |
| 3849 | if (wtoken.animation != null) { |
| 3850 | delayed = runningAppAnimation = true; |
| 3851 | } |
| 3852 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3853 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3854 | for (int i=0; i<N; i++) { |
| 3855 | WindowState win = wtoken.allAppWindows.get(i); |
| 3856 | if (win == wtoken.startingWindow) { |
| 3857 | continue; |
| 3858 | } |
| 3859 | |
| 3860 | if (win.isAnimating()) { |
| 3861 | delayed = true; |
| 3862 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3863 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3864 | //Slog.i(TAG, "Window " + win + ": vis=" + win.isVisible()); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3865 | //win.dump(" "); |
| 3866 | if (visible) { |
| 3867 | if (!win.isVisibleNow()) { |
| 3868 | if (!runningAppAnimation) { |
| 3869 | applyAnimationLocked(win, |
| 3870 | WindowManagerPolicy.TRANSIT_ENTER, true); |
| 3871 | } |
| 3872 | changed = true; |
| 3873 | } |
| 3874 | } else if (win.isVisibleNow()) { |
| 3875 | if (!runningAppAnimation) { |
| 3876 | applyAnimationLocked(win, |
| 3877 | WindowManagerPolicy.TRANSIT_EXIT, false); |
| 3878 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3879 | changed = true; |
| 3880 | } |
| 3881 | } |
| 3882 | |
| 3883 | wtoken.hidden = wtoken.hiddenRequested = !visible; |
| 3884 | if (!visible) { |
| 3885 | unsetAppFreezingScreenLocked(wtoken, true, true); |
| 3886 | } else { |
| 3887 | // If we are being set visible, and the starting window is |
| 3888 | // not yet displayed, then make sure it doesn't get displayed. |
| 3889 | WindowState swin = wtoken.startingWindow; |
| 3890 | if (swin != null && (swin.mDrawPending |
| 3891 | || swin.mCommitDrawPending)) { |
| 3892 | swin.mPolicyVisibility = false; |
| 3893 | swin.mPolicyVisibilityAfterAnim = false; |
| 3894 | } |
| 3895 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3896 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3897 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "setTokenVisibilityLocked: " + wtoken |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3898 | + ": hidden=" + wtoken.hidden + " hiddenRequested=" |
| 3899 | + wtoken.hiddenRequested); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3900 | |
| Dianne Hackborn | 9b52a21 | 2009-12-11 14:51:35 -0800 | [diff] [blame] | 3901 | if (changed) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3902 | mLayoutNeeded = true; |
| Dianne Hackborn | 9b52a21 | 2009-12-11 14:51:35 -0800 | [diff] [blame] | 3903 | if (performLayout) { |
| 3904 | updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES); |
| 3905 | performLayoutAndPlaceSurfacesLocked(); |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 3906 | } else { |
| 3907 | mInputMonitor.updateInputWindowsLw(); |
| Dianne Hackborn | 9b52a21 | 2009-12-11 14:51:35 -0800 | [diff] [blame] | 3908 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3909 | } |
| 3910 | } |
| 3911 | |
| 3912 | if (wtoken.animation != null) { |
| 3913 | delayed = true; |
| 3914 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3915 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3916 | return delayed; |
| 3917 | } |
| 3918 | |
| 3919 | public void setAppVisibility(IBinder token, boolean visible) { |
| 3920 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3921 | "setAppVisibility()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3922 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3923 | } |
| 3924 | |
| 3925 | AppWindowToken wtoken; |
| 3926 | |
| 3927 | synchronized(mWindowMap) { |
| 3928 | wtoken = findAppWindowToken(token); |
| 3929 | if (wtoken == null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3930 | 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] | 3931 | return; |
| 3932 | } |
| 3933 | |
| 3934 | if (DEBUG_APP_TRANSITIONS || DEBUG_ORIENTATION) { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 3935 | RuntimeException e = null; |
| 3936 | if (!HIDE_STACK_CRAWLS) { |
| 3937 | e = new RuntimeException(); |
| 3938 | e.fillInStackTrace(); |
| 3939 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3940 | Slog.v(TAG, "setAppVisibility(" + token + ", " + visible |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3941 | + "): mNextAppTransition=" + mNextAppTransition |
| 3942 | + " hidden=" + wtoken.hidden |
| 3943 | + " hiddenRequested=" + wtoken.hiddenRequested, e); |
| 3944 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3945 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3946 | // If we are preparing an app transition, then delay changing |
| 3947 | // the visibility of this token until we execute that transition. |
| Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 3948 | if (!mDisplayFrozen && mPolicy.isScreenOn() |
| 3949 | && mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3950 | // Already in requested state, don't do anything more. |
| 3951 | if (wtoken.hiddenRequested != visible) { |
| 3952 | return; |
| 3953 | } |
| 3954 | wtoken.hiddenRequested = !visible; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3955 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3956 | if (DEBUG_APP_TRANSITIONS) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3957 | TAG, "Setting dummy animation on: " + wtoken); |
| 3958 | wtoken.setDummyAnimation(); |
| 3959 | mOpeningApps.remove(wtoken); |
| 3960 | mClosingApps.remove(wtoken); |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 3961 | wtoken.waitingToShow = wtoken.waitingToHide = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3962 | wtoken.inPendingTransaction = true; |
| 3963 | if (visible) { |
| 3964 | mOpeningApps.add(wtoken); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3965 | wtoken.startingDisplayed = false; |
| 3966 | wtoken.startingMoved = false; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3967 | |
| Dianne Hackborn | 195f6a0 | 2009-11-24 11:26:00 -0800 | [diff] [blame] | 3968 | // If the token is currently hidden (should be the |
| 3969 | // common case), then we need to set up to wait for |
| 3970 | // its windows to be ready. |
| 3971 | if (wtoken.hidden) { |
| 3972 | wtoken.allDrawn = false; |
| 3973 | wtoken.waitingToShow = true; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3974 | |
| Dianne Hackborn | 195f6a0 | 2009-11-24 11:26:00 -0800 | [diff] [blame] | 3975 | if (wtoken.clientHidden) { |
| 3976 | // In the case where we are making an app visible |
| 3977 | // but holding off for a transition, we still need |
| 3978 | // to tell the client to make its windows visible so |
| 3979 | // they get drawn. Otherwise, we will wait on |
| 3980 | // performing the transition until all windows have |
| 3981 | // been drawn, they never will be, and we are sad. |
| 3982 | wtoken.clientHidden = false; |
| 3983 | wtoken.sendAppVisibilityToClients(); |
| 3984 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3985 | } |
| 3986 | } else { |
| 3987 | mClosingApps.add(wtoken); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3988 | |
| Dianne Hackborn | 195f6a0 | 2009-11-24 11:26:00 -0800 | [diff] [blame] | 3989 | // If the token is currently visible (should be the |
| 3990 | // common case), then set up to wait for it to be hidden. |
| 3991 | if (!wtoken.hidden) { |
| 3992 | wtoken.waitingToHide = true; |
| 3993 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3994 | } |
| 3995 | return; |
| 3996 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3997 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3998 | final long origId = Binder.clearCallingIdentity(); |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 3999 | setTokenVisibilityLocked(wtoken, null, visible, WindowManagerPolicy.TRANSIT_UNSET, true); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4000 | wtoken.updateReportedVisibilityLocked(); |
| 4001 | Binder.restoreCallingIdentity(origId); |
| 4002 | } |
| 4003 | } |
| 4004 | |
| 4005 | void unsetAppFreezingScreenLocked(AppWindowToken wtoken, |
| 4006 | boolean unfreezeSurfaceNow, boolean force) { |
| 4007 | if (wtoken.freezingScreen) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4008 | 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] | 4009 | + " force=" + force); |
| 4010 | final int N = wtoken.allAppWindows.size(); |
| 4011 | boolean unfrozeWindows = false; |
| 4012 | for (int i=0; i<N; i++) { |
| 4013 | WindowState w = wtoken.allAppWindows.get(i); |
| 4014 | if (w.mAppFreezing) { |
| 4015 | w.mAppFreezing = false; |
| 4016 | if (w.mSurface != null && !w.mOrientationChanging) { |
| 4017 | w.mOrientationChanging = true; |
| 4018 | } |
| 4019 | unfrozeWindows = true; |
| 4020 | } |
| 4021 | } |
| 4022 | if (force || unfrozeWindows) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4023 | 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] | 4024 | wtoken.freezingScreen = false; |
| 4025 | mAppsFreezingScreen--; |
| 4026 | } |
| 4027 | if (unfreezeSurfaceNow) { |
| 4028 | if (unfrozeWindows) { |
| 4029 | mLayoutNeeded = true; |
| 4030 | performLayoutAndPlaceSurfacesLocked(); |
| 4031 | } |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 4032 | stopFreezingDisplayLocked(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4033 | } |
| 4034 | } |
| 4035 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4036 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4037 | public void startAppFreezingScreenLocked(AppWindowToken wtoken, |
| 4038 | int configChanges) { |
| 4039 | if (DEBUG_ORIENTATION) { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 4040 | RuntimeException e = null; |
| 4041 | if (!HIDE_STACK_CRAWLS) { |
| 4042 | e = new RuntimeException(); |
| 4043 | e.fillInStackTrace(); |
| 4044 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4045 | Slog.i(TAG, "Set freezing of " + wtoken.appToken |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4046 | + ": hidden=" + wtoken.hidden + " freezing=" |
| 4047 | + wtoken.freezingScreen, e); |
| 4048 | } |
| 4049 | if (!wtoken.hiddenRequested) { |
| 4050 | if (!wtoken.freezingScreen) { |
| 4051 | wtoken.freezingScreen = true; |
| 4052 | mAppsFreezingScreen++; |
| 4053 | if (mAppsFreezingScreen == 1) { |
| 4054 | startFreezingDisplayLocked(); |
| 4055 | mH.removeMessages(H.APP_FREEZE_TIMEOUT); |
| 4056 | mH.sendMessageDelayed(mH.obtainMessage(H.APP_FREEZE_TIMEOUT), |
| 4057 | 5000); |
| 4058 | } |
| 4059 | } |
| 4060 | final int N = wtoken.allAppWindows.size(); |
| 4061 | for (int i=0; i<N; i++) { |
| 4062 | WindowState w = wtoken.allAppWindows.get(i); |
| 4063 | w.mAppFreezing = true; |
| 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 startAppFreezingScreen(IBinder token, int configChanges) { |
| 4069 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 4070 | "setAppFreezingScreen()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4071 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4072 | } |
| 4073 | |
| 4074 | synchronized(mWindowMap) { |
| Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 4075 | if (configChanges == 0 && !mDisplayFrozen && mPolicy.isScreenOn()) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4076 | 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] | 4077 | return; |
| 4078 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4079 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4080 | AppWindowToken wtoken = findAppWindowToken(token); |
| 4081 | if (wtoken == null || wtoken.appToken == null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4082 | 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] | 4083 | return; |
| 4084 | } |
| 4085 | final long origId = Binder.clearCallingIdentity(); |
| 4086 | startAppFreezingScreenLocked(wtoken, configChanges); |
| 4087 | Binder.restoreCallingIdentity(origId); |
| 4088 | } |
| 4089 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4090 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4091 | public void stopAppFreezingScreen(IBinder token, boolean force) { |
| 4092 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 4093 | "setAppFreezingScreen()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4094 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4095 | } |
| 4096 | |
| 4097 | synchronized(mWindowMap) { |
| 4098 | AppWindowToken wtoken = findAppWindowToken(token); |
| 4099 | if (wtoken == null || wtoken.appToken == null) { |
| 4100 | return; |
| 4101 | } |
| 4102 | final long origId = Binder.clearCallingIdentity(); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4103 | 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] | 4104 | + ": hidden=" + wtoken.hidden + " freezing=" + wtoken.freezingScreen); |
| 4105 | unsetAppFreezingScreenLocked(wtoken, true, force); |
| 4106 | Binder.restoreCallingIdentity(origId); |
| 4107 | } |
| 4108 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4109 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4110 | public void removeAppToken(IBinder token) { |
| 4111 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 4112 | "removeAppToken()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4113 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4114 | } |
| 4115 | |
| 4116 | AppWindowToken wtoken = null; |
| 4117 | AppWindowToken startingToken = null; |
| 4118 | boolean delayed = false; |
| 4119 | |
| 4120 | final long origId = Binder.clearCallingIdentity(); |
| 4121 | synchronized(mWindowMap) { |
| 4122 | WindowToken basewtoken = mTokenMap.remove(token); |
| 4123 | mTokenList.remove(basewtoken); |
| 4124 | if (basewtoken != null && (wtoken=basewtoken.appWindowToken) != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4125 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "Removing app token: " + wtoken); |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 4126 | delayed = setTokenVisibilityLocked(wtoken, null, false, WindowManagerPolicy.TRANSIT_UNSET, true); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4127 | wtoken.inPendingTransaction = false; |
| 4128 | mOpeningApps.remove(wtoken); |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4129 | wtoken.waitingToShow = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4130 | if (mClosingApps.contains(wtoken)) { |
| 4131 | delayed = true; |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 4132 | } else if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4133 | mClosingApps.add(wtoken); |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4134 | wtoken.waitingToHide = true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4135 | delayed = true; |
| 4136 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4137 | if (DEBUG_APP_TRANSITIONS) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4138 | TAG, "Removing app " + wtoken + " delayed=" + delayed |
| 4139 | + " animation=" + wtoken.animation |
| 4140 | + " animating=" + wtoken.animating); |
| 4141 | if (delayed) { |
| 4142 | // set the token aside because it has an active animation to be finished |
| 4143 | mExitingAppTokens.add(wtoken); |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 4144 | } else { |
| 4145 | // Make sure there is no animation running on this token, |
| 4146 | // so any windows associated with it will be removed as |
| 4147 | // soon as their animations are complete |
| 4148 | wtoken.animation = null; |
| 4149 | wtoken.animating = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4150 | } |
| 4151 | mAppTokens.remove(wtoken); |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 4152 | if (mLastEnterAnimToken == wtoken) { |
| 4153 | mLastEnterAnimToken = null; |
| 4154 | mLastEnterAnimParams = null; |
| 4155 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4156 | wtoken.removed = true; |
| 4157 | if (wtoken.startingData != null) { |
| 4158 | startingToken = wtoken; |
| 4159 | } |
| 4160 | unsetAppFreezingScreenLocked(wtoken, true, true); |
| 4161 | if (mFocusedApp == wtoken) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4162 | 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] | 4163 | mFocusedApp = null; |
| 4164 | updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL); |
| Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 4165 | mInputMonitor.setFocusedAppLw(null); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4166 | } |
| 4167 | } else { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4168 | 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] | 4169 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4170 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4171 | if (!delayed && wtoken != null) { |
| 4172 | wtoken.updateReportedVisibilityLocked(); |
| 4173 | } |
| 4174 | } |
| 4175 | Binder.restoreCallingIdentity(origId); |
| 4176 | |
| 4177 | if (startingToken != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4178 | 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] | 4179 | + startingToken + ": app token removed"); |
| 4180 | Message m = mH.obtainMessage(H.REMOVE_STARTING, startingToken); |
| 4181 | mH.sendMessage(m); |
| 4182 | } |
| 4183 | } |
| 4184 | |
| 4185 | private boolean tmpRemoveAppWindowsLocked(WindowToken token) { |
| 4186 | final int NW = token.windows.size(); |
| 4187 | for (int i=0; i<NW; i++) { |
| 4188 | WindowState win = token.windows.get(i); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4189 | 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] | 4190 | mWindows.remove(win); |
| Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 4191 | mWindowsChanged = true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4192 | int j = win.mChildWindows.size(); |
| 4193 | while (j > 0) { |
| 4194 | j--; |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 4195 | WindowState cwin = win.mChildWindows.get(j); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4196 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, |
| Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 4197 | "Tmp removing child window " + cwin); |
| 4198 | mWindows.remove(cwin); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4199 | } |
| 4200 | } |
| 4201 | return NW > 0; |
| 4202 | } |
| 4203 | |
| 4204 | void dumpAppTokensLocked() { |
| 4205 | for (int i=mAppTokens.size()-1; i>=0; i--) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4206 | Slog.v(TAG, " #" + i + ": " + mAppTokens.get(i).token); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4207 | } |
| 4208 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4209 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4210 | void dumpWindowsLocked() { |
| 4211 | for (int i=mWindows.size()-1; i>=0; i--) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4212 | Slog.v(TAG, " #" + i + ": " + mWindows.get(i)); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4213 | } |
| 4214 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4215 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4216 | private int findWindowOffsetLocked(int tokenPos) { |
| 4217 | final int NW = mWindows.size(); |
| 4218 | |
| 4219 | if (tokenPos >= mAppTokens.size()) { |
| 4220 | int i = NW; |
| 4221 | while (i > 0) { |
| 4222 | i--; |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 4223 | WindowState win = mWindows.get(i); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4224 | if (win.getAppToken() != null) { |
| 4225 | return i+1; |
| 4226 | } |
| 4227 | } |
| 4228 | } |
| 4229 | |
| 4230 | while (tokenPos > 0) { |
| 4231 | // Find the first app token below the new position that has |
| 4232 | // a window displayed. |
| 4233 | final AppWindowToken wtoken = mAppTokens.get(tokenPos-1); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4234 | 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] | 4235 | + tokenPos + " -- " + wtoken.token); |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4236 | if (wtoken.sendingToBottom) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4237 | if (DEBUG_REORDER) Slog.v(TAG, |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4238 | "Skipping token -- currently sending to bottom"); |
| 4239 | tokenPos--; |
| 4240 | continue; |
| 4241 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4242 | int i = wtoken.windows.size(); |
| 4243 | while (i > 0) { |
| 4244 | i--; |
| 4245 | WindowState win = wtoken.windows.get(i); |
| 4246 | int j = win.mChildWindows.size(); |
| 4247 | while (j > 0) { |
| 4248 | j--; |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 4249 | WindowState cwin = win.mChildWindows.get(j); |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4250 | if (cwin.mSubLayer >= 0) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4251 | for (int pos=NW-1; pos>=0; pos--) { |
| 4252 | if (mWindows.get(pos) == cwin) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4253 | if (DEBUG_REORDER) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4254 | "Found child win @" + (pos+1)); |
| 4255 | return pos+1; |
| 4256 | } |
| 4257 | } |
| 4258 | } |
| 4259 | } |
| 4260 | for (int pos=NW-1; pos>=0; pos--) { |
| 4261 | if (mWindows.get(pos) == win) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4262 | 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] | 4263 | return pos+1; |
| 4264 | } |
| 4265 | } |
| 4266 | } |
| 4267 | tokenPos--; |
| 4268 | } |
| 4269 | |
| 4270 | return 0; |
| 4271 | } |
| 4272 | |
| 4273 | private final int reAddWindowLocked(int index, WindowState win) { |
| 4274 | final int NCW = win.mChildWindows.size(); |
| 4275 | boolean added = false; |
| 4276 | for (int j=0; j<NCW; j++) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 4277 | WindowState cwin = win.mChildWindows.get(j); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4278 | if (!added && cwin.mSubLayer >= 0) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4279 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding child window at " |
| Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 4280 | + index + ": " + cwin); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4281 | mWindows.add(index, win); |
| 4282 | index++; |
| 4283 | added = true; |
| 4284 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4285 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding window at " |
| Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 4286 | + index + ": " + cwin); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4287 | mWindows.add(index, cwin); |
| 4288 | index++; |
| 4289 | } |
| 4290 | if (!added) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4291 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding window at " |
| Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 4292 | + index + ": " + win); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4293 | mWindows.add(index, win); |
| 4294 | index++; |
| 4295 | } |
| Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 4296 | mWindowsChanged = true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4297 | return index; |
| 4298 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4299 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4300 | private final int reAddAppWindowsLocked(int index, WindowToken token) { |
| 4301 | final int NW = token.windows.size(); |
| 4302 | for (int i=0; i<NW; i++) { |
| 4303 | index = reAddWindowLocked(index, token.windows.get(i)); |
| 4304 | } |
| 4305 | return index; |
| 4306 | } |
| 4307 | |
| 4308 | public void moveAppToken(int index, IBinder token) { |
| 4309 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 4310 | "moveAppToken()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4311 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4312 | } |
| 4313 | |
| 4314 | synchronized(mWindowMap) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4315 | if (DEBUG_REORDER) Slog.v(TAG, "Initial app tokens:"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4316 | if (DEBUG_REORDER) dumpAppTokensLocked(); |
| 4317 | final AppWindowToken wtoken = findAppWindowToken(token); |
| 4318 | if (wtoken == null || !mAppTokens.remove(wtoken)) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4319 | 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] | 4320 | + token + " (" + wtoken + ")"); |
| 4321 | return; |
| 4322 | } |
| 4323 | mAppTokens.add(index, wtoken); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4324 | 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] | 4325 | if (DEBUG_REORDER) dumpAppTokensLocked(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4326 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4327 | final long origId = Binder.clearCallingIdentity(); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4328 | 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] | 4329 | if (DEBUG_REORDER) dumpWindowsLocked(); |
| 4330 | if (tmpRemoveAppWindowsLocked(wtoken)) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4331 | 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] | 4332 | if (DEBUG_REORDER) dumpWindowsLocked(); |
| 4333 | reAddAppWindowsLocked(findWindowOffsetLocked(index), wtoken); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4334 | if (DEBUG_REORDER) Slog.v(TAG, "Final window list:"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4335 | if (DEBUG_REORDER) dumpWindowsLocked(); |
| 4336 | updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4337 | mLayoutNeeded = true; |
| 4338 | performLayoutAndPlaceSurfacesLocked(); |
| 4339 | } |
| 4340 | Binder.restoreCallingIdentity(origId); |
| 4341 | } |
| 4342 | } |
| 4343 | |
| 4344 | private void removeAppTokensLocked(List<IBinder> tokens) { |
| 4345 | // XXX This should be done more efficiently! |
| 4346 | // (take advantage of the fact that both lists should be |
| 4347 | // ordered in the same way.) |
| 4348 | int N = tokens.size(); |
| 4349 | for (int i=0; i<N; i++) { |
| 4350 | IBinder token = tokens.get(i); |
| 4351 | final AppWindowToken wtoken = findAppWindowToken(token); |
| 4352 | if (!mAppTokens.remove(wtoken)) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4353 | 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] | 4354 | + token + " (" + wtoken + ")"); |
| 4355 | i--; |
| 4356 | N--; |
| 4357 | } |
| 4358 | } |
| 4359 | } |
| 4360 | |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4361 | private void moveAppWindowsLocked(AppWindowToken wtoken, int tokenPos, |
| 4362 | boolean updateFocusAndLayout) { |
| 4363 | // First remove all of the windows from the list. |
| 4364 | tmpRemoveAppWindowsLocked(wtoken); |
| 4365 | |
| 4366 | // Where to start adding? |
| 4367 | int pos = findWindowOffsetLocked(tokenPos); |
| 4368 | |
| 4369 | // And now add them back at the correct place. |
| 4370 | pos = reAddAppWindowsLocked(pos, wtoken); |
| 4371 | |
| 4372 | if (updateFocusAndLayout) { |
| 4373 | if (!updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES)) { |
| 4374 | assignLayersLocked(); |
| 4375 | } |
| 4376 | mLayoutNeeded = true; |
| 4377 | performLayoutAndPlaceSurfacesLocked(); |
| 4378 | } |
| 4379 | } |
| 4380 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4381 | private void moveAppWindowsLocked(List<IBinder> tokens, int tokenPos) { |
| 4382 | // First remove all of the windows from the list. |
| 4383 | final int N = tokens.size(); |
| 4384 | int i; |
| 4385 | for (i=0; i<N; i++) { |
| 4386 | WindowToken token = mTokenMap.get(tokens.get(i)); |
| 4387 | if (token != null) { |
| 4388 | tmpRemoveAppWindowsLocked(token); |
| 4389 | } |
| 4390 | } |
| 4391 | |
| 4392 | // Where to start adding? |
| 4393 | int pos = findWindowOffsetLocked(tokenPos); |
| 4394 | |
| 4395 | // And now add them back at the correct place. |
| 4396 | for (i=0; i<N; i++) { |
| 4397 | WindowToken token = mTokenMap.get(tokens.get(i)); |
| 4398 | if (token != null) { |
| 4399 | pos = reAddAppWindowsLocked(pos, token); |
| 4400 | } |
| 4401 | } |
| 4402 | |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4403 | if (!updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES)) { |
| 4404 | assignLayersLocked(); |
| 4405 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4406 | mLayoutNeeded = true; |
| 4407 | performLayoutAndPlaceSurfacesLocked(); |
| 4408 | |
| 4409 | //dump(); |
| 4410 | } |
| 4411 | |
| 4412 | public void moveAppTokensToTop(List<IBinder> tokens) { |
| 4413 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 4414 | "moveAppTokensToTop()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4415 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4416 | } |
| 4417 | |
| 4418 | final long origId = Binder.clearCallingIdentity(); |
| 4419 | synchronized(mWindowMap) { |
| 4420 | removeAppTokensLocked(tokens); |
| 4421 | final int N = tokens.size(); |
| 4422 | for (int i=0; i<N; i++) { |
| 4423 | AppWindowToken wt = findAppWindowToken(tokens.get(i)); |
| 4424 | if (wt != null) { |
| 4425 | mAppTokens.add(wt); |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 4426 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4427 | mToTopApps.remove(wt); |
| 4428 | mToBottomApps.remove(wt); |
| 4429 | mToTopApps.add(wt); |
| 4430 | wt.sendingToBottom = false; |
| 4431 | wt.sendingToTop = true; |
| 4432 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4433 | } |
| 4434 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 4435 | |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 4436 | if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET) { |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4437 | moveAppWindowsLocked(tokens, mAppTokens.size()); |
| 4438 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4439 | } |
| 4440 | Binder.restoreCallingIdentity(origId); |
| 4441 | } |
| 4442 | |
| 4443 | public void moveAppTokensToBottom(List<IBinder> tokens) { |
| 4444 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 4445 | "moveAppTokensToBottom()")) { |
| 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 | int pos = 0; |
| 4454 | for (int i=0; i<N; i++) { |
| 4455 | AppWindowToken wt = findAppWindowToken(tokens.get(i)); |
| 4456 | if (wt != null) { |
| 4457 | mAppTokens.add(pos, wt); |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 4458 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4459 | mToTopApps.remove(wt); |
| 4460 | mToBottomApps.remove(wt); |
| 4461 | mToBottomApps.add(i, wt); |
| 4462 | wt.sendingToTop = false; |
| 4463 | wt.sendingToBottom = true; |
| 4464 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4465 | pos++; |
| 4466 | } |
| 4467 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 4468 | |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 4469 | if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET) { |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4470 | moveAppWindowsLocked(tokens, 0); |
| 4471 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4472 | } |
| 4473 | Binder.restoreCallingIdentity(origId); |
| 4474 | } |
| 4475 | |
| 4476 | // ------------------------------------------------------------- |
| 4477 | // Misc IWindowSession methods |
| 4478 | // ------------------------------------------------------------- |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4479 | |
| Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 4480 | private boolean shouldAllowDisableKeyguard() |
| Jim Miller | d6b5705 | 2010-06-07 17:52:42 -0700 | [diff] [blame] | 4481 | { |
| Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 4482 | // We fail safe and prevent disabling keyguard in the unlikely event this gets |
| 4483 | // called before DevicePolicyManagerService has started. |
| 4484 | if (mAllowDisableKeyguard == ALLOW_DISABLE_UNKNOWN) { |
| 4485 | DevicePolicyManager dpm = (DevicePolicyManager) mContext.getSystemService( |
| 4486 | Context.DEVICE_POLICY_SERVICE); |
| 4487 | if (dpm != null) { |
| 4488 | mAllowDisableKeyguard = dpm.getPasswordQuality(null) |
| 4489 | == DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED ? |
| 4490 | ALLOW_DISABLE_YES : ALLOW_DISABLE_NO; |
| 4491 | } |
| Jim Miller | d6b5705 | 2010-06-07 17:52:42 -0700 | [diff] [blame] | 4492 | } |
| Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 4493 | return mAllowDisableKeyguard == ALLOW_DISABLE_YES; |
| Jim Miller | d6b5705 | 2010-06-07 17:52:42 -0700 | [diff] [blame] | 4494 | } |
| 4495 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4496 | public void disableKeyguard(IBinder token, String tag) { |
| Mike Lockwood | 733fdf3 | 2009-09-28 19:08:53 -0400 | [diff] [blame] | 4497 | if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD) |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4498 | != PackageManager.PERMISSION_GRANTED) { |
| 4499 | throw new SecurityException("Requires DISABLE_KEYGUARD permission"); |
| 4500 | } |
| Jim Miller | d6b5705 | 2010-06-07 17:52:42 -0700 | [diff] [blame] | 4501 | |
| Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 4502 | synchronized (mKeyguardTokenWatcher) { |
| 4503 | mKeyguardTokenWatcher.acquire(token, tag); |
| Mike Lockwood | dd88468 | 2009-10-11 16:57:08 -0400 | [diff] [blame] | 4504 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4505 | } |
| 4506 | |
| 4507 | public void reenableKeyguard(IBinder token) { |
| Mike Lockwood | 733fdf3 | 2009-09-28 19:08:53 -0400 | [diff] [blame] | 4508 | if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD) |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4509 | != PackageManager.PERMISSION_GRANTED) { |
| 4510 | throw new SecurityException("Requires DISABLE_KEYGUARD permission"); |
| 4511 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4512 | |
| Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 4513 | synchronized (mKeyguardTokenWatcher) { |
| 4514 | mKeyguardTokenWatcher.release(token); |
| Jim Miller | d6b5705 | 2010-06-07 17:52:42 -0700 | [diff] [blame] | 4515 | |
| Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 4516 | if (!mKeyguardTokenWatcher.isAcquired()) { |
| 4517 | // If we are the last one to reenable the keyguard wait until |
| 4518 | // we have actually finished reenabling until returning. |
| 4519 | // It is possible that reenableKeyguard() can be called before |
| 4520 | // the previous disableKeyguard() is handled, in which case |
| 4521 | // neither mKeyguardTokenWatcher.acquired() or released() would |
| 4522 | // be called. In that case mKeyguardDisabled will be false here |
| 4523 | // and we have nothing to wait for. |
| 4524 | while (mKeyguardDisabled) { |
| 4525 | try { |
| 4526 | mKeyguardTokenWatcher.wait(); |
| 4527 | } catch (InterruptedException e) { |
| 4528 | Thread.currentThread().interrupt(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4529 | } |
| 4530 | } |
| 4531 | } |
| 4532 | } |
| 4533 | } |
| 4534 | |
| 4535 | /** |
| 4536 | * @see android.app.KeyguardManager#exitKeyguardSecurely |
| 4537 | */ |
| 4538 | public void exitKeyguardSecurely(final IOnKeyguardExitResult callback) { |
| 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 | } |
| 4543 | mPolicy.exitKeyguardSecurely(new WindowManagerPolicy.OnKeyguardExitResult() { |
| 4544 | public void onKeyguardExitResult(boolean success) { |
| 4545 | try { |
| 4546 | callback.onKeyguardExitResult(success); |
| 4547 | } catch (RemoteException e) { |
| 4548 | // Client has died, we don't care. |
| 4549 | } |
| 4550 | } |
| 4551 | }); |
| 4552 | } |
| 4553 | |
| 4554 | public boolean inKeyguardRestrictedInputMode() { |
| 4555 | return mPolicy.inKeyguardRestrictedKeyInputMode(); |
| 4556 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4557 | |
| Dianne Hackborn | ffa4248 | 2009-09-23 22:20:11 -0700 | [diff] [blame] | 4558 | public void closeSystemDialogs(String reason) { |
| 4559 | synchronized(mWindowMap) { |
| 4560 | for (int i=mWindows.size()-1; i>=0; i--) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 4561 | WindowState w = mWindows.get(i); |
| Dianne Hackborn | ffa4248 | 2009-09-23 22:20:11 -0700 | [diff] [blame] | 4562 | if (w.mSurface != null) { |
| 4563 | try { |
| 4564 | w.mClient.closeSystemDialogs(reason); |
| 4565 | } catch (RemoteException e) { |
| 4566 | } |
| 4567 | } |
| 4568 | } |
| 4569 | } |
| 4570 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 4571 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4572 | static float fixScale(float scale) { |
| 4573 | if (scale < 0) scale = 0; |
| 4574 | else if (scale > 20) scale = 20; |
| 4575 | return Math.abs(scale); |
| 4576 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4577 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4578 | public void setAnimationScale(int which, float scale) { |
| 4579 | if (!checkCallingPermission(android.Manifest.permission.SET_ANIMATION_SCALE, |
| 4580 | "setAnimationScale()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4581 | throw new SecurityException("Requires SET_ANIMATION_SCALE permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4582 | } |
| 4583 | |
| 4584 | if (scale < 0) scale = 0; |
| 4585 | else if (scale > 20) scale = 20; |
| 4586 | scale = Math.abs(scale); |
| 4587 | switch (which) { |
| 4588 | case 0: mWindowAnimationScale = fixScale(scale); break; |
| 4589 | case 1: mTransitionAnimationScale = fixScale(scale); break; |
| 4590 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4591 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4592 | // Persist setting |
| 4593 | mH.obtainMessage(H.PERSIST_ANIMATION_SCALE).sendToTarget(); |
| 4594 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4595 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4596 | public void setAnimationScales(float[] scales) { |
| 4597 | if (!checkCallingPermission(android.Manifest.permission.SET_ANIMATION_SCALE, |
| 4598 | "setAnimationScale()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4599 | throw new SecurityException("Requires SET_ANIMATION_SCALE permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4600 | } |
| 4601 | |
| 4602 | if (scales != null) { |
| 4603 | if (scales.length >= 1) { |
| 4604 | mWindowAnimationScale = fixScale(scales[0]); |
| 4605 | } |
| 4606 | if (scales.length >= 2) { |
| 4607 | mTransitionAnimationScale = fixScale(scales[1]); |
| 4608 | } |
| 4609 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4610 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4611 | // Persist setting |
| 4612 | mH.obtainMessage(H.PERSIST_ANIMATION_SCALE).sendToTarget(); |
| 4613 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4614 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4615 | public float getAnimationScale(int which) { |
| 4616 | switch (which) { |
| 4617 | case 0: return mWindowAnimationScale; |
| 4618 | case 1: return mTransitionAnimationScale; |
| 4619 | } |
| 4620 | return 0; |
| 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 | public float[] getAnimationScales() { |
| 4624 | return new float[] { mWindowAnimationScale, mTransitionAnimationScale }; |
| 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 int getSwitchState(int sw) { |
| 4628 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4629 | "getSwitchState()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4630 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4631 | } |
| Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 4632 | return mInputManager.getSwitchState(-1, InputDevice.SOURCE_ANY, sw); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4633 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4634 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4635 | public int getSwitchStateForDevice(int devid, int sw) { |
| 4636 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4637 | "getSwitchStateForDevice()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4638 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4639 | } |
| Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 4640 | return mInputManager.getSwitchState(devid, InputDevice.SOURCE_ANY, sw); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4641 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4642 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4643 | public int getScancodeState(int sw) { |
| 4644 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4645 | "getScancodeState()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4646 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4647 | } |
| Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 4648 | return mInputManager.getScanCodeState(-1, InputDevice.SOURCE_ANY, sw); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4649 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4650 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4651 | public int getScancodeStateForDevice(int devid, int sw) { |
| 4652 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4653 | "getScancodeStateForDevice()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4654 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4655 | } |
| Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 4656 | return mInputManager.getScanCodeState(devid, InputDevice.SOURCE_ANY, sw); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4657 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4658 | |
| Dianne Hackborn | 1d62ea9 | 2009-11-17 12:49:50 -0800 | [diff] [blame] | 4659 | public int getTrackballScancodeState(int sw) { |
| 4660 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4661 | "getTrackballScancodeState()")) { |
| 4662 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
| 4663 | } |
| Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 4664 | return mInputManager.getScanCodeState(-1, InputDevice.SOURCE_TRACKBALL, sw); |
| Dianne Hackborn | 1d62ea9 | 2009-11-17 12:49:50 -0800 | [diff] [blame] | 4665 | } |
| 4666 | |
| 4667 | public int getDPadScancodeState(int sw) { |
| 4668 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4669 | "getDPadScancodeState()")) { |
| 4670 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
| 4671 | } |
| Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 4672 | return mInputManager.getScanCodeState(-1, InputDevice.SOURCE_DPAD, sw); |
| Dianne Hackborn | 1d62ea9 | 2009-11-17 12:49:50 -0800 | [diff] [blame] | 4673 | } |
| 4674 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4675 | public int getKeycodeState(int sw) { |
| 4676 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4677 | "getKeycodeState()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4678 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4679 | } |
| Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 4680 | return mInputManager.getKeyCodeState(-1, InputDevice.SOURCE_ANY, sw); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4681 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4682 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4683 | public int getKeycodeStateForDevice(int devid, int sw) { |
| 4684 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4685 | "getKeycodeStateForDevice()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4686 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4687 | } |
| Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 4688 | return mInputManager.getKeyCodeState(devid, InputDevice.SOURCE_ANY, sw); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4689 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4690 | |
| Dianne Hackborn | 1d62ea9 | 2009-11-17 12:49:50 -0800 | [diff] [blame] | 4691 | public int getTrackballKeycodeState(int sw) { |
| 4692 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4693 | "getTrackballKeycodeState()")) { |
| 4694 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
| 4695 | } |
| Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 4696 | return mInputManager.getKeyCodeState(-1, InputDevice.SOURCE_TRACKBALL, sw); |
| Dianne Hackborn | 1d62ea9 | 2009-11-17 12:49:50 -0800 | [diff] [blame] | 4697 | } |
| 4698 | |
| 4699 | public int getDPadKeycodeState(int sw) { |
| 4700 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4701 | "getDPadKeycodeState()")) { |
| 4702 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
| 4703 | } |
| Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 4704 | return mInputManager.getKeyCodeState(-1, InputDevice.SOURCE_DPAD, sw); |
| Dianne Hackborn | 1d62ea9 | 2009-11-17 12:49:50 -0800 | [diff] [blame] | 4705 | } |
| Jeff Brown | a41ca77 | 2010-08-11 14:46:32 -0700 | [diff] [blame] | 4706 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4707 | public boolean hasKeys(int[] keycodes, boolean[] keyExists) { |
| Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 4708 | return mInputManager.hasKeys(-1, InputDevice.SOURCE_ANY, keycodes, keyExists); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4709 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4710 | |
| Jeff Brown | a41ca77 | 2010-08-11 14:46:32 -0700 | [diff] [blame] | 4711 | public InputChannel monitorInput(String inputChannelName) { |
| 4712 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4713 | "monitorInput()")) { |
| 4714 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
| 4715 | } |
| 4716 | return mInputManager.monitorInput(inputChannelName); |
| 4717 | } |
| 4718 | |
| Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 4719 | public InputDevice getInputDevice(int deviceId) { |
| 4720 | return mInputManager.getInputDevice(deviceId); |
| 4721 | } |
| 4722 | |
| 4723 | public int[] getInputDeviceIds() { |
| 4724 | return mInputManager.getInputDeviceIds(); |
| 4725 | } |
| 4726 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4727 | public void enableScreenAfterBoot() { |
| 4728 | synchronized(mWindowMap) { |
| 4729 | if (mSystemBooted) { |
| 4730 | return; |
| 4731 | } |
| 4732 | mSystemBooted = true; |
| 4733 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4734 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4735 | performEnableScreen(); |
| 4736 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4737 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4738 | public void enableScreenIfNeededLocked() { |
| 4739 | if (mDisplayEnabled) { |
| 4740 | return; |
| 4741 | } |
| 4742 | if (!mSystemBooted) { |
| 4743 | return; |
| 4744 | } |
| 4745 | mH.sendMessage(mH.obtainMessage(H.ENABLE_SCREEN)); |
| 4746 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4747 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4748 | public void performEnableScreen() { |
| 4749 | synchronized(mWindowMap) { |
| 4750 | if (mDisplayEnabled) { |
| 4751 | return; |
| 4752 | } |
| 4753 | if (!mSystemBooted) { |
| 4754 | return; |
| 4755 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4756 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4757 | // Don't enable the screen until all existing windows |
| 4758 | // have been drawn. |
| 4759 | final int N = mWindows.size(); |
| 4760 | for (int i=0; i<N; i++) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 4761 | WindowState w = mWindows.get(i); |
| Dianne Hackborn | f3bea9c | 2009-12-09 18:26:21 -0800 | [diff] [blame] | 4762 | if (w.isVisibleLw() && !w.mObscured && !w.isDrawnLw()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4763 | return; |
| 4764 | } |
| 4765 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4766 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4767 | mDisplayEnabled = true; |
| 4768 | if (false) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4769 | Slog.i(TAG, "ENABLING SCREEN!"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4770 | StringWriter sw = new StringWriter(); |
| 4771 | PrintWriter pw = new PrintWriter(sw); |
| 4772 | this.dump(null, pw, null); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4773 | Slog.i(TAG, sw.toString()); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4774 | } |
| 4775 | try { |
| 4776 | IBinder surfaceFlinger = ServiceManager.getService("SurfaceFlinger"); |
| 4777 | if (surfaceFlinger != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4778 | //Slog.i(TAG, "******* TELLING SURFACE FLINGER WE ARE BOOTED!"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4779 | Parcel data = Parcel.obtain(); |
| 4780 | data.writeInterfaceToken("android.ui.ISurfaceComposer"); |
| 4781 | surfaceFlinger.transact(IBinder.FIRST_CALL_TRANSACTION, |
| 4782 | data, null, 0); |
| 4783 | data.recycle(); |
| 4784 | } |
| 4785 | } catch (RemoteException ex) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4786 | Slog.e(TAG, "Boot completed: SurfaceFlinger is dead!"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4787 | } |
| 4788 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4789 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4790 | mPolicy.enableScreenAfterBoot(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4791 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4792 | // Make sure the last requested orientation has been applied. |
| Dianne Hackborn | 321ae68 | 2009-03-27 16:16:03 -0700 | [diff] [blame] | 4793 | setRotationUnchecked(WindowManagerPolicy.USE_LAST_ROTATION, false, |
| 4794 | mLastRotationFlags | Surface.FLAGS_ORIENTATION_ANIMATION_DISABLE); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4795 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4796 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4797 | public void setInTouchMode(boolean mode) { |
| 4798 | synchronized(mWindowMap) { |
| 4799 | mInTouchMode = mode; |
| 4800 | } |
| 4801 | } |
| 4802 | |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4803 | public void setRotation(int rotation, |
| Dianne Hackborn | 1e880db | 2009-03-27 16:04:08 -0700 | [diff] [blame] | 4804 | boolean alwaysSendConfiguration, int animFlags) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4805 | if (!checkCallingPermission(android.Manifest.permission.SET_ORIENTATION, |
| Dianne Hackborn | 1e880db | 2009-03-27 16:04:08 -0700 | [diff] [blame] | 4806 | "setRotation()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4807 | throw new SecurityException("Requires SET_ORIENTATION permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4808 | } |
| 4809 | |
| Dianne Hackborn | 1e880db | 2009-03-27 16:04:08 -0700 | [diff] [blame] | 4810 | setRotationUnchecked(rotation, alwaysSendConfiguration, animFlags); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4811 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4812 | |
| Dianne Hackborn | 1e880db | 2009-03-27 16:04:08 -0700 | [diff] [blame] | 4813 | public void setRotationUnchecked(int rotation, |
| 4814 | boolean alwaysSendConfiguration, int animFlags) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4815 | if(DEBUG_ORIENTATION) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4816 | "alwaysSendConfiguration set to "+alwaysSendConfiguration); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4817 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4818 | long origId = Binder.clearCallingIdentity(); |
| 4819 | boolean changed; |
| 4820 | synchronized(mWindowMap) { |
| Dianne Hackborn | 1e880db | 2009-03-27 16:04:08 -0700 | [diff] [blame] | 4821 | changed = setRotationUncheckedLocked(rotation, animFlags); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4822 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4823 | |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 4824 | if (changed || alwaysSendConfiguration) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4825 | sendNewConfiguration(); |
| 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 | Binder.restoreCallingIdentity(origId); |
| 4829 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4830 | |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 4831 | /** |
| 4832 | * Apply a new rotation to the screen, respecting the requests of |
| 4833 | * applications. Use WindowManagerPolicy.USE_LAST_ROTATION to simply |
| 4834 | * re-evaluate the desired rotation. |
| 4835 | * |
| 4836 | * Returns null if the rotation has been changed. In this case YOU |
| 4837 | * MUST CALL setNewConfiguration() TO UNFREEZE THE SCREEN. |
| 4838 | */ |
| Dianne Hackborn | 1e880db | 2009-03-27 16:04:08 -0700 | [diff] [blame] | 4839 | public boolean setRotationUncheckedLocked(int rotation, int animFlags) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4840 | boolean changed; |
| 4841 | if (rotation == WindowManagerPolicy.USE_LAST_ROTATION) { |
| 4842 | rotation = mRequestedRotation; |
| 4843 | } else { |
| 4844 | mRequestedRotation = rotation; |
| Dianne Hackborn | 321ae68 | 2009-03-27 16:16:03 -0700 | [diff] [blame] | 4845 | mLastRotationFlags = animFlags; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4846 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4847 | 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] | 4848 | rotation = mPolicy.rotationForOrientationLw(mForcedAppOrientation, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4849 | mRotation, mDisplayEnabled); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4850 | 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] | 4851 | changed = mDisplayEnabled && mRotation != rotation; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4852 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4853 | if (changed) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4854 | if (DEBUG_ORIENTATION) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4855 | "Rotation changed to " + rotation |
| 4856 | + " from " + mRotation |
| 4857 | + " (forceApp=" + mForcedAppOrientation |
| 4858 | + ", req=" + mRequestedRotation + ")"); |
| 4859 | mRotation = rotation; |
| 4860 | mWindowsFreezingScreen = true; |
| 4861 | mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT); |
| 4862 | mH.sendMessageDelayed(mH.obtainMessage(H.WINDOW_FREEZE_TIMEOUT), |
| 4863 | 2000); |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 4864 | mWaitingForConfig = true; |
| 4865 | mLayoutNeeded = true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4866 | startFreezingDisplayLocked(); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4867 | Slog.i(TAG, "Setting rotation to " + rotation + ", animFlags=" + animFlags); |
| Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 4868 | mInputManager.setDisplayOrientation(0, rotation); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4869 | if (mDisplayEnabled) { |
| Dianne Hackborn | 321ae68 | 2009-03-27 16:16:03 -0700 | [diff] [blame] | 4870 | Surface.setOrientation(0, rotation, animFlags); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4871 | } |
| 4872 | for (int i=mWindows.size()-1; i>=0; i--) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 4873 | WindowState w = mWindows.get(i); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4874 | if (w.mSurface != null) { |
| 4875 | w.mOrientationChanging = true; |
| 4876 | } |
| 4877 | } |
| 4878 | for (int i=mRotationWatchers.size()-1; i>=0; i--) { |
| 4879 | try { |
| 4880 | mRotationWatchers.get(i).onRotationChanged(rotation); |
| 4881 | } catch (RemoteException e) { |
| 4882 | } |
| 4883 | } |
| 4884 | } //end if changed |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4885 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4886 | return changed; |
| 4887 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4888 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4889 | public int getRotation() { |
| 4890 | return mRotation; |
| 4891 | } |
| 4892 | |
| 4893 | public int watchRotation(IRotationWatcher watcher) { |
| 4894 | final IBinder watcherBinder = watcher.asBinder(); |
| 4895 | IBinder.DeathRecipient dr = new IBinder.DeathRecipient() { |
| 4896 | public void binderDied() { |
| 4897 | synchronized (mWindowMap) { |
| 4898 | for (int i=0; i<mRotationWatchers.size(); i++) { |
| 4899 | if (watcherBinder == mRotationWatchers.get(i).asBinder()) { |
| Suchi Amalapurapu | fff2fda | 2009-06-30 21:36:16 -0700 | [diff] [blame] | 4900 | IRotationWatcher removed = mRotationWatchers.remove(i); |
| 4901 | if (removed != null) { |
| 4902 | removed.asBinder().unlinkToDeath(this, 0); |
| 4903 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4904 | i--; |
| 4905 | } |
| 4906 | } |
| 4907 | } |
| 4908 | } |
| 4909 | }; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4910 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4911 | synchronized (mWindowMap) { |
| 4912 | try { |
| 4913 | watcher.asBinder().linkToDeath(dr, 0); |
| 4914 | mRotationWatchers.add(watcher); |
| 4915 | } catch (RemoteException e) { |
| 4916 | // Client died, no cleanup needed. |
| 4917 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4918 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4919 | return mRotation; |
| 4920 | } |
| 4921 | } |
| 4922 | |
| 4923 | /** |
| 4924 | * Starts the view server on the specified port. |
| 4925 | * |
| 4926 | * @param port The port to listener to. |
| 4927 | * |
| 4928 | * @return True if the server was successfully started, false otherwise. |
| 4929 | * |
| 4930 | * @see com.android.server.ViewServer |
| 4931 | * @see com.android.server.ViewServer#VIEW_SERVER_DEFAULT_PORT |
| 4932 | */ |
| 4933 | public boolean startViewServer(int port) { |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4934 | if (isSystemSecure()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4935 | return false; |
| 4936 | } |
| 4937 | |
| 4938 | if (!checkCallingPermission(Manifest.permission.DUMP, "startViewServer")) { |
| 4939 | return false; |
| 4940 | } |
| 4941 | |
| 4942 | if (port < 1024) { |
| 4943 | return false; |
| 4944 | } |
| 4945 | |
| 4946 | if (mViewServer != null) { |
| 4947 | if (!mViewServer.isRunning()) { |
| 4948 | try { |
| 4949 | return mViewServer.start(); |
| 4950 | } catch (IOException e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4951 | Slog.w(TAG, "View server did not start"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4952 | } |
| 4953 | } |
| 4954 | return false; |
| 4955 | } |
| 4956 | |
| 4957 | try { |
| 4958 | mViewServer = new ViewServer(this, port); |
| 4959 | return mViewServer.start(); |
| 4960 | } catch (IOException e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4961 | Slog.w(TAG, "View server did not start"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4962 | } |
| 4963 | return false; |
| 4964 | } |
| 4965 | |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4966 | private boolean isSystemSecure() { |
| 4967 | return "1".equals(SystemProperties.get(SYSTEM_SECURE, "1")) && |
| 4968 | "0".equals(SystemProperties.get(SYSTEM_DEBUGGABLE, "0")); |
| 4969 | } |
| 4970 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4971 | /** |
| 4972 | * Stops the view server if it exists. |
| 4973 | * |
| 4974 | * @return True if the server stopped, false if it wasn't started or |
| 4975 | * couldn't be stopped. |
| 4976 | * |
| 4977 | * @see com.android.server.ViewServer |
| 4978 | */ |
| 4979 | public boolean stopViewServer() { |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4980 | if (isSystemSecure()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4981 | return false; |
| 4982 | } |
| 4983 | |
| 4984 | if (!checkCallingPermission(Manifest.permission.DUMP, "stopViewServer")) { |
| 4985 | return false; |
| 4986 | } |
| 4987 | |
| 4988 | if (mViewServer != null) { |
| 4989 | return mViewServer.stop(); |
| 4990 | } |
| 4991 | return false; |
| 4992 | } |
| 4993 | |
| 4994 | /** |
| 4995 | * Indicates whether the view server is running. |
| 4996 | * |
| 4997 | * @return True if the server is running, false otherwise. |
| 4998 | * |
| 4999 | * @see com.android.server.ViewServer |
| 5000 | */ |
| 5001 | public boolean isViewServerRunning() { |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5002 | if (isSystemSecure()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5003 | return false; |
| 5004 | } |
| 5005 | |
| 5006 | if (!checkCallingPermission(Manifest.permission.DUMP, "isViewServerRunning")) { |
| 5007 | return false; |
| 5008 | } |
| 5009 | |
| 5010 | return mViewServer != null && mViewServer.isRunning(); |
| 5011 | } |
| 5012 | |
| 5013 | /** |
| 5014 | * Lists all availble windows in the system. The listing is written in the |
| 5015 | * specified Socket's output stream with the following syntax: |
| 5016 | * windowHashCodeInHexadecimal windowName |
| 5017 | * Each line of the ouput represents a different window. |
| 5018 | * |
| 5019 | * @param client The remote client to send the listing to. |
| 5020 | * @return False if an error occured, true otherwise. |
| 5021 | */ |
| 5022 | boolean viewServerListWindows(Socket client) { |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5023 | if (isSystemSecure()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5024 | return false; |
| 5025 | } |
| 5026 | |
| 5027 | boolean result = true; |
| 5028 | |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 5029 | WindowState[] windows; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5030 | synchronized (mWindowMap) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5031 | //noinspection unchecked |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 5032 | windows = mWindows.toArray(new WindowState[mWindows.size()]); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5033 | } |
| 5034 | |
| 5035 | BufferedWriter out = null; |
| 5036 | |
| 5037 | // Any uncaught exception will crash the system process |
| 5038 | try { |
| 5039 | OutputStream clientStream = client.getOutputStream(); |
| 5040 | out = new BufferedWriter(new OutputStreamWriter(clientStream), 8 * 1024); |
| 5041 | |
| 5042 | final int count = windows.length; |
| 5043 | for (int i = 0; i < count; i++) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 5044 | final WindowState w = windows[i]; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5045 | out.write(Integer.toHexString(System.identityHashCode(w))); |
| 5046 | out.write(' '); |
| 5047 | out.append(w.mAttrs.getTitle()); |
| 5048 | out.write('\n'); |
| 5049 | } |
| 5050 | |
| 5051 | out.write("DONE.\n"); |
| 5052 | out.flush(); |
| 5053 | } catch (Exception e) { |
| 5054 | result = false; |
| 5055 | } finally { |
| 5056 | if (out != null) { |
| 5057 | try { |
| 5058 | out.close(); |
| 5059 | } catch (IOException e) { |
| 5060 | result = false; |
| 5061 | } |
| 5062 | } |
| 5063 | } |
| 5064 | |
| 5065 | return result; |
| 5066 | } |
| 5067 | |
| 5068 | /** |
| Konstantin Lopyrev | f962476 | 2010-07-14 17:02:37 -0700 | [diff] [blame] | 5069 | * Returns the focused window in the following format: |
| 5070 | * windowHashCodeInHexadecimal windowName |
| 5071 | * |
| 5072 | * @param client The remote client to send the listing to. |
| 5073 | * @return False if an error occurred, true otherwise. |
| 5074 | */ |
| 5075 | boolean viewServerGetFocusedWindow(Socket client) { |
| 5076 | if (isSystemSecure()) { |
| 5077 | return false; |
| 5078 | } |
| 5079 | |
| 5080 | boolean result = true; |
| 5081 | |
| 5082 | WindowState focusedWindow = getFocusedWindow(); |
| 5083 | |
| 5084 | BufferedWriter out = null; |
| 5085 | |
| 5086 | // Any uncaught exception will crash the system process |
| 5087 | try { |
| 5088 | OutputStream clientStream = client.getOutputStream(); |
| 5089 | out = new BufferedWriter(new OutputStreamWriter(clientStream), 8 * 1024); |
| 5090 | |
| 5091 | if(focusedWindow != null) { |
| 5092 | out.write(Integer.toHexString(System.identityHashCode(focusedWindow))); |
| 5093 | out.write(' '); |
| 5094 | out.append(focusedWindow.mAttrs.getTitle()); |
| 5095 | } |
| 5096 | out.write('\n'); |
| 5097 | out.flush(); |
| 5098 | } catch (Exception e) { |
| 5099 | result = false; |
| 5100 | } finally { |
| 5101 | if (out != null) { |
| 5102 | try { |
| 5103 | out.close(); |
| 5104 | } catch (IOException e) { |
| 5105 | result = false; |
| 5106 | } |
| 5107 | } |
| 5108 | } |
| 5109 | |
| 5110 | return result; |
| 5111 | } |
| 5112 | |
| 5113 | /** |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5114 | * Sends a command to a target window. The result of the command, if any, will be |
| 5115 | * written in the output stream of the specified socket. |
| 5116 | * |
| 5117 | * The parameters must follow this syntax: |
| 5118 | * windowHashcode extra |
| 5119 | * |
| 5120 | * Where XX is the length in characeters of the windowTitle. |
| 5121 | * |
| 5122 | * The first parameter is the target window. The window with the specified hashcode |
| 5123 | * will be the target. If no target can be found, nothing happens. The extra parameters |
| 5124 | * will be delivered to the target window and as parameters to the command itself. |
| 5125 | * |
| 5126 | * @param client The remote client to sent the result, if any, to. |
| 5127 | * @param command The command to execute. |
| 5128 | * @param parameters The command parameters. |
| 5129 | * |
| 5130 | * @return True if the command was successfully delivered, false otherwise. This does |
| 5131 | * not indicate whether the command itself was successful. |
| 5132 | */ |
| 5133 | boolean viewServerWindowCommand(Socket client, String command, String parameters) { |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5134 | if (isSystemSecure()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5135 | return false; |
| 5136 | } |
| 5137 | |
| 5138 | boolean success = true; |
| 5139 | Parcel data = null; |
| 5140 | Parcel reply = null; |
| 5141 | |
| Konstantin Lopyrev | 43b9b48 | 2010-08-24 22:00:12 -0700 | [diff] [blame] | 5142 | BufferedWriter out = null; |
| 5143 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5144 | // Any uncaught exception will crash the system process |
| 5145 | try { |
| 5146 | // Find the hashcode of the window |
| 5147 | int index = parameters.indexOf(' '); |
| 5148 | if (index == -1) { |
| 5149 | index = parameters.length(); |
| 5150 | } |
| 5151 | final String code = parameters.substring(0, index); |
| Romain Guy | 236092a | 2009-12-14 15:31:48 -0800 | [diff] [blame] | 5152 | int hashCode = (int) Long.parseLong(code, 16); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5153 | |
| 5154 | // Extract the command's parameter after the window description |
| 5155 | if (index < parameters.length()) { |
| 5156 | parameters = parameters.substring(index + 1); |
| 5157 | } else { |
| 5158 | parameters = ""; |
| 5159 | } |
| 5160 | |
| 5161 | final WindowManagerService.WindowState window = findWindow(hashCode); |
| 5162 | if (window == null) { |
| 5163 | return false; |
| 5164 | } |
| 5165 | |
| 5166 | data = Parcel.obtain(); |
| 5167 | data.writeInterfaceToken("android.view.IWindow"); |
| 5168 | data.writeString(command); |
| 5169 | data.writeString(parameters); |
| 5170 | data.writeInt(1); |
| 5171 | ParcelFileDescriptor.fromSocket(client).writeToParcel(data, 0); |
| 5172 | |
| 5173 | reply = Parcel.obtain(); |
| 5174 | |
| 5175 | final IBinder binder = window.mClient.asBinder(); |
| 5176 | // TODO: GET THE TRANSACTION CODE IN A SAFER MANNER |
| 5177 | binder.transact(IBinder.FIRST_CALL_TRANSACTION, data, reply, 0); |
| 5178 | |
| 5179 | reply.readException(); |
| 5180 | |
| Konstantin Lopyrev | 43b9b48 | 2010-08-24 22:00:12 -0700 | [diff] [blame] | 5181 | if (!client.isOutputShutdown()) { |
| 5182 | out = new BufferedWriter(new OutputStreamWriter(client.getOutputStream())); |
| 5183 | out.write("DONE\n"); |
| 5184 | out.flush(); |
| 5185 | } |
| 5186 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5187 | } catch (Exception e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5188 | 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] | 5189 | success = false; |
| 5190 | } finally { |
| 5191 | if (data != null) { |
| 5192 | data.recycle(); |
| 5193 | } |
| 5194 | if (reply != null) { |
| 5195 | reply.recycle(); |
| 5196 | } |
| Konstantin Lopyrev | 43b9b48 | 2010-08-24 22:00:12 -0700 | [diff] [blame] | 5197 | if (out != null) { |
| 5198 | try { |
| 5199 | out.close(); |
| 5200 | } catch (IOException e) { |
| 5201 | |
| 5202 | } |
| 5203 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5204 | } |
| 5205 | |
| 5206 | return success; |
| 5207 | } |
| 5208 | |
| Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 5209 | public void addWindowChangeListener(WindowChangeListener listener) { |
| 5210 | synchronized(mWindowMap) { |
| 5211 | mWindowChangeListeners.add(listener); |
| 5212 | } |
| 5213 | } |
| 5214 | |
| 5215 | public void removeWindowChangeListener(WindowChangeListener listener) { |
| 5216 | synchronized(mWindowMap) { |
| 5217 | mWindowChangeListeners.remove(listener); |
| 5218 | } |
| 5219 | } |
| 5220 | |
| 5221 | private void notifyWindowsChanged() { |
| 5222 | WindowChangeListener[] windowChangeListeners; |
| 5223 | synchronized(mWindowMap) { |
| 5224 | if(mWindowChangeListeners.isEmpty()) { |
| 5225 | return; |
| 5226 | } |
| 5227 | windowChangeListeners = new WindowChangeListener[mWindowChangeListeners.size()]; |
| 5228 | windowChangeListeners = mWindowChangeListeners.toArray(windowChangeListeners); |
| 5229 | } |
| 5230 | int N = windowChangeListeners.length; |
| 5231 | for(int i = 0; i < N; i++) { |
| 5232 | windowChangeListeners[i].windowsChanged(); |
| 5233 | } |
| 5234 | } |
| 5235 | |
| Konstantin Lopyrev | 6e0f65f | 2010-07-14 14:55:33 -0700 | [diff] [blame] | 5236 | private void notifyFocusChanged() { |
| 5237 | WindowChangeListener[] windowChangeListeners; |
| 5238 | synchronized(mWindowMap) { |
| 5239 | if(mWindowChangeListeners.isEmpty()) { |
| 5240 | return; |
| 5241 | } |
| 5242 | windowChangeListeners = new WindowChangeListener[mWindowChangeListeners.size()]; |
| 5243 | windowChangeListeners = mWindowChangeListeners.toArray(windowChangeListeners); |
| 5244 | } |
| 5245 | int N = windowChangeListeners.length; |
| 5246 | for(int i = 0; i < N; i++) { |
| 5247 | windowChangeListeners[i].focusChanged(); |
| 5248 | } |
| 5249 | } |
| 5250 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5251 | private WindowState findWindow(int hashCode) { |
| 5252 | if (hashCode == -1) { |
| 5253 | return getFocusedWindow(); |
| 5254 | } |
| 5255 | |
| 5256 | synchronized (mWindowMap) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 5257 | final ArrayList<WindowState> windows = mWindows; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5258 | final int count = windows.size(); |
| 5259 | |
| 5260 | for (int i = 0; i < count; i++) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 5261 | WindowState w = windows.get(i); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5262 | if (System.identityHashCode(w) == hashCode) { |
| 5263 | return w; |
| 5264 | } |
| 5265 | } |
| 5266 | } |
| 5267 | |
| 5268 | return null; |
| 5269 | } |
| 5270 | |
| 5271 | /* |
| 5272 | * Instruct the Activity Manager to fetch the current configuration and broadcast |
| 5273 | * that to config-changed listeners if appropriate. |
| 5274 | */ |
| 5275 | void sendNewConfiguration() { |
| 5276 | try { |
| 5277 | mActivityManager.updateConfiguration(null); |
| 5278 | } catch (RemoteException e) { |
| 5279 | } |
| 5280 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5281 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5282 | public Configuration computeNewConfiguration() { |
| 5283 | synchronized (mWindowMap) { |
| Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 5284 | return computeNewConfigurationLocked(); |
| 5285 | } |
| 5286 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5287 | |
| Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 5288 | Configuration computeNewConfigurationLocked() { |
| 5289 | Configuration config = new Configuration(); |
| 5290 | if (!computeNewConfigurationLocked(config)) { |
| 5291 | return null; |
| 5292 | } |
| Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 5293 | return config; |
| 5294 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5295 | |
| Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 5296 | boolean computeNewConfigurationLocked(Configuration config) { |
| 5297 | if (mDisplay == null) { |
| 5298 | return false; |
| 5299 | } |
| Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 5300 | |
| 5301 | mInputManager.getInputConfiguration(config); |
| Christopher Tate | b696aee | 2010-04-02 19:08:30 -0700 | [diff] [blame] | 5302 | |
| 5303 | // Use the effective "visual" dimensions based on current rotation |
| 5304 | final boolean rotated = (mRotation == Surface.ROTATION_90 |
| 5305 | || mRotation == Surface.ROTATION_270); |
| 5306 | final int dw = rotated ? mInitialDisplayHeight : mInitialDisplayWidth; |
| 5307 | final int dh = rotated ? mInitialDisplayWidth : mInitialDisplayHeight; |
| 5308 | |
| Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 5309 | int orientation = Configuration.ORIENTATION_SQUARE; |
| 5310 | if (dw < dh) { |
| 5311 | orientation = Configuration.ORIENTATION_PORTRAIT; |
| 5312 | } else if (dw > dh) { |
| 5313 | orientation = Configuration.ORIENTATION_LANDSCAPE; |
| 5314 | } |
| 5315 | config.orientation = orientation; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 5316 | |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 5317 | DisplayMetrics dm = new DisplayMetrics(); |
| 5318 | mDisplay.getMetrics(dm); |
| 5319 | CompatibilityInfo.updateCompatibleScreenFrame(dm, orientation, mCompatibleScreenFrame); |
| 5320 | |
| Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 5321 | if (mScreenLayout == Configuration.SCREENLAYOUT_SIZE_UNDEFINED) { |
| Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 5322 | // Note we only do this once because at this point we don't |
| 5323 | // expect the screen to change in this way at runtime, and want |
| 5324 | // to avoid all of this computation for every config change. |
| Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 5325 | int longSize = dw; |
| 5326 | int shortSize = dh; |
| 5327 | if (longSize < shortSize) { |
| 5328 | int tmp = longSize; |
| 5329 | longSize = shortSize; |
| 5330 | shortSize = tmp; |
| 5331 | } |
| 5332 | longSize = (int)(longSize/dm.density); |
| 5333 | shortSize = (int)(shortSize/dm.density); |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 5334 | |
| Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 5335 | // These semi-magic numbers define our compatibility modes for |
| 5336 | // applications with different screens. Don't change unless you |
| 5337 | // make sure to test lots and lots of apps! |
| 5338 | if (longSize < 470) { |
| 5339 | // This is shorter than an HVGA normal density screen (which |
| 5340 | // is 480 pixels on its long side). |
| Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 5341 | mScreenLayout = Configuration.SCREENLAYOUT_SIZE_SMALL |
| 5342 | | Configuration.SCREENLAYOUT_LONG_NO; |
| Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 5343 | } else { |
| Dianne Hackborn | 14cee9f | 2010-04-23 17:51:26 -0700 | [diff] [blame] | 5344 | // What size is this screen screen? |
| 5345 | if (longSize >= 800 && shortSize >= 600) { |
| 5346 | // SVGA or larger screens at medium density are the point |
| 5347 | // at which we consider it to be an extra large screen. |
| 5348 | mScreenLayout = Configuration.SCREENLAYOUT_SIZE_XLARGE; |
| 5349 | } else if (longSize >= 640 && shortSize >= 480) { |
| Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 5350 | // VGA or larger screens at medium density are the point |
| 5351 | // at which we consider it to be a large screen. |
| 5352 | mScreenLayout = Configuration.SCREENLAYOUT_SIZE_LARGE; |
| 5353 | } else { |
| 5354 | mScreenLayout = Configuration.SCREENLAYOUT_SIZE_NORMAL; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 5355 | |
| Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 5356 | // If this screen is wider than normal HVGA, or taller |
| 5357 | // than FWVGA, then for old apps we want to run in size |
| 5358 | // compatibility mode. |
| 5359 | if (shortSize > 321 || longSize > 570) { |
| 5360 | mScreenLayout |= Configuration.SCREENLAYOUT_COMPAT_NEEDED; |
| 5361 | } |
| 5362 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 5363 | |
| Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 5364 | // Is this a long screen? |
| 5365 | if (((longSize*3)/5) >= (shortSize-1)) { |
| 5366 | // Anything wider than WVGA (5:3) is considering to be long. |
| 5367 | mScreenLayout |= Configuration.SCREENLAYOUT_LONG_YES; |
| 5368 | } else { |
| 5369 | mScreenLayout |= Configuration.SCREENLAYOUT_LONG_NO; |
| 5370 | } |
| Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 5371 | } |
| 5372 | } |
| Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 5373 | config.screenLayout = mScreenLayout; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 5374 | |
| Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 5375 | config.keyboardHidden = Configuration.KEYBOARDHIDDEN_NO; |
| 5376 | config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_NO; |
| 5377 | mPolicy.adjustConfigurationLw(config); |
| 5378 | return true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5379 | } |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5380 | |
| 5381 | // ------------------------------------------------------------- |
| 5382 | // Drag and drop |
| 5383 | // ------------------------------------------------------------- |
| 5384 | |
| 5385 | IBinder prepareDragSurface(IWindow window, SurfaceSession session, |
| 5386 | boolean localOnly, int width, int height, Surface outSurface) { |
| 5387 | if (DEBUG_DRAG) { |
| 5388 | Slog.d(TAG, "prepare drag surface: w=" + width + " h=" + height |
| 5389 | + " local=" + localOnly + " win=" + window |
| 5390 | + " asbinder=" + window.asBinder()); |
| 5391 | } |
| 5392 | |
| 5393 | final int callerPid = Binder.getCallingPid(); |
| 5394 | final long origId = Binder.clearCallingIdentity(); |
| 5395 | IBinder token = null; |
| 5396 | |
| 5397 | try { |
| 5398 | synchronized (mWindowMap) { |
| 5399 | try { |
| 5400 | // !!! TODO: fail if the given window does not currently have touch focus? |
| 5401 | |
| 5402 | if (mDragState == null) { |
| 5403 | Surface surface = new Surface(session, callerPid, "drag surface", 0, |
| 5404 | width, height, PixelFormat.TRANSLUCENT, Surface.HIDDEN); |
| 5405 | outSurface.copyFrom(surface); |
| 5406 | token = new Binder(); |
| 5407 | mDragState = new DragState(token, surface, localOnly); |
| 5408 | mDragState.mSurface = surface; |
| 5409 | mDragState.mLocalOnly = localOnly; |
| 5410 | token = mDragState.mToken = new Binder(); |
| 5411 | |
| 5412 | // 5 second timeout for this window to actually begin the drag |
| 5413 | mH.removeMessages(H.DRAG_START_TIMEOUT, window); |
| 5414 | Message msg = mH.obtainMessage(H.DRAG_START_TIMEOUT, window.asBinder()); |
| 5415 | mH.sendMessageDelayed(msg, 5000); |
| 5416 | } else { |
| 5417 | Slog.w(TAG, "Drag already in progress"); |
| 5418 | } |
| 5419 | } catch (Surface.OutOfResourcesException e) { |
| 5420 | Slog.e(TAG, "Can't allocate drag surface w=" + width + " h=" + height, e); |
| 5421 | if (mDragState != null) { |
| 5422 | mDragState.reset(); |
| 5423 | mDragState = null; |
| 5424 | } |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5425 | } |
| 5426 | } |
| 5427 | } finally { |
| 5428 | Binder.restoreCallingIdentity(origId); |
| 5429 | } |
| 5430 | |
| 5431 | return token; |
| 5432 | } |
| 5433 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5434 | // ------------------------------------------------------------- |
| 5435 | // Input Events and Focus Management |
| 5436 | // ------------------------------------------------------------- |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5437 | |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5438 | InputMonitor mInputMonitor = new InputMonitor(); |
| 5439 | |
| 5440 | /* Tracks the progress of input dispatch and ensures that input dispatch state |
| 5441 | * is kept in sync with changes in window focus, visibility, registration, and |
| 5442 | * other relevant Window Manager state transitions. */ |
| 5443 | final class InputMonitor { |
| 5444 | // Current window with input focus for keys and other non-touch events. May be null. |
| 5445 | private WindowState mInputFocus; |
| 5446 | |
| 5447 | // When true, prevents input dispatch from proceeding until set to false again. |
| 5448 | private boolean mInputDispatchFrozen; |
| 5449 | |
| 5450 | // When true, input dispatch proceeds normally. Otherwise all events are dropped. |
| 5451 | private boolean mInputDispatchEnabled = true; |
| 5452 | |
| 5453 | // Temporary list of windows information to provide to the input dispatcher. |
| 5454 | private InputWindowList mTempInputWindows = new InputWindowList(); |
| 5455 | |
| 5456 | // Temporary input application object to provide to the input dispatcher. |
| 5457 | private InputApplication mTempInputApplication = new InputApplication(); |
| 5458 | |
| 5459 | /* Notifies the window manager about a broken input channel. |
| 5460 | * |
| 5461 | * Called by the InputManager. |
| 5462 | */ |
| 5463 | public void notifyInputChannelBroken(InputChannel inputChannel) { |
| 5464 | synchronized (mWindowMap) { |
| 5465 | WindowState windowState = getWindowStateForInputChannelLocked(inputChannel); |
| 5466 | if (windowState == null) { |
| 5467 | return; // irrelevant |
| 5468 | } |
| 5469 | |
| 5470 | Slog.i(TAG, "WINDOW DIED " + windowState); |
| 5471 | removeWindowLocked(windowState.mSession, windowState); |
| Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 5472 | } |
| 5473 | } |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5474 | |
| Jeff Brown | 519e024 | 2010-09-15 15:18:56 -0700 | [diff] [blame] | 5475 | /* Notifies the window manager about an application that is not responding. |
| Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 5476 | * 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] | 5477 | * |
| 5478 | * Called by the InputManager. |
| 5479 | */ |
| Jeff Brown | 519e024 | 2010-09-15 15:18:56 -0700 | [diff] [blame] | 5480 | public long notifyANR(Object token, InputChannel inputChannel) { |
| 5481 | AppWindowToken appWindowToken = null; |
| 5482 | if (inputChannel != null) { |
| 5483 | synchronized (mWindowMap) { |
| 5484 | WindowState windowState = getWindowStateForInputChannelLocked(inputChannel); |
| 5485 | if (windowState != null) { |
| 5486 | Slog.i(TAG, "Input event dispatching timed out sending to " |
| 5487 | + windowState.mAttrs.getTitle()); |
| 5488 | appWindowToken = windowState.mAppToken; |
| 5489 | } |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5490 | } |
| Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 5491 | } |
| 5492 | |
| Jeff Brown | 519e024 | 2010-09-15 15:18:56 -0700 | [diff] [blame] | 5493 | if (appWindowToken == null && token != null) { |
| 5494 | appWindowToken = (AppWindowToken) token; |
| 5495 | Slog.i(TAG, "Input event dispatching timed out sending to application " |
| 5496 | + appWindowToken.stringName); |
| 5497 | } |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5498 | |
| Jeff Brown | 519e024 | 2010-09-15 15:18:56 -0700 | [diff] [blame] | 5499 | if (appWindowToken != null && appWindowToken.appToken != null) { |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5500 | try { |
| 5501 | // Notify the activity manager about the timeout and let it decide whether |
| 5502 | // to abort dispatching or keep waiting. |
| Jeff Brown | 519e024 | 2010-09-15 15:18:56 -0700 | [diff] [blame] | 5503 | boolean abort = appWindowToken.appToken.keyDispatchingTimedOut(); |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5504 | if (! abort) { |
| 5505 | // The activity manager declined to abort dispatching. |
| 5506 | // Wait a bit longer and timeout again later. |
| Jeff Brown | 519e024 | 2010-09-15 15:18:56 -0700 | [diff] [blame] | 5507 | return appWindowToken.inputDispatchingTimeoutNanos; |
| Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 5508 | } |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5509 | } catch (RemoteException ex) { |
| Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 5510 | } |
| 5511 | } |
| Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 5512 | return 0; // abort dispatching |
| Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 5513 | } |
| 5514 | |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5515 | private WindowState getWindowStateForInputChannel(InputChannel inputChannel) { |
| 5516 | synchronized (mWindowMap) { |
| 5517 | return getWindowStateForInputChannelLocked(inputChannel); |
| 5518 | } |
| 5519 | } |
| 5520 | |
| 5521 | private WindowState getWindowStateForInputChannelLocked(InputChannel inputChannel) { |
| 5522 | int windowCount = mWindows.size(); |
| 5523 | for (int i = 0; i < windowCount; i++) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 5524 | WindowState windowState = mWindows.get(i); |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5525 | if (windowState.mInputChannel == inputChannel) { |
| 5526 | return windowState; |
| 5527 | } |
| Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 5528 | } |
| 5529 | |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5530 | return null; |
| Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 5531 | } |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5532 | |
| 5533 | private void addDragInputWindow(InputWindowList windowList) { |
| 5534 | final InputWindow inputWindow = windowList.add(); |
| 5535 | inputWindow.inputChannel = mDragState.mServerChannel; |
| 5536 | inputWindow.name = "drag"; |
| 5537 | inputWindow.layoutParamsFlags = 0; |
| 5538 | inputWindow.layoutParamsType = WindowManager.LayoutParams.TYPE_DRAG; |
| 5539 | inputWindow.dispatchingTimeoutNanos = DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS; |
| 5540 | inputWindow.visible = true; |
| 5541 | inputWindow.canReceiveKeys = false; |
| 5542 | inputWindow.hasFocus = true; |
| 5543 | inputWindow.hasWallpaper = false; |
| 5544 | inputWindow.paused = false; |
| 5545 | inputWindow.layer = mPolicy.windowTypeToLayerLw(inputWindow.layoutParamsType) |
| 5546 | * TYPE_LAYER_MULTIPLIER |
| 5547 | + TYPE_LAYER_OFFSET; |
| 5548 | inputWindow.ownerPid = Process.myPid(); |
| 5549 | inputWindow.ownerUid = Process.myUid(); |
| 5550 | |
| 5551 | // The drag window covers the entire display |
| 5552 | inputWindow.frameLeft = 0; |
| 5553 | inputWindow.frameTop = 0; |
| 5554 | inputWindow.frameRight = mDisplay.getWidth(); |
| 5555 | inputWindow.frameBottom = mDisplay.getHeight(); |
| Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 5556 | |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5557 | inputWindow.visibleFrameLeft = inputWindow.frameLeft; |
| 5558 | inputWindow.visibleFrameTop = inputWindow.frameTop; |
| 5559 | inputWindow.visibleFrameRight = inputWindow.frameRight; |
| 5560 | inputWindow.visibleFrameBottom = inputWindow.frameBottom; |
| 5561 | |
| 5562 | inputWindow.touchableAreaLeft = inputWindow.frameLeft; |
| 5563 | inputWindow.touchableAreaTop = inputWindow.frameTop; |
| 5564 | inputWindow.touchableAreaRight = inputWindow.frameRight; |
| 5565 | inputWindow.touchableAreaBottom = inputWindow.frameBottom; |
| 5566 | } |
| 5567 | |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5568 | /* Updates the cached window information provided to the input dispatcher. */ |
| 5569 | public void updateInputWindowsLw() { |
| 5570 | // Populate the input window list with information about all of the windows that |
| 5571 | // could potentially receive input. |
| 5572 | // As an optimization, we could try to prune the list of windows but this turns |
| 5573 | // out to be difficult because only the native code knows for sure which window |
| 5574 | // currently has touch focus. |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 5575 | final ArrayList<WindowState> windows = mWindows; |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5576 | |
| 5577 | // If there's a drag in flight, provide a pseudowindow to catch drag input |
| 5578 | final boolean inDrag = (mDragState != null); |
| 5579 | if (inDrag) { |
| 5580 | if (DEBUG_DRAG) { |
| 5581 | Log.d(TAG, "Inserting drag window"); |
| 5582 | } |
| 5583 | addDragInputWindow(mTempInputWindows); |
| 5584 | } |
| 5585 | |
| Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 5586 | final int N = windows.size(); |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5587 | for (int i = N - 1; i >= 0; i--) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 5588 | final WindowState child = windows.get(i); |
| Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 5589 | if (child.mInputChannel == null || child.mRemoved) { |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5590 | // Skip this window because it cannot possibly receive input. |
| Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 5591 | continue; |
| 5592 | } |
| 5593 | |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5594 | final int flags = child.mAttrs.flags; |
| 5595 | final int type = child.mAttrs.type; |
| 5596 | |
| 5597 | final boolean hasFocus = (child == mInputFocus); |
| 5598 | final boolean isVisible = child.isVisibleLw(); |
| 5599 | final boolean hasWallpaper = (child == mWallpaperTarget) |
| 5600 | && (type != WindowManager.LayoutParams.TYPE_KEYGUARD); |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5601 | |
| 5602 | // If there's a drag in progress and 'child' is a potential drop target, |
| 5603 | // make sure it's been told about the drag |
| 5604 | if (inDrag && isVisible) { |
| 5605 | mDragState.sendDragStartedIfNeededLw(child); |
| 5606 | } |
| 5607 | |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5608 | // Add a window to our list of input windows. |
| 5609 | final InputWindow inputWindow = mTempInputWindows.add(); |
| 5610 | inputWindow.inputChannel = child.mInputChannel; |
| Jeff Brown | 519e024 | 2010-09-15 15:18:56 -0700 | [diff] [blame] | 5611 | inputWindow.name = child.toString(); |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5612 | inputWindow.layoutParamsFlags = flags; |
| 5613 | inputWindow.layoutParamsType = type; |
| 5614 | inputWindow.dispatchingTimeoutNanos = child.getInputDispatchingTimeoutNanos(); |
| 5615 | inputWindow.visible = isVisible; |
| Jeff Brown | 519e024 | 2010-09-15 15:18:56 -0700 | [diff] [blame] | 5616 | inputWindow.canReceiveKeys = child.canReceiveKeys(); |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5617 | inputWindow.hasFocus = hasFocus; |
| 5618 | inputWindow.hasWallpaper = hasWallpaper; |
| 5619 | inputWindow.paused = child.mAppToken != null ? child.mAppToken.paused : false; |
| Jeff Brown | 519e024 | 2010-09-15 15:18:56 -0700 | [diff] [blame] | 5620 | inputWindow.layer = child.mLayer; |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5621 | inputWindow.ownerPid = child.mSession.mPid; |
| 5622 | inputWindow.ownerUid = child.mSession.mUid; |
| 5623 | |
| 5624 | final Rect frame = child.mFrame; |
| 5625 | inputWindow.frameLeft = frame.left; |
| 5626 | inputWindow.frameTop = frame.top; |
| Jeff Brown | 85a3176 | 2010-09-01 17:01:00 -0700 | [diff] [blame] | 5627 | inputWindow.frameRight = frame.right; |
| 5628 | inputWindow.frameBottom = frame.bottom; |
| 5629 | |
| 5630 | final Rect visibleFrame = child.mVisibleFrame; |
| 5631 | inputWindow.visibleFrameLeft = visibleFrame.left; |
| 5632 | inputWindow.visibleFrameTop = visibleFrame.top; |
| 5633 | inputWindow.visibleFrameRight = visibleFrame.right; |
| 5634 | inputWindow.visibleFrameBottom = visibleFrame.bottom; |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5635 | |
| 5636 | switch (child.mTouchableInsets) { |
| 5637 | default: |
| 5638 | case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME: |
| 5639 | inputWindow.touchableAreaLeft = frame.left; |
| 5640 | inputWindow.touchableAreaTop = frame.top; |
| 5641 | inputWindow.touchableAreaRight = frame.right; |
| 5642 | inputWindow.touchableAreaBottom = frame.bottom; |
| 5643 | break; |
| 5644 | |
| 5645 | case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_CONTENT: { |
| 5646 | Rect inset = child.mGivenContentInsets; |
| 5647 | inputWindow.touchableAreaLeft = frame.left + inset.left; |
| 5648 | inputWindow.touchableAreaTop = frame.top + inset.top; |
| 5649 | inputWindow.touchableAreaRight = frame.right - inset.right; |
| 5650 | inputWindow.touchableAreaBottom = frame.bottom - inset.bottom; |
| 5651 | break; |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5652 | } |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5653 | |
| 5654 | case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_VISIBLE: { |
| 5655 | Rect inset = child.mGivenVisibleInsets; |
| 5656 | inputWindow.touchableAreaLeft = frame.left + inset.left; |
| 5657 | inputWindow.touchableAreaTop = frame.top + inset.top; |
| 5658 | inputWindow.touchableAreaRight = frame.right - inset.right; |
| 5659 | inputWindow.touchableAreaBottom = frame.bottom - inset.bottom; |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5660 | break; |
| 5661 | } |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5662 | } |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5663 | } |
| Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 5664 | |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5665 | // Send windows to native code. |
| 5666 | mInputManager.setInputWindows(mTempInputWindows.toNullTerminatedArray()); |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5667 | |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5668 | // Clear the list in preparation for the next round. |
| 5669 | // Also avoids keeping InputChannel objects referenced unnecessarily. |
| 5670 | mTempInputWindows.clear(); |
| 5671 | } |
| 5672 | |
| Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 5673 | /* Provides feedback for a virtual key down. */ |
| 5674 | public void virtualKeyDownFeedback() { |
| 5675 | synchronized (mWindowMap) { |
| 5676 | mPolicy.performHapticFeedbackLw(null, HapticFeedbackConstants.VIRTUAL_KEY, false); |
| 5677 | } |
| 5678 | } |
| 5679 | |
| Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 5680 | /* Notifies that the lid switch changed state. */ |
| 5681 | public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen) { |
| 5682 | mPolicy.notifyLidSwitchChanged(whenNanos, lidOpen); |
| 5683 | } |
| 5684 | |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5685 | /* Provides an opportunity for the window manager policy to intercept early key |
| 5686 | * processing as soon as the key has been read from the device. */ |
| Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 5687 | public int interceptKeyBeforeQueueing(long whenNanos, int keyCode, boolean down, |
| 5688 | int policyFlags, boolean isScreenOn) { |
| 5689 | return mPolicy.interceptKeyBeforeQueueing(whenNanos, |
| 5690 | keyCode, down, policyFlags, isScreenOn); |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5691 | } |
| 5692 | |
| 5693 | /* Provides an opportunity for the window manager policy to process a key before |
| 5694 | * ordinary dispatch. */ |
| Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 5695 | public boolean interceptKeyBeforeDispatching(InputChannel focus, |
| 5696 | int action, int flags, int keyCode, int metaState, int repeatCount, |
| 5697 | int policyFlags) { |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5698 | WindowState windowState = getWindowStateForInputChannel(focus); |
| Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 5699 | return mPolicy.interceptKeyBeforeDispatching(windowState, action, flags, |
| 5700 | keyCode, metaState, repeatCount, policyFlags); |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5701 | } |
| 5702 | |
| 5703 | /* Called when the current input focus changes. |
| 5704 | * Layer assignment is assumed to be complete by the time this is called. |
| 5705 | */ |
| 5706 | public void setInputFocusLw(WindowState newWindow) { |
| 5707 | if (DEBUG_INPUT) { |
| 5708 | Slog.d(TAG, "Input focus has changed to " + newWindow); |
| 5709 | } |
| 5710 | |
| 5711 | if (newWindow != mInputFocus) { |
| 5712 | if (newWindow != null && newWindow.canReceiveKeys()) { |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5713 | // Displaying a window implicitly causes dispatching to be unpaused. |
| 5714 | // This is to protect against bugs if someone pauses dispatching but |
| 5715 | // forgets to resume. |
| 5716 | newWindow.mToken.paused = false; |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5717 | } |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5718 | |
| 5719 | mInputFocus = newWindow; |
| 5720 | updateInputWindowsLw(); |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5721 | } |
| 5722 | } |
| 5723 | |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5724 | public void setFocusedAppLw(AppWindowToken newApp) { |
| 5725 | // Focused app has changed. |
| 5726 | if (newApp == null) { |
| 5727 | mInputManager.setFocusedApplication(null); |
| 5728 | } else { |
| 5729 | mTempInputApplication.name = newApp.toString(); |
| 5730 | mTempInputApplication.dispatchingTimeoutNanos = |
| 5731 | newApp.inputDispatchingTimeoutNanos; |
| 5732 | mTempInputApplication.token = newApp; |
| 5733 | |
| 5734 | mInputManager.setFocusedApplication(mTempInputApplication); |
| 5735 | } |
| 5736 | } |
| 5737 | |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5738 | public void pauseDispatchingLw(WindowToken window) { |
| 5739 | if (! window.paused) { |
| 5740 | if (DEBUG_INPUT) { |
| 5741 | Slog.v(TAG, "Pausing WindowToken " + window); |
| 5742 | } |
| 5743 | |
| 5744 | window.paused = true; |
| 5745 | updateInputWindowsLw(); |
| 5746 | } |
| 5747 | } |
| 5748 | |
| 5749 | public void resumeDispatchingLw(WindowToken window) { |
| 5750 | if (window.paused) { |
| 5751 | if (DEBUG_INPUT) { |
| 5752 | Slog.v(TAG, "Resuming WindowToken " + window); |
| 5753 | } |
| 5754 | |
| 5755 | window.paused = false; |
| 5756 | updateInputWindowsLw(); |
| 5757 | } |
| 5758 | } |
| 5759 | |
| 5760 | public void freezeInputDispatchingLw() { |
| 5761 | if (! mInputDispatchFrozen) { |
| 5762 | if (DEBUG_INPUT) { |
| 5763 | Slog.v(TAG, "Freezing input dispatching"); |
| 5764 | } |
| 5765 | |
| 5766 | mInputDispatchFrozen = true; |
| 5767 | updateInputDispatchModeLw(); |
| 5768 | } |
| 5769 | } |
| 5770 | |
| 5771 | public void thawInputDispatchingLw() { |
| 5772 | if (mInputDispatchFrozen) { |
| 5773 | if (DEBUG_INPUT) { |
| 5774 | Slog.v(TAG, "Thawing input dispatching"); |
| 5775 | } |
| 5776 | |
| 5777 | mInputDispatchFrozen = false; |
| 5778 | updateInputDispatchModeLw(); |
| 5779 | } |
| 5780 | } |
| 5781 | |
| 5782 | public void setEventDispatchingLw(boolean enabled) { |
| 5783 | if (mInputDispatchEnabled != enabled) { |
| 5784 | if (DEBUG_INPUT) { |
| 5785 | Slog.v(TAG, "Setting event dispatching to " + enabled); |
| 5786 | } |
| 5787 | |
| 5788 | mInputDispatchEnabled = enabled; |
| 5789 | updateInputDispatchModeLw(); |
| 5790 | } |
| 5791 | } |
| 5792 | |
| 5793 | private void updateInputDispatchModeLw() { |
| 5794 | mInputManager.setInputDispatchMode(mInputDispatchEnabled, mInputDispatchFrozen); |
| 5795 | } |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5796 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5797 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5798 | public void pauseKeyDispatching(IBinder _token) { |
| 5799 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 5800 | "pauseKeyDispatching()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5801 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5802 | } |
| 5803 | |
| 5804 | synchronized (mWindowMap) { |
| 5805 | WindowToken token = mTokenMap.get(_token); |
| 5806 | if (token != null) { |
| Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 5807 | mInputMonitor.pauseDispatchingLw(token); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5808 | } |
| 5809 | } |
| 5810 | } |
| 5811 | |
| 5812 | public void resumeKeyDispatching(IBinder _token) { |
| 5813 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 5814 | "resumeKeyDispatching()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5815 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5816 | } |
| 5817 | |
| 5818 | synchronized (mWindowMap) { |
| 5819 | WindowToken token = mTokenMap.get(_token); |
| 5820 | if (token != null) { |
| Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 5821 | mInputMonitor.resumeDispatchingLw(token); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5822 | } |
| 5823 | } |
| 5824 | } |
| 5825 | |
| 5826 | public void setEventDispatching(boolean enabled) { |
| 5827 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 5828 | "resumeKeyDispatching()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5829 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5830 | } |
| 5831 | |
| 5832 | synchronized (mWindowMap) { |
| Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 5833 | mInputMonitor.setEventDispatchingLw(enabled); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5834 | } |
| 5835 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5836 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5837 | /** |
| 5838 | * Injects a keystroke event into the UI. |
| Jeff Brown | bbda99d | 2010-07-28 15:48:59 -0700 | [diff] [blame] | 5839 | * Even when sync is false, this method may block while waiting for current |
| 5840 | * input events to be dispatched. |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5841 | * |
| 5842 | * @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] | 5843 | * {@link SystemClock#uptimeMillis()} as the timebase.) |
| 5844 | * @param sync If true, wait for the event to be completed before returning to the caller. |
| 5845 | * @return Returns true if event was dispatched, false if it was dropped for any reason |
| 5846 | */ |
| 5847 | public boolean injectKeyEvent(KeyEvent ev, boolean sync) { |
| 5848 | long downTime = ev.getDownTime(); |
| 5849 | long eventTime = ev.getEventTime(); |
| 5850 | |
| 5851 | int action = ev.getAction(); |
| 5852 | int code = ev.getKeyCode(); |
| 5853 | int repeatCount = ev.getRepeatCount(); |
| 5854 | int metaState = ev.getMetaState(); |
| 5855 | int deviceId = ev.getDeviceId(); |
| 5856 | int scancode = ev.getScanCode(); |
| Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 5857 | int source = ev.getSource(); |
| 5858 | |
| 5859 | if (source == InputDevice.SOURCE_UNKNOWN) { |
| 5860 | source = InputDevice.SOURCE_KEYBOARD; |
| 5861 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5862 | |
| 5863 | if (eventTime == 0) eventTime = SystemClock.uptimeMillis(); |
| 5864 | if (downTime == 0) downTime = eventTime; |
| 5865 | |
| 5866 | KeyEvent newEvent = new KeyEvent(downTime, eventTime, action, code, repeatCount, metaState, |
| Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 5867 | deviceId, scancode, KeyEvent.FLAG_FROM_SYSTEM, source); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5868 | |
| Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5869 | final int pid = Binder.getCallingPid(); |
| 5870 | final int uid = Binder.getCallingUid(); |
| 5871 | final long ident = Binder.clearCallingIdentity(); |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5872 | |
| Jeff Brown | bbda99d | 2010-07-28 15:48:59 -0700 | [diff] [blame] | 5873 | final int result = mInputManager.injectInputEvent(newEvent, pid, uid, |
| 5874 | sync ? InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH |
| 5875 | : InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT, |
| 5876 | INJECTION_TIMEOUT_MILLIS); |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5877 | |
| Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5878 | Binder.restoreCallingIdentity(ident); |
| Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 5879 | return reportInjectionResult(result); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5880 | } |
| 5881 | |
| 5882 | /** |
| 5883 | * Inject a pointer (touch) event into the UI. |
| Jeff Brown | bbda99d | 2010-07-28 15:48:59 -0700 | [diff] [blame] | 5884 | * Even when sync is false, this method may block while waiting for current |
| 5885 | * input events to be dispatched. |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5886 | * |
| 5887 | * @param ev A motion event describing the pointer (touch) action. (As noted in |
| 5888 | * {@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] | 5889 | * {@link SystemClock#uptimeMillis()} as the timebase.) |
| 5890 | * @param sync If true, wait for the event to be completed before returning to the caller. |
| 5891 | * @return Returns true if event was dispatched, false if it was dropped for any reason |
| 5892 | */ |
| 5893 | public boolean injectPointerEvent(MotionEvent ev, boolean sync) { |
| Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5894 | final int pid = Binder.getCallingPid(); |
| 5895 | final int uid = Binder.getCallingUid(); |
| 5896 | final long ident = Binder.clearCallingIdentity(); |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5897 | |
| Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 5898 | MotionEvent newEvent = MotionEvent.obtain(ev); |
| 5899 | if ((newEvent.getSource() & InputDevice.SOURCE_CLASS_POINTER) == 0) { |
| 5900 | newEvent.setSource(InputDevice.SOURCE_TOUCHSCREEN); |
| 5901 | } |
| 5902 | |
| Jeff Brown | bbda99d | 2010-07-28 15:48:59 -0700 | [diff] [blame] | 5903 | final int result = mInputManager.injectInputEvent(newEvent, pid, uid, |
| 5904 | sync ? InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH |
| 5905 | : InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT, |
| 5906 | INJECTION_TIMEOUT_MILLIS); |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5907 | |
| Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5908 | Binder.restoreCallingIdentity(ident); |
| Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 5909 | return reportInjectionResult(result); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5910 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5911 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5912 | /** |
| 5913 | * Inject a trackball (navigation device) event into the UI. |
| Jeff Brown | bbda99d | 2010-07-28 15:48:59 -0700 | [diff] [blame] | 5914 | * Even when sync is false, this method may block while waiting for current |
| 5915 | * input events to be dispatched. |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5916 | * |
| 5917 | * @param ev A motion event describing the trackball action. (As noted in |
| 5918 | * {@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] | 5919 | * {@link SystemClock#uptimeMillis()} as the timebase.) |
| 5920 | * @param sync If true, wait for the event to be completed before returning to the caller. |
| 5921 | * @return Returns true if event was dispatched, false if it was dropped for any reason |
| 5922 | */ |
| 5923 | public boolean injectTrackballEvent(MotionEvent ev, boolean sync) { |
| Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5924 | final int pid = Binder.getCallingPid(); |
| 5925 | final int uid = Binder.getCallingUid(); |
| 5926 | final long ident = Binder.clearCallingIdentity(); |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5927 | |
| Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 5928 | MotionEvent newEvent = MotionEvent.obtain(ev); |
| 5929 | if ((newEvent.getSource() & InputDevice.SOURCE_CLASS_TRACKBALL) == 0) { |
| 5930 | newEvent.setSource(InputDevice.SOURCE_TRACKBALL); |
| 5931 | } |
| 5932 | |
| Jeff Brown | bbda99d | 2010-07-28 15:48:59 -0700 | [diff] [blame] | 5933 | final int result = mInputManager.injectInputEvent(newEvent, pid, uid, |
| 5934 | sync ? InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH |
| 5935 | : InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT, |
| 5936 | INJECTION_TIMEOUT_MILLIS); |
| 5937 | |
| 5938 | Binder.restoreCallingIdentity(ident); |
| 5939 | return reportInjectionResult(result); |
| 5940 | } |
| 5941 | |
| 5942 | /** |
| 5943 | * Inject an input event into the UI without waiting for dispatch to commence. |
| 5944 | * This variant is useful for fire-and-forget input event injection. It does not |
| 5945 | * block any longer than it takes to enqueue the input event. |
| 5946 | * |
| 5947 | * @param ev An input event. (Be sure to set the input source correctly.) |
| 5948 | * @return Returns true if event was dispatched, false if it was dropped for any reason |
| 5949 | */ |
| 5950 | public boolean injectInputEventNoWait(InputEvent ev) { |
| 5951 | final int pid = Binder.getCallingPid(); |
| 5952 | final int uid = Binder.getCallingUid(); |
| 5953 | final long ident = Binder.clearCallingIdentity(); |
| 5954 | |
| 5955 | final int result = mInputManager.injectInputEvent(ev, pid, uid, |
| 5956 | InputManager.INPUT_EVENT_INJECTION_SYNC_NONE, |
| 5957 | INJECTION_TIMEOUT_MILLIS); |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5958 | |
| Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5959 | Binder.restoreCallingIdentity(ident); |
| Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 5960 | return reportInjectionResult(result); |
| 5961 | } |
| 5962 | |
| 5963 | private boolean reportInjectionResult(int result) { |
| Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 5964 | switch (result) { |
| 5965 | case InputManager.INPUT_EVENT_INJECTION_PERMISSION_DENIED: |
| 5966 | Slog.w(TAG, "Input event injection permission denied."); |
| 5967 | throw new SecurityException( |
| 5968 | "Injecting to another application requires INJECT_EVENTS permission"); |
| 5969 | case InputManager.INPUT_EVENT_INJECTION_SUCCEEDED: |
| Christopher Tate | 09e85dc | 2010-08-02 11:54:41 -0700 | [diff] [blame] | 5970 | //Slog.v(TAG, "Input event injection succeeded."); |
| Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 5971 | return true; |
| 5972 | case InputManager.INPUT_EVENT_INJECTION_TIMED_OUT: |
| 5973 | Slog.w(TAG, "Input event injection timed out."); |
| 5974 | return false; |
| 5975 | case InputManager.INPUT_EVENT_INJECTION_FAILED: |
| 5976 | default: |
| 5977 | Slog.w(TAG, "Input event injection failed."); |
| 5978 | return false; |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5979 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5980 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5981 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5982 | private WindowState getFocusedWindow() { |
| 5983 | synchronized (mWindowMap) { |
| 5984 | return getFocusedWindowLocked(); |
| 5985 | } |
| 5986 | } |
| 5987 | |
| 5988 | private WindowState getFocusedWindowLocked() { |
| 5989 | return mCurrentFocus; |
| 5990 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5991 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5992 | public boolean detectSafeMode() { |
| 5993 | mSafeMode = mPolicy.detectSafeMode(); |
| 5994 | return mSafeMode; |
| 5995 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5996 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5997 | public void systemReady() { |
| Dianne Hackborn | 5132b37 | 2010-07-29 12:51:35 -0700 | [diff] [blame] | 5998 | synchronized(mWindowMap) { |
| 5999 | if (mDisplay != null) { |
| 6000 | throw new IllegalStateException("Display already initialized"); |
| 6001 | } |
| 6002 | WindowManager wm = (WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE); |
| 6003 | mDisplay = wm.getDefaultDisplay(); |
| 6004 | mInitialDisplayWidth = mDisplay.getWidth(); |
| 6005 | mInitialDisplayHeight = mDisplay.getHeight(); |
| 6006 | mInputManager.setDisplaySize(0, mInitialDisplayWidth, mInitialDisplayHeight); |
| 6007 | } |
| 6008 | |
| 6009 | try { |
| 6010 | mActivityManager.updateConfiguration(null); |
| 6011 | } catch (RemoteException e) { |
| 6012 | } |
| Dianne Hackborn | 154db5f | 2010-07-29 19:15:19 -0700 | [diff] [blame] | 6013 | |
| 6014 | mPolicy.systemReady(); |
| Dianne Hackborn | 5132b37 | 2010-07-29 12:51:35 -0700 | [diff] [blame] | 6015 | } |
| 6016 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6017 | // ------------------------------------------------------------- |
| 6018 | // Client Session State |
| 6019 | // ------------------------------------------------------------- |
| 6020 | |
| 6021 | private final class Session extends IWindowSession.Stub |
| 6022 | implements IBinder.DeathRecipient { |
| 6023 | final IInputMethodClient mClient; |
| 6024 | final IInputContext mInputContext; |
| 6025 | final int mUid; |
| 6026 | final int mPid; |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 6027 | final String mStringName; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6028 | SurfaceSession mSurfaceSession; |
| 6029 | int mNumWindow = 0; |
| 6030 | boolean mClientDead = false; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6031 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6032 | public Session(IInputMethodClient client, IInputContext inputContext) { |
| 6033 | mClient = client; |
| 6034 | mInputContext = inputContext; |
| 6035 | mUid = Binder.getCallingUid(); |
| 6036 | mPid = Binder.getCallingPid(); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 6037 | StringBuilder sb = new StringBuilder(); |
| 6038 | sb.append("Session{"); |
| 6039 | sb.append(Integer.toHexString(System.identityHashCode(this))); |
| 6040 | sb.append(" uid "); |
| 6041 | sb.append(mUid); |
| 6042 | sb.append("}"); |
| 6043 | mStringName = sb.toString(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6044 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6045 | synchronized (mWindowMap) { |
| 6046 | if (mInputMethodManager == null && mHaveInputMethods) { |
| 6047 | IBinder b = ServiceManager.getService( |
| 6048 | Context.INPUT_METHOD_SERVICE); |
| 6049 | mInputMethodManager = IInputMethodManager.Stub.asInterface(b); |
| 6050 | } |
| 6051 | } |
| 6052 | long ident = Binder.clearCallingIdentity(); |
| 6053 | try { |
| 6054 | // Note: it is safe to call in to the input method manager |
| 6055 | // here because we are not holding our lock. |
| 6056 | if (mInputMethodManager != null) { |
| 6057 | mInputMethodManager.addClient(client, inputContext, |
| 6058 | mUid, mPid); |
| 6059 | } else { |
| 6060 | client.setUsingInputMethod(false); |
| 6061 | } |
| 6062 | client.asBinder().linkToDeath(this, 0); |
| 6063 | } catch (RemoteException e) { |
| 6064 | // The caller has died, so we can just forget about this. |
| 6065 | try { |
| 6066 | if (mInputMethodManager != null) { |
| 6067 | mInputMethodManager.removeClient(client); |
| 6068 | } |
| 6069 | } catch (RemoteException ee) { |
| 6070 | } |
| 6071 | } finally { |
| 6072 | Binder.restoreCallingIdentity(ident); |
| 6073 | } |
| 6074 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6075 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6076 | @Override |
| 6077 | public boolean onTransact(int code, Parcel data, Parcel reply, int flags) |
| 6078 | throws RemoteException { |
| 6079 | try { |
| 6080 | return super.onTransact(code, data, reply, flags); |
| 6081 | } catch (RuntimeException e) { |
| 6082 | // Log all 'real' exceptions thrown to the caller |
| 6083 | if (!(e instanceof SecurityException)) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6084 | Slog.e(TAG, "Window Session Crash", e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6085 | } |
| 6086 | throw e; |
| 6087 | } |
| 6088 | } |
| 6089 | |
| 6090 | public void binderDied() { |
| 6091 | // Note: it is safe to call in to the input method manager |
| 6092 | // here because we are not holding our lock. |
| 6093 | try { |
| 6094 | if (mInputMethodManager != null) { |
| 6095 | mInputMethodManager.removeClient(mClient); |
| 6096 | } |
| 6097 | } catch (RemoteException e) { |
| 6098 | } |
| 6099 | synchronized(mWindowMap) { |
| Suchi Amalapurapu | fff2fda | 2009-06-30 21:36:16 -0700 | [diff] [blame] | 6100 | mClient.asBinder().unlinkToDeath(this, 0); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6101 | mClientDead = true; |
| 6102 | killSessionLocked(); |
| 6103 | } |
| 6104 | } |
| 6105 | |
| 6106 | public int add(IWindow window, WindowManager.LayoutParams attrs, |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 6107 | int viewVisibility, Rect outContentInsets, InputChannel outInputChannel) { |
| 6108 | return addWindow(this, window, attrs, viewVisibility, outContentInsets, |
| 6109 | outInputChannel); |
| 6110 | } |
| 6111 | |
| 6112 | public int addWithoutInputChannel(IWindow window, WindowManager.LayoutParams attrs, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6113 | int viewVisibility, Rect outContentInsets) { |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 6114 | return addWindow(this, window, attrs, viewVisibility, outContentInsets, null); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6115 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6116 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6117 | public void remove(IWindow window) { |
| 6118 | removeWindow(this, window); |
| 6119 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6120 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6121 | public int relayout(IWindow window, WindowManager.LayoutParams attrs, |
| 6122 | int requestedWidth, int requestedHeight, int viewFlags, |
| 6123 | boolean insetsPending, Rect outFrame, Rect outContentInsets, |
| Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 6124 | Rect outVisibleInsets, Configuration outConfig, Surface outSurface) { |
| Dianne Hackborn | f123e49 | 2010-09-24 11:16:23 -0700 | [diff] [blame] | 6125 | //Log.d(TAG, ">>>>>> ENTERED relayout from " + Binder.getCallingPid()); |
| 6126 | int res = relayoutWindow(this, window, attrs, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6127 | requestedWidth, requestedHeight, viewFlags, insetsPending, |
| Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 6128 | outFrame, outContentInsets, outVisibleInsets, outConfig, outSurface); |
| Dianne Hackborn | f123e49 | 2010-09-24 11:16:23 -0700 | [diff] [blame] | 6129 | //Log.d(TAG, "<<<<<< EXITING relayout to " + Binder.getCallingPid()); |
| 6130 | return res; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6131 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6132 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6133 | public void setTransparentRegion(IWindow window, Region region) { |
| 6134 | setTransparentRegionWindow(this, window, region); |
| 6135 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6136 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6137 | public void setInsets(IWindow window, int touchableInsets, |
| 6138 | Rect contentInsets, Rect visibleInsets) { |
| 6139 | setInsetsWindow(this, window, touchableInsets, contentInsets, |
| 6140 | visibleInsets); |
| 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 void getDisplayFrame(IWindow window, Rect outDisplayFrame) { |
| 6144 | getWindowDisplayFrame(this, window, outDisplayFrame); |
| 6145 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6146 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6147 | public void finishDrawing(IWindow window) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6148 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6149 | TAG, "IWindow finishDrawing called for " + window); |
| 6150 | finishDrawingWindow(this, window); |
| 6151 | } |
| 6152 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6153 | public void setInTouchMode(boolean mode) { |
| 6154 | synchronized(mWindowMap) { |
| 6155 | mInTouchMode = mode; |
| 6156 | } |
| 6157 | } |
| 6158 | |
| 6159 | public boolean getInTouchMode() { |
| 6160 | synchronized(mWindowMap) { |
| 6161 | return mInTouchMode; |
| 6162 | } |
| 6163 | } |
| 6164 | |
| 6165 | public boolean performHapticFeedback(IWindow window, int effectId, |
| 6166 | boolean always) { |
| 6167 | synchronized(mWindowMap) { |
| 6168 | long ident = Binder.clearCallingIdentity(); |
| 6169 | try { |
| The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 6170 | return mPolicy.performHapticFeedbackLw( |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 6171 | windowForClientLocked(this, window, true), |
| 6172 | effectId, always); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6173 | } finally { |
| 6174 | Binder.restoreCallingIdentity(ident); |
| 6175 | } |
| 6176 | } |
| 6177 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6178 | |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 6179 | /* Drag/drop */ |
| 6180 | public IBinder prepareDrag(IWindow window, boolean localOnly, |
| 6181 | int width, int height, Surface outSurface) { |
| 6182 | return prepareDragSurface(window, mSurfaceSession, localOnly, |
| 6183 | width, height, outSurface); |
| 6184 | } |
| 6185 | |
| 6186 | public boolean performDrag(IWindow window, IBinder dragToken, |
| 6187 | float touchX, float touchY, float thumbCenterX, float thumbCenterY, |
| 6188 | ClipData data) { |
| 6189 | if (DEBUG_DRAG) { |
| 6190 | Slog.d(TAG, "perform drag: win=" + window + " data=" + data); |
| 6191 | } |
| 6192 | |
| 6193 | synchronized (mWindowMap) { |
| 6194 | if (mDragState == null) { |
| 6195 | Slog.w(TAG, "No drag prepared"); |
| 6196 | throw new IllegalStateException("performDrag() without prepareDrag()"); |
| 6197 | } |
| 6198 | |
| 6199 | if (dragToken != mDragState.mToken) { |
| 6200 | Slog.w(TAG, "Performing mismatched drag"); |
| 6201 | throw new IllegalStateException("performDrag() does not match prepareDrag()"); |
| 6202 | } |
| 6203 | |
| 6204 | WindowState callingWin = windowForClientLocked(null, window, false); |
| 6205 | if (callingWin == null) { |
| 6206 | Slog.w(TAG, "Bad requesting window " + window); |
| 6207 | return false; // !!! TODO: throw here? |
| 6208 | } |
| 6209 | |
| 6210 | // !!! TODO: if input is not still focused on the initiating window, fail |
| 6211 | // the drag initiation (e.g. an alarm window popped up just as the application |
| 6212 | // called performDrag() |
| 6213 | |
| 6214 | mH.removeMessages(H.DRAG_START_TIMEOUT, window.asBinder()); |
| 6215 | |
| Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 6216 | // !!! TODO: extract the current touch (x, y) in screen coordinates. That |
| 6217 | // will let us eliminate the (touchX,touchY) parameters from the API. |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 6218 | |
| 6219 | mDragState.register(); |
| 6220 | mInputMonitor.updateInputWindowsLw(); |
| 6221 | mInputManager.transferTouchFocus(callingWin.mInputChannel, |
| 6222 | mDragState.mServerChannel); |
| 6223 | |
| 6224 | mDragState.mData = data; |
| 6225 | mDragState.broadcastDragStartedLw(); |
| 6226 | |
| 6227 | // remember the thumb offsets for later |
| 6228 | mDragState.mThumbOffsetX = thumbCenterX; |
| 6229 | mDragState.mThumbOffsetY = thumbCenterY; |
| 6230 | |
| 6231 | // Make the surface visible at the proper location |
| 6232 | final Surface surface = mDragState.mSurface; |
| 6233 | surface.openTransaction(); |
| 6234 | try { |
| 6235 | surface.setPosition((int)(touchX - thumbCenterX), |
| 6236 | (int)(touchY - thumbCenterY)); |
| 6237 | surface.setAlpha(.5f); |
| 6238 | surface.show(); |
| 6239 | } finally { |
| 6240 | surface.closeTransaction(); |
| 6241 | } |
| 6242 | } |
| 6243 | |
| 6244 | return true; // success! |
| 6245 | } |
| 6246 | |
| 6247 | public void dragRecipientEntered(IWindow window) { |
| 6248 | if (DEBUG_DRAG) { |
| 6249 | Slog.d(TAG, "Drag into new candidate view @ " + window); |
| 6250 | } |
| 6251 | } |
| 6252 | |
| 6253 | public void dragRecipientExited(IWindow window) { |
| 6254 | if (DEBUG_DRAG) { |
| 6255 | Slog.d(TAG, "Drag from old candidate view @ " + window); |
| 6256 | } |
| 6257 | } |
| 6258 | |
| Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 6259 | 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] | 6260 | synchronized(mWindowMap) { |
| 6261 | long ident = Binder.clearCallingIdentity(); |
| 6262 | try { |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 6263 | setWindowWallpaperPositionLocked( |
| 6264 | windowForClientLocked(this, window, true), |
| Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 6265 | x, y, xStep, yStep); |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 6266 | } finally { |
| 6267 | Binder.restoreCallingIdentity(ident); |
| 6268 | } |
| 6269 | } |
| 6270 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6271 | |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 6272 | public void wallpaperOffsetsComplete(IBinder window) { |
| 6273 | WindowManagerService.this.wallpaperOffsetsComplete(window); |
| 6274 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6275 | |
| Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 6276 | public Bundle sendWallpaperCommand(IBinder window, String action, int x, int y, |
| 6277 | int z, Bundle extras, boolean sync) { |
| 6278 | synchronized(mWindowMap) { |
| 6279 | long ident = Binder.clearCallingIdentity(); |
| 6280 | try { |
| 6281 | return sendWindowWallpaperCommandLocked( |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 6282 | windowForClientLocked(this, window, true), |
| Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 6283 | action, x, y, z, extras, sync); |
| 6284 | } finally { |
| 6285 | Binder.restoreCallingIdentity(ident); |
| 6286 | } |
| 6287 | } |
| 6288 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6289 | |
| Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 6290 | public void wallpaperCommandComplete(IBinder window, Bundle result) { |
| 6291 | WindowManagerService.this.wallpaperCommandComplete(window, result); |
| 6292 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6293 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6294 | void windowAddedLocked() { |
| 6295 | if (mSurfaceSession == null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6296 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6297 | TAG, "First window added to " + this + ", creating SurfaceSession"); |
| 6298 | mSurfaceSession = new SurfaceSession(); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6299 | if (SHOW_TRANSACTIONS) Slog.i( |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 6300 | TAG, " NEW SURFACE SESSION " + mSurfaceSession); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6301 | mSessions.add(this); |
| 6302 | } |
| 6303 | mNumWindow++; |
| 6304 | } |
| 6305 | |
| 6306 | void windowRemovedLocked() { |
| 6307 | mNumWindow--; |
| 6308 | killSessionLocked(); |
| 6309 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6310 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6311 | void killSessionLocked() { |
| 6312 | if (mNumWindow <= 0 && mClientDead) { |
| 6313 | mSessions.remove(this); |
| 6314 | if (mSurfaceSession != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6315 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6316 | TAG, "Last window removed from " + this |
| 6317 | + ", destroying " + mSurfaceSession); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6318 | if (SHOW_TRANSACTIONS) Slog.i( |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 6319 | TAG, " KILL SURFACE SESSION " + mSurfaceSession); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6320 | try { |
| 6321 | mSurfaceSession.kill(); |
| 6322 | } catch (Exception e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6323 | Slog.w(TAG, "Exception thrown when killing surface session " |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6324 | + mSurfaceSession + " in session " + this |
| 6325 | + ": " + e.toString()); |
| 6326 | } |
| 6327 | mSurfaceSession = null; |
| 6328 | } |
| 6329 | } |
| 6330 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6331 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6332 | void dump(PrintWriter pw, String prefix) { |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 6333 | pw.print(prefix); pw.print("mNumWindow="); pw.print(mNumWindow); |
| 6334 | pw.print(" mClientDead="); pw.print(mClientDead); |
| 6335 | pw.print(" mSurfaceSession="); pw.println(mSurfaceSession); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6336 | } |
| 6337 | |
| 6338 | @Override |
| 6339 | public String toString() { |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 6340 | return mStringName; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6341 | } |
| 6342 | } |
| 6343 | |
| 6344 | // ------------------------------------------------------------- |
| 6345 | // Client Window State |
| 6346 | // ------------------------------------------------------------- |
| 6347 | |
| 6348 | private final class WindowState implements WindowManagerPolicy.WindowState { |
| 6349 | final Session mSession; |
| 6350 | final IWindow mClient; |
| 6351 | WindowToken mToken; |
| The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 6352 | WindowToken mRootToken; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6353 | AppWindowToken mAppToken; |
| 6354 | AppWindowToken mTargetAppToken; |
| 6355 | final WindowManager.LayoutParams mAttrs = new WindowManager.LayoutParams(); |
| 6356 | final DeathRecipient mDeathRecipient; |
| 6357 | final WindowState mAttachedWindow; |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 6358 | final ArrayList<WindowState> mChildWindows = new ArrayList<WindowState>(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6359 | final int mBaseLayer; |
| 6360 | final int mSubLayer; |
| 6361 | final boolean mLayoutAttached; |
| 6362 | final boolean mIsImWindow; |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 6363 | final boolean mIsWallpaper; |
| 6364 | final boolean mIsFloatingLayer; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6365 | int mViewVisibility; |
| 6366 | boolean mPolicyVisibility = true; |
| 6367 | boolean mPolicyVisibilityAfterAnim = true; |
| 6368 | boolean mAppFreezing; |
| 6369 | Surface mSurface; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 6370 | boolean mReportDestroySurface; |
| 6371 | boolean mSurfacePendingDestroy; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6372 | boolean mAttachedHidden; // is our parent window hidden? |
| 6373 | boolean mLastHidden; // was this window last hidden? |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 6374 | boolean mWallpaperVisible; // for wallpaper, what was last vis report? |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6375 | int mRequestedWidth; |
| 6376 | int mRequestedHeight; |
| 6377 | int mLastRequestedWidth; |
| 6378 | int mLastRequestedHeight; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6379 | int mLayer; |
| 6380 | int mAnimLayer; |
| 6381 | int mLastLayer; |
| 6382 | boolean mHaveFrame; |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 6383 | boolean mObscured; |
| Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 6384 | boolean mTurnOnScreen; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6385 | |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 6386 | int mLayoutSeq = -1; |
| 6387 | |
| 6388 | Configuration mConfiguration = null; |
| 6389 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6390 | // Actual frame shown on-screen (may be modified by animation) |
| 6391 | final Rect mShownFrame = new Rect(); |
| 6392 | final Rect mLastShownFrame = new Rect(); |
| 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 | /** |
| Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 6395 | * Set when we have changed the size of the surface, to know that |
| 6396 | * we must tell them application to resize (and thus redraw itself). |
| 6397 | */ |
| 6398 | boolean mSurfaceResized; |
| 6399 | |
| 6400 | /** |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6401 | * Insets that determine the actually visible area |
| 6402 | */ |
| 6403 | final Rect mVisibleInsets = new Rect(); |
| 6404 | final Rect mLastVisibleInsets = new Rect(); |
| 6405 | boolean mVisibleInsetsChanged; |
| 6406 | |
| 6407 | /** |
| 6408 | * Insets that are covered by system windows |
| 6409 | */ |
| 6410 | final Rect mContentInsets = new Rect(); |
| 6411 | final Rect mLastContentInsets = new Rect(); |
| 6412 | boolean mContentInsetsChanged; |
| 6413 | |
| 6414 | /** |
| 6415 | * Set to true if we are waiting for this window to receive its |
| 6416 | * given internal insets before laying out other windows based on it. |
| 6417 | */ |
| 6418 | boolean mGivenInsetsPending; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6419 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6420 | /** |
| 6421 | * These are the content insets that were given during layout for |
| 6422 | * this window, to be applied to windows behind it. |
| 6423 | */ |
| 6424 | final Rect mGivenContentInsets = new Rect(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6425 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6426 | /** |
| 6427 | * These are the visible insets that were given during layout for |
| 6428 | * this window, to be applied to windows behind it. |
| 6429 | */ |
| 6430 | final Rect mGivenVisibleInsets = new Rect(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6431 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6432 | /** |
| 6433 | * Flag indicating whether the touchable region should be adjusted by |
| 6434 | * the visible insets; if false the area outside the visible insets is |
| 6435 | * NOT touchable, so we must use those to adjust the frame during hit |
| 6436 | * tests. |
| 6437 | */ |
| 6438 | int mTouchableInsets = ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6439 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6440 | // Current transformation being applied. |
| 6441 | float mDsDx=1, mDtDx=0, mDsDy=0, mDtDy=1; |
| 6442 | float mLastDsDx=1, mLastDtDx=0, mLastDsDy=0, mLastDtDy=1; |
| 6443 | float mHScale=1, mVScale=1; |
| 6444 | float mLastHScale=1, mLastVScale=1; |
| 6445 | final Matrix mTmpMatrix = new Matrix(); |
| 6446 | |
| 6447 | // "Real" frame that the application sees. |
| 6448 | final Rect mFrame = new Rect(); |
| 6449 | final Rect mLastFrame = new Rect(); |
| 6450 | |
| 6451 | final Rect mContainingFrame = new Rect(); |
| 6452 | final Rect mDisplayFrame = new Rect(); |
| 6453 | final Rect mContentFrame = new Rect(); |
| 6454 | final Rect mVisibleFrame = new Rect(); |
| 6455 | |
| 6456 | float mShownAlpha = 1; |
| 6457 | float mAlpha = 1; |
| 6458 | float mLastAlpha = 1; |
| 6459 | |
| 6460 | // Set to true if, when the window gets displayed, it should perform |
| 6461 | // an enter animation. |
| 6462 | boolean mEnterAnimationPending; |
| 6463 | |
| 6464 | // Currently running animation. |
| 6465 | boolean mAnimating; |
| 6466 | boolean mLocalAnimating; |
| 6467 | Animation mAnimation; |
| 6468 | boolean mAnimationIsEntrance; |
| 6469 | boolean mHasTransformation; |
| 6470 | boolean mHasLocalTransformation; |
| 6471 | final Transformation mTransformation = new Transformation(); |
| 6472 | |
| Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 6473 | // If a window showing a wallpaper: the requested offset for the |
| 6474 | // wallpaper; if a wallpaper window: the currently applied offset. |
| 6475 | float mWallpaperX = -1; |
| 6476 | float mWallpaperY = -1; |
| Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 6477 | |
| 6478 | // If a window showing a wallpaper: what fraction of the offset |
| 6479 | // range corresponds to a full virtual screen. |
| 6480 | float mWallpaperXStep = -1; |
| 6481 | float mWallpaperYStep = -1; |
| 6482 | |
| Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 6483 | // Wallpaper windows: pixels offset based on above variables. |
| 6484 | int mXOffset; |
| 6485 | int mYOffset; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6486 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6487 | // This is set after IWindowSession.relayout() has been called at |
| 6488 | // least once for the window. It allows us to detect the situation |
| 6489 | // where we don't yet have a surface, but should have one soon, so |
| 6490 | // we can give the window focus before waiting for the relayout. |
| 6491 | boolean mRelayoutCalled; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6492 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6493 | // This is set after the Surface has been created but before the |
| 6494 | // window has been drawn. During this time the surface is hidden. |
| 6495 | boolean mDrawPending; |
| 6496 | |
| 6497 | // This is set after the window has finished drawing for the first |
| 6498 | // time but before its surface is shown. The surface will be |
| 6499 | // displayed when the next layout is run. |
| 6500 | boolean mCommitDrawPending; |
| 6501 | |
| 6502 | // This is set during the time after the window's drawing has been |
| 6503 | // committed, and before its surface is actually shown. It is used |
| 6504 | // to delay showing the surface until all windows in a token are ready |
| 6505 | // to be shown. |
| 6506 | boolean mReadyToShow; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6507 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6508 | // Set when the window has been shown in the screen the first time. |
| 6509 | boolean mHasDrawn; |
| 6510 | |
| 6511 | // Currently running an exit animation? |
| 6512 | boolean mExiting; |
| 6513 | |
| 6514 | // Currently on the mDestroySurface list? |
| 6515 | boolean mDestroying; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6516 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6517 | // Completely remove from window manager after exit animation? |
| 6518 | boolean mRemoveOnExit; |
| 6519 | |
| 6520 | // Set when the orientation is changing and this window has not yet |
| 6521 | // been updated for the new orientation. |
| 6522 | boolean mOrientationChanging; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6523 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6524 | // Is this window now (or just being) removed? |
| 6525 | boolean mRemoved; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6526 | |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 6527 | // For debugging, this is the last information given to the surface flinger. |
| 6528 | boolean mSurfaceShown; |
| 6529 | int mSurfaceX, mSurfaceY, mSurfaceW, mSurfaceH; |
| 6530 | int mSurfaceLayer; |
| 6531 | float mSurfaceAlpha; |
| 6532 | |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 6533 | // Input channel |
| 6534 | InputChannel mInputChannel; |
| 6535 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6536 | WindowState(Session s, IWindow c, WindowToken token, |
| 6537 | WindowState attachedWindow, WindowManager.LayoutParams a, |
| 6538 | int viewVisibility) { |
| 6539 | mSession = s; |
| 6540 | mClient = c; |
| 6541 | mToken = token; |
| 6542 | mAttrs.copyFrom(a); |
| 6543 | mViewVisibility = viewVisibility; |
| 6544 | DeathRecipient deathRecipient = new DeathRecipient(); |
| 6545 | mAlpha = a.alpha; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6546 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6547 | TAG, "Window " + this + " client=" + c.asBinder() |
| 6548 | + " token=" + token + " (" + mAttrs.token + ")"); |
| 6549 | try { |
| 6550 | c.asBinder().linkToDeath(deathRecipient, 0); |
| 6551 | } catch (RemoteException e) { |
| 6552 | mDeathRecipient = null; |
| 6553 | mAttachedWindow = null; |
| 6554 | mLayoutAttached = false; |
| 6555 | mIsImWindow = false; |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 6556 | mIsWallpaper = false; |
| 6557 | mIsFloatingLayer = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6558 | mBaseLayer = 0; |
| 6559 | mSubLayer = 0; |
| 6560 | return; |
| 6561 | } |
| 6562 | mDeathRecipient = deathRecipient; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6563 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6564 | if ((mAttrs.type >= FIRST_SUB_WINDOW && |
| 6565 | mAttrs.type <= LAST_SUB_WINDOW)) { |
| 6566 | // The multiplier here is to reserve space for multiple |
| 6567 | // windows in the same type layer. |
| 6568 | mBaseLayer = mPolicy.windowTypeToLayerLw( |
| 6569 | attachedWindow.mAttrs.type) * TYPE_LAYER_MULTIPLIER |
| 6570 | + TYPE_LAYER_OFFSET; |
| 6571 | mSubLayer = mPolicy.subWindowTypeToLayerLw(a.type); |
| 6572 | mAttachedWindow = attachedWindow; |
| 6573 | mAttachedWindow.mChildWindows.add(this); |
| 6574 | mLayoutAttached = mAttrs.type != |
| 6575 | WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG; |
| 6576 | mIsImWindow = attachedWindow.mAttrs.type == TYPE_INPUT_METHOD |
| 6577 | || attachedWindow.mAttrs.type == TYPE_INPUT_METHOD_DIALOG; |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 6578 | mIsWallpaper = attachedWindow.mAttrs.type == TYPE_WALLPAPER; |
| 6579 | mIsFloatingLayer = mIsImWindow || mIsWallpaper; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6580 | } else { |
| 6581 | // The multiplier here is to reserve space for multiple |
| 6582 | // windows in the same type layer. |
| 6583 | mBaseLayer = mPolicy.windowTypeToLayerLw(a.type) |
| 6584 | * TYPE_LAYER_MULTIPLIER |
| 6585 | + TYPE_LAYER_OFFSET; |
| 6586 | mSubLayer = 0; |
| 6587 | mAttachedWindow = null; |
| 6588 | mLayoutAttached = false; |
| 6589 | mIsImWindow = mAttrs.type == TYPE_INPUT_METHOD |
| 6590 | || mAttrs.type == TYPE_INPUT_METHOD_DIALOG; |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 6591 | mIsWallpaper = mAttrs.type == TYPE_WALLPAPER; |
| 6592 | mIsFloatingLayer = mIsImWindow || mIsWallpaper; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6593 | } |
| 6594 | |
| 6595 | WindowState appWin = this; |
| 6596 | while (appWin.mAttachedWindow != null) { |
| 6597 | appWin = mAttachedWindow; |
| 6598 | } |
| 6599 | WindowToken appToken = appWin.mToken; |
| 6600 | while (appToken.appWindowToken == null) { |
| 6601 | WindowToken parent = mTokenMap.get(appToken.token); |
| 6602 | if (parent == null || appToken == parent) { |
| 6603 | break; |
| 6604 | } |
| 6605 | appToken = parent; |
| 6606 | } |
| The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 6607 | mRootToken = appToken; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6608 | mAppToken = appToken.appWindowToken; |
| 6609 | |
| 6610 | mSurface = null; |
| 6611 | mRequestedWidth = 0; |
| 6612 | mRequestedHeight = 0; |
| 6613 | mLastRequestedWidth = 0; |
| 6614 | mLastRequestedHeight = 0; |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 6615 | mXOffset = 0; |
| 6616 | mYOffset = 0; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6617 | mLayer = 0; |
| 6618 | mAnimLayer = 0; |
| 6619 | mLastLayer = 0; |
| 6620 | } |
| 6621 | |
| 6622 | void attach() { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6623 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6624 | TAG, "Attaching " + this + " token=" + mToken |
| 6625 | + ", list=" + mToken.windows); |
| 6626 | mSession.windowAddedLocked(); |
| 6627 | } |
| 6628 | |
| 6629 | public void computeFrameLw(Rect pf, Rect df, Rect cf, Rect vf) { |
| 6630 | mHaveFrame = true; |
| 6631 | |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 6632 | final Rect container = mContainingFrame; |
| 6633 | container.set(pf); |
| 6634 | |
| 6635 | final Rect display = mDisplayFrame; |
| 6636 | display.set(df); |
| 6637 | |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 6638 | if ((mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0) { |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 6639 | container.intersect(mCompatibleScreenFrame); |
| Mitsuru Oshima | d2967e2 | 2009-07-20 14:01:43 -0700 | [diff] [blame] | 6640 | if ((mAttrs.flags & FLAG_LAYOUT_NO_LIMITS) == 0) { |
| 6641 | display.intersect(mCompatibleScreenFrame); |
| 6642 | } |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 6643 | } |
| 6644 | |
| 6645 | final int pw = container.right - container.left; |
| 6646 | final int ph = container.bottom - container.top; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6647 | |
| 6648 | int w,h; |
| 6649 | if ((mAttrs.flags & mAttrs.FLAG_SCALED) != 0) { |
| 6650 | w = mAttrs.width < 0 ? pw : mAttrs.width; |
| 6651 | h = mAttrs.height< 0 ? ph : mAttrs.height; |
| 6652 | } else { |
| Romain Guy | 980a938 | 2010-01-08 15:06:28 -0800 | [diff] [blame] | 6653 | w = mAttrs.width == mAttrs.MATCH_PARENT ? pw : mRequestedWidth; |
| 6654 | h = mAttrs.height== mAttrs.MATCH_PARENT ? ph : mRequestedHeight; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6655 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6656 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6657 | final Rect content = mContentFrame; |
| 6658 | content.set(cf); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6659 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6660 | final Rect visible = mVisibleFrame; |
| 6661 | visible.set(vf); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6662 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6663 | final Rect frame = mFrame; |
| Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 6664 | final int fw = frame.width(); |
| 6665 | final int fh = frame.height(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6666 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6667 | //System.out.println("In: w=" + w + " h=" + h + " container=" + |
| 6668 | // container + " x=" + mAttrs.x + " y=" + mAttrs.y); |
| 6669 | |
| 6670 | Gravity.apply(mAttrs.gravity, w, h, container, |
| 6671 | (int) (mAttrs.x + mAttrs.horizontalMargin * pw), |
| 6672 | (int) (mAttrs.y + mAttrs.verticalMargin * ph), frame); |
| 6673 | |
| 6674 | //System.out.println("Out: " + mFrame); |
| 6675 | |
| 6676 | // Now make sure the window fits in the overall display. |
| 6677 | Gravity.applyDisplay(mAttrs.gravity, df, frame); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6678 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6679 | // Make sure the content and visible frames are inside of the |
| 6680 | // final window frame. |
| 6681 | if (content.left < frame.left) content.left = frame.left; |
| 6682 | if (content.top < frame.top) content.top = frame.top; |
| 6683 | if (content.right > frame.right) content.right = frame.right; |
| 6684 | if (content.bottom > frame.bottom) content.bottom = frame.bottom; |
| 6685 | if (visible.left < frame.left) visible.left = frame.left; |
| 6686 | if (visible.top < frame.top) visible.top = frame.top; |
| 6687 | if (visible.right > frame.right) visible.right = frame.right; |
| 6688 | if (visible.bottom > frame.bottom) visible.bottom = frame.bottom; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6689 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6690 | final Rect contentInsets = mContentInsets; |
| 6691 | contentInsets.left = content.left-frame.left; |
| 6692 | contentInsets.top = content.top-frame.top; |
| 6693 | contentInsets.right = frame.right-content.right; |
| 6694 | contentInsets.bottom = frame.bottom-content.bottom; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6695 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6696 | final Rect visibleInsets = mVisibleInsets; |
| 6697 | visibleInsets.left = visible.left-frame.left; |
| 6698 | visibleInsets.top = visible.top-frame.top; |
| 6699 | visibleInsets.right = frame.right-visible.right; |
| 6700 | visibleInsets.bottom = frame.bottom-visible.bottom; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6701 | |
| Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 6702 | if (mIsWallpaper && (fw != frame.width() || fh != frame.height())) { |
| 6703 | updateWallpaperOffsetLocked(this, mDisplay.getWidth(), |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 6704 | mDisplay.getHeight(), false); |
| Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 6705 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6706 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6707 | if (localLOGV) { |
| 6708 | //if ("com.google.android.youtube".equals(mAttrs.packageName) |
| 6709 | // && mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_PANEL) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6710 | Slog.v(TAG, "Resolving (mRequestedWidth=" |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6711 | + mRequestedWidth + ", mRequestedheight=" |
| 6712 | + mRequestedHeight + ") to" + " (pw=" + pw + ", ph=" + ph |
| 6713 | + "): frame=" + mFrame.toShortString() |
| 6714 | + " ci=" + contentInsets.toShortString() |
| 6715 | + " vi=" + visibleInsets.toShortString()); |
| 6716 | //} |
| 6717 | } |
| 6718 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6719 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6720 | public Rect getFrameLw() { |
| 6721 | return mFrame; |
| 6722 | } |
| 6723 | |
| 6724 | public Rect getShownFrameLw() { |
| 6725 | return mShownFrame; |
| 6726 | } |
| 6727 | |
| 6728 | public Rect getDisplayFrameLw() { |
| 6729 | return mDisplayFrame; |
| 6730 | } |
| 6731 | |
| 6732 | public Rect getContentFrameLw() { |
| 6733 | return mContentFrame; |
| 6734 | } |
| 6735 | |
| 6736 | public Rect getVisibleFrameLw() { |
| 6737 | return mVisibleFrame; |
| 6738 | } |
| 6739 | |
| 6740 | public boolean getGivenInsetsPendingLw() { |
| 6741 | return mGivenInsetsPending; |
| 6742 | } |
| 6743 | |
| 6744 | public Rect getGivenContentInsetsLw() { |
| 6745 | return mGivenContentInsets; |
| 6746 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6747 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6748 | public Rect getGivenVisibleInsetsLw() { |
| 6749 | return mGivenVisibleInsets; |
| 6750 | } |
| 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 | public WindowManager.LayoutParams getAttrs() { |
| 6753 | return mAttrs; |
| 6754 | } |
| 6755 | |
| 6756 | public int getSurfaceLayer() { |
| 6757 | return mLayer; |
| 6758 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6759 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6760 | public IApplicationToken getAppToken() { |
| 6761 | return mAppToken != null ? mAppToken.appToken : null; |
| 6762 | } |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 6763 | |
| 6764 | public long getInputDispatchingTimeoutNanos() { |
| 6765 | return mAppToken != null |
| 6766 | ? mAppToken.inputDispatchingTimeoutNanos |
| 6767 | : DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS; |
| 6768 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6769 | |
| 6770 | public boolean hasAppShownWindows() { |
| 6771 | return mAppToken != null ? mAppToken.firstWindowDrawn : false; |
| 6772 | } |
| 6773 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6774 | public void setAnimation(Animation anim) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6775 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6776 | TAG, "Setting animation in " + this + ": " + anim); |
| 6777 | mAnimating = false; |
| 6778 | mLocalAnimating = false; |
| 6779 | mAnimation = anim; |
| 6780 | mAnimation.restrictDuration(MAX_ANIMATION_DURATION); |
| 6781 | mAnimation.scaleCurrentDuration(mWindowAnimationScale); |
| 6782 | } |
| 6783 | |
| 6784 | public void clearAnimation() { |
| 6785 | if (mAnimation != null) { |
| 6786 | mAnimating = true; |
| 6787 | mLocalAnimating = false; |
| 6788 | mAnimation = null; |
| 6789 | } |
| 6790 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6791 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6792 | Surface createSurfaceLocked() { |
| 6793 | if (mSurface == null) { |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 6794 | mReportDestroySurface = false; |
| 6795 | mSurfacePendingDestroy = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6796 | mDrawPending = true; |
| 6797 | mCommitDrawPending = false; |
| 6798 | mReadyToShow = false; |
| 6799 | if (mAppToken != null) { |
| 6800 | mAppToken.allDrawn = false; |
| 6801 | } |
| 6802 | |
| 6803 | int flags = 0; |
| Mathias Agopian | 317a628 | 2009-08-13 17:29:02 -0700 | [diff] [blame] | 6804 | if (mAttrs.memoryType == MEMORY_TYPE_PUSH_BUFFERS) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6805 | flags |= Surface.PUSH_BUFFERS; |
| 6806 | } |
| 6807 | |
| 6808 | if ((mAttrs.flags&WindowManager.LayoutParams.FLAG_SECURE) != 0) { |
| 6809 | flags |= Surface.SECURE; |
| 6810 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6811 | if (DEBUG_VISIBILITY) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6812 | TAG, "Creating surface in session " |
| 6813 | + mSession.mSurfaceSession + " window " + this |
| 6814 | + " w=" + mFrame.width() |
| 6815 | + " h=" + mFrame.height() + " format=" |
| 6816 | + mAttrs.format + " flags=" + flags); |
| 6817 | |
| 6818 | int w = mFrame.width(); |
| 6819 | int h = mFrame.height(); |
| 6820 | if ((mAttrs.flags & LayoutParams.FLAG_SCALED) != 0) { |
| 6821 | // for a scaled surface, we always want the requested |
| 6822 | // size. |
| 6823 | w = mRequestedWidth; |
| 6824 | h = mRequestedHeight; |
| 6825 | } |
| 6826 | |
| Romain Guy | 9825ec6 | 2009-10-01 00:58:09 -0700 | [diff] [blame] | 6827 | // Something is wrong and SurfaceFlinger will not like this, |
| 6828 | // try to revert to sane values |
| 6829 | if (w <= 0) w = 1; |
| 6830 | if (h <= 0) h = 1; |
| 6831 | |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 6832 | mSurfaceShown = false; |
| 6833 | mSurfaceLayer = 0; |
| 6834 | mSurfaceAlpha = 1; |
| 6835 | mSurfaceX = 0; |
| 6836 | mSurfaceY = 0; |
| 6837 | mSurfaceW = w; |
| 6838 | mSurfaceH = h; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6839 | try { |
| 6840 | mSurface = new Surface( |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6841 | mSession.mSurfaceSession, mSession.mPid, |
| Mathias Agopian | 5d26c1e | 2010-03-01 16:09:43 -0800 | [diff] [blame] | 6842 | mAttrs.getTitle().toString(), |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6843 | 0, w, h, mAttrs.format, flags); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6844 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " CREATE SURFACE " |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 6845 | + mSurface + " IN SESSION " |
| 6846 | + mSession.mSurfaceSession |
| 6847 | + ": pid=" + mSession.mPid + " format=" |
| 6848 | + mAttrs.format + " flags=0x" |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 6849 | + Integer.toHexString(flags) |
| 6850 | + " / " + this); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6851 | } catch (Surface.OutOfResourcesException e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6852 | Slog.w(TAG, "OutOfResourcesException creating surface"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6853 | reclaimSomeSurfaceMemoryLocked(this, "create"); |
| 6854 | return null; |
| 6855 | } catch (Exception e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6856 | Slog.e(TAG, "Exception creating surface", e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6857 | return null; |
| 6858 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6859 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6860 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6861 | TAG, "Got surface: " + mSurface |
| 6862 | + ", set left=" + mFrame.left + " top=" + mFrame.top |
| 6863 | + ", animLayer=" + mAnimLayer); |
| 6864 | if (SHOW_TRANSACTIONS) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6865 | Slog.i(TAG, ">>> OPEN TRANSACTION"); |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 6866 | if (SHOW_TRANSACTIONS) logSurface(this, |
| 6867 | "CREATE pos=(" + mFrame.left + "," + mFrame.top + ") (" + |
| 6868 | mFrame.width() + "x" + mFrame.height() + "), layer=" + |
| 6869 | mAnimLayer + " HIDE", null); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6870 | } |
| 6871 | Surface.openTransaction(); |
| 6872 | try { |
| 6873 | try { |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 6874 | mSurfaceX = mFrame.left + mXOffset; |
| Dianne Hackborn | 529bef6 | 2010-03-25 11:48:43 -0700 | [diff] [blame] | 6875 | mSurfaceY = mFrame.top + mYOffset; |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 6876 | mSurface.setPosition(mSurfaceX, mSurfaceY); |
| 6877 | mSurfaceLayer = mAnimLayer; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6878 | mSurface.setLayer(mAnimLayer); |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 6879 | mSurfaceShown = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6880 | mSurface.hide(); |
| 6881 | if ((mAttrs.flags&WindowManager.LayoutParams.FLAG_DITHER) != 0) { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 6882 | if (SHOW_TRANSACTIONS) logSurface(this, "DITHER", null); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6883 | mSurface.setFlags(Surface.SURFACE_DITHER, |
| 6884 | Surface.SURFACE_DITHER); |
| 6885 | } |
| 6886 | } catch (RuntimeException e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6887 | Slog.w(TAG, "Error creating surface in " + w, e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6888 | reclaimSomeSurfaceMemoryLocked(this, "create-init"); |
| 6889 | } |
| 6890 | mLastHidden = true; |
| 6891 | } finally { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6892 | if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6893 | Surface.closeTransaction(); |
| 6894 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6895 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6896 | TAG, "Created surface " + this); |
| 6897 | } |
| 6898 | return mSurface; |
| 6899 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6900 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6901 | void destroySurfaceLocked() { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6902 | if (mAppToken != null && this == mAppToken.startingWindow) { |
| 6903 | mAppToken.startingDisplayed = false; |
| 6904 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6905 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6906 | if (mSurface != null) { |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 6907 | mDrawPending = false; |
| 6908 | mCommitDrawPending = false; |
| 6909 | mReadyToShow = false; |
| 6910 | |
| 6911 | int i = mChildWindows.size(); |
| 6912 | while (i > 0) { |
| 6913 | i--; |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 6914 | WindowState c = mChildWindows.get(i); |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 6915 | c.mAttachedHidden = true; |
| 6916 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6917 | |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 6918 | if (mReportDestroySurface) { |
| 6919 | mReportDestroySurface = false; |
| 6920 | mSurfacePendingDestroy = true; |
| 6921 | try { |
| 6922 | mClient.dispatchGetNewSurface(); |
| 6923 | // We'll really destroy on the next time around. |
| 6924 | return; |
| 6925 | } catch (RemoteException e) { |
| 6926 | } |
| 6927 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6928 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6929 | try { |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 6930 | if (DEBUG_VISIBILITY) { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 6931 | RuntimeException e = null; |
| 6932 | if (!HIDE_STACK_CRAWLS) { |
| 6933 | e = new RuntimeException(); |
| 6934 | e.fillInStackTrace(); |
| 6935 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6936 | Slog.w(TAG, "Window " + this + " destroying surface " |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 6937 | + mSurface + ", session " + mSession, e); |
| 6938 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6939 | if (SHOW_TRANSACTIONS) { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 6940 | RuntimeException e = null; |
| 6941 | if (!HIDE_STACK_CRAWLS) { |
| 6942 | e = new RuntimeException(); |
| 6943 | e.fillInStackTrace(); |
| 6944 | } |
| 6945 | if (SHOW_TRANSACTIONS) logSurface(this, "DESTROY", e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6946 | } |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 6947 | mSurface.destroy(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6948 | } catch (RuntimeException e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6949 | Slog.w(TAG, "Exception thrown when destroying Window " + this |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6950 | + " surface " + mSurface + " session " + mSession |
| 6951 | + ": " + e.toString()); |
| 6952 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6953 | |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 6954 | mSurfaceShown = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6955 | mSurface = null; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6956 | } |
| 6957 | } |
| 6958 | |
| 6959 | boolean finishDrawingLocked() { |
| 6960 | if (mDrawPending) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6961 | if (SHOW_TRANSACTIONS || DEBUG_ORIENTATION) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6962 | TAG, "finishDrawingLocked: " + mSurface); |
| 6963 | mCommitDrawPending = true; |
| 6964 | mDrawPending = false; |
| 6965 | return true; |
| 6966 | } |
| 6967 | return false; |
| 6968 | } |
| 6969 | |
| 6970 | // This must be called while inside a transaction. |
| Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 6971 | boolean commitFinishDrawingLocked(long currentTime) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6972 | //Slog.i(TAG, "commitFinishDrawingLocked: " + mSurface); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6973 | if (!mCommitDrawPending) { |
| Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 6974 | return false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6975 | } |
| 6976 | mCommitDrawPending = false; |
| 6977 | mReadyToShow = true; |
| 6978 | final boolean starting = mAttrs.type == TYPE_APPLICATION_STARTING; |
| 6979 | final AppWindowToken atoken = mAppToken; |
| 6980 | if (atoken == null || atoken.allDrawn || starting) { |
| 6981 | performShowLocked(); |
| 6982 | } |
| Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 6983 | return true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6984 | } |
| 6985 | |
| 6986 | // This must be called while inside a transaction. |
| 6987 | boolean performShowLocked() { |
| 6988 | if (DEBUG_VISIBILITY) { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 6989 | RuntimeException e = null; |
| 6990 | if (!HIDE_STACK_CRAWLS) { |
| 6991 | e = new RuntimeException(); |
| 6992 | e.fillInStackTrace(); |
| 6993 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6994 | Slog.v(TAG, "performShow on " + this |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6995 | + ": readyToShow=" + mReadyToShow + " readyForDisplay=" + isReadyForDisplay() |
| 6996 | + " starting=" + (mAttrs.type == TYPE_APPLICATION_STARTING), e); |
| 6997 | } |
| 6998 | if (mReadyToShow && isReadyForDisplay()) { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 6999 | if (SHOW_TRANSACTIONS || DEBUG_ORIENTATION) logSurface(this, |
| 7000 | "SHOW (performShowLocked)", null); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7001 | if (DEBUG_VISIBILITY) Slog.v(TAG, "Showing " + this |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7002 | + " during animation: policyVis=" + mPolicyVisibility |
| 7003 | + " attHidden=" + mAttachedHidden |
| 7004 | + " tok.hiddenRequested=" |
| 7005 | + (mAppToken != null ? mAppToken.hiddenRequested : false) |
| Dianne Hackborn | 248b188 | 2009-09-16 16:46:44 -0700 | [diff] [blame] | 7006 | + " tok.hidden=" |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7007 | + (mAppToken != null ? mAppToken.hidden : false) |
| 7008 | + " animating=" + mAnimating |
| 7009 | + " tok animating=" |
| 7010 | + (mAppToken != null ? mAppToken.animating : false)); |
| 7011 | if (!showSurfaceRobustlyLocked(this)) { |
| 7012 | return false; |
| 7013 | } |
| 7014 | mLastAlpha = -1; |
| 7015 | mHasDrawn = true; |
| 7016 | mLastHidden = false; |
| 7017 | mReadyToShow = false; |
| 7018 | enableScreenIfNeededLocked(); |
| 7019 | |
| 7020 | applyEnterAnimationLocked(this); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7021 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7022 | int i = mChildWindows.size(); |
| 7023 | while (i > 0) { |
| 7024 | i--; |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 7025 | WindowState c = mChildWindows.get(i); |
| Dianne Hackborn | f09c1a2 | 2010-04-22 15:59:21 -0700 | [diff] [blame] | 7026 | if (c.mAttachedHidden) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7027 | c.mAttachedHidden = false; |
| Dianne Hackborn | f09c1a2 | 2010-04-22 15:59:21 -0700 | [diff] [blame] | 7028 | if (c.mSurface != null) { |
| 7029 | c.performShowLocked(); |
| 7030 | // It hadn't been shown, which means layout not |
| 7031 | // performed on it, so now we want to make sure to |
| 7032 | // do a layout. If called from within the transaction |
| 7033 | // loop, this will cause it to restart with a new |
| 7034 | // layout. |
| 7035 | mLayoutNeeded = true; |
| 7036 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7037 | } |
| 7038 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7039 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7040 | if (mAttrs.type != TYPE_APPLICATION_STARTING |
| 7041 | && mAppToken != null) { |
| 7042 | mAppToken.firstWindowDrawn = true; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7043 | |
| Dianne Hackborn | 248b188 | 2009-09-16 16:46:44 -0700 | [diff] [blame] | 7044 | if (mAppToken.startingData != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7045 | if (DEBUG_STARTING_WINDOW || DEBUG_ANIM) Slog.v(TAG, |
| Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 7046 | "Finish starting " + mToken |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7047 | + ": first real window is shown, no animation"); |
| Dianne Hackborn | 248b188 | 2009-09-16 16:46:44 -0700 | [diff] [blame] | 7048 | // If this initial window is animating, stop it -- we |
| 7049 | // will do an animation to reveal it from behind the |
| 7050 | // starting window, so there is no need for it to also |
| 7051 | // be doing its own stuff. |
| 7052 | if (mAnimation != null) { |
| 7053 | mAnimation = null; |
| 7054 | // Make sure we clean up the animation. |
| 7055 | mAnimating = true; |
| 7056 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7057 | mFinishedStarting.add(mAppToken); |
| 7058 | mH.sendEmptyMessage(H.FINISHED_STARTING); |
| 7059 | } |
| 7060 | mAppToken.updateReportedVisibilityLocked(); |
| 7061 | } |
| 7062 | } |
| 7063 | return true; |
| 7064 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7065 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7066 | // This must be called while inside a transaction. Returns true if |
| 7067 | // there is more animation to run. |
| 7068 | boolean stepAnimationLocked(long currentTime, int dw, int dh) { |
| Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 7069 | if (!mDisplayFrozen && mPolicy.isScreenOn()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7070 | // We will run animations as long as the display isn't frozen. |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7071 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7072 | if (!mDrawPending && !mCommitDrawPending && mAnimation != null) { |
| 7073 | mHasTransformation = true; |
| 7074 | mHasLocalTransformation = true; |
| 7075 | if (!mLocalAnimating) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7076 | if (DEBUG_ANIM) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7077 | TAG, "Starting animation in " + this + |
| 7078 | " @ " + currentTime + ": ww=" + mFrame.width() + " wh=" + mFrame.height() + |
| 7079 | " dw=" + dw + " dh=" + dh + " scale=" + mWindowAnimationScale); |
| 7080 | mAnimation.initialize(mFrame.width(), mFrame.height(), dw, dh); |
| 7081 | mAnimation.setStartTime(currentTime); |
| 7082 | mLocalAnimating = true; |
| 7083 | mAnimating = true; |
| 7084 | } |
| 7085 | mTransformation.clear(); |
| 7086 | final boolean more = mAnimation.getTransformation( |
| 7087 | currentTime, mTransformation); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7088 | if (DEBUG_ANIM) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7089 | TAG, "Stepped animation in " + this + |
| 7090 | ": more=" + more + ", xform=" + mTransformation); |
| 7091 | if (more) { |
| 7092 | // we're not done! |
| 7093 | return true; |
| 7094 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7095 | if (DEBUG_ANIM) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7096 | TAG, "Finished animation in " + this + |
| 7097 | " @ " + currentTime); |
| 7098 | mAnimation = null; |
| 7099 | //WindowManagerService.this.dump(); |
| 7100 | } |
| 7101 | mHasLocalTransformation = false; |
| 7102 | if ((!mLocalAnimating || mAnimationIsEntrance) && mAppToken != null |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 7103 | && mAppToken.animation != null) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7104 | // When our app token is animating, we kind-of pretend like |
| 7105 | // we are as well. Note the mLocalAnimating mAnimationIsEntrance |
| 7106 | // part of this check means that we will only do this if |
| 7107 | // our window is not currently exiting, or it is not |
| 7108 | // locally animating itself. The idea being that one that |
| 7109 | // is exiting and doing a local animation should be removed |
| 7110 | // once that animation is done. |
| 7111 | mAnimating = true; |
| 7112 | mHasTransformation = true; |
| 7113 | mTransformation.clear(); |
| 7114 | return false; |
| 7115 | } else if (mHasTransformation) { |
| 7116 | // Little trick to get through the path below to act like |
| 7117 | // we have finished an animation. |
| 7118 | mAnimating = true; |
| 7119 | } else if (isAnimating()) { |
| 7120 | mAnimating = true; |
| 7121 | } |
| 7122 | } else if (mAnimation != null) { |
| 7123 | // If the display is frozen, and there is a pending animation, |
| 7124 | // clear it and make sure we run the cleanup code. |
| 7125 | mAnimating = true; |
| 7126 | mLocalAnimating = true; |
| 7127 | mAnimation = null; |
| 7128 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7129 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7130 | if (!mAnimating && !mLocalAnimating) { |
| 7131 | return false; |
| 7132 | } |
| 7133 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7134 | if (DEBUG_ANIM) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7135 | TAG, "Animation done in " + this + ": exiting=" + mExiting |
| 7136 | + ", reportedVisible=" |
| 7137 | + (mAppToken != null ? mAppToken.reportedVisible : false)); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7138 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7139 | mAnimating = false; |
| 7140 | mLocalAnimating = false; |
| 7141 | mAnimation = null; |
| 7142 | mAnimLayer = mLayer; |
| 7143 | if (mIsImWindow) { |
| 7144 | mAnimLayer += mInputMethodAnimLayerAdjustment; |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 7145 | } else if (mIsWallpaper) { |
| 7146 | mAnimLayer += mWallpaperAnimLayerAdjustment; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7147 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7148 | if (DEBUG_LAYERS) Slog.v(TAG, "Stepping win " + this |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7149 | + " anim layer: " + mAnimLayer); |
| 7150 | mHasTransformation = false; |
| 7151 | mHasLocalTransformation = false; |
| Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 7152 | if (mPolicyVisibility != mPolicyVisibilityAfterAnim) { |
| 7153 | if (DEBUG_VISIBILITY) { |
| 7154 | Slog.v(TAG, "Policy visibility changing after anim in " + this + ": " |
| 7155 | + mPolicyVisibilityAfterAnim); |
| 7156 | } |
| 7157 | mPolicyVisibility = mPolicyVisibilityAfterAnim; |
| 7158 | if (!mPolicyVisibility) { |
| 7159 | if (mCurrentFocus == this) { |
| 7160 | mFocusMayChange = true; |
| 7161 | } |
| 7162 | // Window is no longer visible -- make sure if we were waiting |
| 7163 | // for it to be displayed before enabling the display, that |
| 7164 | // we allow the display to be enabled now. |
| 7165 | enableScreenIfNeededLocked(); |
| 7166 | } |
| Dianne Hackborn | f3bea9c | 2009-12-09 18:26:21 -0800 | [diff] [blame] | 7167 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7168 | mTransformation.clear(); |
| 7169 | if (mHasDrawn |
| 7170 | && mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING |
| 7171 | && mAppToken != null |
| 7172 | && mAppToken.firstWindowDrawn |
| 7173 | && mAppToken.startingData != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7174 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Finish starting " |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7175 | + mToken + ": first real window done animating"); |
| 7176 | mFinishedStarting.add(mAppToken); |
| 7177 | mH.sendEmptyMessage(H.FINISHED_STARTING); |
| 7178 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7179 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7180 | finishExit(); |
| 7181 | |
| 7182 | if (mAppToken != null) { |
| 7183 | mAppToken.updateReportedVisibilityLocked(); |
| 7184 | } |
| 7185 | |
| 7186 | return false; |
| 7187 | } |
| 7188 | |
| 7189 | void finishExit() { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7190 | if (DEBUG_ANIM) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7191 | TAG, "finishExit in " + this |
| 7192 | + ": exiting=" + mExiting |
| 7193 | + " remove=" + mRemoveOnExit |
| 7194 | + " windowAnimating=" + isWindowAnimating()); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7195 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7196 | final int N = mChildWindows.size(); |
| 7197 | for (int i=0; i<N; i++) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 7198 | mChildWindows.get(i).finishExit(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7199 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7200 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7201 | if (!mExiting) { |
| 7202 | return; |
| 7203 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7204 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7205 | if (isWindowAnimating()) { |
| 7206 | return; |
| 7207 | } |
| 7208 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7209 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7210 | TAG, "Exit animation finished in " + this |
| 7211 | + ": remove=" + mRemoveOnExit); |
| 7212 | if (mSurface != null) { |
| 7213 | mDestroySurface.add(this); |
| 7214 | mDestroying = true; |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 7215 | if (SHOW_TRANSACTIONS) logSurface(this, "HIDE (finishExit)", null); |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 7216 | mSurfaceShown = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7217 | try { |
| 7218 | mSurface.hide(); |
| 7219 | } catch (RuntimeException e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7220 | Slog.w(TAG, "Error hiding surface in " + this, e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7221 | } |
| 7222 | mLastHidden = true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7223 | } |
| 7224 | mExiting = false; |
| 7225 | if (mRemoveOnExit) { |
| 7226 | mPendingRemove.add(this); |
| 7227 | mRemoveOnExit = false; |
| 7228 | } |
| 7229 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7230 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7231 | boolean isIdentityMatrix(float dsdx, float dtdx, float dsdy, float dtdy) { |
| 7232 | if (dsdx < .99999f || dsdx > 1.00001f) return false; |
| 7233 | if (dtdy < .99999f || dtdy > 1.00001f) return false; |
| 7234 | if (dtdx < -.000001f || dtdx > .000001f) return false; |
| 7235 | if (dsdy < -.000001f || dsdy > .000001f) return false; |
| 7236 | return true; |
| 7237 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7238 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7239 | void computeShownFrameLocked() { |
| 7240 | final boolean selfTransformation = mHasLocalTransformation; |
| 7241 | Transformation attachedTransformation = |
| 7242 | (mAttachedWindow != null && mAttachedWindow.mHasLocalTransformation) |
| 7243 | ? mAttachedWindow.mTransformation : null; |
| 7244 | Transformation appTransformation = |
| 7245 | (mAppToken != null && mAppToken.hasTransformation) |
| 7246 | ? mAppToken.transformation : null; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7247 | |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 7248 | // Wallpapers are animated based on the "real" window they |
| 7249 | // are currently targeting. |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 7250 | if (mAttrs.type == TYPE_WALLPAPER && mLowerWallpaperTarget == null |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 7251 | && mWallpaperTarget != null) { |
| Dianne Hackborn | 5baba16 | 2009-09-23 17:01:12 -0700 | [diff] [blame] | 7252 | if (mWallpaperTarget.mHasLocalTransformation && |
| 7253 | mWallpaperTarget.mAnimation != null && |
| 7254 | !mWallpaperTarget.mAnimation.getDetachWallpaper()) { |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 7255 | attachedTransformation = mWallpaperTarget.mTransformation; |
| Dianne Hackborn | 5baba16 | 2009-09-23 17:01:12 -0700 | [diff] [blame] | 7256 | if (DEBUG_WALLPAPER && attachedTransformation != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7257 | Slog.v(TAG, "WP target attached xform: " + attachedTransformation); |
| Dianne Hackborn | 5baba16 | 2009-09-23 17:01:12 -0700 | [diff] [blame] | 7258 | } |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 7259 | } |
| 7260 | if (mWallpaperTarget.mAppToken != null && |
| Dianne Hackborn | 5baba16 | 2009-09-23 17:01:12 -0700 | [diff] [blame] | 7261 | mWallpaperTarget.mAppToken.hasTransformation && |
| 7262 | mWallpaperTarget.mAppToken.animation != null && |
| 7263 | !mWallpaperTarget.mAppToken.animation.getDetachWallpaper()) { |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 7264 | appTransformation = mWallpaperTarget.mAppToken.transformation; |
| Dianne Hackborn | 5baba16 | 2009-09-23 17:01:12 -0700 | [diff] [blame] | 7265 | if (DEBUG_WALLPAPER && appTransformation != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7266 | Slog.v(TAG, "WP target app xform: " + appTransformation); |
| Dianne Hackborn | 5baba16 | 2009-09-23 17:01:12 -0700 | [diff] [blame] | 7267 | } |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 7268 | } |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 7269 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7270 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7271 | if (selfTransformation || attachedTransformation != null |
| 7272 | || appTransformation != null) { |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7273 | // cache often used attributes locally |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7274 | final Rect frame = mFrame; |
| 7275 | final float tmpFloats[] = mTmpFloats; |
| 7276 | final Matrix tmpMatrix = mTmpMatrix; |
| 7277 | |
| 7278 | // Compute the desired transformation. |
| Dianne Hackborn | 65c2387 | 2009-09-18 17:47:02 -0700 | [diff] [blame] | 7279 | tmpMatrix.setTranslate(0, 0); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7280 | if (selfTransformation) { |
| Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 7281 | tmpMatrix.postConcat(mTransformation.getMatrix()); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7282 | } |
| Dianne Hackborn | 65c2387 | 2009-09-18 17:47:02 -0700 | [diff] [blame] | 7283 | tmpMatrix.postTranslate(frame.left, frame.top); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7284 | if (attachedTransformation != null) { |
| Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 7285 | tmpMatrix.postConcat(attachedTransformation.getMatrix()); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7286 | } |
| 7287 | if (appTransformation != null) { |
| Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 7288 | tmpMatrix.postConcat(appTransformation.getMatrix()); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7289 | } |
| 7290 | |
| 7291 | // "convert" it into SurfaceFlinger's format |
| 7292 | // (a 2x2 matrix + an offset) |
| 7293 | // Here we must not transform the position of the surface |
| 7294 | // since it is already included in the transformation. |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7295 | //Slog.i(TAG, "Transform: " + matrix); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7296 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7297 | tmpMatrix.getValues(tmpFloats); |
| 7298 | mDsDx = tmpFloats[Matrix.MSCALE_X]; |
| 7299 | mDtDx = tmpFloats[Matrix.MSKEW_X]; |
| 7300 | mDsDy = tmpFloats[Matrix.MSKEW_Y]; |
| 7301 | mDtDy = tmpFloats[Matrix.MSCALE_Y]; |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 7302 | int x = (int)tmpFloats[Matrix.MTRANS_X] + mXOffset; |
| 7303 | int y = (int)tmpFloats[Matrix.MTRANS_Y] + mYOffset; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7304 | int w = frame.width(); |
| 7305 | int h = frame.height(); |
| 7306 | mShownFrame.set(x, y, x+w, y+h); |
| 7307 | |
| 7308 | // Now set the alpha... but because our current hardware |
| 7309 | // can't do alpha transformation on a non-opaque surface, |
| 7310 | // turn it off if we are running an animation that is also |
| 7311 | // transforming since it is more important to have that |
| 7312 | // animation be smooth. |
| 7313 | mShownAlpha = mAlpha; |
| 7314 | if (!mLimitedAlphaCompositing |
| 7315 | || (!PixelFormat.formatHasAlpha(mAttrs.format) |
| 7316 | || (isIdentityMatrix(mDsDx, mDtDx, mDsDy, mDtDy) |
| 7317 | && x == frame.left && y == frame.top))) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7318 | //Slog.i(TAG, "Applying alpha transform"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7319 | if (selfTransformation) { |
| 7320 | mShownAlpha *= mTransformation.getAlpha(); |
| 7321 | } |
| 7322 | if (attachedTransformation != null) { |
| 7323 | mShownAlpha *= attachedTransformation.getAlpha(); |
| 7324 | } |
| 7325 | if (appTransformation != null) { |
| 7326 | mShownAlpha *= appTransformation.getAlpha(); |
| 7327 | } |
| 7328 | } else { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7329 | //Slog.i(TAG, "Not applying alpha transform"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7330 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7331 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7332 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7333 | TAG, "Continuing animation in " + this + |
| 7334 | ": " + mShownFrame + |
| 7335 | ", alpha=" + mTransformation.getAlpha()); |
| 7336 | return; |
| 7337 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7338 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7339 | mShownFrame.set(mFrame); |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 7340 | if (mXOffset != 0 || mYOffset != 0) { |
| 7341 | mShownFrame.offset(mXOffset, mYOffset); |
| 7342 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7343 | mShownAlpha = mAlpha; |
| 7344 | mDsDx = 1; |
| 7345 | mDtDx = 0; |
| 7346 | mDsDy = 0; |
| 7347 | mDtDy = 1; |
| 7348 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7349 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7350 | /** |
| 7351 | * Is this window visible? It is not visible if there is no |
| 7352 | * surface, or we are in the process of running an exit animation |
| 7353 | * that will remove the surface, or its app token has been hidden. |
| 7354 | */ |
| 7355 | public boolean isVisibleLw() { |
| 7356 | final AppWindowToken atoken = mAppToken; |
| 7357 | return mSurface != null && mPolicyVisibility && !mAttachedHidden |
| 7358 | && (atoken == null || !atoken.hiddenRequested) |
| 7359 | && !mExiting && !mDestroying; |
| 7360 | } |
| 7361 | |
| 7362 | /** |
| Dianne Hackborn | 3d163f07 | 2009-10-07 21:26:57 -0700 | [diff] [blame] | 7363 | * Like {@link #isVisibleLw}, but also counts a window that is currently |
| 7364 | * "hidden" behind the keyguard as visible. This allows us to apply |
| 7365 | * things like window flags that impact the keyguard. |
| 7366 | * XXX I am starting to think we need to have ANOTHER visibility flag |
| 7367 | * for this "hidden behind keyguard" state rather than overloading |
| 7368 | * mPolicyVisibility. Ungh. |
| 7369 | */ |
| 7370 | public boolean isVisibleOrBehindKeyguardLw() { |
| 7371 | final AppWindowToken atoken = mAppToken; |
| 7372 | return mSurface != null && !mAttachedHidden |
| 7373 | && (atoken == null ? mPolicyVisibility : !atoken.hiddenRequested) |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 7374 | && !mDrawPending && !mCommitDrawPending |
| Dianne Hackborn | 3d163f07 | 2009-10-07 21:26:57 -0700 | [diff] [blame] | 7375 | && !mExiting && !mDestroying; |
| 7376 | } |
| 7377 | |
| 7378 | /** |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7379 | * Is this window visible, ignoring its app token? It is not visible |
| 7380 | * if there is no surface, or we are in the process of running an exit animation |
| 7381 | * that will remove the surface. |
| 7382 | */ |
| 7383 | public boolean isWinVisibleLw() { |
| 7384 | final AppWindowToken atoken = mAppToken; |
| 7385 | return mSurface != null && mPolicyVisibility && !mAttachedHidden |
| 7386 | && (atoken == null || !atoken.hiddenRequested || atoken.animating) |
| 7387 | && !mExiting && !mDestroying; |
| 7388 | } |
| 7389 | |
| 7390 | /** |
| 7391 | * The same as isVisible(), but follows the current hidden state of |
| 7392 | * the associated app token, not the pending requested hidden state. |
| 7393 | */ |
| 7394 | boolean isVisibleNow() { |
| 7395 | return mSurface != null && mPolicyVisibility && !mAttachedHidden |
| The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 7396 | && !mRootToken.hidden && !mExiting && !mDestroying; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7397 | } |
| 7398 | |
| 7399 | /** |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 7400 | * Can this window possibly be a drag/drop target? The test here is |
| 7401 | * a combination of the above "visible now" with the check that the |
| 7402 | * Input Manager uses when discarding windows from input consideration. |
| 7403 | */ |
| 7404 | boolean isPotentialDragTarget() { |
| 7405 | return isVisibleNow() && (mInputChannel != null) && !mRemoved; |
| 7406 | } |
| 7407 | |
| 7408 | /** |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7409 | * Same as isVisible(), but we also count it as visible between the |
| 7410 | * call to IWindowSession.add() and the first relayout(). |
| 7411 | */ |
| 7412 | boolean isVisibleOrAdding() { |
| 7413 | final AppWindowToken atoken = mAppToken; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 7414 | return ((mSurface != null && !mReportDestroySurface) |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7415 | || (!mRelayoutCalled && mViewVisibility == View.VISIBLE)) |
| 7416 | && mPolicyVisibility && !mAttachedHidden |
| 7417 | && (atoken == null || !atoken.hiddenRequested) |
| 7418 | && !mExiting && !mDestroying; |
| 7419 | } |
| 7420 | |
| 7421 | /** |
| 7422 | * Is this window currently on-screen? It is on-screen either if it |
| 7423 | * is visible or it is currently running an animation before no longer |
| 7424 | * being visible. |
| 7425 | */ |
| 7426 | boolean isOnScreen() { |
| 7427 | final AppWindowToken atoken = mAppToken; |
| 7428 | if (atoken != null) { |
| 7429 | return mSurface != null && mPolicyVisibility && !mDestroying |
| 7430 | && ((!mAttachedHidden && !atoken.hiddenRequested) |
| Dianne Hackborn | 0cd4887 | 2009-08-13 18:51:59 -0700 | [diff] [blame] | 7431 | || mAnimation != null || atoken.animation != null); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7432 | } else { |
| 7433 | return mSurface != null && mPolicyVisibility && !mDestroying |
| Dianne Hackborn | 0cd4887 | 2009-08-13 18:51:59 -0700 | [diff] [blame] | 7434 | && (!mAttachedHidden || mAnimation != null); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7435 | } |
| 7436 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7437 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7438 | /** |
| 7439 | * Like isOnScreen(), but we don't return true if the window is part |
| 7440 | * of a transition that has not yet been started. |
| 7441 | */ |
| 7442 | boolean isReadyForDisplay() { |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 7443 | if (mRootToken.waitingToShow && |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 7444 | mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 7445 | return false; |
| 7446 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7447 | final AppWindowToken atoken = mAppToken; |
| Dianne Hackborn | 0cd4887 | 2009-08-13 18:51:59 -0700 | [diff] [blame] | 7448 | final boolean animating = atoken != null |
| 7449 | ? (atoken.animation != null) : false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7450 | return mSurface != null && mPolicyVisibility && !mDestroying |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 7451 | && ((!mAttachedHidden && mViewVisibility == View.VISIBLE |
| 7452 | && !mRootToken.hidden) |
| Dianne Hackborn | 0cd4887 | 2009-08-13 18:51:59 -0700 | [diff] [blame] | 7453 | || mAnimation != null || animating); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7454 | } |
| 7455 | |
| 7456 | /** Is the window or its container currently animating? */ |
| 7457 | boolean isAnimating() { |
| 7458 | final WindowState attached = mAttachedWindow; |
| 7459 | final AppWindowToken atoken = mAppToken; |
| 7460 | return mAnimation != null |
| 7461 | || (attached != null && attached.mAnimation != null) |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7462 | || (atoken != null && |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7463 | (atoken.animation != null |
| 7464 | || atoken.inPendingTransaction)); |
| 7465 | } |
| 7466 | |
| 7467 | /** Is this window currently animating? */ |
| 7468 | boolean isWindowAnimating() { |
| 7469 | return mAnimation != null; |
| 7470 | } |
| 7471 | |
| 7472 | /** |
| 7473 | * Like isOnScreen, but returns false if the surface hasn't yet |
| 7474 | * been drawn. |
| 7475 | */ |
| 7476 | public boolean isDisplayedLw() { |
| 7477 | final AppWindowToken atoken = mAppToken; |
| 7478 | return mSurface != null && mPolicyVisibility && !mDestroying |
| 7479 | && !mDrawPending && !mCommitDrawPending |
| 7480 | && ((!mAttachedHidden && |
| 7481 | (atoken == null || !atoken.hiddenRequested)) |
| 7482 | || mAnimating); |
| 7483 | } |
| 7484 | |
| Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 7485 | /** |
| 7486 | * Returns true if the window has a surface that it has drawn a |
| 7487 | * complete UI in to. |
| 7488 | */ |
| 7489 | public boolean isDrawnLw() { |
| 7490 | final AppWindowToken atoken = mAppToken; |
| 7491 | return mSurface != null && !mDestroying |
| 7492 | && !mDrawPending && !mCommitDrawPending; |
| 7493 | } |
| 7494 | |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 7495 | /** |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 7496 | * Return true if the window is opaque and fully drawn. This indicates |
| 7497 | * it may obscure windows behind it. |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 7498 | */ |
| 7499 | boolean isOpaqueDrawn() { |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 7500 | return (mAttrs.format == PixelFormat.OPAQUE |
| 7501 | || mAttrs.type == TYPE_WALLPAPER) |
| 7502 | && mSurface != null && mAnimation == null |
| 7503 | && (mAppToken == null || mAppToken.animation == null) |
| 7504 | && !mDrawPending && !mCommitDrawPending; |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 7505 | } |
| 7506 | |
| 7507 | boolean needsBackgroundFiller(int screenWidth, int screenHeight) { |
| 7508 | return |
| 7509 | // only if the application is requesting compatible window |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 7510 | (mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0 && |
| 7511 | // only if it's visible |
| 7512 | mHasDrawn && mViewVisibility == View.VISIBLE && |
| Mitsuru Oshima | d2967e2 | 2009-07-20 14:01:43 -0700 | [diff] [blame] | 7513 | // and only if the application fills the compatible screen |
| 7514 | mFrame.left <= mCompatibleScreenFrame.left && |
| 7515 | mFrame.top <= mCompatibleScreenFrame.top && |
| 7516 | mFrame.right >= mCompatibleScreenFrame.right && |
| 7517 | mFrame.bottom >= mCompatibleScreenFrame.bottom && |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 7518 | // and starting window do not need background filler |
| Mitsuru Oshima | d2967e2 | 2009-07-20 14:01:43 -0700 | [diff] [blame] | 7519 | mAttrs.type != mAttrs.TYPE_APPLICATION_STARTING; |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 7520 | } |
| 7521 | |
| 7522 | boolean isFullscreen(int screenWidth, int screenHeight) { |
| 7523 | return mFrame.left <= 0 && mFrame.top <= 0 && |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 7524 | mFrame.right >= screenWidth && mFrame.bottom >= screenHeight; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7525 | } |
| 7526 | |
| 7527 | void removeLocked() { |
| Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 7528 | disposeInputChannel(); |
| 7529 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7530 | if (mAttachedWindow != null) { |
| 7531 | mAttachedWindow.mChildWindows.remove(this); |
| 7532 | } |
| 7533 | destroySurfaceLocked(); |
| 7534 | mSession.windowRemovedLocked(); |
| 7535 | try { |
| 7536 | mClient.asBinder().unlinkToDeath(mDeathRecipient, 0); |
| 7537 | } catch (RuntimeException e) { |
| 7538 | // Ignore if it has already been removed (usually because |
| 7539 | // we are doing this as part of processing a death note.) |
| 7540 | } |
| Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 7541 | } |
| 7542 | |
| 7543 | void disposeInputChannel() { |
| Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 7544 | if (mInputChannel != null) { |
| 7545 | mInputManager.unregisterInputChannel(mInputChannel); |
| 7546 | |
| 7547 | mInputChannel.dispose(); |
| 7548 | mInputChannel = null; |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 7549 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7550 | } |
| 7551 | |
| 7552 | private class DeathRecipient implements IBinder.DeathRecipient { |
| 7553 | public void binderDied() { |
| 7554 | try { |
| 7555 | synchronized(mWindowMap) { |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 7556 | WindowState win = windowForClientLocked(mSession, mClient, false); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7557 | Slog.i(TAG, "WIN DEATH: " + win); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7558 | if (win != null) { |
| 7559 | removeWindowLocked(mSession, win); |
| 7560 | } |
| 7561 | } |
| 7562 | } catch (IllegalArgumentException ex) { |
| 7563 | // This will happen if the window has already been |
| 7564 | // removed. |
| 7565 | } |
| 7566 | } |
| 7567 | } |
| 7568 | |
| 7569 | /** Returns true if this window desires key events. */ |
| 7570 | public final boolean canReceiveKeys() { |
| 7571 | return isVisibleOrAdding() |
| 7572 | && (mViewVisibility == View.VISIBLE) |
| 7573 | && ((mAttrs.flags & WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) == 0); |
| 7574 | } |
| 7575 | |
| 7576 | public boolean hasDrawnLw() { |
| 7577 | return mHasDrawn; |
| 7578 | } |
| 7579 | |
| 7580 | public boolean showLw(boolean doAnimation) { |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 7581 | return showLw(doAnimation, true); |
| 7582 | } |
| 7583 | |
| 7584 | boolean showLw(boolean doAnimation, boolean requestAnim) { |
| 7585 | if (mPolicyVisibility && mPolicyVisibilityAfterAnim) { |
| 7586 | return false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7587 | } |
| Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 7588 | if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility true: " + this); |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 7589 | if (doAnimation) { |
| 7590 | if (DEBUG_VISIBILITY) Slog.v(TAG, "doAnimation: mPolicyVisibility=" |
| 7591 | + mPolicyVisibility + " mAnimation=" + mAnimation); |
| 7592 | if (mDisplayFrozen || !mPolicy.isScreenOn()) { |
| 7593 | doAnimation = false; |
| 7594 | } else if (mPolicyVisibility && mAnimation == null) { |
| 7595 | // Check for the case where we are currently visible and |
| 7596 | // not animating; we do not want to do animation at such a |
| 7597 | // point to become visible when we already are. |
| 7598 | doAnimation = false; |
| 7599 | } |
| 7600 | } |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 7601 | mPolicyVisibility = true; |
| 7602 | mPolicyVisibilityAfterAnim = true; |
| 7603 | if (doAnimation) { |
| 7604 | applyAnimationLocked(this, WindowManagerPolicy.TRANSIT_ENTER, true); |
| 7605 | } |
| 7606 | if (requestAnim) { |
| 7607 | requestAnimationLocked(0); |
| 7608 | } |
| 7609 | return true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7610 | } |
| 7611 | |
| 7612 | public boolean hideLw(boolean doAnimation) { |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 7613 | return hideLw(doAnimation, true); |
| 7614 | } |
| 7615 | |
| 7616 | boolean hideLw(boolean doAnimation, boolean requestAnim) { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 7617 | if (doAnimation) { |
| 7618 | if (mDisplayFrozen || !mPolicy.isScreenOn()) { |
| 7619 | doAnimation = false; |
| 7620 | } |
| 7621 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7622 | boolean current = doAnimation ? mPolicyVisibilityAfterAnim |
| 7623 | : mPolicyVisibility; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 7624 | if (!current) { |
| 7625 | return false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7626 | } |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 7627 | if (doAnimation) { |
| 7628 | applyAnimationLocked(this, WindowManagerPolicy.TRANSIT_EXIT, false); |
| 7629 | if (mAnimation == null) { |
| 7630 | doAnimation = false; |
| 7631 | } |
| 7632 | } |
| 7633 | if (doAnimation) { |
| 7634 | mPolicyVisibilityAfterAnim = false; |
| 7635 | } else { |
| Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 7636 | if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility false: " + this); |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 7637 | mPolicyVisibilityAfterAnim = false; |
| 7638 | mPolicyVisibility = false; |
| Dianne Hackborn | f3bea9c | 2009-12-09 18:26:21 -0800 | [diff] [blame] | 7639 | // Window is no longer visible -- make sure if we were waiting |
| 7640 | // for it to be displayed before enabling the display, that |
| 7641 | // we allow the display to be enabled now. |
| 7642 | enableScreenIfNeededLocked(); |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 7643 | if (mCurrentFocus == this) { |
| 7644 | mFocusMayChange = true; |
| 7645 | } |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 7646 | } |
| 7647 | if (requestAnim) { |
| 7648 | requestAnimationLocked(0); |
| 7649 | } |
| 7650 | return true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7651 | } |
| 7652 | |
| 7653 | void dump(PrintWriter pw, String prefix) { |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7654 | pw.print(prefix); pw.print("mSession="); pw.print(mSession); |
| 7655 | pw.print(" mClient="); pw.println(mClient.asBinder()); |
| 7656 | pw.print(prefix); pw.print("mAttrs="); pw.println(mAttrs); |
| 7657 | if (mAttachedWindow != null || mLayoutAttached) { |
| 7658 | pw.print(prefix); pw.print("mAttachedWindow="); pw.print(mAttachedWindow); |
| 7659 | pw.print(" mLayoutAttached="); pw.println(mLayoutAttached); |
| 7660 | } |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 7661 | if (mIsImWindow || mIsWallpaper || mIsFloatingLayer) { |
| 7662 | pw.print(prefix); pw.print("mIsImWindow="); pw.print(mIsImWindow); |
| 7663 | pw.print(" mIsWallpaper="); pw.print(mIsWallpaper); |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 7664 | pw.print(" mIsFloatingLayer="); pw.print(mIsFloatingLayer); |
| 7665 | pw.print(" mWallpaperVisible="); pw.println(mWallpaperVisible); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7666 | } |
| 7667 | pw.print(prefix); pw.print("mBaseLayer="); pw.print(mBaseLayer); |
| 7668 | pw.print(" mSubLayer="); pw.print(mSubLayer); |
| 7669 | pw.print(" mAnimLayer="); pw.print(mLayer); pw.print("+"); |
| 7670 | pw.print((mTargetAppToken != null ? mTargetAppToken.animLayerAdjustment |
| 7671 | : (mAppToken != null ? mAppToken.animLayerAdjustment : 0))); |
| 7672 | pw.print("="); pw.print(mAnimLayer); |
| 7673 | pw.print(" mLastLayer="); pw.println(mLastLayer); |
| 7674 | if (mSurface != null) { |
| 7675 | pw.print(prefix); pw.print("mSurface="); pw.println(mSurface); |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 7676 | pw.print(prefix); pw.print("Surface: shown="); pw.print(mSurfaceShown); |
| 7677 | pw.print(" layer="); pw.print(mSurfaceLayer); |
| 7678 | pw.print(" alpha="); pw.print(mSurfaceAlpha); |
| 7679 | pw.print(" rect=("); pw.print(mSurfaceX); |
| 7680 | pw.print(","); pw.print(mSurfaceY); |
| 7681 | pw.print(") "); pw.print(mSurfaceW); |
| 7682 | pw.print(" x "); pw.println(mSurfaceH); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7683 | } |
| 7684 | pw.print(prefix); pw.print("mToken="); pw.println(mToken); |
| 7685 | pw.print(prefix); pw.print("mRootToken="); pw.println(mRootToken); |
| 7686 | if (mAppToken != null) { |
| 7687 | pw.print(prefix); pw.print("mAppToken="); pw.println(mAppToken); |
| 7688 | } |
| 7689 | if (mTargetAppToken != null) { |
| 7690 | pw.print(prefix); pw.print("mTargetAppToken="); pw.println(mTargetAppToken); |
| 7691 | } |
| 7692 | pw.print(prefix); pw.print("mViewVisibility=0x"); |
| 7693 | pw.print(Integer.toHexString(mViewVisibility)); |
| 7694 | pw.print(" mLastHidden="); pw.print(mLastHidden); |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 7695 | pw.print(" mHaveFrame="); pw.print(mHaveFrame); |
| 7696 | pw.print(" mObscured="); pw.println(mObscured); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7697 | if (!mPolicyVisibility || !mPolicyVisibilityAfterAnim || mAttachedHidden) { |
| 7698 | pw.print(prefix); pw.print("mPolicyVisibility="); |
| 7699 | pw.print(mPolicyVisibility); |
| 7700 | pw.print(" mPolicyVisibilityAfterAnim="); |
| 7701 | pw.print(mPolicyVisibilityAfterAnim); |
| 7702 | pw.print(" mAttachedHidden="); pw.println(mAttachedHidden); |
| 7703 | } |
| Dianne Hackborn | 9b52a21 | 2009-12-11 14:51:35 -0800 | [diff] [blame] | 7704 | if (!mRelayoutCalled) { |
| 7705 | pw.print(prefix); pw.print("mRelayoutCalled="); pw.println(mRelayoutCalled); |
| 7706 | } |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7707 | pw.print(prefix); pw.print("Requested w="); pw.print(mRequestedWidth); |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 7708 | pw.print(" h="); pw.print(mRequestedHeight); |
| 7709 | pw.print(" mLayoutSeq="); pw.println(mLayoutSeq); |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 7710 | if (mXOffset != 0 || mYOffset != 0) { |
| 7711 | pw.print(prefix); pw.print("Offsets x="); pw.print(mXOffset); |
| 7712 | pw.print(" y="); pw.println(mYOffset); |
| 7713 | } |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7714 | pw.print(prefix); pw.print("mGivenContentInsets="); |
| 7715 | mGivenContentInsets.printShortString(pw); |
| 7716 | pw.print(" mGivenVisibleInsets="); |
| 7717 | mGivenVisibleInsets.printShortString(pw); |
| 7718 | pw.println(); |
| 7719 | if (mTouchableInsets != 0 || mGivenInsetsPending) { |
| 7720 | pw.print(prefix); pw.print("mTouchableInsets="); pw.print(mTouchableInsets); |
| 7721 | pw.print(" mGivenInsetsPending="); pw.println(mGivenInsetsPending); |
| 7722 | } |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 7723 | pw.print(prefix); pw.print("mConfiguration="); pw.println(mConfiguration); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7724 | pw.print(prefix); pw.print("mShownFrame="); |
| 7725 | mShownFrame.printShortString(pw); |
| 7726 | pw.print(" last="); mLastShownFrame.printShortString(pw); |
| 7727 | pw.println(); |
| 7728 | pw.print(prefix); pw.print("mFrame="); mFrame.printShortString(pw); |
| 7729 | pw.print(" last="); mLastFrame.printShortString(pw); |
| 7730 | pw.println(); |
| 7731 | pw.print(prefix); pw.print("mContainingFrame="); |
| 7732 | mContainingFrame.printShortString(pw); |
| 7733 | pw.print(" mDisplayFrame="); |
| 7734 | mDisplayFrame.printShortString(pw); |
| 7735 | pw.println(); |
| 7736 | pw.print(prefix); pw.print("mContentFrame="); mContentFrame.printShortString(pw); |
| 7737 | pw.print(" mVisibleFrame="); mVisibleFrame.printShortString(pw); |
| 7738 | pw.println(); |
| 7739 | pw.print(prefix); pw.print("mContentInsets="); mContentInsets.printShortString(pw); |
| 7740 | pw.print(" last="); mLastContentInsets.printShortString(pw); |
| 7741 | pw.print(" mVisibleInsets="); mVisibleInsets.printShortString(pw); |
| 7742 | pw.print(" last="); mLastVisibleInsets.printShortString(pw); |
| 7743 | pw.println(); |
| 7744 | if (mShownAlpha != 1 || mAlpha != 1 || mLastAlpha != 1) { |
| 7745 | pw.print(prefix); pw.print("mShownAlpha="); pw.print(mShownAlpha); |
| 7746 | pw.print(" mAlpha="); pw.print(mAlpha); |
| 7747 | pw.print(" mLastAlpha="); pw.println(mLastAlpha); |
| 7748 | } |
| 7749 | if (mAnimating || mLocalAnimating || mAnimationIsEntrance |
| 7750 | || mAnimation != null) { |
| 7751 | pw.print(prefix); pw.print("mAnimating="); pw.print(mAnimating); |
| 7752 | pw.print(" mLocalAnimating="); pw.print(mLocalAnimating); |
| 7753 | pw.print(" mAnimationIsEntrance="); pw.print(mAnimationIsEntrance); |
| 7754 | pw.print(" mAnimation="); pw.println(mAnimation); |
| 7755 | } |
| 7756 | if (mHasTransformation || mHasLocalTransformation) { |
| 7757 | pw.print(prefix); pw.print("XForm: has="); |
| 7758 | pw.print(mHasTransformation); |
| 7759 | pw.print(" hasLocal="); pw.print(mHasLocalTransformation); |
| 7760 | pw.print(" "); mTransformation.printShortString(pw); |
| 7761 | pw.println(); |
| 7762 | } |
| 7763 | pw.print(prefix); pw.print("mDrawPending="); pw.print(mDrawPending); |
| 7764 | pw.print(" mCommitDrawPending="); pw.print(mCommitDrawPending); |
| 7765 | pw.print(" mReadyToShow="); pw.print(mReadyToShow); |
| 7766 | pw.print(" mHasDrawn="); pw.println(mHasDrawn); |
| 7767 | if (mExiting || mRemoveOnExit || mDestroying || mRemoved) { |
| 7768 | pw.print(prefix); pw.print("mExiting="); pw.print(mExiting); |
| 7769 | pw.print(" mRemoveOnExit="); pw.print(mRemoveOnExit); |
| 7770 | pw.print(" mDestroying="); pw.print(mDestroying); |
| 7771 | pw.print(" mRemoved="); pw.println(mRemoved); |
| 7772 | } |
| Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 7773 | if (mOrientationChanging || mAppFreezing || mTurnOnScreen) { |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7774 | pw.print(prefix); pw.print("mOrientationChanging="); |
| 7775 | pw.print(mOrientationChanging); |
| Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 7776 | pw.print(" mAppFreezing="); pw.print(mAppFreezing); |
| 7777 | pw.print(" mTurnOnScreen="); pw.println(mTurnOnScreen); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7778 | } |
| Mitsuru Oshima | 589cebe | 2009-07-22 20:38:58 -0700 | [diff] [blame] | 7779 | if (mHScale != 1 || mVScale != 1) { |
| 7780 | pw.print(prefix); pw.print("mHScale="); pw.print(mHScale); |
| 7781 | pw.print(" mVScale="); pw.println(mVScale); |
| 7782 | } |
| Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 7783 | if (mWallpaperX != -1 || mWallpaperY != -1) { |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 7784 | pw.print(prefix); pw.print("mWallpaperX="); pw.print(mWallpaperX); |
| 7785 | pw.print(" mWallpaperY="); pw.println(mWallpaperY); |
| 7786 | } |
| Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 7787 | if (mWallpaperXStep != -1 || mWallpaperYStep != -1) { |
| 7788 | pw.print(prefix); pw.print("mWallpaperXStep="); pw.print(mWallpaperXStep); |
| 7789 | pw.print(" mWallpaperYStep="); pw.println(mWallpaperYStep); |
| 7790 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7791 | } |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 7792 | |
| 7793 | String makeInputChannelName() { |
| 7794 | return Integer.toHexString(System.identityHashCode(this)) |
| 7795 | + " " + mAttrs.getTitle(); |
| 7796 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7797 | |
| 7798 | @Override |
| 7799 | public String toString() { |
| 7800 | return "Window{" |
| 7801 | + Integer.toHexString(System.identityHashCode(this)) |
| 7802 | + " " + mAttrs.getTitle() + " paused=" + mToken.paused + "}"; |
| 7803 | } |
| 7804 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7805 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7806 | // ------------------------------------------------------------- |
| 7807 | // Window Token State |
| 7808 | // ------------------------------------------------------------- |
| 7809 | |
| 7810 | class WindowToken { |
| 7811 | // The actual token. |
| 7812 | final IBinder token; |
| 7813 | |
| 7814 | // The type of window this token is for, as per WindowManager.LayoutParams. |
| 7815 | final int windowType; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7816 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7817 | // Set if this token was explicitly added by a client, so should |
| 7818 | // not be removed when all windows are removed. |
| 7819 | final boolean explicit; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7820 | |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7821 | // For printing. |
| 7822 | String stringName; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7823 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7824 | // If this is an AppWindowToken, this is non-null. |
| 7825 | AppWindowToken appWindowToken; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7826 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7827 | // All of the windows associated with this token. |
| 7828 | final ArrayList<WindowState> windows = new ArrayList<WindowState>(); |
| 7829 | |
| 7830 | // Is key dispatching paused for this token? |
| 7831 | boolean paused = false; |
| 7832 | |
| 7833 | // Should this token's windows be hidden? |
| 7834 | boolean hidden; |
| 7835 | |
| 7836 | // Temporary for finding which tokens no longer have visible windows. |
| 7837 | boolean hasVisible; |
| 7838 | |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 7839 | // Set to true when this token is in a pending transaction where it |
| 7840 | // will be shown. |
| 7841 | boolean waitingToShow; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7842 | |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 7843 | // Set to true when this token is in a pending transaction where it |
| 7844 | // will be hidden. |
| 7845 | boolean waitingToHide; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7846 | |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 7847 | // Set to true when this token is in a pending transaction where its |
| 7848 | // windows will be put to the bottom of the list. |
| 7849 | boolean sendingToBottom; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7850 | |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 7851 | // Set to true when this token is in a pending transaction where its |
| 7852 | // windows will be put to the top of the list. |
| 7853 | boolean sendingToTop; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7854 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7855 | WindowToken(IBinder _token, int type, boolean _explicit) { |
| 7856 | token = _token; |
| 7857 | windowType = type; |
| 7858 | explicit = _explicit; |
| 7859 | } |
| 7860 | |
| 7861 | void dump(PrintWriter pw, String prefix) { |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7862 | pw.print(prefix); pw.print("token="); pw.println(token); |
| 7863 | pw.print(prefix); pw.print("windows="); pw.println(windows); |
| 7864 | pw.print(prefix); pw.print("windowType="); pw.print(windowType); |
| 7865 | pw.print(" hidden="); pw.print(hidden); |
| 7866 | pw.print(" hasVisible="); pw.println(hasVisible); |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 7867 | if (waitingToShow || waitingToHide || sendingToBottom || sendingToTop) { |
| 7868 | pw.print(prefix); pw.print("waitingToShow="); pw.print(waitingToShow); |
| 7869 | pw.print(" waitingToHide="); pw.print(waitingToHide); |
| 7870 | pw.print(" sendingToBottom="); pw.print(sendingToBottom); |
| 7871 | pw.print(" sendingToTop="); pw.println(sendingToTop); |
| 7872 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7873 | } |
| 7874 | |
| 7875 | @Override |
| 7876 | public String toString() { |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7877 | if (stringName == null) { |
| 7878 | StringBuilder sb = new StringBuilder(); |
| 7879 | sb.append("WindowToken{"); |
| 7880 | sb.append(Integer.toHexString(System.identityHashCode(this))); |
| 7881 | sb.append(" token="); sb.append(token); sb.append('}'); |
| 7882 | stringName = sb.toString(); |
| 7883 | } |
| 7884 | return stringName; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7885 | } |
| 7886 | }; |
| 7887 | |
| 7888 | class AppWindowToken extends WindowToken { |
| 7889 | // Non-null only for application tokens. |
| 7890 | final IApplicationToken appToken; |
| 7891 | |
| 7892 | // All of the windows and child windows that are included in this |
| 7893 | // application token. Note this list is NOT sorted! |
| 7894 | final ArrayList<WindowState> allAppWindows = new ArrayList<WindowState>(); |
| 7895 | |
| 7896 | int groupId = -1; |
| 7897 | boolean appFullscreen; |
| 7898 | int requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 7899 | |
| 7900 | // The input dispatching timeout for this application token in nanoseconds. |
| 7901 | long inputDispatchingTimeoutNanos; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7902 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7903 | // These are used for determining when all windows associated with |
| 7904 | // an activity have been drawn, so they can be made visible together |
| 7905 | // at the same time. |
| 7906 | int lastTransactionSequence = mTransactionSequence-1; |
| 7907 | int numInterestingWindows; |
| 7908 | int numDrawnWindows; |
| 7909 | boolean inPendingTransaction; |
| 7910 | boolean allDrawn; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7911 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7912 | // Is this token going to be hidden in a little while? If so, it |
| 7913 | // won't be taken into account for setting the screen orientation. |
| 7914 | boolean willBeHidden; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7915 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7916 | // Is this window's surface needed? This is almost like hidden, except |
| 7917 | // it will sometimes be true a little earlier: when the token has |
| 7918 | // been shown, but is still waiting for its app transition to execute |
| 7919 | // before making its windows shown. |
| 7920 | boolean hiddenRequested; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7921 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7922 | // Have we told the window clients to hide themselves? |
| 7923 | boolean clientHidden; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7924 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7925 | // Last visibility state we reported to the app token. |
| 7926 | boolean reportedVisible; |
| 7927 | |
| 7928 | // Set to true when the token has been removed from the window mgr. |
| 7929 | boolean removed; |
| 7930 | |
| 7931 | // Have we been asked to have this token keep the screen frozen? |
| 7932 | boolean freezingScreen; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7933 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7934 | boolean animating; |
| 7935 | Animation animation; |
| 7936 | boolean hasTransformation; |
| 7937 | final Transformation transformation = new Transformation(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7938 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7939 | // Offset to the window of all layers in the token, for use by |
| 7940 | // AppWindowToken animations. |
| 7941 | int animLayerAdjustment; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7942 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7943 | // Information about an application starting window if displayed. |
| 7944 | StartingData startingData; |
| 7945 | WindowState startingWindow; |
| 7946 | View startingView; |
| 7947 | boolean startingDisplayed; |
| 7948 | boolean startingMoved; |
| 7949 | boolean firstWindowDrawn; |
| 7950 | |
| 7951 | AppWindowToken(IApplicationToken _token) { |
| 7952 | super(_token.asBinder(), |
| 7953 | WindowManager.LayoutParams.TYPE_APPLICATION, true); |
| 7954 | appWindowToken = this; |
| 7955 | appToken = _token; |
| 7956 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7957 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7958 | public void setAnimation(Animation anim) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7959 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7960 | TAG, "Setting animation in " + this + ": " + anim); |
| 7961 | animation = anim; |
| 7962 | animating = false; |
| 7963 | anim.restrictDuration(MAX_ANIMATION_DURATION); |
| 7964 | anim.scaleCurrentDuration(mTransitionAnimationScale); |
| 7965 | int zorder = anim.getZAdjustment(); |
| 7966 | int adj = 0; |
| 7967 | if (zorder == Animation.ZORDER_TOP) { |
| 7968 | adj = TYPE_LAYER_OFFSET; |
| 7969 | } else if (zorder == Animation.ZORDER_BOTTOM) { |
| 7970 | adj = -TYPE_LAYER_OFFSET; |
| 7971 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7972 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7973 | if (animLayerAdjustment != adj) { |
| 7974 | animLayerAdjustment = adj; |
| 7975 | updateLayers(); |
| 7976 | } |
| 7977 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7978 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7979 | public void setDummyAnimation() { |
| 7980 | if (animation == null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7981 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7982 | TAG, "Setting dummy animation in " + this); |
| 7983 | animation = sDummyAnimation; |
| 7984 | } |
| 7985 | } |
| 7986 | |
| 7987 | public void clearAnimation() { |
| 7988 | if (animation != null) { |
| 7989 | animation = null; |
| 7990 | animating = true; |
| 7991 | } |
| 7992 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7993 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7994 | void updateLayers() { |
| 7995 | final int N = allAppWindows.size(); |
| 7996 | final int adj = animLayerAdjustment; |
| 7997 | for (int i=0; i<N; i++) { |
| 7998 | WindowState w = allAppWindows.get(i); |
| 7999 | w.mAnimLayer = w.mLayer + adj; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8000 | if (DEBUG_LAYERS) Slog.v(TAG, "Updating layer " + w + ": " |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8001 | + w.mAnimLayer); |
| 8002 | if (w == mInputMethodTarget) { |
| 8003 | setInputMethodAnimLayerAdjustment(adj); |
| 8004 | } |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 8005 | if (w == mWallpaperTarget && mLowerWallpaperTarget == null) { |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 8006 | setWallpaperAnimLayerAdjustmentLocked(adj); |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 8007 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8008 | } |
| 8009 | } |
| 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 | void sendAppVisibilityToClients() { |
| 8012 | final int N = allAppWindows.size(); |
| 8013 | for (int i=0; i<N; i++) { |
| 8014 | WindowState win = allAppWindows.get(i); |
| 8015 | if (win == startingWindow && clientHidden) { |
| 8016 | // Don't hide the starting window. |
| 8017 | continue; |
| 8018 | } |
| 8019 | try { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8020 | if (DEBUG_VISIBILITY) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8021 | "Setting visibility of " + win + ": " + (!clientHidden)); |
| 8022 | win.mClient.dispatchAppVisibility(!clientHidden); |
| 8023 | } catch (RemoteException e) { |
| 8024 | } |
| 8025 | } |
| 8026 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8027 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8028 | void showAllWindowsLocked() { |
| 8029 | final int NW = allAppWindows.size(); |
| 8030 | for (int i=0; i<NW; i++) { |
| 8031 | WindowState w = allAppWindows.get(i); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8032 | if (DEBUG_VISIBILITY) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8033 | "performing show on: " + w); |
| 8034 | w.performShowLocked(); |
| 8035 | } |
| 8036 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8037 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8038 | // This must be called while inside a transaction. |
| 8039 | boolean stepAnimationLocked(long currentTime, int dw, int dh) { |
| Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 8040 | if (!mDisplayFrozen && mPolicy.isScreenOn()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8041 | // We will run animations as long as the display isn't frozen. |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8042 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8043 | if (animation == sDummyAnimation) { |
| 8044 | // This guy is going to animate, but not yet. For now count |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 8045 | // it as not animating for purposes of scheduling transactions; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8046 | // when it is really time to animate, this will be set to |
| 8047 | // a real animation and the next call will execute normally. |
| 8048 | return false; |
| 8049 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8050 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8051 | if ((allDrawn || animating || startingDisplayed) && animation != null) { |
| 8052 | if (!animating) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8053 | if (DEBUG_ANIM) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8054 | TAG, "Starting animation in " + this + |
| 8055 | " @ " + currentTime + ": dw=" + dw + " dh=" + dh |
| 8056 | + " scale=" + mTransitionAnimationScale |
| 8057 | + " allDrawn=" + allDrawn + " animating=" + animating); |
| 8058 | animation.initialize(dw, dh, dw, dh); |
| 8059 | animation.setStartTime(currentTime); |
| 8060 | animating = true; |
| 8061 | } |
| 8062 | transformation.clear(); |
| 8063 | final boolean more = animation.getTransformation( |
| 8064 | currentTime, transformation); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8065 | if (DEBUG_ANIM) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8066 | TAG, "Stepped animation in " + this + |
| 8067 | ": more=" + more + ", xform=" + transformation); |
| 8068 | if (more) { |
| 8069 | // we're done! |
| 8070 | hasTransformation = true; |
| 8071 | return true; |
| 8072 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8073 | if (DEBUG_ANIM) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8074 | TAG, "Finished animation in " + this + |
| 8075 | " @ " + currentTime); |
| 8076 | animation = null; |
| 8077 | } |
| 8078 | } else if (animation != null) { |
| 8079 | // If the display is frozen, and there is a pending animation, |
| 8080 | // clear it and make sure we run the cleanup code. |
| 8081 | animating = true; |
| 8082 | animation = null; |
| 8083 | } |
| 8084 | |
| 8085 | hasTransformation = false; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8086 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8087 | if (!animating) { |
| 8088 | return false; |
| 8089 | } |
| 8090 | |
| 8091 | clearAnimation(); |
| 8092 | animating = false; |
| 8093 | if (mInputMethodTarget != null && mInputMethodTarget.mAppToken == this) { |
| 8094 | moveInputMethodWindowsIfNeededLocked(true); |
| 8095 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8096 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8097 | if (DEBUG_ANIM) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8098 | TAG, "Animation done in " + this |
| 8099 | + ": reportedVisible=" + reportedVisible); |
| 8100 | |
| 8101 | transformation.clear(); |
| 8102 | if (animLayerAdjustment != 0) { |
| 8103 | animLayerAdjustment = 0; |
| 8104 | updateLayers(); |
| 8105 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8106 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8107 | final int N = windows.size(); |
| 8108 | for (int i=0; i<N; i++) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 8109 | windows.get(i).finishExit(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8110 | } |
| 8111 | updateReportedVisibilityLocked(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8112 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8113 | return false; |
| 8114 | } |
| 8115 | |
| 8116 | void updateReportedVisibilityLocked() { |
| 8117 | if (appToken == null) { |
| 8118 | return; |
| 8119 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8120 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8121 | int numInteresting = 0; |
| 8122 | int numVisible = 0; |
| 8123 | boolean nowGone = true; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8124 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8125 | 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] | 8126 | final int N = allAppWindows.size(); |
| 8127 | for (int i=0; i<N; i++) { |
| 8128 | WindowState win = allAppWindows.get(i); |
| Dianne Hackborn | 6cf67fa | 2009-12-21 16:46:34 -0800 | [diff] [blame] | 8129 | if (win == startingWindow || win.mAppFreezing |
| The Android Open Source Project | 727cec0 | 2010-04-08 11:35:37 -0700 | [diff] [blame] | 8130 | || win.mViewVisibility != View.VISIBLE |
| 8131 | || win.mAttrs.type == TYPE_APPLICATION_STARTING) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8132 | continue; |
| 8133 | } |
| 8134 | if (DEBUG_VISIBILITY) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8135 | Slog.v(TAG, "Win " + win + ": isDrawn=" |
| Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 8136 | + win.isDrawnLw() |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8137 | + ", isAnimating=" + win.isAnimating()); |
| Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 8138 | if (!win.isDrawnLw()) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8139 | Slog.v(TAG, "Not displayed: s=" + win.mSurface |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8140 | + " pv=" + win.mPolicyVisibility |
| 8141 | + " dp=" + win.mDrawPending |
| 8142 | + " cdp=" + win.mCommitDrawPending |
| 8143 | + " ah=" + win.mAttachedHidden |
| 8144 | + " th=" |
| 8145 | + (win.mAppToken != null |
| 8146 | ? win.mAppToken.hiddenRequested : false) |
| 8147 | + " a=" + win.mAnimating); |
| 8148 | } |
| 8149 | } |
| 8150 | numInteresting++; |
| Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 8151 | if (win.isDrawnLw()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8152 | if (!win.isAnimating()) { |
| 8153 | numVisible++; |
| 8154 | } |
| 8155 | nowGone = false; |
| 8156 | } else if (win.isAnimating()) { |
| 8157 | nowGone = false; |
| 8158 | } |
| 8159 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8160 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8161 | boolean nowVisible = numInteresting > 0 && numVisible >= numInteresting; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8162 | if (DEBUG_VISIBILITY) Slog.v(TAG, "VIS " + this + ": interesting=" |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8163 | + numInteresting + " visible=" + numVisible); |
| 8164 | if (nowVisible != reportedVisible) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8165 | if (DEBUG_VISIBILITY) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8166 | TAG, "Visibility changed in " + this |
| 8167 | + ": vis=" + nowVisible); |
| 8168 | reportedVisible = nowVisible; |
| 8169 | Message m = mH.obtainMessage( |
| 8170 | H.REPORT_APPLICATION_TOKEN_WINDOWS, |
| 8171 | nowVisible ? 1 : 0, |
| 8172 | nowGone ? 1 : 0, |
| 8173 | this); |
| 8174 | mH.sendMessage(m); |
| 8175 | } |
| 8176 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8177 | |
| Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 8178 | WindowState findMainWindow() { |
| 8179 | int j = windows.size(); |
| 8180 | while (j > 0) { |
| 8181 | j--; |
| 8182 | WindowState win = windows.get(j); |
| 8183 | if (win.mAttrs.type == WindowManager.LayoutParams.TYPE_BASE_APPLICATION |
| 8184 | || win.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING) { |
| 8185 | return win; |
| 8186 | } |
| 8187 | } |
| 8188 | return null; |
| 8189 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8190 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8191 | void dump(PrintWriter pw, String prefix) { |
| 8192 | super.dump(pw, prefix); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8193 | if (appToken != null) { |
| 8194 | pw.print(prefix); pw.println("app=true"); |
| 8195 | } |
| 8196 | if (allAppWindows.size() > 0) { |
| 8197 | pw.print(prefix); pw.print("allAppWindows="); pw.println(allAppWindows); |
| 8198 | } |
| 8199 | pw.print(prefix); pw.print("groupId="); pw.print(groupId); |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8200 | pw.print(" appFullscreen="); pw.print(appFullscreen); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8201 | pw.print(" requestedOrientation="); pw.println(requestedOrientation); |
| 8202 | pw.print(prefix); pw.print("hiddenRequested="); pw.print(hiddenRequested); |
| 8203 | pw.print(" clientHidden="); pw.print(clientHidden); |
| 8204 | pw.print(" willBeHidden="); pw.print(willBeHidden); |
| 8205 | pw.print(" reportedVisible="); pw.println(reportedVisible); |
| 8206 | if (paused || freezingScreen) { |
| 8207 | pw.print(prefix); pw.print("paused="); pw.print(paused); |
| 8208 | pw.print(" freezingScreen="); pw.println(freezingScreen); |
| 8209 | } |
| 8210 | if (numInterestingWindows != 0 || numDrawnWindows != 0 |
| 8211 | || inPendingTransaction || allDrawn) { |
| 8212 | pw.print(prefix); pw.print("numInterestingWindows="); |
| 8213 | pw.print(numInterestingWindows); |
| 8214 | pw.print(" numDrawnWindows="); pw.print(numDrawnWindows); |
| 8215 | pw.print(" inPendingTransaction="); pw.print(inPendingTransaction); |
| 8216 | pw.print(" allDrawn="); pw.println(allDrawn); |
| 8217 | } |
| 8218 | if (animating || animation != null) { |
| 8219 | pw.print(prefix); pw.print("animating="); pw.print(animating); |
| 8220 | pw.print(" animation="); pw.println(animation); |
| 8221 | } |
| 8222 | if (animLayerAdjustment != 0) { |
| 8223 | pw.print(prefix); pw.print("animLayerAdjustment="); pw.println(animLayerAdjustment); |
| 8224 | } |
| 8225 | if (hasTransformation) { |
| 8226 | pw.print(prefix); pw.print("hasTransformation="); pw.print(hasTransformation); |
| 8227 | pw.print(" transformation="); transformation.printShortString(pw); |
| 8228 | pw.println(); |
| 8229 | } |
| 8230 | if (startingData != null || removed || firstWindowDrawn) { |
| 8231 | pw.print(prefix); pw.print("startingData="); pw.print(startingData); |
| 8232 | pw.print(" removed="); pw.print(removed); |
| 8233 | pw.print(" firstWindowDrawn="); pw.println(firstWindowDrawn); |
| 8234 | } |
| 8235 | if (startingWindow != null || startingView != null |
| 8236 | || startingDisplayed || startingMoved) { |
| 8237 | pw.print(prefix); pw.print("startingWindow="); pw.print(startingWindow); |
| 8238 | pw.print(" startingView="); pw.print(startingView); |
| 8239 | pw.print(" startingDisplayed="); pw.print(startingDisplayed); |
| 8240 | pw.print(" startingMoved"); pw.println(startingMoved); |
| 8241 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8242 | } |
| 8243 | |
| 8244 | @Override |
| 8245 | public String toString() { |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8246 | if (stringName == null) { |
| 8247 | StringBuilder sb = new StringBuilder(); |
| 8248 | sb.append("AppWindowToken{"); |
| 8249 | sb.append(Integer.toHexString(System.identityHashCode(this))); |
| 8250 | sb.append(" token="); sb.append(token); sb.append('}'); |
| 8251 | stringName = sb.toString(); |
| 8252 | } |
| 8253 | return stringName; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8254 | } |
| 8255 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8256 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8257 | // ------------------------------------------------------------- |
| 8258 | // DummyAnimation |
| 8259 | // ------------------------------------------------------------- |
| 8260 | |
| 8261 | // This is an animation that does nothing: it just immediately finishes |
| 8262 | // itself every time it is called. It is used as a stub animation in cases |
| 8263 | // where we want to synchronize multiple things that may be animating. |
| 8264 | static final class DummyAnimation extends Animation { |
| 8265 | public boolean getTransformation(long currentTime, Transformation outTransformation) { |
| 8266 | return false; |
| 8267 | } |
| 8268 | } |
| 8269 | static final Animation sDummyAnimation = new DummyAnimation(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8270 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8271 | // ------------------------------------------------------------- |
| 8272 | // Async Handler |
| 8273 | // ------------------------------------------------------------- |
| 8274 | |
| 8275 | static final class StartingData { |
| 8276 | final String pkg; |
| 8277 | final int theme; |
| 8278 | final CharSequence nonLocalizedLabel; |
| 8279 | final int labelRes; |
| 8280 | final int icon; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8281 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8282 | StartingData(String _pkg, int _theme, CharSequence _nonLocalizedLabel, |
| 8283 | int _labelRes, int _icon) { |
| 8284 | pkg = _pkg; |
| 8285 | theme = _theme; |
| 8286 | nonLocalizedLabel = _nonLocalizedLabel; |
| 8287 | labelRes = _labelRes; |
| 8288 | icon = _icon; |
| 8289 | } |
| 8290 | } |
| 8291 | |
| 8292 | private final class H extends Handler { |
| 8293 | public static final int REPORT_FOCUS_CHANGE = 2; |
| 8294 | public static final int REPORT_LOSING_FOCUS = 3; |
| 8295 | public static final int ANIMATE = 4; |
| 8296 | public static final int ADD_STARTING = 5; |
| 8297 | public static final int REMOVE_STARTING = 6; |
| 8298 | public static final int FINISHED_STARTING = 7; |
| 8299 | public static final int REPORT_APPLICATION_TOKEN_WINDOWS = 8; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8300 | public static final int WINDOW_FREEZE_TIMEOUT = 11; |
| 8301 | public static final int HOLD_SCREEN_CHANGED = 12; |
| 8302 | public static final int APP_TRANSITION_TIMEOUT = 13; |
| 8303 | public static final int PERSIST_ANIMATION_SCALE = 14; |
| 8304 | public static final int FORCE_GC = 15; |
| 8305 | public static final int ENABLE_SCREEN = 16; |
| 8306 | public static final int APP_FREEZE_TIMEOUT = 17; |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 8307 | public static final int SEND_NEW_CONFIGURATION = 18; |
| Konstantin Lopyrev | 6e0f65f | 2010-07-14 14:55:33 -0700 | [diff] [blame] | 8308 | public static final int REPORT_WINDOWS_CHANGE = 19; |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 8309 | public static final int DRAG_START_TIMEOUT = 20; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8310 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8311 | private Session mLastReportedHold; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8312 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8313 | public H() { |
| 8314 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8315 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8316 | @Override |
| 8317 | public void handleMessage(Message msg) { |
| 8318 | switch (msg.what) { |
| 8319 | case REPORT_FOCUS_CHANGE: { |
| 8320 | WindowState lastFocus; |
| 8321 | WindowState newFocus; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8322 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8323 | synchronized(mWindowMap) { |
| 8324 | lastFocus = mLastFocus; |
| 8325 | newFocus = mCurrentFocus; |
| 8326 | if (lastFocus == newFocus) { |
| 8327 | // Focus is not changing, so nothing to do. |
| 8328 | return; |
| 8329 | } |
| 8330 | mLastFocus = newFocus; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8331 | //Slog.i(TAG, "Focus moving from " + lastFocus |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8332 | // + " to " + newFocus); |
| 8333 | if (newFocus != null && lastFocus != null |
| 8334 | && !newFocus.isDisplayedLw()) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8335 | //Slog.i(TAG, "Delaying loss of focus..."); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8336 | mLosingFocus.add(lastFocus); |
| 8337 | lastFocus = null; |
| 8338 | } |
| 8339 | } |
| 8340 | |
| 8341 | if (lastFocus != newFocus) { |
| 8342 | //System.out.println("Changing focus from " + lastFocus |
| 8343 | // + " to " + newFocus); |
| 8344 | if (newFocus != null) { |
| 8345 | try { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8346 | //Slog.i(TAG, "Gaining focus: " + newFocus); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8347 | newFocus.mClient.windowFocusChanged(true, mInTouchMode); |
| 8348 | } catch (RemoteException e) { |
| 8349 | // Ignore if process has died. |
| 8350 | } |
| Konstantin Lopyrev | 5e7833a | 2010-08-09 17:01:11 -0700 | [diff] [blame] | 8351 | notifyFocusChanged(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8352 | } |
| 8353 | |
| 8354 | if (lastFocus != null) { |
| 8355 | try { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8356 | //Slog.i(TAG, "Losing focus: " + lastFocus); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8357 | lastFocus.mClient.windowFocusChanged(false, mInTouchMode); |
| 8358 | } catch (RemoteException e) { |
| 8359 | // Ignore if process has died. |
| 8360 | } |
| 8361 | } |
| 8362 | } |
| 8363 | } break; |
| 8364 | |
| 8365 | case REPORT_LOSING_FOCUS: { |
| 8366 | ArrayList<WindowState> losers; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8367 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8368 | synchronized(mWindowMap) { |
| 8369 | losers = mLosingFocus; |
| 8370 | mLosingFocus = new ArrayList<WindowState>(); |
| 8371 | } |
| 8372 | |
| 8373 | final int N = losers.size(); |
| 8374 | for (int i=0; i<N; i++) { |
| 8375 | try { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8376 | //Slog.i(TAG, "Losing delayed focus: " + losers.get(i)); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8377 | losers.get(i).mClient.windowFocusChanged(false, mInTouchMode); |
| 8378 | } catch (RemoteException e) { |
| 8379 | // Ignore if process has died. |
| 8380 | } |
| 8381 | } |
| 8382 | } break; |
| 8383 | |
| 8384 | case ANIMATE: { |
| 8385 | synchronized(mWindowMap) { |
| 8386 | mAnimationPending = false; |
| 8387 | performLayoutAndPlaceSurfacesLocked(); |
| 8388 | } |
| 8389 | } break; |
| 8390 | |
| 8391 | case ADD_STARTING: { |
| 8392 | final AppWindowToken wtoken = (AppWindowToken)msg.obj; |
| 8393 | final StartingData sd = wtoken.startingData; |
| 8394 | |
| 8395 | if (sd == null) { |
| 8396 | // Animation has been canceled... do nothing. |
| 8397 | return; |
| 8398 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8399 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8400 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Add starting " |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8401 | + wtoken + ": pkg=" + sd.pkg); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8402 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8403 | View view = null; |
| 8404 | try { |
| 8405 | view = mPolicy.addStartingWindow( |
| 8406 | wtoken.token, sd.pkg, |
| 8407 | sd.theme, sd.nonLocalizedLabel, sd.labelRes, |
| 8408 | sd.icon); |
| 8409 | } catch (Exception e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8410 | Slog.w(TAG, "Exception when adding starting window", e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8411 | } |
| 8412 | |
| 8413 | if (view != null) { |
| 8414 | boolean abort = false; |
| 8415 | |
| 8416 | synchronized(mWindowMap) { |
| 8417 | if (wtoken.removed || wtoken.startingData == null) { |
| 8418 | // If the window was successfully added, then |
| 8419 | // we need to remove it. |
| 8420 | if (wtoken.startingWindow != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8421 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8422 | "Aborted starting " + wtoken |
| 8423 | + ": removed=" + wtoken.removed |
| 8424 | + " startingData=" + wtoken.startingData); |
| 8425 | wtoken.startingWindow = null; |
| 8426 | wtoken.startingData = null; |
| 8427 | abort = true; |
| 8428 | } |
| 8429 | } else { |
| 8430 | wtoken.startingView = view; |
| 8431 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8432 | if (DEBUG_STARTING_WINDOW && !abort) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8433 | "Added starting " + wtoken |
| 8434 | + ": startingWindow=" |
| 8435 | + wtoken.startingWindow + " startingView=" |
| 8436 | + wtoken.startingView); |
| 8437 | } |
| 8438 | |
| 8439 | if (abort) { |
| 8440 | try { |
| 8441 | mPolicy.removeStartingWindow(wtoken.token, view); |
| 8442 | } catch (Exception e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8443 | Slog.w(TAG, "Exception when removing starting window", e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8444 | } |
| 8445 | } |
| 8446 | } |
| 8447 | } break; |
| 8448 | |
| 8449 | case REMOVE_STARTING: { |
| 8450 | final AppWindowToken wtoken = (AppWindowToken)msg.obj; |
| 8451 | IBinder token = null; |
| 8452 | View view = null; |
| 8453 | synchronized (mWindowMap) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8454 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Remove starting " |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8455 | + wtoken + ": startingWindow=" |
| 8456 | + wtoken.startingWindow + " startingView=" |
| 8457 | + wtoken.startingView); |
| 8458 | if (wtoken.startingWindow != null) { |
| 8459 | view = wtoken.startingView; |
| 8460 | token = wtoken.token; |
| 8461 | wtoken.startingData = null; |
| 8462 | wtoken.startingView = null; |
| 8463 | wtoken.startingWindow = null; |
| 8464 | } |
| 8465 | } |
| 8466 | if (view != null) { |
| 8467 | try { |
| 8468 | mPolicy.removeStartingWindow(token, view); |
| 8469 | } catch (Exception e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8470 | Slog.w(TAG, "Exception when removing starting window", e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8471 | } |
| 8472 | } |
| 8473 | } break; |
| 8474 | |
| 8475 | case FINISHED_STARTING: { |
| 8476 | IBinder token = null; |
| 8477 | View view = null; |
| 8478 | while (true) { |
| 8479 | synchronized (mWindowMap) { |
| 8480 | final int N = mFinishedStarting.size(); |
| 8481 | if (N <= 0) { |
| 8482 | break; |
| 8483 | } |
| 8484 | AppWindowToken wtoken = mFinishedStarting.remove(N-1); |
| 8485 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8486 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8487 | "Finished starting " + wtoken |
| 8488 | + ": startingWindow=" + wtoken.startingWindow |
| 8489 | + " startingView=" + wtoken.startingView); |
| 8490 | |
| 8491 | if (wtoken.startingWindow == null) { |
| 8492 | continue; |
| 8493 | } |
| 8494 | |
| 8495 | view = wtoken.startingView; |
| 8496 | token = wtoken.token; |
| 8497 | wtoken.startingData = null; |
| 8498 | wtoken.startingView = null; |
| 8499 | wtoken.startingWindow = null; |
| 8500 | } |
| 8501 | |
| 8502 | try { |
| 8503 | mPolicy.removeStartingWindow(token, view); |
| 8504 | } catch (Exception e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8505 | Slog.w(TAG, "Exception when removing starting window", e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8506 | } |
| 8507 | } |
| 8508 | } break; |
| 8509 | |
| 8510 | case REPORT_APPLICATION_TOKEN_WINDOWS: { |
| 8511 | final AppWindowToken wtoken = (AppWindowToken)msg.obj; |
| 8512 | |
| 8513 | boolean nowVisible = msg.arg1 != 0; |
| 8514 | boolean nowGone = msg.arg2 != 0; |
| 8515 | |
| 8516 | try { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8517 | if (DEBUG_VISIBILITY) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8518 | TAG, "Reporting visible in " + wtoken |
| 8519 | + " visible=" + nowVisible |
| 8520 | + " gone=" + nowGone); |
| 8521 | if (nowVisible) { |
| 8522 | wtoken.appToken.windowsVisible(); |
| 8523 | } else { |
| 8524 | wtoken.appToken.windowsGone(); |
| 8525 | } |
| 8526 | } catch (RemoteException ex) { |
| 8527 | } |
| 8528 | } break; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8529 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8530 | case WINDOW_FREEZE_TIMEOUT: { |
| 8531 | synchronized (mWindowMap) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8532 | Slog.w(TAG, "Window freeze timeout expired."); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8533 | int i = mWindows.size(); |
| 8534 | while (i > 0) { |
| 8535 | i--; |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 8536 | WindowState w = mWindows.get(i); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8537 | if (w.mOrientationChanging) { |
| 8538 | w.mOrientationChanging = false; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8539 | Slog.w(TAG, "Force clearing orientation change: " + w); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8540 | } |
| 8541 | } |
| 8542 | performLayoutAndPlaceSurfacesLocked(); |
| 8543 | } |
| 8544 | break; |
| 8545 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8546 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8547 | case HOLD_SCREEN_CHANGED: { |
| 8548 | Session oldHold; |
| 8549 | Session newHold; |
| 8550 | synchronized (mWindowMap) { |
| 8551 | oldHold = mLastReportedHold; |
| 8552 | newHold = (Session)msg.obj; |
| 8553 | mLastReportedHold = newHold; |
| 8554 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8555 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8556 | if (oldHold != newHold) { |
| 8557 | try { |
| 8558 | if (oldHold != null) { |
| Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 8559 | mBatteryStats.noteStopWakelock(oldHold.mUid, -1, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8560 | "window", |
| 8561 | BatteryStats.WAKE_TYPE_WINDOW); |
| 8562 | } |
| 8563 | if (newHold != null) { |
| Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 8564 | mBatteryStats.noteStartWakelock(newHold.mUid, -1, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8565 | "window", |
| 8566 | BatteryStats.WAKE_TYPE_WINDOW); |
| 8567 | } |
| 8568 | } catch (RemoteException e) { |
| 8569 | } |
| 8570 | } |
| 8571 | break; |
| 8572 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8573 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8574 | case APP_TRANSITION_TIMEOUT: { |
| 8575 | synchronized (mWindowMap) { |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 8576 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8577 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8578 | "*** APP TRANSITION TIMEOUT"); |
| 8579 | mAppTransitionReady = true; |
| 8580 | mAppTransitionTimeout = true; |
| 8581 | performLayoutAndPlaceSurfacesLocked(); |
| 8582 | } |
| 8583 | } |
| 8584 | break; |
| 8585 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8586 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8587 | case PERSIST_ANIMATION_SCALE: { |
| 8588 | Settings.System.putFloat(mContext.getContentResolver(), |
| 8589 | Settings.System.WINDOW_ANIMATION_SCALE, mWindowAnimationScale); |
| 8590 | Settings.System.putFloat(mContext.getContentResolver(), |
| 8591 | Settings.System.TRANSITION_ANIMATION_SCALE, mTransitionAnimationScale); |
| 8592 | break; |
| 8593 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8594 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8595 | case FORCE_GC: { |
| 8596 | synchronized(mWindowMap) { |
| 8597 | if (mAnimationPending) { |
| 8598 | // If we are animating, don't do the gc now but |
| 8599 | // delay a bit so we don't interrupt the animation. |
| 8600 | mH.sendMessageDelayed(mH.obtainMessage(H.FORCE_GC), |
| 8601 | 2000); |
| 8602 | return; |
| 8603 | } |
| 8604 | // If we are currently rotating the display, it will |
| 8605 | // schedule a new message when done. |
| 8606 | if (mDisplayFrozen) { |
| 8607 | return; |
| 8608 | } |
| 8609 | mFreezeGcPending = 0; |
| 8610 | } |
| 8611 | Runtime.getRuntime().gc(); |
| 8612 | break; |
| 8613 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8614 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8615 | case ENABLE_SCREEN: { |
| 8616 | performEnableScreen(); |
| 8617 | break; |
| 8618 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8619 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8620 | case APP_FREEZE_TIMEOUT: { |
| 8621 | synchronized (mWindowMap) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8622 | Slog.w(TAG, "App freeze timeout expired."); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8623 | int i = mAppTokens.size(); |
| 8624 | while (i > 0) { |
| 8625 | i--; |
| 8626 | AppWindowToken tok = mAppTokens.get(i); |
| 8627 | if (tok.freezingScreen) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8628 | Slog.w(TAG, "Force clearing freeze: " + tok); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8629 | unsetAppFreezingScreenLocked(tok, true, true); |
| 8630 | } |
| 8631 | } |
| 8632 | } |
| 8633 | break; |
| 8634 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8635 | |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 8636 | case SEND_NEW_CONFIGURATION: { |
| 8637 | removeMessages(SEND_NEW_CONFIGURATION); |
| 8638 | sendNewConfiguration(); |
| The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 8639 | break; |
| 8640 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8641 | |
| Konstantin Lopyrev | 6e0f65f | 2010-07-14 14:55:33 -0700 | [diff] [blame] | 8642 | case REPORT_WINDOWS_CHANGE: { |
| Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 8643 | if (mWindowsChanged) { |
| 8644 | synchronized (mWindowMap) { |
| 8645 | mWindowsChanged = false; |
| 8646 | } |
| 8647 | notifyWindowsChanged(); |
| 8648 | } |
| 8649 | break; |
| 8650 | } |
| 8651 | |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 8652 | case DRAG_START_TIMEOUT: { |
| 8653 | IBinder win = (IBinder)msg.obj; |
| 8654 | if (DEBUG_DRAG) { |
| 8655 | Slog.w(TAG, "Timeout starting drag by win " + win); |
| 8656 | } |
| 8657 | synchronized (mWindowMap) { |
| 8658 | // !!! TODO: ANR the app that has failed to start the drag in time |
| 8659 | if (mDragState != null) { |
| 8660 | mDragState.reset(); |
| 8661 | mDragState = null; |
| 8662 | } |
| 8663 | } |
| 8664 | } |
| 8665 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8666 | } |
| 8667 | } |
| 8668 | } |
| 8669 | |
| 8670 | // ------------------------------------------------------------- |
| 8671 | // IWindowManager API |
| 8672 | // ------------------------------------------------------------- |
| 8673 | |
| 8674 | public IWindowSession openSession(IInputMethodClient client, |
| 8675 | IInputContext inputContext) { |
| 8676 | if (client == null) throw new IllegalArgumentException("null client"); |
| 8677 | if (inputContext == null) throw new IllegalArgumentException("null inputContext"); |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 8678 | Session session = new Session(client, inputContext); |
| 8679 | return session; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8680 | } |
| 8681 | |
| 8682 | public boolean inputMethodClientHasFocus(IInputMethodClient client) { |
| 8683 | synchronized (mWindowMap) { |
| 8684 | // The focus for the client is the window immediately below |
| 8685 | // where we would place the input method window. |
| 8686 | int idx = findDesiredInputMethodWindowIndexLocked(false); |
| 8687 | WindowState imFocus; |
| 8688 | if (idx > 0) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 8689 | imFocus = mWindows.get(idx-1); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8690 | if (imFocus != null) { |
| 8691 | if (imFocus.mSession.mClient != null && |
| 8692 | imFocus.mSession.mClient.asBinder() == client.asBinder()) { |
| 8693 | return true; |
| 8694 | } |
| 8695 | } |
| 8696 | } |
| 8697 | } |
| 8698 | return false; |
| 8699 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8700 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8701 | // ------------------------------------------------------------- |
| 8702 | // Internals |
| 8703 | // ------------------------------------------------------------- |
| 8704 | |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 8705 | final WindowState windowForClientLocked(Session session, IWindow client, |
| 8706 | boolean throwOnError) { |
| 8707 | return windowForClientLocked(session, client.asBinder(), throwOnError); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8708 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8709 | |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 8710 | final WindowState windowForClientLocked(Session session, IBinder client, |
| 8711 | boolean throwOnError) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8712 | WindowState win = mWindowMap.get(client); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8713 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8714 | TAG, "Looking up client " + client + ": " + win); |
| 8715 | if (win == null) { |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 8716 | RuntimeException ex = new IllegalArgumentException( |
| 8717 | "Requested window " + client + " does not exist"); |
| 8718 | if (throwOnError) { |
| 8719 | throw ex; |
| 8720 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8721 | Slog.w(TAG, "Failed looking up window", ex); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8722 | return null; |
| 8723 | } |
| 8724 | if (session != null && win.mSession != session) { |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 8725 | RuntimeException ex = new IllegalArgumentException( |
| 8726 | "Requested window " + client + " is in session " + |
| 8727 | win.mSession + ", not " + session); |
| 8728 | if (throwOnError) { |
| 8729 | throw ex; |
| 8730 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8731 | Slog.w(TAG, "Failed looking up window", ex); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8732 | return null; |
| 8733 | } |
| 8734 | |
| 8735 | return win; |
| 8736 | } |
| 8737 | |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8738 | final void rebuildAppWindowListLocked() { |
| 8739 | int NW = mWindows.size(); |
| 8740 | int i; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8741 | int lastWallpaper = -1; |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 8742 | int numRemoved = 0; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8743 | |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8744 | // First remove all existing app windows. |
| 8745 | i=0; |
| 8746 | while (i < NW) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 8747 | WindowState w = mWindows.get(i); |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8748 | if (w.mAppToken != null) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 8749 | WindowState win = mWindows.remove(i); |
| Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 8750 | mWindowsChanged = true; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8751 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, |
| Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 8752 | "Rebuild removing window: " + win); |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8753 | NW--; |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 8754 | numRemoved++; |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8755 | continue; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8756 | } else if (w.mAttrs.type == WindowManager.LayoutParams.TYPE_WALLPAPER |
| 8757 | && lastWallpaper == i-1) { |
| 8758 | lastWallpaper = i; |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8759 | } |
| 8760 | i++; |
| 8761 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8762 | |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8763 | // The wallpaper window(s) typically live at the bottom of the stack, |
| 8764 | // so skip them before adding app tokens. |
| 8765 | lastWallpaper++; |
| 8766 | i = lastWallpaper; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8767 | |
| Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 8768 | // First add all of the exiting app tokens... these are no longer |
| 8769 | // in the main app list, but still have windows shown. We put them |
| 8770 | // in the back because now that the animation is over we no longer |
| 8771 | // will care about them. |
| 8772 | int NT = mExitingAppTokens.size(); |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8773 | for (int j=0; j<NT; j++) { |
| Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 8774 | i = reAddAppWindowsLocked(i, mExitingAppTokens.get(j)); |
| 8775 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8776 | |
| Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 8777 | // And add in the still active app tokens in Z order. |
| 8778 | NT = mAppTokens.size(); |
| 8779 | for (int j=0; j<NT; j++) { |
| 8780 | i = reAddAppWindowsLocked(i, mAppTokens.get(j)); |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8781 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8782 | |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8783 | i -= lastWallpaper; |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 8784 | if (i != numRemoved) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8785 | Slog.w(TAG, "Rebuild removed " + numRemoved |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 8786 | + " windows but added " + i); |
| 8787 | } |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8788 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8789 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8790 | private final void assignLayersLocked() { |
| 8791 | int N = mWindows.size(); |
| 8792 | int curBaseLayer = 0; |
| 8793 | int curLayer = 0; |
| 8794 | int i; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8795 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8796 | for (i=0; i<N; i++) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 8797 | WindowState w = mWindows.get(i); |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 8798 | if (w.mBaseLayer == curBaseLayer || w.mIsImWindow |
| 8799 | || (i > 0 && w.mIsWallpaper)) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8800 | curLayer += WINDOW_LAYER_MULTIPLIER; |
| 8801 | w.mLayer = curLayer; |
| 8802 | } else { |
| 8803 | curBaseLayer = curLayer = w.mBaseLayer; |
| 8804 | w.mLayer = curLayer; |
| 8805 | } |
| 8806 | if (w.mTargetAppToken != null) { |
| 8807 | w.mAnimLayer = w.mLayer + w.mTargetAppToken.animLayerAdjustment; |
| 8808 | } else if (w.mAppToken != null) { |
| 8809 | w.mAnimLayer = w.mLayer + w.mAppToken.animLayerAdjustment; |
| 8810 | } else { |
| 8811 | w.mAnimLayer = w.mLayer; |
| 8812 | } |
| 8813 | if (w.mIsImWindow) { |
| 8814 | w.mAnimLayer += mInputMethodAnimLayerAdjustment; |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 8815 | } else if (w.mIsWallpaper) { |
| 8816 | w.mAnimLayer += mWallpaperAnimLayerAdjustment; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8817 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8818 | if (DEBUG_LAYERS) Slog.v(TAG, "Assign layer " + w + ": " |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8819 | + w.mAnimLayer); |
| 8820 | //System.out.println( |
| 8821 | // "Assigned layer " + curLayer + " to " + w.mClient.asBinder()); |
| 8822 | } |
| 8823 | } |
| 8824 | |
| 8825 | private boolean mInLayout = false; |
| 8826 | private final void performLayoutAndPlaceSurfacesLocked() { |
| 8827 | if (mInLayout) { |
| Dave Bort | cfe6524 | 2009-04-09 14:51:04 -0700 | [diff] [blame] | 8828 | if (DEBUG) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8829 | throw new RuntimeException("Recursive call!"); |
| 8830 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8831 | Slog.w(TAG, "performLayoutAndPlaceSurfacesLocked called while in layout"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8832 | return; |
| 8833 | } |
| 8834 | |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 8835 | if (mWaitingForConfig) { |
| 8836 | // Our configuration has changed (most likely rotation), but we |
| 8837 | // don't yet have the complete configuration to report to |
| 8838 | // applications. Don't do any window layout until we have it. |
| 8839 | return; |
| 8840 | } |
| 8841 | |
| Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 8842 | if (mDisplay == null) { |
| 8843 | // Not yet initialized, nothing to do. |
| 8844 | return; |
| 8845 | } |
| 8846 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8847 | boolean recoveringMemory = false; |
| 8848 | if (mForceRemoves != null) { |
| 8849 | recoveringMemory = true; |
| 8850 | // Wait a little it for things to settle down, and off we go. |
| 8851 | for (int i=0; i<mForceRemoves.size(); i++) { |
| 8852 | WindowState ws = mForceRemoves.get(i); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8853 | Slog.i(TAG, "Force removing: " + ws); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8854 | removeWindowInnerLocked(ws.mSession, ws); |
| 8855 | } |
| 8856 | mForceRemoves = null; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8857 | 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] | 8858 | Object tmp = new Object(); |
| 8859 | synchronized (tmp) { |
| 8860 | try { |
| 8861 | tmp.wait(250); |
| 8862 | } catch (InterruptedException e) { |
| 8863 | } |
| 8864 | } |
| 8865 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8866 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8867 | mInLayout = true; |
| 8868 | try { |
| 8869 | performLayoutAndPlaceSurfacesLockedInner(recoveringMemory); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8870 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8871 | int i = mPendingRemove.size()-1; |
| 8872 | if (i >= 0) { |
| 8873 | while (i >= 0) { |
| 8874 | WindowState w = mPendingRemove.get(i); |
| 8875 | removeWindowInnerLocked(w.mSession, w); |
| 8876 | i--; |
| 8877 | } |
| 8878 | mPendingRemove.clear(); |
| 8879 | |
| 8880 | mInLayout = false; |
| 8881 | assignLayersLocked(); |
| 8882 | mLayoutNeeded = true; |
| 8883 | performLayoutAndPlaceSurfacesLocked(); |
| 8884 | |
| 8885 | } else { |
| 8886 | mInLayout = false; |
| 8887 | if (mLayoutNeeded) { |
| 8888 | requestAnimationLocked(0); |
| 8889 | } |
| 8890 | } |
| Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 8891 | if (mWindowsChanged && !mWindowChangeListeners.isEmpty()) { |
| Konstantin Lopyrev | 6e0f65f | 2010-07-14 14:55:33 -0700 | [diff] [blame] | 8892 | mH.removeMessages(H.REPORT_WINDOWS_CHANGE); |
| 8893 | mH.sendMessage(mH.obtainMessage(H.REPORT_WINDOWS_CHANGE)); |
| Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 8894 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8895 | } catch (RuntimeException e) { |
| 8896 | mInLayout = false; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8897 | 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] | 8898 | } |
| 8899 | } |
| 8900 | |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 8901 | private final int performLayoutLockedInner() { |
| 8902 | if (!mLayoutNeeded) { |
| 8903 | return 0; |
| 8904 | } |
| 8905 | |
| 8906 | mLayoutNeeded = false; |
| 8907 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8908 | final int dw = mDisplay.getWidth(); |
| 8909 | final int dh = mDisplay.getHeight(); |
| 8910 | |
| 8911 | final int N = mWindows.size(); |
| 8912 | int i; |
| 8913 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8914 | if (DEBUG_LAYOUT) Slog.v(TAG, "performLayout: needed=" |
| Dianne Hackborn | 9b52a21 | 2009-12-11 14:51:35 -0800 | [diff] [blame] | 8915 | + mLayoutNeeded + " dw=" + dw + " dh=" + dh); |
| 8916 | |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 8917 | mPolicy.beginLayoutLw(dw, dh); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8918 | |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 8919 | int seq = mLayoutSeq+1; |
| 8920 | if (seq < 0) seq = 0; |
| 8921 | mLayoutSeq = seq; |
| 8922 | |
| 8923 | // First perform layout of any root windows (not attached |
| 8924 | // to another window). |
| 8925 | int topAttached = -1; |
| 8926 | for (i = N-1; i >= 0; i--) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 8927 | WindowState win = mWindows.get(i); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8928 | |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 8929 | // Don't do layout of a window if it is not visible, or |
| 8930 | // soon won't be visible, to avoid wasting time and funky |
| 8931 | // changes while a window is animating away. |
| 8932 | final AppWindowToken atoken = win.mAppToken; |
| 8933 | final boolean gone = win.mViewVisibility == View.GONE |
| 8934 | || !win.mRelayoutCalled |
| 8935 | || win.mRootToken.hidden |
| 8936 | || (atoken != null && atoken.hiddenRequested) |
| 8937 | || win.mAttachedHidden |
| 8938 | || win.mExiting || win.mDestroying; |
| 8939 | |
| 8940 | if (!win.mLayoutAttached) { |
| 8941 | if (DEBUG_LAYOUT) Slog.v(TAG, "First pass " + win |
| 8942 | + ": gone=" + gone + " mHaveFrame=" + win.mHaveFrame |
| 8943 | + " mLayoutAttached=" + win.mLayoutAttached); |
| 8944 | if (DEBUG_LAYOUT && gone) Slog.v(TAG, " (mViewVisibility=" |
| 8945 | + win.mViewVisibility + " mRelayoutCalled=" |
| 8946 | + win.mRelayoutCalled + " hidden=" |
| 8947 | + win.mRootToken.hidden + " hiddenRequested=" |
| 8948 | + (atoken != null && atoken.hiddenRequested) |
| 8949 | + " mAttachedHidden=" + win.mAttachedHidden); |
| 8950 | } |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 8951 | |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 8952 | // If this view is GONE, then skip it -- keep the current |
| 8953 | // frame, and let the caller know so they can ignore it |
| 8954 | // if they want. (We do the normal layout for INVISIBLE |
| 8955 | // windows, since that means "perform layout as normal, |
| 8956 | // just don't display"). |
| 8957 | if (!gone || !win.mHaveFrame) { |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 8958 | if (!win.mLayoutAttached) { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 8959 | mPolicy.layoutWindowLw(win, win.mAttrs, null); |
| 8960 | win.mLayoutSeq = seq; |
| 8961 | if (DEBUG_LAYOUT) Slog.v(TAG, "-> mFrame=" |
| 8962 | + win.mFrame + " mContainingFrame=" |
| 8963 | + win.mContainingFrame + " mDisplayFrame=" |
| 8964 | + win.mDisplayFrame); |
| 8965 | } else { |
| 8966 | if (topAttached < 0) topAttached = i; |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 8967 | } |
| Dianne Hackborn | 958b9ad | 2009-03-31 18:00:36 -0700 | [diff] [blame] | 8968 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8969 | } |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 8970 | |
| 8971 | // Now perform layout of attached windows, which usually |
| 8972 | // depend on the position of the window they are attached to. |
| 8973 | // XXX does not deal with windows that are attached to windows |
| 8974 | // that are themselves attached. |
| 8975 | for (i = topAttached; i >= 0; i--) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 8976 | WindowState win = mWindows.get(i); |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 8977 | |
| 8978 | // If this view is GONE, then skip it -- keep the current |
| 8979 | // frame, and let the caller know so they can ignore it |
| 8980 | // if they want. (We do the normal layout for INVISIBLE |
| 8981 | // windows, since that means "perform layout as normal, |
| 8982 | // just don't display"). |
| 8983 | if (win.mLayoutAttached) { |
| 8984 | if (DEBUG_LAYOUT) Slog.v(TAG, "Second pass " + win |
| 8985 | + " mHaveFrame=" + win.mHaveFrame |
| 8986 | + " mViewVisibility=" + win.mViewVisibility |
| 8987 | + " mRelayoutCalled=" + win.mRelayoutCalled); |
| 8988 | if ((win.mViewVisibility != View.GONE && win.mRelayoutCalled) |
| 8989 | || !win.mHaveFrame) { |
| 8990 | mPolicy.layoutWindowLw(win, win.mAttrs, win.mAttachedWindow); |
| 8991 | win.mLayoutSeq = seq; |
| 8992 | if (DEBUG_LAYOUT) Slog.v(TAG, "-> mFrame=" |
| 8993 | + win.mFrame + " mContainingFrame=" |
| 8994 | + win.mContainingFrame + " mDisplayFrame=" |
| 8995 | + win.mDisplayFrame); |
| 8996 | } |
| 8997 | } |
| 8998 | } |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 8999 | |
| 9000 | // Window frames may have changed. Tell the input dispatcher about it. |
| Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 9001 | mInputMonitor.updateInputWindowsLw(); |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9002 | |
| 9003 | return mPolicy.finishLayoutLw(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9004 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9005 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9006 | private final void performLayoutAndPlaceSurfacesLockedInner( |
| 9007 | boolean recoveringMemory) { |
| Joe Onorato | 34bcebc | 2010-07-07 18:05:01 -0400 | [diff] [blame] | 9008 | if (mDisplay == null) { |
| 9009 | Slog.i(TAG, "skipping performLayoutAndPlaceSurfacesLockedInner with no mDisplay"); |
| 9010 | return; |
| 9011 | } |
| 9012 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9013 | final long currentTime = SystemClock.uptimeMillis(); |
| 9014 | final int dw = mDisplay.getWidth(); |
| 9015 | final int dh = mDisplay.getHeight(); |
| 9016 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9017 | int i; |
| 9018 | |
| Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 9019 | if (mFocusMayChange) { |
| 9020 | mFocusMayChange = false; |
| 9021 | updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES); |
| 9022 | } |
| 9023 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9024 | // Initialize state of exiting tokens. |
| 9025 | for (i=mExitingTokens.size()-1; i>=0; i--) { |
| 9026 | mExitingTokens.get(i).hasVisible = false; |
| 9027 | } |
| 9028 | |
| 9029 | // Initialize state of exiting applications. |
| 9030 | for (i=mExitingAppTokens.size()-1; i>=0; i--) { |
| 9031 | mExitingAppTokens.get(i).hasVisible = false; |
| 9032 | } |
| 9033 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9034 | boolean orientationChangeComplete = true; |
| 9035 | Session holdScreen = null; |
| 9036 | float screenBrightness = -1; |
| Mike Lockwood | fb73f79 | 2009-11-20 11:31:18 -0500 | [diff] [blame] | 9037 | float buttonBrightness = -1; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9038 | boolean focusDisplayed = false; |
| 9039 | boolean animating = false; |
| Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 9040 | boolean createWatermark = false; |
| 9041 | |
| 9042 | if (mFxSession == null) { |
| 9043 | mFxSession = new SurfaceSession(); |
| 9044 | createWatermark = true; |
| 9045 | } |
| 9046 | |
| 9047 | if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9048 | |
| 9049 | Surface.openTransaction(); |
| Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 9050 | |
| 9051 | if (createWatermark) { |
| 9052 | createWatermark(); |
| 9053 | } |
| 9054 | if (mWatermark != null) { |
| 9055 | mWatermark.positionSurface(dw, dh); |
| 9056 | } |
| 9057 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9058 | try { |
| Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 9059 | boolean wallpaperForceHidingChanged = false; |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9060 | int repeats = 0; |
| 9061 | int changes = 0; |
| 9062 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9063 | do { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9064 | repeats++; |
| 9065 | if (repeats > 6) { |
| 9066 | Slog.w(TAG, "Animation repeat aborted after too many iterations"); |
| 9067 | mLayoutNeeded = false; |
| 9068 | break; |
| 9069 | } |
| 9070 | |
| 9071 | if ((changes&(WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER |
| 9072 | | WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG |
| 9073 | | WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT)) != 0) { |
| 9074 | if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER) != 0) { |
| 9075 | if ((adjustWallpaperWindowsLocked()&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) { |
| 9076 | assignLayersLocked(); |
| 9077 | mLayoutNeeded = true; |
| 9078 | } |
| 9079 | } |
| 9080 | if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG) != 0) { |
| 9081 | if (DEBUG_LAYOUT) Slog.v(TAG, "Computing new config from layout"); |
| 9082 | if (updateOrientationFromAppTokensLocked()) { |
| 9083 | mLayoutNeeded = true; |
| 9084 | mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION); |
| 9085 | } |
| 9086 | } |
| 9087 | if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT) != 0) { |
| 9088 | mLayoutNeeded = true; |
| 9089 | } |
| 9090 | } |
| 9091 | |
| 9092 | // FIRST LOOP: Perform a layout, if needed. |
| 9093 | if (repeats < 4) { |
| 9094 | changes = performLayoutLockedInner(); |
| 9095 | if (changes != 0) { |
| 9096 | continue; |
| 9097 | } |
| 9098 | } else { |
| 9099 | Slog.w(TAG, "Layout repeat skipped after too many iterations"); |
| 9100 | changes = 0; |
| 9101 | } |
| 9102 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9103 | final int transactionSequence = ++mTransactionSequence; |
| 9104 | |
| 9105 | // Update animations of all applications, including those |
| 9106 | // associated with exiting/removed apps |
| 9107 | boolean tokensAnimating = false; |
| 9108 | final int NAT = mAppTokens.size(); |
| 9109 | for (i=0; i<NAT; i++) { |
| 9110 | if (mAppTokens.get(i).stepAnimationLocked(currentTime, dw, dh)) { |
| 9111 | tokensAnimating = true; |
| 9112 | } |
| 9113 | } |
| 9114 | final int NEAT = mExitingAppTokens.size(); |
| 9115 | for (i=0; i<NEAT; i++) { |
| 9116 | if (mExitingAppTokens.get(i).stepAnimationLocked(currentTime, dw, dh)) { |
| 9117 | tokensAnimating = true; |
| 9118 | } |
| 9119 | } |
| 9120 | |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9121 | // SECOND LOOP: Execute animations and update visibility of windows. |
| 9122 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9123 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "*** ANIM STEP: seq=" |
| Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 9124 | + transactionSequence + " tokensAnimating=" |
| 9125 | + tokensAnimating); |
| 9126 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9127 | animating = tokensAnimating; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9128 | |
| 9129 | boolean tokenMayBeDrawn = false; |
| Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 9130 | boolean wallpaperMayChange = false; |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9131 | boolean forceHiding = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9132 | |
| 9133 | mPolicy.beginAnimationLw(dw, dh); |
| 9134 | |
| Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 9135 | final int N = mWindows.size(); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9136 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9137 | for (i=N-1; i>=0; i--) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 9138 | WindowState w = mWindows.get(i); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9139 | |
| 9140 | final WindowManager.LayoutParams attrs = w.mAttrs; |
| 9141 | |
| 9142 | if (w.mSurface != null) { |
| 9143 | // Execute animation. |
| Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 9144 | if (w.commitFinishDrawingLocked(currentTime)) { |
| 9145 | if ((w.mAttrs.flags |
| 9146 | & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER) != 0) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9147 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 9148 | "First draw done in potential wallpaper target " + w); |
| Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 9149 | wallpaperMayChange = true; |
| 9150 | } |
| 9151 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9152 | |
| Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 9153 | boolean wasAnimating = w.mAnimating; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9154 | if (w.stepAnimationLocked(currentTime, dw, dh)) { |
| 9155 | animating = true; |
| 9156 | //w.dump(" "); |
| 9157 | } |
| Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 9158 | if (wasAnimating && !w.mAnimating && mWallpaperTarget == w) { |
| 9159 | wallpaperMayChange = true; |
| 9160 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9161 | |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9162 | if (mPolicy.doesForceHide(w, attrs)) { |
| 9163 | if (!wasAnimating && animating) { |
| Dianne Hackborn | 20cb56e | 2010-03-04 00:58:29 -0800 | [diff] [blame] | 9164 | if (DEBUG_VISIBILITY) Slog.v(TAG, |
| 9165 | "Animation done that could impact force hide: " |
| 9166 | + w); |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9167 | wallpaperForceHidingChanged = true; |
| Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 9168 | mFocusMayChange = true; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9169 | } else if (w.isReadyForDisplay() && w.mAnimation == null) { |
| 9170 | forceHiding = true; |
| 9171 | } |
| 9172 | } else if (mPolicy.canBeForceHidden(w, attrs)) { |
| 9173 | boolean changed; |
| 9174 | if (forceHiding) { |
| 9175 | changed = w.hideLw(false, false); |
| Dianne Hackborn | 20cb56e | 2010-03-04 00:58:29 -0800 | [diff] [blame] | 9176 | if (DEBUG_VISIBILITY && changed) Slog.v(TAG, |
| 9177 | "Now policy hidden: " + w); |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9178 | } else { |
| 9179 | changed = w.showLw(false, false); |
| Dianne Hackborn | 20cb56e | 2010-03-04 00:58:29 -0800 | [diff] [blame] | 9180 | if (DEBUG_VISIBILITY && changed) Slog.v(TAG, |
| 9181 | "Now policy shown: " + w); |
| 9182 | if (changed) { |
| 9183 | if (wallpaperForceHidingChanged |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9184 | && w.isVisibleNow() /*w.isReadyForDisplay()*/) { |
| Dianne Hackborn | 20cb56e | 2010-03-04 00:58:29 -0800 | [diff] [blame] | 9185 | // Assume we will need to animate. If |
| 9186 | // we don't (because the wallpaper will |
| 9187 | // stay with the lock screen), then we will |
| 9188 | // clean up later. |
| 9189 | Animation a = mPolicy.createForceHideEnterAnimation(); |
| 9190 | if (a != null) { |
| 9191 | w.setAnimation(a); |
| 9192 | } |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9193 | } |
| Dianne Hackborn | 20cb56e | 2010-03-04 00:58:29 -0800 | [diff] [blame] | 9194 | if (mCurrentFocus == null || |
| 9195 | mCurrentFocus.mLayer < w.mLayer) { |
| 9196 | // We are showing on to of the current |
| 9197 | // focus, so re-evaluate focus to make |
| 9198 | // sure it is correct. |
| 9199 | mFocusMayChange = true; |
| 9200 | } |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9201 | } |
| 9202 | } |
| 9203 | if (changed && (attrs.flags |
| 9204 | & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER) != 0) { |
| 9205 | wallpaperMayChange = true; |
| 9206 | } |
| 9207 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9208 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9209 | mPolicy.animatingWindowLw(w, attrs); |
| 9210 | } |
| 9211 | |
| 9212 | final AppWindowToken atoken = w.mAppToken; |
| 9213 | if (atoken != null && (!atoken.allDrawn || atoken.freezingScreen)) { |
| 9214 | if (atoken.lastTransactionSequence != transactionSequence) { |
| 9215 | atoken.lastTransactionSequence = transactionSequence; |
| 9216 | atoken.numInterestingWindows = atoken.numDrawnWindows = 0; |
| 9217 | atoken.startingDisplayed = false; |
| 9218 | } |
| 9219 | if ((w.isOnScreen() || w.mAttrs.type |
| 9220 | == WindowManager.LayoutParams.TYPE_BASE_APPLICATION) |
| 9221 | && !w.mExiting && !w.mDestroying) { |
| 9222 | if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9223 | Slog.v(TAG, "Eval win " + w + ": isDrawn=" |
| Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 9224 | + w.isDrawnLw() |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9225 | + ", isAnimating=" + w.isAnimating()); |
| Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 9226 | if (!w.isDrawnLw()) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9227 | Slog.v(TAG, "Not displayed: s=" + w.mSurface |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9228 | + " pv=" + w.mPolicyVisibility |
| 9229 | + " dp=" + w.mDrawPending |
| 9230 | + " cdp=" + w.mCommitDrawPending |
| 9231 | + " ah=" + w.mAttachedHidden |
| 9232 | + " th=" + atoken.hiddenRequested |
| 9233 | + " a=" + w.mAnimating); |
| 9234 | } |
| 9235 | } |
| 9236 | if (w != atoken.startingWindow) { |
| 9237 | if (!atoken.freezingScreen || !w.mAppFreezing) { |
| 9238 | atoken.numInterestingWindows++; |
| Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 9239 | if (w.isDrawnLw()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9240 | atoken.numDrawnWindows++; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9241 | if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9242 | "tokenMayBeDrawn: " + atoken |
| 9243 | + " freezingScreen=" + atoken.freezingScreen |
| 9244 | + " mAppFreezing=" + w.mAppFreezing); |
| 9245 | tokenMayBeDrawn = true; |
| 9246 | } |
| 9247 | } |
| Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 9248 | } else if (w.isDrawnLw()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9249 | atoken.startingDisplayed = true; |
| 9250 | } |
| 9251 | } |
| 9252 | } else if (w.mReadyToShow) { |
| 9253 | w.performShowLocked(); |
| 9254 | } |
| 9255 | } |
| 9256 | |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9257 | changes |= mPolicy.finishAnimationLw(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9258 | |
| 9259 | if (tokenMayBeDrawn) { |
| 9260 | // See if any windows have been drawn, so they (and others |
| 9261 | // associated with them) can now be shown. |
| 9262 | final int NT = mTokenList.size(); |
| 9263 | for (i=0; i<NT; i++) { |
| 9264 | AppWindowToken wtoken = mTokenList.get(i).appWindowToken; |
| 9265 | if (wtoken == null) { |
| 9266 | continue; |
| 9267 | } |
| 9268 | if (wtoken.freezingScreen) { |
| 9269 | int numInteresting = wtoken.numInterestingWindows; |
| 9270 | if (numInteresting > 0 && wtoken.numDrawnWindows >= numInteresting) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9271 | if (DEBUG_VISIBILITY) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9272 | "allDrawn: " + wtoken |
| 9273 | + " interesting=" + numInteresting |
| 9274 | + " drawn=" + wtoken.numDrawnWindows); |
| 9275 | wtoken.showAllWindowsLocked(); |
| 9276 | unsetAppFreezingScreenLocked(wtoken, false, true); |
| 9277 | orientationChangeComplete = true; |
| 9278 | } |
| 9279 | } else if (!wtoken.allDrawn) { |
| 9280 | int numInteresting = wtoken.numInterestingWindows; |
| 9281 | if (numInteresting > 0 && wtoken.numDrawnWindows >= numInteresting) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9282 | if (DEBUG_VISIBILITY) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9283 | "allDrawn: " + wtoken |
| 9284 | + " interesting=" + numInteresting |
| 9285 | + " drawn=" + wtoken.numDrawnWindows); |
| 9286 | wtoken.allDrawn = true; |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9287 | changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9288 | |
| 9289 | // We can now show all of the drawn windows! |
| 9290 | if (!mOpeningApps.contains(wtoken)) { |
| 9291 | wtoken.showAllWindowsLocked(); |
| 9292 | } |
| 9293 | } |
| 9294 | } |
| 9295 | } |
| 9296 | } |
| 9297 | |
| 9298 | // If we are ready to perform an app transition, check through |
| 9299 | // all of the app tokens to be shown and see if they are ready |
| 9300 | // to go. |
| 9301 | if (mAppTransitionReady) { |
| 9302 | int NN = mOpeningApps.size(); |
| 9303 | boolean goodToGo = true; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9304 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9305 | "Checking " + NN + " opening apps (frozen=" |
| 9306 | + mDisplayFrozen + " timeout=" |
| 9307 | + mAppTransitionTimeout + ")..."); |
| 9308 | if (!mDisplayFrozen && !mAppTransitionTimeout) { |
| 9309 | // If the display isn't frozen, wait to do anything until |
| 9310 | // all of the apps are ready. Otherwise just go because |
| 9311 | // we'll unfreeze the display when everyone is ready. |
| 9312 | for (i=0; i<NN && goodToGo; i++) { |
| 9313 | AppWindowToken wtoken = mOpeningApps.get(i); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9314 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9315 | "Check opening app" + wtoken + ": allDrawn=" |
| 9316 | + wtoken.allDrawn + " startingDisplayed=" |
| 9317 | + wtoken.startingDisplayed); |
| 9318 | if (!wtoken.allDrawn && !wtoken.startingDisplayed |
| 9319 | && !wtoken.startingMoved) { |
| 9320 | goodToGo = false; |
| 9321 | } |
| 9322 | } |
| 9323 | } |
| 9324 | if (goodToGo) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9325 | 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] | 9326 | int transit = mNextAppTransition; |
| 9327 | if (mSkipAppTransitionAnimation) { |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 9328 | transit = WindowManagerPolicy.TRANSIT_UNSET; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9329 | } |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 9330 | mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9331 | mAppTransitionReady = false; |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9332 | mAppTransitionRunning = true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9333 | mAppTransitionTimeout = false; |
| 9334 | mStartingIconInTransition = false; |
| 9335 | mSkipAppTransitionAnimation = false; |
| 9336 | |
| 9337 | mH.removeMessages(H.APP_TRANSITION_TIMEOUT); |
| 9338 | |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9339 | // If there are applications waiting to come to the |
| 9340 | // top of the stack, now is the time to move their windows. |
| 9341 | // (Note that we don't do apps going to the bottom |
| 9342 | // here -- we want to keep their windows in the old |
| 9343 | // Z-order until the animation completes.) |
| 9344 | if (mToTopApps.size() > 0) { |
| 9345 | NN = mAppTokens.size(); |
| 9346 | for (i=0; i<NN; i++) { |
| 9347 | AppWindowToken wtoken = mAppTokens.get(i); |
| 9348 | if (wtoken.sendingToTop) { |
| 9349 | wtoken.sendingToTop = false; |
| 9350 | moveAppWindowsLocked(wtoken, NN, false); |
| 9351 | } |
| 9352 | } |
| 9353 | mToTopApps.clear(); |
| 9354 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9355 | |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 9356 | WindowState oldWallpaper = mWallpaperTarget; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9357 | |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 9358 | adjustWallpaperWindowsLocked(); |
| Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 9359 | wallpaperMayChange = false; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9360 | |
| Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 9361 | // The top-most window will supply the layout params, |
| 9362 | // and we will determine it below. |
| 9363 | LayoutParams animLp = null; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9364 | AppWindowToken animToken = null; |
| Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 9365 | int bestAnimLayer = -1; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9366 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9367 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 9368 | "New wallpaper target=" + mWallpaperTarget |
| 9369 | + ", lower target=" + mLowerWallpaperTarget |
| 9370 | + ", upper target=" + mUpperWallpaperTarget); |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 9371 | int foundWallpapers = 0; |
| Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 9372 | // Do a first pass through the tokens for two |
| 9373 | // things: |
| 9374 | // (1) Determine if both the closing and opening |
| 9375 | // app token sets are wallpaper targets, in which |
| 9376 | // case special animations are needed |
| 9377 | // (since the wallpaper needs to stay static |
| 9378 | // behind them). |
| 9379 | // (2) Find the layout params of the top-most |
| 9380 | // application window in the tokens, which is |
| 9381 | // what will control the animation theme. |
| 9382 | final int NC = mClosingApps.size(); |
| 9383 | NN = NC + mOpeningApps.size(); |
| 9384 | for (i=0; i<NN; i++) { |
| 9385 | AppWindowToken wtoken; |
| 9386 | int mode; |
| 9387 | if (i < NC) { |
| 9388 | wtoken = mClosingApps.get(i); |
| 9389 | mode = 1; |
| 9390 | } else { |
| 9391 | wtoken = mOpeningApps.get(i-NC); |
| 9392 | mode = 2; |
| 9393 | } |
| 9394 | if (mLowerWallpaperTarget != null) { |
| 9395 | if (mLowerWallpaperTarget.mAppToken == wtoken |
| 9396 | || mUpperWallpaperTarget.mAppToken == wtoken) { |
| 9397 | foundWallpapers |= mode; |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 9398 | } |
| 9399 | } |
| Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 9400 | if (wtoken.appFullscreen) { |
| 9401 | WindowState ws = wtoken.findMainWindow(); |
| 9402 | if (ws != null) { |
| 9403 | // If this is a compatibility mode |
| 9404 | // window, we will always use its anim. |
| 9405 | if ((ws.mAttrs.flags&FLAG_COMPATIBLE_WINDOW) != 0) { |
| 9406 | animLp = ws.mAttrs; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9407 | animToken = ws.mAppToken; |
| Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 9408 | bestAnimLayer = Integer.MAX_VALUE; |
| 9409 | } else if (ws.mLayer > bestAnimLayer) { |
| 9410 | animLp = ws.mAttrs; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9411 | animToken = ws.mAppToken; |
| Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 9412 | bestAnimLayer = ws.mLayer; |
| 9413 | } |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 9414 | } |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 9415 | } |
| 9416 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9417 | |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 9418 | if (foundWallpapers == 3) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9419 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 9420 | "Wallpaper animation!"); |
| 9421 | switch (transit) { |
| 9422 | case WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN: |
| 9423 | case WindowManagerPolicy.TRANSIT_TASK_OPEN: |
| 9424 | case WindowManagerPolicy.TRANSIT_TASK_TO_FRONT: |
| 9425 | transit = WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_OPEN; |
| 9426 | break; |
| 9427 | case WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE: |
| 9428 | case WindowManagerPolicy.TRANSIT_TASK_CLOSE: |
| 9429 | case WindowManagerPolicy.TRANSIT_TASK_TO_BACK: |
| 9430 | transit = WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_CLOSE; |
| 9431 | break; |
| 9432 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9433 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 9434 | "New transit: " + transit); |
| 9435 | } else if (oldWallpaper != null) { |
| 9436 | // We are transitioning from an activity with |
| 9437 | // a wallpaper to one without. |
| 9438 | transit = WindowManagerPolicy.TRANSIT_WALLPAPER_CLOSE; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9439 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 9440 | "New transit away from wallpaper: " + transit); |
| 9441 | } else if (mWallpaperTarget != null) { |
| 9442 | // We are transitioning from an activity without |
| 9443 | // a wallpaper to now showing the wallpaper |
| 9444 | transit = WindowManagerPolicy.TRANSIT_WALLPAPER_OPEN; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9445 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 9446 | "New transit into wallpaper: " + transit); |
| 9447 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9448 | |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9449 | if ((transit&WindowManagerPolicy.TRANSIT_ENTER_MASK) != 0) { |
| 9450 | mLastEnterAnimToken = animToken; |
| 9451 | mLastEnterAnimParams = animLp; |
| 9452 | } else if (mLastEnterAnimParams != null) { |
| 9453 | animLp = mLastEnterAnimParams; |
| 9454 | mLastEnterAnimToken = null; |
| 9455 | mLastEnterAnimParams = null; |
| 9456 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9457 | |
| Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 9458 | // If all closing windows are obscured, then there is |
| 9459 | // no need to do an animation. This is the case, for |
| 9460 | // example, when this transition is being done behind |
| 9461 | // the lock screen. |
| 9462 | if (!mPolicy.allowAppAnimationsLw()) { |
| 9463 | animLp = null; |
| 9464 | } |
| 9465 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9466 | NN = mOpeningApps.size(); |
| 9467 | for (i=0; i<NN; i++) { |
| 9468 | AppWindowToken wtoken = mOpeningApps.get(i); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9469 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9470 | "Now opening app" + wtoken); |
| 9471 | wtoken.reportedVisible = false; |
| 9472 | wtoken.inPendingTransaction = false; |
| Dianne Hackborn | 83360b3 | 2009-08-24 18:43:32 -0700 | [diff] [blame] | 9473 | wtoken.animation = null; |
| Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 9474 | setTokenVisibilityLocked(wtoken, animLp, true, transit, false); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9475 | wtoken.updateReportedVisibilityLocked(); |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9476 | wtoken.waitingToShow = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9477 | wtoken.showAllWindowsLocked(); |
| 9478 | } |
| 9479 | NN = mClosingApps.size(); |
| 9480 | for (i=0; i<NN; i++) { |
| 9481 | AppWindowToken wtoken = mClosingApps.get(i); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9482 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9483 | "Now closing app" + wtoken); |
| 9484 | wtoken.inPendingTransaction = false; |
| Dianne Hackborn | 83360b3 | 2009-08-24 18:43:32 -0700 | [diff] [blame] | 9485 | wtoken.animation = null; |
| Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 9486 | setTokenVisibilityLocked(wtoken, animLp, false, transit, false); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9487 | wtoken.updateReportedVisibilityLocked(); |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9488 | wtoken.waitingToHide = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9489 | // Force the allDrawn flag, because we want to start |
| 9490 | // this guy's animations regardless of whether it's |
| 9491 | // gotten drawn. |
| 9492 | wtoken.allDrawn = true; |
| 9493 | } |
| 9494 | |
| Dianne Hackborn | 8b571a8 | 2009-09-25 16:09:43 -0700 | [diff] [blame] | 9495 | mNextAppTransitionPackage = null; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9496 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9497 | mOpeningApps.clear(); |
| 9498 | mClosingApps.clear(); |
| 9499 | |
| 9500 | // This has changed the visibility of windows, so perform |
| 9501 | // a new layout to get them all up-to-date. |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9502 | changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9503 | mLayoutNeeded = true; |
| Dianne Hackborn | 20583ff | 2009-07-27 21:51:05 -0700 | [diff] [blame] | 9504 | if (!moveInputMethodWindowsIfNeededLocked(true)) { |
| 9505 | assignLayersLocked(); |
| 9506 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9507 | updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES); |
| Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 9508 | mFocusMayChange = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9509 | } |
| 9510 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9511 | |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 9512 | int adjResult = 0; |
| 9513 | |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9514 | if (!animating && mAppTransitionRunning) { |
| 9515 | // We have finished the animation of an app transition. To do |
| 9516 | // this, we have delayed a lot of operations like showing and |
| 9517 | // hiding apps, moving apps in Z-order, etc. The app token list |
| 9518 | // reflects the correct Z-order, but the window list may now |
| 9519 | // be out of sync with it. So here we will just rebuild the |
| 9520 | // entire app window list. Fun! |
| 9521 | mAppTransitionRunning = false; |
| 9522 | // Clear information about apps that were moving. |
| 9523 | mToBottomApps.clear(); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9524 | |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9525 | rebuildAppWindowListLocked(); |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9526 | changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT; |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 9527 | adjResult |= ADJUST_WALLPAPER_LAYERS_CHANGED; |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9528 | moveInputMethodWindowsIfNeededLocked(false); |
| 9529 | wallpaperMayChange = true; |
| Suchi Amalapurapu | c9568e3 | 2009-11-05 18:51:16 -0800 | [diff] [blame] | 9530 | // Since the window list has been rebuilt, focus might |
| 9531 | // have to be recomputed since the actual order of windows |
| 9532 | // might have changed again. |
| Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 9533 | mFocusMayChange = true; |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9534 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9535 | |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9536 | if (wallpaperForceHidingChanged && changes == 0 && !mAppTransitionReady) { |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9537 | // At this point, there was a window with a wallpaper that |
| 9538 | // was force hiding other windows behind it, but now it |
| 9539 | // is going away. This may be simple -- just animate |
| 9540 | // away the wallpaper and its window -- or it may be |
| 9541 | // hard -- the wallpaper now needs to be shown behind |
| 9542 | // something that was hidden. |
| 9543 | WindowState oldWallpaper = mWallpaperTarget; |
| Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 9544 | if (mLowerWallpaperTarget != null |
| 9545 | && mLowerWallpaperTarget.mAppToken != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9546 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
| Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 9547 | "wallpaperForceHiding changed with lower=" |
| 9548 | + mLowerWallpaperTarget); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9549 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
| Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 9550 | "hidden=" + mLowerWallpaperTarget.mAppToken.hidden + |
| 9551 | " hiddenRequested=" + mLowerWallpaperTarget.mAppToken.hiddenRequested); |
| 9552 | if (mLowerWallpaperTarget.mAppToken.hidden) { |
| 9553 | // The lower target has become hidden before we |
| 9554 | // actually started the animation... let's completely |
| 9555 | // re-evaluate everything. |
| 9556 | mLowerWallpaperTarget = mUpperWallpaperTarget = null; |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9557 | changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM; |
| Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 9558 | } |
| 9559 | } |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 9560 | adjResult |= adjustWallpaperWindowsLocked(); |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9561 | wallpaperMayChange = false; |
| Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 9562 | wallpaperForceHidingChanged = false; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9563 | if (DEBUG_WALLPAPER) Slog.v(TAG, "****** OLD: " + oldWallpaper |
| Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 9564 | + " NEW: " + mWallpaperTarget |
| 9565 | + " LOWER: " + mLowerWallpaperTarget); |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9566 | if (mLowerWallpaperTarget == null) { |
| 9567 | // Whoops, we don't need a special wallpaper animation. |
| 9568 | // Clear them out. |
| 9569 | forceHiding = false; |
| 9570 | for (i=N-1; i>=0; i--) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 9571 | WindowState w = mWindows.get(i); |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9572 | if (w.mSurface != null) { |
| 9573 | final WindowManager.LayoutParams attrs = w.mAttrs; |
| Suchi Amalapurapu | c03d28b | 2009-10-28 14:32:05 -0700 | [diff] [blame] | 9574 | if (mPolicy.doesForceHide(w, attrs) && w.isVisibleLw()) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9575 | if (DEBUG_FOCUS) Slog.i(TAG, "win=" + w + " force hides other windows"); |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9576 | forceHiding = true; |
| 9577 | } else if (mPolicy.canBeForceHidden(w, attrs)) { |
| 9578 | if (!w.mAnimating) { |
| 9579 | // We set the animation above so it |
| 9580 | // is not yet running. |
| 9581 | w.clearAnimation(); |
| 9582 | } |
| 9583 | } |
| 9584 | } |
| 9585 | } |
| 9586 | } |
| 9587 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9588 | |
| Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 9589 | if (wallpaperMayChange) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9590 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 9591 | "Wallpaper may change! Adjusting"); |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 9592 | adjResult |= adjustWallpaperWindowsLocked(); |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9593 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9594 | |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9595 | if ((adjResult&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9596 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9597 | "Wallpaper layer changed: assigning layers + relayout"); |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9598 | changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9599 | assignLayersLocked(); |
| 9600 | } else if ((adjResult&ADJUST_WALLPAPER_VISIBILITY_CHANGED) != 0) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9601 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9602 | "Wallpaper visibility changed: relayout"); |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9603 | changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9604 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9605 | |
| Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 9606 | if (mFocusMayChange) { |
| 9607 | mFocusMayChange = false; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9608 | if (updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES)) { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9609 | changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9610 | adjResult = 0; |
| Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 9611 | } |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9612 | } |
| 9613 | |
| 9614 | if (mLayoutNeeded) { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9615 | changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT; |
| Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 9616 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9617 | |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9618 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "*** ANIM STEP: changes=0x" |
| 9619 | + Integer.toHexString(changes)); |
| Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 9620 | |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 9621 | mInputMonitor.updateInputWindowsLw(); |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9622 | } while (changes != 0); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9623 | |
| 9624 | // THIRD LOOP: Update the surfaces of all windows. |
| 9625 | |
| 9626 | final boolean someoneLosingFocus = mLosingFocus.size() != 0; |
| 9627 | |
| 9628 | boolean obscured = false; |
| 9629 | boolean blurring = false; |
| 9630 | boolean dimming = false; |
| 9631 | boolean covered = false; |
| Dianne Hackborn | 9ed4a4b | 2009-03-25 17:10:37 -0700 | [diff] [blame] | 9632 | boolean syswin = false; |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 9633 | boolean backgroundFillerShown = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9634 | |
| Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 9635 | final int N = mWindows.size(); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9636 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9637 | for (i=N-1; i>=0; i--) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 9638 | WindowState w = mWindows.get(i); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9639 | |
| 9640 | boolean displayed = false; |
| 9641 | final WindowManager.LayoutParams attrs = w.mAttrs; |
| 9642 | final int attrFlags = attrs.flags; |
| 9643 | |
| 9644 | if (w.mSurface != null) { |
| Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 9645 | // XXX NOTE: The logic here could be improved. We have |
| 9646 | // the decision about whether to resize a window separated |
| 9647 | // from whether to hide the surface. This can cause us to |
| 9648 | // resize a surface even if we are going to hide it. You |
| 9649 | // can see this by (1) holding device in landscape mode on |
| 9650 | // home screen; (2) tapping browser icon (device will rotate |
| 9651 | // to landscape; (3) tap home. The wallpaper will be resized |
| 9652 | // in step 2 but then immediately hidden, causing us to |
| 9653 | // have to resize and then redraw it again in step 3. It |
| 9654 | // would be nice to figure out how to avoid this, but it is |
| 9655 | // difficult because we do need to resize surfaces in some |
| 9656 | // cases while they are hidden such as when first showing a |
| 9657 | // window. |
| 9658 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9659 | w.computeShownFrameLocked(); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9660 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9661 | TAG, "Placing surface #" + i + " " + w.mSurface |
| 9662 | + ": new=" + w.mShownFrame + ", old=" |
| 9663 | + w.mLastShownFrame); |
| 9664 | |
| 9665 | boolean resize; |
| 9666 | int width, height; |
| 9667 | if ((w.mAttrs.flags & w.mAttrs.FLAG_SCALED) != 0) { |
| 9668 | resize = w.mLastRequestedWidth != w.mRequestedWidth || |
| 9669 | w.mLastRequestedHeight != w.mRequestedHeight; |
| 9670 | // for a scaled surface, we just want to use |
| 9671 | // the requested size. |
| 9672 | width = w.mRequestedWidth; |
| 9673 | height = w.mRequestedHeight; |
| 9674 | w.mLastRequestedWidth = width; |
| 9675 | w.mLastRequestedHeight = height; |
| 9676 | w.mLastShownFrame.set(w.mShownFrame); |
| 9677 | try { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9678 | if (SHOW_TRANSACTIONS) logSurface(w, |
| 9679 | "POS " + w.mShownFrame.left |
| 9680 | + ", " + w.mShownFrame.top, null); |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 9681 | w.mSurfaceX = w.mShownFrame.left; |
| 9682 | w.mSurfaceY = w.mShownFrame.top; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9683 | w.mSurface.setPosition(w.mShownFrame.left, w.mShownFrame.top); |
| 9684 | } catch (RuntimeException e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9685 | Slog.w(TAG, "Error positioning surface in " + w, e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9686 | if (!recoveringMemory) { |
| 9687 | reclaimSomeSurfaceMemoryLocked(w, "position"); |
| 9688 | } |
| 9689 | } |
| 9690 | } else { |
| 9691 | resize = !w.mLastShownFrame.equals(w.mShownFrame); |
| 9692 | width = w.mShownFrame.width(); |
| 9693 | height = w.mShownFrame.height(); |
| 9694 | w.mLastShownFrame.set(w.mShownFrame); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9695 | } |
| 9696 | |
| 9697 | if (resize) { |
| 9698 | if (width < 1) width = 1; |
| 9699 | if (height < 1) height = 1; |
| 9700 | if (w.mSurface != null) { |
| 9701 | try { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9702 | if (SHOW_TRANSACTIONS) logSurface(w, |
| 9703 | "POS " + w.mShownFrame.left + "," |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 9704 | + w.mShownFrame.top + " SIZE " |
| 9705 | + w.mShownFrame.width() + "x" |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9706 | + w.mShownFrame.height(), null); |
| Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 9707 | w.mSurfaceResized = true; |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 9708 | w.mSurfaceW = width; |
| 9709 | w.mSurfaceH = height; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9710 | w.mSurface.setSize(width, height); |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 9711 | w.mSurfaceX = w.mShownFrame.left; |
| 9712 | w.mSurfaceY = w.mShownFrame.top; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9713 | w.mSurface.setPosition(w.mShownFrame.left, |
| 9714 | w.mShownFrame.top); |
| 9715 | } catch (RuntimeException e) { |
| 9716 | // If something goes wrong with the surface (such |
| 9717 | // as running out of memory), don't take down the |
| 9718 | // entire system. |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9719 | Slog.e(TAG, "Failure updating surface of " + w |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9720 | + "size=(" + width + "x" + height |
| 9721 | + "), pos=(" + w.mShownFrame.left |
| 9722 | + "," + w.mShownFrame.top + ")", e); |
| 9723 | if (!recoveringMemory) { |
| 9724 | reclaimSomeSurfaceMemoryLocked(w, "size"); |
| 9725 | } |
| 9726 | } |
| 9727 | } |
| 9728 | } |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 9729 | if (!w.mAppFreezing && w.mLayoutSeq == mLayoutSeq) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9730 | w.mContentInsetsChanged = |
| 9731 | !w.mLastContentInsets.equals(w.mContentInsets); |
| 9732 | w.mVisibleInsetsChanged = |
| 9733 | !w.mLastVisibleInsets.equals(w.mVisibleInsets); |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 9734 | boolean configChanged = |
| 9735 | w.mConfiguration != mCurConfiguration |
| 9736 | && (w.mConfiguration == null |
| 9737 | || mCurConfiguration.diff(w.mConfiguration) != 0); |
| Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 9738 | if (DEBUG_CONFIGURATION && configChanged) { |
| 9739 | Slog.v(TAG, "Win " + w + " config changed: " |
| 9740 | + mCurConfiguration); |
| 9741 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9742 | if (localLOGV) Slog.v(TAG, "Resizing " + w |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 9743 | + ": configChanged=" + configChanged |
| 9744 | + " last=" + w.mLastFrame + " frame=" + w.mFrame); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9745 | if (!w.mLastFrame.equals(w.mFrame) |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9746 | || w.mContentInsetsChanged |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 9747 | || w.mVisibleInsetsChanged |
| Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 9748 | || w.mSurfaceResized |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 9749 | || configChanged) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9750 | w.mLastFrame.set(w.mFrame); |
| 9751 | w.mLastContentInsets.set(w.mContentInsets); |
| 9752 | w.mLastVisibleInsets.set(w.mVisibleInsets); |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 9753 | // If the screen is currently frozen, then keep |
| 9754 | // it frozen until this window draws at its new |
| 9755 | // orientation. |
| 9756 | if (mDisplayFrozen) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9757 | if (DEBUG_ORIENTATION) Slog.v(TAG, |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 9758 | "Resizing while display frozen: " + w); |
| 9759 | w.mOrientationChanging = true; |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 9760 | if (!mWindowsFreezingScreen) { |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 9761 | mWindowsFreezingScreen = true; |
| 9762 | // XXX should probably keep timeout from |
| 9763 | // when we first froze the display. |
| 9764 | mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT); |
| 9765 | mH.sendMessageDelayed(mH.obtainMessage( |
| 9766 | H.WINDOW_FREEZE_TIMEOUT), 2000); |
| 9767 | } |
| 9768 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9769 | // If the orientation is changing, then we need to |
| 9770 | // hold off on unfreezing the display until this |
| 9771 | // window has been redrawn; to do that, we need |
| 9772 | // to go through the process of getting informed |
| 9773 | // by the application when it has finished drawing. |
| 9774 | if (w.mOrientationChanging) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9775 | if (DEBUG_ORIENTATION) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9776 | "Orientation start waiting for draw in " |
| 9777 | + w + ", surface " + w.mSurface); |
| 9778 | w.mDrawPending = true; |
| 9779 | w.mCommitDrawPending = false; |
| 9780 | w.mReadyToShow = false; |
| 9781 | if (w.mAppToken != null) { |
| 9782 | w.mAppToken.allDrawn = false; |
| 9783 | } |
| 9784 | } |
| Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 9785 | if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9786 | "Resizing window " + w + " to " + w.mFrame); |
| 9787 | mResizingWindows.add(w); |
| 9788 | } else if (w.mOrientationChanging) { |
| 9789 | if (!w.mDrawPending && !w.mCommitDrawPending) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9790 | if (DEBUG_ORIENTATION) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9791 | "Orientation not waiting for draw in " |
| 9792 | + w + ", surface " + w.mSurface); |
| 9793 | w.mOrientationChanging = false; |
| 9794 | } |
| 9795 | } |
| 9796 | } |
| 9797 | |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9798 | if (w.mAttachedHidden || !w.isReadyForDisplay()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9799 | if (!w.mLastHidden) { |
| 9800 | //dump(); |
| 9801 | w.mLastHidden = true; |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9802 | if (SHOW_TRANSACTIONS) logSurface(w, |
| 9803 | "HIDE (performLayout)", null); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9804 | if (w.mSurface != null) { |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 9805 | w.mSurfaceShown = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9806 | try { |
| 9807 | w.mSurface.hide(); |
| 9808 | } catch (RuntimeException e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9809 | Slog.w(TAG, "Exception hiding surface in " + w); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9810 | } |
| 9811 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9812 | } |
| 9813 | // If we are waiting for this window to handle an |
| 9814 | // orientation change, well, it is hidden, so |
| 9815 | // doesn't really matter. Note that this does |
| 9816 | // introduce a potential glitch if the window |
| 9817 | // becomes unhidden before it has drawn for the |
| 9818 | // new orientation. |
| 9819 | if (w.mOrientationChanging) { |
| 9820 | w.mOrientationChanging = false; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9821 | if (DEBUG_ORIENTATION) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9822 | "Orientation change skips hidden " + w); |
| 9823 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9824 | } else if (w.mLastLayer != w.mAnimLayer |
| 9825 | || w.mLastAlpha != w.mShownAlpha |
| 9826 | || w.mLastDsDx != w.mDsDx |
| 9827 | || w.mLastDtDx != w.mDtDx |
| 9828 | || w.mLastDsDy != w.mDsDy |
| 9829 | || w.mLastDtDy != w.mDtDy |
| 9830 | || w.mLastHScale != w.mHScale |
| 9831 | || w.mLastVScale != w.mVScale |
| 9832 | || w.mLastHidden) { |
| 9833 | displayed = true; |
| 9834 | w.mLastAlpha = w.mShownAlpha; |
| 9835 | w.mLastLayer = w.mAnimLayer; |
| 9836 | w.mLastDsDx = w.mDsDx; |
| 9837 | w.mLastDtDx = w.mDtDx; |
| 9838 | w.mLastDsDy = w.mDsDy; |
| 9839 | w.mLastDtDy = w.mDtDy; |
| 9840 | w.mLastHScale = w.mHScale; |
| 9841 | w.mLastVScale = w.mVScale; |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9842 | if (SHOW_TRANSACTIONS) logSurface(w, |
| 9843 | "alpha=" + w.mShownAlpha + " layer=" + w.mAnimLayer |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 9844 | + " matrix=[" + (w.mDsDx*w.mHScale) |
| 9845 | + "," + (w.mDtDx*w.mVScale) |
| 9846 | + "][" + (w.mDsDy*w.mHScale) |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9847 | + "," + (w.mDtDy*w.mVScale) + "]", null); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9848 | if (w.mSurface != null) { |
| 9849 | try { |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 9850 | w.mSurfaceAlpha = w.mShownAlpha; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9851 | w.mSurface.setAlpha(w.mShownAlpha); |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 9852 | w.mSurfaceLayer = w.mAnimLayer; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9853 | w.mSurface.setLayer(w.mAnimLayer); |
| 9854 | w.mSurface.setMatrix( |
| 9855 | w.mDsDx*w.mHScale, w.mDtDx*w.mVScale, |
| 9856 | w.mDsDy*w.mHScale, w.mDtDy*w.mVScale); |
| 9857 | } catch (RuntimeException e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9858 | Slog.w(TAG, "Error updating surface in " + w, e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9859 | if (!recoveringMemory) { |
| 9860 | reclaimSomeSurfaceMemoryLocked(w, "update"); |
| 9861 | } |
| 9862 | } |
| 9863 | } |
| 9864 | |
| 9865 | if (w.mLastHidden && !w.mDrawPending |
| 9866 | && !w.mCommitDrawPending |
| 9867 | && !w.mReadyToShow) { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9868 | if (SHOW_TRANSACTIONS) logSurface(w, |
| 9869 | "SHOW (performLayout)", null); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9870 | if (DEBUG_VISIBILITY) Slog.v(TAG, "Showing " + w |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9871 | + " during relayout"); |
| 9872 | if (showSurfaceRobustlyLocked(w)) { |
| 9873 | w.mHasDrawn = true; |
| 9874 | w.mLastHidden = false; |
| 9875 | } else { |
| 9876 | w.mOrientationChanging = false; |
| 9877 | } |
| 9878 | } |
| 9879 | if (w.mSurface != null) { |
| 9880 | w.mToken.hasVisible = true; |
| 9881 | } |
| 9882 | } else { |
| 9883 | displayed = true; |
| 9884 | } |
| 9885 | |
| 9886 | if (displayed) { |
| 9887 | if (!covered) { |
| Romain Guy | 980a938 | 2010-01-08 15:06:28 -0800 | [diff] [blame] | 9888 | if (attrs.width == LayoutParams.MATCH_PARENT |
| 9889 | && attrs.height == LayoutParams.MATCH_PARENT) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9890 | covered = true; |
| 9891 | } |
| 9892 | } |
| 9893 | if (w.mOrientationChanging) { |
| 9894 | if (w.mDrawPending || w.mCommitDrawPending) { |
| 9895 | orientationChangeComplete = false; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9896 | if (DEBUG_ORIENTATION) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9897 | "Orientation continue waiting for draw in " + w); |
| 9898 | } else { |
| 9899 | w.mOrientationChanging = false; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9900 | if (DEBUG_ORIENTATION) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9901 | "Orientation change complete in " + w); |
| 9902 | } |
| 9903 | } |
| 9904 | w.mToken.hasVisible = true; |
| 9905 | } |
| 9906 | } else if (w.mOrientationChanging) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9907 | if (DEBUG_ORIENTATION) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9908 | "Orientation change skips hidden " + w); |
| 9909 | w.mOrientationChanging = false; |
| 9910 | } |
| 9911 | |
| 9912 | final boolean canBeSeen = w.isDisplayedLw(); |
| 9913 | |
| 9914 | if (someoneLosingFocus && w == mCurrentFocus && canBeSeen) { |
| 9915 | focusDisplayed = true; |
| 9916 | } |
| 9917 | |
| Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 9918 | final boolean obscuredChanged = w.mObscured != obscured; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9919 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9920 | // Update effect. |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 9921 | if (!(w.mObscured=obscured)) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9922 | if (w.mSurface != null) { |
| 9923 | if ((attrFlags&FLAG_KEEP_SCREEN_ON) != 0) { |
| 9924 | holdScreen = w.mSession; |
| 9925 | } |
| Dianne Hackborn | 9ed4a4b | 2009-03-25 17:10:37 -0700 | [diff] [blame] | 9926 | if (!syswin && w.mAttrs.screenBrightness >= 0 |
| 9927 | && screenBrightness < 0) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9928 | screenBrightness = w.mAttrs.screenBrightness; |
| 9929 | } |
| Mike Lockwood | fb73f79 | 2009-11-20 11:31:18 -0500 | [diff] [blame] | 9930 | if (!syswin && w.mAttrs.buttonBrightness >= 0 |
| 9931 | && buttonBrightness < 0) { |
| 9932 | buttonBrightness = w.mAttrs.buttonBrightness; |
| 9933 | } |
| Mike Lockwood | 46af6a8 | 2010-03-09 08:28:22 -0500 | [diff] [blame] | 9934 | if (canBeSeen |
| 9935 | && (attrs.type == WindowManager.LayoutParams.TYPE_SYSTEM_DIALOG |
| 9936 | || attrs.type == WindowManager.LayoutParams.TYPE_KEYGUARD |
| 9937 | || attrs.type == WindowManager.LayoutParams.TYPE_SYSTEM_ERROR)) { |
| Dianne Hackborn | 9ed4a4b | 2009-03-25 17:10:37 -0700 | [diff] [blame] | 9938 | syswin = true; |
| 9939 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9940 | } |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 9941 | |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 9942 | boolean opaqueDrawn = canBeSeen && w.isOpaqueDrawn(); |
| 9943 | if (opaqueDrawn && w.isFullscreen(dw, dh)) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9944 | // This window completely covers everything behind it, |
| 9945 | // so we want to leave all of them as unblurred (for |
| 9946 | // performance reasons). |
| 9947 | obscured = true; |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 9948 | } else if (opaqueDrawn && w.needsBackgroundFiller(dw, dh)) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9949 | if (SHOW_TRANSACTIONS) Slog.d(TAG, "showing background filler"); |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 9950 | // This window is in compatibility mode, and needs background filler. |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 9951 | obscured = true; |
| 9952 | if (mBackgroundFillerSurface == null) { |
| 9953 | try { |
| 9954 | mBackgroundFillerSurface = new Surface(mFxSession, 0, |
| Mathias Agopian | 5d26c1e | 2010-03-01 16:09:43 -0800 | [diff] [blame] | 9955 | "BackGroundFiller", |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 9956 | 0, dw, dh, |
| 9957 | PixelFormat.OPAQUE, |
| 9958 | Surface.FX_SURFACE_NORMAL); |
| 9959 | } catch (Exception e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9960 | Slog.e(TAG, "Exception creating filler surface", e); |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 9961 | } |
| 9962 | } |
| 9963 | try { |
| 9964 | mBackgroundFillerSurface.setPosition(0, 0); |
| 9965 | mBackgroundFillerSurface.setSize(dw, dh); |
| 9966 | // Using the same layer as Dim because they will never be shown at the |
| 9967 | // same time. |
| 9968 | mBackgroundFillerSurface.setLayer(w.mAnimLayer - 1); |
| 9969 | mBackgroundFillerSurface.show(); |
| 9970 | } catch (RuntimeException e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9971 | Slog.e(TAG, "Exception showing filler surface"); |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 9972 | } |
| 9973 | backgroundFillerShown = true; |
| 9974 | mBackgroundFillerShown = true; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9975 | } else if (canBeSeen && !obscured && |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9976 | (attrFlags&FLAG_BLUR_BEHIND|FLAG_DIM_BEHIND) != 0) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9977 | if (localLOGV) Slog.v(TAG, "Win " + w |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9978 | + ": blurring=" + blurring |
| 9979 | + " obscured=" + obscured |
| 9980 | + " displayed=" + displayed); |
| 9981 | if ((attrFlags&FLAG_DIM_BEHIND) != 0) { |
| 9982 | if (!dimming) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9983 | //Slog.i(TAG, "DIM BEHIND: " + w); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9984 | dimming = true; |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 9985 | if (mDimAnimator == null) { |
| 9986 | mDimAnimator = new DimAnimator(mFxSession); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9987 | } |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 9988 | mDimAnimator.show(dw, dh); |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 9989 | mDimAnimator.updateParameters(w, currentTime); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9990 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9991 | } |
| 9992 | if ((attrFlags&FLAG_BLUR_BEHIND) != 0) { |
| 9993 | if (!blurring) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9994 | //Slog.i(TAG, "BLUR BEHIND: " + w); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9995 | blurring = true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9996 | if (mBlurSurface == null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9997 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR " |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9998 | + mBlurSurface + ": CREATE"); |
| 9999 | try { |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10000 | mBlurSurface = new Surface(mFxSession, 0, |
| Mathias Agopian | 5d26c1e | 2010-03-01 16:09:43 -0800 | [diff] [blame] | 10001 | "BlurSurface", |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10002 | -1, 16, 16, |
| 10003 | PixelFormat.OPAQUE, |
| 10004 | Surface.FX_SURFACE_BLUR); |
| 10005 | } catch (Exception e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10006 | Slog.e(TAG, "Exception creating Blur surface", e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10007 | } |
| 10008 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10009 | if (mBlurSurface != null) { |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 10010 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR " |
| 10011 | + mBlurSurface + ": pos=(0,0) (" + |
| 10012 | dw + "x" + dh + "), layer=" + (w.mAnimLayer-1)); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10013 | mBlurSurface.setPosition(0, 0); |
| 10014 | mBlurSurface.setSize(dw, dh); |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 10015 | mBlurSurface.setLayer(w.mAnimLayer-2); |
| 10016 | if (!mBlurShown) { |
| 10017 | try { |
| 10018 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR " |
| 10019 | + mBlurSurface + ": SHOW"); |
| 10020 | mBlurSurface.show(); |
| 10021 | } catch (RuntimeException e) { |
| 10022 | Slog.w(TAG, "Failure showing blur surface", e); |
| 10023 | } |
| 10024 | mBlurShown = true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10025 | } |
| 10026 | } |
| 10027 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10028 | } |
| 10029 | } |
| 10030 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10031 | |
| Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 10032 | if (obscuredChanged && mWallpaperTarget == w) { |
| 10033 | // This is the wallpaper target and its obscured state |
| 10034 | // changed... make sure the current wallaper's visibility |
| 10035 | // has been updated accordingly. |
| 10036 | updateWallpaperVisibilityLocked(); |
| 10037 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10038 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10039 | |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 10040 | if (backgroundFillerShown == false && mBackgroundFillerShown) { |
| 10041 | mBackgroundFillerShown = false; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10042 | if (SHOW_TRANSACTIONS) Slog.d(TAG, "hiding background filler"); |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 10043 | try { |
| 10044 | mBackgroundFillerSurface.hide(); |
| 10045 | } catch (RuntimeException e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10046 | Slog.e(TAG, "Exception hiding filler surface", e); |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 10047 | } |
| 10048 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10049 | |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 10050 | if (mDimAnimator != null && mDimAnimator.mDimShown) { |
| Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 10051 | animating |= mDimAnimator.updateSurface(dimming, currentTime, |
| 10052 | mDisplayFrozen || !mPolicy.isScreenOn()); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10053 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10054 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10055 | if (!blurring && mBlurShown) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10056 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR " + mBlurSurface |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10057 | + ": HIDE"); |
| 10058 | try { |
| 10059 | mBlurSurface.hide(); |
| 10060 | } catch (IllegalArgumentException e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10061 | Slog.w(TAG, "Illegal argument exception hiding blur surface"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10062 | } |
| 10063 | mBlurShown = false; |
| 10064 | } |
| 10065 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10066 | if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10067 | } catch (RuntimeException e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10068 | Slog.e(TAG, "Unhandled exception in Window Manager", e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10069 | } |
| 10070 | |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 10071 | mInputMonitor.updateInputWindowsLw(); |
| 10072 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10073 | Surface.closeTransaction(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10074 | |
| Dianne Hackborn | b9fb170 | 2010-08-23 16:49:02 -0700 | [diff] [blame] | 10075 | if (mWatermark != null) { |
| 10076 | mWatermark.drawIfNeeded(); |
| 10077 | } |
| 10078 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10079 | if (DEBUG_ORIENTATION && mDisplayFrozen) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10080 | "With display frozen, orientationChangeComplete=" |
| 10081 | + orientationChangeComplete); |
| 10082 | if (orientationChangeComplete) { |
| 10083 | if (mWindowsFreezingScreen) { |
| 10084 | mWindowsFreezingScreen = false; |
| 10085 | mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT); |
| 10086 | } |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 10087 | stopFreezingDisplayLocked(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10088 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10089 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10090 | i = mResizingWindows.size(); |
| 10091 | if (i > 0) { |
| 10092 | do { |
| 10093 | i--; |
| 10094 | WindowState win = mResizingWindows.get(i); |
| 10095 | try { |
| Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 10096 | if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG, |
| 10097 | "Reporting new frame to " + win + ": " + win.mFrame); |
| Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 10098 | int diff = 0; |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 10099 | boolean configChanged = |
| 10100 | win.mConfiguration != mCurConfiguration |
| 10101 | && (win.mConfiguration == null |
| Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 10102 | || (diff=mCurConfiguration.diff(win.mConfiguration)) != 0); |
| 10103 | if ((DEBUG_RESIZE || DEBUG_ORIENTATION || DEBUG_CONFIGURATION) |
| 10104 | && configChanged) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10105 | Slog.i(TAG, "Sending new config to window " + win + ": " |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 10106 | + win.mFrame.width() + "x" + win.mFrame.height() |
| Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 10107 | + " / " + mCurConfiguration + " / 0x" |
| 10108 | + Integer.toHexString(diff)); |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 10109 | } |
| Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 10110 | win.mConfiguration = mCurConfiguration; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10111 | win.mClient.resized(win.mFrame.width(), |
| 10112 | win.mFrame.height(), win.mLastContentInsets, |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 10113 | win.mLastVisibleInsets, win.mDrawPending, |
| 10114 | configChanged ? win.mConfiguration : null); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10115 | win.mContentInsetsChanged = false; |
| 10116 | win.mVisibleInsetsChanged = false; |
| Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 10117 | win.mSurfaceResized = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10118 | } catch (RemoteException e) { |
| 10119 | win.mOrientationChanging = false; |
| 10120 | } |
| 10121 | } while (i > 0); |
| 10122 | mResizingWindows.clear(); |
| 10123 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10124 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10125 | // Destroy the surface of any windows that are no longer visible. |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 10126 | boolean wallpaperDestroyed = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10127 | i = mDestroySurface.size(); |
| 10128 | if (i > 0) { |
| 10129 | do { |
| 10130 | i--; |
| 10131 | WindowState win = mDestroySurface.get(i); |
| 10132 | win.mDestroying = false; |
| 10133 | if (mInputMethodWindow == win) { |
| 10134 | mInputMethodWindow = null; |
| 10135 | } |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 10136 | if (win == mWallpaperTarget) { |
| 10137 | wallpaperDestroyed = true; |
| 10138 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10139 | win.destroySurfaceLocked(); |
| 10140 | } while (i > 0); |
| 10141 | mDestroySurface.clear(); |
| 10142 | } |
| 10143 | |
| 10144 | // Time to remove any exiting tokens? |
| 10145 | for (i=mExitingTokens.size()-1; i>=0; i--) { |
| 10146 | WindowToken token = mExitingTokens.get(i); |
| 10147 | if (!token.hasVisible) { |
| 10148 | mExitingTokens.remove(i); |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 10149 | if (token.windowType == TYPE_WALLPAPER) { |
| 10150 | mWallpaperTokens.remove(token); |
| 10151 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10152 | } |
| 10153 | } |
| 10154 | |
| 10155 | // Time to remove any exiting applications? |
| 10156 | for (i=mExitingAppTokens.size()-1; i>=0; i--) { |
| 10157 | AppWindowToken token = mExitingAppTokens.get(i); |
| 10158 | if (!token.hasVisible && !mClosingApps.contains(token)) { |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 10159 | // Make sure there is no animation running on this token, |
| 10160 | // so any windows associated with it will be removed as |
| 10161 | // soon as their animations are complete |
| 10162 | token.animation = null; |
| 10163 | token.animating = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10164 | mAppTokens.remove(token); |
| 10165 | mExitingAppTokens.remove(i); |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10166 | if (mLastEnterAnimToken == token) { |
| 10167 | mLastEnterAnimToken = null; |
| 10168 | mLastEnterAnimParams = null; |
| 10169 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10170 | } |
| 10171 | } |
| 10172 | |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 10173 | boolean needRelayout = false; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10174 | |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 10175 | if (!animating && mAppTransitionRunning) { |
| 10176 | // We have finished the animation of an app transition. To do |
| 10177 | // this, we have delayed a lot of operations like showing and |
| 10178 | // hiding apps, moving apps in Z-order, etc. The app token list |
| 10179 | // reflects the correct Z-order, but the window list may now |
| 10180 | // be out of sync with it. So here we will just rebuild the |
| 10181 | // entire app window list. Fun! |
| 10182 | mAppTransitionRunning = false; |
| 10183 | needRelayout = true; |
| 10184 | rebuildAppWindowListLocked(); |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 10185 | assignLayersLocked(); |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 10186 | // Clear information about apps that were moving. |
| 10187 | mToBottomApps.clear(); |
| 10188 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10189 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10190 | if (focusDisplayed) { |
| 10191 | mH.sendEmptyMessage(H.REPORT_LOSING_FOCUS); |
| 10192 | } |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 10193 | if (wallpaperDestroyed) { |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 10194 | needRelayout = adjustWallpaperWindowsLocked() != 0; |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 10195 | } |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 10196 | if (needRelayout) { |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 10197 | requestAnimationLocked(0); |
| 10198 | } else if (animating) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10199 | requestAnimationLocked(currentTime+(1000/60)-SystemClock.uptimeMillis()); |
| 10200 | } |
| Jeff Brown | eb857f1 | 2010-07-16 10:06:33 -0700 | [diff] [blame] | 10201 | |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 10202 | mInputMonitor.updateInputWindowsLw(); |
| Jeff Brown | eb857f1 | 2010-07-16 10:06:33 -0700 | [diff] [blame] | 10203 | |
| Jeff Brown | 8e03b75 | 2010-06-13 19:16:55 -0700 | [diff] [blame] | 10204 | setHoldScreenLocked(holdScreen != null); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10205 | if (screenBrightness < 0 || screenBrightness > 1.0f) { |
| 10206 | mPowerManager.setScreenBrightnessOverride(-1); |
| 10207 | } else { |
| 10208 | mPowerManager.setScreenBrightnessOverride((int) |
| 10209 | (screenBrightness * Power.BRIGHTNESS_ON)); |
| 10210 | } |
| Mike Lockwood | fb73f79 | 2009-11-20 11:31:18 -0500 | [diff] [blame] | 10211 | if (buttonBrightness < 0 || buttonBrightness > 1.0f) { |
| 10212 | mPowerManager.setButtonBrightnessOverride(-1); |
| 10213 | } else { |
| 10214 | mPowerManager.setButtonBrightnessOverride((int) |
| 10215 | (buttonBrightness * Power.BRIGHTNESS_ON)); |
| 10216 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10217 | if (holdScreen != mHoldingScreenOn) { |
| 10218 | mHoldingScreenOn = holdScreen; |
| 10219 | Message m = mH.obtainMessage(H.HOLD_SCREEN_CHANGED, holdScreen); |
| 10220 | mH.sendMessage(m); |
| 10221 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10222 | |
| Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 10223 | if (mTurnOnScreen) { |
| Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 10224 | if (DEBUG_VISIBILITY) Slog.v(TAG, "Turning screen on after layout!"); |
| Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 10225 | mPowerManager.userActivity(SystemClock.uptimeMillis(), false, |
| 10226 | LocalPowerManager.BUTTON_EVENT, true); |
| 10227 | mTurnOnScreen = false; |
| 10228 | } |
| Dianne Hackborn | f3bea9c | 2009-12-09 18:26:21 -0800 | [diff] [blame] | 10229 | |
| 10230 | // Check to see if we are now in a state where the screen should |
| 10231 | // be enabled, because the window obscured flags have changed. |
| 10232 | enableScreenIfNeededLocked(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10233 | } |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 10234 | |
| 10235 | /** |
| 10236 | * Must be called with the main window manager lock held. |
| 10237 | */ |
| 10238 | void setHoldScreenLocked(boolean holding) { |
| 10239 | boolean state = mHoldingScreenWakeLock.isHeld(); |
| 10240 | if (holding != state) { |
| 10241 | if (holding) { |
| 10242 | mHoldingScreenWakeLock.acquire(); |
| 10243 | } else { |
| 10244 | mPolicy.screenOnStoppedLw(); |
| 10245 | mHoldingScreenWakeLock.release(); |
| 10246 | } |
| 10247 | } |
| 10248 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10249 | |
| 10250 | void requestAnimationLocked(long delay) { |
| 10251 | if (!mAnimationPending) { |
| 10252 | mAnimationPending = true; |
| 10253 | mH.sendMessageDelayed(mH.obtainMessage(H.ANIMATE), delay); |
| 10254 | } |
| 10255 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10256 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10257 | /** |
| 10258 | * Have the surface flinger show a surface, robustly dealing with |
| 10259 | * error conditions. In particular, if there is not enough memory |
| 10260 | * to show the surface, then we will try to get rid of other surfaces |
| 10261 | * in order to succeed. |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10262 | * |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10263 | * @return Returns true if the surface was successfully shown. |
| 10264 | */ |
| 10265 | boolean showSurfaceRobustlyLocked(WindowState win) { |
| 10266 | try { |
| 10267 | if (win.mSurface != null) { |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 10268 | win.mSurfaceShown = true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10269 | win.mSurface.show(); |
| Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 10270 | if (win.mTurnOnScreen) { |
| Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 10271 | if (DEBUG_VISIBILITY) Slog.v(TAG, |
| 10272 | "Show surface turning screen on: " + win); |
| Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 10273 | win.mTurnOnScreen = false; |
| 10274 | mTurnOnScreen = true; |
| 10275 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10276 | } |
| 10277 | return true; |
| 10278 | } catch (RuntimeException e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10279 | 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] | 10280 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10281 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10282 | reclaimSomeSurfaceMemoryLocked(win, "show"); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10283 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10284 | return false; |
| 10285 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10286 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10287 | void reclaimSomeSurfaceMemoryLocked(WindowState win, String operation) { |
| 10288 | final Surface surface = win.mSurface; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10289 | |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10290 | EventLog.writeEvent(EventLogTags.WM_NO_SURFACE_MEMORY, win.toString(), |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10291 | win.mSession.mPid, operation); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10292 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10293 | if (mForceRemoves == null) { |
| 10294 | mForceRemoves = new ArrayList<WindowState>(); |
| 10295 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10296 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10297 | long callingIdentity = Binder.clearCallingIdentity(); |
| 10298 | try { |
| 10299 | // There was some problem... first, do a sanity check of the |
| 10300 | // window list to make sure we haven't left any dangling surfaces |
| 10301 | // around. |
| 10302 | int N = mWindows.size(); |
| 10303 | boolean leakedSurface = false; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10304 | 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] | 10305 | for (int i=0; i<N; i++) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 10306 | WindowState ws = mWindows.get(i); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10307 | if (ws.mSurface != null) { |
| 10308 | if (!mSessions.contains(ws.mSession)) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10309 | Slog.w(TAG, "LEAKED SURFACE (session doesn't exist): " |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10310 | + ws + " surface=" + ws.mSurface |
| 10311 | + " token=" + win.mToken |
| 10312 | + " pid=" + ws.mSession.mPid |
| 10313 | + " uid=" + ws.mSession.mUid); |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 10314 | ws.mSurface.destroy(); |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 10315 | ws.mSurfaceShown = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10316 | ws.mSurface = null; |
| 10317 | mForceRemoves.add(ws); |
| 10318 | i--; |
| 10319 | N--; |
| 10320 | leakedSurface = true; |
| 10321 | } else if (win.mAppToken != null && win.mAppToken.clientHidden) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10322 | Slog.w(TAG, "LEAKED SURFACE (app token hidden): " |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10323 | + ws + " surface=" + ws.mSurface |
| 10324 | + " token=" + win.mAppToken); |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 10325 | ws.mSurface.destroy(); |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 10326 | ws.mSurfaceShown = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10327 | ws.mSurface = null; |
| 10328 | leakedSurface = true; |
| 10329 | } |
| 10330 | } |
| 10331 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10332 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10333 | boolean killedApps = false; |
| 10334 | if (!leakedSurface) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10335 | Slog.w(TAG, "No leaked surfaces; killing applicatons!"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10336 | SparseIntArray pidCandidates = new SparseIntArray(); |
| 10337 | for (int i=0; i<N; i++) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 10338 | WindowState ws = mWindows.get(i); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10339 | if (ws.mSurface != null) { |
| 10340 | pidCandidates.append(ws.mSession.mPid, ws.mSession.mPid); |
| 10341 | } |
| 10342 | } |
| 10343 | if (pidCandidates.size() > 0) { |
| 10344 | int[] pids = new int[pidCandidates.size()]; |
| 10345 | for (int i=0; i<pids.length; i++) { |
| 10346 | pids[i] = pidCandidates.keyAt(i); |
| 10347 | } |
| 10348 | try { |
| Suchi Amalapurapu | e99bb5f | 2010-03-19 14:36:49 -0700 | [diff] [blame] | 10349 | if (mActivityManager.killPids(pids, "Free memory")) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10350 | killedApps = true; |
| 10351 | } |
| 10352 | } catch (RemoteException e) { |
| 10353 | } |
| 10354 | } |
| 10355 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10356 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10357 | if (leakedSurface || killedApps) { |
| 10358 | // We managed to reclaim some memory, so get rid of the trouble |
| 10359 | // surface and ask the app to request another one. |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10360 | 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] | 10361 | if (surface != null) { |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 10362 | surface.destroy(); |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 10363 | win.mSurfaceShown = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10364 | win.mSurface = null; |
| 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 | try { |
| 10368 | win.mClient.dispatchGetNewSurface(); |
| 10369 | } catch (RemoteException e) { |
| 10370 | } |
| 10371 | } |
| 10372 | } finally { |
| 10373 | Binder.restoreCallingIdentity(callingIdentity); |
| 10374 | } |
| 10375 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10376 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10377 | private boolean updateFocusedWindowLocked(int mode) { |
| 10378 | WindowState newFocus = computeFocusedWindowLocked(); |
| 10379 | if (mCurrentFocus != newFocus) { |
| 10380 | // This check makes sure that we don't already have the focus |
| 10381 | // change message pending. |
| 10382 | mH.removeMessages(H.REPORT_FOCUS_CHANGE); |
| 10383 | mH.sendEmptyMessage(H.REPORT_FOCUS_CHANGE); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10384 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10385 | TAG, "Changing focus from " + mCurrentFocus + " to " + newFocus); |
| 10386 | final WindowState oldFocus = mCurrentFocus; |
| 10387 | mCurrentFocus = newFocus; |
| 10388 | mLosingFocus.remove(newFocus); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10389 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10390 | final WindowState imWindow = mInputMethodWindow; |
| 10391 | if (newFocus != imWindow && oldFocus != imWindow) { |
| The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 10392 | if (moveInputMethodWindowsIfNeededLocked( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10393 | mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS && |
| The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 10394 | mode != UPDATE_FOCUS_WILL_PLACE_SURFACES)) { |
| 10395 | mLayoutNeeded = true; |
| 10396 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10397 | if (mode == UPDATE_FOCUS_PLACING_SURFACES) { |
| 10398 | performLayoutLockedInner(); |
| The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 10399 | } else if (mode == UPDATE_FOCUS_WILL_PLACE_SURFACES) { |
| 10400 | // Client will do the layout, but we need to assign layers |
| 10401 | // for handleNewWindowLocked() below. |
| 10402 | assignLayersLocked(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10403 | } |
| 10404 | } |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 10405 | |
| 10406 | if (mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS) { |
| 10407 | // If we defer assigning layers, then the caller is responsible for |
| 10408 | // doing this part. |
| 10409 | finishUpdateFocusedWindowAfterAssignLayersLocked(); |
| The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 10410 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10411 | return true; |
| 10412 | } |
| 10413 | return false; |
| 10414 | } |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 10415 | |
| 10416 | private void finishUpdateFocusedWindowAfterAssignLayersLocked() { |
| Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 10417 | mInputMonitor.setInputFocusLw(mCurrentFocus); |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 10418 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10419 | |
| 10420 | private WindowState computeFocusedWindowLocked() { |
| 10421 | WindowState result = null; |
| 10422 | WindowState win; |
| 10423 | |
| 10424 | int i = mWindows.size() - 1; |
| 10425 | int nextAppIndex = mAppTokens.size()-1; |
| 10426 | WindowToken nextApp = nextAppIndex >= 0 |
| 10427 | ? mAppTokens.get(nextAppIndex) : null; |
| 10428 | |
| 10429 | while (i >= 0) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 10430 | win = mWindows.get(i); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10431 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10432 | if (localLOGV || DEBUG_FOCUS) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10433 | TAG, "Looking for focus: " + i |
| 10434 | + " = " + win |
| 10435 | + ", flags=" + win.mAttrs.flags |
| 10436 | + ", canReceive=" + win.canReceiveKeys()); |
| 10437 | |
| 10438 | AppWindowToken thisApp = win.mAppToken; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10439 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10440 | // If this window's application has been removed, just skip it. |
| 10441 | if (thisApp != null && thisApp.removed) { |
| 10442 | i--; |
| 10443 | continue; |
| 10444 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10445 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10446 | // If there is a focused app, don't allow focus to go to any |
| 10447 | // windows below it. If this is an application window, step |
| 10448 | // through the app tokens until we find its app. |
| 10449 | if (thisApp != null && nextApp != null && thisApp != nextApp |
| 10450 | && win.mAttrs.type != TYPE_APPLICATION_STARTING) { |
| 10451 | int origAppIndex = nextAppIndex; |
| 10452 | while (nextAppIndex > 0) { |
| 10453 | if (nextApp == mFocusedApp) { |
| 10454 | // Whoops, we are below the focused app... no focus |
| 10455 | // for you! |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10456 | if (localLOGV || DEBUG_FOCUS) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10457 | TAG, "Reached focused app: " + mFocusedApp); |
| 10458 | return null; |
| 10459 | } |
| 10460 | nextAppIndex--; |
| 10461 | nextApp = mAppTokens.get(nextAppIndex); |
| 10462 | if (nextApp == thisApp) { |
| 10463 | break; |
| 10464 | } |
| 10465 | } |
| 10466 | if (thisApp != nextApp) { |
| 10467 | // Uh oh, the app token doesn't exist! This shouldn't |
| 10468 | // happen, but if it does we can get totally hosed... |
| 10469 | // so restart at the original app. |
| 10470 | nextAppIndex = origAppIndex; |
| 10471 | nextApp = mAppTokens.get(nextAppIndex); |
| 10472 | } |
| 10473 | } |
| 10474 | |
| 10475 | // Dispatch to this window if it is wants key events. |
| 10476 | if (win.canReceiveKeys()) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10477 | if (DEBUG_FOCUS) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10478 | TAG, "Found focus @ " + i + " = " + win); |
| 10479 | result = win; |
| 10480 | break; |
| 10481 | } |
| 10482 | |
| 10483 | i--; |
| 10484 | } |
| 10485 | |
| 10486 | return result; |
| 10487 | } |
| 10488 | |
| 10489 | private void startFreezingDisplayLocked() { |
| 10490 | if (mDisplayFrozen) { |
| 10491 | return; |
| 10492 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10493 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10494 | mScreenFrozenLock.acquire(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10495 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10496 | long now = SystemClock.uptimeMillis(); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10497 | //Slog.i(TAG, "Freezing, gc pending: " + mFreezeGcPending + ", now " + now); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10498 | if (mFreezeGcPending != 0) { |
| 10499 | if (now > (mFreezeGcPending+1000)) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10500 | //Slog.i(TAG, "Gc! " + now + " > " + (mFreezeGcPending+1000)); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10501 | mH.removeMessages(H.FORCE_GC); |
| 10502 | Runtime.getRuntime().gc(); |
| 10503 | mFreezeGcPending = now; |
| 10504 | } |
| 10505 | } else { |
| 10506 | mFreezeGcPending = now; |
| 10507 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10508 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10509 | mDisplayFrozen = true; |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 10510 | |
| Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 10511 | mInputMonitor.freezeInputDispatchingLw(); |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 10512 | |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 10513 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
| 10514 | mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10515 | mNextAppTransitionPackage = null; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10516 | mAppTransitionReady = true; |
| 10517 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10518 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10519 | if (PROFILE_ORIENTATION) { |
| 10520 | File file = new File("/data/system/frozen"); |
| 10521 | Debug.startMethodTracing(file.toString(), 8 * 1024 * 1024); |
| 10522 | } |
| 10523 | Surface.freezeDisplay(0); |
| 10524 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10525 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10526 | private void stopFreezingDisplayLocked() { |
| 10527 | if (!mDisplayFrozen) { |
| 10528 | return; |
| 10529 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10530 | |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 10531 | if (mWaitingForConfig || mAppsFreezingScreen > 0 || mWindowsFreezingScreen) { |
| 10532 | return; |
| 10533 | } |
| 10534 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10535 | mDisplayFrozen = false; |
| 10536 | mH.removeMessages(H.APP_FREEZE_TIMEOUT); |
| 10537 | if (PROFILE_ORIENTATION) { |
| 10538 | Debug.stopMethodTracing(); |
| 10539 | } |
| 10540 | Surface.unfreezeDisplay(0); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10541 | |
| Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 10542 | mInputMonitor.thawInputDispatchingLw(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10543 | |
| Christopher Tate | b696aee | 2010-04-02 19:08:30 -0700 | [diff] [blame] | 10544 | // While the display is frozen we don't re-compute the orientation |
| 10545 | // to avoid inconsistent states. However, something interesting |
| 10546 | // could have actually changed during that time so re-evaluate it |
| 10547 | // now to catch that. |
| 10548 | if (updateOrientationFromAppTokensLocked()) { |
| 10549 | mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION); |
| 10550 | } |
| 10551 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10552 | // A little kludge: a lot could have happened while the |
| 10553 | // display was frozen, so now that we are coming back we |
| 10554 | // do a gc so that any remote references the system |
| 10555 | // processes holds on others can be released if they are |
| 10556 | // no longer needed. |
| 10557 | mH.removeMessages(H.FORCE_GC); |
| 10558 | mH.sendMessageDelayed(mH.obtainMessage(H.FORCE_GC), |
| 10559 | 2000); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10560 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10561 | mScreenFrozenLock.release(); |
| 10562 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10563 | |
| Dianne Hackborn | b9fb170 | 2010-08-23 16:49:02 -0700 | [diff] [blame] | 10564 | static int getPropertyInt(String[] tokens, int index, int defUnits, int defDps, |
| 10565 | DisplayMetrics dm) { |
| 10566 | if (index < tokens.length) { |
| 10567 | String str = tokens[index]; |
| 10568 | if (str != null && str.length() > 0) { |
| 10569 | try { |
| 10570 | int val = Integer.parseInt(str); |
| 10571 | return val; |
| 10572 | } catch (Exception e) { |
| 10573 | } |
| 10574 | } |
| Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 10575 | } |
| 10576 | if (defUnits == TypedValue.COMPLEX_UNIT_PX) { |
| 10577 | return defDps; |
| 10578 | } |
| 10579 | int val = (int)TypedValue.applyDimension(defUnits, defDps, dm); |
| 10580 | return val; |
| 10581 | } |
| 10582 | |
| 10583 | class Watermark { |
| Dianne Hackborn | b9fb170 | 2010-08-23 16:49:02 -0700 | [diff] [blame] | 10584 | final String[] mTokens; |
| 10585 | final String mText; |
| 10586 | final Paint mTextPaint; |
| 10587 | final int mTextWidth; |
| 10588 | final int mTextHeight; |
| 10589 | final int mTextAscent; |
| 10590 | final int mTextDescent; |
| 10591 | final int mDeltaX; |
| 10592 | final int mDeltaY; |
| Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 10593 | |
| Dianne Hackborn | b9fb170 | 2010-08-23 16:49:02 -0700 | [diff] [blame] | 10594 | Surface mSurface; |
| 10595 | int mLastDW; |
| 10596 | int mLastDH; |
| 10597 | boolean mDrawNeeded; |
| 10598 | |
| 10599 | Watermark(SurfaceSession session, String[] tokens) { |
| Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 10600 | final DisplayMetrics dm = new DisplayMetrics(); |
| 10601 | mDisplay.getMetrics(dm); |
| 10602 | |
| Dianne Hackborn | b9fb170 | 2010-08-23 16:49:02 -0700 | [diff] [blame] | 10603 | if (false) { |
| 10604 | Log.i(TAG, "*********************** WATERMARK"); |
| 10605 | for (int i=0; i<tokens.length; i++) { |
| 10606 | Log.i(TAG, " TOKEN #" + i + ": " + tokens[i]); |
| 10607 | } |
| 10608 | } |
| Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 10609 | |
| Dianne Hackborn | b9fb170 | 2010-08-23 16:49:02 -0700 | [diff] [blame] | 10610 | mTokens = tokens; |
| Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 10611 | |
| Dianne Hackborn | b9fb170 | 2010-08-23 16:49:02 -0700 | [diff] [blame] | 10612 | StringBuilder builder = new StringBuilder(32); |
| 10613 | int len = mTokens[0].length(); |
| 10614 | len = len & ~1; |
| 10615 | for (int i=0; i<len; i+=2) { |
| 10616 | int c1 = mTokens[0].charAt(i); |
| 10617 | int c2 = mTokens[0].charAt(i+1); |
| 10618 | if (c1 >= 'a' && c1 <= 'f') c1 = c1 - 'a' + 10; |
| 10619 | else if (c1 >= 'A' && c1 <= 'F') c1 = c1 - 'A' + 10; |
| 10620 | else c1 -= '0'; |
| 10621 | if (c2 >= 'a' && c2 <= 'f') c2 = c2 - 'a' + 10; |
| 10622 | else if (c2 >= 'A' && c2 <= 'F') c2 = c2 - 'A' + 10; |
| 10623 | else c2 -= '0'; |
| 10624 | builder.append((char)(255-((c1*16)+c2))); |
| 10625 | } |
| 10626 | mText = builder.toString(); |
| 10627 | if (false) { |
| 10628 | Log.i(TAG, "Final text: " + mText); |
| 10629 | } |
| 10630 | |
| 10631 | int fontSize = getPropertyInt(tokens, 1, |
| 10632 | TypedValue.COMPLEX_UNIT_DIP, 20, dm); |
| 10633 | |
| 10634 | mTextPaint = new Paint(Paint.ANTI_ALIAS_FLAG); |
| 10635 | mTextPaint.setTextSize(fontSize); |
| 10636 | mTextPaint.setTypeface(Typeface.create(Typeface.SANS_SERIF, Typeface.BOLD)); |
| 10637 | |
| 10638 | FontMetricsInt fm = mTextPaint.getFontMetricsInt(); |
| 10639 | mTextWidth = (int)mTextPaint.measureText(mText); |
| 10640 | mTextAscent = fm.ascent; |
| 10641 | mTextDescent = fm.descent; |
| 10642 | mTextHeight = fm.descent - fm.ascent; |
| 10643 | |
| 10644 | mDeltaX = getPropertyInt(tokens, 2, |
| 10645 | TypedValue.COMPLEX_UNIT_PX, mTextWidth*2, dm); |
| 10646 | mDeltaY = getPropertyInt(tokens, 3, |
| 10647 | TypedValue.COMPLEX_UNIT_PX, mTextHeight*3, dm); |
| 10648 | int shadowColor = getPropertyInt(tokens, 4, |
| 10649 | TypedValue.COMPLEX_UNIT_PX, 0xb0000000, dm); |
| 10650 | int color = getPropertyInt(tokens, 5, |
| 10651 | TypedValue.COMPLEX_UNIT_PX, 0x60ffffff, dm); |
| 10652 | int shadowRadius = getPropertyInt(tokens, 6, |
| 10653 | TypedValue.COMPLEX_UNIT_PX, 7, dm); |
| 10654 | int shadowDx = getPropertyInt(tokens, 8, |
| 10655 | TypedValue.COMPLEX_UNIT_PX, 0, dm); |
| 10656 | int shadowDy = getPropertyInt(tokens, 9, |
| 10657 | TypedValue.COMPLEX_UNIT_PX, 0, dm); |
| 10658 | |
| 10659 | mTextPaint.setColor(color); |
| 10660 | mTextPaint.setShadowLayer(shadowRadius, shadowDx, shadowDy, shadowColor); |
| Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 10661 | |
| 10662 | try { |
| 10663 | mSurface = new Surface(session, 0, |
| Dianne Hackborn | b9fb170 | 2010-08-23 16:49:02 -0700 | [diff] [blame] | 10664 | "WatermarkSurface", -1, 1, 1, PixelFormat.TRANSLUCENT, 0); |
| Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 10665 | mSurface.setLayer(TYPE_LAYER_MULTIPLIER*100); |
| Dianne Hackborn | b9fb170 | 2010-08-23 16:49:02 -0700 | [diff] [blame] | 10666 | mSurface.setPosition(0, 0); |
| Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 10667 | mSurface.show(); |
| 10668 | } catch (OutOfResourcesException e) { |
| 10669 | } |
| 10670 | } |
| 10671 | |
| 10672 | void positionSurface(int dw, int dh) { |
| Dianne Hackborn | b9fb170 | 2010-08-23 16:49:02 -0700 | [diff] [blame] | 10673 | if (mLastDW != dw || mLastDH != dh) { |
| 10674 | mLastDW = dw; |
| 10675 | mLastDH = dh; |
| 10676 | mSurface.setSize(dw, dh); |
| 10677 | mDrawNeeded = true; |
| 10678 | } |
| 10679 | } |
| 10680 | |
| 10681 | void drawIfNeeded() { |
| 10682 | if (mDrawNeeded) { |
| 10683 | final int dw = mLastDW; |
| 10684 | final int dh = mLastDH; |
| 10685 | |
| 10686 | mDrawNeeded = false; |
| 10687 | Rect dirty = new Rect(0, 0, dw, dh); |
| 10688 | Canvas c = null; |
| 10689 | try { |
| 10690 | c = mSurface.lockCanvas(dirty); |
| 10691 | } catch (IllegalArgumentException e) { |
| 10692 | } catch (OutOfResourcesException e) { |
| 10693 | } |
| 10694 | if (c != null) { |
| 10695 | int deltaX = mDeltaX; |
| 10696 | int deltaY = mDeltaY; |
| 10697 | |
| 10698 | // deltaX shouldn't be close to a round fraction of our |
| 10699 | // x step, or else things will line up too much. |
| 10700 | int div = (dw+mTextWidth)/deltaX; |
| 10701 | int rem = (dw+mTextWidth) - (div*deltaX); |
| 10702 | int qdelta = deltaX/4; |
| 10703 | if (rem < qdelta || rem > (deltaX-qdelta)) { |
| 10704 | deltaX += deltaX/3; |
| 10705 | } |
| 10706 | |
| 10707 | int y = -mTextHeight; |
| 10708 | int x = -mTextWidth; |
| 10709 | while (y < (dh+mTextHeight)) { |
| 10710 | c.drawText(mText, x, y, mTextPaint); |
| 10711 | x += deltaX; |
| 10712 | if (x >= dw) { |
| 10713 | x -= (dw+mTextWidth); |
| 10714 | y += deltaY; |
| 10715 | } |
| 10716 | } |
| 10717 | mSurface.unlockCanvasAndPost(c); |
| 10718 | } |
| 10719 | } |
| Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 10720 | } |
| 10721 | } |
| 10722 | |
| 10723 | void createWatermark() { |
| 10724 | if (mWatermark != null) { |
| 10725 | return; |
| 10726 | } |
| 10727 | |
| Dianne Hackborn | b9fb170 | 2010-08-23 16:49:02 -0700 | [diff] [blame] | 10728 | File file = new File("/system/etc/setup.conf"); |
| 10729 | FileInputStream in = null; |
| 10730 | try { |
| 10731 | in = new FileInputStream(file); |
| 10732 | DataInputStream ind = new DataInputStream(in); |
| 10733 | String line = ind.readLine(); |
| 10734 | if (line != null) { |
| 10735 | String[] toks = line.split("%"); |
| 10736 | if (toks != null && toks.length > 0) { |
| 10737 | mWatermark = new Watermark(mFxSession, toks); |
| 10738 | } |
| 10739 | } |
| 10740 | } catch (FileNotFoundException e) { |
| 10741 | } catch (IOException e) { |
| 10742 | } finally { |
| 10743 | if (in != null) { |
| 10744 | try { |
| 10745 | in.close(); |
| 10746 | } catch (IOException e) { |
| 10747 | } |
| 10748 | } |
| Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 10749 | } |
| Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 10750 | } |
| 10751 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10752 | @Override |
| 10753 | public void dump(FileDescriptor fd, PrintWriter pw, String[] args) { |
| 10754 | if (mContext.checkCallingOrSelfPermission("android.permission.DUMP") |
| 10755 | != PackageManager.PERMISSION_GRANTED) { |
| 10756 | pw.println("Permission Denial: can't dump WindowManager from from pid=" |
| 10757 | + Binder.getCallingPid() |
| 10758 | + ", uid=" + Binder.getCallingUid()); |
| 10759 | return; |
| 10760 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10761 | |
| Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 10762 | mInputManager.dump(pw); |
| Dianne Hackborn | a2e9226 | 2010-03-02 17:19:29 -0800 | [diff] [blame] | 10763 | pw.println(" "); |
| 10764 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10765 | synchronized(mWindowMap) { |
| 10766 | pw.println("Current Window Manager state:"); |
| 10767 | for (int i=mWindows.size()-1; i>=0; i--) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 10768 | WindowState w = mWindows.get(i); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10769 | pw.print(" Window #"); pw.print(i); pw.print(' '); |
| 10770 | pw.print(w); pw.println(":"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10771 | w.dump(pw, " "); |
| 10772 | } |
| 10773 | if (mInputMethodDialogs.size() > 0) { |
| 10774 | pw.println(" "); |
| 10775 | pw.println(" Input method dialogs:"); |
| 10776 | for (int i=mInputMethodDialogs.size()-1; i>=0; i--) { |
| 10777 | WindowState w = mInputMethodDialogs.get(i); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10778 | 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] | 10779 | } |
| 10780 | } |
| 10781 | if (mPendingRemove.size() > 0) { |
| 10782 | pw.println(" "); |
| 10783 | pw.println(" Remove pending for:"); |
| 10784 | for (int i=mPendingRemove.size()-1; i>=0; i--) { |
| 10785 | WindowState w = mPendingRemove.get(i); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10786 | pw.print(" Remove #"); pw.print(i); pw.print(' '); |
| 10787 | pw.print(w); pw.println(":"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10788 | w.dump(pw, " "); |
| 10789 | } |
| 10790 | } |
| 10791 | if (mForceRemoves != null && mForceRemoves.size() > 0) { |
| 10792 | pw.println(" "); |
| 10793 | pw.println(" Windows force removing:"); |
| 10794 | for (int i=mForceRemoves.size()-1; i>=0; i--) { |
| 10795 | WindowState w = mForceRemoves.get(i); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10796 | pw.print(" Removing #"); pw.print(i); pw.print(' '); |
| 10797 | pw.print(w); pw.println(":"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10798 | w.dump(pw, " "); |
| 10799 | } |
| 10800 | } |
| 10801 | if (mDestroySurface.size() > 0) { |
| 10802 | pw.println(" "); |
| 10803 | pw.println(" Windows waiting to destroy their surface:"); |
| 10804 | for (int i=mDestroySurface.size()-1; i>=0; i--) { |
| 10805 | WindowState w = mDestroySurface.get(i); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10806 | pw.print(" Destroy #"); pw.print(i); pw.print(' '); |
| 10807 | pw.print(w); pw.println(":"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10808 | w.dump(pw, " "); |
| 10809 | } |
| 10810 | } |
| 10811 | if (mLosingFocus.size() > 0) { |
| 10812 | pw.println(" "); |
| 10813 | pw.println(" Windows losing focus:"); |
| 10814 | for (int i=mLosingFocus.size()-1; i>=0; i--) { |
| 10815 | WindowState w = mLosingFocus.get(i); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10816 | pw.print(" Losing #"); pw.print(i); pw.print(' '); |
| 10817 | pw.print(w); pw.println(":"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10818 | w.dump(pw, " "); |
| 10819 | } |
| 10820 | } |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 10821 | if (mResizingWindows.size() > 0) { |
| 10822 | pw.println(" "); |
| 10823 | pw.println(" Windows waiting to resize:"); |
| 10824 | for (int i=mResizingWindows.size()-1; i>=0; i--) { |
| 10825 | WindowState w = mResizingWindows.get(i); |
| 10826 | pw.print(" Resizing #"); pw.print(i); pw.print(' '); |
| 10827 | pw.print(w); pw.println(":"); |
| 10828 | w.dump(pw, " "); |
| 10829 | } |
| 10830 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10831 | if (mSessions.size() > 0) { |
| 10832 | pw.println(" "); |
| 10833 | pw.println(" All active sessions:"); |
| 10834 | Iterator<Session> it = mSessions.iterator(); |
| 10835 | while (it.hasNext()) { |
| 10836 | Session s = it.next(); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10837 | pw.print(" Session "); pw.print(s); pw.println(':'); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10838 | s.dump(pw, " "); |
| 10839 | } |
| 10840 | } |
| 10841 | if (mTokenMap.size() > 0) { |
| 10842 | pw.println(" "); |
| 10843 | pw.println(" All tokens:"); |
| 10844 | Iterator<WindowToken> it = mTokenMap.values().iterator(); |
| 10845 | while (it.hasNext()) { |
| 10846 | WindowToken token = it.next(); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10847 | pw.print(" Token "); pw.print(token.token); pw.println(':'); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10848 | token.dump(pw, " "); |
| 10849 | } |
| 10850 | } |
| 10851 | if (mTokenList.size() > 0) { |
| 10852 | pw.println(" "); |
| 10853 | pw.println(" Window token list:"); |
| 10854 | for (int i=0; i<mTokenList.size(); i++) { |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10855 | pw.print(" #"); pw.print(i); pw.print(": "); |
| 10856 | pw.println(mTokenList.get(i)); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10857 | } |
| 10858 | } |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 10859 | if (mWallpaperTokens.size() > 0) { |
| 10860 | pw.println(" "); |
| 10861 | pw.println(" Wallpaper tokens:"); |
| 10862 | for (int i=mWallpaperTokens.size()-1; i>=0; i--) { |
| 10863 | WindowToken token = mWallpaperTokens.get(i); |
| 10864 | pw.print(" Wallpaper #"); pw.print(i); |
| 10865 | pw.print(' '); pw.print(token); pw.println(':'); |
| 10866 | token.dump(pw, " "); |
| 10867 | } |
| 10868 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10869 | if (mAppTokens.size() > 0) { |
| 10870 | pw.println(" "); |
| 10871 | pw.println(" Application tokens in Z order:"); |
| 10872 | for (int i=mAppTokens.size()-1; i>=0; i--) { |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10873 | pw.print(" App #"); pw.print(i); pw.print(": "); |
| 10874 | pw.println(mAppTokens.get(i)); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10875 | } |
| 10876 | } |
| 10877 | if (mFinishedStarting.size() > 0) { |
| 10878 | pw.println(" "); |
| 10879 | pw.println(" Finishing start of application tokens:"); |
| 10880 | for (int i=mFinishedStarting.size()-1; i>=0; i--) { |
| 10881 | WindowToken token = mFinishedStarting.get(i); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10882 | pw.print(" Finished Starting #"); pw.print(i); |
| 10883 | pw.print(' '); pw.print(token); pw.println(':'); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10884 | token.dump(pw, " "); |
| 10885 | } |
| 10886 | } |
| 10887 | if (mExitingTokens.size() > 0) { |
| 10888 | pw.println(" "); |
| 10889 | pw.println(" Exiting tokens:"); |
| 10890 | for (int i=mExitingTokens.size()-1; i>=0; i--) { |
| 10891 | WindowToken token = mExitingTokens.get(i); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10892 | pw.print(" Exiting #"); pw.print(i); |
| 10893 | pw.print(' '); pw.print(token); pw.println(':'); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10894 | token.dump(pw, " "); |
| 10895 | } |
| 10896 | } |
| 10897 | if (mExitingAppTokens.size() > 0) { |
| 10898 | pw.println(" "); |
| 10899 | pw.println(" Exiting application tokens:"); |
| 10900 | for (int i=mExitingAppTokens.size()-1; i>=0; i--) { |
| 10901 | WindowToken token = mExitingAppTokens.get(i); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10902 | pw.print(" Exiting App #"); pw.print(i); |
| 10903 | pw.print(' '); pw.print(token); pw.println(':'); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10904 | token.dump(pw, " "); |
| 10905 | } |
| 10906 | } |
| 10907 | pw.println(" "); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10908 | pw.print(" mCurrentFocus="); pw.println(mCurrentFocus); |
| 10909 | pw.print(" mLastFocus="); pw.println(mLastFocus); |
| 10910 | pw.print(" mFocusedApp="); pw.println(mFocusedApp); |
| 10911 | pw.print(" mInputMethodTarget="); pw.println(mInputMethodTarget); |
| 10912 | pw.print(" mInputMethodWindow="); pw.println(mInputMethodWindow); |
| Dianne Hackborn | f21adf6 | 2009-08-13 10:20:21 -0700 | [diff] [blame] | 10913 | pw.print(" mWallpaperTarget="); pw.println(mWallpaperTarget); |
| Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 10914 | if (mLowerWallpaperTarget != null && mUpperWallpaperTarget != null) { |
| 10915 | pw.print(" mLowerWallpaperTarget="); pw.println(mLowerWallpaperTarget); |
| 10916 | pw.print(" mUpperWallpaperTarget="); pw.println(mUpperWallpaperTarget); |
| 10917 | } |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 10918 | pw.print(" mCurConfiguration="); pw.println(this.mCurConfiguration); |
| 10919 | pw.print(" mInTouchMode="); pw.print(mInTouchMode); |
| 10920 | pw.print(" mLayoutSeq="); pw.println(mLayoutSeq); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10921 | pw.print(" mSystemBooted="); pw.print(mSystemBooted); |
| 10922 | pw.print(" mDisplayEnabled="); pw.println(mDisplayEnabled); |
| 10923 | pw.print(" mLayoutNeeded="); pw.print(mLayoutNeeded); |
| 10924 | pw.print(" mBlurShown="); pw.println(mBlurShown); |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 10925 | if (mDimAnimator != null) { |
| 10926 | mDimAnimator.printTo(pw); |
| 10927 | } else { |
| Dianne Hackborn | a2e9226 | 2010-03-02 17:19:29 -0800 | [diff] [blame] | 10928 | pw.println( " no DimAnimator "); |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 10929 | } |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10930 | pw.print(" mInputMethodAnimLayerAdjustment="); |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 10931 | pw.print(mInputMethodAnimLayerAdjustment); |
| 10932 | pw.print(" mWallpaperAnimLayerAdjustment="); |
| 10933 | pw.println(mWallpaperAnimLayerAdjustment); |
| Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 10934 | pw.print(" mLastWallpaperX="); pw.print(mLastWallpaperX); |
| 10935 | pw.print(" mLastWallpaperY="); pw.println(mLastWallpaperY); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10936 | pw.print(" mDisplayFrozen="); pw.print(mDisplayFrozen); |
| 10937 | pw.print(" mWindowsFreezingScreen="); pw.print(mWindowsFreezingScreen); |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 10938 | pw.print(" mAppsFreezingScreen="); pw.print(mAppsFreezingScreen); |
| 10939 | pw.print(" mWaitingForConfig="); pw.println(mWaitingForConfig); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10940 | pw.print(" mRotation="); pw.print(mRotation); |
| 10941 | pw.print(", mForcedAppOrientation="); pw.print(mForcedAppOrientation); |
| 10942 | pw.print(", mRequestedRotation="); pw.println(mRequestedRotation); |
| 10943 | pw.print(" mAnimationPending="); pw.print(mAnimationPending); |
| 10944 | pw.print(" mWindowAnimationScale="); pw.print(mWindowAnimationScale); |
| 10945 | pw.print(" mTransitionWindowAnimationScale="); pw.println(mTransitionAnimationScale); |
| 10946 | pw.print(" mNextAppTransition=0x"); |
| 10947 | pw.print(Integer.toHexString(mNextAppTransition)); |
| 10948 | pw.print(", mAppTransitionReady="); pw.print(mAppTransitionReady); |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 10949 | pw.print(", mAppTransitionRunning="); pw.print(mAppTransitionRunning); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10950 | pw.print(", mAppTransitionTimeout="); pw.println( mAppTransitionTimeout); |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10951 | if (mNextAppTransitionPackage != null) { |
| 10952 | pw.print(" mNextAppTransitionPackage="); |
| 10953 | pw.print(mNextAppTransitionPackage); |
| 10954 | pw.print(", mNextAppTransitionEnter=0x"); |
| 10955 | pw.print(Integer.toHexString(mNextAppTransitionEnter)); |
| 10956 | pw.print(", mNextAppTransitionExit=0x"); |
| 10957 | pw.print(Integer.toHexString(mNextAppTransitionExit)); |
| 10958 | } |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10959 | pw.print(" mStartingIconInTransition="); pw.print(mStartingIconInTransition); |
| 10960 | pw.print(", mSkipAppTransitionAnimation="); pw.println(mSkipAppTransitionAnimation); |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10961 | if (mLastEnterAnimToken != null || mLastEnterAnimToken != null) { |
| 10962 | pw.print(" mLastEnterAnimToken="); pw.print(mLastEnterAnimToken); |
| 10963 | pw.print(", mLastEnterAnimParams="); pw.println(mLastEnterAnimParams); |
| 10964 | } |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10965 | if (mOpeningApps.size() > 0) { |
| 10966 | pw.print(" mOpeningApps="); pw.println(mOpeningApps); |
| 10967 | } |
| 10968 | if (mClosingApps.size() > 0) { |
| 10969 | pw.print(" mClosingApps="); pw.println(mClosingApps); |
| 10970 | } |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 10971 | if (mToTopApps.size() > 0) { |
| 10972 | pw.print(" mToTopApps="); pw.println(mToTopApps); |
| 10973 | } |
| 10974 | if (mToBottomApps.size() > 0) { |
| 10975 | pw.print(" mToBottomApps="); pw.println(mToBottomApps); |
| 10976 | } |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10977 | pw.print(" DisplayWidth="); pw.print(mDisplay.getWidth()); |
| 10978 | pw.print(" DisplayHeight="); pw.println(mDisplay.getHeight()); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10979 | } |
| 10980 | } |
| 10981 | |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 10982 | // 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] | 10983 | public void monitor() { |
| 10984 | synchronized (mWindowMap) { } |
| Mike Lockwood | 983ee09 | 2009-11-22 01:42:24 -0500 | [diff] [blame] | 10985 | synchronized (mKeyguardTokenWatcher) { } |
| Dianne Hackborn | ddca3ee | 2009-07-23 19:01:31 -0700 | [diff] [blame] | 10986 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10987 | |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 10988 | /** |
| 10989 | * DimAnimator class that controls the dim animation. This holds the surface and |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10990 | * all state used for dim animation. |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 10991 | */ |
| 10992 | private static class DimAnimator { |
| 10993 | Surface mDimSurface; |
| 10994 | boolean mDimShown = false; |
| 10995 | float mDimCurrentAlpha; |
| 10996 | float mDimTargetAlpha; |
| 10997 | float mDimDeltaPerMs; |
| 10998 | long mLastDimAnimTime; |
| Dianne Hackborn | f83c555 | 2010-03-31 22:19:32 -0700 | [diff] [blame] | 10999 | |
| 11000 | int mLastDimWidth, mLastDimHeight; |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11001 | |
| 11002 | DimAnimator (SurfaceSession session) { |
| 11003 | if (mDimSurface == null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 11004 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11005 | + mDimSurface + ": CREATE"); |
| 11006 | try { |
| Mathias Agopian | 5d26c1e | 2010-03-01 16:09:43 -0800 | [diff] [blame] | 11007 | mDimSurface = new Surface(session, 0, |
| 11008 | "DimSurface", |
| 11009 | -1, 16, 16, PixelFormat.OPAQUE, |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11010 | Surface.FX_SURFACE_DIM); |
| Maciej Białka | 9ee5c22 | 2010-03-24 10:25:40 +0100 | [diff] [blame] | 11011 | mDimSurface.setAlpha(0.0f); |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11012 | } catch (Exception e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 11013 | Slog.e(TAG, "Exception creating Dim surface", e); |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11014 | } |
| 11015 | } |
| 11016 | } |
| 11017 | |
| 11018 | /** |
| 11019 | * Show the dim surface. |
| 11020 | */ |
| 11021 | void show(int dw, int dh) { |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 11022 | if (!mDimShown) { |
| 11023 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface + ": SHOW pos=(0,0) (" + |
| 11024 | dw + "x" + dh + ")"); |
| 11025 | mDimShown = true; |
| 11026 | try { |
| Dianne Hackborn | f83c555 | 2010-03-31 22:19:32 -0700 | [diff] [blame] | 11027 | mLastDimWidth = dw; |
| 11028 | mLastDimHeight = dh; |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 11029 | mDimSurface.setPosition(0, 0); |
| 11030 | mDimSurface.setSize(dw, dh); |
| 11031 | mDimSurface.show(); |
| 11032 | } catch (RuntimeException e) { |
| 11033 | Slog.w(TAG, "Failure showing dim surface", e); |
| 11034 | } |
| Dianne Hackborn | f83c555 | 2010-03-31 22:19:32 -0700 | [diff] [blame] | 11035 | } else if (mLastDimWidth != dw || mLastDimHeight != dh) { |
| 11036 | mLastDimWidth = dw; |
| 11037 | mLastDimHeight = dh; |
| 11038 | mDimSurface.setSize(dw, dh); |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11039 | } |
| 11040 | } |
| 11041 | |
| 11042 | /** |
| 11043 | * Set's the dim surface's layer and update dim parameters that will be used in |
| 11044 | * {@link updateSurface} after all windows are examined. |
| 11045 | */ |
| 11046 | void updateParameters(WindowState w, long currentTime) { |
| 11047 | mDimSurface.setLayer(w.mAnimLayer-1); |
| 11048 | |
| 11049 | final float target = w.mExiting ? 0 : w.mAttrs.dimAmount; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 11050 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 11051 | + ": layer=" + (w.mAnimLayer-1) + " target=" + target); |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11052 | if (mDimTargetAlpha != target) { |
| 11053 | // If the desired dim level has changed, then |
| 11054 | // start an animation to it. |
| 11055 | mLastDimAnimTime = currentTime; |
| 11056 | long duration = (w.mAnimating && w.mAnimation != null) |
| 11057 | ? w.mAnimation.computeDurationHint() |
| 11058 | : DEFAULT_DIM_DURATION; |
| 11059 | if (target > mDimTargetAlpha) { |
| 11060 | // This is happening behind the activity UI, |
| 11061 | // so we can make it run a little longer to |
| 11062 | // give a stronger impression without disrupting |
| 11063 | // the user. |
| 11064 | duration *= DIM_DURATION_MULTIPLIER; |
| 11065 | } |
| 11066 | if (duration < 1) { |
| 11067 | // Don't divide by zero |
| 11068 | duration = 1; |
| 11069 | } |
| 11070 | mDimTargetAlpha = target; |
| 11071 | mDimDeltaPerMs = (mDimTargetAlpha-mDimCurrentAlpha) / duration; |
| 11072 | } |
| 11073 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 11074 | |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11075 | /** |
| 11076 | * Updating the surface's alpha. Returns true if the animation continues, or returns |
| 11077 | * false when the animation is finished and the dim surface is hidden. |
| 11078 | */ |
| 11079 | boolean updateSurface(boolean dimming, long currentTime, boolean displayFrozen) { |
| 11080 | if (!dimming) { |
| 11081 | if (mDimTargetAlpha != 0) { |
| 11082 | mLastDimAnimTime = currentTime; |
| 11083 | mDimTargetAlpha = 0; |
| 11084 | mDimDeltaPerMs = (-mDimCurrentAlpha) / DEFAULT_DIM_DURATION; |
| 11085 | } |
| 11086 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 11087 | |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11088 | boolean animating = false; |
| 11089 | if (mLastDimAnimTime != 0) { |
| 11090 | mDimCurrentAlpha += mDimDeltaPerMs |
| 11091 | * (currentTime-mLastDimAnimTime); |
| 11092 | boolean more = true; |
| 11093 | if (displayFrozen) { |
| 11094 | // If the display is frozen, there is no reason to animate. |
| 11095 | more = false; |
| 11096 | } else if (mDimDeltaPerMs > 0) { |
| 11097 | if (mDimCurrentAlpha > mDimTargetAlpha) { |
| 11098 | more = false; |
| 11099 | } |
| 11100 | } else if (mDimDeltaPerMs < 0) { |
| 11101 | if (mDimCurrentAlpha < mDimTargetAlpha) { |
| 11102 | more = false; |
| 11103 | } |
| 11104 | } else { |
| 11105 | more = false; |
| 11106 | } |
| 11107 | |
| 11108 | // Do we need to continue animating? |
| 11109 | if (more) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 11110 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11111 | + mDimSurface + ": alpha=" + mDimCurrentAlpha); |
| 11112 | mLastDimAnimTime = currentTime; |
| 11113 | mDimSurface.setAlpha(mDimCurrentAlpha); |
| 11114 | animating = true; |
| 11115 | } else { |
| 11116 | mDimCurrentAlpha = mDimTargetAlpha; |
| 11117 | mLastDimAnimTime = 0; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 11118 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11119 | + mDimSurface + ": final alpha=" + mDimCurrentAlpha); |
| 11120 | mDimSurface.setAlpha(mDimCurrentAlpha); |
| 11121 | if (!dimming) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 11122 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11123 | + ": HIDE"); |
| 11124 | try { |
| 11125 | mDimSurface.hide(); |
| 11126 | } catch (RuntimeException e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 11127 | Slog.w(TAG, "Illegal argument exception hiding dim surface"); |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11128 | } |
| 11129 | mDimShown = false; |
| 11130 | } |
| 11131 | } |
| 11132 | } |
| 11133 | return animating; |
| 11134 | } |
| 11135 | |
| 11136 | public void printTo(PrintWriter pw) { |
| 11137 | pw.print(" mDimShown="); pw.print(mDimShown); |
| 11138 | pw.print(" current="); pw.print(mDimCurrentAlpha); |
| 11139 | pw.print(" target="); pw.print(mDimTargetAlpha); |
| 11140 | pw.print(" delta="); pw.print(mDimDeltaPerMs); |
| 11141 | pw.print(" lastAnimTime="); pw.println(mLastDimAnimTime); |
| 11142 | } |
| 11143 | } |
| 11144 | |
| 11145 | /** |
| 11146 | * Animation that fade in after 0.5 interpolate time, or fade out in reverse order. |
| 11147 | * This is used for opening/closing transition for apps in compatible mode. |
| 11148 | */ |
| 11149 | private static class FadeInOutAnimation extends Animation { |
| 11150 | int mWidth; |
| 11151 | boolean mFadeIn; |
| 11152 | |
| 11153 | public FadeInOutAnimation(boolean fadeIn) { |
| 11154 | setInterpolator(new AccelerateInterpolator()); |
| 11155 | setDuration(DEFAULT_FADE_IN_OUT_DURATION); |
| 11156 | mFadeIn = fadeIn; |
| 11157 | } |
| 11158 | |
| 11159 | @Override |
| 11160 | protected void applyTransformation(float interpolatedTime, Transformation t) { |
| 11161 | float x = interpolatedTime; |
| 11162 | if (!mFadeIn) { |
| 11163 | x = 1.0f - x; // reverse the interpolation for fade out |
| 11164 | } |
| 11165 | if (x < 0.5) { |
| 11166 | // move the window out of the screen. |
| 11167 | t.getMatrix().setTranslate(mWidth, 0); |
| 11168 | } else { |
| 11169 | t.getMatrix().setTranslate(0, 0);// show |
| 11170 | t.setAlpha((x - 0.5f) * 2); |
| 11171 | } |
| 11172 | } |
| 11173 | |
| 11174 | @Override |
| 11175 | public void initialize(int width, int height, int parentWidth, int parentHeight) { |
| 11176 | // width is the screen width {@see AppWindowToken#stepAnimatinoLocked} |
| 11177 | mWidth = width; |
| 11178 | } |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11179 | |
| 11180 | @Override |
| Mitsuru Oshima | 5a2b91d | 2009-07-16 16:30:02 -0700 | [diff] [blame] | 11181 | public int getZAdjustment() { |
| 11182 | return Animation.ZORDER_TOP; |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11183 | } |
| 11184 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11185 | } |