| 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(); |
| Chris Tate | 5994359 | 2010-10-11 20:33:44 -0700 | [diff] [blame^] | 807 | synchronized (mWindowMap) { |
| 808 | mInputMonitor.updateInputWindowsLw(); |
| 809 | } |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 810 | |
| 811 | // free our resources and drop all the object references |
| 812 | mDragState.reset(); |
| 813 | mDragState = null; |
| 814 | } |
| 815 | } |
| 816 | } catch (Exception e) { |
| 817 | Slog.e(TAG, "Exception caught by drag handleMotion", e); |
| 818 | } finally { |
| 819 | finishedCallback.run(); |
| 820 | } |
| 821 | } |
| 822 | }; |
| 823 | |
| 824 | /** |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 825 | * Whether the UI is currently running in touch mode (not showing |
| 826 | * navigational focus because the user is directly pressing the screen). |
| 827 | */ |
| 828 | boolean mInTouchMode = false; |
| 829 | |
| 830 | private ViewServer mViewServer; |
| Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 831 | private ArrayList<WindowChangeListener> mWindowChangeListeners = |
| 832 | new ArrayList<WindowChangeListener>(); |
| 833 | private boolean mWindowsChanged = false; |
| 834 | |
| 835 | public interface WindowChangeListener { |
| 836 | public void windowsChanged(); |
| Konstantin Lopyrev | 6e0f65f | 2010-07-14 14:55:33 -0700 | [diff] [blame] | 837 | public void focusChanged(); |
| Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 838 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 839 | |
| Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 840 | final Configuration mTempConfiguration = new Configuration(); |
| Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 841 | int mScreenLayout = Configuration.SCREENLAYOUT_SIZE_UNDEFINED; |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 842 | |
| 843 | // The frame use to limit the size of the app running in compatibility mode. |
| 844 | Rect mCompatibleScreenFrame = new Rect(); |
| 845 | // The surface used to fill the outer rim of the app running in compatibility mode. |
| 846 | Surface mBackgroundFillerSurface = null; |
| 847 | boolean mBackgroundFillerShown = false; |
| 848 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 849 | public static WindowManagerService main(Context context, |
| 850 | PowerManagerService pm, boolean haveInputMethods) { |
| 851 | WMThread thr = new WMThread(context, pm, haveInputMethods); |
| 852 | thr.start(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 853 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 854 | synchronized (thr) { |
| 855 | while (thr.mService == null) { |
| 856 | try { |
| 857 | thr.wait(); |
| 858 | } catch (InterruptedException e) { |
| 859 | } |
| 860 | } |
| 861 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 862 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 863 | return thr.mService; |
| 864 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 865 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 866 | static class WMThread extends Thread { |
| 867 | WindowManagerService mService; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 868 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 869 | private final Context mContext; |
| 870 | private final PowerManagerService mPM; |
| 871 | private final boolean mHaveInputMethods; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 872 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 873 | public WMThread(Context context, PowerManagerService pm, |
| 874 | boolean haveInputMethods) { |
| 875 | super("WindowManager"); |
| 876 | mContext = context; |
| 877 | mPM = pm; |
| 878 | mHaveInputMethods = haveInputMethods; |
| 879 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 880 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 881 | public void run() { |
| 882 | Looper.prepare(); |
| 883 | WindowManagerService s = new WindowManagerService(mContext, mPM, |
| 884 | mHaveInputMethods); |
| 885 | android.os.Process.setThreadPriority( |
| 886 | android.os.Process.THREAD_PRIORITY_DISPLAY); |
| Christopher Tate | 160edb3 | 2010-06-30 17:46:30 -0700 | [diff] [blame] | 887 | android.os.Process.setCanSelfBackground(false); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 888 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 889 | synchronized (this) { |
| 890 | mService = s; |
| 891 | notifyAll(); |
| 892 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 893 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 894 | Looper.loop(); |
| 895 | } |
| 896 | } |
| 897 | |
| 898 | static class PolicyThread extends Thread { |
| 899 | private final WindowManagerPolicy mPolicy; |
| 900 | private final WindowManagerService mService; |
| 901 | private final Context mContext; |
| 902 | private final PowerManagerService mPM; |
| 903 | boolean mRunning = false; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 904 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 905 | public PolicyThread(WindowManagerPolicy policy, |
| 906 | WindowManagerService service, Context context, |
| 907 | PowerManagerService pm) { |
| 908 | super("WindowManagerPolicy"); |
| 909 | mPolicy = policy; |
| 910 | mService = service; |
| 911 | mContext = context; |
| 912 | mPM = pm; |
| 913 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 914 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 915 | public void run() { |
| 916 | Looper.prepare(); |
| Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 917 | WindowManagerPolicyThread.set(this, Looper.myLooper()); |
| 918 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 919 | //Looper.myLooper().setMessageLogging(new LogPrinter( |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 920 | // Log.VERBOSE, "WindowManagerPolicy", Log.LOG_ID_SYSTEM)); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 921 | android.os.Process.setThreadPriority( |
| 922 | android.os.Process.THREAD_PRIORITY_FOREGROUND); |
| Christopher Tate | 160edb3 | 2010-06-30 17:46:30 -0700 | [diff] [blame] | 923 | android.os.Process.setCanSelfBackground(false); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 924 | mPolicy.init(mContext, mService, mPM); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 925 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 926 | synchronized (this) { |
| 927 | mRunning = true; |
| 928 | notifyAll(); |
| 929 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 930 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 931 | Looper.loop(); |
| 932 | } |
| 933 | } |
| 934 | |
| 935 | private WindowManagerService(Context context, PowerManagerService pm, |
| 936 | boolean haveInputMethods) { |
| 937 | mContext = context; |
| 938 | mHaveInputMethods = haveInputMethods; |
| 939 | mLimitedAlphaCompositing = context.getResources().getBoolean( |
| 940 | com.android.internal.R.bool.config_sf_limitedAlpha); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 941 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 942 | mPowerManager = pm; |
| 943 | mPowerManager.setPolicy(mPolicy); |
| 944 | PowerManager pmc = (PowerManager)context.getSystemService(Context.POWER_SERVICE); |
| 945 | mScreenFrozenLock = pmc.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, |
| 946 | "SCREEN_FROZEN"); |
| 947 | mScreenFrozenLock.setReferenceCounted(false); |
| 948 | |
| 949 | mActivityManager = ActivityManagerNative.getDefault(); |
| 950 | mBatteryStats = BatteryStatsService.getService(); |
| 951 | |
| 952 | // Get persisted window scale setting |
| 953 | mWindowAnimationScale = Settings.System.getFloat(context.getContentResolver(), |
| 954 | Settings.System.WINDOW_ANIMATION_SCALE, mWindowAnimationScale); |
| 955 | mTransitionAnimationScale = Settings.System.getFloat(context.getContentResolver(), |
| 956 | Settings.System.TRANSITION_ANIMATION_SCALE, mTransitionAnimationScale); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 957 | |
| Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 958 | // Track changes to DevicePolicyManager state so we can enable/disable keyguard. |
| 959 | IntentFilter filter = new IntentFilter(); |
| 960 | filter.addAction(DevicePolicyManager.ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED); |
| 961 | mContext.registerReceiver(mBroadcastReceiver, filter); |
| 962 | |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 963 | mHoldingScreenWakeLock = pmc.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK, |
| 964 | "KEEP_SCREEN_ON_FLAG"); |
| 965 | mHoldingScreenWakeLock.setReferenceCounted(false); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 966 | |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 967 | mInputManager = new InputManager(context, this); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 968 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 969 | PolicyThread thr = new PolicyThread(mPolicy, this, context, pm); |
| 970 | thr.start(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 971 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 972 | synchronized (thr) { |
| 973 | while (!thr.mRunning) { |
| 974 | try { |
| 975 | thr.wait(); |
| 976 | } catch (InterruptedException e) { |
| 977 | } |
| 978 | } |
| 979 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 980 | |
| Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 981 | mInputManager.start(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 982 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 983 | // Add ourself to the Watchdog monitors. |
| 984 | Watchdog.getInstance().addMonitor(this); |
| 985 | } |
| 986 | |
| 987 | @Override |
| 988 | public boolean onTransact(int code, Parcel data, Parcel reply, int flags) |
| 989 | throws RemoteException { |
| 990 | try { |
| 991 | return super.onTransact(code, data, reply, flags); |
| 992 | } catch (RuntimeException e) { |
| 993 | // The window manager only throws security exceptions, so let's |
| 994 | // log all others. |
| 995 | if (!(e instanceof SecurityException)) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 996 | Slog.e(TAG, "Window Manager Crash", e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 997 | } |
| 998 | throw e; |
| 999 | } |
| 1000 | } |
| 1001 | |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1002 | private void placeWindowAfter(WindowState pos, WindowState window) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1003 | final int i = mWindows.indexOf(pos); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1004 | if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1005 | TAG, "Adding window " + window + " at " |
| 1006 | + (i+1) + " of " + mWindows.size() + " (after " + pos + ")"); |
| 1007 | mWindows.add(i+1, window); |
| Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 1008 | mWindowsChanged = true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1009 | } |
| 1010 | |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1011 | private void placeWindowBefore(WindowState pos, WindowState window) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1012 | final int i = mWindows.indexOf(pos); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1013 | if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1014 | TAG, "Adding window " + window + " at " |
| 1015 | + i + " of " + mWindows.size() + " (before " + pos + ")"); |
| 1016 | mWindows.add(i, window); |
| Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 1017 | mWindowsChanged = true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1018 | } |
| 1019 | |
| 1020 | //This method finds out the index of a window that has the same app token as |
| 1021 | //win. used for z ordering the windows in mWindows |
| 1022 | private int findIdxBasedOnAppTokens(WindowState win) { |
| 1023 | //use a local variable to cache mWindows |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1024 | ArrayList<WindowState> localmWindows = mWindows; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1025 | int jmax = localmWindows.size(); |
| 1026 | if(jmax == 0) { |
| 1027 | return -1; |
| 1028 | } |
| 1029 | for(int j = (jmax-1); j >= 0; j--) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1030 | WindowState wentry = localmWindows.get(j); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1031 | if(wentry.mAppToken == win.mAppToken) { |
| 1032 | return j; |
| 1033 | } |
| 1034 | } |
| 1035 | return -1; |
| 1036 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1037 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1038 | private void addWindowToListInOrderLocked(WindowState win, boolean addToToken) { |
| 1039 | final IWindow client = win.mClient; |
| 1040 | final WindowToken token = win.mToken; |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1041 | final ArrayList<WindowState> localmWindows = mWindows; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1042 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1043 | final int N = localmWindows.size(); |
| 1044 | final WindowState attached = win.mAttachedWindow; |
| 1045 | int i; |
| 1046 | if (attached == null) { |
| 1047 | int tokenWindowsPos = token.windows.size(); |
| 1048 | if (token.appWindowToken != null) { |
| 1049 | int index = tokenWindowsPos-1; |
| 1050 | if (index >= 0) { |
| 1051 | // If this application has existing windows, we |
| 1052 | // simply place the new window on top of them... but |
| 1053 | // keep the starting window on top. |
| 1054 | if (win.mAttrs.type == TYPE_BASE_APPLICATION) { |
| 1055 | // Base windows go behind everything else. |
| 1056 | placeWindowBefore(token.windows.get(0), win); |
| 1057 | tokenWindowsPos = 0; |
| 1058 | } else { |
| 1059 | AppWindowToken atoken = win.mAppToken; |
| 1060 | if (atoken != null && |
| 1061 | token.windows.get(index) == atoken.startingWindow) { |
| 1062 | placeWindowBefore(token.windows.get(index), win); |
| 1063 | tokenWindowsPos--; |
| 1064 | } else { |
| 1065 | int newIdx = findIdxBasedOnAppTokens(win); |
| 1066 | if(newIdx != -1) { |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1067 | //there is a window above this one associated with the same |
| 1068 | //apptoken note that the window could be a floating window |
| 1069 | //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] | 1070 | //windows associated with this token. |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1071 | if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v( |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 1072 | TAG, "Adding window " + win + " at " |
| 1073 | + (newIdx+1) + " of " + N); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1074 | localmWindows.add(newIdx+1, win); |
| Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 1075 | mWindowsChanged = true; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1076 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1077 | } |
| 1078 | } |
| 1079 | } else { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1080 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1081 | TAG, "Figuring out where to add app window " |
| 1082 | + client.asBinder() + " (token=" + token + ")"); |
| 1083 | // Figure out where the window should go, based on the |
| 1084 | // order of applications. |
| 1085 | final int NA = mAppTokens.size(); |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1086 | WindowState pos = null; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1087 | for (i=NA-1; i>=0; i--) { |
| 1088 | AppWindowToken t = mAppTokens.get(i); |
| 1089 | if (t == token) { |
| 1090 | i--; |
| 1091 | break; |
| 1092 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1093 | |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 1094 | // We haven't reached the token yet; if this token |
| 1095 | // is not going to the bottom and has windows, we can |
| 1096 | // use it as an anchor for when we do reach the token. |
| 1097 | if (!t.sendingToBottom && t.windows.size() > 0) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1098 | pos = t.windows.get(0); |
| 1099 | } |
| 1100 | } |
| 1101 | // We now know the index into the apps. If we found |
| 1102 | // an app window above, that gives us the position; else |
| 1103 | // we need to look some more. |
| 1104 | if (pos != null) { |
| 1105 | // Move behind any windows attached to this one. |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1106 | WindowToken atoken = mTokenMap.get(pos.mClient.asBinder()); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1107 | if (atoken != null) { |
| 1108 | final int NC = atoken.windows.size(); |
| 1109 | if (NC > 0) { |
| 1110 | WindowState bottom = atoken.windows.get(0); |
| 1111 | if (bottom.mSubLayer < 0) { |
| 1112 | pos = bottom; |
| 1113 | } |
| 1114 | } |
| 1115 | } |
| 1116 | placeWindowBefore(pos, win); |
| 1117 | } else { |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 1118 | // Continue looking down until we find the first |
| 1119 | // token that has windows. |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1120 | while (i >= 0) { |
| 1121 | AppWindowToken t = mAppTokens.get(i); |
| 1122 | final int NW = t.windows.size(); |
| 1123 | if (NW > 0) { |
| 1124 | pos = t.windows.get(NW-1); |
| 1125 | break; |
| 1126 | } |
| 1127 | i--; |
| 1128 | } |
| 1129 | if (pos != null) { |
| 1130 | // Move in front of any windows attached to this |
| 1131 | // one. |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1132 | WindowToken atoken = mTokenMap.get(pos.mClient.asBinder()); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1133 | if (atoken != null) { |
| 1134 | final int NC = atoken.windows.size(); |
| 1135 | if (NC > 0) { |
| 1136 | WindowState top = atoken.windows.get(NC-1); |
| 1137 | if (top.mSubLayer >= 0) { |
| 1138 | pos = top; |
| 1139 | } |
| 1140 | } |
| 1141 | } |
| 1142 | placeWindowAfter(pos, win); |
| 1143 | } else { |
| 1144 | // Just search for the start of this layer. |
| 1145 | final int myLayer = win.mBaseLayer; |
| 1146 | for (i=0; i<N; i++) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1147 | WindowState w = localmWindows.get(i); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1148 | if (w.mBaseLayer > myLayer) { |
| 1149 | break; |
| 1150 | } |
| 1151 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1152 | if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v( |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 1153 | TAG, "Adding window " + win + " at " |
| 1154 | + i + " of " + N); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1155 | localmWindows.add(i, win); |
| Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 1156 | mWindowsChanged = true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1157 | } |
| 1158 | } |
| 1159 | } |
| 1160 | } else { |
| 1161 | // Figure out where window should go, based on layer. |
| 1162 | final int myLayer = win.mBaseLayer; |
| 1163 | for (i=N-1; i>=0; i--) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1164 | if (localmWindows.get(i).mBaseLayer <= myLayer) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1165 | i++; |
| 1166 | break; |
| 1167 | } |
| 1168 | } |
| 1169 | if (i < 0) i = 0; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1170 | if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v( |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 1171 | TAG, "Adding window " + win + " at " |
| 1172 | + i + " of " + N); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1173 | localmWindows.add(i, win); |
| Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 1174 | mWindowsChanged = true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1175 | } |
| 1176 | if (addToToken) { |
| 1177 | token.windows.add(tokenWindowsPos, win); |
| 1178 | } |
| 1179 | |
| 1180 | } else { |
| 1181 | // Figure out this window's ordering relative to the window |
| 1182 | // it is attached to. |
| 1183 | final int NA = token.windows.size(); |
| 1184 | final int sublayer = win.mSubLayer; |
| 1185 | int largestSublayer = Integer.MIN_VALUE; |
| 1186 | WindowState windowWithLargestSublayer = null; |
| 1187 | for (i=0; i<NA; i++) { |
| 1188 | WindowState w = token.windows.get(i); |
| 1189 | final int wSublayer = w.mSubLayer; |
| 1190 | if (wSublayer >= largestSublayer) { |
| 1191 | largestSublayer = wSublayer; |
| 1192 | windowWithLargestSublayer = w; |
| 1193 | } |
| 1194 | if (sublayer < 0) { |
| 1195 | // For negative sublayers, we go below all windows |
| 1196 | // in the same sublayer. |
| 1197 | if (wSublayer >= sublayer) { |
| 1198 | if (addToToken) { |
| 1199 | token.windows.add(i, win); |
| 1200 | } |
| 1201 | placeWindowBefore( |
| 1202 | wSublayer >= 0 ? attached : w, win); |
| 1203 | break; |
| 1204 | } |
| 1205 | } else { |
| 1206 | // For positive sublayers, we go above all windows |
| 1207 | // in the same sublayer. |
| 1208 | if (wSublayer > sublayer) { |
| 1209 | if (addToToken) { |
| 1210 | token.windows.add(i, win); |
| 1211 | } |
| 1212 | placeWindowBefore(w, win); |
| 1213 | break; |
| 1214 | } |
| 1215 | } |
| 1216 | } |
| 1217 | if (i >= NA) { |
| 1218 | if (addToToken) { |
| 1219 | token.windows.add(win); |
| 1220 | } |
| 1221 | if (sublayer < 0) { |
| 1222 | placeWindowBefore(attached, win); |
| 1223 | } else { |
| 1224 | placeWindowAfter(largestSublayer >= 0 |
| 1225 | ? windowWithLargestSublayer |
| 1226 | : attached, |
| 1227 | win); |
| 1228 | } |
| 1229 | } |
| 1230 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1231 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1232 | if (win.mAppToken != null && addToToken) { |
| 1233 | win.mAppToken.allAppWindows.add(win); |
| 1234 | } |
| 1235 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1236 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1237 | static boolean canBeImeTarget(WindowState w) { |
| 1238 | final int fl = w.mAttrs.flags |
| 1239 | & (FLAG_NOT_FOCUSABLE|FLAG_ALT_FOCUSABLE_IM); |
| 1240 | if (fl == 0 || fl == (FLAG_NOT_FOCUSABLE|FLAG_ALT_FOCUSABLE_IM)) { |
| 1241 | return w.isVisibleOrAdding(); |
| 1242 | } |
| 1243 | return false; |
| 1244 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1245 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1246 | int findDesiredInputMethodWindowIndexLocked(boolean willMove) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1247 | final ArrayList<WindowState> localmWindows = mWindows; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1248 | final int N = localmWindows.size(); |
| 1249 | WindowState w = null; |
| 1250 | int i = N; |
| 1251 | while (i > 0) { |
| 1252 | i--; |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1253 | w = localmWindows.get(i); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1254 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1255 | //Slog.i(TAG, "Checking window @" + i + " " + w + " fl=0x" |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1256 | // + Integer.toHexString(w.mAttrs.flags)); |
| 1257 | if (canBeImeTarget(w)) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1258 | //Slog.i(TAG, "Putting input method here!"); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1259 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1260 | // Yet more tricksyness! If this window is a "starting" |
| 1261 | // window, we do actually want to be on top of it, but |
| 1262 | // it is not -really- where input will go. So if the caller |
| 1263 | // is not actually looking to move the IME, look down below |
| 1264 | // for a real window to target... |
| 1265 | if (!willMove |
| 1266 | && w.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING |
| 1267 | && i > 0) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1268 | WindowState wb = localmWindows.get(i-1); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1269 | if (wb.mAppToken == w.mAppToken && canBeImeTarget(wb)) { |
| 1270 | i--; |
| 1271 | w = wb; |
| 1272 | } |
| 1273 | } |
| 1274 | break; |
| 1275 | } |
| 1276 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1277 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1278 | mUpcomingInputMethodTarget = w; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1279 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1280 | 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] | 1281 | + w + " willMove=" + willMove); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1282 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1283 | if (willMove && w != null) { |
| 1284 | final WindowState curTarget = mInputMethodTarget; |
| 1285 | if (curTarget != null && curTarget.mAppToken != null) { |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1286 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1287 | // Now some fun for dealing with window animations that |
| 1288 | // modify the Z order. We need to look at all windows below |
| 1289 | // the current target that are in this app, finding the highest |
| 1290 | // visible one in layering. |
| 1291 | AppWindowToken token = curTarget.mAppToken; |
| 1292 | WindowState highestTarget = null; |
| 1293 | int highestPos = 0; |
| 1294 | if (token.animating || token.animation != null) { |
| 1295 | int pos = 0; |
| 1296 | pos = localmWindows.indexOf(curTarget); |
| 1297 | while (pos >= 0) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1298 | WindowState win = localmWindows.get(pos); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1299 | if (win.mAppToken != token) { |
| 1300 | break; |
| 1301 | } |
| 1302 | if (!win.mRemoved) { |
| 1303 | if (highestTarget == null || win.mAnimLayer > |
| 1304 | highestTarget.mAnimLayer) { |
| 1305 | highestTarget = win; |
| 1306 | highestPos = pos; |
| 1307 | } |
| 1308 | } |
| 1309 | pos--; |
| 1310 | } |
| 1311 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1312 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1313 | if (highestTarget != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1314 | if (DEBUG_INPUT_METHOD) Slog.v(TAG, "mNextAppTransition=" |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1315 | + mNextAppTransition + " " + highestTarget |
| 1316 | + " animating=" + highestTarget.isAnimating() |
| 1317 | + " layer=" + highestTarget.mAnimLayer |
| 1318 | + " new layer=" + w.mAnimLayer); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1319 | |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 1320 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1321 | // If we are currently setting up for an animation, |
| 1322 | // hold everything until we can find out what will happen. |
| 1323 | mInputMethodTargetWaitingAnim = true; |
| 1324 | mInputMethodTarget = highestTarget; |
| 1325 | return highestPos + 1; |
| 1326 | } else if (highestTarget.isAnimating() && |
| 1327 | highestTarget.mAnimLayer > w.mAnimLayer) { |
| 1328 | // If the window we are currently targeting is involved |
| 1329 | // with an animation, and it is on top of the next target |
| 1330 | // we will be over, then hold off on moving until |
| 1331 | // that is done. |
| 1332 | mInputMethodTarget = highestTarget; |
| 1333 | return highestPos + 1; |
| 1334 | } |
| 1335 | } |
| 1336 | } |
| 1337 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1338 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1339 | //Slog.i(TAG, "Placing input method @" + (i+1)); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1340 | if (w != null) { |
| 1341 | if (willMove) { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 1342 | if (DEBUG_INPUT_METHOD) { |
| 1343 | RuntimeException e = null; |
| 1344 | if (!HIDE_STACK_CRAWLS) { |
| 1345 | e = new RuntimeException(); |
| 1346 | e.fillInStackTrace(); |
| 1347 | } |
| 1348 | Slog.w(TAG, "Moving IM target from " |
| 1349 | + mInputMethodTarget + " to " + w, e); |
| 1350 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1351 | mInputMethodTarget = w; |
| 1352 | if (w.mAppToken != null) { |
| 1353 | setInputMethodAnimLayerAdjustment(w.mAppToken.animLayerAdjustment); |
| 1354 | } else { |
| 1355 | setInputMethodAnimLayerAdjustment(0); |
| 1356 | } |
| 1357 | } |
| 1358 | return i+1; |
| 1359 | } |
| 1360 | if (willMove) { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 1361 | if (DEBUG_INPUT_METHOD) { |
| 1362 | RuntimeException e = null; |
| 1363 | if (!HIDE_STACK_CRAWLS) { |
| 1364 | e = new RuntimeException(); |
| 1365 | e.fillInStackTrace(); |
| 1366 | } |
| 1367 | Slog.w(TAG, "Moving IM target from " |
| 1368 | + mInputMethodTarget + " to null", e); |
| 1369 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1370 | mInputMethodTarget = null; |
| 1371 | setInputMethodAnimLayerAdjustment(0); |
| 1372 | } |
| 1373 | return -1; |
| 1374 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1375 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1376 | void addInputMethodWindowToListLocked(WindowState win) { |
| 1377 | int pos = findDesiredInputMethodWindowIndexLocked(true); |
| 1378 | if (pos >= 0) { |
| 1379 | win.mTargetAppToken = mInputMethodTarget.mAppToken; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1380 | if (DEBUG_WINDOW_MOVEMENT) Slog.v( |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 1381 | TAG, "Adding input method window " + win + " at " + pos); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1382 | mWindows.add(pos, win); |
| Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 1383 | mWindowsChanged = true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1384 | moveInputMethodDialogsLocked(pos+1); |
| 1385 | return; |
| 1386 | } |
| 1387 | win.mTargetAppToken = null; |
| 1388 | addWindowToListInOrderLocked(win, true); |
| 1389 | moveInputMethodDialogsLocked(pos); |
| 1390 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1391 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1392 | void setInputMethodAnimLayerAdjustment(int adj) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1393 | 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] | 1394 | mInputMethodAnimLayerAdjustment = adj; |
| 1395 | WindowState imw = mInputMethodWindow; |
| 1396 | if (imw != null) { |
| 1397 | imw.mAnimLayer = imw.mLayer + adj; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1398 | if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + imw |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1399 | + " anim layer: " + imw.mAnimLayer); |
| 1400 | int wi = imw.mChildWindows.size(); |
| 1401 | while (wi > 0) { |
| 1402 | wi--; |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1403 | WindowState cw = imw.mChildWindows.get(wi); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1404 | cw.mAnimLayer = cw.mLayer + adj; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1405 | if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + cw |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1406 | + " anim layer: " + cw.mAnimLayer); |
| 1407 | } |
| 1408 | } |
| 1409 | int di = mInputMethodDialogs.size(); |
| 1410 | while (di > 0) { |
| 1411 | di --; |
| 1412 | imw = mInputMethodDialogs.get(di); |
| 1413 | imw.mAnimLayer = imw.mLayer + adj; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1414 | if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + imw |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1415 | + " anim layer: " + imw.mAnimLayer); |
| 1416 | } |
| 1417 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1418 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1419 | private int tmpRemoveWindowLocked(int interestingPos, WindowState win) { |
| 1420 | int wpos = mWindows.indexOf(win); |
| 1421 | if (wpos >= 0) { |
| 1422 | if (wpos < interestingPos) interestingPos--; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1423 | 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] | 1424 | mWindows.remove(wpos); |
| Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 1425 | mWindowsChanged = true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1426 | int NC = win.mChildWindows.size(); |
| 1427 | while (NC > 0) { |
| 1428 | NC--; |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1429 | WindowState cw = win.mChildWindows.get(NC); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1430 | int cpos = mWindows.indexOf(cw); |
| 1431 | if (cpos >= 0) { |
| 1432 | if (cpos < interestingPos) interestingPos--; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1433 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Temp removing child at " |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 1434 | + cpos + ": " + cw); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1435 | mWindows.remove(cpos); |
| 1436 | } |
| 1437 | } |
| 1438 | } |
| 1439 | return interestingPos; |
| 1440 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1441 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1442 | private void reAddWindowToListInOrderLocked(WindowState win) { |
| 1443 | addWindowToListInOrderLocked(win, false); |
| 1444 | // This is a hack to get all of the child windows added as well |
| 1445 | // at the right position. Child windows should be rare and |
| 1446 | // this case should be rare, so it shouldn't be that big a deal. |
| 1447 | int wpos = mWindows.indexOf(win); |
| 1448 | if (wpos >= 0) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1449 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "ReAdd removing from " + wpos |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 1450 | + ": " + win); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1451 | mWindows.remove(wpos); |
| Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 1452 | mWindowsChanged = true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1453 | reAddWindowLocked(wpos, win); |
| 1454 | } |
| 1455 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1456 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1457 | void logWindowList(String prefix) { |
| 1458 | int N = mWindows.size(); |
| 1459 | while (N > 0) { |
| 1460 | N--; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1461 | Slog.v(TAG, prefix + "#" + N + ": " + mWindows.get(N)); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1462 | } |
| 1463 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1464 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1465 | void moveInputMethodDialogsLocked(int pos) { |
| 1466 | ArrayList<WindowState> dialogs = mInputMethodDialogs; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1467 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1468 | final int N = dialogs.size(); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1469 | 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] | 1470 | for (int i=0; i<N; i++) { |
| 1471 | pos = tmpRemoveWindowLocked(pos, dialogs.get(i)); |
| 1472 | } |
| 1473 | if (DEBUG_INPUT_METHOD) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1474 | Slog.v(TAG, "Window list w/pos=" + pos); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1475 | logWindowList(" "); |
| 1476 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1477 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1478 | if (pos >= 0) { |
| 1479 | final AppWindowToken targetAppToken = mInputMethodTarget.mAppToken; |
| 1480 | if (pos < mWindows.size()) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1481 | WindowState wp = mWindows.get(pos); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1482 | if (wp == mInputMethodWindow) { |
| 1483 | pos++; |
| 1484 | } |
| 1485 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1486 | 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] | 1487 | for (int i=0; i<N; i++) { |
| 1488 | WindowState win = dialogs.get(i); |
| 1489 | win.mTargetAppToken = targetAppToken; |
| 1490 | pos = reAddWindowLocked(pos, win); |
| 1491 | } |
| 1492 | if (DEBUG_INPUT_METHOD) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1493 | Slog.v(TAG, "Final window list:"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1494 | logWindowList(" "); |
| 1495 | } |
| 1496 | return; |
| 1497 | } |
| 1498 | for (int i=0; i<N; i++) { |
| 1499 | WindowState win = dialogs.get(i); |
| 1500 | win.mTargetAppToken = null; |
| 1501 | reAddWindowToListInOrderLocked(win); |
| 1502 | if (DEBUG_INPUT_METHOD) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1503 | Slog.v(TAG, "No IM target, final list:"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1504 | logWindowList(" "); |
| 1505 | } |
| 1506 | } |
| 1507 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1508 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1509 | boolean moveInputMethodWindowsIfNeededLocked(boolean needAssignLayers) { |
| 1510 | final WindowState imWin = mInputMethodWindow; |
| 1511 | final int DN = mInputMethodDialogs.size(); |
| 1512 | if (imWin == null && DN == 0) { |
| 1513 | return false; |
| 1514 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1515 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1516 | int imPos = findDesiredInputMethodWindowIndexLocked(true); |
| 1517 | if (imPos >= 0) { |
| 1518 | // In this case, the input method windows are to be placed |
| 1519 | // immediately above the window they are targeting. |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1520 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1521 | // First check to see if the input method windows are already |
| 1522 | // located here, and contiguous. |
| 1523 | final int N = mWindows.size(); |
| 1524 | WindowState firstImWin = imPos < N |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1525 | ? mWindows.get(imPos) : null; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1526 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1527 | // Figure out the actual input method window that should be |
| 1528 | // at the bottom of their stack. |
| 1529 | WindowState baseImWin = imWin != null |
| 1530 | ? imWin : mInputMethodDialogs.get(0); |
| 1531 | if (baseImWin.mChildWindows.size() > 0) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1532 | WindowState cw = baseImWin.mChildWindows.get(0); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1533 | if (cw.mSubLayer < 0) baseImWin = cw; |
| 1534 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1535 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1536 | if (firstImWin == baseImWin) { |
| 1537 | // The windows haven't moved... but are they still contiguous? |
| 1538 | // First find the top IM window. |
| 1539 | int pos = imPos+1; |
| 1540 | while (pos < N) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1541 | if (!(mWindows.get(pos)).mIsImWindow) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1542 | break; |
| 1543 | } |
| 1544 | pos++; |
| 1545 | } |
| 1546 | pos++; |
| 1547 | // Now there should be no more input method windows above. |
| 1548 | while (pos < N) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1549 | if ((mWindows.get(pos)).mIsImWindow) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1550 | break; |
| 1551 | } |
| 1552 | pos++; |
| 1553 | } |
| 1554 | if (pos >= N) { |
| 1555 | // All is good! |
| 1556 | return false; |
| 1557 | } |
| 1558 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1559 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1560 | if (imWin != null) { |
| 1561 | if (DEBUG_INPUT_METHOD) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1562 | Slog.v(TAG, "Moving IM from " + imPos); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1563 | logWindowList(" "); |
| 1564 | } |
| 1565 | imPos = tmpRemoveWindowLocked(imPos, imWin); |
| 1566 | if (DEBUG_INPUT_METHOD) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1567 | 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] | 1568 | logWindowList(" "); |
| 1569 | } |
| 1570 | imWin.mTargetAppToken = mInputMethodTarget.mAppToken; |
| 1571 | reAddWindowLocked(imPos, imWin); |
| 1572 | if (DEBUG_INPUT_METHOD) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1573 | Slog.v(TAG, "List after moving IM to " + imPos + ":"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1574 | logWindowList(" "); |
| 1575 | } |
| 1576 | if (DN > 0) moveInputMethodDialogsLocked(imPos+1); |
| 1577 | } else { |
| 1578 | moveInputMethodDialogsLocked(imPos); |
| 1579 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1580 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1581 | } else { |
| 1582 | // In this case, the input method windows go in a fixed layer, |
| 1583 | // because they aren't currently associated with a focus window. |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1584 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1585 | if (imWin != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1586 | 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] | 1587 | tmpRemoveWindowLocked(0, imWin); |
| 1588 | imWin.mTargetAppToken = null; |
| 1589 | reAddWindowToListInOrderLocked(imWin); |
| 1590 | if (DEBUG_INPUT_METHOD) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1591 | Slog.v(TAG, "List with no IM target:"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1592 | logWindowList(" "); |
| 1593 | } |
| 1594 | if (DN > 0) moveInputMethodDialogsLocked(-1);; |
| 1595 | } else { |
| 1596 | moveInputMethodDialogsLocked(-1);; |
| 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 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1600 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1601 | if (needAssignLayers) { |
| 1602 | assignLayersLocked(); |
| 1603 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1604 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1605 | return true; |
| 1606 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1607 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1608 | void adjustInputMethodDialogsLocked() { |
| 1609 | moveInputMethodDialogsLocked(findDesiredInputMethodWindowIndexLocked(true)); |
| 1610 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1611 | |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 1612 | final boolean isWallpaperVisible(WindowState wallpaperTarget) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1613 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper vis: target obscured=" |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 1614 | + (wallpaperTarget != null ? Boolean.toString(wallpaperTarget.mObscured) : "??") |
| 1615 | + " anim=" + ((wallpaperTarget != null && wallpaperTarget.mAppToken != null) |
| 1616 | ? wallpaperTarget.mAppToken.animation : null) |
| 1617 | + " upper=" + mUpperWallpaperTarget |
| 1618 | + " lower=" + mLowerWallpaperTarget); |
| 1619 | return (wallpaperTarget != null |
| 1620 | && (!wallpaperTarget.mObscured || (wallpaperTarget.mAppToken != null |
| 1621 | && wallpaperTarget.mAppToken.animation != null))) |
| 1622 | || mUpperWallpaperTarget != null |
| 1623 | || mLowerWallpaperTarget != null; |
| 1624 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1625 | |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 1626 | static final int ADJUST_WALLPAPER_LAYERS_CHANGED = 1<<1; |
| 1627 | static final int ADJUST_WALLPAPER_VISIBILITY_CHANGED = 1<<2; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1628 | |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 1629 | int adjustWallpaperWindowsLocked() { |
| 1630 | int changed = 0; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1631 | |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1632 | final int dw = mDisplay.getWidth(); |
| 1633 | final int dh = mDisplay.getHeight(); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1634 | |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1635 | // First find top-most window that has asked to be on top of the |
| 1636 | // wallpaper; all wallpapers go behind it. |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1637 | final ArrayList<WindowState> localmWindows = mWindows; |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1638 | int N = localmWindows.size(); |
| 1639 | WindowState w = null; |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1640 | WindowState foundW = null; |
| 1641 | int foundI = 0; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1642 | WindowState topCurW = null; |
| 1643 | int topCurI = 0; |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1644 | int i = N; |
| 1645 | while (i > 0) { |
| 1646 | i--; |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1647 | w = localmWindows.get(i); |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1648 | if ((w.mAttrs.type == WindowManager.LayoutParams.TYPE_WALLPAPER)) { |
| 1649 | if (topCurW == null) { |
| 1650 | topCurW = w; |
| 1651 | topCurI = i; |
| 1652 | } |
| 1653 | continue; |
| 1654 | } |
| 1655 | topCurW = null; |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1656 | if (w.mAppToken != null) { |
| 1657 | // If this window's app token is hidden and not animating, |
| 1658 | // it is of no interest to us. |
| 1659 | if (w.mAppToken.hidden && w.mAppToken.animation == null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1660 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1661 | "Skipping hidden or animating token: " + w); |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1662 | topCurW = null; |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1663 | continue; |
| 1664 | } |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1665 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1666 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Win " + w + ": readyfordisplay=" |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1667 | + w.isReadyForDisplay() + " drawpending=" + w.mDrawPending |
| 1668 | + " commitdrawpending=" + w.mCommitDrawPending); |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1669 | if ((w.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0 && w.isReadyForDisplay() |
| Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 1670 | && (mWallpaperTarget == w |
| 1671 | || (!w.mDrawPending && !w.mCommitDrawPending))) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1672 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1673 | "Found wallpaper activity: #" + i + "=" + w); |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1674 | foundW = w; |
| 1675 | foundI = i; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1676 | if (w == mWallpaperTarget && ((w.mAppToken != null |
| 1677 | && w.mAppToken.animation != null) |
| 1678 | || w.mAnimation != null)) { |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1679 | // The current wallpaper target is animating, so we'll |
| 1680 | // look behind it for another possible target and figure |
| 1681 | // out what is going on below. |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1682 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Win " + w |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1683 | + ": token animating, looking behind."); |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1684 | continue; |
| 1685 | } |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1686 | break; |
| 1687 | } |
| 1688 | } |
| 1689 | |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 1690 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1691 | // If we are currently waiting for an app transition, and either |
| 1692 | // the current target or the next target are involved with it, |
| 1693 | // then hold off on doing anything with the wallpaper. |
| 1694 | // Note that we are checking here for just whether the target |
| 1695 | // is part of an app token... which is potentially overly aggressive |
| 1696 | // (the app token may not be involved in the transition), but good |
| 1697 | // enough (we'll just wait until whatever transition is pending |
| 1698 | // executes). |
| 1699 | if (mWallpaperTarget != null && mWallpaperTarget.mAppToken != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1700 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1701 | "Wallpaper not changing: waiting for app anim in current target"); |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 1702 | return 0; |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1703 | } |
| 1704 | if (foundW != null && foundW.mAppToken != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1705 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1706 | "Wallpaper not changing: waiting for app anim in found target"); |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 1707 | return 0; |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1708 | } |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1709 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1710 | |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1711 | if (mWallpaperTarget != foundW) { |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1712 | if (DEBUG_WALLPAPER) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1713 | Slog.v(TAG, "New wallpaper target: " + foundW |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1714 | + " oldTarget: " + mWallpaperTarget); |
| 1715 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1716 | |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1717 | mLowerWallpaperTarget = null; |
| 1718 | mUpperWallpaperTarget = null; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1719 | |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1720 | WindowState oldW = mWallpaperTarget; |
| 1721 | mWallpaperTarget = foundW; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1722 | |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1723 | // Now what is happening... if the current and new targets are |
| 1724 | // animating, then we are in our super special mode! |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1725 | if (foundW != null && oldW != null) { |
| 1726 | boolean oldAnim = oldW.mAnimation != null |
| 1727 | || (oldW.mAppToken != null && oldW.mAppToken.animation != null); |
| 1728 | boolean foundAnim = foundW.mAnimation != null |
| 1729 | || (foundW.mAppToken != null && foundW.mAppToken.animation != null); |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1730 | if (DEBUG_WALLPAPER) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1731 | Slog.v(TAG, "New animation: " + foundAnim |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1732 | + " old animation: " + oldAnim); |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1733 | } |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1734 | if (foundAnim && oldAnim) { |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1735 | int oldI = localmWindows.indexOf(oldW); |
| 1736 | if (DEBUG_WALLPAPER) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1737 | Slog.v(TAG, "New i: " + foundI + " old i: " + oldI); |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1738 | } |
| 1739 | if (oldI >= 0) { |
| 1740 | if (DEBUG_WALLPAPER) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1741 | Slog.v(TAG, "Animating wallpapers: old#" + oldI |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1742 | + "=" + oldW + "; new#" + foundI |
| 1743 | + "=" + foundW); |
| 1744 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1745 | |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1746 | // Set the new target correctly. |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1747 | if (foundW.mAppToken != null && foundW.mAppToken.hiddenRequested) { |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1748 | if (DEBUG_WALLPAPER) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1749 | Slog.v(TAG, "Old wallpaper still the target."); |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1750 | } |
| 1751 | mWallpaperTarget = oldW; |
| 1752 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1753 | |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1754 | // Now set the upper and lower wallpaper targets |
| 1755 | // correctly, and make sure that we are positioning |
| 1756 | // the wallpaper below the lower. |
| 1757 | if (foundI > oldI) { |
| 1758 | // The new target is on top of the old one. |
| 1759 | if (DEBUG_WALLPAPER) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1760 | Slog.v(TAG, "Found target above old target."); |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1761 | } |
| 1762 | mUpperWallpaperTarget = foundW; |
| 1763 | mLowerWallpaperTarget = oldW; |
| 1764 | foundW = oldW; |
| 1765 | foundI = oldI; |
| 1766 | } else { |
| 1767 | // The new target is below the old one. |
| 1768 | if (DEBUG_WALLPAPER) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1769 | Slog.v(TAG, "Found target below old target."); |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1770 | } |
| 1771 | mUpperWallpaperTarget = oldW; |
| 1772 | mLowerWallpaperTarget = foundW; |
| 1773 | } |
| 1774 | } |
| 1775 | } |
| 1776 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1777 | |
| Dianne Hackborn | 6b1cb35 | 2009-09-28 18:27:26 -0700 | [diff] [blame] | 1778 | } else if (mLowerWallpaperTarget != null) { |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1779 | // Is it time to stop animating? |
| Dianne Hackborn | 6b1cb35 | 2009-09-28 18:27:26 -0700 | [diff] [blame] | 1780 | boolean lowerAnimating = mLowerWallpaperTarget.mAnimation != null |
| 1781 | || (mLowerWallpaperTarget.mAppToken != null |
| 1782 | && mLowerWallpaperTarget.mAppToken.animation != null); |
| 1783 | boolean upperAnimating = mUpperWallpaperTarget.mAnimation != null |
| 1784 | || (mUpperWallpaperTarget.mAppToken != null |
| 1785 | && mUpperWallpaperTarget.mAppToken.animation != null); |
| 1786 | if (!lowerAnimating || !upperAnimating) { |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1787 | if (DEBUG_WALLPAPER) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1788 | Slog.v(TAG, "No longer animating wallpaper targets!"); |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1789 | } |
| 1790 | mLowerWallpaperTarget = null; |
| 1791 | mUpperWallpaperTarget = null; |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1792 | } |
| 1793 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1794 | |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1795 | boolean visible = foundW != null; |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 1796 | if (visible) { |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1797 | // The window is visible to the compositor... but is it visible |
| 1798 | // to the user? That is what the wallpaper cares about. |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 1799 | visible = isWallpaperVisible(foundW); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1800 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper visibility: " + visible); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1801 | |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1802 | // If the wallpaper target is animating, we may need to copy |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1803 | // its layer adjustment. Only do this if we are not transfering |
| 1804 | // between two wallpaper targets. |
| 1805 | mWallpaperAnimLayerAdjustment = |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1806 | (mLowerWallpaperTarget == null && foundW.mAppToken != null) |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1807 | ? foundW.mAppToken.animLayerAdjustment : 0; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1808 | |
| Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 1809 | final int maxLayer = mPolicy.getMaxWallpaperLayer() |
| 1810 | * TYPE_LAYER_MULTIPLIER |
| 1811 | + TYPE_LAYER_OFFSET; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1812 | |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1813 | // Now w is the window we are supposed to be behind... but we |
| 1814 | // 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] | 1815 | // AND any starting window associated with it, AND below the |
| 1816 | // maximum layer the policy allows for wallpapers. |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1817 | while (foundI > 0) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1818 | WindowState wb = localmWindows.get(foundI-1); |
| Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 1819 | if (wb.mBaseLayer < maxLayer && |
| 1820 | wb.mAttachedWindow != foundW && |
| Pal Szasz | 73dc259 | 2010-09-03 11:46:26 +0200 | [diff] [blame] | 1821 | wb.mAttachedWindow != foundW.mAttachedWindow && |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1822 | (wb.mAttrs.type != TYPE_APPLICATION_STARTING || |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1823 | wb.mToken != foundW.mToken)) { |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1824 | // This window is not related to the previous one in any |
| 1825 | // interesting way, so stop here. |
| 1826 | break; |
| 1827 | } |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1828 | foundW = wb; |
| 1829 | foundI--; |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1830 | } |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 1831 | } else { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1832 | if (DEBUG_WALLPAPER) Slog.v(TAG, "No wallpaper target"); |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1833 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1834 | |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1835 | if (foundW == null && topCurW != null) { |
| 1836 | // There is no wallpaper target, so it goes at the bottom. |
| 1837 | // We will assume it is the same place as last time, if known. |
| 1838 | foundW = topCurW; |
| 1839 | foundI = topCurI+1; |
| 1840 | } else { |
| 1841 | // Okay i is the position immediately above the wallpaper. Look at |
| 1842 | // what is below it for later. |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1843 | foundW = foundI > 0 ? localmWindows.get(foundI-1) : null; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1844 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1845 | |
| Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 1846 | if (visible) { |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1847 | if (mWallpaperTarget.mWallpaperX >= 0) { |
| 1848 | mLastWallpaperX = mWallpaperTarget.mWallpaperX; |
| Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 1849 | mLastWallpaperXStep = mWallpaperTarget.mWallpaperXStep; |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1850 | } |
| 1851 | if (mWallpaperTarget.mWallpaperY >= 0) { |
| 1852 | mLastWallpaperY = mWallpaperTarget.mWallpaperY; |
| Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 1853 | mLastWallpaperYStep = mWallpaperTarget.mWallpaperYStep; |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1854 | } |
| Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 1855 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1856 | |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1857 | // Start stepping backwards from here, ensuring that our wallpaper windows |
| 1858 | // are correctly placed. |
| 1859 | int curTokenIndex = mWallpaperTokens.size(); |
| 1860 | while (curTokenIndex > 0) { |
| 1861 | curTokenIndex--; |
| 1862 | WindowToken token = mWallpaperTokens.get(curTokenIndex); |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 1863 | if (token.hidden == visible) { |
| 1864 | changed |= ADJUST_WALLPAPER_VISIBILITY_CHANGED; |
| 1865 | token.hidden = !visible; |
| 1866 | // Need to do a layout to ensure the wallpaper now has the |
| 1867 | // correct size. |
| 1868 | mLayoutNeeded = true; |
| 1869 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1870 | |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1871 | int curWallpaperIndex = token.windows.size(); |
| 1872 | while (curWallpaperIndex > 0) { |
| 1873 | curWallpaperIndex--; |
| 1874 | WindowState wallpaper = token.windows.get(curWallpaperIndex); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1875 | |
| Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 1876 | if (visible) { |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1877 | updateWallpaperOffsetLocked(wallpaper, dw, dh, false); |
| Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 1878 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1879 | |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 1880 | // First, make sure the client has the current visibility |
| 1881 | // state. |
| 1882 | if (wallpaper.mWallpaperVisible != visible) { |
| 1883 | wallpaper.mWallpaperVisible = visible; |
| 1884 | try { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1885 | if (DEBUG_VISIBILITY || DEBUG_WALLPAPER) Slog.v(TAG, |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 1886 | "Setting visibility of wallpaper " + wallpaper |
| 1887 | + ": " + visible); |
| 1888 | wallpaper.mClient.dispatchAppVisibility(visible); |
| 1889 | } catch (RemoteException e) { |
| 1890 | } |
| 1891 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1892 | |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 1893 | wallpaper.mAnimLayer = wallpaper.mLayer + mWallpaperAnimLayerAdjustment; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1894 | if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper win " |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1895 | + wallpaper + " anim layer: " + wallpaper.mAnimLayer); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1896 | |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1897 | // First, if this window is at the current index, then all |
| 1898 | // is well. |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1899 | if (wallpaper == foundW) { |
| 1900 | foundI--; |
| 1901 | foundW = foundI > 0 |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1902 | ? localmWindows.get(foundI-1) : null; |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1903 | continue; |
| 1904 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1905 | |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1906 | // The window didn't match... the current wallpaper window, |
| 1907 | // wherever it is, is in the wrong place, so make sure it is |
| 1908 | // not in the list. |
| 1909 | int oldIndex = localmWindows.indexOf(wallpaper); |
| 1910 | if (oldIndex >= 0) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1911 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Wallpaper removing at " |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 1912 | + oldIndex + ": " + wallpaper); |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1913 | localmWindows.remove(oldIndex); |
| Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 1914 | mWindowsChanged = true; |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1915 | if (oldIndex < foundI) { |
| 1916 | foundI--; |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1917 | } |
| 1918 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1919 | |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1920 | // Now stick it in. |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1921 | if (DEBUG_WALLPAPER || DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 1922 | "Moving wallpaper " + wallpaper |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1923 | + " from " + oldIndex + " to " + foundI); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1924 | |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1925 | localmWindows.add(foundI, wallpaper); |
| Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 1926 | mWindowsChanged = true; |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 1927 | changed |= ADJUST_WALLPAPER_LAYERS_CHANGED; |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1928 | } |
| 1929 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1930 | |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1931 | return changed; |
| 1932 | } |
| 1933 | |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 1934 | void setWallpaperAnimLayerAdjustmentLocked(int adj) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1935 | if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG, |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1936 | "Setting wallpaper layer adj to " + adj); |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 1937 | mWallpaperAnimLayerAdjustment = adj; |
| 1938 | int curTokenIndex = mWallpaperTokens.size(); |
| 1939 | while (curTokenIndex > 0) { |
| 1940 | curTokenIndex--; |
| 1941 | WindowToken token = mWallpaperTokens.get(curTokenIndex); |
| 1942 | int curWallpaperIndex = token.windows.size(); |
| 1943 | while (curWallpaperIndex > 0) { |
| 1944 | curWallpaperIndex--; |
| 1945 | WindowState wallpaper = token.windows.get(curWallpaperIndex); |
| 1946 | wallpaper.mAnimLayer = wallpaper.mLayer + adj; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1947 | if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper win " |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1948 | + wallpaper + " anim layer: " + wallpaper.mAnimLayer); |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 1949 | } |
| 1950 | } |
| 1951 | } |
| 1952 | |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1953 | boolean updateWallpaperOffsetLocked(WindowState wallpaperWin, int dw, int dh, |
| 1954 | boolean sync) { |
| Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 1955 | boolean changed = false; |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1956 | boolean rawChanged = false; |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1957 | float wpx = mLastWallpaperX >= 0 ? mLastWallpaperX : 0.5f; |
| Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 1958 | float wpxs = mLastWallpaperXStep >= 0 ? mLastWallpaperXStep : -1.0f; |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1959 | int availw = wallpaperWin.mFrame.right-wallpaperWin.mFrame.left-dw; |
| 1960 | int offset = availw > 0 ? -(int)(availw*wpx+.5f) : 0; |
| 1961 | changed = wallpaperWin.mXOffset != offset; |
| 1962 | if (changed) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1963 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Update wallpaper " |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1964 | + wallpaperWin + " x: " + offset); |
| 1965 | wallpaperWin.mXOffset = offset; |
| 1966 | } |
| Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 1967 | if (wallpaperWin.mWallpaperX != wpx || wallpaperWin.mWallpaperXStep != wpxs) { |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1968 | wallpaperWin.mWallpaperX = wpx; |
| Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 1969 | wallpaperWin.mWallpaperXStep = wpxs; |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1970 | rawChanged = true; |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 1971 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1972 | |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1973 | float wpy = mLastWallpaperY >= 0 ? mLastWallpaperY : 0.5f; |
| Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 1974 | float wpys = mLastWallpaperYStep >= 0 ? mLastWallpaperYStep : -1.0f; |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1975 | int availh = wallpaperWin.mFrame.bottom-wallpaperWin.mFrame.top-dh; |
| 1976 | offset = availh > 0 ? -(int)(availh*wpy+.5f) : 0; |
| 1977 | if (wallpaperWin.mYOffset != offset) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1978 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Update wallpaper " |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1979 | + wallpaperWin + " y: " + offset); |
| 1980 | changed = true; |
| 1981 | wallpaperWin.mYOffset = offset; |
| 1982 | } |
| Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 1983 | if (wallpaperWin.mWallpaperY != wpy || wallpaperWin.mWallpaperYStep != wpys) { |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1984 | wallpaperWin.mWallpaperY = wpy; |
| Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 1985 | wallpaperWin.mWallpaperYStep = wpys; |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1986 | rawChanged = true; |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 1987 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1988 | |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1989 | if (rawChanged) { |
| Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 1990 | try { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1991 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Report new wp offset " |
| Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 1992 | + wallpaperWin + " x=" + wallpaperWin.mWallpaperX |
| 1993 | + " y=" + wallpaperWin.mWallpaperY); |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1994 | if (sync) { |
| Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 1995 | mWaitingOnWallpaper = wallpaperWin; |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1996 | } |
| Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 1997 | wallpaperWin.mClient.dispatchWallpaperOffsets( |
| Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 1998 | wallpaperWin.mWallpaperX, wallpaperWin.mWallpaperY, |
| 1999 | wallpaperWin.mWallpaperXStep, wallpaperWin.mWallpaperYStep, sync); |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 2000 | if (sync) { |
| Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 2001 | if (mWaitingOnWallpaper != null) { |
| 2002 | long start = SystemClock.uptimeMillis(); |
| 2003 | if ((mLastWallpaperTimeoutTime+WALLPAPER_TIMEOUT_RECOVERY) |
| 2004 | < start) { |
| 2005 | try { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2006 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
| Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 2007 | "Waiting for offset complete..."); |
| 2008 | mWindowMap.wait(WALLPAPER_TIMEOUT); |
| 2009 | } catch (InterruptedException e) { |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 2010 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2011 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Offset complete!"); |
| Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 2012 | if ((start+WALLPAPER_TIMEOUT) |
| 2013 | < SystemClock.uptimeMillis()) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2014 | Slog.i(TAG, "Timeout waiting for wallpaper to offset: " |
| Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 2015 | + wallpaperWin); |
| 2016 | mLastWallpaperTimeoutTime = start; |
| 2017 | } |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 2018 | } |
| Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 2019 | mWaitingOnWallpaper = null; |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 2020 | } |
| 2021 | } |
| Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 2022 | } catch (RemoteException e) { |
| 2023 | } |
| 2024 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2025 | |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 2026 | return changed; |
| 2027 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2028 | |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 2029 | void wallpaperOffsetsComplete(IBinder window) { |
| Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 2030 | synchronized (mWindowMap) { |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 2031 | if (mWaitingOnWallpaper != null && |
| 2032 | mWaitingOnWallpaper.mClient.asBinder() == window) { |
| 2033 | mWaitingOnWallpaper = null; |
| Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 2034 | mWindowMap.notifyAll(); |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 2035 | } |
| 2036 | } |
| 2037 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2038 | |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 2039 | boolean updateWallpaperOffsetLocked(WindowState changingTarget, boolean sync) { |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 2040 | final int dw = mDisplay.getWidth(); |
| 2041 | final int dh = mDisplay.getHeight(); |
| 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 | boolean changed = false; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2044 | |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 2045 | WindowState target = mWallpaperTarget; |
| 2046 | if (target != null) { |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 2047 | if (target.mWallpaperX >= 0) { |
| 2048 | mLastWallpaperX = target.mWallpaperX; |
| 2049 | } else if (changingTarget.mWallpaperX >= 0) { |
| 2050 | mLastWallpaperX = changingTarget.mWallpaperX; |
| 2051 | } |
| 2052 | if (target.mWallpaperY >= 0) { |
| 2053 | mLastWallpaperY = target.mWallpaperY; |
| 2054 | } else if (changingTarget.mWallpaperY >= 0) { |
| 2055 | mLastWallpaperY = changingTarget.mWallpaperY; |
| 2056 | } |
| 2057 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2058 | |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 2059 | int curTokenIndex = mWallpaperTokens.size(); |
| 2060 | while (curTokenIndex > 0) { |
| 2061 | curTokenIndex--; |
| 2062 | WindowToken token = mWallpaperTokens.get(curTokenIndex); |
| 2063 | int curWallpaperIndex = token.windows.size(); |
| 2064 | while (curWallpaperIndex > 0) { |
| 2065 | curWallpaperIndex--; |
| 2066 | WindowState wallpaper = token.windows.get(curWallpaperIndex); |
| 2067 | if (updateWallpaperOffsetLocked(wallpaper, dw, dh, sync)) { |
| 2068 | wallpaper.computeShownFrameLocked(); |
| 2069 | changed = true; |
| 2070 | // We only want to be synchronous with one wallpaper. |
| 2071 | sync = false; |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 2072 | } |
| 2073 | } |
| 2074 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2075 | |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 2076 | return changed; |
| 2077 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2078 | |
| Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 2079 | void updateWallpaperVisibilityLocked() { |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 2080 | final boolean visible = isWallpaperVisible(mWallpaperTarget); |
| Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 2081 | final int dw = mDisplay.getWidth(); |
| 2082 | final int dh = mDisplay.getHeight(); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2083 | |
| Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 2084 | int curTokenIndex = mWallpaperTokens.size(); |
| 2085 | while (curTokenIndex > 0) { |
| 2086 | curTokenIndex--; |
| 2087 | WindowToken token = mWallpaperTokens.get(curTokenIndex); |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 2088 | if (token.hidden == visible) { |
| 2089 | token.hidden = !visible; |
| 2090 | // Need to do a layout to ensure the wallpaper now has the |
| 2091 | // correct size. |
| 2092 | mLayoutNeeded = true; |
| 2093 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2094 | |
| Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 2095 | int curWallpaperIndex = token.windows.size(); |
| 2096 | while (curWallpaperIndex > 0) { |
| 2097 | curWallpaperIndex--; |
| 2098 | WindowState wallpaper = token.windows.get(curWallpaperIndex); |
| 2099 | if (visible) { |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 2100 | updateWallpaperOffsetLocked(wallpaper, dw, dh, false); |
| Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 2101 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2102 | |
| Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 2103 | if (wallpaper.mWallpaperVisible != visible) { |
| 2104 | wallpaper.mWallpaperVisible = visible; |
| 2105 | try { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2106 | if (DEBUG_VISIBILITY || DEBUG_WALLPAPER) Slog.v(TAG, |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 2107 | "Updating visibility of wallpaper " + wallpaper |
| Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 2108 | + ": " + visible); |
| 2109 | wallpaper.mClient.dispatchAppVisibility(visible); |
| 2110 | } catch (RemoteException e) { |
| 2111 | } |
| 2112 | } |
| 2113 | } |
| 2114 | } |
| 2115 | } |
| Dianne Hackborn | 90d2db3 | 2010-02-11 22:19:06 -0800 | [diff] [blame] | 2116 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2117 | public int addWindow(Session session, IWindow client, |
| 2118 | WindowManager.LayoutParams attrs, int viewVisibility, |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 2119 | Rect outContentInsets, InputChannel outInputChannel) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2120 | int res = mPolicy.checkAddPermission(attrs); |
| 2121 | if (res != WindowManagerImpl.ADD_OKAY) { |
| 2122 | return res; |
| 2123 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2124 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2125 | boolean reportNewConfig = false; |
| 2126 | WindowState attachedWindow = null; |
| 2127 | WindowState win = null; |
| Dianne Hackborn | 5132b37 | 2010-07-29 12:51:35 -0700 | [diff] [blame] | 2128 | long origId; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2129 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2130 | synchronized(mWindowMap) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2131 | if (mDisplay == null) { |
| Dianne Hackborn | 5132b37 | 2010-07-29 12:51:35 -0700 | [diff] [blame] | 2132 | throw new IllegalStateException("Display has not been initialialized"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2133 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2134 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2135 | if (mWindowMap.containsKey(client.asBinder())) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2136 | Slog.w(TAG, "Window " + client + " is already added"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2137 | return WindowManagerImpl.ADD_DUPLICATE_ADD; |
| 2138 | } |
| 2139 | |
| 2140 | if (attrs.type >= FIRST_SUB_WINDOW && attrs.type <= LAST_SUB_WINDOW) { |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2141 | attachedWindow = windowForClientLocked(null, attrs.token, false); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2142 | if (attachedWindow == null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2143 | 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] | 2144 | + attrs.token + ". Aborting."); |
| 2145 | return WindowManagerImpl.ADD_BAD_SUBWINDOW_TOKEN; |
| 2146 | } |
| 2147 | if (attachedWindow.mAttrs.type >= FIRST_SUB_WINDOW |
| 2148 | && attachedWindow.mAttrs.type <= LAST_SUB_WINDOW) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2149 | 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] | 2150 | + attrs.token + ". Aborting."); |
| 2151 | return WindowManagerImpl.ADD_BAD_SUBWINDOW_TOKEN; |
| 2152 | } |
| 2153 | } |
| 2154 | |
| 2155 | boolean addToken = false; |
| 2156 | WindowToken token = mTokenMap.get(attrs.token); |
| 2157 | if (token == null) { |
| 2158 | if (attrs.type >= FIRST_APPLICATION_WINDOW |
| 2159 | && attrs.type <= LAST_APPLICATION_WINDOW) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2160 | 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] | 2161 | + attrs.token + ". Aborting."); |
| 2162 | return WindowManagerImpl.ADD_BAD_APP_TOKEN; |
| 2163 | } |
| 2164 | if (attrs.type == TYPE_INPUT_METHOD) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2165 | 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] | 2166 | + attrs.token + ". Aborting."); |
| 2167 | return WindowManagerImpl.ADD_BAD_APP_TOKEN; |
| 2168 | } |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2169 | if (attrs.type == TYPE_WALLPAPER) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2170 | Slog.w(TAG, "Attempted to add wallpaper window with unknown token " |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2171 | + attrs.token + ". Aborting."); |
| 2172 | return WindowManagerImpl.ADD_BAD_APP_TOKEN; |
| 2173 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2174 | token = new WindowToken(attrs.token, -1, false); |
| 2175 | addToken = true; |
| 2176 | } else if (attrs.type >= FIRST_APPLICATION_WINDOW |
| 2177 | && attrs.type <= LAST_APPLICATION_WINDOW) { |
| 2178 | AppWindowToken atoken = token.appWindowToken; |
| 2179 | if (atoken == null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2180 | 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] | 2181 | + token + ". Aborting."); |
| 2182 | return WindowManagerImpl.ADD_NOT_APP_TOKEN; |
| 2183 | } else if (atoken.removed) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2184 | 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] | 2185 | + token + ". Aborting."); |
| 2186 | return WindowManagerImpl.ADD_APP_EXITING; |
| 2187 | } |
| 2188 | if (attrs.type == TYPE_APPLICATION_STARTING && atoken.firstWindowDrawn) { |
| 2189 | // No need for this guy! |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2190 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2191 | TAG, "**** NO NEED TO START: " + attrs.getTitle()); |
| 2192 | return WindowManagerImpl.ADD_STARTING_NOT_NEEDED; |
| 2193 | } |
| 2194 | } else if (attrs.type == TYPE_INPUT_METHOD) { |
| 2195 | if (token.windowType != TYPE_INPUT_METHOD) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2196 | 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] | 2197 | + attrs.token + ". Aborting."); |
| 2198 | return WindowManagerImpl.ADD_BAD_APP_TOKEN; |
| 2199 | } |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2200 | } else if (attrs.type == TYPE_WALLPAPER) { |
| 2201 | if (token.windowType != TYPE_WALLPAPER) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2202 | Slog.w(TAG, "Attempted to add wallpaper window with bad token " |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2203 | + attrs.token + ". Aborting."); |
| 2204 | return WindowManagerImpl.ADD_BAD_APP_TOKEN; |
| 2205 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2206 | } |
| 2207 | |
| 2208 | win = new WindowState(session, client, token, |
| 2209 | attachedWindow, attrs, viewVisibility); |
| 2210 | if (win.mDeathRecipient == null) { |
| 2211 | // Client has apparently died, so there is no reason to |
| 2212 | // continue. |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2213 | Slog.w(TAG, "Adding window client " + client.asBinder() |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2214 | + " that is dead, aborting."); |
| 2215 | return WindowManagerImpl.ADD_APP_EXITING; |
| 2216 | } |
| 2217 | |
| 2218 | mPolicy.adjustWindowParamsLw(win.mAttrs); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2219 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2220 | res = mPolicy.prepareAddWindowLw(win, attrs); |
| 2221 | if (res != WindowManagerImpl.ADD_OKAY) { |
| 2222 | return res; |
| 2223 | } |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 2224 | |
| Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 2225 | if (outInputChannel != null) { |
| 2226 | String name = win.makeInputChannelName(); |
| 2227 | InputChannel[] inputChannels = InputChannel.openInputChannelPair(name); |
| 2228 | win.mInputChannel = inputChannels[0]; |
| 2229 | inputChannels[1].transferToBinderOutParameter(outInputChannel); |
| 2230 | |
| 2231 | mInputManager.registerInputChannel(win.mInputChannel); |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 2232 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2233 | |
| 2234 | // From now on, no exceptions or errors allowed! |
| 2235 | |
| 2236 | res = WindowManagerImpl.ADD_OKAY; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2237 | |
| Dianne Hackborn | 5132b37 | 2010-07-29 12:51:35 -0700 | [diff] [blame] | 2238 | origId = Binder.clearCallingIdentity(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2239 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2240 | if (addToken) { |
| 2241 | mTokenMap.put(attrs.token, token); |
| 2242 | mTokenList.add(token); |
| 2243 | } |
| 2244 | win.attach(); |
| 2245 | mWindowMap.put(client.asBinder(), win); |
| 2246 | |
| 2247 | if (attrs.type == TYPE_APPLICATION_STARTING && |
| 2248 | token.appWindowToken != null) { |
| 2249 | token.appWindowToken.startingWindow = win; |
| 2250 | } |
| 2251 | |
| 2252 | boolean imMayMove = true; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2253 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2254 | if (attrs.type == TYPE_INPUT_METHOD) { |
| 2255 | mInputMethodWindow = win; |
| 2256 | addInputMethodWindowToListLocked(win); |
| 2257 | imMayMove = false; |
| 2258 | } else if (attrs.type == TYPE_INPUT_METHOD_DIALOG) { |
| 2259 | mInputMethodDialogs.add(win); |
| 2260 | addWindowToListInOrderLocked(win, true); |
| 2261 | adjustInputMethodDialogsLocked(); |
| 2262 | imMayMove = false; |
| 2263 | } else { |
| 2264 | addWindowToListInOrderLocked(win, true); |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 2265 | if (attrs.type == TYPE_WALLPAPER) { |
| 2266 | mLastWallpaperTimeoutTime = 0; |
| 2267 | adjustWallpaperWindowsLocked(); |
| 2268 | } else if ((attrs.flags&FLAG_SHOW_WALLPAPER) != 0) { |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2269 | adjustWallpaperWindowsLocked(); |
| 2270 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2271 | } |
| 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 | win.mEnterAnimationPending = true; |
| 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 | mPolicy.getContentInsetHintLw(attrs, outContentInsets); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2276 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2277 | if (mInTouchMode) { |
| 2278 | res |= WindowManagerImpl.ADD_FLAG_IN_TOUCH_MODE; |
| 2279 | } |
| 2280 | if (win == null || win.mAppToken == null || !win.mAppToken.clientHidden) { |
| 2281 | res |= WindowManagerImpl.ADD_FLAG_APP_VISIBLE; |
| 2282 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2283 | |
| The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 2284 | boolean focusChanged = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2285 | if (win.canReceiveKeys()) { |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 2286 | focusChanged = updateFocusedWindowLocked(UPDATE_FOCUS_WILL_ASSIGN_LAYERS); |
| 2287 | if (focusChanged) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2288 | imMayMove = false; |
| 2289 | } |
| 2290 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2291 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2292 | if (imMayMove) { |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2293 | moveInputMethodWindowsIfNeededLocked(false); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2294 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2295 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2296 | assignLayersLocked(); |
| 2297 | // Don't do layout here, the window must call |
| 2298 | // relayout to be displayed, so we'll do it there. |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2299 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2300 | //dump(); |
| 2301 | |
| The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 2302 | if (focusChanged) { |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 2303 | finishUpdateFocusedWindowAfterAssignLayersLocked(); |
| The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 2304 | } |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 2305 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2306 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2307 | TAG, "New client " + client.asBinder() |
| 2308 | + ": window=" + win); |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2309 | |
| 2310 | if (win.isVisibleOrAdding() && updateOrientationFromAppTokensLocked()) { |
| 2311 | reportNewConfig = true; |
| 2312 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2313 | } |
| 2314 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2315 | if (reportNewConfig) { |
| 2316 | sendNewConfiguration(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2317 | } |
| Dianne Hackborn | 5132b37 | 2010-07-29 12:51:35 -0700 | [diff] [blame] | 2318 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2319 | Binder.restoreCallingIdentity(origId); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2320 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2321 | return res; |
| 2322 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2323 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2324 | public void removeWindow(Session session, IWindow client) { |
| 2325 | synchronized(mWindowMap) { |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2326 | WindowState win = windowForClientLocked(session, client, false); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2327 | if (win == null) { |
| 2328 | return; |
| 2329 | } |
| 2330 | removeWindowLocked(session, win); |
| 2331 | } |
| 2332 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2333 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2334 | public void removeWindowLocked(Session session, WindowState win) { |
| 2335 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2336 | if (localLOGV || DEBUG_FOCUS) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2337 | TAG, "Remove " + win + " client=" |
| 2338 | + Integer.toHexString(System.identityHashCode( |
| 2339 | win.mClient.asBinder())) |
| 2340 | + ", surface=" + win.mSurface); |
| 2341 | |
| 2342 | final long origId = Binder.clearCallingIdentity(); |
| Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 2343 | |
| 2344 | win.disposeInputChannel(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2345 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2346 | if (DEBUG_APP_TRANSITIONS) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2347 | TAG, "Remove " + win + ": mSurface=" + win.mSurface |
| 2348 | + " mExiting=" + win.mExiting |
| 2349 | + " isAnimating=" + win.isAnimating() |
| 2350 | + " app-animation=" |
| 2351 | + (win.mAppToken != null ? win.mAppToken.animation : null) |
| 2352 | + " inPendingTransaction=" |
| 2353 | + (win.mAppToken != null ? win.mAppToken.inPendingTransaction : false) |
| 2354 | + " mDisplayFrozen=" + mDisplayFrozen); |
| 2355 | // Visibility of the removed window. Will be used later to update orientation later on. |
| 2356 | boolean wasVisible = false; |
| 2357 | // First, see if we need to run an animation. If we do, we have |
| 2358 | // to hold off on removing the window until the animation is done. |
| 2359 | // If the display is frozen, just remove immediately, since the |
| 2360 | // animation wouldn't be seen. |
| Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 2361 | if (win.mSurface != null && !mDisplayFrozen && mPolicy.isScreenOn()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2362 | // If we are not currently running the exit animation, we |
| 2363 | // need to see about starting one. |
| 2364 | if (wasVisible=win.isWinVisibleLw()) { |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2365 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2366 | int transit = WindowManagerPolicy.TRANSIT_EXIT; |
| 2367 | if (win.getAttrs().type == TYPE_APPLICATION_STARTING) { |
| 2368 | transit = WindowManagerPolicy.TRANSIT_PREVIEW_DONE; |
| 2369 | } |
| 2370 | // Try starting an animation. |
| 2371 | if (applyAnimationLocked(win, transit, false)) { |
| 2372 | win.mExiting = true; |
| 2373 | } |
| 2374 | } |
| 2375 | if (win.mExiting || win.isAnimating()) { |
| 2376 | // The exit animation is running... wait for it! |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2377 | //Slog.i(TAG, "*** Running exit animation..."); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2378 | win.mExiting = true; |
| 2379 | win.mRemoveOnExit = true; |
| 2380 | mLayoutNeeded = true; |
| 2381 | updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES); |
| 2382 | performLayoutAndPlaceSurfacesLocked(); |
| 2383 | if (win.mAppToken != null) { |
| 2384 | win.mAppToken.updateReportedVisibilityLocked(); |
| 2385 | } |
| 2386 | //dump(); |
| 2387 | Binder.restoreCallingIdentity(origId); |
| 2388 | return; |
| 2389 | } |
| 2390 | } |
| 2391 | |
| 2392 | removeWindowInnerLocked(session, win); |
| 2393 | // Removing a visible window will effect the computed orientation |
| 2394 | // So just update orientation if needed. |
| The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 2395 | if (wasVisible && computeForcedAppOrientationLocked() |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2396 | != mForcedAppOrientation |
| 2397 | && updateOrientationFromAppTokensLocked()) { |
| 2398 | mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2399 | } |
| 2400 | updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL); |
| 2401 | Binder.restoreCallingIdentity(origId); |
| 2402 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2403 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2404 | private void removeWindowInnerLocked(Session session, WindowState win) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2405 | win.mRemoved = true; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2406 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2407 | if (mInputMethodTarget == win) { |
| 2408 | moveInputMethodWindowsIfNeededLocked(false); |
| 2409 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2410 | |
| Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 2411 | if (false) { |
| 2412 | RuntimeException e = new RuntimeException("here"); |
| 2413 | e.fillInStackTrace(); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2414 | Slog.w(TAG, "Removing window " + win, e); |
| Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 2415 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2416 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2417 | mPolicy.removeWindowLw(win); |
| 2418 | win.removeLocked(); |
| 2419 | |
| 2420 | mWindowMap.remove(win.mClient.asBinder()); |
| 2421 | mWindows.remove(win); |
| Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 2422 | mWindowsChanged = true; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2423 | 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] | 2424 | |
| 2425 | if (mInputMethodWindow == win) { |
| 2426 | mInputMethodWindow = null; |
| 2427 | } else if (win.mAttrs.type == TYPE_INPUT_METHOD_DIALOG) { |
| 2428 | mInputMethodDialogs.remove(win); |
| 2429 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2430 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2431 | final WindowToken token = win.mToken; |
| 2432 | final AppWindowToken atoken = win.mAppToken; |
| 2433 | token.windows.remove(win); |
| 2434 | if (atoken != null) { |
| 2435 | atoken.allAppWindows.remove(win); |
| 2436 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2437 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2438 | TAG, "**** Removing window " + win + ": count=" |
| 2439 | + token.windows.size()); |
| 2440 | if (token.windows.size() == 0) { |
| 2441 | if (!token.explicit) { |
| 2442 | mTokenMap.remove(token.token); |
| 2443 | mTokenList.remove(token); |
| 2444 | } else if (atoken != null) { |
| 2445 | atoken.firstWindowDrawn = false; |
| 2446 | } |
| 2447 | } |
| 2448 | |
| 2449 | if (atoken != null) { |
| 2450 | if (atoken.startingWindow == win) { |
| 2451 | atoken.startingWindow = null; |
| 2452 | } else if (atoken.allAppWindows.size() == 0 && atoken.startingData != null) { |
| 2453 | // If this is the last window and we had requested a starting |
| 2454 | // transition window, well there is no point now. |
| 2455 | atoken.startingData = null; |
| 2456 | } else if (atoken.allAppWindows.size() == 1 && atoken.startingView != null) { |
| 2457 | // If this is the last window except for a starting transition |
| 2458 | // window, we need to get rid of the starting transition. |
| 2459 | if (DEBUG_STARTING_WINDOW) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2460 | Slog.v(TAG, "Schedule remove starting " + token |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2461 | + ": no more real windows"); |
| 2462 | } |
| 2463 | Message m = mH.obtainMessage(H.REMOVE_STARTING, atoken); |
| 2464 | mH.sendMessage(m); |
| 2465 | } |
| 2466 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2467 | |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 2468 | if (win.mAttrs.type == TYPE_WALLPAPER) { |
| 2469 | mLastWallpaperTimeoutTime = 0; |
| 2470 | adjustWallpaperWindowsLocked(); |
| 2471 | } else if ((win.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0) { |
| Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 2472 | adjustWallpaperWindowsLocked(); |
| 2473 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2474 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2475 | if (!mInLayout) { |
| 2476 | assignLayersLocked(); |
| 2477 | mLayoutNeeded = true; |
| 2478 | performLayoutAndPlaceSurfacesLocked(); |
| 2479 | if (win.mAppToken != null) { |
| 2480 | win.mAppToken.updateReportedVisibilityLocked(); |
| 2481 | } |
| 2482 | } |
| Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 2483 | |
| 2484 | mInputMonitor.updateInputWindowsLw(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2485 | } |
| 2486 | |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 2487 | private static void logSurface(WindowState w, String msg, RuntimeException where) { |
| 2488 | String str = " SURFACE " + Integer.toHexString(w.hashCode()) |
| 2489 | + ": " + msg + " / " + w.mAttrs.getTitle(); |
| 2490 | if (where != null) { |
| 2491 | Slog.i(TAG, str, where); |
| 2492 | } else { |
| 2493 | Slog.i(TAG, str); |
| 2494 | } |
| 2495 | } |
| 2496 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2497 | private void setTransparentRegionWindow(Session session, IWindow client, Region region) { |
| 2498 | long origId = Binder.clearCallingIdentity(); |
| 2499 | try { |
| 2500 | synchronized (mWindowMap) { |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2501 | WindowState w = windowForClientLocked(session, client, false); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2502 | if ((w != null) && (w.mSurface != null)) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2503 | if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2504 | Surface.openTransaction(); |
| 2505 | try { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 2506 | if (SHOW_TRANSACTIONS) logSurface(w, |
| 2507 | "transparentRegionHint=" + region, null); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2508 | w.mSurface.setTransparentRegionHint(region); |
| 2509 | } finally { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2510 | if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2511 | Surface.closeTransaction(); |
| 2512 | } |
| 2513 | } |
| 2514 | } |
| 2515 | } finally { |
| 2516 | Binder.restoreCallingIdentity(origId); |
| 2517 | } |
| 2518 | } |
| 2519 | |
| 2520 | void setInsetsWindow(Session session, IWindow client, |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2521 | int touchableInsets, Rect contentInsets, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2522 | Rect visibleInsets) { |
| 2523 | long origId = Binder.clearCallingIdentity(); |
| 2524 | try { |
| 2525 | synchronized (mWindowMap) { |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2526 | WindowState w = windowForClientLocked(session, client, false); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2527 | if (w != null) { |
| 2528 | w.mGivenInsetsPending = false; |
| 2529 | w.mGivenContentInsets.set(contentInsets); |
| 2530 | w.mGivenVisibleInsets.set(visibleInsets); |
| 2531 | w.mTouchableInsets = touchableInsets; |
| 2532 | mLayoutNeeded = true; |
| 2533 | performLayoutAndPlaceSurfacesLocked(); |
| 2534 | } |
| 2535 | } |
| 2536 | } finally { |
| 2537 | Binder.restoreCallingIdentity(origId); |
| 2538 | } |
| 2539 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2540 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2541 | public void getWindowDisplayFrame(Session session, IWindow client, |
| 2542 | Rect outDisplayFrame) { |
| 2543 | synchronized(mWindowMap) { |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2544 | WindowState win = windowForClientLocked(session, client, false); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2545 | if (win == null) { |
| 2546 | outDisplayFrame.setEmpty(); |
| 2547 | return; |
| 2548 | } |
| 2549 | outDisplayFrame.set(win.mDisplayFrame); |
| 2550 | } |
| 2551 | } |
| 2552 | |
| Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 2553 | public void setWindowWallpaperPositionLocked(WindowState window, float x, float y, |
| 2554 | float xStep, float yStep) { |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 2555 | if (window.mWallpaperX != x || window.mWallpaperY != y) { |
| 2556 | window.mWallpaperX = x; |
| 2557 | window.mWallpaperY = y; |
| Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 2558 | window.mWallpaperXStep = xStep; |
| 2559 | window.mWallpaperYStep = yStep; |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 2560 | if (updateWallpaperOffsetLocked(window, true)) { |
| 2561 | performLayoutAndPlaceSurfacesLocked(); |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 2562 | } |
| 2563 | } |
| 2564 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2565 | |
| Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 2566 | void wallpaperCommandComplete(IBinder window, Bundle result) { |
| 2567 | synchronized (mWindowMap) { |
| 2568 | if (mWaitingOnWallpaper != null && |
| 2569 | mWaitingOnWallpaper.mClient.asBinder() == window) { |
| 2570 | mWaitingOnWallpaper = null; |
| 2571 | mWindowMap.notifyAll(); |
| 2572 | } |
| 2573 | } |
| 2574 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2575 | |
| Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 2576 | public Bundle sendWindowWallpaperCommandLocked(WindowState window, |
| 2577 | String action, int x, int y, int z, Bundle extras, boolean sync) { |
| 2578 | if (window == mWallpaperTarget || window == mLowerWallpaperTarget |
| 2579 | || window == mUpperWallpaperTarget) { |
| 2580 | boolean doWait = sync; |
| 2581 | int curTokenIndex = mWallpaperTokens.size(); |
| 2582 | while (curTokenIndex > 0) { |
| 2583 | curTokenIndex--; |
| 2584 | WindowToken token = mWallpaperTokens.get(curTokenIndex); |
| 2585 | int curWallpaperIndex = token.windows.size(); |
| 2586 | while (curWallpaperIndex > 0) { |
| 2587 | curWallpaperIndex--; |
| 2588 | WindowState wallpaper = token.windows.get(curWallpaperIndex); |
| 2589 | try { |
| 2590 | wallpaper.mClient.dispatchWallpaperCommand(action, |
| 2591 | x, y, z, extras, sync); |
| 2592 | // We only want to be synchronous with one wallpaper. |
| 2593 | sync = false; |
| 2594 | } catch (RemoteException e) { |
| 2595 | } |
| 2596 | } |
| 2597 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2598 | |
| Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 2599 | if (doWait) { |
| 2600 | // XXX Need to wait for result. |
| 2601 | } |
| 2602 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2603 | |
| Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 2604 | return null; |
| 2605 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2606 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2607 | public int relayoutWindow(Session session, IWindow client, |
| 2608 | WindowManager.LayoutParams attrs, int requestedWidth, |
| 2609 | int requestedHeight, int viewVisibility, boolean insetsPending, |
| 2610 | Rect outFrame, Rect outContentInsets, Rect outVisibleInsets, |
| Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 2611 | Configuration outConfig, Surface outSurface) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2612 | boolean displayed = false; |
| 2613 | boolean inTouchMode; |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2614 | boolean configChanged; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2615 | long origId = Binder.clearCallingIdentity(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2616 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2617 | synchronized(mWindowMap) { |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2618 | WindowState win = windowForClientLocked(session, client, false); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2619 | if (win == null) { |
| 2620 | return 0; |
| 2621 | } |
| 2622 | win.mRequestedWidth = requestedWidth; |
| 2623 | win.mRequestedHeight = requestedHeight; |
| 2624 | |
| 2625 | if (attrs != null) { |
| 2626 | mPolicy.adjustWindowParamsLw(attrs); |
| 2627 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2628 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2629 | int attrChanges = 0; |
| 2630 | int flagChanges = 0; |
| 2631 | if (attrs != null) { |
| 2632 | flagChanges = win.mAttrs.flags ^= attrs.flags; |
| 2633 | attrChanges = win.mAttrs.copyFrom(attrs); |
| 2634 | } |
| 2635 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2636 | 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] | 2637 | |
| 2638 | if ((attrChanges & WindowManager.LayoutParams.ALPHA_CHANGED) != 0) { |
| 2639 | win.mAlpha = attrs.alpha; |
| 2640 | } |
| 2641 | |
| 2642 | final boolean scaledWindow = |
| 2643 | ((win.mAttrs.flags & WindowManager.LayoutParams.FLAG_SCALED) != 0); |
| 2644 | |
| 2645 | if (scaledWindow) { |
| 2646 | // requested{Width|Height} Surface's physical size |
| 2647 | // attrs.{width|height} Size on screen |
| 2648 | win.mHScale = (attrs.width != requestedWidth) ? |
| 2649 | (attrs.width / (float)requestedWidth) : 1.0f; |
| 2650 | win.mVScale = (attrs.height != requestedHeight) ? |
| 2651 | (attrs.height / (float)requestedHeight) : 1.0f; |
| Dianne Hackborn | 9b52a21 | 2009-12-11 14:51:35 -0800 | [diff] [blame] | 2652 | } else { |
| 2653 | win.mHScale = win.mVScale = 1; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2654 | } |
| 2655 | |
| 2656 | boolean imMayMove = (flagChanges&( |
| 2657 | WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM | |
| 2658 | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE)) != 0; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2659 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2660 | boolean focusMayChange = win.mViewVisibility != viewVisibility |
| 2661 | || ((flagChanges&WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) != 0) |
| 2662 | || (!win.mRelayoutCalled); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2663 | |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2664 | boolean wallpaperMayMove = win.mViewVisibility != viewVisibility |
| 2665 | && (win.mAttrs.flags & FLAG_SHOW_WALLPAPER) != 0; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2666 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2667 | win.mRelayoutCalled = true; |
| 2668 | final int oldVisibility = win.mViewVisibility; |
| 2669 | win.mViewVisibility = viewVisibility; |
| 2670 | if (viewVisibility == View.VISIBLE && |
| 2671 | (win.mAppToken == null || !win.mAppToken.clientHidden)) { |
| 2672 | displayed = !win.isVisibleLw(); |
| 2673 | if (win.mExiting) { |
| 2674 | win.mExiting = false; |
| 2675 | win.mAnimation = null; |
| 2676 | } |
| 2677 | if (win.mDestroying) { |
| 2678 | win.mDestroying = false; |
| 2679 | mDestroySurface.remove(win); |
| 2680 | } |
| 2681 | if (oldVisibility == View.GONE) { |
| 2682 | win.mEnterAnimationPending = true; |
| 2683 | } |
| Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 2684 | if (displayed) { |
| 2685 | if (win.mSurface != null && !win.mDrawPending |
| 2686 | && !win.mCommitDrawPending && !mDisplayFrozen |
| 2687 | && mPolicy.isScreenOn()) { |
| 2688 | applyEnterAnimationLocked(win); |
| 2689 | } |
| 2690 | if ((win.mAttrs.flags |
| 2691 | & WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON) != 0) { |
| 2692 | if (DEBUG_VISIBILITY) Slog.v(TAG, |
| 2693 | "Relayout window turning screen on: " + win); |
| 2694 | win.mTurnOnScreen = true; |
| 2695 | } |
| 2696 | int diff = 0; |
| 2697 | if (win.mConfiguration != mCurConfiguration |
| 2698 | && (win.mConfiguration == null |
| 2699 | || (diff=mCurConfiguration.diff(win.mConfiguration)) != 0)) { |
| 2700 | win.mConfiguration = mCurConfiguration; |
| 2701 | if (DEBUG_CONFIGURATION) { |
| 2702 | Slog.i(TAG, "Window " + win + " visible with new config: " |
| 2703 | + win.mConfiguration + " / 0x" |
| 2704 | + Integer.toHexString(diff)); |
| 2705 | } |
| 2706 | outConfig.setTo(mCurConfiguration); |
| 2707 | } |
| Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 2708 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2709 | if ((attrChanges&WindowManager.LayoutParams.FORMAT_CHANGED) != 0) { |
| 2710 | // To change the format, we need to re-build the surface. |
| 2711 | win.destroySurfaceLocked(); |
| 2712 | displayed = true; |
| 2713 | } |
| 2714 | try { |
| 2715 | Surface surface = win.createSurfaceLocked(); |
| 2716 | if (surface != null) { |
| 2717 | outSurface.copyFrom(surface); |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2718 | win.mReportDestroySurface = false; |
| 2719 | win.mSurfacePendingDestroy = false; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2720 | if (SHOW_TRANSACTIONS) Slog.i(TAG, |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 2721 | " OUT SURFACE " + outSurface + ": copied"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2722 | } else { |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 2723 | // For some reason there isn't a surface. Clear the |
| 2724 | // caller's object so they see the same state. |
| 2725 | outSurface.release(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2726 | } |
| 2727 | } catch (Exception e) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 2728 | mInputMonitor.updateInputWindowsLw(); |
| 2729 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2730 | Slog.w(TAG, "Exception thrown when creating surface for client " |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 2731 | + client + " (" + win.mAttrs.getTitle() + ")", |
| 2732 | e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2733 | Binder.restoreCallingIdentity(origId); |
| 2734 | return 0; |
| 2735 | } |
| 2736 | if (displayed) { |
| 2737 | focusMayChange = true; |
| 2738 | } |
| 2739 | if (win.mAttrs.type == TYPE_INPUT_METHOD |
| 2740 | && mInputMethodWindow == null) { |
| 2741 | mInputMethodWindow = win; |
| 2742 | imMayMove = true; |
| 2743 | } |
| Dianne Hackborn | 558947c | 2009-12-18 16:02:50 -0800 | [diff] [blame] | 2744 | if (win.mAttrs.type == TYPE_BASE_APPLICATION |
| 2745 | && win.mAppToken != null |
| 2746 | && win.mAppToken.startingWindow != null) { |
| 2747 | // Special handling of starting window over the base |
| 2748 | // window of the app: propagate lock screen flags to it, |
| 2749 | // to provide the correct semantics while starting. |
| 2750 | final int mask = |
| 2751 | WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED |
| Mike Lockwood | ef73162 | 2010-01-27 17:51:34 -0500 | [diff] [blame] | 2752 | | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD |
| 2753 | | WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON; |
| Dianne Hackborn | 558947c | 2009-12-18 16:02:50 -0800 | [diff] [blame] | 2754 | WindowManager.LayoutParams sa = win.mAppToken.startingWindow.mAttrs; |
| 2755 | sa.flags = (sa.flags&~mask) | (win.mAttrs.flags&mask); |
| 2756 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2757 | } else { |
| 2758 | win.mEnterAnimationPending = false; |
| 2759 | if (win.mSurface != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2760 | if (DEBUG_VISIBILITY) Slog.i(TAG, "Relayout invis " + win |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2761 | + ": mExiting=" + win.mExiting |
| 2762 | + " mSurfacePendingDestroy=" + win.mSurfacePendingDestroy); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2763 | // If we are not currently running the exit animation, we |
| 2764 | // need to see about starting one. |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2765 | if (!win.mExiting || win.mSurfacePendingDestroy) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2766 | // Try starting an animation; if there isn't one, we |
| 2767 | // can destroy the surface right away. |
| 2768 | int transit = WindowManagerPolicy.TRANSIT_EXIT; |
| 2769 | if (win.getAttrs().type == TYPE_APPLICATION_STARTING) { |
| 2770 | transit = WindowManagerPolicy.TRANSIT_PREVIEW_DONE; |
| 2771 | } |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2772 | if (!win.mSurfacePendingDestroy && win.isWinVisibleLw() && |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2773 | applyAnimationLocked(win, transit, false)) { |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2774 | focusMayChange = true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2775 | win.mExiting = true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2776 | } else if (win.isAnimating()) { |
| 2777 | // Currently in a hide animation... turn this into |
| 2778 | // an exit. |
| 2779 | win.mExiting = true; |
| Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 2780 | } else if (win == mWallpaperTarget) { |
| 2781 | // If the wallpaper is currently behind this |
| 2782 | // window, we need to change both of them inside |
| 2783 | // of a transaction to avoid artifacts. |
| 2784 | win.mExiting = true; |
| 2785 | win.mAnimating = true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2786 | } else { |
| 2787 | if (mInputMethodWindow == win) { |
| 2788 | mInputMethodWindow = null; |
| 2789 | } |
| 2790 | win.destroySurfaceLocked(); |
| 2791 | } |
| 2792 | } |
| 2793 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2794 | |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2795 | if (win.mSurface == null || (win.getAttrs().flags |
| 2796 | & WindowManager.LayoutParams.FLAG_KEEP_SURFACE_WHILE_ANIMATING) == 0 |
| 2797 | || win.mSurfacePendingDestroy) { |
| 2798 | // We are being called from a local process, which |
| 2799 | // means outSurface holds its current surface. Ensure the |
| 2800 | // surface object is cleared, but we don't want it actually |
| 2801 | // destroyed at this point. |
| 2802 | win.mSurfacePendingDestroy = false; |
| 2803 | outSurface.release(); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2804 | if (DEBUG_VISIBILITY) Slog.i(TAG, "Releasing surface in: " + win); |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2805 | } else if (win.mSurface != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2806 | if (DEBUG_VISIBILITY) Slog.i(TAG, |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2807 | "Keeping surface, will report destroy: " + win); |
| 2808 | win.mReportDestroySurface = true; |
| 2809 | outSurface.copyFrom(win.mSurface); |
| 2810 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2811 | } |
| 2812 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2813 | if (focusMayChange) { |
| 2814 | //System.out.println("Focus may change: " + win.mAttrs.getTitle()); |
| 2815 | if (updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES)) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2816 | imMayMove = false; |
| 2817 | } |
| 2818 | //System.out.println("Relayout " + win + ": focus=" + mCurrentFocus); |
| 2819 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2820 | |
| The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 2821 | // updateFocusedWindowLocked() already assigned layers so we only need to |
| 2822 | // reassign them at this point if the IM window state gets shuffled |
| 2823 | boolean assignLayers = false; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2824 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2825 | if (imMayMove) { |
| Dianne Hackborn | 8abd5f0 | 2009-11-20 18:09:03 -0800 | [diff] [blame] | 2826 | if (moveInputMethodWindowsIfNeededLocked(false) || displayed) { |
| 2827 | // Little hack here -- we -should- be able to rely on the |
| 2828 | // function to return true if the IME has moved and needs |
| 2829 | // its layer recomputed. However, if the IME was hidden |
| 2830 | // and isn't actually moved in the list, its layer may be |
| 2831 | // 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] | 2832 | assignLayers = true; |
| 2833 | } |
| 2834 | } |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2835 | if (wallpaperMayMove) { |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 2836 | if ((adjustWallpaperWindowsLocked()&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) { |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2837 | assignLayers = true; |
| 2838 | } |
| 2839 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2840 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2841 | mLayoutNeeded = true; |
| 2842 | win.mGivenInsetsPending = insetsPending; |
| 2843 | if (assignLayers) { |
| 2844 | assignLayersLocked(); |
| 2845 | } |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2846 | configChanged = updateOrientationFromAppTokensLocked(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2847 | performLayoutAndPlaceSurfacesLocked(); |
| Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 2848 | if (displayed && win.mIsWallpaper) { |
| 2849 | updateWallpaperOffsetLocked(win, mDisplay.getWidth(), |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 2850 | mDisplay.getHeight(), false); |
| Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 2851 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2852 | if (win.mAppToken != null) { |
| 2853 | win.mAppToken.updateReportedVisibilityLocked(); |
| 2854 | } |
| 2855 | outFrame.set(win.mFrame); |
| 2856 | outContentInsets.set(win.mContentInsets); |
| 2857 | outVisibleInsets.set(win.mVisibleInsets); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2858 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2859 | TAG, "Relayout given client " + client.asBinder() |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2860 | + ", requestedWidth=" + requestedWidth |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2861 | + ", requestedHeight=" + requestedHeight |
| 2862 | + ", viewVisibility=" + viewVisibility |
| 2863 | + "\nRelayout returning frame=" + outFrame |
| 2864 | + ", surface=" + outSurface); |
| 2865 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2866 | if (localLOGV || DEBUG_FOCUS) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2867 | TAG, "Relayout of " + win + ": focusMayChange=" + focusMayChange); |
| 2868 | |
| 2869 | inTouchMode = mInTouchMode; |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 2870 | |
| 2871 | mInputMonitor.updateInputWindowsLw(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2872 | } |
| 2873 | |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2874 | if (configChanged) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2875 | sendNewConfiguration(); |
| 2876 | } |
| 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 | Binder.restoreCallingIdentity(origId); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2879 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2880 | return (inTouchMode ? WindowManagerImpl.RELAYOUT_IN_TOUCH_MODE : 0) |
| 2881 | | (displayed ? WindowManagerImpl.RELAYOUT_FIRST_TIME : 0); |
| 2882 | } |
| 2883 | |
| 2884 | public void finishDrawingWindow(Session session, IWindow client) { |
| 2885 | final long origId = Binder.clearCallingIdentity(); |
| 2886 | synchronized(mWindowMap) { |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2887 | WindowState win = windowForClientLocked(session, client, false); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2888 | if (win != null && win.finishDrawingLocked()) { |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 2889 | if ((win.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0) { |
| 2890 | adjustWallpaperWindowsLocked(); |
| 2891 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2892 | mLayoutNeeded = true; |
| 2893 | performLayoutAndPlaceSurfacesLocked(); |
| 2894 | } |
| 2895 | } |
| 2896 | Binder.restoreCallingIdentity(origId); |
| 2897 | } |
| 2898 | |
| 2899 | private AttributeCache.Entry getCachedAnimations(WindowManager.LayoutParams lp) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2900 | 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] | 2901 | + (lp != null ? lp.packageName : null) |
| 2902 | + " resId=0x" + (lp != null ? Integer.toHexString(lp.windowAnimations) : null)); |
| 2903 | if (lp != null && lp.windowAnimations != 0) { |
| 2904 | // If this is a system resource, don't try to load it from the |
| 2905 | // application resources. It is nice to avoid loading application |
| 2906 | // resources if we can. |
| 2907 | String packageName = lp.packageName != null ? lp.packageName : "android"; |
| 2908 | int resId = lp.windowAnimations; |
| 2909 | if ((resId&0xFF000000) == 0x01000000) { |
| 2910 | packageName = "android"; |
| 2911 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2912 | 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] | 2913 | + packageName); |
| 2914 | return AttributeCache.instance().get(packageName, resId, |
| 2915 | com.android.internal.R.styleable.WindowAnimation); |
| 2916 | } |
| 2917 | return null; |
| 2918 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2919 | |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2920 | private AttributeCache.Entry getCachedAnimations(String packageName, int resId) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2921 | if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: params package=" |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2922 | + packageName + " resId=0x" + Integer.toHexString(resId)); |
| 2923 | if (packageName != null) { |
| 2924 | if ((resId&0xFF000000) == 0x01000000) { |
| 2925 | packageName = "android"; |
| 2926 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2927 | if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: picked package=" |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2928 | + packageName); |
| 2929 | return AttributeCache.instance().get(packageName, resId, |
| 2930 | com.android.internal.R.styleable.WindowAnimation); |
| 2931 | } |
| 2932 | return null; |
| 2933 | } |
| 2934 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2935 | private void applyEnterAnimationLocked(WindowState win) { |
| 2936 | int transit = WindowManagerPolicy.TRANSIT_SHOW; |
| 2937 | if (win.mEnterAnimationPending) { |
| 2938 | win.mEnterAnimationPending = false; |
| 2939 | transit = WindowManagerPolicy.TRANSIT_ENTER; |
| 2940 | } |
| 2941 | |
| 2942 | applyAnimationLocked(win, transit, true); |
| 2943 | } |
| 2944 | |
| 2945 | private boolean applyAnimationLocked(WindowState win, |
| 2946 | int transit, boolean isEntrance) { |
| 2947 | if (win.mLocalAnimating && win.mAnimationIsEntrance == isEntrance) { |
| 2948 | // If we are trying to apply an animation, but already running |
| 2949 | // an animation of the same type, then just leave that one alone. |
| 2950 | return true; |
| 2951 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2952 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2953 | // Only apply an animation if the display isn't frozen. If it is |
| 2954 | // frozen, there is no reason to animate and it can cause strange |
| 2955 | // artifacts when we unfreeze the display if some different animation |
| 2956 | // is running. |
| Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 2957 | if (!mDisplayFrozen && mPolicy.isScreenOn()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2958 | int anim = mPolicy.selectAnimationLw(win, transit); |
| 2959 | int attr = -1; |
| 2960 | Animation a = null; |
| 2961 | if (anim != 0) { |
| 2962 | a = AnimationUtils.loadAnimation(mContext, anim); |
| 2963 | } else { |
| 2964 | switch (transit) { |
| 2965 | case WindowManagerPolicy.TRANSIT_ENTER: |
| 2966 | attr = com.android.internal.R.styleable.WindowAnimation_windowEnterAnimation; |
| 2967 | break; |
| 2968 | case WindowManagerPolicy.TRANSIT_EXIT: |
| 2969 | attr = com.android.internal.R.styleable.WindowAnimation_windowExitAnimation; |
| 2970 | break; |
| 2971 | case WindowManagerPolicy.TRANSIT_SHOW: |
| 2972 | attr = com.android.internal.R.styleable.WindowAnimation_windowShowAnimation; |
| 2973 | break; |
| 2974 | case WindowManagerPolicy.TRANSIT_HIDE: |
| 2975 | attr = com.android.internal.R.styleable.WindowAnimation_windowHideAnimation; |
| 2976 | break; |
| 2977 | } |
| 2978 | if (attr >= 0) { |
| 2979 | a = loadAnimation(win.mAttrs, attr); |
| 2980 | } |
| 2981 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2982 | if (DEBUG_ANIM) Slog.v(TAG, "applyAnimation: win=" + win |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2983 | + " anim=" + anim + " attr=0x" + Integer.toHexString(attr) |
| 2984 | + " mAnimation=" + win.mAnimation |
| 2985 | + " isEntrance=" + isEntrance); |
| 2986 | if (a != null) { |
| 2987 | if (DEBUG_ANIM) { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 2988 | RuntimeException e = null; |
| 2989 | if (!HIDE_STACK_CRAWLS) { |
| 2990 | e = new RuntimeException(); |
| 2991 | e.fillInStackTrace(); |
| 2992 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2993 | Slog.v(TAG, "Loaded animation " + a + " for " + win, e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2994 | } |
| 2995 | win.setAnimation(a); |
| 2996 | win.mAnimationIsEntrance = isEntrance; |
| 2997 | } |
| 2998 | } else { |
| 2999 | win.clearAnimation(); |
| 3000 | } |
| 3001 | |
| 3002 | return win.mAnimation != null; |
| 3003 | } |
| 3004 | |
| 3005 | private Animation loadAnimation(WindowManager.LayoutParams lp, int animAttr) { |
| 3006 | int anim = 0; |
| 3007 | Context context = mContext; |
| 3008 | if (animAttr >= 0) { |
| 3009 | AttributeCache.Entry ent = getCachedAnimations(lp); |
| 3010 | if (ent != null) { |
| 3011 | context = ent.context; |
| 3012 | anim = ent.array.getResourceId(animAttr, 0); |
| 3013 | } |
| 3014 | } |
| 3015 | if (anim != 0) { |
| 3016 | return AnimationUtils.loadAnimation(context, anim); |
| 3017 | } |
| 3018 | return null; |
| 3019 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3020 | |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 3021 | private Animation loadAnimation(String packageName, int resId) { |
| 3022 | int anim = 0; |
| 3023 | Context context = mContext; |
| 3024 | if (resId >= 0) { |
| 3025 | AttributeCache.Entry ent = getCachedAnimations(packageName, resId); |
| 3026 | if (ent != null) { |
| 3027 | context = ent.context; |
| 3028 | anim = resId; |
| 3029 | } |
| 3030 | } |
| 3031 | if (anim != 0) { |
| 3032 | return AnimationUtils.loadAnimation(context, anim); |
| 3033 | } |
| 3034 | return null; |
| 3035 | } |
| 3036 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3037 | private boolean applyAnimationLocked(AppWindowToken wtoken, |
| 3038 | WindowManager.LayoutParams lp, int transit, boolean enter) { |
| 3039 | // Only apply an animation if the display isn't frozen. If it is |
| 3040 | // frozen, there is no reason to animate and it can cause strange |
| 3041 | // artifacts when we unfreeze the display if some different animation |
| 3042 | // is running. |
| Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 3043 | if (!mDisplayFrozen && mPolicy.isScreenOn()) { |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 3044 | Animation a; |
| Mitsuru Oshima | d2967e2 | 2009-07-20 14:01:43 -0700 | [diff] [blame] | 3045 | if (lp != null && (lp.flags & FLAG_COMPATIBLE_WINDOW) != 0) { |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 3046 | a = new FadeInOutAnimation(enter); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3047 | if (DEBUG_ANIM) Slog.v(TAG, |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 3048 | "applying FadeInOutAnimation for a window in compatibility mode"); |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 3049 | } else if (mNextAppTransitionPackage != null) { |
| 3050 | a = loadAnimation(mNextAppTransitionPackage, enter ? |
| 3051 | mNextAppTransitionEnter : mNextAppTransitionExit); |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 3052 | } else { |
| 3053 | int animAttr = 0; |
| 3054 | switch (transit) { |
| 3055 | case WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN: |
| 3056 | animAttr = enter |
| 3057 | ? com.android.internal.R.styleable.WindowAnimation_activityOpenEnterAnimation |
| 3058 | : com.android.internal.R.styleable.WindowAnimation_activityOpenExitAnimation; |
| 3059 | break; |
| 3060 | case WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE: |
| 3061 | animAttr = enter |
| 3062 | ? com.android.internal.R.styleable.WindowAnimation_activityCloseEnterAnimation |
| 3063 | : com.android.internal.R.styleable.WindowAnimation_activityCloseExitAnimation; |
| 3064 | break; |
| 3065 | case WindowManagerPolicy.TRANSIT_TASK_OPEN: |
| 3066 | animAttr = enter |
| 3067 | ? com.android.internal.R.styleable.WindowAnimation_taskOpenEnterAnimation |
| 3068 | : com.android.internal.R.styleable.WindowAnimation_taskOpenExitAnimation; |
| 3069 | break; |
| 3070 | case WindowManagerPolicy.TRANSIT_TASK_CLOSE: |
| 3071 | animAttr = enter |
| 3072 | ? com.android.internal.R.styleable.WindowAnimation_taskCloseEnterAnimation |
| 3073 | : com.android.internal.R.styleable.WindowAnimation_taskCloseExitAnimation; |
| 3074 | break; |
| 3075 | case WindowManagerPolicy.TRANSIT_TASK_TO_FRONT: |
| 3076 | animAttr = enter |
| 3077 | ? com.android.internal.R.styleable.WindowAnimation_taskToFrontEnterAnimation |
| 3078 | : com.android.internal.R.styleable.WindowAnimation_taskToFrontExitAnimation; |
| 3079 | break; |
| 3080 | case WindowManagerPolicy.TRANSIT_TASK_TO_BACK: |
| 3081 | animAttr = enter |
| Mitsuru Oshima | 5a2b91d | 2009-07-16 16:30:02 -0700 | [diff] [blame] | 3082 | ? com.android.internal.R.styleable.WindowAnimation_taskToBackEnterAnimation |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 3083 | : com.android.internal.R.styleable.WindowAnimation_taskToBackExitAnimation; |
| 3084 | break; |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 3085 | case WindowManagerPolicy.TRANSIT_WALLPAPER_OPEN: |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 3086 | animAttr = enter |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 3087 | ? com.android.internal.R.styleable.WindowAnimation_wallpaperOpenEnterAnimation |
| 3088 | : com.android.internal.R.styleable.WindowAnimation_wallpaperOpenExitAnimation; |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 3089 | break; |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 3090 | case WindowManagerPolicy.TRANSIT_WALLPAPER_CLOSE: |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 3091 | animAttr = enter |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 3092 | ? com.android.internal.R.styleable.WindowAnimation_wallpaperCloseEnterAnimation |
| 3093 | : com.android.internal.R.styleable.WindowAnimation_wallpaperCloseExitAnimation; |
| 3094 | break; |
| 3095 | case WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_OPEN: |
| 3096 | animAttr = enter |
| 3097 | ? com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenEnterAnimation |
| 3098 | : com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenExitAnimation; |
| 3099 | break; |
| 3100 | case WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_CLOSE: |
| 3101 | animAttr = enter |
| 3102 | ? com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseEnterAnimation |
| 3103 | : com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseExitAnimation; |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 3104 | break; |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 3105 | } |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 3106 | a = animAttr != 0 ? loadAnimation(lp, animAttr) : null; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3107 | if (DEBUG_ANIM) Slog.v(TAG, "applyAnimation: wtoken=" + wtoken |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 3108 | + " anim=" + a |
| 3109 | + " animAttr=0x" + Integer.toHexString(animAttr) |
| 3110 | + " transit=" + transit); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3111 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3112 | if (a != null) { |
| 3113 | if (DEBUG_ANIM) { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 3114 | RuntimeException e = null; |
| 3115 | if (!HIDE_STACK_CRAWLS) { |
| 3116 | e = new RuntimeException(); |
| 3117 | e.fillInStackTrace(); |
| 3118 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3119 | Slog.v(TAG, "Loaded animation " + a + " for " + wtoken, e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3120 | } |
| 3121 | wtoken.setAnimation(a); |
| 3122 | } |
| 3123 | } else { |
| 3124 | wtoken.clearAnimation(); |
| 3125 | } |
| 3126 | |
| 3127 | return wtoken.animation != null; |
| 3128 | } |
| 3129 | |
| 3130 | // ------------------------------------------------------------- |
| 3131 | // Application Window Tokens |
| 3132 | // ------------------------------------------------------------- |
| 3133 | |
| 3134 | public void validateAppTokens(List tokens) { |
| 3135 | int v = tokens.size()-1; |
| 3136 | int m = mAppTokens.size()-1; |
| 3137 | while (v >= 0 && m >= 0) { |
| 3138 | AppWindowToken wtoken = mAppTokens.get(m); |
| 3139 | if (wtoken.removed) { |
| 3140 | m--; |
| 3141 | continue; |
| 3142 | } |
| 3143 | if (tokens.get(v) != wtoken.token) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3144 | 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] | 3145 | + " @ " + v + ", internal is " + wtoken.token + " @ " + m); |
| 3146 | } |
| 3147 | v--; |
| 3148 | m--; |
| 3149 | } |
| 3150 | while (v >= 0) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3151 | 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] | 3152 | v--; |
| 3153 | } |
| 3154 | while (m >= 0) { |
| 3155 | AppWindowToken wtoken = mAppTokens.get(m); |
| 3156 | if (!wtoken.removed) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3157 | Slog.w(TAG, "Invalid internal token: " + wtoken.token + " @ " + m); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3158 | } |
| 3159 | m--; |
| 3160 | } |
| 3161 | } |
| 3162 | |
| 3163 | boolean checkCallingPermission(String permission, String func) { |
| 3164 | // Quick check: if the calling permission is me, it's all okay. |
| 3165 | if (Binder.getCallingPid() == Process.myPid()) { |
| 3166 | return true; |
| 3167 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3168 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3169 | if (mContext.checkCallingPermission(permission) |
| 3170 | == PackageManager.PERMISSION_GRANTED) { |
| 3171 | return true; |
| 3172 | } |
| 3173 | String msg = "Permission Denial: " + func + " from pid=" |
| 3174 | + Binder.getCallingPid() |
| 3175 | + ", uid=" + Binder.getCallingUid() |
| 3176 | + " requires " + permission; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3177 | Slog.w(TAG, msg); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3178 | return false; |
| 3179 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3180 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3181 | AppWindowToken findAppWindowToken(IBinder token) { |
| 3182 | WindowToken wtoken = mTokenMap.get(token); |
| 3183 | if (wtoken == null) { |
| 3184 | return null; |
| 3185 | } |
| 3186 | return wtoken.appWindowToken; |
| 3187 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3188 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3189 | public void addWindowToken(IBinder token, int type) { |
| 3190 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3191 | "addWindowToken()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3192 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3193 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3194 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3195 | synchronized(mWindowMap) { |
| 3196 | WindowToken wtoken = mTokenMap.get(token); |
| 3197 | if (wtoken != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3198 | 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] | 3199 | return; |
| 3200 | } |
| 3201 | wtoken = new WindowToken(token, type, true); |
| 3202 | mTokenMap.put(token, wtoken); |
| 3203 | mTokenList.add(wtoken); |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 3204 | if (type == TYPE_WALLPAPER) { |
| 3205 | mWallpaperTokens.add(wtoken); |
| 3206 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3207 | } |
| 3208 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3209 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3210 | public void removeWindowToken(IBinder token) { |
| 3211 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3212 | "removeWindowToken()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3213 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3214 | } |
| 3215 | |
| 3216 | final long origId = Binder.clearCallingIdentity(); |
| 3217 | synchronized(mWindowMap) { |
| 3218 | WindowToken wtoken = mTokenMap.remove(token); |
| 3219 | mTokenList.remove(wtoken); |
| 3220 | if (wtoken != null) { |
| 3221 | boolean delayed = false; |
| 3222 | if (!wtoken.hidden) { |
| 3223 | wtoken.hidden = true; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3224 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3225 | final int N = wtoken.windows.size(); |
| 3226 | boolean changed = false; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3227 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3228 | for (int i=0; i<N; i++) { |
| 3229 | WindowState win = wtoken.windows.get(i); |
| 3230 | |
| 3231 | if (win.isAnimating()) { |
| 3232 | delayed = true; |
| 3233 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3234 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3235 | if (win.isVisibleNow()) { |
| 3236 | applyAnimationLocked(win, |
| 3237 | WindowManagerPolicy.TRANSIT_EXIT, false); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3238 | changed = true; |
| 3239 | } |
| 3240 | } |
| 3241 | |
| 3242 | if (changed) { |
| 3243 | mLayoutNeeded = true; |
| 3244 | performLayoutAndPlaceSurfacesLocked(); |
| 3245 | updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL); |
| 3246 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3247 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3248 | if (delayed) { |
| 3249 | mExitingTokens.add(wtoken); |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 3250 | } else if (wtoken.windowType == TYPE_WALLPAPER) { |
| 3251 | mWallpaperTokens.remove(wtoken); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3252 | } |
| 3253 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3254 | |
| Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 3255 | mInputMonitor.updateInputWindowsLw(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3256 | } else { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3257 | 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] | 3258 | } |
| 3259 | } |
| 3260 | Binder.restoreCallingIdentity(origId); |
| 3261 | } |
| 3262 | |
| 3263 | public void addAppToken(int addPos, IApplicationToken token, |
| 3264 | int groupId, int requestedOrientation, boolean fullscreen) { |
| 3265 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3266 | "addAppToken()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3267 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3268 | } |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 3269 | |
| 3270 | // Get the dispatching timeout here while we are not holding any locks so that it |
| 3271 | // can be cached by the AppWindowToken. The timeout value is used later by the |
| 3272 | // input dispatcher in code that does hold locks. If we did not cache the value |
| 3273 | // here we would run the chance of introducing a deadlock between the window manager |
| 3274 | // (which holds locks while updating the input dispatcher state) and the activity manager |
| 3275 | // (which holds locks while querying the application token). |
| 3276 | long inputDispatchingTimeoutNanos; |
| 3277 | try { |
| 3278 | inputDispatchingTimeoutNanos = token.getKeyDispatchingTimeout() * 1000000L; |
| 3279 | } catch (RemoteException ex) { |
| 3280 | Slog.w(TAG, "Could not get dispatching timeout.", ex); |
| 3281 | inputDispatchingTimeoutNanos = DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS; |
| 3282 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3283 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3284 | synchronized(mWindowMap) { |
| 3285 | AppWindowToken wtoken = findAppWindowToken(token.asBinder()); |
| 3286 | if (wtoken != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3287 | 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] | 3288 | return; |
| 3289 | } |
| 3290 | wtoken = new AppWindowToken(token); |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 3291 | wtoken.inputDispatchingTimeoutNanos = inputDispatchingTimeoutNanos; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3292 | wtoken.groupId = groupId; |
| 3293 | wtoken.appFullscreen = fullscreen; |
| 3294 | wtoken.requestedOrientation = requestedOrientation; |
| 3295 | mAppTokens.add(addPos, wtoken); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3296 | 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] | 3297 | mTokenMap.put(token.asBinder(), wtoken); |
| 3298 | mTokenList.add(wtoken); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3299 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3300 | // Application tokens start out hidden. |
| 3301 | wtoken.hidden = true; |
| 3302 | wtoken.hiddenRequested = true; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3303 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3304 | //dump(); |
| 3305 | } |
| 3306 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3307 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3308 | public void setAppGroupId(IBinder token, int groupId) { |
| 3309 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3310 | "setAppStartingIcon()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3311 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3312 | } |
| 3313 | |
| 3314 | synchronized(mWindowMap) { |
| 3315 | AppWindowToken wtoken = findAppWindowToken(token); |
| 3316 | if (wtoken == null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3317 | Slog.w(TAG, "Attempted to set group id of non-existing app token: " + token); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3318 | return; |
| 3319 | } |
| 3320 | wtoken.groupId = groupId; |
| 3321 | } |
| 3322 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3323 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3324 | public int getOrientationFromWindowsLocked() { |
| 3325 | int pos = mWindows.size() - 1; |
| 3326 | while (pos >= 0) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 3327 | WindowState wtoken = mWindows.get(pos); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3328 | pos--; |
| 3329 | if (wtoken.mAppToken != null) { |
| 3330 | // We hit an application window. so the orientation will be determined by the |
| 3331 | // app window. No point in continuing further. |
| 3332 | return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
| 3333 | } |
| Christopher Tate | b696aee | 2010-04-02 19:08:30 -0700 | [diff] [blame] | 3334 | if (!wtoken.isVisibleLw() || !wtoken.mPolicyVisibilityAfterAnim) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3335 | continue; |
| 3336 | } |
| 3337 | int req = wtoken.mAttrs.screenOrientation; |
| 3338 | if((req == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) || |
| 3339 | (req == ActivityInfo.SCREEN_ORIENTATION_BEHIND)){ |
| 3340 | continue; |
| 3341 | } else { |
| 3342 | return req; |
| 3343 | } |
| 3344 | } |
| 3345 | return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
| 3346 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3347 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3348 | public int getOrientationFromAppTokensLocked() { |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3349 | int pos = mAppTokens.size() - 1; |
| 3350 | int curGroup = 0; |
| 3351 | int lastOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
| 3352 | boolean findingBehind = false; |
| 3353 | boolean haveGroup = false; |
| 3354 | boolean lastFullscreen = false; |
| 3355 | while (pos >= 0) { |
| 3356 | AppWindowToken wtoken = mAppTokens.get(pos); |
| 3357 | pos--; |
| 3358 | // if we're about to tear down this window and not seek for |
| 3359 | // the behind activity, don't use it for orientation |
| 3360 | if (!findingBehind |
| 3361 | && (!wtoken.hidden && wtoken.hiddenRequested)) { |
| 3362 | continue; |
| 3363 | } |
| 3364 | |
| 3365 | if (!haveGroup) { |
| 3366 | // We ignore any hidden applications on the top. |
| 3367 | if (wtoken.hiddenRequested || wtoken.willBeHidden) { |
| The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3368 | continue; |
| 3369 | } |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3370 | haveGroup = true; |
| 3371 | curGroup = wtoken.groupId; |
| 3372 | lastOrientation = wtoken.requestedOrientation; |
| 3373 | } else if (curGroup != wtoken.groupId) { |
| 3374 | // If we have hit a new application group, and the bottom |
| 3375 | // of the previous group didn't explicitly say to use |
| 3376 | // the orientation behind it, and the last app was |
| 3377 | // full screen, then we'll stick with the |
| 3378 | // user's orientation. |
| 3379 | if (lastOrientation != ActivityInfo.SCREEN_ORIENTATION_BEHIND |
| 3380 | && lastFullscreen) { |
| 3381 | return lastOrientation; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3382 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3383 | } |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3384 | int or = wtoken.requestedOrientation; |
| 3385 | // If this application is fullscreen, and didn't explicitly say |
| 3386 | // to use the orientation behind it, then just take whatever |
| 3387 | // orientation it has and ignores whatever is under it. |
| 3388 | lastFullscreen = wtoken.appFullscreen; |
| 3389 | if (lastFullscreen |
| 3390 | && or != ActivityInfo.SCREEN_ORIENTATION_BEHIND) { |
| 3391 | return or; |
| 3392 | } |
| 3393 | // If this application has requested an explicit orientation, |
| 3394 | // then use it. |
| Dianne Hackborn | e5439f2 | 2010-10-02 16:53:50 -0700 | [diff] [blame] | 3395 | if (or != ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED |
| 3396 | && or != ActivityInfo.SCREEN_ORIENTATION_BEHIND) { |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3397 | return or; |
| 3398 | } |
| 3399 | findingBehind |= (or == ActivityInfo.SCREEN_ORIENTATION_BEHIND); |
| 3400 | } |
| 3401 | return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3402 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3403 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3404 | public Configuration updateOrientationFromAppTokens( |
| The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3405 | Configuration currentConfig, IBinder freezeThisOneIfNeeded) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3406 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3407 | "updateOrientationFromAppTokens()")) { |
| 3408 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| 3409 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3410 | |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3411 | Configuration config = null; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3412 | long ident = Binder.clearCallingIdentity(); |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3413 | |
| 3414 | synchronized(mWindowMap) { |
| 3415 | if (updateOrientationFromAppTokensLocked()) { |
| 3416 | if (freezeThisOneIfNeeded != null) { |
| 3417 | AppWindowToken wtoken = findAppWindowToken( |
| 3418 | freezeThisOneIfNeeded); |
| 3419 | if (wtoken != null) { |
| 3420 | startAppFreezingScreenLocked(wtoken, |
| 3421 | ActivityInfo.CONFIG_ORIENTATION); |
| 3422 | } |
| 3423 | } |
| 3424 | config = computeNewConfigurationLocked(); |
| 3425 | |
| 3426 | } else if (currentConfig != null) { |
| 3427 | // No obvious action we need to take, but if our current |
| Casey Burkhardt | 0920ba5 | 2010-08-03 12:04:19 -0700 | [diff] [blame] | 3428 | // state mismatches the activity manager's, update it, |
| 3429 | // disregarding font scale, which should remain set to |
| 3430 | // the value of the previous configuration. |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3431 | mTempConfiguration.setToDefaults(); |
| Casey Burkhardt | 0920ba5 | 2010-08-03 12:04:19 -0700 | [diff] [blame] | 3432 | mTempConfiguration.fontScale = currentConfig.fontScale; |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3433 | if (computeNewConfigurationLocked(mTempConfiguration)) { |
| 3434 | if (currentConfig.diff(mTempConfiguration) != 0) { |
| 3435 | mWaitingForConfig = true; |
| 3436 | mLayoutNeeded = true; |
| 3437 | startFreezingDisplayLocked(); |
| 3438 | config = new Configuration(mTempConfiguration); |
| 3439 | } |
| 3440 | } |
| 3441 | } |
| 3442 | } |
| 3443 | |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3444 | Binder.restoreCallingIdentity(ident); |
| 3445 | return config; |
| 3446 | } |
| 3447 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3448 | /* |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3449 | * Determine the new desired orientation of the display, returning |
| 3450 | * a non-null new Configuration if it has changed from the current |
| 3451 | * orientation. IF TRUE IS RETURNED SOMEONE MUST CALL |
| 3452 | * setNewConfiguration() TO TELL THE WINDOW MANAGER IT CAN UNFREEZE THE |
| 3453 | * SCREEN. This will typically be done for you if you call |
| 3454 | * sendNewConfiguration(). |
| 3455 | * |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3456 | * The orientation is computed from non-application windows first. If none of |
| 3457 | * the non-application windows specify orientation, the orientation is computed from |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3458 | * application tokens. |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3459 | * @see android.view.IWindowManager#updateOrientationFromAppTokens( |
| 3460 | * android.os.IBinder) |
| 3461 | */ |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3462 | boolean updateOrientationFromAppTokensLocked() { |
| Christopher Tate | b696aee | 2010-04-02 19:08:30 -0700 | [diff] [blame] | 3463 | if (mDisplayFrozen) { |
| 3464 | // If the display is frozen, some activities may be in the middle |
| 3465 | // of restarting, and thus have removed their old window. If the |
| 3466 | // window has the flag to hide the lock screen, then the lock screen |
| 3467 | // can re-appear and inflict its own orientation on us. Keep the |
| 3468 | // orientation stable until this all settles down. |
| 3469 | return false; |
| 3470 | } |
| 3471 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3472 | boolean changed = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3473 | long ident = Binder.clearCallingIdentity(); |
| 3474 | try { |
| The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 3475 | int req = computeForcedAppOrientationLocked(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3476 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3477 | if (req != mForcedAppOrientation) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3478 | mForcedAppOrientation = req; |
| 3479 | //send a message to Policy indicating orientation change to take |
| 3480 | //action like disabling/enabling sensors etc., |
| The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 3481 | mPolicy.setCurrentOrientationLw(req); |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3482 | if (setRotationUncheckedLocked(WindowManagerPolicy.USE_LAST_ROTATION, |
| 3483 | mLastRotationFlags | Surface.FLAGS_ORIENTATION_ANIMATION_DISABLE)) { |
| 3484 | changed = true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3485 | } |
| 3486 | } |
| The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3487 | |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3488 | return changed; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3489 | } finally { |
| 3490 | Binder.restoreCallingIdentity(ident); |
| 3491 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3492 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3493 | |
| The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 3494 | int computeForcedAppOrientationLocked() { |
| 3495 | int req = getOrientationFromWindowsLocked(); |
| 3496 | if (req == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) { |
| 3497 | req = getOrientationFromAppTokensLocked(); |
| 3498 | } |
| 3499 | return req; |
| 3500 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3501 | |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3502 | public void setNewConfiguration(Configuration config) { |
| 3503 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3504 | "setNewConfiguration()")) { |
| 3505 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| 3506 | } |
| 3507 | |
| 3508 | synchronized(mWindowMap) { |
| 3509 | mCurConfiguration = new Configuration(config); |
| 3510 | mWaitingForConfig = false; |
| 3511 | performLayoutAndPlaceSurfacesLocked(); |
| 3512 | } |
| 3513 | } |
| 3514 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3515 | public void setAppOrientation(IApplicationToken token, int requestedOrientation) { |
| 3516 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3517 | "setAppOrientation()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3518 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3519 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3520 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3521 | synchronized(mWindowMap) { |
| 3522 | AppWindowToken wtoken = findAppWindowToken(token.asBinder()); |
| 3523 | if (wtoken == null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3524 | 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] | 3525 | return; |
| 3526 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3527 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3528 | wtoken.requestedOrientation = requestedOrientation; |
| 3529 | } |
| 3530 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3531 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3532 | public int getAppOrientation(IApplicationToken token) { |
| 3533 | synchronized(mWindowMap) { |
| 3534 | AppWindowToken wtoken = findAppWindowToken(token.asBinder()); |
| 3535 | if (wtoken == null) { |
| 3536 | return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
| 3537 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3538 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3539 | return wtoken.requestedOrientation; |
| 3540 | } |
| 3541 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3542 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3543 | public void setFocusedApp(IBinder token, boolean moveFocusNow) { |
| 3544 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3545 | "setFocusedApp()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3546 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3547 | } |
| 3548 | |
| 3549 | synchronized(mWindowMap) { |
| 3550 | boolean changed = false; |
| 3551 | if (token == null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3552 | 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] | 3553 | changed = mFocusedApp != null; |
| 3554 | mFocusedApp = null; |
| Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 3555 | if (changed) { |
| 3556 | mInputMonitor.setFocusedAppLw(null); |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 3557 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3558 | } else { |
| 3559 | AppWindowToken newFocus = findAppWindowToken(token); |
| 3560 | if (newFocus == null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3561 | 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] | 3562 | return; |
| 3563 | } |
| 3564 | changed = mFocusedApp != newFocus; |
| 3565 | mFocusedApp = newFocus; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3566 | if (DEBUG_FOCUS) Slog.v(TAG, "Set focused app to: " + mFocusedApp); |
| Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 3567 | if (changed) { |
| 3568 | mInputMonitor.setFocusedAppLw(newFocus); |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 3569 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3570 | } |
| 3571 | |
| 3572 | if (moveFocusNow && changed) { |
| 3573 | final long origId = Binder.clearCallingIdentity(); |
| 3574 | updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL); |
| 3575 | Binder.restoreCallingIdentity(origId); |
| 3576 | } |
| 3577 | } |
| 3578 | } |
| 3579 | |
| 3580 | public void prepareAppTransition(int transit) { |
| 3581 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3582 | "prepareAppTransition()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3583 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3584 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3585 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3586 | synchronized(mWindowMap) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3587 | if (DEBUG_APP_TRANSITIONS) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3588 | TAG, "Prepare app transition: transit=" + transit |
| 3589 | + " mNextAppTransition=" + mNextAppTransition); |
| Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 3590 | if (!mDisplayFrozen && mPolicy.isScreenOn()) { |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 3591 | if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET |
| 3592 | || mNextAppTransition == WindowManagerPolicy.TRANSIT_NONE) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3593 | mNextAppTransition = transit; |
| Dianne Hackborn | d7cd29d | 2009-07-01 11:22:45 -0700 | [diff] [blame] | 3594 | } else if (transit == WindowManagerPolicy.TRANSIT_TASK_OPEN |
| 3595 | && mNextAppTransition == WindowManagerPolicy.TRANSIT_TASK_CLOSE) { |
| 3596 | // Opening a new task always supersedes a close for the anim. |
| 3597 | mNextAppTransition = transit; |
| 3598 | } else if (transit == WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN |
| 3599 | && mNextAppTransition == WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE) { |
| 3600 | // Opening a new activity always supersedes a close for the anim. |
| 3601 | mNextAppTransition = transit; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3602 | } |
| 3603 | mAppTransitionReady = false; |
| 3604 | mAppTransitionTimeout = false; |
| 3605 | mStartingIconInTransition = false; |
| 3606 | mSkipAppTransitionAnimation = false; |
| 3607 | mH.removeMessages(H.APP_TRANSITION_TIMEOUT); |
| 3608 | mH.sendMessageDelayed(mH.obtainMessage(H.APP_TRANSITION_TIMEOUT), |
| 3609 | 5000); |
| 3610 | } |
| 3611 | } |
| 3612 | } |
| 3613 | |
| 3614 | public int getPendingAppTransition() { |
| 3615 | return mNextAppTransition; |
| 3616 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3617 | |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 3618 | public void overridePendingAppTransition(String packageName, |
| 3619 | int enterAnim, int exitAnim) { |
| Dianne Hackborn | 8b571a8 | 2009-09-25 16:09:43 -0700 | [diff] [blame] | 3620 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 3621 | mNextAppTransitionPackage = packageName; |
| 3622 | mNextAppTransitionEnter = enterAnim; |
| 3623 | mNextAppTransitionExit = exitAnim; |
| 3624 | } |
| 3625 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3626 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3627 | public void executeAppTransition() { |
| 3628 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3629 | "executeAppTransition()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3630 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3631 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3632 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3633 | synchronized(mWindowMap) { |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 3634 | if (DEBUG_APP_TRANSITIONS) { |
| 3635 | RuntimeException e = new RuntimeException("here"); |
| 3636 | e.fillInStackTrace(); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3637 | Slog.w(TAG, "Execute app transition: mNextAppTransition=" |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 3638 | + mNextAppTransition, e); |
| 3639 | } |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 3640 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3641 | mAppTransitionReady = true; |
| 3642 | final long origId = Binder.clearCallingIdentity(); |
| 3643 | performLayoutAndPlaceSurfacesLocked(); |
| 3644 | Binder.restoreCallingIdentity(origId); |
| 3645 | } |
| 3646 | } |
| 3647 | } |
| 3648 | |
| 3649 | public void setAppStartingWindow(IBinder token, String pkg, |
| 3650 | int theme, CharSequence nonLocalizedLabel, int labelRes, int icon, |
| 3651 | IBinder transferFrom, boolean createIfNeeded) { |
| 3652 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3653 | "setAppStartingIcon()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3654 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3655 | } |
| 3656 | |
| 3657 | synchronized(mWindowMap) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3658 | if (DEBUG_STARTING_WINDOW) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3659 | TAG, "setAppStartingIcon: token=" + token + " pkg=" + pkg |
| 3660 | + " transferFrom=" + transferFrom); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3661 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3662 | AppWindowToken wtoken = findAppWindowToken(token); |
| 3663 | if (wtoken == null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3664 | 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] | 3665 | return; |
| 3666 | } |
| 3667 | |
| 3668 | // If the display is frozen, we won't do anything until the |
| 3669 | // actual window is displayed so there is no reason to put in |
| 3670 | // the starting window. |
| Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 3671 | if (mDisplayFrozen || !mPolicy.isScreenOn()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3672 | return; |
| 3673 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3674 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3675 | if (wtoken.startingData != null) { |
| 3676 | return; |
| 3677 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3678 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3679 | if (transferFrom != null) { |
| 3680 | AppWindowToken ttoken = findAppWindowToken(transferFrom); |
| 3681 | if (ttoken != null) { |
| 3682 | WindowState startingWindow = ttoken.startingWindow; |
| 3683 | if (startingWindow != null) { |
| 3684 | if (mStartingIconInTransition) { |
| 3685 | // In this case, the starting icon has already |
| 3686 | // been displayed, so start letting windows get |
| 3687 | // shown immediately without any more transitions. |
| 3688 | mSkipAppTransitionAnimation = true; |
| 3689 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3690 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3691 | "Moving existing starting from " + ttoken |
| 3692 | + " to " + wtoken); |
| 3693 | final long origId = Binder.clearCallingIdentity(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3694 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3695 | // Transfer the starting window over to the new |
| 3696 | // token. |
| 3697 | wtoken.startingData = ttoken.startingData; |
| 3698 | wtoken.startingView = ttoken.startingView; |
| 3699 | wtoken.startingWindow = startingWindow; |
| 3700 | ttoken.startingData = null; |
| 3701 | ttoken.startingView = null; |
| 3702 | ttoken.startingWindow = null; |
| 3703 | ttoken.startingMoved = true; |
| 3704 | startingWindow.mToken = wtoken; |
| Dianne Hackborn | ef49c57 | 2009-03-24 19:27:32 -0700 | [diff] [blame] | 3705 | startingWindow.mRootToken = wtoken; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3706 | startingWindow.mAppToken = wtoken; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3707 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 3708 | "Removing starting window: " + startingWindow); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3709 | mWindows.remove(startingWindow); |
| Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 3710 | mWindowsChanged = true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3711 | ttoken.windows.remove(startingWindow); |
| 3712 | ttoken.allAppWindows.remove(startingWindow); |
| 3713 | addWindowToListInOrderLocked(startingWindow, true); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3714 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3715 | // Propagate other interesting state between the |
| 3716 | // tokens. If the old token is displayed, we should |
| 3717 | // immediately force the new one to be displayed. If |
| 3718 | // it is animating, we need to move that animation to |
| 3719 | // the new one. |
| 3720 | if (ttoken.allDrawn) { |
| 3721 | wtoken.allDrawn = true; |
| 3722 | } |
| 3723 | if (ttoken.firstWindowDrawn) { |
| 3724 | wtoken.firstWindowDrawn = true; |
| 3725 | } |
| 3726 | if (!ttoken.hidden) { |
| 3727 | wtoken.hidden = false; |
| 3728 | wtoken.hiddenRequested = false; |
| 3729 | wtoken.willBeHidden = false; |
| 3730 | } |
| 3731 | if (wtoken.clientHidden != ttoken.clientHidden) { |
| 3732 | wtoken.clientHidden = ttoken.clientHidden; |
| 3733 | wtoken.sendAppVisibilityToClients(); |
| 3734 | } |
| 3735 | if (ttoken.animation != null) { |
| 3736 | wtoken.animation = ttoken.animation; |
| 3737 | wtoken.animating = ttoken.animating; |
| 3738 | wtoken.animLayerAdjustment = ttoken.animLayerAdjustment; |
| 3739 | ttoken.animation = null; |
| 3740 | ttoken.animLayerAdjustment = 0; |
| 3741 | wtoken.updateLayers(); |
| 3742 | ttoken.updateLayers(); |
| 3743 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3744 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3745 | updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3746 | mLayoutNeeded = true; |
| 3747 | performLayoutAndPlaceSurfacesLocked(); |
| 3748 | Binder.restoreCallingIdentity(origId); |
| 3749 | return; |
| 3750 | } else if (ttoken.startingData != null) { |
| 3751 | // The previous app was getting ready to show a |
| 3752 | // starting window, but hasn't yet done so. Steal it! |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3753 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3754 | "Moving pending starting from " + ttoken |
| 3755 | + " to " + wtoken); |
| 3756 | wtoken.startingData = ttoken.startingData; |
| 3757 | ttoken.startingData = null; |
| 3758 | ttoken.startingMoved = true; |
| 3759 | Message m = mH.obtainMessage(H.ADD_STARTING, wtoken); |
| 3760 | // Note: we really want to do sendMessageAtFrontOfQueue() because we |
| 3761 | // want to process the message ASAP, before any other queued |
| 3762 | // messages. |
| 3763 | mH.sendMessageAtFrontOfQueue(m); |
| 3764 | return; |
| 3765 | } |
| 3766 | } |
| 3767 | } |
| 3768 | |
| 3769 | // There is no existing starting window, and the caller doesn't |
| 3770 | // want us to create one, so that's it! |
| 3771 | if (!createIfNeeded) { |
| 3772 | return; |
| 3773 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3774 | |
| Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 3775 | // If this is a translucent or wallpaper window, then don't |
| 3776 | // show a starting window -- the current effect (a full-screen |
| 3777 | // opaque starting window that fades away to the real contents |
| 3778 | // when it is ready) does not work for this. |
| 3779 | if (theme != 0) { |
| 3780 | AttributeCache.Entry ent = AttributeCache.instance().get(pkg, theme, |
| 3781 | com.android.internal.R.styleable.Window); |
| 3782 | if (ent.array.getBoolean( |
| 3783 | com.android.internal.R.styleable.Window_windowIsTranslucent, false)) { |
| 3784 | return; |
| 3785 | } |
| 3786 | if (ent.array.getBoolean( |
| Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 3787 | com.android.internal.R.styleable.Window_windowIsFloating, false)) { |
| 3788 | return; |
| 3789 | } |
| 3790 | if (ent.array.getBoolean( |
| Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 3791 | com.android.internal.R.styleable.Window_windowShowWallpaper, false)) { |
| 3792 | return; |
| 3793 | } |
| 3794 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3795 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3796 | mStartingIconInTransition = true; |
| 3797 | wtoken.startingData = new StartingData( |
| 3798 | pkg, theme, nonLocalizedLabel, |
| 3799 | labelRes, icon); |
| 3800 | Message m = mH.obtainMessage(H.ADD_STARTING, wtoken); |
| 3801 | // Note: we really want to do sendMessageAtFrontOfQueue() because we |
| 3802 | // want to process the message ASAP, before any other queued |
| 3803 | // messages. |
| 3804 | mH.sendMessageAtFrontOfQueue(m); |
| 3805 | } |
| 3806 | } |
| 3807 | |
| 3808 | public void setAppWillBeHidden(IBinder token) { |
| 3809 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3810 | "setAppWillBeHidden()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3811 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3812 | } |
| 3813 | |
| 3814 | AppWindowToken wtoken; |
| 3815 | |
| 3816 | synchronized(mWindowMap) { |
| 3817 | wtoken = findAppWindowToken(token); |
| 3818 | if (wtoken == null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3819 | 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] | 3820 | return; |
| 3821 | } |
| 3822 | wtoken.willBeHidden = true; |
| 3823 | } |
| 3824 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3825 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3826 | boolean setTokenVisibilityLocked(AppWindowToken wtoken, WindowManager.LayoutParams lp, |
| 3827 | boolean visible, int transit, boolean performLayout) { |
| 3828 | boolean delayed = false; |
| 3829 | |
| 3830 | if (wtoken.clientHidden == visible) { |
| 3831 | wtoken.clientHidden = !visible; |
| 3832 | wtoken.sendAppVisibilityToClients(); |
| 3833 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3834 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3835 | wtoken.willBeHidden = false; |
| 3836 | if (wtoken.hidden == visible) { |
| 3837 | final int N = wtoken.allAppWindows.size(); |
| 3838 | boolean changed = false; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3839 | if (DEBUG_APP_TRANSITIONS) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3840 | TAG, "Changing app " + wtoken + " hidden=" + wtoken.hidden |
| 3841 | + " performLayout=" + performLayout); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3842 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3843 | boolean runningAppAnimation = false; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3844 | |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 3845 | if (transit != WindowManagerPolicy.TRANSIT_UNSET) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3846 | if (wtoken.animation == sDummyAnimation) { |
| 3847 | wtoken.animation = null; |
| 3848 | } |
| 3849 | applyAnimationLocked(wtoken, lp, transit, visible); |
| 3850 | changed = true; |
| 3851 | if (wtoken.animation != null) { |
| 3852 | delayed = runningAppAnimation = true; |
| 3853 | } |
| 3854 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3855 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3856 | for (int i=0; i<N; i++) { |
| 3857 | WindowState win = wtoken.allAppWindows.get(i); |
| 3858 | if (win == wtoken.startingWindow) { |
| 3859 | continue; |
| 3860 | } |
| 3861 | |
| 3862 | if (win.isAnimating()) { |
| 3863 | delayed = true; |
| 3864 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3865 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3866 | //Slog.i(TAG, "Window " + win + ": vis=" + win.isVisible()); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3867 | //win.dump(" "); |
| 3868 | if (visible) { |
| 3869 | if (!win.isVisibleNow()) { |
| 3870 | if (!runningAppAnimation) { |
| 3871 | applyAnimationLocked(win, |
| 3872 | WindowManagerPolicy.TRANSIT_ENTER, true); |
| 3873 | } |
| 3874 | changed = true; |
| 3875 | } |
| 3876 | } else if (win.isVisibleNow()) { |
| 3877 | if (!runningAppAnimation) { |
| 3878 | applyAnimationLocked(win, |
| 3879 | WindowManagerPolicy.TRANSIT_EXIT, false); |
| 3880 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3881 | changed = true; |
| 3882 | } |
| 3883 | } |
| 3884 | |
| 3885 | wtoken.hidden = wtoken.hiddenRequested = !visible; |
| 3886 | if (!visible) { |
| 3887 | unsetAppFreezingScreenLocked(wtoken, true, true); |
| 3888 | } else { |
| 3889 | // If we are being set visible, and the starting window is |
| 3890 | // not yet displayed, then make sure it doesn't get displayed. |
| 3891 | WindowState swin = wtoken.startingWindow; |
| 3892 | if (swin != null && (swin.mDrawPending |
| 3893 | || swin.mCommitDrawPending)) { |
| 3894 | swin.mPolicyVisibility = false; |
| 3895 | swin.mPolicyVisibilityAfterAnim = false; |
| 3896 | } |
| 3897 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3898 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3899 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "setTokenVisibilityLocked: " + wtoken |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3900 | + ": hidden=" + wtoken.hidden + " hiddenRequested=" |
| 3901 | + wtoken.hiddenRequested); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3902 | |
| Dianne Hackborn | 9b52a21 | 2009-12-11 14:51:35 -0800 | [diff] [blame] | 3903 | if (changed) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3904 | mLayoutNeeded = true; |
| Dianne Hackborn | 9b52a21 | 2009-12-11 14:51:35 -0800 | [diff] [blame] | 3905 | if (performLayout) { |
| 3906 | updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES); |
| 3907 | performLayoutAndPlaceSurfacesLocked(); |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 3908 | } else { |
| 3909 | mInputMonitor.updateInputWindowsLw(); |
| Dianne Hackborn | 9b52a21 | 2009-12-11 14:51:35 -0800 | [diff] [blame] | 3910 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3911 | } |
| 3912 | } |
| 3913 | |
| 3914 | if (wtoken.animation != null) { |
| 3915 | delayed = true; |
| 3916 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3917 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3918 | return delayed; |
| 3919 | } |
| 3920 | |
| 3921 | public void setAppVisibility(IBinder token, boolean visible) { |
| 3922 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3923 | "setAppVisibility()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3924 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3925 | } |
| 3926 | |
| 3927 | AppWindowToken wtoken; |
| 3928 | |
| 3929 | synchronized(mWindowMap) { |
| 3930 | wtoken = findAppWindowToken(token); |
| 3931 | if (wtoken == null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3932 | 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] | 3933 | return; |
| 3934 | } |
| 3935 | |
| 3936 | if (DEBUG_APP_TRANSITIONS || DEBUG_ORIENTATION) { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 3937 | RuntimeException e = null; |
| 3938 | if (!HIDE_STACK_CRAWLS) { |
| 3939 | e = new RuntimeException(); |
| 3940 | e.fillInStackTrace(); |
| 3941 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3942 | Slog.v(TAG, "setAppVisibility(" + token + ", " + visible |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3943 | + "): mNextAppTransition=" + mNextAppTransition |
| 3944 | + " hidden=" + wtoken.hidden |
| 3945 | + " hiddenRequested=" + wtoken.hiddenRequested, e); |
| 3946 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3947 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3948 | // If we are preparing an app transition, then delay changing |
| 3949 | // the visibility of this token until we execute that transition. |
| Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 3950 | if (!mDisplayFrozen && mPolicy.isScreenOn() |
| 3951 | && mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3952 | // Already in requested state, don't do anything more. |
| 3953 | if (wtoken.hiddenRequested != visible) { |
| 3954 | return; |
| 3955 | } |
| 3956 | wtoken.hiddenRequested = !visible; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3957 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3958 | if (DEBUG_APP_TRANSITIONS) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3959 | TAG, "Setting dummy animation on: " + wtoken); |
| 3960 | wtoken.setDummyAnimation(); |
| 3961 | mOpeningApps.remove(wtoken); |
| 3962 | mClosingApps.remove(wtoken); |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 3963 | wtoken.waitingToShow = wtoken.waitingToHide = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3964 | wtoken.inPendingTransaction = true; |
| 3965 | if (visible) { |
| 3966 | mOpeningApps.add(wtoken); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3967 | wtoken.startingDisplayed = false; |
| 3968 | wtoken.startingMoved = false; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3969 | |
| Dianne Hackborn | 195f6a0 | 2009-11-24 11:26:00 -0800 | [diff] [blame] | 3970 | // If the token is currently hidden (should be the |
| 3971 | // common case), then we need to set up to wait for |
| 3972 | // its windows to be ready. |
| 3973 | if (wtoken.hidden) { |
| 3974 | wtoken.allDrawn = false; |
| 3975 | wtoken.waitingToShow = true; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3976 | |
| Dianne Hackborn | 195f6a0 | 2009-11-24 11:26:00 -0800 | [diff] [blame] | 3977 | if (wtoken.clientHidden) { |
| 3978 | // In the case where we are making an app visible |
| 3979 | // but holding off for a transition, we still need |
| 3980 | // to tell the client to make its windows visible so |
| 3981 | // they get drawn. Otherwise, we will wait on |
| 3982 | // performing the transition until all windows have |
| 3983 | // been drawn, they never will be, and we are sad. |
| 3984 | wtoken.clientHidden = false; |
| 3985 | wtoken.sendAppVisibilityToClients(); |
| 3986 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3987 | } |
| 3988 | } else { |
| 3989 | mClosingApps.add(wtoken); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3990 | |
| Dianne Hackborn | 195f6a0 | 2009-11-24 11:26:00 -0800 | [diff] [blame] | 3991 | // If the token is currently visible (should be the |
| 3992 | // common case), then set up to wait for it to be hidden. |
| 3993 | if (!wtoken.hidden) { |
| 3994 | wtoken.waitingToHide = true; |
| 3995 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3996 | } |
| 3997 | return; |
| 3998 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3999 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4000 | final long origId = Binder.clearCallingIdentity(); |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 4001 | setTokenVisibilityLocked(wtoken, null, visible, WindowManagerPolicy.TRANSIT_UNSET, true); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4002 | wtoken.updateReportedVisibilityLocked(); |
| 4003 | Binder.restoreCallingIdentity(origId); |
| 4004 | } |
| 4005 | } |
| 4006 | |
| 4007 | void unsetAppFreezingScreenLocked(AppWindowToken wtoken, |
| 4008 | boolean unfreezeSurfaceNow, boolean force) { |
| 4009 | if (wtoken.freezingScreen) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4010 | 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] | 4011 | + " force=" + force); |
| 4012 | final int N = wtoken.allAppWindows.size(); |
| 4013 | boolean unfrozeWindows = false; |
| 4014 | for (int i=0; i<N; i++) { |
| 4015 | WindowState w = wtoken.allAppWindows.get(i); |
| 4016 | if (w.mAppFreezing) { |
| 4017 | w.mAppFreezing = false; |
| 4018 | if (w.mSurface != null && !w.mOrientationChanging) { |
| 4019 | w.mOrientationChanging = true; |
| 4020 | } |
| 4021 | unfrozeWindows = true; |
| 4022 | } |
| 4023 | } |
| 4024 | if (force || unfrozeWindows) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4025 | 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] | 4026 | wtoken.freezingScreen = false; |
| 4027 | mAppsFreezingScreen--; |
| 4028 | } |
| 4029 | if (unfreezeSurfaceNow) { |
| 4030 | if (unfrozeWindows) { |
| 4031 | mLayoutNeeded = true; |
| 4032 | performLayoutAndPlaceSurfacesLocked(); |
| 4033 | } |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 4034 | stopFreezingDisplayLocked(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4035 | } |
| 4036 | } |
| 4037 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4038 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4039 | public void startAppFreezingScreenLocked(AppWindowToken wtoken, |
| 4040 | int configChanges) { |
| 4041 | if (DEBUG_ORIENTATION) { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 4042 | RuntimeException e = null; |
| 4043 | if (!HIDE_STACK_CRAWLS) { |
| 4044 | e = new RuntimeException(); |
| 4045 | e.fillInStackTrace(); |
| 4046 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4047 | Slog.i(TAG, "Set freezing of " + wtoken.appToken |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4048 | + ": hidden=" + wtoken.hidden + " freezing=" |
| 4049 | + wtoken.freezingScreen, e); |
| 4050 | } |
| 4051 | if (!wtoken.hiddenRequested) { |
| 4052 | if (!wtoken.freezingScreen) { |
| 4053 | wtoken.freezingScreen = true; |
| 4054 | mAppsFreezingScreen++; |
| 4055 | if (mAppsFreezingScreen == 1) { |
| 4056 | startFreezingDisplayLocked(); |
| 4057 | mH.removeMessages(H.APP_FREEZE_TIMEOUT); |
| 4058 | mH.sendMessageDelayed(mH.obtainMessage(H.APP_FREEZE_TIMEOUT), |
| 4059 | 5000); |
| 4060 | } |
| 4061 | } |
| 4062 | final int N = wtoken.allAppWindows.size(); |
| 4063 | for (int i=0; i<N; i++) { |
| 4064 | WindowState w = wtoken.allAppWindows.get(i); |
| 4065 | w.mAppFreezing = true; |
| 4066 | } |
| 4067 | } |
| 4068 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4069 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4070 | public void startAppFreezingScreen(IBinder token, int configChanges) { |
| 4071 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 4072 | "setAppFreezingScreen()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4073 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4074 | } |
| 4075 | |
| 4076 | synchronized(mWindowMap) { |
| Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 4077 | if (configChanges == 0 && !mDisplayFrozen && mPolicy.isScreenOn()) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4078 | 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] | 4079 | return; |
| 4080 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4081 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4082 | AppWindowToken wtoken = findAppWindowToken(token); |
| 4083 | if (wtoken == null || wtoken.appToken == null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4084 | 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] | 4085 | return; |
| 4086 | } |
| 4087 | final long origId = Binder.clearCallingIdentity(); |
| 4088 | startAppFreezingScreenLocked(wtoken, configChanges); |
| 4089 | Binder.restoreCallingIdentity(origId); |
| 4090 | } |
| 4091 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4092 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4093 | public void stopAppFreezingScreen(IBinder token, boolean force) { |
| 4094 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 4095 | "setAppFreezingScreen()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4096 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4097 | } |
| 4098 | |
| 4099 | synchronized(mWindowMap) { |
| 4100 | AppWindowToken wtoken = findAppWindowToken(token); |
| 4101 | if (wtoken == null || wtoken.appToken == null) { |
| 4102 | return; |
| 4103 | } |
| 4104 | final long origId = Binder.clearCallingIdentity(); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4105 | 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] | 4106 | + ": hidden=" + wtoken.hidden + " freezing=" + wtoken.freezingScreen); |
| 4107 | unsetAppFreezingScreenLocked(wtoken, true, force); |
| 4108 | Binder.restoreCallingIdentity(origId); |
| 4109 | } |
| 4110 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4111 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4112 | public void removeAppToken(IBinder token) { |
| 4113 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 4114 | "removeAppToken()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4115 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4116 | } |
| 4117 | |
| 4118 | AppWindowToken wtoken = null; |
| 4119 | AppWindowToken startingToken = null; |
| 4120 | boolean delayed = false; |
| 4121 | |
| 4122 | final long origId = Binder.clearCallingIdentity(); |
| 4123 | synchronized(mWindowMap) { |
| 4124 | WindowToken basewtoken = mTokenMap.remove(token); |
| 4125 | mTokenList.remove(basewtoken); |
| 4126 | if (basewtoken != null && (wtoken=basewtoken.appWindowToken) != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4127 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "Removing app token: " + wtoken); |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 4128 | delayed = setTokenVisibilityLocked(wtoken, null, false, WindowManagerPolicy.TRANSIT_UNSET, true); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4129 | wtoken.inPendingTransaction = false; |
| 4130 | mOpeningApps.remove(wtoken); |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4131 | wtoken.waitingToShow = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4132 | if (mClosingApps.contains(wtoken)) { |
| 4133 | delayed = true; |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 4134 | } else if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4135 | mClosingApps.add(wtoken); |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4136 | wtoken.waitingToHide = true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4137 | delayed = true; |
| 4138 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4139 | if (DEBUG_APP_TRANSITIONS) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4140 | TAG, "Removing app " + wtoken + " delayed=" + delayed |
| 4141 | + " animation=" + wtoken.animation |
| 4142 | + " animating=" + wtoken.animating); |
| 4143 | if (delayed) { |
| 4144 | // set the token aside because it has an active animation to be finished |
| 4145 | mExitingAppTokens.add(wtoken); |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 4146 | } else { |
| 4147 | // Make sure there is no animation running on this token, |
| 4148 | // so any windows associated with it will be removed as |
| 4149 | // soon as their animations are complete |
| 4150 | wtoken.animation = null; |
| 4151 | wtoken.animating = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4152 | } |
| 4153 | mAppTokens.remove(wtoken); |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 4154 | if (mLastEnterAnimToken == wtoken) { |
| 4155 | mLastEnterAnimToken = null; |
| 4156 | mLastEnterAnimParams = null; |
| 4157 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4158 | wtoken.removed = true; |
| 4159 | if (wtoken.startingData != null) { |
| 4160 | startingToken = wtoken; |
| 4161 | } |
| 4162 | unsetAppFreezingScreenLocked(wtoken, true, true); |
| 4163 | if (mFocusedApp == wtoken) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4164 | 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] | 4165 | mFocusedApp = null; |
| 4166 | updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL); |
| Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 4167 | mInputMonitor.setFocusedAppLw(null); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4168 | } |
| 4169 | } else { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4170 | 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] | 4171 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4172 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4173 | if (!delayed && wtoken != null) { |
| 4174 | wtoken.updateReportedVisibilityLocked(); |
| 4175 | } |
| 4176 | } |
| 4177 | Binder.restoreCallingIdentity(origId); |
| 4178 | |
| 4179 | if (startingToken != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4180 | 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] | 4181 | + startingToken + ": app token removed"); |
| 4182 | Message m = mH.obtainMessage(H.REMOVE_STARTING, startingToken); |
| 4183 | mH.sendMessage(m); |
| 4184 | } |
| 4185 | } |
| 4186 | |
| 4187 | private boolean tmpRemoveAppWindowsLocked(WindowToken token) { |
| 4188 | final int NW = token.windows.size(); |
| 4189 | for (int i=0; i<NW; i++) { |
| 4190 | WindowState win = token.windows.get(i); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4191 | 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] | 4192 | mWindows.remove(win); |
| Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 4193 | mWindowsChanged = true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4194 | int j = win.mChildWindows.size(); |
| 4195 | while (j > 0) { |
| 4196 | j--; |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 4197 | WindowState cwin = win.mChildWindows.get(j); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4198 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, |
| Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 4199 | "Tmp removing child window " + cwin); |
| 4200 | mWindows.remove(cwin); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4201 | } |
| 4202 | } |
| 4203 | return NW > 0; |
| 4204 | } |
| 4205 | |
| 4206 | void dumpAppTokensLocked() { |
| 4207 | for (int i=mAppTokens.size()-1; i>=0; i--) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4208 | Slog.v(TAG, " #" + i + ": " + mAppTokens.get(i).token); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4209 | } |
| 4210 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4211 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4212 | void dumpWindowsLocked() { |
| 4213 | for (int i=mWindows.size()-1; i>=0; i--) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4214 | Slog.v(TAG, " #" + i + ": " + mWindows.get(i)); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4215 | } |
| 4216 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4217 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4218 | private int findWindowOffsetLocked(int tokenPos) { |
| 4219 | final int NW = mWindows.size(); |
| 4220 | |
| 4221 | if (tokenPos >= mAppTokens.size()) { |
| 4222 | int i = NW; |
| 4223 | while (i > 0) { |
| 4224 | i--; |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 4225 | WindowState win = mWindows.get(i); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4226 | if (win.getAppToken() != null) { |
| 4227 | return i+1; |
| 4228 | } |
| 4229 | } |
| 4230 | } |
| 4231 | |
| 4232 | while (tokenPos > 0) { |
| 4233 | // Find the first app token below the new position that has |
| 4234 | // a window displayed. |
| 4235 | final AppWindowToken wtoken = mAppTokens.get(tokenPos-1); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4236 | 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] | 4237 | + tokenPos + " -- " + wtoken.token); |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4238 | if (wtoken.sendingToBottom) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4239 | if (DEBUG_REORDER) Slog.v(TAG, |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4240 | "Skipping token -- currently sending to bottom"); |
| 4241 | tokenPos--; |
| 4242 | continue; |
| 4243 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4244 | int i = wtoken.windows.size(); |
| 4245 | while (i > 0) { |
| 4246 | i--; |
| 4247 | WindowState win = wtoken.windows.get(i); |
| 4248 | int j = win.mChildWindows.size(); |
| 4249 | while (j > 0) { |
| 4250 | j--; |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 4251 | WindowState cwin = win.mChildWindows.get(j); |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4252 | if (cwin.mSubLayer >= 0) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4253 | for (int pos=NW-1; pos>=0; pos--) { |
| 4254 | if (mWindows.get(pos) == cwin) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4255 | if (DEBUG_REORDER) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4256 | "Found child win @" + (pos+1)); |
| 4257 | return pos+1; |
| 4258 | } |
| 4259 | } |
| 4260 | } |
| 4261 | } |
| 4262 | for (int pos=NW-1; pos>=0; pos--) { |
| 4263 | if (mWindows.get(pos) == win) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4264 | 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] | 4265 | return pos+1; |
| 4266 | } |
| 4267 | } |
| 4268 | } |
| 4269 | tokenPos--; |
| 4270 | } |
| 4271 | |
| 4272 | return 0; |
| 4273 | } |
| 4274 | |
| 4275 | private final int reAddWindowLocked(int index, WindowState win) { |
| 4276 | final int NCW = win.mChildWindows.size(); |
| 4277 | boolean added = false; |
| 4278 | for (int j=0; j<NCW; j++) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 4279 | WindowState cwin = win.mChildWindows.get(j); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4280 | if (!added && cwin.mSubLayer >= 0) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4281 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding child window at " |
| Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 4282 | + index + ": " + cwin); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4283 | mWindows.add(index, win); |
| 4284 | index++; |
| 4285 | added = true; |
| 4286 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4287 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding window at " |
| Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 4288 | + index + ": " + cwin); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4289 | mWindows.add(index, cwin); |
| 4290 | index++; |
| 4291 | } |
| 4292 | if (!added) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4293 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding window at " |
| Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 4294 | + index + ": " + win); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4295 | mWindows.add(index, win); |
| 4296 | index++; |
| 4297 | } |
| Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 4298 | mWindowsChanged = true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4299 | return index; |
| 4300 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4301 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4302 | private final int reAddAppWindowsLocked(int index, WindowToken token) { |
| 4303 | final int NW = token.windows.size(); |
| 4304 | for (int i=0; i<NW; i++) { |
| 4305 | index = reAddWindowLocked(index, token.windows.get(i)); |
| 4306 | } |
| 4307 | return index; |
| 4308 | } |
| 4309 | |
| 4310 | public void moveAppToken(int index, IBinder token) { |
| 4311 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 4312 | "moveAppToken()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4313 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4314 | } |
| 4315 | |
| 4316 | synchronized(mWindowMap) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4317 | if (DEBUG_REORDER) Slog.v(TAG, "Initial app tokens:"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4318 | if (DEBUG_REORDER) dumpAppTokensLocked(); |
| 4319 | final AppWindowToken wtoken = findAppWindowToken(token); |
| 4320 | if (wtoken == null || !mAppTokens.remove(wtoken)) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4321 | 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] | 4322 | + token + " (" + wtoken + ")"); |
| 4323 | return; |
| 4324 | } |
| 4325 | mAppTokens.add(index, wtoken); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4326 | 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] | 4327 | if (DEBUG_REORDER) dumpAppTokensLocked(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4328 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4329 | final long origId = Binder.clearCallingIdentity(); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4330 | 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] | 4331 | if (DEBUG_REORDER) dumpWindowsLocked(); |
| 4332 | if (tmpRemoveAppWindowsLocked(wtoken)) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4333 | 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] | 4334 | if (DEBUG_REORDER) dumpWindowsLocked(); |
| 4335 | reAddAppWindowsLocked(findWindowOffsetLocked(index), wtoken); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4336 | if (DEBUG_REORDER) Slog.v(TAG, "Final window list:"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4337 | if (DEBUG_REORDER) dumpWindowsLocked(); |
| 4338 | updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4339 | mLayoutNeeded = true; |
| 4340 | performLayoutAndPlaceSurfacesLocked(); |
| 4341 | } |
| 4342 | Binder.restoreCallingIdentity(origId); |
| 4343 | } |
| 4344 | } |
| 4345 | |
| 4346 | private void removeAppTokensLocked(List<IBinder> tokens) { |
| 4347 | // XXX This should be done more efficiently! |
| 4348 | // (take advantage of the fact that both lists should be |
| 4349 | // ordered in the same way.) |
| 4350 | int N = tokens.size(); |
| 4351 | for (int i=0; i<N; i++) { |
| 4352 | IBinder token = tokens.get(i); |
| 4353 | final AppWindowToken wtoken = findAppWindowToken(token); |
| 4354 | if (!mAppTokens.remove(wtoken)) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4355 | 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] | 4356 | + token + " (" + wtoken + ")"); |
| 4357 | i--; |
| 4358 | N--; |
| 4359 | } |
| 4360 | } |
| 4361 | } |
| 4362 | |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4363 | private void moveAppWindowsLocked(AppWindowToken wtoken, int tokenPos, |
| 4364 | boolean updateFocusAndLayout) { |
| 4365 | // First remove all of the windows from the list. |
| 4366 | tmpRemoveAppWindowsLocked(wtoken); |
| 4367 | |
| 4368 | // Where to start adding? |
| 4369 | int pos = findWindowOffsetLocked(tokenPos); |
| 4370 | |
| 4371 | // And now add them back at the correct place. |
| 4372 | pos = reAddAppWindowsLocked(pos, wtoken); |
| 4373 | |
| 4374 | if (updateFocusAndLayout) { |
| 4375 | if (!updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES)) { |
| 4376 | assignLayersLocked(); |
| 4377 | } |
| 4378 | mLayoutNeeded = true; |
| 4379 | performLayoutAndPlaceSurfacesLocked(); |
| 4380 | } |
| 4381 | } |
| 4382 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4383 | private void moveAppWindowsLocked(List<IBinder> tokens, int tokenPos) { |
| 4384 | // First remove all of the windows from the list. |
| 4385 | final int N = tokens.size(); |
| 4386 | int i; |
| 4387 | for (i=0; i<N; i++) { |
| 4388 | WindowToken token = mTokenMap.get(tokens.get(i)); |
| 4389 | if (token != null) { |
| 4390 | tmpRemoveAppWindowsLocked(token); |
| 4391 | } |
| 4392 | } |
| 4393 | |
| 4394 | // Where to start adding? |
| 4395 | int pos = findWindowOffsetLocked(tokenPos); |
| 4396 | |
| 4397 | // And now add them back at the correct place. |
| 4398 | for (i=0; i<N; i++) { |
| 4399 | WindowToken token = mTokenMap.get(tokens.get(i)); |
| 4400 | if (token != null) { |
| 4401 | pos = reAddAppWindowsLocked(pos, token); |
| 4402 | } |
| 4403 | } |
| 4404 | |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4405 | if (!updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES)) { |
| 4406 | assignLayersLocked(); |
| 4407 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4408 | mLayoutNeeded = true; |
| 4409 | performLayoutAndPlaceSurfacesLocked(); |
| 4410 | |
| 4411 | //dump(); |
| 4412 | } |
| 4413 | |
| 4414 | public void moveAppTokensToTop(List<IBinder> tokens) { |
| 4415 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 4416 | "moveAppTokensToTop()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4417 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4418 | } |
| 4419 | |
| 4420 | final long origId = Binder.clearCallingIdentity(); |
| 4421 | synchronized(mWindowMap) { |
| 4422 | removeAppTokensLocked(tokens); |
| 4423 | final int N = tokens.size(); |
| 4424 | for (int i=0; i<N; i++) { |
| 4425 | AppWindowToken wt = findAppWindowToken(tokens.get(i)); |
| 4426 | if (wt != null) { |
| 4427 | mAppTokens.add(wt); |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 4428 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4429 | mToTopApps.remove(wt); |
| 4430 | mToBottomApps.remove(wt); |
| 4431 | mToTopApps.add(wt); |
| 4432 | wt.sendingToBottom = false; |
| 4433 | wt.sendingToTop = true; |
| 4434 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4435 | } |
| 4436 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 4437 | |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 4438 | if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET) { |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4439 | moveAppWindowsLocked(tokens, mAppTokens.size()); |
| 4440 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4441 | } |
| 4442 | Binder.restoreCallingIdentity(origId); |
| 4443 | } |
| 4444 | |
| 4445 | public void moveAppTokensToBottom(List<IBinder> tokens) { |
| 4446 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 4447 | "moveAppTokensToBottom()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4448 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4449 | } |
| 4450 | |
| 4451 | final long origId = Binder.clearCallingIdentity(); |
| 4452 | synchronized(mWindowMap) { |
| 4453 | removeAppTokensLocked(tokens); |
| 4454 | final int N = tokens.size(); |
| 4455 | int pos = 0; |
| 4456 | for (int i=0; i<N; i++) { |
| 4457 | AppWindowToken wt = findAppWindowToken(tokens.get(i)); |
| 4458 | if (wt != null) { |
| 4459 | mAppTokens.add(pos, wt); |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 4460 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4461 | mToTopApps.remove(wt); |
| 4462 | mToBottomApps.remove(wt); |
| 4463 | mToBottomApps.add(i, wt); |
| 4464 | wt.sendingToTop = false; |
| 4465 | wt.sendingToBottom = true; |
| 4466 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4467 | pos++; |
| 4468 | } |
| 4469 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 4470 | |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 4471 | if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET) { |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4472 | moveAppWindowsLocked(tokens, 0); |
| 4473 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4474 | } |
| 4475 | Binder.restoreCallingIdentity(origId); |
| 4476 | } |
| 4477 | |
| 4478 | // ------------------------------------------------------------- |
| 4479 | // Misc IWindowSession methods |
| 4480 | // ------------------------------------------------------------- |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4481 | |
| Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 4482 | private boolean shouldAllowDisableKeyguard() |
| Jim Miller | d6b5705 | 2010-06-07 17:52:42 -0700 | [diff] [blame] | 4483 | { |
| Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 4484 | // We fail safe and prevent disabling keyguard in the unlikely event this gets |
| 4485 | // called before DevicePolicyManagerService has started. |
| 4486 | if (mAllowDisableKeyguard == ALLOW_DISABLE_UNKNOWN) { |
| 4487 | DevicePolicyManager dpm = (DevicePolicyManager) mContext.getSystemService( |
| 4488 | Context.DEVICE_POLICY_SERVICE); |
| 4489 | if (dpm != null) { |
| 4490 | mAllowDisableKeyguard = dpm.getPasswordQuality(null) |
| 4491 | == DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED ? |
| 4492 | ALLOW_DISABLE_YES : ALLOW_DISABLE_NO; |
| 4493 | } |
| Jim Miller | d6b5705 | 2010-06-07 17:52:42 -0700 | [diff] [blame] | 4494 | } |
| Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 4495 | return mAllowDisableKeyguard == ALLOW_DISABLE_YES; |
| Jim Miller | d6b5705 | 2010-06-07 17:52:42 -0700 | [diff] [blame] | 4496 | } |
| 4497 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4498 | public void disableKeyguard(IBinder token, String tag) { |
| Mike Lockwood | 733fdf3 | 2009-09-28 19:08:53 -0400 | [diff] [blame] | 4499 | if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD) |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4500 | != PackageManager.PERMISSION_GRANTED) { |
| 4501 | throw new SecurityException("Requires DISABLE_KEYGUARD permission"); |
| 4502 | } |
| Jim Miller | d6b5705 | 2010-06-07 17:52:42 -0700 | [diff] [blame] | 4503 | |
| Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 4504 | synchronized (mKeyguardTokenWatcher) { |
| 4505 | mKeyguardTokenWatcher.acquire(token, tag); |
| Mike Lockwood | dd88468 | 2009-10-11 16:57:08 -0400 | [diff] [blame] | 4506 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4507 | } |
| 4508 | |
| 4509 | public void reenableKeyguard(IBinder token) { |
| Mike Lockwood | 733fdf3 | 2009-09-28 19:08:53 -0400 | [diff] [blame] | 4510 | if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD) |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4511 | != PackageManager.PERMISSION_GRANTED) { |
| 4512 | throw new SecurityException("Requires DISABLE_KEYGUARD permission"); |
| 4513 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4514 | |
| Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 4515 | synchronized (mKeyguardTokenWatcher) { |
| 4516 | mKeyguardTokenWatcher.release(token); |
| Jim Miller | d6b5705 | 2010-06-07 17:52:42 -0700 | [diff] [blame] | 4517 | |
| Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 4518 | if (!mKeyguardTokenWatcher.isAcquired()) { |
| 4519 | // If we are the last one to reenable the keyguard wait until |
| 4520 | // we have actually finished reenabling until returning. |
| 4521 | // It is possible that reenableKeyguard() can be called before |
| 4522 | // the previous disableKeyguard() is handled, in which case |
| 4523 | // neither mKeyguardTokenWatcher.acquired() or released() would |
| 4524 | // be called. In that case mKeyguardDisabled will be false here |
| 4525 | // and we have nothing to wait for. |
| 4526 | while (mKeyguardDisabled) { |
| 4527 | try { |
| 4528 | mKeyguardTokenWatcher.wait(); |
| 4529 | } catch (InterruptedException e) { |
| 4530 | Thread.currentThread().interrupt(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4531 | } |
| 4532 | } |
| 4533 | } |
| 4534 | } |
| 4535 | } |
| 4536 | |
| 4537 | /** |
| 4538 | * @see android.app.KeyguardManager#exitKeyguardSecurely |
| 4539 | */ |
| 4540 | public void exitKeyguardSecurely(final IOnKeyguardExitResult callback) { |
| Mike Lockwood | 733fdf3 | 2009-09-28 19:08:53 -0400 | [diff] [blame] | 4541 | if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD) |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4542 | != PackageManager.PERMISSION_GRANTED) { |
| 4543 | throw new SecurityException("Requires DISABLE_KEYGUARD permission"); |
| 4544 | } |
| 4545 | mPolicy.exitKeyguardSecurely(new WindowManagerPolicy.OnKeyguardExitResult() { |
| 4546 | public void onKeyguardExitResult(boolean success) { |
| 4547 | try { |
| 4548 | callback.onKeyguardExitResult(success); |
| 4549 | } catch (RemoteException e) { |
| 4550 | // Client has died, we don't care. |
| 4551 | } |
| 4552 | } |
| 4553 | }); |
| 4554 | } |
| 4555 | |
| 4556 | public boolean inKeyguardRestrictedInputMode() { |
| 4557 | return mPolicy.inKeyguardRestrictedKeyInputMode(); |
| 4558 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4559 | |
| Dianne Hackborn | ffa4248 | 2009-09-23 22:20:11 -0700 | [diff] [blame] | 4560 | public void closeSystemDialogs(String reason) { |
| 4561 | synchronized(mWindowMap) { |
| 4562 | for (int i=mWindows.size()-1; i>=0; i--) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 4563 | WindowState w = mWindows.get(i); |
| Dianne Hackborn | ffa4248 | 2009-09-23 22:20:11 -0700 | [diff] [blame] | 4564 | if (w.mSurface != null) { |
| 4565 | try { |
| 4566 | w.mClient.closeSystemDialogs(reason); |
| 4567 | } catch (RemoteException e) { |
| 4568 | } |
| 4569 | } |
| 4570 | } |
| 4571 | } |
| 4572 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 4573 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4574 | static float fixScale(float scale) { |
| 4575 | if (scale < 0) scale = 0; |
| 4576 | else if (scale > 20) scale = 20; |
| 4577 | return Math.abs(scale); |
| 4578 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4579 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4580 | public void setAnimationScale(int which, float scale) { |
| 4581 | if (!checkCallingPermission(android.Manifest.permission.SET_ANIMATION_SCALE, |
| 4582 | "setAnimationScale()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4583 | throw new SecurityException("Requires SET_ANIMATION_SCALE permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4584 | } |
| 4585 | |
| 4586 | if (scale < 0) scale = 0; |
| 4587 | else if (scale > 20) scale = 20; |
| 4588 | scale = Math.abs(scale); |
| 4589 | switch (which) { |
| 4590 | case 0: mWindowAnimationScale = fixScale(scale); break; |
| 4591 | case 1: mTransitionAnimationScale = fixScale(scale); break; |
| 4592 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4593 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4594 | // Persist setting |
| 4595 | mH.obtainMessage(H.PERSIST_ANIMATION_SCALE).sendToTarget(); |
| 4596 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4597 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4598 | public void setAnimationScales(float[] scales) { |
| 4599 | if (!checkCallingPermission(android.Manifest.permission.SET_ANIMATION_SCALE, |
| 4600 | "setAnimationScale()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4601 | throw new SecurityException("Requires SET_ANIMATION_SCALE permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4602 | } |
| 4603 | |
| 4604 | if (scales != null) { |
| 4605 | if (scales.length >= 1) { |
| 4606 | mWindowAnimationScale = fixScale(scales[0]); |
| 4607 | } |
| 4608 | if (scales.length >= 2) { |
| 4609 | mTransitionAnimationScale = fixScale(scales[1]); |
| 4610 | } |
| 4611 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4612 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4613 | // Persist setting |
| 4614 | mH.obtainMessage(H.PERSIST_ANIMATION_SCALE).sendToTarget(); |
| 4615 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4616 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4617 | public float getAnimationScale(int which) { |
| 4618 | switch (which) { |
| 4619 | case 0: return mWindowAnimationScale; |
| 4620 | case 1: return mTransitionAnimationScale; |
| 4621 | } |
| 4622 | return 0; |
| 4623 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4624 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4625 | public float[] getAnimationScales() { |
| 4626 | return new float[] { mWindowAnimationScale, mTransitionAnimationScale }; |
| 4627 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4628 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4629 | public int getSwitchState(int sw) { |
| 4630 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4631 | "getSwitchState()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4632 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4633 | } |
| Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 4634 | return mInputManager.getSwitchState(-1, InputDevice.SOURCE_ANY, sw); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4635 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4636 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4637 | public int getSwitchStateForDevice(int devid, int sw) { |
| 4638 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4639 | "getSwitchStateForDevice()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4640 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4641 | } |
| Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 4642 | return mInputManager.getSwitchState(devid, InputDevice.SOURCE_ANY, sw); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4643 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4644 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4645 | public int getScancodeState(int sw) { |
| 4646 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4647 | "getScancodeState()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4648 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4649 | } |
| Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 4650 | return mInputManager.getScanCodeState(-1, InputDevice.SOURCE_ANY, sw); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4651 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4652 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4653 | public int getScancodeStateForDevice(int devid, int sw) { |
| 4654 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4655 | "getScancodeStateForDevice()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4656 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4657 | } |
| Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 4658 | return mInputManager.getScanCodeState(devid, InputDevice.SOURCE_ANY, sw); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4659 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4660 | |
| Dianne Hackborn | 1d62ea9 | 2009-11-17 12:49:50 -0800 | [diff] [blame] | 4661 | public int getTrackballScancodeState(int sw) { |
| 4662 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4663 | "getTrackballScancodeState()")) { |
| 4664 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
| 4665 | } |
| Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 4666 | return mInputManager.getScanCodeState(-1, InputDevice.SOURCE_TRACKBALL, sw); |
| Dianne Hackborn | 1d62ea9 | 2009-11-17 12:49:50 -0800 | [diff] [blame] | 4667 | } |
| 4668 | |
| 4669 | public int getDPadScancodeState(int sw) { |
| 4670 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4671 | "getDPadScancodeState()")) { |
| 4672 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
| 4673 | } |
| Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 4674 | return mInputManager.getScanCodeState(-1, InputDevice.SOURCE_DPAD, sw); |
| Dianne Hackborn | 1d62ea9 | 2009-11-17 12:49:50 -0800 | [diff] [blame] | 4675 | } |
| 4676 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4677 | public int getKeycodeState(int sw) { |
| 4678 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4679 | "getKeycodeState()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4680 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4681 | } |
| Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 4682 | return mInputManager.getKeyCodeState(-1, InputDevice.SOURCE_ANY, sw); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4683 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4684 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4685 | public int getKeycodeStateForDevice(int devid, int sw) { |
| 4686 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4687 | "getKeycodeStateForDevice()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4688 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4689 | } |
| Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 4690 | return mInputManager.getKeyCodeState(devid, InputDevice.SOURCE_ANY, sw); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4691 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4692 | |
| Dianne Hackborn | 1d62ea9 | 2009-11-17 12:49:50 -0800 | [diff] [blame] | 4693 | public int getTrackballKeycodeState(int sw) { |
| 4694 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4695 | "getTrackballKeycodeState()")) { |
| 4696 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
| 4697 | } |
| Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 4698 | return mInputManager.getKeyCodeState(-1, InputDevice.SOURCE_TRACKBALL, sw); |
| Dianne Hackborn | 1d62ea9 | 2009-11-17 12:49:50 -0800 | [diff] [blame] | 4699 | } |
| 4700 | |
| 4701 | public int getDPadKeycodeState(int sw) { |
| 4702 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4703 | "getDPadKeycodeState()")) { |
| 4704 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
| 4705 | } |
| Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 4706 | return mInputManager.getKeyCodeState(-1, InputDevice.SOURCE_DPAD, sw); |
| Dianne Hackborn | 1d62ea9 | 2009-11-17 12:49:50 -0800 | [diff] [blame] | 4707 | } |
| Jeff Brown | a41ca77 | 2010-08-11 14:46:32 -0700 | [diff] [blame] | 4708 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4709 | public boolean hasKeys(int[] keycodes, boolean[] keyExists) { |
| Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 4710 | return mInputManager.hasKeys(-1, InputDevice.SOURCE_ANY, keycodes, keyExists); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4711 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4712 | |
| Jeff Brown | a41ca77 | 2010-08-11 14:46:32 -0700 | [diff] [blame] | 4713 | public InputChannel monitorInput(String inputChannelName) { |
| 4714 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4715 | "monitorInput()")) { |
| 4716 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
| 4717 | } |
| 4718 | return mInputManager.monitorInput(inputChannelName); |
| 4719 | } |
| 4720 | |
| Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 4721 | public InputDevice getInputDevice(int deviceId) { |
| 4722 | return mInputManager.getInputDevice(deviceId); |
| 4723 | } |
| 4724 | |
| 4725 | public int[] getInputDeviceIds() { |
| 4726 | return mInputManager.getInputDeviceIds(); |
| 4727 | } |
| 4728 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4729 | public void enableScreenAfterBoot() { |
| 4730 | synchronized(mWindowMap) { |
| 4731 | if (mSystemBooted) { |
| 4732 | return; |
| 4733 | } |
| 4734 | mSystemBooted = true; |
| 4735 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4736 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4737 | performEnableScreen(); |
| 4738 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4739 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4740 | public void enableScreenIfNeededLocked() { |
| 4741 | if (mDisplayEnabled) { |
| 4742 | return; |
| 4743 | } |
| 4744 | if (!mSystemBooted) { |
| 4745 | return; |
| 4746 | } |
| 4747 | mH.sendMessage(mH.obtainMessage(H.ENABLE_SCREEN)); |
| 4748 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4749 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4750 | public void performEnableScreen() { |
| 4751 | synchronized(mWindowMap) { |
| 4752 | if (mDisplayEnabled) { |
| 4753 | return; |
| 4754 | } |
| 4755 | if (!mSystemBooted) { |
| 4756 | return; |
| 4757 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4758 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4759 | // Don't enable the screen until all existing windows |
| 4760 | // have been drawn. |
| 4761 | final int N = mWindows.size(); |
| 4762 | for (int i=0; i<N; i++) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 4763 | WindowState w = mWindows.get(i); |
| Dianne Hackborn | f3bea9c | 2009-12-09 18:26:21 -0800 | [diff] [blame] | 4764 | if (w.isVisibleLw() && !w.mObscured && !w.isDrawnLw()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4765 | return; |
| 4766 | } |
| 4767 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4768 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4769 | mDisplayEnabled = true; |
| 4770 | if (false) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4771 | Slog.i(TAG, "ENABLING SCREEN!"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4772 | StringWriter sw = new StringWriter(); |
| 4773 | PrintWriter pw = new PrintWriter(sw); |
| 4774 | this.dump(null, pw, null); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4775 | Slog.i(TAG, sw.toString()); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4776 | } |
| 4777 | try { |
| 4778 | IBinder surfaceFlinger = ServiceManager.getService("SurfaceFlinger"); |
| 4779 | if (surfaceFlinger != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4780 | //Slog.i(TAG, "******* TELLING SURFACE FLINGER WE ARE BOOTED!"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4781 | Parcel data = Parcel.obtain(); |
| 4782 | data.writeInterfaceToken("android.ui.ISurfaceComposer"); |
| 4783 | surfaceFlinger.transact(IBinder.FIRST_CALL_TRANSACTION, |
| 4784 | data, null, 0); |
| 4785 | data.recycle(); |
| 4786 | } |
| 4787 | } catch (RemoteException ex) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4788 | Slog.e(TAG, "Boot completed: SurfaceFlinger is dead!"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4789 | } |
| 4790 | } |
| 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 | mPolicy.enableScreenAfterBoot(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4793 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4794 | // Make sure the last requested orientation has been applied. |
| Dianne Hackborn | 321ae68 | 2009-03-27 16:16:03 -0700 | [diff] [blame] | 4795 | setRotationUnchecked(WindowManagerPolicy.USE_LAST_ROTATION, false, |
| 4796 | mLastRotationFlags | Surface.FLAGS_ORIENTATION_ANIMATION_DISABLE); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4797 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4798 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4799 | public void setInTouchMode(boolean mode) { |
| 4800 | synchronized(mWindowMap) { |
| 4801 | mInTouchMode = mode; |
| 4802 | } |
| 4803 | } |
| 4804 | |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4805 | public void setRotation(int rotation, |
| Dianne Hackborn | 1e880db | 2009-03-27 16:04:08 -0700 | [diff] [blame] | 4806 | boolean alwaysSendConfiguration, int animFlags) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4807 | if (!checkCallingPermission(android.Manifest.permission.SET_ORIENTATION, |
| Dianne Hackborn | 1e880db | 2009-03-27 16:04:08 -0700 | [diff] [blame] | 4808 | "setRotation()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4809 | throw new SecurityException("Requires SET_ORIENTATION permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4810 | } |
| 4811 | |
| Dianne Hackborn | 1e880db | 2009-03-27 16:04:08 -0700 | [diff] [blame] | 4812 | setRotationUnchecked(rotation, alwaysSendConfiguration, animFlags); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4813 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4814 | |
| Dianne Hackborn | 1e880db | 2009-03-27 16:04:08 -0700 | [diff] [blame] | 4815 | public void setRotationUnchecked(int rotation, |
| 4816 | boolean alwaysSendConfiguration, int animFlags) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4817 | if(DEBUG_ORIENTATION) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4818 | "alwaysSendConfiguration set to "+alwaysSendConfiguration); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4819 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4820 | long origId = Binder.clearCallingIdentity(); |
| 4821 | boolean changed; |
| 4822 | synchronized(mWindowMap) { |
| Dianne Hackborn | 1e880db | 2009-03-27 16:04:08 -0700 | [diff] [blame] | 4823 | changed = setRotationUncheckedLocked(rotation, animFlags); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4824 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4825 | |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 4826 | if (changed || alwaysSendConfiguration) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4827 | sendNewConfiguration(); |
| 4828 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4829 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4830 | Binder.restoreCallingIdentity(origId); |
| 4831 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4832 | |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 4833 | /** |
| 4834 | * Apply a new rotation to the screen, respecting the requests of |
| 4835 | * applications. Use WindowManagerPolicy.USE_LAST_ROTATION to simply |
| 4836 | * re-evaluate the desired rotation. |
| 4837 | * |
| 4838 | * Returns null if the rotation has been changed. In this case YOU |
| 4839 | * MUST CALL setNewConfiguration() TO UNFREEZE THE SCREEN. |
| 4840 | */ |
| Dianne Hackborn | 1e880db | 2009-03-27 16:04:08 -0700 | [diff] [blame] | 4841 | public boolean setRotationUncheckedLocked(int rotation, int animFlags) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4842 | boolean changed; |
| 4843 | if (rotation == WindowManagerPolicy.USE_LAST_ROTATION) { |
| 4844 | rotation = mRequestedRotation; |
| 4845 | } else { |
| 4846 | mRequestedRotation = rotation; |
| Dianne Hackborn | 321ae68 | 2009-03-27 16:16:03 -0700 | [diff] [blame] | 4847 | mLastRotationFlags = animFlags; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4848 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4849 | 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] | 4850 | rotation = mPolicy.rotationForOrientationLw(mForcedAppOrientation, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4851 | mRotation, mDisplayEnabled); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4852 | 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] | 4853 | changed = mDisplayEnabled && mRotation != rotation; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4854 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4855 | if (changed) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4856 | if (DEBUG_ORIENTATION) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4857 | "Rotation changed to " + rotation |
| 4858 | + " from " + mRotation |
| 4859 | + " (forceApp=" + mForcedAppOrientation |
| 4860 | + ", req=" + mRequestedRotation + ")"); |
| 4861 | mRotation = rotation; |
| 4862 | mWindowsFreezingScreen = true; |
| 4863 | mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT); |
| 4864 | mH.sendMessageDelayed(mH.obtainMessage(H.WINDOW_FREEZE_TIMEOUT), |
| 4865 | 2000); |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 4866 | mWaitingForConfig = true; |
| 4867 | mLayoutNeeded = true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4868 | startFreezingDisplayLocked(); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4869 | Slog.i(TAG, "Setting rotation to " + rotation + ", animFlags=" + animFlags); |
| Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 4870 | mInputManager.setDisplayOrientation(0, rotation); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4871 | if (mDisplayEnabled) { |
| Dianne Hackborn | 321ae68 | 2009-03-27 16:16:03 -0700 | [diff] [blame] | 4872 | Surface.setOrientation(0, rotation, animFlags); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4873 | } |
| 4874 | for (int i=mWindows.size()-1; i>=0; i--) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 4875 | WindowState w = mWindows.get(i); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4876 | if (w.mSurface != null) { |
| 4877 | w.mOrientationChanging = true; |
| 4878 | } |
| 4879 | } |
| 4880 | for (int i=mRotationWatchers.size()-1; i>=0; i--) { |
| 4881 | try { |
| 4882 | mRotationWatchers.get(i).onRotationChanged(rotation); |
| 4883 | } catch (RemoteException e) { |
| 4884 | } |
| 4885 | } |
| 4886 | } //end if changed |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4887 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4888 | return changed; |
| 4889 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4890 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4891 | public int getRotation() { |
| 4892 | return mRotation; |
| 4893 | } |
| 4894 | |
| 4895 | public int watchRotation(IRotationWatcher watcher) { |
| 4896 | final IBinder watcherBinder = watcher.asBinder(); |
| 4897 | IBinder.DeathRecipient dr = new IBinder.DeathRecipient() { |
| 4898 | public void binderDied() { |
| 4899 | synchronized (mWindowMap) { |
| 4900 | for (int i=0; i<mRotationWatchers.size(); i++) { |
| 4901 | if (watcherBinder == mRotationWatchers.get(i).asBinder()) { |
| Suchi Amalapurapu | fff2fda | 2009-06-30 21:36:16 -0700 | [diff] [blame] | 4902 | IRotationWatcher removed = mRotationWatchers.remove(i); |
| 4903 | if (removed != null) { |
| 4904 | removed.asBinder().unlinkToDeath(this, 0); |
| 4905 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4906 | i--; |
| 4907 | } |
| 4908 | } |
| 4909 | } |
| 4910 | } |
| 4911 | }; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4912 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4913 | synchronized (mWindowMap) { |
| 4914 | try { |
| 4915 | watcher.asBinder().linkToDeath(dr, 0); |
| 4916 | mRotationWatchers.add(watcher); |
| 4917 | } catch (RemoteException e) { |
| 4918 | // Client died, no cleanup needed. |
| 4919 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4920 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4921 | return mRotation; |
| 4922 | } |
| 4923 | } |
| 4924 | |
| 4925 | /** |
| 4926 | * Starts the view server on the specified port. |
| 4927 | * |
| 4928 | * @param port The port to listener to. |
| 4929 | * |
| 4930 | * @return True if the server was successfully started, false otherwise. |
| 4931 | * |
| 4932 | * @see com.android.server.ViewServer |
| 4933 | * @see com.android.server.ViewServer#VIEW_SERVER_DEFAULT_PORT |
| 4934 | */ |
| 4935 | public boolean startViewServer(int port) { |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4936 | if (isSystemSecure()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4937 | return false; |
| 4938 | } |
| 4939 | |
| 4940 | if (!checkCallingPermission(Manifest.permission.DUMP, "startViewServer")) { |
| 4941 | return false; |
| 4942 | } |
| 4943 | |
| 4944 | if (port < 1024) { |
| 4945 | return false; |
| 4946 | } |
| 4947 | |
| 4948 | if (mViewServer != null) { |
| 4949 | if (!mViewServer.isRunning()) { |
| 4950 | try { |
| 4951 | return mViewServer.start(); |
| 4952 | } catch (IOException e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4953 | Slog.w(TAG, "View server did not start"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4954 | } |
| 4955 | } |
| 4956 | return false; |
| 4957 | } |
| 4958 | |
| 4959 | try { |
| 4960 | mViewServer = new ViewServer(this, port); |
| 4961 | return mViewServer.start(); |
| 4962 | } catch (IOException e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4963 | Slog.w(TAG, "View server did not start"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4964 | } |
| 4965 | return false; |
| 4966 | } |
| 4967 | |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4968 | private boolean isSystemSecure() { |
| 4969 | return "1".equals(SystemProperties.get(SYSTEM_SECURE, "1")) && |
| 4970 | "0".equals(SystemProperties.get(SYSTEM_DEBUGGABLE, "0")); |
| 4971 | } |
| 4972 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4973 | /** |
| 4974 | * Stops the view server if it exists. |
| 4975 | * |
| 4976 | * @return True if the server stopped, false if it wasn't started or |
| 4977 | * couldn't be stopped. |
| 4978 | * |
| 4979 | * @see com.android.server.ViewServer |
| 4980 | */ |
| 4981 | public boolean stopViewServer() { |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4982 | if (isSystemSecure()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4983 | return false; |
| 4984 | } |
| 4985 | |
| 4986 | if (!checkCallingPermission(Manifest.permission.DUMP, "stopViewServer")) { |
| 4987 | return false; |
| 4988 | } |
| 4989 | |
| 4990 | if (mViewServer != null) { |
| 4991 | return mViewServer.stop(); |
| 4992 | } |
| 4993 | return false; |
| 4994 | } |
| 4995 | |
| 4996 | /** |
| 4997 | * Indicates whether the view server is running. |
| 4998 | * |
| 4999 | * @return True if the server is running, false otherwise. |
| 5000 | * |
| 5001 | * @see com.android.server.ViewServer |
| 5002 | */ |
| 5003 | public boolean isViewServerRunning() { |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5004 | if (isSystemSecure()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5005 | return false; |
| 5006 | } |
| 5007 | |
| 5008 | if (!checkCallingPermission(Manifest.permission.DUMP, "isViewServerRunning")) { |
| 5009 | return false; |
| 5010 | } |
| 5011 | |
| 5012 | return mViewServer != null && mViewServer.isRunning(); |
| 5013 | } |
| 5014 | |
| 5015 | /** |
| 5016 | * Lists all availble windows in the system. The listing is written in the |
| 5017 | * specified Socket's output stream with the following syntax: |
| 5018 | * windowHashCodeInHexadecimal windowName |
| 5019 | * Each line of the ouput represents a different window. |
| 5020 | * |
| 5021 | * @param client The remote client to send the listing to. |
| 5022 | * @return False if an error occured, true otherwise. |
| 5023 | */ |
| 5024 | boolean viewServerListWindows(Socket client) { |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5025 | if (isSystemSecure()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5026 | return false; |
| 5027 | } |
| 5028 | |
| 5029 | boolean result = true; |
| 5030 | |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 5031 | WindowState[] windows; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5032 | synchronized (mWindowMap) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5033 | //noinspection unchecked |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 5034 | windows = mWindows.toArray(new WindowState[mWindows.size()]); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5035 | } |
| 5036 | |
| 5037 | BufferedWriter out = null; |
| 5038 | |
| 5039 | // Any uncaught exception will crash the system process |
| 5040 | try { |
| 5041 | OutputStream clientStream = client.getOutputStream(); |
| 5042 | out = new BufferedWriter(new OutputStreamWriter(clientStream), 8 * 1024); |
| 5043 | |
| 5044 | final int count = windows.length; |
| 5045 | for (int i = 0; i < count; i++) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 5046 | final WindowState w = windows[i]; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5047 | out.write(Integer.toHexString(System.identityHashCode(w))); |
| 5048 | out.write(' '); |
| 5049 | out.append(w.mAttrs.getTitle()); |
| 5050 | out.write('\n'); |
| 5051 | } |
| 5052 | |
| 5053 | out.write("DONE.\n"); |
| 5054 | out.flush(); |
| 5055 | } catch (Exception e) { |
| 5056 | result = false; |
| 5057 | } finally { |
| 5058 | if (out != null) { |
| 5059 | try { |
| 5060 | out.close(); |
| 5061 | } catch (IOException e) { |
| 5062 | result = false; |
| 5063 | } |
| 5064 | } |
| 5065 | } |
| 5066 | |
| 5067 | return result; |
| 5068 | } |
| 5069 | |
| 5070 | /** |
| Konstantin Lopyrev | f962476 | 2010-07-14 17:02:37 -0700 | [diff] [blame] | 5071 | * Returns the focused window in the following format: |
| 5072 | * windowHashCodeInHexadecimal windowName |
| 5073 | * |
| 5074 | * @param client The remote client to send the listing to. |
| 5075 | * @return False if an error occurred, true otherwise. |
| 5076 | */ |
| 5077 | boolean viewServerGetFocusedWindow(Socket client) { |
| 5078 | if (isSystemSecure()) { |
| 5079 | return false; |
| 5080 | } |
| 5081 | |
| 5082 | boolean result = true; |
| 5083 | |
| 5084 | WindowState focusedWindow = getFocusedWindow(); |
| 5085 | |
| 5086 | BufferedWriter out = null; |
| 5087 | |
| 5088 | // Any uncaught exception will crash the system process |
| 5089 | try { |
| 5090 | OutputStream clientStream = client.getOutputStream(); |
| 5091 | out = new BufferedWriter(new OutputStreamWriter(clientStream), 8 * 1024); |
| 5092 | |
| 5093 | if(focusedWindow != null) { |
| 5094 | out.write(Integer.toHexString(System.identityHashCode(focusedWindow))); |
| 5095 | out.write(' '); |
| 5096 | out.append(focusedWindow.mAttrs.getTitle()); |
| 5097 | } |
| 5098 | out.write('\n'); |
| 5099 | out.flush(); |
| 5100 | } catch (Exception e) { |
| 5101 | result = false; |
| 5102 | } finally { |
| 5103 | if (out != null) { |
| 5104 | try { |
| 5105 | out.close(); |
| 5106 | } catch (IOException e) { |
| 5107 | result = false; |
| 5108 | } |
| 5109 | } |
| 5110 | } |
| 5111 | |
| 5112 | return result; |
| 5113 | } |
| 5114 | |
| 5115 | /** |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5116 | * Sends a command to a target window. The result of the command, if any, will be |
| 5117 | * written in the output stream of the specified socket. |
| 5118 | * |
| 5119 | * The parameters must follow this syntax: |
| 5120 | * windowHashcode extra |
| 5121 | * |
| 5122 | * Where XX is the length in characeters of the windowTitle. |
| 5123 | * |
| 5124 | * The first parameter is the target window. The window with the specified hashcode |
| 5125 | * will be the target. If no target can be found, nothing happens. The extra parameters |
| 5126 | * will be delivered to the target window and as parameters to the command itself. |
| 5127 | * |
| 5128 | * @param client The remote client to sent the result, if any, to. |
| 5129 | * @param command The command to execute. |
| 5130 | * @param parameters The command parameters. |
| 5131 | * |
| 5132 | * @return True if the command was successfully delivered, false otherwise. This does |
| 5133 | * not indicate whether the command itself was successful. |
| 5134 | */ |
| 5135 | boolean viewServerWindowCommand(Socket client, String command, String parameters) { |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5136 | if (isSystemSecure()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5137 | return false; |
| 5138 | } |
| 5139 | |
| 5140 | boolean success = true; |
| 5141 | Parcel data = null; |
| 5142 | Parcel reply = null; |
| 5143 | |
| Konstantin Lopyrev | 43b9b48 | 2010-08-24 22:00:12 -0700 | [diff] [blame] | 5144 | BufferedWriter out = null; |
| 5145 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5146 | // Any uncaught exception will crash the system process |
| 5147 | try { |
| 5148 | // Find the hashcode of the window |
| 5149 | int index = parameters.indexOf(' '); |
| 5150 | if (index == -1) { |
| 5151 | index = parameters.length(); |
| 5152 | } |
| 5153 | final String code = parameters.substring(0, index); |
| Romain Guy | 236092a | 2009-12-14 15:31:48 -0800 | [diff] [blame] | 5154 | int hashCode = (int) Long.parseLong(code, 16); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5155 | |
| 5156 | // Extract the command's parameter after the window description |
| 5157 | if (index < parameters.length()) { |
| 5158 | parameters = parameters.substring(index + 1); |
| 5159 | } else { |
| 5160 | parameters = ""; |
| 5161 | } |
| 5162 | |
| 5163 | final WindowManagerService.WindowState window = findWindow(hashCode); |
| 5164 | if (window == null) { |
| 5165 | return false; |
| 5166 | } |
| 5167 | |
| 5168 | data = Parcel.obtain(); |
| 5169 | data.writeInterfaceToken("android.view.IWindow"); |
| 5170 | data.writeString(command); |
| 5171 | data.writeString(parameters); |
| 5172 | data.writeInt(1); |
| 5173 | ParcelFileDescriptor.fromSocket(client).writeToParcel(data, 0); |
| 5174 | |
| 5175 | reply = Parcel.obtain(); |
| 5176 | |
| 5177 | final IBinder binder = window.mClient.asBinder(); |
| 5178 | // TODO: GET THE TRANSACTION CODE IN A SAFER MANNER |
| 5179 | binder.transact(IBinder.FIRST_CALL_TRANSACTION, data, reply, 0); |
| 5180 | |
| 5181 | reply.readException(); |
| 5182 | |
| Konstantin Lopyrev | 43b9b48 | 2010-08-24 22:00:12 -0700 | [diff] [blame] | 5183 | if (!client.isOutputShutdown()) { |
| 5184 | out = new BufferedWriter(new OutputStreamWriter(client.getOutputStream())); |
| 5185 | out.write("DONE\n"); |
| 5186 | out.flush(); |
| 5187 | } |
| 5188 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5189 | } catch (Exception e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5190 | 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] | 5191 | success = false; |
| 5192 | } finally { |
| 5193 | if (data != null) { |
| 5194 | data.recycle(); |
| 5195 | } |
| 5196 | if (reply != null) { |
| 5197 | reply.recycle(); |
| 5198 | } |
| Konstantin Lopyrev | 43b9b48 | 2010-08-24 22:00:12 -0700 | [diff] [blame] | 5199 | if (out != null) { |
| 5200 | try { |
| 5201 | out.close(); |
| 5202 | } catch (IOException e) { |
| 5203 | |
| 5204 | } |
| 5205 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5206 | } |
| 5207 | |
| 5208 | return success; |
| 5209 | } |
| 5210 | |
| Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 5211 | public void addWindowChangeListener(WindowChangeListener listener) { |
| 5212 | synchronized(mWindowMap) { |
| 5213 | mWindowChangeListeners.add(listener); |
| 5214 | } |
| 5215 | } |
| 5216 | |
| 5217 | public void removeWindowChangeListener(WindowChangeListener listener) { |
| 5218 | synchronized(mWindowMap) { |
| 5219 | mWindowChangeListeners.remove(listener); |
| 5220 | } |
| 5221 | } |
| 5222 | |
| 5223 | private void notifyWindowsChanged() { |
| 5224 | WindowChangeListener[] windowChangeListeners; |
| 5225 | synchronized(mWindowMap) { |
| 5226 | if(mWindowChangeListeners.isEmpty()) { |
| 5227 | return; |
| 5228 | } |
| 5229 | windowChangeListeners = new WindowChangeListener[mWindowChangeListeners.size()]; |
| 5230 | windowChangeListeners = mWindowChangeListeners.toArray(windowChangeListeners); |
| 5231 | } |
| 5232 | int N = windowChangeListeners.length; |
| 5233 | for(int i = 0; i < N; i++) { |
| 5234 | windowChangeListeners[i].windowsChanged(); |
| 5235 | } |
| 5236 | } |
| 5237 | |
| Konstantin Lopyrev | 6e0f65f | 2010-07-14 14:55:33 -0700 | [diff] [blame] | 5238 | private void notifyFocusChanged() { |
| 5239 | WindowChangeListener[] windowChangeListeners; |
| 5240 | synchronized(mWindowMap) { |
| 5241 | if(mWindowChangeListeners.isEmpty()) { |
| 5242 | return; |
| 5243 | } |
| 5244 | windowChangeListeners = new WindowChangeListener[mWindowChangeListeners.size()]; |
| 5245 | windowChangeListeners = mWindowChangeListeners.toArray(windowChangeListeners); |
| 5246 | } |
| 5247 | int N = windowChangeListeners.length; |
| 5248 | for(int i = 0; i < N; i++) { |
| 5249 | windowChangeListeners[i].focusChanged(); |
| 5250 | } |
| 5251 | } |
| 5252 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5253 | private WindowState findWindow(int hashCode) { |
| 5254 | if (hashCode == -1) { |
| 5255 | return getFocusedWindow(); |
| 5256 | } |
| 5257 | |
| 5258 | synchronized (mWindowMap) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 5259 | final ArrayList<WindowState> windows = mWindows; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5260 | final int count = windows.size(); |
| 5261 | |
| 5262 | for (int i = 0; i < count; i++) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 5263 | WindowState w = windows.get(i); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5264 | if (System.identityHashCode(w) == hashCode) { |
| 5265 | return w; |
| 5266 | } |
| 5267 | } |
| 5268 | } |
| 5269 | |
| 5270 | return null; |
| 5271 | } |
| 5272 | |
| 5273 | /* |
| 5274 | * Instruct the Activity Manager to fetch the current configuration and broadcast |
| 5275 | * that to config-changed listeners if appropriate. |
| 5276 | */ |
| 5277 | void sendNewConfiguration() { |
| 5278 | try { |
| 5279 | mActivityManager.updateConfiguration(null); |
| 5280 | } catch (RemoteException e) { |
| 5281 | } |
| 5282 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5283 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5284 | public Configuration computeNewConfiguration() { |
| 5285 | synchronized (mWindowMap) { |
| Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 5286 | return computeNewConfigurationLocked(); |
| 5287 | } |
| 5288 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5289 | |
| Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 5290 | Configuration computeNewConfigurationLocked() { |
| 5291 | Configuration config = new Configuration(); |
| 5292 | if (!computeNewConfigurationLocked(config)) { |
| 5293 | return null; |
| 5294 | } |
| Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 5295 | return config; |
| 5296 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5297 | |
| Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 5298 | boolean computeNewConfigurationLocked(Configuration config) { |
| 5299 | if (mDisplay == null) { |
| 5300 | return false; |
| 5301 | } |
| Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 5302 | |
| 5303 | mInputManager.getInputConfiguration(config); |
| Christopher Tate | b696aee | 2010-04-02 19:08:30 -0700 | [diff] [blame] | 5304 | |
| 5305 | // Use the effective "visual" dimensions based on current rotation |
| 5306 | final boolean rotated = (mRotation == Surface.ROTATION_90 |
| 5307 | || mRotation == Surface.ROTATION_270); |
| 5308 | final int dw = rotated ? mInitialDisplayHeight : mInitialDisplayWidth; |
| 5309 | final int dh = rotated ? mInitialDisplayWidth : mInitialDisplayHeight; |
| 5310 | |
| Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 5311 | int orientation = Configuration.ORIENTATION_SQUARE; |
| 5312 | if (dw < dh) { |
| 5313 | orientation = Configuration.ORIENTATION_PORTRAIT; |
| 5314 | } else if (dw > dh) { |
| 5315 | orientation = Configuration.ORIENTATION_LANDSCAPE; |
| 5316 | } |
| 5317 | config.orientation = orientation; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 5318 | |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 5319 | DisplayMetrics dm = new DisplayMetrics(); |
| 5320 | mDisplay.getMetrics(dm); |
| 5321 | CompatibilityInfo.updateCompatibleScreenFrame(dm, orientation, mCompatibleScreenFrame); |
| 5322 | |
| Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 5323 | if (mScreenLayout == Configuration.SCREENLAYOUT_SIZE_UNDEFINED) { |
| Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 5324 | // Note we only do this once because at this point we don't |
| 5325 | // expect the screen to change in this way at runtime, and want |
| 5326 | // to avoid all of this computation for every config change. |
| Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 5327 | int longSize = dw; |
| 5328 | int shortSize = dh; |
| 5329 | if (longSize < shortSize) { |
| 5330 | int tmp = longSize; |
| 5331 | longSize = shortSize; |
| 5332 | shortSize = tmp; |
| 5333 | } |
| 5334 | longSize = (int)(longSize/dm.density); |
| 5335 | shortSize = (int)(shortSize/dm.density); |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 5336 | |
| Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 5337 | // These semi-magic numbers define our compatibility modes for |
| 5338 | // applications with different screens. Don't change unless you |
| 5339 | // make sure to test lots and lots of apps! |
| 5340 | if (longSize < 470) { |
| 5341 | // This is shorter than an HVGA normal density screen (which |
| 5342 | // is 480 pixels on its long side). |
| Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 5343 | mScreenLayout = Configuration.SCREENLAYOUT_SIZE_SMALL |
| 5344 | | Configuration.SCREENLAYOUT_LONG_NO; |
| Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 5345 | } else { |
| Dianne Hackborn | 14cee9f | 2010-04-23 17:51:26 -0700 | [diff] [blame] | 5346 | // What size is this screen screen? |
| 5347 | if (longSize >= 800 && shortSize >= 600) { |
| 5348 | // SVGA or larger screens at medium density are the point |
| 5349 | // at which we consider it to be an extra large screen. |
| 5350 | mScreenLayout = Configuration.SCREENLAYOUT_SIZE_XLARGE; |
| 5351 | } else if (longSize >= 640 && shortSize >= 480) { |
| Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 5352 | // VGA or larger screens at medium density are the point |
| 5353 | // at which we consider it to be a large screen. |
| 5354 | mScreenLayout = Configuration.SCREENLAYOUT_SIZE_LARGE; |
| 5355 | } else { |
| 5356 | mScreenLayout = Configuration.SCREENLAYOUT_SIZE_NORMAL; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 5357 | |
| Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 5358 | // If this screen is wider than normal HVGA, or taller |
| 5359 | // than FWVGA, then for old apps we want to run in size |
| 5360 | // compatibility mode. |
| 5361 | if (shortSize > 321 || longSize > 570) { |
| 5362 | mScreenLayout |= Configuration.SCREENLAYOUT_COMPAT_NEEDED; |
| 5363 | } |
| 5364 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 5365 | |
| Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 5366 | // Is this a long screen? |
| 5367 | if (((longSize*3)/5) >= (shortSize-1)) { |
| 5368 | // Anything wider than WVGA (5:3) is considering to be long. |
| 5369 | mScreenLayout |= Configuration.SCREENLAYOUT_LONG_YES; |
| 5370 | } else { |
| 5371 | mScreenLayout |= Configuration.SCREENLAYOUT_LONG_NO; |
| 5372 | } |
| Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 5373 | } |
| 5374 | } |
| Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 5375 | config.screenLayout = mScreenLayout; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 5376 | |
| Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 5377 | config.keyboardHidden = Configuration.KEYBOARDHIDDEN_NO; |
| 5378 | config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_NO; |
| 5379 | mPolicy.adjustConfigurationLw(config); |
| 5380 | return true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5381 | } |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5382 | |
| 5383 | // ------------------------------------------------------------- |
| 5384 | // Drag and drop |
| 5385 | // ------------------------------------------------------------- |
| 5386 | |
| 5387 | IBinder prepareDragSurface(IWindow window, SurfaceSession session, |
| 5388 | boolean localOnly, int width, int height, Surface outSurface) { |
| 5389 | if (DEBUG_DRAG) { |
| 5390 | Slog.d(TAG, "prepare drag surface: w=" + width + " h=" + height |
| 5391 | + " local=" + localOnly + " win=" + window |
| 5392 | + " asbinder=" + window.asBinder()); |
| 5393 | } |
| 5394 | |
| 5395 | final int callerPid = Binder.getCallingPid(); |
| 5396 | final long origId = Binder.clearCallingIdentity(); |
| 5397 | IBinder token = null; |
| 5398 | |
| 5399 | try { |
| 5400 | synchronized (mWindowMap) { |
| 5401 | try { |
| 5402 | // !!! TODO: fail if the given window does not currently have touch focus? |
| 5403 | |
| 5404 | if (mDragState == null) { |
| 5405 | Surface surface = new Surface(session, callerPid, "drag surface", 0, |
| 5406 | width, height, PixelFormat.TRANSLUCENT, Surface.HIDDEN); |
| 5407 | outSurface.copyFrom(surface); |
| 5408 | token = new Binder(); |
| 5409 | mDragState = new DragState(token, surface, localOnly); |
| 5410 | mDragState.mSurface = surface; |
| 5411 | mDragState.mLocalOnly = localOnly; |
| 5412 | token = mDragState.mToken = new Binder(); |
| 5413 | |
| 5414 | // 5 second timeout for this window to actually begin the drag |
| 5415 | mH.removeMessages(H.DRAG_START_TIMEOUT, window); |
| 5416 | Message msg = mH.obtainMessage(H.DRAG_START_TIMEOUT, window.asBinder()); |
| 5417 | mH.sendMessageDelayed(msg, 5000); |
| 5418 | } else { |
| 5419 | Slog.w(TAG, "Drag already in progress"); |
| 5420 | } |
| 5421 | } catch (Surface.OutOfResourcesException e) { |
| 5422 | Slog.e(TAG, "Can't allocate drag surface w=" + width + " h=" + height, e); |
| 5423 | if (mDragState != null) { |
| 5424 | mDragState.reset(); |
| 5425 | mDragState = null; |
| 5426 | } |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5427 | } |
| 5428 | } |
| 5429 | } finally { |
| 5430 | Binder.restoreCallingIdentity(origId); |
| 5431 | } |
| 5432 | |
| 5433 | return token; |
| 5434 | } |
| 5435 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5436 | // ------------------------------------------------------------- |
| 5437 | // Input Events and Focus Management |
| 5438 | // ------------------------------------------------------------- |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5439 | |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5440 | InputMonitor mInputMonitor = new InputMonitor(); |
| 5441 | |
| 5442 | /* Tracks the progress of input dispatch and ensures that input dispatch state |
| 5443 | * is kept in sync with changes in window focus, visibility, registration, and |
| 5444 | * other relevant Window Manager state transitions. */ |
| 5445 | final class InputMonitor { |
| 5446 | // Current window with input focus for keys and other non-touch events. May be null. |
| 5447 | private WindowState mInputFocus; |
| 5448 | |
| 5449 | // When true, prevents input dispatch from proceeding until set to false again. |
| 5450 | private boolean mInputDispatchFrozen; |
| 5451 | |
| 5452 | // When true, input dispatch proceeds normally. Otherwise all events are dropped. |
| 5453 | private boolean mInputDispatchEnabled = true; |
| 5454 | |
| 5455 | // Temporary list of windows information to provide to the input dispatcher. |
| 5456 | private InputWindowList mTempInputWindows = new InputWindowList(); |
| 5457 | |
| 5458 | // Temporary input application object to provide to the input dispatcher. |
| 5459 | private InputApplication mTempInputApplication = new InputApplication(); |
| 5460 | |
| 5461 | /* Notifies the window manager about a broken input channel. |
| 5462 | * |
| 5463 | * Called by the InputManager. |
| 5464 | */ |
| 5465 | public void notifyInputChannelBroken(InputChannel inputChannel) { |
| 5466 | synchronized (mWindowMap) { |
| 5467 | WindowState windowState = getWindowStateForInputChannelLocked(inputChannel); |
| 5468 | if (windowState == null) { |
| 5469 | return; // irrelevant |
| 5470 | } |
| 5471 | |
| 5472 | Slog.i(TAG, "WINDOW DIED " + windowState); |
| 5473 | removeWindowLocked(windowState.mSession, windowState); |
| Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 5474 | } |
| 5475 | } |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5476 | |
| Jeff Brown | 519e024 | 2010-09-15 15:18:56 -0700 | [diff] [blame] | 5477 | /* Notifies the window manager about an application that is not responding. |
| Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 5478 | * 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] | 5479 | * |
| 5480 | * Called by the InputManager. |
| 5481 | */ |
| Jeff Brown | 519e024 | 2010-09-15 15:18:56 -0700 | [diff] [blame] | 5482 | public long notifyANR(Object token, InputChannel inputChannel) { |
| 5483 | AppWindowToken appWindowToken = null; |
| 5484 | if (inputChannel != null) { |
| 5485 | synchronized (mWindowMap) { |
| 5486 | WindowState windowState = getWindowStateForInputChannelLocked(inputChannel); |
| 5487 | if (windowState != null) { |
| 5488 | Slog.i(TAG, "Input event dispatching timed out sending to " |
| 5489 | + windowState.mAttrs.getTitle()); |
| 5490 | appWindowToken = windowState.mAppToken; |
| 5491 | } |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5492 | } |
| Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 5493 | } |
| 5494 | |
| Jeff Brown | 519e024 | 2010-09-15 15:18:56 -0700 | [diff] [blame] | 5495 | if (appWindowToken == null && token != null) { |
| 5496 | appWindowToken = (AppWindowToken) token; |
| 5497 | Slog.i(TAG, "Input event dispatching timed out sending to application " |
| 5498 | + appWindowToken.stringName); |
| 5499 | } |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5500 | |
| Jeff Brown | 519e024 | 2010-09-15 15:18:56 -0700 | [diff] [blame] | 5501 | if (appWindowToken != null && appWindowToken.appToken != null) { |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5502 | try { |
| 5503 | // Notify the activity manager about the timeout and let it decide whether |
| 5504 | // to abort dispatching or keep waiting. |
| Jeff Brown | 519e024 | 2010-09-15 15:18:56 -0700 | [diff] [blame] | 5505 | boolean abort = appWindowToken.appToken.keyDispatchingTimedOut(); |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5506 | if (! abort) { |
| 5507 | // The activity manager declined to abort dispatching. |
| 5508 | // Wait a bit longer and timeout again later. |
| Jeff Brown | 519e024 | 2010-09-15 15:18:56 -0700 | [diff] [blame] | 5509 | return appWindowToken.inputDispatchingTimeoutNanos; |
| Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 5510 | } |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5511 | } catch (RemoteException ex) { |
| Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 5512 | } |
| 5513 | } |
| Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 5514 | return 0; // abort dispatching |
| Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 5515 | } |
| 5516 | |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5517 | private WindowState getWindowStateForInputChannel(InputChannel inputChannel) { |
| 5518 | synchronized (mWindowMap) { |
| 5519 | return getWindowStateForInputChannelLocked(inputChannel); |
| 5520 | } |
| 5521 | } |
| 5522 | |
| 5523 | private WindowState getWindowStateForInputChannelLocked(InputChannel inputChannel) { |
| 5524 | int windowCount = mWindows.size(); |
| 5525 | for (int i = 0; i < windowCount; i++) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 5526 | WindowState windowState = mWindows.get(i); |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5527 | if (windowState.mInputChannel == inputChannel) { |
| 5528 | return windowState; |
| 5529 | } |
| Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 5530 | } |
| 5531 | |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5532 | return null; |
| Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 5533 | } |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5534 | |
| 5535 | private void addDragInputWindow(InputWindowList windowList) { |
| 5536 | final InputWindow inputWindow = windowList.add(); |
| 5537 | inputWindow.inputChannel = mDragState.mServerChannel; |
| 5538 | inputWindow.name = "drag"; |
| 5539 | inputWindow.layoutParamsFlags = 0; |
| 5540 | inputWindow.layoutParamsType = WindowManager.LayoutParams.TYPE_DRAG; |
| 5541 | inputWindow.dispatchingTimeoutNanos = DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS; |
| 5542 | inputWindow.visible = true; |
| 5543 | inputWindow.canReceiveKeys = false; |
| 5544 | inputWindow.hasFocus = true; |
| 5545 | inputWindow.hasWallpaper = false; |
| 5546 | inputWindow.paused = false; |
| 5547 | inputWindow.layer = mPolicy.windowTypeToLayerLw(inputWindow.layoutParamsType) |
| 5548 | * TYPE_LAYER_MULTIPLIER |
| 5549 | + TYPE_LAYER_OFFSET; |
| 5550 | inputWindow.ownerPid = Process.myPid(); |
| 5551 | inputWindow.ownerUid = Process.myUid(); |
| 5552 | |
| 5553 | // The drag window covers the entire display |
| 5554 | inputWindow.frameLeft = 0; |
| 5555 | inputWindow.frameTop = 0; |
| 5556 | inputWindow.frameRight = mDisplay.getWidth(); |
| 5557 | inputWindow.frameBottom = mDisplay.getHeight(); |
| Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 5558 | |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5559 | inputWindow.visibleFrameLeft = inputWindow.frameLeft; |
| 5560 | inputWindow.visibleFrameTop = inputWindow.frameTop; |
| 5561 | inputWindow.visibleFrameRight = inputWindow.frameRight; |
| 5562 | inputWindow.visibleFrameBottom = inputWindow.frameBottom; |
| 5563 | |
| 5564 | inputWindow.touchableAreaLeft = inputWindow.frameLeft; |
| 5565 | inputWindow.touchableAreaTop = inputWindow.frameTop; |
| 5566 | inputWindow.touchableAreaRight = inputWindow.frameRight; |
| 5567 | inputWindow.touchableAreaBottom = inputWindow.frameBottom; |
| 5568 | } |
| 5569 | |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5570 | /* Updates the cached window information provided to the input dispatcher. */ |
| 5571 | public void updateInputWindowsLw() { |
| 5572 | // Populate the input window list with information about all of the windows that |
| 5573 | // could potentially receive input. |
| 5574 | // As an optimization, we could try to prune the list of windows but this turns |
| 5575 | // out to be difficult because only the native code knows for sure which window |
| 5576 | // currently has touch focus. |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 5577 | final ArrayList<WindowState> windows = mWindows; |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5578 | |
| 5579 | // If there's a drag in flight, provide a pseudowindow to catch drag input |
| 5580 | final boolean inDrag = (mDragState != null); |
| 5581 | if (inDrag) { |
| 5582 | if (DEBUG_DRAG) { |
| 5583 | Log.d(TAG, "Inserting drag window"); |
| 5584 | } |
| 5585 | addDragInputWindow(mTempInputWindows); |
| 5586 | } |
| 5587 | |
| Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 5588 | final int N = windows.size(); |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5589 | for (int i = N - 1; i >= 0; i--) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 5590 | final WindowState child = windows.get(i); |
| Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 5591 | if (child.mInputChannel == null || child.mRemoved) { |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5592 | // Skip this window because it cannot possibly receive input. |
| Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 5593 | continue; |
| 5594 | } |
| 5595 | |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5596 | final int flags = child.mAttrs.flags; |
| 5597 | final int type = child.mAttrs.type; |
| 5598 | |
| 5599 | final boolean hasFocus = (child == mInputFocus); |
| 5600 | final boolean isVisible = child.isVisibleLw(); |
| 5601 | final boolean hasWallpaper = (child == mWallpaperTarget) |
| 5602 | && (type != WindowManager.LayoutParams.TYPE_KEYGUARD); |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5603 | |
| 5604 | // If there's a drag in progress and 'child' is a potential drop target, |
| 5605 | // make sure it's been told about the drag |
| 5606 | if (inDrag && isVisible) { |
| 5607 | mDragState.sendDragStartedIfNeededLw(child); |
| 5608 | } |
| 5609 | |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5610 | // Add a window to our list of input windows. |
| 5611 | final InputWindow inputWindow = mTempInputWindows.add(); |
| 5612 | inputWindow.inputChannel = child.mInputChannel; |
| Jeff Brown | 519e024 | 2010-09-15 15:18:56 -0700 | [diff] [blame] | 5613 | inputWindow.name = child.toString(); |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5614 | inputWindow.layoutParamsFlags = flags; |
| 5615 | inputWindow.layoutParamsType = type; |
| 5616 | inputWindow.dispatchingTimeoutNanos = child.getInputDispatchingTimeoutNanos(); |
| 5617 | inputWindow.visible = isVisible; |
| Jeff Brown | 519e024 | 2010-09-15 15:18:56 -0700 | [diff] [blame] | 5618 | inputWindow.canReceiveKeys = child.canReceiveKeys(); |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5619 | inputWindow.hasFocus = hasFocus; |
| 5620 | inputWindow.hasWallpaper = hasWallpaper; |
| 5621 | inputWindow.paused = child.mAppToken != null ? child.mAppToken.paused : false; |
| Jeff Brown | 519e024 | 2010-09-15 15:18:56 -0700 | [diff] [blame] | 5622 | inputWindow.layer = child.mLayer; |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5623 | inputWindow.ownerPid = child.mSession.mPid; |
| 5624 | inputWindow.ownerUid = child.mSession.mUid; |
| 5625 | |
| 5626 | final Rect frame = child.mFrame; |
| 5627 | inputWindow.frameLeft = frame.left; |
| 5628 | inputWindow.frameTop = frame.top; |
| Jeff Brown | 85a3176 | 2010-09-01 17:01:00 -0700 | [diff] [blame] | 5629 | inputWindow.frameRight = frame.right; |
| 5630 | inputWindow.frameBottom = frame.bottom; |
| 5631 | |
| 5632 | final Rect visibleFrame = child.mVisibleFrame; |
| 5633 | inputWindow.visibleFrameLeft = visibleFrame.left; |
| 5634 | inputWindow.visibleFrameTop = visibleFrame.top; |
| 5635 | inputWindow.visibleFrameRight = visibleFrame.right; |
| 5636 | inputWindow.visibleFrameBottom = visibleFrame.bottom; |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5637 | |
| 5638 | switch (child.mTouchableInsets) { |
| 5639 | default: |
| 5640 | case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME: |
| 5641 | inputWindow.touchableAreaLeft = frame.left; |
| 5642 | inputWindow.touchableAreaTop = frame.top; |
| 5643 | inputWindow.touchableAreaRight = frame.right; |
| 5644 | inputWindow.touchableAreaBottom = frame.bottom; |
| 5645 | break; |
| 5646 | |
| 5647 | case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_CONTENT: { |
| 5648 | Rect inset = child.mGivenContentInsets; |
| 5649 | inputWindow.touchableAreaLeft = frame.left + inset.left; |
| 5650 | inputWindow.touchableAreaTop = frame.top + inset.top; |
| 5651 | inputWindow.touchableAreaRight = frame.right - inset.right; |
| 5652 | inputWindow.touchableAreaBottom = frame.bottom - inset.bottom; |
| 5653 | break; |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5654 | } |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5655 | |
| 5656 | case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_VISIBLE: { |
| 5657 | Rect inset = child.mGivenVisibleInsets; |
| 5658 | inputWindow.touchableAreaLeft = frame.left + inset.left; |
| 5659 | inputWindow.touchableAreaTop = frame.top + inset.top; |
| 5660 | inputWindow.touchableAreaRight = frame.right - inset.right; |
| 5661 | inputWindow.touchableAreaBottom = frame.bottom - inset.bottom; |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5662 | break; |
| 5663 | } |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5664 | } |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5665 | } |
| Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 5666 | |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5667 | // Send windows to native code. |
| 5668 | mInputManager.setInputWindows(mTempInputWindows.toNullTerminatedArray()); |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5669 | |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5670 | // Clear the list in preparation for the next round. |
| 5671 | // Also avoids keeping InputChannel objects referenced unnecessarily. |
| 5672 | mTempInputWindows.clear(); |
| 5673 | } |
| 5674 | |
| Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 5675 | /* Notifies that the lid switch changed state. */ |
| 5676 | public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen) { |
| 5677 | mPolicy.notifyLidSwitchChanged(whenNanos, lidOpen); |
| 5678 | } |
| 5679 | |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5680 | /* Provides an opportunity for the window manager policy to intercept early key |
| 5681 | * processing as soon as the key has been read from the device. */ |
| Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 5682 | public int interceptKeyBeforeQueueing(long whenNanos, int keyCode, boolean down, |
| 5683 | int policyFlags, boolean isScreenOn) { |
| 5684 | return mPolicy.interceptKeyBeforeQueueing(whenNanos, |
| 5685 | keyCode, down, policyFlags, isScreenOn); |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5686 | } |
| 5687 | |
| 5688 | /* Provides an opportunity for the window manager policy to process a key before |
| 5689 | * ordinary dispatch. */ |
| Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 5690 | public boolean interceptKeyBeforeDispatching(InputChannel focus, |
| 5691 | int action, int flags, int keyCode, int metaState, int repeatCount, |
| 5692 | int policyFlags) { |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5693 | WindowState windowState = getWindowStateForInputChannel(focus); |
| Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 5694 | return mPolicy.interceptKeyBeforeDispatching(windowState, action, flags, |
| 5695 | keyCode, metaState, repeatCount, policyFlags); |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5696 | } |
| 5697 | |
| 5698 | /* Called when the current input focus changes. |
| 5699 | * Layer assignment is assumed to be complete by the time this is called. |
| 5700 | */ |
| 5701 | public void setInputFocusLw(WindowState newWindow) { |
| 5702 | if (DEBUG_INPUT) { |
| 5703 | Slog.d(TAG, "Input focus has changed to " + newWindow); |
| 5704 | } |
| 5705 | |
| 5706 | if (newWindow != mInputFocus) { |
| 5707 | if (newWindow != null && newWindow.canReceiveKeys()) { |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5708 | // Displaying a window implicitly causes dispatching to be unpaused. |
| 5709 | // This is to protect against bugs if someone pauses dispatching but |
| 5710 | // forgets to resume. |
| 5711 | newWindow.mToken.paused = false; |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5712 | } |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5713 | |
| 5714 | mInputFocus = newWindow; |
| 5715 | updateInputWindowsLw(); |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5716 | } |
| 5717 | } |
| 5718 | |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5719 | public void setFocusedAppLw(AppWindowToken newApp) { |
| 5720 | // Focused app has changed. |
| 5721 | if (newApp == null) { |
| 5722 | mInputManager.setFocusedApplication(null); |
| 5723 | } else { |
| 5724 | mTempInputApplication.name = newApp.toString(); |
| 5725 | mTempInputApplication.dispatchingTimeoutNanos = |
| 5726 | newApp.inputDispatchingTimeoutNanos; |
| 5727 | mTempInputApplication.token = newApp; |
| 5728 | |
| 5729 | mInputManager.setFocusedApplication(mTempInputApplication); |
| 5730 | } |
| 5731 | } |
| 5732 | |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5733 | public void pauseDispatchingLw(WindowToken window) { |
| 5734 | if (! window.paused) { |
| 5735 | if (DEBUG_INPUT) { |
| 5736 | Slog.v(TAG, "Pausing WindowToken " + window); |
| 5737 | } |
| 5738 | |
| 5739 | window.paused = true; |
| 5740 | updateInputWindowsLw(); |
| 5741 | } |
| 5742 | } |
| 5743 | |
| 5744 | public void resumeDispatchingLw(WindowToken window) { |
| 5745 | if (window.paused) { |
| 5746 | if (DEBUG_INPUT) { |
| 5747 | Slog.v(TAG, "Resuming WindowToken " + window); |
| 5748 | } |
| 5749 | |
| 5750 | window.paused = false; |
| 5751 | updateInputWindowsLw(); |
| 5752 | } |
| 5753 | } |
| 5754 | |
| 5755 | public void freezeInputDispatchingLw() { |
| 5756 | if (! mInputDispatchFrozen) { |
| 5757 | if (DEBUG_INPUT) { |
| 5758 | Slog.v(TAG, "Freezing input dispatching"); |
| 5759 | } |
| 5760 | |
| 5761 | mInputDispatchFrozen = true; |
| 5762 | updateInputDispatchModeLw(); |
| 5763 | } |
| 5764 | } |
| 5765 | |
| 5766 | public void thawInputDispatchingLw() { |
| 5767 | if (mInputDispatchFrozen) { |
| 5768 | if (DEBUG_INPUT) { |
| 5769 | Slog.v(TAG, "Thawing input dispatching"); |
| 5770 | } |
| 5771 | |
| 5772 | mInputDispatchFrozen = false; |
| 5773 | updateInputDispatchModeLw(); |
| 5774 | } |
| 5775 | } |
| 5776 | |
| 5777 | public void setEventDispatchingLw(boolean enabled) { |
| 5778 | if (mInputDispatchEnabled != enabled) { |
| 5779 | if (DEBUG_INPUT) { |
| 5780 | Slog.v(TAG, "Setting event dispatching to " + enabled); |
| 5781 | } |
| 5782 | |
| 5783 | mInputDispatchEnabled = enabled; |
| 5784 | updateInputDispatchModeLw(); |
| 5785 | } |
| 5786 | } |
| 5787 | |
| 5788 | private void updateInputDispatchModeLw() { |
| 5789 | mInputManager.setInputDispatchMode(mInputDispatchEnabled, mInputDispatchFrozen); |
| 5790 | } |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5791 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5792 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5793 | public void pauseKeyDispatching(IBinder _token) { |
| 5794 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 5795 | "pauseKeyDispatching()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5796 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5797 | } |
| 5798 | |
| 5799 | synchronized (mWindowMap) { |
| 5800 | WindowToken token = mTokenMap.get(_token); |
| 5801 | if (token != null) { |
| Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 5802 | mInputMonitor.pauseDispatchingLw(token); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5803 | } |
| 5804 | } |
| 5805 | } |
| 5806 | |
| 5807 | public void resumeKeyDispatching(IBinder _token) { |
| 5808 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 5809 | "resumeKeyDispatching()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5810 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5811 | } |
| 5812 | |
| 5813 | synchronized (mWindowMap) { |
| 5814 | WindowToken token = mTokenMap.get(_token); |
| 5815 | if (token != null) { |
| Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 5816 | mInputMonitor.resumeDispatchingLw(token); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5817 | } |
| 5818 | } |
| 5819 | } |
| 5820 | |
| 5821 | public void setEventDispatching(boolean enabled) { |
| 5822 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 5823 | "resumeKeyDispatching()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5824 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5825 | } |
| 5826 | |
| 5827 | synchronized (mWindowMap) { |
| Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 5828 | mInputMonitor.setEventDispatchingLw(enabled); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5829 | } |
| 5830 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5831 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5832 | /** |
| 5833 | * Injects a keystroke event into the UI. |
| Jeff Brown | bbda99d | 2010-07-28 15:48:59 -0700 | [diff] [blame] | 5834 | * Even when sync is false, this method may block while waiting for current |
| 5835 | * input events to be dispatched. |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5836 | * |
| 5837 | * @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] | 5838 | * {@link SystemClock#uptimeMillis()} as the timebase.) |
| 5839 | * @param sync If true, wait for the event to be completed before returning to the caller. |
| 5840 | * @return Returns true if event was dispatched, false if it was dropped for any reason |
| 5841 | */ |
| 5842 | public boolean injectKeyEvent(KeyEvent ev, boolean sync) { |
| 5843 | long downTime = ev.getDownTime(); |
| 5844 | long eventTime = ev.getEventTime(); |
| 5845 | |
| 5846 | int action = ev.getAction(); |
| 5847 | int code = ev.getKeyCode(); |
| 5848 | int repeatCount = ev.getRepeatCount(); |
| 5849 | int metaState = ev.getMetaState(); |
| 5850 | int deviceId = ev.getDeviceId(); |
| 5851 | int scancode = ev.getScanCode(); |
| Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 5852 | int source = ev.getSource(); |
| 5853 | |
| 5854 | if (source == InputDevice.SOURCE_UNKNOWN) { |
| 5855 | source = InputDevice.SOURCE_KEYBOARD; |
| 5856 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5857 | |
| 5858 | if (eventTime == 0) eventTime = SystemClock.uptimeMillis(); |
| 5859 | if (downTime == 0) downTime = eventTime; |
| 5860 | |
| 5861 | KeyEvent newEvent = new KeyEvent(downTime, eventTime, action, code, repeatCount, metaState, |
| Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 5862 | deviceId, scancode, KeyEvent.FLAG_FROM_SYSTEM, source); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5863 | |
| Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5864 | final int pid = Binder.getCallingPid(); |
| 5865 | final int uid = Binder.getCallingUid(); |
| 5866 | final long ident = Binder.clearCallingIdentity(); |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5867 | |
| Jeff Brown | bbda99d | 2010-07-28 15:48:59 -0700 | [diff] [blame] | 5868 | final int result = mInputManager.injectInputEvent(newEvent, pid, uid, |
| 5869 | sync ? InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH |
| 5870 | : InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT, |
| 5871 | INJECTION_TIMEOUT_MILLIS); |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5872 | |
| Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5873 | Binder.restoreCallingIdentity(ident); |
| Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 5874 | return reportInjectionResult(result); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5875 | } |
| 5876 | |
| 5877 | /** |
| 5878 | * Inject a pointer (touch) event into the UI. |
| Jeff Brown | bbda99d | 2010-07-28 15:48:59 -0700 | [diff] [blame] | 5879 | * Even when sync is false, this method may block while waiting for current |
| 5880 | * input events to be dispatched. |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5881 | * |
| 5882 | * @param ev A motion event describing the pointer (touch) action. (As noted in |
| 5883 | * {@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] | 5884 | * {@link SystemClock#uptimeMillis()} as the timebase.) |
| 5885 | * @param sync If true, wait for the event to be completed before returning to the caller. |
| 5886 | * @return Returns true if event was dispatched, false if it was dropped for any reason |
| 5887 | */ |
| 5888 | public boolean injectPointerEvent(MotionEvent ev, boolean sync) { |
| Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5889 | final int pid = Binder.getCallingPid(); |
| 5890 | final int uid = Binder.getCallingUid(); |
| 5891 | final long ident = Binder.clearCallingIdentity(); |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5892 | |
| Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 5893 | MotionEvent newEvent = MotionEvent.obtain(ev); |
| 5894 | if ((newEvent.getSource() & InputDevice.SOURCE_CLASS_POINTER) == 0) { |
| 5895 | newEvent.setSource(InputDevice.SOURCE_TOUCHSCREEN); |
| 5896 | } |
| 5897 | |
| Jeff Brown | bbda99d | 2010-07-28 15:48:59 -0700 | [diff] [blame] | 5898 | final int result = mInputManager.injectInputEvent(newEvent, pid, uid, |
| 5899 | sync ? InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH |
| 5900 | : InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT, |
| 5901 | INJECTION_TIMEOUT_MILLIS); |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5902 | |
| Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5903 | Binder.restoreCallingIdentity(ident); |
| Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 5904 | return reportInjectionResult(result); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5905 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5906 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5907 | /** |
| 5908 | * Inject a trackball (navigation device) event into the UI. |
| Jeff Brown | bbda99d | 2010-07-28 15:48:59 -0700 | [diff] [blame] | 5909 | * Even when sync is false, this method may block while waiting for current |
| 5910 | * input events to be dispatched. |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5911 | * |
| 5912 | * @param ev A motion event describing the trackball action. (As noted in |
| 5913 | * {@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] | 5914 | * {@link SystemClock#uptimeMillis()} as the timebase.) |
| 5915 | * @param sync If true, wait for the event to be completed before returning to the caller. |
| 5916 | * @return Returns true if event was dispatched, false if it was dropped for any reason |
| 5917 | */ |
| 5918 | public boolean injectTrackballEvent(MotionEvent ev, boolean sync) { |
| Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5919 | final int pid = Binder.getCallingPid(); |
| 5920 | final int uid = Binder.getCallingUid(); |
| 5921 | final long ident = Binder.clearCallingIdentity(); |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5922 | |
| Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 5923 | MotionEvent newEvent = MotionEvent.obtain(ev); |
| 5924 | if ((newEvent.getSource() & InputDevice.SOURCE_CLASS_TRACKBALL) == 0) { |
| 5925 | newEvent.setSource(InputDevice.SOURCE_TRACKBALL); |
| 5926 | } |
| 5927 | |
| Jeff Brown | bbda99d | 2010-07-28 15:48:59 -0700 | [diff] [blame] | 5928 | final int result = mInputManager.injectInputEvent(newEvent, pid, uid, |
| 5929 | sync ? InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH |
| 5930 | : InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT, |
| 5931 | INJECTION_TIMEOUT_MILLIS); |
| 5932 | |
| 5933 | Binder.restoreCallingIdentity(ident); |
| 5934 | return reportInjectionResult(result); |
| 5935 | } |
| 5936 | |
| 5937 | /** |
| 5938 | * Inject an input event into the UI without waiting for dispatch to commence. |
| 5939 | * This variant is useful for fire-and-forget input event injection. It does not |
| 5940 | * block any longer than it takes to enqueue the input event. |
| 5941 | * |
| 5942 | * @param ev An input event. (Be sure to set the input source correctly.) |
| 5943 | * @return Returns true if event was dispatched, false if it was dropped for any reason |
| 5944 | */ |
| 5945 | public boolean injectInputEventNoWait(InputEvent ev) { |
| 5946 | final int pid = Binder.getCallingPid(); |
| 5947 | final int uid = Binder.getCallingUid(); |
| 5948 | final long ident = Binder.clearCallingIdentity(); |
| 5949 | |
| 5950 | final int result = mInputManager.injectInputEvent(ev, pid, uid, |
| 5951 | InputManager.INPUT_EVENT_INJECTION_SYNC_NONE, |
| 5952 | INJECTION_TIMEOUT_MILLIS); |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5953 | |
| Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5954 | Binder.restoreCallingIdentity(ident); |
| Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 5955 | return reportInjectionResult(result); |
| 5956 | } |
| 5957 | |
| 5958 | private boolean reportInjectionResult(int result) { |
| Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 5959 | switch (result) { |
| 5960 | case InputManager.INPUT_EVENT_INJECTION_PERMISSION_DENIED: |
| 5961 | Slog.w(TAG, "Input event injection permission denied."); |
| 5962 | throw new SecurityException( |
| 5963 | "Injecting to another application requires INJECT_EVENTS permission"); |
| 5964 | case InputManager.INPUT_EVENT_INJECTION_SUCCEEDED: |
| Christopher Tate | 09e85dc | 2010-08-02 11:54:41 -0700 | [diff] [blame] | 5965 | //Slog.v(TAG, "Input event injection succeeded."); |
| Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 5966 | return true; |
| 5967 | case InputManager.INPUT_EVENT_INJECTION_TIMED_OUT: |
| 5968 | Slog.w(TAG, "Input event injection timed out."); |
| 5969 | return false; |
| 5970 | case InputManager.INPUT_EVENT_INJECTION_FAILED: |
| 5971 | default: |
| 5972 | Slog.w(TAG, "Input event injection failed."); |
| 5973 | return false; |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5974 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5975 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5976 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5977 | private WindowState getFocusedWindow() { |
| 5978 | synchronized (mWindowMap) { |
| 5979 | return getFocusedWindowLocked(); |
| 5980 | } |
| 5981 | } |
| 5982 | |
| 5983 | private WindowState getFocusedWindowLocked() { |
| 5984 | return mCurrentFocus; |
| 5985 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5986 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5987 | public boolean detectSafeMode() { |
| 5988 | mSafeMode = mPolicy.detectSafeMode(); |
| 5989 | return mSafeMode; |
| 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 void systemReady() { |
| Dianne Hackborn | 5132b37 | 2010-07-29 12:51:35 -0700 | [diff] [blame] | 5993 | synchronized(mWindowMap) { |
| 5994 | if (mDisplay != null) { |
| 5995 | throw new IllegalStateException("Display already initialized"); |
| 5996 | } |
| 5997 | WindowManager wm = (WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE); |
| 5998 | mDisplay = wm.getDefaultDisplay(); |
| 5999 | mInitialDisplayWidth = mDisplay.getWidth(); |
| 6000 | mInitialDisplayHeight = mDisplay.getHeight(); |
| 6001 | mInputManager.setDisplaySize(0, mInitialDisplayWidth, mInitialDisplayHeight); |
| 6002 | } |
| 6003 | |
| 6004 | try { |
| 6005 | mActivityManager.updateConfiguration(null); |
| 6006 | } catch (RemoteException e) { |
| 6007 | } |
| Dianne Hackborn | 154db5f | 2010-07-29 19:15:19 -0700 | [diff] [blame] | 6008 | |
| 6009 | mPolicy.systemReady(); |
| Dianne Hackborn | 5132b37 | 2010-07-29 12:51:35 -0700 | [diff] [blame] | 6010 | } |
| 6011 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6012 | // ------------------------------------------------------------- |
| 6013 | // Client Session State |
| 6014 | // ------------------------------------------------------------- |
| 6015 | |
| 6016 | private final class Session extends IWindowSession.Stub |
| 6017 | implements IBinder.DeathRecipient { |
| 6018 | final IInputMethodClient mClient; |
| 6019 | final IInputContext mInputContext; |
| 6020 | final int mUid; |
| 6021 | final int mPid; |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 6022 | final String mStringName; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6023 | SurfaceSession mSurfaceSession; |
| 6024 | int mNumWindow = 0; |
| 6025 | boolean mClientDead = false; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6026 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6027 | public Session(IInputMethodClient client, IInputContext inputContext) { |
| 6028 | mClient = client; |
| 6029 | mInputContext = inputContext; |
| 6030 | mUid = Binder.getCallingUid(); |
| 6031 | mPid = Binder.getCallingPid(); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 6032 | StringBuilder sb = new StringBuilder(); |
| 6033 | sb.append("Session{"); |
| 6034 | sb.append(Integer.toHexString(System.identityHashCode(this))); |
| 6035 | sb.append(" uid "); |
| 6036 | sb.append(mUid); |
| 6037 | sb.append("}"); |
| 6038 | mStringName = sb.toString(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6039 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6040 | synchronized (mWindowMap) { |
| 6041 | if (mInputMethodManager == null && mHaveInputMethods) { |
| 6042 | IBinder b = ServiceManager.getService( |
| 6043 | Context.INPUT_METHOD_SERVICE); |
| 6044 | mInputMethodManager = IInputMethodManager.Stub.asInterface(b); |
| 6045 | } |
| 6046 | } |
| 6047 | long ident = Binder.clearCallingIdentity(); |
| 6048 | try { |
| 6049 | // Note: it is safe to call in to the input method manager |
| 6050 | // here because we are not holding our lock. |
| 6051 | if (mInputMethodManager != null) { |
| 6052 | mInputMethodManager.addClient(client, inputContext, |
| 6053 | mUid, mPid); |
| 6054 | } else { |
| 6055 | client.setUsingInputMethod(false); |
| 6056 | } |
| 6057 | client.asBinder().linkToDeath(this, 0); |
| 6058 | } catch (RemoteException e) { |
| 6059 | // The caller has died, so we can just forget about this. |
| 6060 | try { |
| 6061 | if (mInputMethodManager != null) { |
| 6062 | mInputMethodManager.removeClient(client); |
| 6063 | } |
| 6064 | } catch (RemoteException ee) { |
| 6065 | } |
| 6066 | } finally { |
| 6067 | Binder.restoreCallingIdentity(ident); |
| 6068 | } |
| 6069 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6070 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6071 | @Override |
| 6072 | public boolean onTransact(int code, Parcel data, Parcel reply, int flags) |
| 6073 | throws RemoteException { |
| 6074 | try { |
| 6075 | return super.onTransact(code, data, reply, flags); |
| 6076 | } catch (RuntimeException e) { |
| 6077 | // Log all 'real' exceptions thrown to the caller |
| 6078 | if (!(e instanceof SecurityException)) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6079 | Slog.e(TAG, "Window Session Crash", e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6080 | } |
| 6081 | throw e; |
| 6082 | } |
| 6083 | } |
| 6084 | |
| 6085 | public void binderDied() { |
| 6086 | // Note: it is safe to call in to the input method manager |
| 6087 | // here because we are not holding our lock. |
| 6088 | try { |
| 6089 | if (mInputMethodManager != null) { |
| 6090 | mInputMethodManager.removeClient(mClient); |
| 6091 | } |
| 6092 | } catch (RemoteException e) { |
| 6093 | } |
| 6094 | synchronized(mWindowMap) { |
| Suchi Amalapurapu | fff2fda | 2009-06-30 21:36:16 -0700 | [diff] [blame] | 6095 | mClient.asBinder().unlinkToDeath(this, 0); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6096 | mClientDead = true; |
| 6097 | killSessionLocked(); |
| 6098 | } |
| 6099 | } |
| 6100 | |
| 6101 | public int add(IWindow window, WindowManager.LayoutParams attrs, |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 6102 | int viewVisibility, Rect outContentInsets, InputChannel outInputChannel) { |
| 6103 | return addWindow(this, window, attrs, viewVisibility, outContentInsets, |
| 6104 | outInputChannel); |
| 6105 | } |
| 6106 | |
| 6107 | public int addWithoutInputChannel(IWindow window, WindowManager.LayoutParams attrs, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6108 | int viewVisibility, Rect outContentInsets) { |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 6109 | return addWindow(this, window, attrs, viewVisibility, outContentInsets, null); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6110 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6111 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6112 | public void remove(IWindow window) { |
| 6113 | removeWindow(this, window); |
| 6114 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6115 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6116 | public int relayout(IWindow window, WindowManager.LayoutParams attrs, |
| 6117 | int requestedWidth, int requestedHeight, int viewFlags, |
| 6118 | boolean insetsPending, Rect outFrame, Rect outContentInsets, |
| Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 6119 | Rect outVisibleInsets, Configuration outConfig, Surface outSurface) { |
| Dianne Hackborn | f123e49 | 2010-09-24 11:16:23 -0700 | [diff] [blame] | 6120 | //Log.d(TAG, ">>>>>> ENTERED relayout from " + Binder.getCallingPid()); |
| 6121 | int res = relayoutWindow(this, window, attrs, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6122 | requestedWidth, requestedHeight, viewFlags, insetsPending, |
| Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 6123 | outFrame, outContentInsets, outVisibleInsets, outConfig, outSurface); |
| Dianne Hackborn | f123e49 | 2010-09-24 11:16:23 -0700 | [diff] [blame] | 6124 | //Log.d(TAG, "<<<<<< EXITING relayout to " + Binder.getCallingPid()); |
| 6125 | return res; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6126 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6127 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6128 | public void setTransparentRegion(IWindow window, Region region) { |
| 6129 | setTransparentRegionWindow(this, window, region); |
| 6130 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6131 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6132 | public void setInsets(IWindow window, int touchableInsets, |
| 6133 | Rect contentInsets, Rect visibleInsets) { |
| 6134 | setInsetsWindow(this, window, touchableInsets, contentInsets, |
| 6135 | visibleInsets); |
| 6136 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6137 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6138 | public void getDisplayFrame(IWindow window, Rect outDisplayFrame) { |
| 6139 | getWindowDisplayFrame(this, window, outDisplayFrame); |
| 6140 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6141 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6142 | public void finishDrawing(IWindow window) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6143 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6144 | TAG, "IWindow finishDrawing called for " + window); |
| 6145 | finishDrawingWindow(this, window); |
| 6146 | } |
| 6147 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6148 | public void setInTouchMode(boolean mode) { |
| 6149 | synchronized(mWindowMap) { |
| 6150 | mInTouchMode = mode; |
| 6151 | } |
| 6152 | } |
| 6153 | |
| 6154 | public boolean getInTouchMode() { |
| 6155 | synchronized(mWindowMap) { |
| 6156 | return mInTouchMode; |
| 6157 | } |
| 6158 | } |
| 6159 | |
| 6160 | public boolean performHapticFeedback(IWindow window, int effectId, |
| 6161 | boolean always) { |
| 6162 | synchronized(mWindowMap) { |
| 6163 | long ident = Binder.clearCallingIdentity(); |
| 6164 | try { |
| The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 6165 | return mPolicy.performHapticFeedbackLw( |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 6166 | windowForClientLocked(this, window, true), |
| 6167 | effectId, always); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6168 | } finally { |
| 6169 | Binder.restoreCallingIdentity(ident); |
| 6170 | } |
| 6171 | } |
| 6172 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6173 | |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 6174 | /* Drag/drop */ |
| 6175 | public IBinder prepareDrag(IWindow window, boolean localOnly, |
| 6176 | int width, int height, Surface outSurface) { |
| 6177 | return prepareDragSurface(window, mSurfaceSession, localOnly, |
| 6178 | width, height, outSurface); |
| 6179 | } |
| 6180 | |
| 6181 | public boolean performDrag(IWindow window, IBinder dragToken, |
| 6182 | float touchX, float touchY, float thumbCenterX, float thumbCenterY, |
| 6183 | ClipData data) { |
| 6184 | if (DEBUG_DRAG) { |
| 6185 | Slog.d(TAG, "perform drag: win=" + window + " data=" + data); |
| 6186 | } |
| 6187 | |
| 6188 | synchronized (mWindowMap) { |
| 6189 | if (mDragState == null) { |
| 6190 | Slog.w(TAG, "No drag prepared"); |
| 6191 | throw new IllegalStateException("performDrag() without prepareDrag()"); |
| 6192 | } |
| 6193 | |
| 6194 | if (dragToken != mDragState.mToken) { |
| 6195 | Slog.w(TAG, "Performing mismatched drag"); |
| 6196 | throw new IllegalStateException("performDrag() does not match prepareDrag()"); |
| 6197 | } |
| 6198 | |
| 6199 | WindowState callingWin = windowForClientLocked(null, window, false); |
| 6200 | if (callingWin == null) { |
| 6201 | Slog.w(TAG, "Bad requesting window " + window); |
| 6202 | return false; // !!! TODO: throw here? |
| 6203 | } |
| 6204 | |
| 6205 | // !!! TODO: if input is not still focused on the initiating window, fail |
| 6206 | // the drag initiation (e.g. an alarm window popped up just as the application |
| 6207 | // called performDrag() |
| 6208 | |
| 6209 | mH.removeMessages(H.DRAG_START_TIMEOUT, window.asBinder()); |
| 6210 | |
| Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 6211 | // !!! TODO: extract the current touch (x, y) in screen coordinates. That |
| 6212 | // will let us eliminate the (touchX,touchY) parameters from the API. |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 6213 | |
| 6214 | mDragState.register(); |
| 6215 | mInputMonitor.updateInputWindowsLw(); |
| 6216 | mInputManager.transferTouchFocus(callingWin.mInputChannel, |
| 6217 | mDragState.mServerChannel); |
| 6218 | |
| 6219 | mDragState.mData = data; |
| 6220 | mDragState.broadcastDragStartedLw(); |
| 6221 | |
| 6222 | // remember the thumb offsets for later |
| 6223 | mDragState.mThumbOffsetX = thumbCenterX; |
| 6224 | mDragState.mThumbOffsetY = thumbCenterY; |
| 6225 | |
| 6226 | // Make the surface visible at the proper location |
| 6227 | final Surface surface = mDragState.mSurface; |
| 6228 | surface.openTransaction(); |
| 6229 | try { |
| 6230 | surface.setPosition((int)(touchX - thumbCenterX), |
| 6231 | (int)(touchY - thumbCenterY)); |
| 6232 | surface.setAlpha(.5f); |
| 6233 | surface.show(); |
| 6234 | } finally { |
| 6235 | surface.closeTransaction(); |
| 6236 | } |
| 6237 | } |
| 6238 | |
| 6239 | return true; // success! |
| 6240 | } |
| 6241 | |
| 6242 | public void dragRecipientEntered(IWindow window) { |
| 6243 | if (DEBUG_DRAG) { |
| 6244 | Slog.d(TAG, "Drag into new candidate view @ " + window); |
| 6245 | } |
| 6246 | } |
| 6247 | |
| 6248 | public void dragRecipientExited(IWindow window) { |
| 6249 | if (DEBUG_DRAG) { |
| 6250 | Slog.d(TAG, "Drag from old candidate view @ " + window); |
| 6251 | } |
| 6252 | } |
| 6253 | |
| Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 6254 | 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] | 6255 | synchronized(mWindowMap) { |
| 6256 | long ident = Binder.clearCallingIdentity(); |
| 6257 | try { |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 6258 | setWindowWallpaperPositionLocked( |
| 6259 | windowForClientLocked(this, window, true), |
| Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 6260 | x, y, xStep, yStep); |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 6261 | } finally { |
| 6262 | Binder.restoreCallingIdentity(ident); |
| 6263 | } |
| 6264 | } |
| 6265 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6266 | |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 6267 | public void wallpaperOffsetsComplete(IBinder window) { |
| 6268 | WindowManagerService.this.wallpaperOffsetsComplete(window); |
| 6269 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6270 | |
| Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 6271 | public Bundle sendWallpaperCommand(IBinder window, String action, int x, int y, |
| 6272 | int z, Bundle extras, boolean sync) { |
| 6273 | synchronized(mWindowMap) { |
| 6274 | long ident = Binder.clearCallingIdentity(); |
| 6275 | try { |
| 6276 | return sendWindowWallpaperCommandLocked( |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 6277 | windowForClientLocked(this, window, true), |
| Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 6278 | action, x, y, z, extras, sync); |
| 6279 | } finally { |
| 6280 | Binder.restoreCallingIdentity(ident); |
| 6281 | } |
| 6282 | } |
| 6283 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6284 | |
| Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 6285 | public void wallpaperCommandComplete(IBinder window, Bundle result) { |
| 6286 | WindowManagerService.this.wallpaperCommandComplete(window, result); |
| 6287 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6288 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6289 | void windowAddedLocked() { |
| 6290 | if (mSurfaceSession == null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6291 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6292 | TAG, "First window added to " + this + ", creating SurfaceSession"); |
| 6293 | mSurfaceSession = new SurfaceSession(); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6294 | if (SHOW_TRANSACTIONS) Slog.i( |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 6295 | TAG, " NEW SURFACE SESSION " + mSurfaceSession); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6296 | mSessions.add(this); |
| 6297 | } |
| 6298 | mNumWindow++; |
| 6299 | } |
| 6300 | |
| 6301 | void windowRemovedLocked() { |
| 6302 | mNumWindow--; |
| 6303 | killSessionLocked(); |
| 6304 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6305 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6306 | void killSessionLocked() { |
| 6307 | if (mNumWindow <= 0 && mClientDead) { |
| 6308 | mSessions.remove(this); |
| 6309 | if (mSurfaceSession != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6310 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6311 | TAG, "Last window removed from " + this |
| 6312 | + ", destroying " + mSurfaceSession); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6313 | if (SHOW_TRANSACTIONS) Slog.i( |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 6314 | TAG, " KILL SURFACE SESSION " + mSurfaceSession); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6315 | try { |
| 6316 | mSurfaceSession.kill(); |
| 6317 | } catch (Exception e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6318 | Slog.w(TAG, "Exception thrown when killing surface session " |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6319 | + mSurfaceSession + " in session " + this |
| 6320 | + ": " + e.toString()); |
| 6321 | } |
| 6322 | mSurfaceSession = null; |
| 6323 | } |
| 6324 | } |
| 6325 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6326 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6327 | void dump(PrintWriter pw, String prefix) { |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 6328 | pw.print(prefix); pw.print("mNumWindow="); pw.print(mNumWindow); |
| 6329 | pw.print(" mClientDead="); pw.print(mClientDead); |
| 6330 | pw.print(" mSurfaceSession="); pw.println(mSurfaceSession); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6331 | } |
| 6332 | |
| 6333 | @Override |
| 6334 | public String toString() { |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 6335 | return mStringName; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6336 | } |
| 6337 | } |
| 6338 | |
| 6339 | // ------------------------------------------------------------- |
| 6340 | // Client Window State |
| 6341 | // ------------------------------------------------------------- |
| 6342 | |
| 6343 | private final class WindowState implements WindowManagerPolicy.WindowState { |
| 6344 | final Session mSession; |
| 6345 | final IWindow mClient; |
| 6346 | WindowToken mToken; |
| The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 6347 | WindowToken mRootToken; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6348 | AppWindowToken mAppToken; |
| 6349 | AppWindowToken mTargetAppToken; |
| 6350 | final WindowManager.LayoutParams mAttrs = new WindowManager.LayoutParams(); |
| 6351 | final DeathRecipient mDeathRecipient; |
| 6352 | final WindowState mAttachedWindow; |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 6353 | final ArrayList<WindowState> mChildWindows = new ArrayList<WindowState>(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6354 | final int mBaseLayer; |
| 6355 | final int mSubLayer; |
| 6356 | final boolean mLayoutAttached; |
| 6357 | final boolean mIsImWindow; |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 6358 | final boolean mIsWallpaper; |
| 6359 | final boolean mIsFloatingLayer; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6360 | int mViewVisibility; |
| 6361 | boolean mPolicyVisibility = true; |
| 6362 | boolean mPolicyVisibilityAfterAnim = true; |
| 6363 | boolean mAppFreezing; |
| 6364 | Surface mSurface; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 6365 | boolean mReportDestroySurface; |
| 6366 | boolean mSurfacePendingDestroy; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6367 | boolean mAttachedHidden; // is our parent window hidden? |
| 6368 | boolean mLastHidden; // was this window last hidden? |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 6369 | boolean mWallpaperVisible; // for wallpaper, what was last vis report? |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6370 | int mRequestedWidth; |
| 6371 | int mRequestedHeight; |
| 6372 | int mLastRequestedWidth; |
| 6373 | int mLastRequestedHeight; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6374 | int mLayer; |
| 6375 | int mAnimLayer; |
| 6376 | int mLastLayer; |
| 6377 | boolean mHaveFrame; |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 6378 | boolean mObscured; |
| Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 6379 | boolean mTurnOnScreen; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6380 | |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 6381 | int mLayoutSeq = -1; |
| 6382 | |
| 6383 | Configuration mConfiguration = null; |
| 6384 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6385 | // Actual frame shown on-screen (may be modified by animation) |
| 6386 | final Rect mShownFrame = new Rect(); |
| 6387 | final Rect mLastShownFrame = new Rect(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6388 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6389 | /** |
| Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 6390 | * Set when we have changed the size of the surface, to know that |
| 6391 | * we must tell them application to resize (and thus redraw itself). |
| 6392 | */ |
| 6393 | boolean mSurfaceResized; |
| 6394 | |
| 6395 | /** |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6396 | * Insets that determine the actually visible area |
| 6397 | */ |
| 6398 | final Rect mVisibleInsets = new Rect(); |
| 6399 | final Rect mLastVisibleInsets = new Rect(); |
| 6400 | boolean mVisibleInsetsChanged; |
| 6401 | |
| 6402 | /** |
| 6403 | * Insets that are covered by system windows |
| 6404 | */ |
| 6405 | final Rect mContentInsets = new Rect(); |
| 6406 | final Rect mLastContentInsets = new Rect(); |
| 6407 | boolean mContentInsetsChanged; |
| 6408 | |
| 6409 | /** |
| 6410 | * Set to true if we are waiting for this window to receive its |
| 6411 | * given internal insets before laying out other windows based on it. |
| 6412 | */ |
| 6413 | boolean mGivenInsetsPending; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6414 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6415 | /** |
| 6416 | * These are the content insets that were given during layout for |
| 6417 | * this window, to be applied to windows behind it. |
| 6418 | */ |
| 6419 | final Rect mGivenContentInsets = new Rect(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6420 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6421 | /** |
| 6422 | * These are the visible insets that were given during layout for |
| 6423 | * this window, to be applied to windows behind it. |
| 6424 | */ |
| 6425 | final Rect mGivenVisibleInsets = new Rect(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6426 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6427 | /** |
| 6428 | * Flag indicating whether the touchable region should be adjusted by |
| 6429 | * the visible insets; if false the area outside the visible insets is |
| 6430 | * NOT touchable, so we must use those to adjust the frame during hit |
| 6431 | * tests. |
| 6432 | */ |
| 6433 | int mTouchableInsets = ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6434 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6435 | // Current transformation being applied. |
| 6436 | float mDsDx=1, mDtDx=0, mDsDy=0, mDtDy=1; |
| 6437 | float mLastDsDx=1, mLastDtDx=0, mLastDsDy=0, mLastDtDy=1; |
| 6438 | float mHScale=1, mVScale=1; |
| 6439 | float mLastHScale=1, mLastVScale=1; |
| 6440 | final Matrix mTmpMatrix = new Matrix(); |
| 6441 | |
| 6442 | // "Real" frame that the application sees. |
| 6443 | final Rect mFrame = new Rect(); |
| 6444 | final Rect mLastFrame = new Rect(); |
| 6445 | |
| 6446 | final Rect mContainingFrame = new Rect(); |
| 6447 | final Rect mDisplayFrame = new Rect(); |
| 6448 | final Rect mContentFrame = new Rect(); |
| 6449 | final Rect mVisibleFrame = new Rect(); |
| 6450 | |
| 6451 | float mShownAlpha = 1; |
| 6452 | float mAlpha = 1; |
| 6453 | float mLastAlpha = 1; |
| 6454 | |
| 6455 | // Set to true if, when the window gets displayed, it should perform |
| 6456 | // an enter animation. |
| 6457 | boolean mEnterAnimationPending; |
| 6458 | |
| 6459 | // Currently running animation. |
| 6460 | boolean mAnimating; |
| 6461 | boolean mLocalAnimating; |
| 6462 | Animation mAnimation; |
| 6463 | boolean mAnimationIsEntrance; |
| 6464 | boolean mHasTransformation; |
| 6465 | boolean mHasLocalTransformation; |
| 6466 | final Transformation mTransformation = new Transformation(); |
| 6467 | |
| Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 6468 | // If a window showing a wallpaper: the requested offset for the |
| 6469 | // wallpaper; if a wallpaper window: the currently applied offset. |
| 6470 | float mWallpaperX = -1; |
| 6471 | float mWallpaperY = -1; |
| Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 6472 | |
| 6473 | // If a window showing a wallpaper: what fraction of the offset |
| 6474 | // range corresponds to a full virtual screen. |
| 6475 | float mWallpaperXStep = -1; |
| 6476 | float mWallpaperYStep = -1; |
| 6477 | |
| Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 6478 | // Wallpaper windows: pixels offset based on above variables. |
| 6479 | int mXOffset; |
| 6480 | int mYOffset; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6481 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6482 | // This is set after IWindowSession.relayout() has been called at |
| 6483 | // least once for the window. It allows us to detect the situation |
| 6484 | // where we don't yet have a surface, but should have one soon, so |
| 6485 | // we can give the window focus before waiting for the relayout. |
| 6486 | boolean mRelayoutCalled; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6487 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6488 | // This is set after the Surface has been created but before the |
| 6489 | // window has been drawn. During this time the surface is hidden. |
| 6490 | boolean mDrawPending; |
| 6491 | |
| 6492 | // This is set after the window has finished drawing for the first |
| 6493 | // time but before its surface is shown. The surface will be |
| 6494 | // displayed when the next layout is run. |
| 6495 | boolean mCommitDrawPending; |
| 6496 | |
| 6497 | // This is set during the time after the window's drawing has been |
| 6498 | // committed, and before its surface is actually shown. It is used |
| 6499 | // to delay showing the surface until all windows in a token are ready |
| 6500 | // to be shown. |
| 6501 | boolean mReadyToShow; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6502 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6503 | // Set when the window has been shown in the screen the first time. |
| 6504 | boolean mHasDrawn; |
| 6505 | |
| 6506 | // Currently running an exit animation? |
| 6507 | boolean mExiting; |
| 6508 | |
| 6509 | // Currently on the mDestroySurface list? |
| 6510 | boolean mDestroying; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6511 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6512 | // Completely remove from window manager after exit animation? |
| 6513 | boolean mRemoveOnExit; |
| 6514 | |
| 6515 | // Set when the orientation is changing and this window has not yet |
| 6516 | // been updated for the new orientation. |
| 6517 | boolean mOrientationChanging; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6518 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6519 | // Is this window now (or just being) removed? |
| 6520 | boolean mRemoved; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6521 | |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 6522 | // For debugging, this is the last information given to the surface flinger. |
| 6523 | boolean mSurfaceShown; |
| 6524 | int mSurfaceX, mSurfaceY, mSurfaceW, mSurfaceH; |
| 6525 | int mSurfaceLayer; |
| 6526 | float mSurfaceAlpha; |
| 6527 | |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 6528 | // Input channel |
| 6529 | InputChannel mInputChannel; |
| 6530 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6531 | WindowState(Session s, IWindow c, WindowToken token, |
| 6532 | WindowState attachedWindow, WindowManager.LayoutParams a, |
| 6533 | int viewVisibility) { |
| 6534 | mSession = s; |
| 6535 | mClient = c; |
| 6536 | mToken = token; |
| 6537 | mAttrs.copyFrom(a); |
| 6538 | mViewVisibility = viewVisibility; |
| 6539 | DeathRecipient deathRecipient = new DeathRecipient(); |
| 6540 | mAlpha = a.alpha; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6541 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6542 | TAG, "Window " + this + " client=" + c.asBinder() |
| 6543 | + " token=" + token + " (" + mAttrs.token + ")"); |
| 6544 | try { |
| 6545 | c.asBinder().linkToDeath(deathRecipient, 0); |
| 6546 | } catch (RemoteException e) { |
| 6547 | mDeathRecipient = null; |
| 6548 | mAttachedWindow = null; |
| 6549 | mLayoutAttached = false; |
| 6550 | mIsImWindow = false; |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 6551 | mIsWallpaper = false; |
| 6552 | mIsFloatingLayer = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6553 | mBaseLayer = 0; |
| 6554 | mSubLayer = 0; |
| 6555 | return; |
| 6556 | } |
| 6557 | mDeathRecipient = deathRecipient; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6558 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6559 | if ((mAttrs.type >= FIRST_SUB_WINDOW && |
| 6560 | mAttrs.type <= LAST_SUB_WINDOW)) { |
| 6561 | // The multiplier here is to reserve space for multiple |
| 6562 | // windows in the same type layer. |
| 6563 | mBaseLayer = mPolicy.windowTypeToLayerLw( |
| 6564 | attachedWindow.mAttrs.type) * TYPE_LAYER_MULTIPLIER |
| 6565 | + TYPE_LAYER_OFFSET; |
| 6566 | mSubLayer = mPolicy.subWindowTypeToLayerLw(a.type); |
| 6567 | mAttachedWindow = attachedWindow; |
| 6568 | mAttachedWindow.mChildWindows.add(this); |
| 6569 | mLayoutAttached = mAttrs.type != |
| 6570 | WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG; |
| 6571 | mIsImWindow = attachedWindow.mAttrs.type == TYPE_INPUT_METHOD |
| 6572 | || attachedWindow.mAttrs.type == TYPE_INPUT_METHOD_DIALOG; |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 6573 | mIsWallpaper = attachedWindow.mAttrs.type == TYPE_WALLPAPER; |
| 6574 | mIsFloatingLayer = mIsImWindow || mIsWallpaper; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6575 | } else { |
| 6576 | // The multiplier here is to reserve space for multiple |
| 6577 | // windows in the same type layer. |
| 6578 | mBaseLayer = mPolicy.windowTypeToLayerLw(a.type) |
| 6579 | * TYPE_LAYER_MULTIPLIER |
| 6580 | + TYPE_LAYER_OFFSET; |
| 6581 | mSubLayer = 0; |
| 6582 | mAttachedWindow = null; |
| 6583 | mLayoutAttached = false; |
| 6584 | mIsImWindow = mAttrs.type == TYPE_INPUT_METHOD |
| 6585 | || mAttrs.type == TYPE_INPUT_METHOD_DIALOG; |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 6586 | mIsWallpaper = mAttrs.type == TYPE_WALLPAPER; |
| 6587 | mIsFloatingLayer = mIsImWindow || mIsWallpaper; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6588 | } |
| 6589 | |
| 6590 | WindowState appWin = this; |
| 6591 | while (appWin.mAttachedWindow != null) { |
| 6592 | appWin = mAttachedWindow; |
| 6593 | } |
| 6594 | WindowToken appToken = appWin.mToken; |
| 6595 | while (appToken.appWindowToken == null) { |
| 6596 | WindowToken parent = mTokenMap.get(appToken.token); |
| 6597 | if (parent == null || appToken == parent) { |
| 6598 | break; |
| 6599 | } |
| 6600 | appToken = parent; |
| 6601 | } |
| The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 6602 | mRootToken = appToken; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6603 | mAppToken = appToken.appWindowToken; |
| 6604 | |
| 6605 | mSurface = null; |
| 6606 | mRequestedWidth = 0; |
| 6607 | mRequestedHeight = 0; |
| 6608 | mLastRequestedWidth = 0; |
| 6609 | mLastRequestedHeight = 0; |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 6610 | mXOffset = 0; |
| 6611 | mYOffset = 0; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6612 | mLayer = 0; |
| 6613 | mAnimLayer = 0; |
| 6614 | mLastLayer = 0; |
| 6615 | } |
| 6616 | |
| 6617 | void attach() { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6618 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6619 | TAG, "Attaching " + this + " token=" + mToken |
| 6620 | + ", list=" + mToken.windows); |
| 6621 | mSession.windowAddedLocked(); |
| 6622 | } |
| 6623 | |
| 6624 | public void computeFrameLw(Rect pf, Rect df, Rect cf, Rect vf) { |
| 6625 | mHaveFrame = true; |
| 6626 | |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 6627 | final Rect container = mContainingFrame; |
| 6628 | container.set(pf); |
| 6629 | |
| 6630 | final Rect display = mDisplayFrame; |
| 6631 | display.set(df); |
| 6632 | |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 6633 | if ((mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0) { |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 6634 | container.intersect(mCompatibleScreenFrame); |
| Mitsuru Oshima | d2967e2 | 2009-07-20 14:01:43 -0700 | [diff] [blame] | 6635 | if ((mAttrs.flags & FLAG_LAYOUT_NO_LIMITS) == 0) { |
| 6636 | display.intersect(mCompatibleScreenFrame); |
| 6637 | } |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 6638 | } |
| 6639 | |
| 6640 | final int pw = container.right - container.left; |
| 6641 | final int ph = container.bottom - container.top; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6642 | |
| 6643 | int w,h; |
| 6644 | if ((mAttrs.flags & mAttrs.FLAG_SCALED) != 0) { |
| 6645 | w = mAttrs.width < 0 ? pw : mAttrs.width; |
| 6646 | h = mAttrs.height< 0 ? ph : mAttrs.height; |
| 6647 | } else { |
| Romain Guy | 980a938 | 2010-01-08 15:06:28 -0800 | [diff] [blame] | 6648 | w = mAttrs.width == mAttrs.MATCH_PARENT ? pw : mRequestedWidth; |
| 6649 | h = mAttrs.height== mAttrs.MATCH_PARENT ? ph : mRequestedHeight; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6650 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6651 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6652 | final Rect content = mContentFrame; |
| 6653 | content.set(cf); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6654 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6655 | final Rect visible = mVisibleFrame; |
| 6656 | visible.set(vf); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6657 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6658 | final Rect frame = mFrame; |
| Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 6659 | final int fw = frame.width(); |
| 6660 | final int fh = frame.height(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6661 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6662 | //System.out.println("In: w=" + w + " h=" + h + " container=" + |
| 6663 | // container + " x=" + mAttrs.x + " y=" + mAttrs.y); |
| 6664 | |
| 6665 | Gravity.apply(mAttrs.gravity, w, h, container, |
| 6666 | (int) (mAttrs.x + mAttrs.horizontalMargin * pw), |
| 6667 | (int) (mAttrs.y + mAttrs.verticalMargin * ph), frame); |
| 6668 | |
| 6669 | //System.out.println("Out: " + mFrame); |
| 6670 | |
| 6671 | // Now make sure the window fits in the overall display. |
| 6672 | Gravity.applyDisplay(mAttrs.gravity, df, frame); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6673 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6674 | // Make sure the content and visible frames are inside of the |
| 6675 | // final window frame. |
| 6676 | if (content.left < frame.left) content.left = frame.left; |
| 6677 | if (content.top < frame.top) content.top = frame.top; |
| 6678 | if (content.right > frame.right) content.right = frame.right; |
| 6679 | if (content.bottom > frame.bottom) content.bottom = frame.bottom; |
| 6680 | if (visible.left < frame.left) visible.left = frame.left; |
| 6681 | if (visible.top < frame.top) visible.top = frame.top; |
| 6682 | if (visible.right > frame.right) visible.right = frame.right; |
| 6683 | if (visible.bottom > frame.bottom) visible.bottom = frame.bottom; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6684 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6685 | final Rect contentInsets = mContentInsets; |
| 6686 | contentInsets.left = content.left-frame.left; |
| 6687 | contentInsets.top = content.top-frame.top; |
| 6688 | contentInsets.right = frame.right-content.right; |
| 6689 | contentInsets.bottom = frame.bottom-content.bottom; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6690 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6691 | final Rect visibleInsets = mVisibleInsets; |
| 6692 | visibleInsets.left = visible.left-frame.left; |
| 6693 | visibleInsets.top = visible.top-frame.top; |
| 6694 | visibleInsets.right = frame.right-visible.right; |
| 6695 | visibleInsets.bottom = frame.bottom-visible.bottom; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6696 | |
| Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 6697 | if (mIsWallpaper && (fw != frame.width() || fh != frame.height())) { |
| 6698 | updateWallpaperOffsetLocked(this, mDisplay.getWidth(), |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 6699 | mDisplay.getHeight(), false); |
| Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 6700 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6701 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6702 | if (localLOGV) { |
| 6703 | //if ("com.google.android.youtube".equals(mAttrs.packageName) |
| 6704 | // && mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_PANEL) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6705 | Slog.v(TAG, "Resolving (mRequestedWidth=" |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6706 | + mRequestedWidth + ", mRequestedheight=" |
| 6707 | + mRequestedHeight + ") to" + " (pw=" + pw + ", ph=" + ph |
| 6708 | + "): frame=" + mFrame.toShortString() |
| 6709 | + " ci=" + contentInsets.toShortString() |
| 6710 | + " vi=" + visibleInsets.toShortString()); |
| 6711 | //} |
| 6712 | } |
| 6713 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6714 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6715 | public Rect getFrameLw() { |
| 6716 | return mFrame; |
| 6717 | } |
| 6718 | |
| 6719 | public Rect getShownFrameLw() { |
| 6720 | return mShownFrame; |
| 6721 | } |
| 6722 | |
| 6723 | public Rect getDisplayFrameLw() { |
| 6724 | return mDisplayFrame; |
| 6725 | } |
| 6726 | |
| 6727 | public Rect getContentFrameLw() { |
| 6728 | return mContentFrame; |
| 6729 | } |
| 6730 | |
| 6731 | public Rect getVisibleFrameLw() { |
| 6732 | return mVisibleFrame; |
| 6733 | } |
| 6734 | |
| 6735 | public boolean getGivenInsetsPendingLw() { |
| 6736 | return mGivenInsetsPending; |
| 6737 | } |
| 6738 | |
| 6739 | public Rect getGivenContentInsetsLw() { |
| 6740 | return mGivenContentInsets; |
| 6741 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6742 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6743 | public Rect getGivenVisibleInsetsLw() { |
| 6744 | return mGivenVisibleInsets; |
| 6745 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6746 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6747 | public WindowManager.LayoutParams getAttrs() { |
| 6748 | return mAttrs; |
| 6749 | } |
| 6750 | |
| 6751 | public int getSurfaceLayer() { |
| 6752 | return mLayer; |
| 6753 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6754 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6755 | public IApplicationToken getAppToken() { |
| 6756 | return mAppToken != null ? mAppToken.appToken : null; |
| 6757 | } |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 6758 | |
| 6759 | public long getInputDispatchingTimeoutNanos() { |
| 6760 | return mAppToken != null |
| 6761 | ? mAppToken.inputDispatchingTimeoutNanos |
| 6762 | : DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS; |
| 6763 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6764 | |
| 6765 | public boolean hasAppShownWindows() { |
| 6766 | return mAppToken != null ? mAppToken.firstWindowDrawn : false; |
| 6767 | } |
| 6768 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6769 | public void setAnimation(Animation anim) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6770 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6771 | TAG, "Setting animation in " + this + ": " + anim); |
| 6772 | mAnimating = false; |
| 6773 | mLocalAnimating = false; |
| 6774 | mAnimation = anim; |
| 6775 | mAnimation.restrictDuration(MAX_ANIMATION_DURATION); |
| 6776 | mAnimation.scaleCurrentDuration(mWindowAnimationScale); |
| 6777 | } |
| 6778 | |
| 6779 | public void clearAnimation() { |
| 6780 | if (mAnimation != null) { |
| 6781 | mAnimating = true; |
| 6782 | mLocalAnimating = false; |
| 6783 | mAnimation = null; |
| 6784 | } |
| 6785 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6786 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6787 | Surface createSurfaceLocked() { |
| 6788 | if (mSurface == null) { |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 6789 | mReportDestroySurface = false; |
| 6790 | mSurfacePendingDestroy = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6791 | mDrawPending = true; |
| 6792 | mCommitDrawPending = false; |
| 6793 | mReadyToShow = false; |
| 6794 | if (mAppToken != null) { |
| 6795 | mAppToken.allDrawn = false; |
| 6796 | } |
| 6797 | |
| 6798 | int flags = 0; |
| Mathias Agopian | 317a628 | 2009-08-13 17:29:02 -0700 | [diff] [blame] | 6799 | if (mAttrs.memoryType == MEMORY_TYPE_PUSH_BUFFERS) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6800 | flags |= Surface.PUSH_BUFFERS; |
| 6801 | } |
| 6802 | |
| 6803 | if ((mAttrs.flags&WindowManager.LayoutParams.FLAG_SECURE) != 0) { |
| 6804 | flags |= Surface.SECURE; |
| 6805 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6806 | if (DEBUG_VISIBILITY) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6807 | TAG, "Creating surface in session " |
| 6808 | + mSession.mSurfaceSession + " window " + this |
| 6809 | + " w=" + mFrame.width() |
| 6810 | + " h=" + mFrame.height() + " format=" |
| 6811 | + mAttrs.format + " flags=" + flags); |
| 6812 | |
| 6813 | int w = mFrame.width(); |
| 6814 | int h = mFrame.height(); |
| 6815 | if ((mAttrs.flags & LayoutParams.FLAG_SCALED) != 0) { |
| 6816 | // for a scaled surface, we always want the requested |
| 6817 | // size. |
| 6818 | w = mRequestedWidth; |
| 6819 | h = mRequestedHeight; |
| 6820 | } |
| 6821 | |
| Romain Guy | 9825ec6 | 2009-10-01 00:58:09 -0700 | [diff] [blame] | 6822 | // Something is wrong and SurfaceFlinger will not like this, |
| 6823 | // try to revert to sane values |
| 6824 | if (w <= 0) w = 1; |
| 6825 | if (h <= 0) h = 1; |
| 6826 | |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 6827 | mSurfaceShown = false; |
| 6828 | mSurfaceLayer = 0; |
| 6829 | mSurfaceAlpha = 1; |
| 6830 | mSurfaceX = 0; |
| 6831 | mSurfaceY = 0; |
| 6832 | mSurfaceW = w; |
| 6833 | mSurfaceH = h; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6834 | try { |
| 6835 | mSurface = new Surface( |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6836 | mSession.mSurfaceSession, mSession.mPid, |
| Mathias Agopian | 5d26c1e | 2010-03-01 16:09:43 -0800 | [diff] [blame] | 6837 | mAttrs.getTitle().toString(), |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6838 | 0, w, h, mAttrs.format, flags); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6839 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " CREATE SURFACE " |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 6840 | + mSurface + " IN SESSION " |
| 6841 | + mSession.mSurfaceSession |
| 6842 | + ": pid=" + mSession.mPid + " format=" |
| 6843 | + mAttrs.format + " flags=0x" |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 6844 | + Integer.toHexString(flags) |
| 6845 | + " / " + this); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6846 | } catch (Surface.OutOfResourcesException e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6847 | Slog.w(TAG, "OutOfResourcesException creating surface"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6848 | reclaimSomeSurfaceMemoryLocked(this, "create"); |
| 6849 | return null; |
| 6850 | } catch (Exception e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6851 | Slog.e(TAG, "Exception creating surface", e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6852 | return null; |
| 6853 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6854 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6855 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6856 | TAG, "Got surface: " + mSurface |
| 6857 | + ", set left=" + mFrame.left + " top=" + mFrame.top |
| 6858 | + ", animLayer=" + mAnimLayer); |
| 6859 | if (SHOW_TRANSACTIONS) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6860 | Slog.i(TAG, ">>> OPEN TRANSACTION"); |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 6861 | if (SHOW_TRANSACTIONS) logSurface(this, |
| 6862 | "CREATE pos=(" + mFrame.left + "," + mFrame.top + ") (" + |
| 6863 | mFrame.width() + "x" + mFrame.height() + "), layer=" + |
| 6864 | mAnimLayer + " HIDE", null); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6865 | } |
| 6866 | Surface.openTransaction(); |
| 6867 | try { |
| 6868 | try { |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 6869 | mSurfaceX = mFrame.left + mXOffset; |
| Dianne Hackborn | 529bef6 | 2010-03-25 11:48:43 -0700 | [diff] [blame] | 6870 | mSurfaceY = mFrame.top + mYOffset; |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 6871 | mSurface.setPosition(mSurfaceX, mSurfaceY); |
| 6872 | mSurfaceLayer = mAnimLayer; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6873 | mSurface.setLayer(mAnimLayer); |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 6874 | mSurfaceShown = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6875 | mSurface.hide(); |
| 6876 | if ((mAttrs.flags&WindowManager.LayoutParams.FLAG_DITHER) != 0) { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 6877 | if (SHOW_TRANSACTIONS) logSurface(this, "DITHER", null); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6878 | mSurface.setFlags(Surface.SURFACE_DITHER, |
| 6879 | Surface.SURFACE_DITHER); |
| 6880 | } |
| 6881 | } catch (RuntimeException e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6882 | Slog.w(TAG, "Error creating surface in " + w, e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6883 | reclaimSomeSurfaceMemoryLocked(this, "create-init"); |
| 6884 | } |
| 6885 | mLastHidden = true; |
| 6886 | } finally { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6887 | if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6888 | Surface.closeTransaction(); |
| 6889 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6890 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6891 | TAG, "Created surface " + this); |
| 6892 | } |
| 6893 | return mSurface; |
| 6894 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6895 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6896 | void destroySurfaceLocked() { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6897 | if (mAppToken != null && this == mAppToken.startingWindow) { |
| 6898 | mAppToken.startingDisplayed = false; |
| 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 | if (mSurface != null) { |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 6902 | mDrawPending = false; |
| 6903 | mCommitDrawPending = false; |
| 6904 | mReadyToShow = false; |
| 6905 | |
| 6906 | int i = mChildWindows.size(); |
| 6907 | while (i > 0) { |
| 6908 | i--; |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 6909 | WindowState c = mChildWindows.get(i); |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 6910 | c.mAttachedHidden = true; |
| 6911 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6912 | |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 6913 | if (mReportDestroySurface) { |
| 6914 | mReportDestroySurface = false; |
| 6915 | mSurfacePendingDestroy = true; |
| 6916 | try { |
| 6917 | mClient.dispatchGetNewSurface(); |
| 6918 | // We'll really destroy on the next time around. |
| 6919 | return; |
| 6920 | } catch (RemoteException e) { |
| 6921 | } |
| 6922 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6923 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6924 | try { |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 6925 | if (DEBUG_VISIBILITY) { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 6926 | RuntimeException e = null; |
| 6927 | if (!HIDE_STACK_CRAWLS) { |
| 6928 | e = new RuntimeException(); |
| 6929 | e.fillInStackTrace(); |
| 6930 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6931 | Slog.w(TAG, "Window " + this + " destroying surface " |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 6932 | + mSurface + ", session " + mSession, e); |
| 6933 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6934 | if (SHOW_TRANSACTIONS) { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 6935 | RuntimeException e = null; |
| 6936 | if (!HIDE_STACK_CRAWLS) { |
| 6937 | e = new RuntimeException(); |
| 6938 | e.fillInStackTrace(); |
| 6939 | } |
| 6940 | if (SHOW_TRANSACTIONS) logSurface(this, "DESTROY", e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6941 | } |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 6942 | mSurface.destroy(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6943 | } catch (RuntimeException e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6944 | Slog.w(TAG, "Exception thrown when destroying Window " + this |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6945 | + " surface " + mSurface + " session " + mSession |
| 6946 | + ": " + e.toString()); |
| 6947 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6948 | |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 6949 | mSurfaceShown = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6950 | mSurface = null; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6951 | } |
| 6952 | } |
| 6953 | |
| 6954 | boolean finishDrawingLocked() { |
| 6955 | if (mDrawPending) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6956 | if (SHOW_TRANSACTIONS || DEBUG_ORIENTATION) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6957 | TAG, "finishDrawingLocked: " + mSurface); |
| 6958 | mCommitDrawPending = true; |
| 6959 | mDrawPending = false; |
| 6960 | return true; |
| 6961 | } |
| 6962 | return false; |
| 6963 | } |
| 6964 | |
| 6965 | // This must be called while inside a transaction. |
| Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 6966 | boolean commitFinishDrawingLocked(long currentTime) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6967 | //Slog.i(TAG, "commitFinishDrawingLocked: " + mSurface); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6968 | if (!mCommitDrawPending) { |
| Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 6969 | return false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6970 | } |
| 6971 | mCommitDrawPending = false; |
| 6972 | mReadyToShow = true; |
| 6973 | final boolean starting = mAttrs.type == TYPE_APPLICATION_STARTING; |
| 6974 | final AppWindowToken atoken = mAppToken; |
| 6975 | if (atoken == null || atoken.allDrawn || starting) { |
| 6976 | performShowLocked(); |
| 6977 | } |
| Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 6978 | return true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6979 | } |
| 6980 | |
| 6981 | // This must be called while inside a transaction. |
| 6982 | boolean performShowLocked() { |
| 6983 | if (DEBUG_VISIBILITY) { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 6984 | RuntimeException e = null; |
| 6985 | if (!HIDE_STACK_CRAWLS) { |
| 6986 | e = new RuntimeException(); |
| 6987 | e.fillInStackTrace(); |
| 6988 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6989 | Slog.v(TAG, "performShow on " + this |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6990 | + ": readyToShow=" + mReadyToShow + " readyForDisplay=" + isReadyForDisplay() |
| 6991 | + " starting=" + (mAttrs.type == TYPE_APPLICATION_STARTING), e); |
| 6992 | } |
| 6993 | if (mReadyToShow && isReadyForDisplay()) { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 6994 | if (SHOW_TRANSACTIONS || DEBUG_ORIENTATION) logSurface(this, |
| 6995 | "SHOW (performShowLocked)", null); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6996 | if (DEBUG_VISIBILITY) Slog.v(TAG, "Showing " + this |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6997 | + " during animation: policyVis=" + mPolicyVisibility |
| 6998 | + " attHidden=" + mAttachedHidden |
| 6999 | + " tok.hiddenRequested=" |
| 7000 | + (mAppToken != null ? mAppToken.hiddenRequested : false) |
| Dianne Hackborn | 248b188 | 2009-09-16 16:46:44 -0700 | [diff] [blame] | 7001 | + " tok.hidden=" |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7002 | + (mAppToken != null ? mAppToken.hidden : false) |
| 7003 | + " animating=" + mAnimating |
| 7004 | + " tok animating=" |
| 7005 | + (mAppToken != null ? mAppToken.animating : false)); |
| 7006 | if (!showSurfaceRobustlyLocked(this)) { |
| 7007 | return false; |
| 7008 | } |
| 7009 | mLastAlpha = -1; |
| 7010 | mHasDrawn = true; |
| 7011 | mLastHidden = false; |
| 7012 | mReadyToShow = false; |
| 7013 | enableScreenIfNeededLocked(); |
| 7014 | |
| 7015 | applyEnterAnimationLocked(this); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7016 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7017 | int i = mChildWindows.size(); |
| 7018 | while (i > 0) { |
| 7019 | i--; |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 7020 | WindowState c = mChildWindows.get(i); |
| Dianne Hackborn | f09c1a2 | 2010-04-22 15:59:21 -0700 | [diff] [blame] | 7021 | if (c.mAttachedHidden) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7022 | c.mAttachedHidden = false; |
| Dianne Hackborn | f09c1a2 | 2010-04-22 15:59:21 -0700 | [diff] [blame] | 7023 | if (c.mSurface != null) { |
| 7024 | c.performShowLocked(); |
| 7025 | // It hadn't been shown, which means layout not |
| 7026 | // performed on it, so now we want to make sure to |
| 7027 | // do a layout. If called from within the transaction |
| 7028 | // loop, this will cause it to restart with a new |
| 7029 | // layout. |
| 7030 | mLayoutNeeded = true; |
| 7031 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7032 | } |
| 7033 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7034 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7035 | if (mAttrs.type != TYPE_APPLICATION_STARTING |
| 7036 | && mAppToken != null) { |
| 7037 | mAppToken.firstWindowDrawn = true; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7038 | |
| Dianne Hackborn | 248b188 | 2009-09-16 16:46:44 -0700 | [diff] [blame] | 7039 | if (mAppToken.startingData != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7040 | if (DEBUG_STARTING_WINDOW || DEBUG_ANIM) Slog.v(TAG, |
| Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 7041 | "Finish starting " + mToken |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7042 | + ": first real window is shown, no animation"); |
| Dianne Hackborn | 248b188 | 2009-09-16 16:46:44 -0700 | [diff] [blame] | 7043 | // If this initial window is animating, stop it -- we |
| 7044 | // will do an animation to reveal it from behind the |
| 7045 | // starting window, so there is no need for it to also |
| 7046 | // be doing its own stuff. |
| 7047 | if (mAnimation != null) { |
| 7048 | mAnimation = null; |
| 7049 | // Make sure we clean up the animation. |
| 7050 | mAnimating = true; |
| 7051 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7052 | mFinishedStarting.add(mAppToken); |
| 7053 | mH.sendEmptyMessage(H.FINISHED_STARTING); |
| 7054 | } |
| 7055 | mAppToken.updateReportedVisibilityLocked(); |
| 7056 | } |
| 7057 | } |
| 7058 | return true; |
| 7059 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7060 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7061 | // This must be called while inside a transaction. Returns true if |
| 7062 | // there is more animation to run. |
| 7063 | boolean stepAnimationLocked(long currentTime, int dw, int dh) { |
| Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 7064 | if (!mDisplayFrozen && mPolicy.isScreenOn()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7065 | // We will run animations as long as the display isn't frozen. |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7066 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7067 | if (!mDrawPending && !mCommitDrawPending && mAnimation != null) { |
| 7068 | mHasTransformation = true; |
| 7069 | mHasLocalTransformation = true; |
| 7070 | if (!mLocalAnimating) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7071 | if (DEBUG_ANIM) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7072 | TAG, "Starting animation in " + this + |
| 7073 | " @ " + currentTime + ": ww=" + mFrame.width() + " wh=" + mFrame.height() + |
| 7074 | " dw=" + dw + " dh=" + dh + " scale=" + mWindowAnimationScale); |
| 7075 | mAnimation.initialize(mFrame.width(), mFrame.height(), dw, dh); |
| 7076 | mAnimation.setStartTime(currentTime); |
| 7077 | mLocalAnimating = true; |
| 7078 | mAnimating = true; |
| 7079 | } |
| 7080 | mTransformation.clear(); |
| 7081 | final boolean more = mAnimation.getTransformation( |
| 7082 | currentTime, mTransformation); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7083 | if (DEBUG_ANIM) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7084 | TAG, "Stepped animation in " + this + |
| 7085 | ": more=" + more + ", xform=" + mTransformation); |
| 7086 | if (more) { |
| 7087 | // we're not done! |
| 7088 | return true; |
| 7089 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7090 | if (DEBUG_ANIM) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7091 | TAG, "Finished animation in " + this + |
| 7092 | " @ " + currentTime); |
| 7093 | mAnimation = null; |
| 7094 | //WindowManagerService.this.dump(); |
| 7095 | } |
| 7096 | mHasLocalTransformation = false; |
| 7097 | if ((!mLocalAnimating || mAnimationIsEntrance) && mAppToken != null |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 7098 | && mAppToken.animation != null) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7099 | // When our app token is animating, we kind-of pretend like |
| 7100 | // we are as well. Note the mLocalAnimating mAnimationIsEntrance |
| 7101 | // part of this check means that we will only do this if |
| 7102 | // our window is not currently exiting, or it is not |
| 7103 | // locally animating itself. The idea being that one that |
| 7104 | // is exiting and doing a local animation should be removed |
| 7105 | // once that animation is done. |
| 7106 | mAnimating = true; |
| 7107 | mHasTransformation = true; |
| 7108 | mTransformation.clear(); |
| 7109 | return false; |
| 7110 | } else if (mHasTransformation) { |
| 7111 | // Little trick to get through the path below to act like |
| 7112 | // we have finished an animation. |
| 7113 | mAnimating = true; |
| 7114 | } else if (isAnimating()) { |
| 7115 | mAnimating = true; |
| 7116 | } |
| 7117 | } else if (mAnimation != null) { |
| 7118 | // If the display is frozen, and there is a pending animation, |
| 7119 | // clear it and make sure we run the cleanup code. |
| 7120 | mAnimating = true; |
| 7121 | mLocalAnimating = true; |
| 7122 | mAnimation = null; |
| 7123 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7124 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7125 | if (!mAnimating && !mLocalAnimating) { |
| 7126 | return false; |
| 7127 | } |
| 7128 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7129 | if (DEBUG_ANIM) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7130 | TAG, "Animation done in " + this + ": exiting=" + mExiting |
| 7131 | + ", reportedVisible=" |
| 7132 | + (mAppToken != null ? mAppToken.reportedVisible : false)); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7133 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7134 | mAnimating = false; |
| 7135 | mLocalAnimating = false; |
| 7136 | mAnimation = null; |
| 7137 | mAnimLayer = mLayer; |
| 7138 | if (mIsImWindow) { |
| 7139 | mAnimLayer += mInputMethodAnimLayerAdjustment; |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 7140 | } else if (mIsWallpaper) { |
| 7141 | mAnimLayer += mWallpaperAnimLayerAdjustment; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7142 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7143 | if (DEBUG_LAYERS) Slog.v(TAG, "Stepping win " + this |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7144 | + " anim layer: " + mAnimLayer); |
| 7145 | mHasTransformation = false; |
| 7146 | mHasLocalTransformation = false; |
| Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 7147 | if (mPolicyVisibility != mPolicyVisibilityAfterAnim) { |
| 7148 | if (DEBUG_VISIBILITY) { |
| 7149 | Slog.v(TAG, "Policy visibility changing after anim in " + this + ": " |
| 7150 | + mPolicyVisibilityAfterAnim); |
| 7151 | } |
| 7152 | mPolicyVisibility = mPolicyVisibilityAfterAnim; |
| 7153 | if (!mPolicyVisibility) { |
| 7154 | if (mCurrentFocus == this) { |
| 7155 | mFocusMayChange = true; |
| 7156 | } |
| 7157 | // Window is no longer visible -- make sure if we were waiting |
| 7158 | // for it to be displayed before enabling the display, that |
| 7159 | // we allow the display to be enabled now. |
| 7160 | enableScreenIfNeededLocked(); |
| 7161 | } |
| Dianne Hackborn | f3bea9c | 2009-12-09 18:26:21 -0800 | [diff] [blame] | 7162 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7163 | mTransformation.clear(); |
| 7164 | if (mHasDrawn |
| 7165 | && mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING |
| 7166 | && mAppToken != null |
| 7167 | && mAppToken.firstWindowDrawn |
| 7168 | && mAppToken.startingData != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7169 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Finish starting " |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7170 | + mToken + ": first real window done animating"); |
| 7171 | mFinishedStarting.add(mAppToken); |
| 7172 | mH.sendEmptyMessage(H.FINISHED_STARTING); |
| 7173 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7174 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7175 | finishExit(); |
| 7176 | |
| 7177 | if (mAppToken != null) { |
| 7178 | mAppToken.updateReportedVisibilityLocked(); |
| 7179 | } |
| 7180 | |
| 7181 | return false; |
| 7182 | } |
| 7183 | |
| 7184 | void finishExit() { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7185 | if (DEBUG_ANIM) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7186 | TAG, "finishExit in " + this |
| 7187 | + ": exiting=" + mExiting |
| 7188 | + " remove=" + mRemoveOnExit |
| 7189 | + " windowAnimating=" + isWindowAnimating()); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7190 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7191 | final int N = mChildWindows.size(); |
| 7192 | for (int i=0; i<N; i++) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 7193 | mChildWindows.get(i).finishExit(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7194 | } |
| 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 | if (!mExiting) { |
| 7197 | return; |
| 7198 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7199 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7200 | if (isWindowAnimating()) { |
| 7201 | return; |
| 7202 | } |
| 7203 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7204 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7205 | TAG, "Exit animation finished in " + this |
| 7206 | + ": remove=" + mRemoveOnExit); |
| 7207 | if (mSurface != null) { |
| 7208 | mDestroySurface.add(this); |
| 7209 | mDestroying = true; |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 7210 | if (SHOW_TRANSACTIONS) logSurface(this, "HIDE (finishExit)", null); |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 7211 | mSurfaceShown = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7212 | try { |
| 7213 | mSurface.hide(); |
| 7214 | } catch (RuntimeException e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7215 | Slog.w(TAG, "Error hiding surface in " + this, e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7216 | } |
| 7217 | mLastHidden = true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7218 | } |
| 7219 | mExiting = false; |
| 7220 | if (mRemoveOnExit) { |
| 7221 | mPendingRemove.add(this); |
| 7222 | mRemoveOnExit = false; |
| 7223 | } |
| 7224 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7225 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7226 | boolean isIdentityMatrix(float dsdx, float dtdx, float dsdy, float dtdy) { |
| 7227 | if (dsdx < .99999f || dsdx > 1.00001f) return false; |
| 7228 | if (dtdy < .99999f || dtdy > 1.00001f) return false; |
| 7229 | if (dtdx < -.000001f || dtdx > .000001f) return false; |
| 7230 | if (dsdy < -.000001f || dsdy > .000001f) return false; |
| 7231 | return true; |
| 7232 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7233 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7234 | void computeShownFrameLocked() { |
| 7235 | final boolean selfTransformation = mHasLocalTransformation; |
| 7236 | Transformation attachedTransformation = |
| 7237 | (mAttachedWindow != null && mAttachedWindow.mHasLocalTransformation) |
| 7238 | ? mAttachedWindow.mTransformation : null; |
| 7239 | Transformation appTransformation = |
| 7240 | (mAppToken != null && mAppToken.hasTransformation) |
| 7241 | ? mAppToken.transformation : null; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7242 | |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 7243 | // Wallpapers are animated based on the "real" window they |
| 7244 | // are currently targeting. |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 7245 | if (mAttrs.type == TYPE_WALLPAPER && mLowerWallpaperTarget == null |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 7246 | && mWallpaperTarget != null) { |
| Dianne Hackborn | 5baba16 | 2009-09-23 17:01:12 -0700 | [diff] [blame] | 7247 | if (mWallpaperTarget.mHasLocalTransformation && |
| 7248 | mWallpaperTarget.mAnimation != null && |
| 7249 | !mWallpaperTarget.mAnimation.getDetachWallpaper()) { |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 7250 | attachedTransformation = mWallpaperTarget.mTransformation; |
| Dianne Hackborn | 5baba16 | 2009-09-23 17:01:12 -0700 | [diff] [blame] | 7251 | if (DEBUG_WALLPAPER && attachedTransformation != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7252 | Slog.v(TAG, "WP target attached xform: " + attachedTransformation); |
| Dianne Hackborn | 5baba16 | 2009-09-23 17:01:12 -0700 | [diff] [blame] | 7253 | } |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 7254 | } |
| 7255 | if (mWallpaperTarget.mAppToken != null && |
| Dianne Hackborn | 5baba16 | 2009-09-23 17:01:12 -0700 | [diff] [blame] | 7256 | mWallpaperTarget.mAppToken.hasTransformation && |
| 7257 | mWallpaperTarget.mAppToken.animation != null && |
| 7258 | !mWallpaperTarget.mAppToken.animation.getDetachWallpaper()) { |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 7259 | appTransformation = mWallpaperTarget.mAppToken.transformation; |
| Dianne Hackborn | 5baba16 | 2009-09-23 17:01:12 -0700 | [diff] [blame] | 7260 | if (DEBUG_WALLPAPER && appTransformation != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7261 | Slog.v(TAG, "WP target app xform: " + appTransformation); |
| Dianne Hackborn | 5baba16 | 2009-09-23 17:01:12 -0700 | [diff] [blame] | 7262 | } |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 7263 | } |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 7264 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7265 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7266 | if (selfTransformation || attachedTransformation != null |
| 7267 | || appTransformation != null) { |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7268 | // cache often used attributes locally |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7269 | final Rect frame = mFrame; |
| 7270 | final float tmpFloats[] = mTmpFloats; |
| 7271 | final Matrix tmpMatrix = mTmpMatrix; |
| 7272 | |
| 7273 | // Compute the desired transformation. |
| Dianne Hackborn | 65c2387 | 2009-09-18 17:47:02 -0700 | [diff] [blame] | 7274 | tmpMatrix.setTranslate(0, 0); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7275 | if (selfTransformation) { |
| Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 7276 | tmpMatrix.postConcat(mTransformation.getMatrix()); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7277 | } |
| Dianne Hackborn | 65c2387 | 2009-09-18 17:47:02 -0700 | [diff] [blame] | 7278 | tmpMatrix.postTranslate(frame.left, frame.top); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7279 | if (attachedTransformation != null) { |
| Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 7280 | tmpMatrix.postConcat(attachedTransformation.getMatrix()); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7281 | } |
| 7282 | if (appTransformation != null) { |
| Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 7283 | tmpMatrix.postConcat(appTransformation.getMatrix()); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7284 | } |
| 7285 | |
| 7286 | // "convert" it into SurfaceFlinger's format |
| 7287 | // (a 2x2 matrix + an offset) |
| 7288 | // Here we must not transform the position of the surface |
| 7289 | // since it is already included in the transformation. |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7290 | //Slog.i(TAG, "Transform: " + matrix); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7291 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7292 | tmpMatrix.getValues(tmpFloats); |
| 7293 | mDsDx = tmpFloats[Matrix.MSCALE_X]; |
| 7294 | mDtDx = tmpFloats[Matrix.MSKEW_X]; |
| 7295 | mDsDy = tmpFloats[Matrix.MSKEW_Y]; |
| 7296 | mDtDy = tmpFloats[Matrix.MSCALE_Y]; |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 7297 | int x = (int)tmpFloats[Matrix.MTRANS_X] + mXOffset; |
| 7298 | int y = (int)tmpFloats[Matrix.MTRANS_Y] + mYOffset; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7299 | int w = frame.width(); |
| 7300 | int h = frame.height(); |
| 7301 | mShownFrame.set(x, y, x+w, y+h); |
| 7302 | |
| 7303 | // Now set the alpha... but because our current hardware |
| 7304 | // can't do alpha transformation on a non-opaque surface, |
| 7305 | // turn it off if we are running an animation that is also |
| 7306 | // transforming since it is more important to have that |
| 7307 | // animation be smooth. |
| 7308 | mShownAlpha = mAlpha; |
| 7309 | if (!mLimitedAlphaCompositing |
| 7310 | || (!PixelFormat.formatHasAlpha(mAttrs.format) |
| 7311 | || (isIdentityMatrix(mDsDx, mDtDx, mDsDy, mDtDy) |
| 7312 | && x == frame.left && y == frame.top))) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7313 | //Slog.i(TAG, "Applying alpha transform"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7314 | if (selfTransformation) { |
| 7315 | mShownAlpha *= mTransformation.getAlpha(); |
| 7316 | } |
| 7317 | if (attachedTransformation != null) { |
| 7318 | mShownAlpha *= attachedTransformation.getAlpha(); |
| 7319 | } |
| 7320 | if (appTransformation != null) { |
| 7321 | mShownAlpha *= appTransformation.getAlpha(); |
| 7322 | } |
| 7323 | } else { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7324 | //Slog.i(TAG, "Not applying alpha transform"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7325 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7326 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7327 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7328 | TAG, "Continuing animation in " + this + |
| 7329 | ": " + mShownFrame + |
| 7330 | ", alpha=" + mTransformation.getAlpha()); |
| 7331 | return; |
| 7332 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7333 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7334 | mShownFrame.set(mFrame); |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 7335 | if (mXOffset != 0 || mYOffset != 0) { |
| 7336 | mShownFrame.offset(mXOffset, mYOffset); |
| 7337 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7338 | mShownAlpha = mAlpha; |
| 7339 | mDsDx = 1; |
| 7340 | mDtDx = 0; |
| 7341 | mDsDy = 0; |
| 7342 | mDtDy = 1; |
| 7343 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7344 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7345 | /** |
| 7346 | * Is this window visible? It is not visible if there is no |
| 7347 | * surface, or we are in the process of running an exit animation |
| 7348 | * that will remove the surface, or its app token has been hidden. |
| 7349 | */ |
| 7350 | public boolean isVisibleLw() { |
| 7351 | final AppWindowToken atoken = mAppToken; |
| 7352 | return mSurface != null && mPolicyVisibility && !mAttachedHidden |
| 7353 | && (atoken == null || !atoken.hiddenRequested) |
| 7354 | && !mExiting && !mDestroying; |
| 7355 | } |
| 7356 | |
| 7357 | /** |
| Dianne Hackborn | 3d163f07 | 2009-10-07 21:26:57 -0700 | [diff] [blame] | 7358 | * Like {@link #isVisibleLw}, but also counts a window that is currently |
| 7359 | * "hidden" behind the keyguard as visible. This allows us to apply |
| 7360 | * things like window flags that impact the keyguard. |
| 7361 | * XXX I am starting to think we need to have ANOTHER visibility flag |
| 7362 | * for this "hidden behind keyguard" state rather than overloading |
| 7363 | * mPolicyVisibility. Ungh. |
| 7364 | */ |
| 7365 | public boolean isVisibleOrBehindKeyguardLw() { |
| 7366 | final AppWindowToken atoken = mAppToken; |
| 7367 | return mSurface != null && !mAttachedHidden |
| 7368 | && (atoken == null ? mPolicyVisibility : !atoken.hiddenRequested) |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 7369 | && !mDrawPending && !mCommitDrawPending |
| Dianne Hackborn | 3d163f07 | 2009-10-07 21:26:57 -0700 | [diff] [blame] | 7370 | && !mExiting && !mDestroying; |
| 7371 | } |
| 7372 | |
| 7373 | /** |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7374 | * Is this window visible, ignoring its app token? It is not visible |
| 7375 | * if there is no surface, or we are in the process of running an exit animation |
| 7376 | * that will remove the surface. |
| 7377 | */ |
| 7378 | public boolean isWinVisibleLw() { |
| 7379 | final AppWindowToken atoken = mAppToken; |
| 7380 | return mSurface != null && mPolicyVisibility && !mAttachedHidden |
| 7381 | && (atoken == null || !atoken.hiddenRequested || atoken.animating) |
| 7382 | && !mExiting && !mDestroying; |
| 7383 | } |
| 7384 | |
| 7385 | /** |
| 7386 | * The same as isVisible(), but follows the current hidden state of |
| 7387 | * the associated app token, not the pending requested hidden state. |
| 7388 | */ |
| 7389 | boolean isVisibleNow() { |
| 7390 | return mSurface != null && mPolicyVisibility && !mAttachedHidden |
| The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 7391 | && !mRootToken.hidden && !mExiting && !mDestroying; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7392 | } |
| 7393 | |
| 7394 | /** |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 7395 | * Can this window possibly be a drag/drop target? The test here is |
| 7396 | * a combination of the above "visible now" with the check that the |
| 7397 | * Input Manager uses when discarding windows from input consideration. |
| 7398 | */ |
| 7399 | boolean isPotentialDragTarget() { |
| 7400 | return isVisibleNow() && (mInputChannel != null) && !mRemoved; |
| 7401 | } |
| 7402 | |
| 7403 | /** |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7404 | * Same as isVisible(), but we also count it as visible between the |
| 7405 | * call to IWindowSession.add() and the first relayout(). |
| 7406 | */ |
| 7407 | boolean isVisibleOrAdding() { |
| 7408 | final AppWindowToken atoken = mAppToken; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 7409 | return ((mSurface != null && !mReportDestroySurface) |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7410 | || (!mRelayoutCalled && mViewVisibility == View.VISIBLE)) |
| 7411 | && mPolicyVisibility && !mAttachedHidden |
| 7412 | && (atoken == null || !atoken.hiddenRequested) |
| 7413 | && !mExiting && !mDestroying; |
| 7414 | } |
| 7415 | |
| 7416 | /** |
| 7417 | * Is this window currently on-screen? It is on-screen either if it |
| 7418 | * is visible or it is currently running an animation before no longer |
| 7419 | * being visible. |
| 7420 | */ |
| 7421 | boolean isOnScreen() { |
| 7422 | final AppWindowToken atoken = mAppToken; |
| 7423 | if (atoken != null) { |
| 7424 | return mSurface != null && mPolicyVisibility && !mDestroying |
| 7425 | && ((!mAttachedHidden && !atoken.hiddenRequested) |
| Dianne Hackborn | 0cd4887 | 2009-08-13 18:51:59 -0700 | [diff] [blame] | 7426 | || mAnimation != null || atoken.animation != null); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7427 | } else { |
| 7428 | return mSurface != null && mPolicyVisibility && !mDestroying |
| Dianne Hackborn | 0cd4887 | 2009-08-13 18:51:59 -0700 | [diff] [blame] | 7429 | && (!mAttachedHidden || mAnimation != null); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7430 | } |
| 7431 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7432 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7433 | /** |
| 7434 | * Like isOnScreen(), but we don't return true if the window is part |
| 7435 | * of a transition that has not yet been started. |
| 7436 | */ |
| 7437 | boolean isReadyForDisplay() { |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 7438 | if (mRootToken.waitingToShow && |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 7439 | mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 7440 | return false; |
| 7441 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7442 | final AppWindowToken atoken = mAppToken; |
| Dianne Hackborn | 0cd4887 | 2009-08-13 18:51:59 -0700 | [diff] [blame] | 7443 | final boolean animating = atoken != null |
| 7444 | ? (atoken.animation != null) : false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7445 | return mSurface != null && mPolicyVisibility && !mDestroying |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 7446 | && ((!mAttachedHidden && mViewVisibility == View.VISIBLE |
| 7447 | && !mRootToken.hidden) |
| Dianne Hackborn | 0cd4887 | 2009-08-13 18:51:59 -0700 | [diff] [blame] | 7448 | || mAnimation != null || animating); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7449 | } |
| 7450 | |
| 7451 | /** Is the window or its container currently animating? */ |
| 7452 | boolean isAnimating() { |
| 7453 | final WindowState attached = mAttachedWindow; |
| 7454 | final AppWindowToken atoken = mAppToken; |
| 7455 | return mAnimation != null |
| 7456 | || (attached != null && attached.mAnimation != null) |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7457 | || (atoken != null && |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7458 | (atoken.animation != null |
| 7459 | || atoken.inPendingTransaction)); |
| 7460 | } |
| 7461 | |
| 7462 | /** Is this window currently animating? */ |
| 7463 | boolean isWindowAnimating() { |
| 7464 | return mAnimation != null; |
| 7465 | } |
| 7466 | |
| 7467 | /** |
| 7468 | * Like isOnScreen, but returns false if the surface hasn't yet |
| 7469 | * been drawn. |
| 7470 | */ |
| 7471 | public boolean isDisplayedLw() { |
| 7472 | final AppWindowToken atoken = mAppToken; |
| 7473 | return mSurface != null && mPolicyVisibility && !mDestroying |
| 7474 | && !mDrawPending && !mCommitDrawPending |
| 7475 | && ((!mAttachedHidden && |
| 7476 | (atoken == null || !atoken.hiddenRequested)) |
| 7477 | || mAnimating); |
| 7478 | } |
| 7479 | |
| Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 7480 | /** |
| 7481 | * Returns true if the window has a surface that it has drawn a |
| 7482 | * complete UI in to. |
| 7483 | */ |
| 7484 | public boolean isDrawnLw() { |
| 7485 | final AppWindowToken atoken = mAppToken; |
| 7486 | return mSurface != null && !mDestroying |
| 7487 | && !mDrawPending && !mCommitDrawPending; |
| 7488 | } |
| 7489 | |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 7490 | /** |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 7491 | * Return true if the window is opaque and fully drawn. This indicates |
| 7492 | * it may obscure windows behind it. |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 7493 | */ |
| 7494 | boolean isOpaqueDrawn() { |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 7495 | return (mAttrs.format == PixelFormat.OPAQUE |
| 7496 | || mAttrs.type == TYPE_WALLPAPER) |
| 7497 | && mSurface != null && mAnimation == null |
| 7498 | && (mAppToken == null || mAppToken.animation == null) |
| 7499 | && !mDrawPending && !mCommitDrawPending; |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 7500 | } |
| 7501 | |
| 7502 | boolean needsBackgroundFiller(int screenWidth, int screenHeight) { |
| 7503 | return |
| 7504 | // only if the application is requesting compatible window |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 7505 | (mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0 && |
| 7506 | // only if it's visible |
| 7507 | mHasDrawn && mViewVisibility == View.VISIBLE && |
| Mitsuru Oshima | d2967e2 | 2009-07-20 14:01:43 -0700 | [diff] [blame] | 7508 | // and only if the application fills the compatible screen |
| 7509 | mFrame.left <= mCompatibleScreenFrame.left && |
| 7510 | mFrame.top <= mCompatibleScreenFrame.top && |
| 7511 | mFrame.right >= mCompatibleScreenFrame.right && |
| 7512 | mFrame.bottom >= mCompatibleScreenFrame.bottom && |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 7513 | // and starting window do not need background filler |
| Mitsuru Oshima | d2967e2 | 2009-07-20 14:01:43 -0700 | [diff] [blame] | 7514 | mAttrs.type != mAttrs.TYPE_APPLICATION_STARTING; |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 7515 | } |
| 7516 | |
| 7517 | boolean isFullscreen(int screenWidth, int screenHeight) { |
| 7518 | return mFrame.left <= 0 && mFrame.top <= 0 && |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 7519 | mFrame.right >= screenWidth && mFrame.bottom >= screenHeight; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7520 | } |
| 7521 | |
| 7522 | void removeLocked() { |
| Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 7523 | disposeInputChannel(); |
| 7524 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7525 | if (mAttachedWindow != null) { |
| 7526 | mAttachedWindow.mChildWindows.remove(this); |
| 7527 | } |
| 7528 | destroySurfaceLocked(); |
| 7529 | mSession.windowRemovedLocked(); |
| 7530 | try { |
| 7531 | mClient.asBinder().unlinkToDeath(mDeathRecipient, 0); |
| 7532 | } catch (RuntimeException e) { |
| 7533 | // Ignore if it has already been removed (usually because |
| 7534 | // we are doing this as part of processing a death note.) |
| 7535 | } |
| Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 7536 | } |
| 7537 | |
| 7538 | void disposeInputChannel() { |
| Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 7539 | if (mInputChannel != null) { |
| 7540 | mInputManager.unregisterInputChannel(mInputChannel); |
| 7541 | |
| 7542 | mInputChannel.dispose(); |
| 7543 | mInputChannel = null; |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 7544 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7545 | } |
| 7546 | |
| 7547 | private class DeathRecipient implements IBinder.DeathRecipient { |
| 7548 | public void binderDied() { |
| 7549 | try { |
| 7550 | synchronized(mWindowMap) { |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 7551 | WindowState win = windowForClientLocked(mSession, mClient, false); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7552 | Slog.i(TAG, "WIN DEATH: " + win); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7553 | if (win != null) { |
| 7554 | removeWindowLocked(mSession, win); |
| 7555 | } |
| 7556 | } |
| 7557 | } catch (IllegalArgumentException ex) { |
| 7558 | // This will happen if the window has already been |
| 7559 | // removed. |
| 7560 | } |
| 7561 | } |
| 7562 | } |
| 7563 | |
| 7564 | /** Returns true if this window desires key events. */ |
| 7565 | public final boolean canReceiveKeys() { |
| 7566 | return isVisibleOrAdding() |
| 7567 | && (mViewVisibility == View.VISIBLE) |
| 7568 | && ((mAttrs.flags & WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) == 0); |
| 7569 | } |
| 7570 | |
| 7571 | public boolean hasDrawnLw() { |
| 7572 | return mHasDrawn; |
| 7573 | } |
| 7574 | |
| 7575 | public boolean showLw(boolean doAnimation) { |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 7576 | return showLw(doAnimation, true); |
| 7577 | } |
| 7578 | |
| 7579 | boolean showLw(boolean doAnimation, boolean requestAnim) { |
| 7580 | if (mPolicyVisibility && mPolicyVisibilityAfterAnim) { |
| 7581 | return false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7582 | } |
| Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 7583 | if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility true: " + this); |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 7584 | if (doAnimation) { |
| 7585 | if (DEBUG_VISIBILITY) Slog.v(TAG, "doAnimation: mPolicyVisibility=" |
| 7586 | + mPolicyVisibility + " mAnimation=" + mAnimation); |
| 7587 | if (mDisplayFrozen || !mPolicy.isScreenOn()) { |
| 7588 | doAnimation = false; |
| 7589 | } else if (mPolicyVisibility && mAnimation == null) { |
| 7590 | // Check for the case where we are currently visible and |
| 7591 | // not animating; we do not want to do animation at such a |
| 7592 | // point to become visible when we already are. |
| 7593 | doAnimation = false; |
| 7594 | } |
| 7595 | } |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 7596 | mPolicyVisibility = true; |
| 7597 | mPolicyVisibilityAfterAnim = true; |
| 7598 | if (doAnimation) { |
| 7599 | applyAnimationLocked(this, WindowManagerPolicy.TRANSIT_ENTER, true); |
| 7600 | } |
| 7601 | if (requestAnim) { |
| 7602 | requestAnimationLocked(0); |
| 7603 | } |
| 7604 | return true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7605 | } |
| 7606 | |
| 7607 | public boolean hideLw(boolean doAnimation) { |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 7608 | return hideLw(doAnimation, true); |
| 7609 | } |
| 7610 | |
| 7611 | boolean hideLw(boolean doAnimation, boolean requestAnim) { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 7612 | if (doAnimation) { |
| 7613 | if (mDisplayFrozen || !mPolicy.isScreenOn()) { |
| 7614 | doAnimation = false; |
| 7615 | } |
| 7616 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7617 | boolean current = doAnimation ? mPolicyVisibilityAfterAnim |
| 7618 | : mPolicyVisibility; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 7619 | if (!current) { |
| 7620 | return false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7621 | } |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 7622 | if (doAnimation) { |
| 7623 | applyAnimationLocked(this, WindowManagerPolicy.TRANSIT_EXIT, false); |
| 7624 | if (mAnimation == null) { |
| 7625 | doAnimation = false; |
| 7626 | } |
| 7627 | } |
| 7628 | if (doAnimation) { |
| 7629 | mPolicyVisibilityAfterAnim = false; |
| 7630 | } else { |
| Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 7631 | if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility false: " + this); |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 7632 | mPolicyVisibilityAfterAnim = false; |
| 7633 | mPolicyVisibility = false; |
| Dianne Hackborn | f3bea9c | 2009-12-09 18:26:21 -0800 | [diff] [blame] | 7634 | // Window is no longer visible -- make sure if we were waiting |
| 7635 | // for it to be displayed before enabling the display, that |
| 7636 | // we allow the display to be enabled now. |
| 7637 | enableScreenIfNeededLocked(); |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 7638 | if (mCurrentFocus == this) { |
| 7639 | mFocusMayChange = true; |
| 7640 | } |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 7641 | } |
| 7642 | if (requestAnim) { |
| 7643 | requestAnimationLocked(0); |
| 7644 | } |
| 7645 | return true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7646 | } |
| 7647 | |
| 7648 | void dump(PrintWriter pw, String prefix) { |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7649 | pw.print(prefix); pw.print("mSession="); pw.print(mSession); |
| 7650 | pw.print(" mClient="); pw.println(mClient.asBinder()); |
| 7651 | pw.print(prefix); pw.print("mAttrs="); pw.println(mAttrs); |
| 7652 | if (mAttachedWindow != null || mLayoutAttached) { |
| 7653 | pw.print(prefix); pw.print("mAttachedWindow="); pw.print(mAttachedWindow); |
| 7654 | pw.print(" mLayoutAttached="); pw.println(mLayoutAttached); |
| 7655 | } |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 7656 | if (mIsImWindow || mIsWallpaper || mIsFloatingLayer) { |
| 7657 | pw.print(prefix); pw.print("mIsImWindow="); pw.print(mIsImWindow); |
| 7658 | pw.print(" mIsWallpaper="); pw.print(mIsWallpaper); |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 7659 | pw.print(" mIsFloatingLayer="); pw.print(mIsFloatingLayer); |
| 7660 | pw.print(" mWallpaperVisible="); pw.println(mWallpaperVisible); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7661 | } |
| 7662 | pw.print(prefix); pw.print("mBaseLayer="); pw.print(mBaseLayer); |
| 7663 | pw.print(" mSubLayer="); pw.print(mSubLayer); |
| 7664 | pw.print(" mAnimLayer="); pw.print(mLayer); pw.print("+"); |
| 7665 | pw.print((mTargetAppToken != null ? mTargetAppToken.animLayerAdjustment |
| 7666 | : (mAppToken != null ? mAppToken.animLayerAdjustment : 0))); |
| 7667 | pw.print("="); pw.print(mAnimLayer); |
| 7668 | pw.print(" mLastLayer="); pw.println(mLastLayer); |
| 7669 | if (mSurface != null) { |
| 7670 | pw.print(prefix); pw.print("mSurface="); pw.println(mSurface); |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 7671 | pw.print(prefix); pw.print("Surface: shown="); pw.print(mSurfaceShown); |
| 7672 | pw.print(" layer="); pw.print(mSurfaceLayer); |
| 7673 | pw.print(" alpha="); pw.print(mSurfaceAlpha); |
| 7674 | pw.print(" rect=("); pw.print(mSurfaceX); |
| 7675 | pw.print(","); pw.print(mSurfaceY); |
| 7676 | pw.print(") "); pw.print(mSurfaceW); |
| 7677 | pw.print(" x "); pw.println(mSurfaceH); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7678 | } |
| 7679 | pw.print(prefix); pw.print("mToken="); pw.println(mToken); |
| 7680 | pw.print(prefix); pw.print("mRootToken="); pw.println(mRootToken); |
| 7681 | if (mAppToken != null) { |
| 7682 | pw.print(prefix); pw.print("mAppToken="); pw.println(mAppToken); |
| 7683 | } |
| 7684 | if (mTargetAppToken != null) { |
| 7685 | pw.print(prefix); pw.print("mTargetAppToken="); pw.println(mTargetAppToken); |
| 7686 | } |
| 7687 | pw.print(prefix); pw.print("mViewVisibility=0x"); |
| 7688 | pw.print(Integer.toHexString(mViewVisibility)); |
| 7689 | pw.print(" mLastHidden="); pw.print(mLastHidden); |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 7690 | pw.print(" mHaveFrame="); pw.print(mHaveFrame); |
| 7691 | pw.print(" mObscured="); pw.println(mObscured); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7692 | if (!mPolicyVisibility || !mPolicyVisibilityAfterAnim || mAttachedHidden) { |
| 7693 | pw.print(prefix); pw.print("mPolicyVisibility="); |
| 7694 | pw.print(mPolicyVisibility); |
| 7695 | pw.print(" mPolicyVisibilityAfterAnim="); |
| 7696 | pw.print(mPolicyVisibilityAfterAnim); |
| 7697 | pw.print(" mAttachedHidden="); pw.println(mAttachedHidden); |
| 7698 | } |
| Dianne Hackborn | 9b52a21 | 2009-12-11 14:51:35 -0800 | [diff] [blame] | 7699 | if (!mRelayoutCalled) { |
| 7700 | pw.print(prefix); pw.print("mRelayoutCalled="); pw.println(mRelayoutCalled); |
| 7701 | } |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7702 | pw.print(prefix); pw.print("Requested w="); pw.print(mRequestedWidth); |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 7703 | pw.print(" h="); pw.print(mRequestedHeight); |
| 7704 | pw.print(" mLayoutSeq="); pw.println(mLayoutSeq); |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 7705 | if (mXOffset != 0 || mYOffset != 0) { |
| 7706 | pw.print(prefix); pw.print("Offsets x="); pw.print(mXOffset); |
| 7707 | pw.print(" y="); pw.println(mYOffset); |
| 7708 | } |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7709 | pw.print(prefix); pw.print("mGivenContentInsets="); |
| 7710 | mGivenContentInsets.printShortString(pw); |
| 7711 | pw.print(" mGivenVisibleInsets="); |
| 7712 | mGivenVisibleInsets.printShortString(pw); |
| 7713 | pw.println(); |
| 7714 | if (mTouchableInsets != 0 || mGivenInsetsPending) { |
| 7715 | pw.print(prefix); pw.print("mTouchableInsets="); pw.print(mTouchableInsets); |
| 7716 | pw.print(" mGivenInsetsPending="); pw.println(mGivenInsetsPending); |
| 7717 | } |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 7718 | pw.print(prefix); pw.print("mConfiguration="); pw.println(mConfiguration); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7719 | pw.print(prefix); pw.print("mShownFrame="); |
| 7720 | mShownFrame.printShortString(pw); |
| 7721 | pw.print(" last="); mLastShownFrame.printShortString(pw); |
| 7722 | pw.println(); |
| 7723 | pw.print(prefix); pw.print("mFrame="); mFrame.printShortString(pw); |
| 7724 | pw.print(" last="); mLastFrame.printShortString(pw); |
| 7725 | pw.println(); |
| 7726 | pw.print(prefix); pw.print("mContainingFrame="); |
| 7727 | mContainingFrame.printShortString(pw); |
| 7728 | pw.print(" mDisplayFrame="); |
| 7729 | mDisplayFrame.printShortString(pw); |
| 7730 | pw.println(); |
| 7731 | pw.print(prefix); pw.print("mContentFrame="); mContentFrame.printShortString(pw); |
| 7732 | pw.print(" mVisibleFrame="); mVisibleFrame.printShortString(pw); |
| 7733 | pw.println(); |
| 7734 | pw.print(prefix); pw.print("mContentInsets="); mContentInsets.printShortString(pw); |
| 7735 | pw.print(" last="); mLastContentInsets.printShortString(pw); |
| 7736 | pw.print(" mVisibleInsets="); mVisibleInsets.printShortString(pw); |
| 7737 | pw.print(" last="); mLastVisibleInsets.printShortString(pw); |
| 7738 | pw.println(); |
| 7739 | if (mShownAlpha != 1 || mAlpha != 1 || mLastAlpha != 1) { |
| 7740 | pw.print(prefix); pw.print("mShownAlpha="); pw.print(mShownAlpha); |
| 7741 | pw.print(" mAlpha="); pw.print(mAlpha); |
| 7742 | pw.print(" mLastAlpha="); pw.println(mLastAlpha); |
| 7743 | } |
| 7744 | if (mAnimating || mLocalAnimating || mAnimationIsEntrance |
| 7745 | || mAnimation != null) { |
| 7746 | pw.print(prefix); pw.print("mAnimating="); pw.print(mAnimating); |
| 7747 | pw.print(" mLocalAnimating="); pw.print(mLocalAnimating); |
| 7748 | pw.print(" mAnimationIsEntrance="); pw.print(mAnimationIsEntrance); |
| 7749 | pw.print(" mAnimation="); pw.println(mAnimation); |
| 7750 | } |
| 7751 | if (mHasTransformation || mHasLocalTransformation) { |
| 7752 | pw.print(prefix); pw.print("XForm: has="); |
| 7753 | pw.print(mHasTransformation); |
| 7754 | pw.print(" hasLocal="); pw.print(mHasLocalTransformation); |
| 7755 | pw.print(" "); mTransformation.printShortString(pw); |
| 7756 | pw.println(); |
| 7757 | } |
| 7758 | pw.print(prefix); pw.print("mDrawPending="); pw.print(mDrawPending); |
| 7759 | pw.print(" mCommitDrawPending="); pw.print(mCommitDrawPending); |
| 7760 | pw.print(" mReadyToShow="); pw.print(mReadyToShow); |
| 7761 | pw.print(" mHasDrawn="); pw.println(mHasDrawn); |
| 7762 | if (mExiting || mRemoveOnExit || mDestroying || mRemoved) { |
| 7763 | pw.print(prefix); pw.print("mExiting="); pw.print(mExiting); |
| 7764 | pw.print(" mRemoveOnExit="); pw.print(mRemoveOnExit); |
| 7765 | pw.print(" mDestroying="); pw.print(mDestroying); |
| 7766 | pw.print(" mRemoved="); pw.println(mRemoved); |
| 7767 | } |
| Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 7768 | if (mOrientationChanging || mAppFreezing || mTurnOnScreen) { |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7769 | pw.print(prefix); pw.print("mOrientationChanging="); |
| 7770 | pw.print(mOrientationChanging); |
| Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 7771 | pw.print(" mAppFreezing="); pw.print(mAppFreezing); |
| 7772 | pw.print(" mTurnOnScreen="); pw.println(mTurnOnScreen); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7773 | } |
| Mitsuru Oshima | 589cebe | 2009-07-22 20:38:58 -0700 | [diff] [blame] | 7774 | if (mHScale != 1 || mVScale != 1) { |
| 7775 | pw.print(prefix); pw.print("mHScale="); pw.print(mHScale); |
| 7776 | pw.print(" mVScale="); pw.println(mVScale); |
| 7777 | } |
| Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 7778 | if (mWallpaperX != -1 || mWallpaperY != -1) { |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 7779 | pw.print(prefix); pw.print("mWallpaperX="); pw.print(mWallpaperX); |
| 7780 | pw.print(" mWallpaperY="); pw.println(mWallpaperY); |
| 7781 | } |
| Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 7782 | if (mWallpaperXStep != -1 || mWallpaperYStep != -1) { |
| 7783 | pw.print(prefix); pw.print("mWallpaperXStep="); pw.print(mWallpaperXStep); |
| 7784 | pw.print(" mWallpaperYStep="); pw.println(mWallpaperYStep); |
| 7785 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7786 | } |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 7787 | |
| 7788 | String makeInputChannelName() { |
| 7789 | return Integer.toHexString(System.identityHashCode(this)) |
| 7790 | + " " + mAttrs.getTitle(); |
| 7791 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7792 | |
| 7793 | @Override |
| 7794 | public String toString() { |
| 7795 | return "Window{" |
| 7796 | + Integer.toHexString(System.identityHashCode(this)) |
| 7797 | + " " + mAttrs.getTitle() + " paused=" + mToken.paused + "}"; |
| 7798 | } |
| 7799 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7800 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7801 | // ------------------------------------------------------------- |
| 7802 | // Window Token State |
| 7803 | // ------------------------------------------------------------- |
| 7804 | |
| 7805 | class WindowToken { |
| 7806 | // The actual token. |
| 7807 | final IBinder token; |
| 7808 | |
| 7809 | // The type of window this token is for, as per WindowManager.LayoutParams. |
| 7810 | final int windowType; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7811 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7812 | // Set if this token was explicitly added by a client, so should |
| 7813 | // not be removed when all windows are removed. |
| 7814 | final boolean explicit; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7815 | |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7816 | // For printing. |
| 7817 | String stringName; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7818 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7819 | // If this is an AppWindowToken, this is non-null. |
| 7820 | AppWindowToken appWindowToken; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7821 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7822 | // All of the windows associated with this token. |
| 7823 | final ArrayList<WindowState> windows = new ArrayList<WindowState>(); |
| 7824 | |
| 7825 | // Is key dispatching paused for this token? |
| 7826 | boolean paused = false; |
| 7827 | |
| 7828 | // Should this token's windows be hidden? |
| 7829 | boolean hidden; |
| 7830 | |
| 7831 | // Temporary for finding which tokens no longer have visible windows. |
| 7832 | boolean hasVisible; |
| 7833 | |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 7834 | // Set to true when this token is in a pending transaction where it |
| 7835 | // will be shown. |
| 7836 | boolean waitingToShow; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7837 | |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 7838 | // Set to true when this token is in a pending transaction where it |
| 7839 | // will be hidden. |
| 7840 | boolean waitingToHide; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7841 | |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 7842 | // Set to true when this token is in a pending transaction where its |
| 7843 | // windows will be put to the bottom of the list. |
| 7844 | boolean sendingToBottom; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7845 | |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 7846 | // Set to true when this token is in a pending transaction where its |
| 7847 | // windows will be put to the top of the list. |
| 7848 | boolean sendingToTop; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7849 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7850 | WindowToken(IBinder _token, int type, boolean _explicit) { |
| 7851 | token = _token; |
| 7852 | windowType = type; |
| 7853 | explicit = _explicit; |
| 7854 | } |
| 7855 | |
| 7856 | void dump(PrintWriter pw, String prefix) { |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7857 | pw.print(prefix); pw.print("token="); pw.println(token); |
| 7858 | pw.print(prefix); pw.print("windows="); pw.println(windows); |
| 7859 | pw.print(prefix); pw.print("windowType="); pw.print(windowType); |
| 7860 | pw.print(" hidden="); pw.print(hidden); |
| 7861 | pw.print(" hasVisible="); pw.println(hasVisible); |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 7862 | if (waitingToShow || waitingToHide || sendingToBottom || sendingToTop) { |
| 7863 | pw.print(prefix); pw.print("waitingToShow="); pw.print(waitingToShow); |
| 7864 | pw.print(" waitingToHide="); pw.print(waitingToHide); |
| 7865 | pw.print(" sendingToBottom="); pw.print(sendingToBottom); |
| 7866 | pw.print(" sendingToTop="); pw.println(sendingToTop); |
| 7867 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7868 | } |
| 7869 | |
| 7870 | @Override |
| 7871 | public String toString() { |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7872 | if (stringName == null) { |
| 7873 | StringBuilder sb = new StringBuilder(); |
| 7874 | sb.append("WindowToken{"); |
| 7875 | sb.append(Integer.toHexString(System.identityHashCode(this))); |
| 7876 | sb.append(" token="); sb.append(token); sb.append('}'); |
| 7877 | stringName = sb.toString(); |
| 7878 | } |
| 7879 | return stringName; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7880 | } |
| 7881 | }; |
| 7882 | |
| 7883 | class AppWindowToken extends WindowToken { |
| 7884 | // Non-null only for application tokens. |
| 7885 | final IApplicationToken appToken; |
| 7886 | |
| 7887 | // All of the windows and child windows that are included in this |
| 7888 | // application token. Note this list is NOT sorted! |
| 7889 | final ArrayList<WindowState> allAppWindows = new ArrayList<WindowState>(); |
| 7890 | |
| 7891 | int groupId = -1; |
| 7892 | boolean appFullscreen; |
| 7893 | int requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 7894 | |
| 7895 | // The input dispatching timeout for this application token in nanoseconds. |
| 7896 | long inputDispatchingTimeoutNanos; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7897 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7898 | // These are used for determining when all windows associated with |
| 7899 | // an activity have been drawn, so they can be made visible together |
| 7900 | // at the same time. |
| 7901 | int lastTransactionSequence = mTransactionSequence-1; |
| 7902 | int numInterestingWindows; |
| 7903 | int numDrawnWindows; |
| 7904 | boolean inPendingTransaction; |
| 7905 | boolean allDrawn; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7906 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7907 | // Is this token going to be hidden in a little while? If so, it |
| 7908 | // won't be taken into account for setting the screen orientation. |
| 7909 | boolean willBeHidden; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7910 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7911 | // Is this window's surface needed? This is almost like hidden, except |
| 7912 | // it will sometimes be true a little earlier: when the token has |
| 7913 | // been shown, but is still waiting for its app transition to execute |
| 7914 | // before making its windows shown. |
| 7915 | boolean hiddenRequested; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7916 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7917 | // Have we told the window clients to hide themselves? |
| 7918 | boolean clientHidden; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7919 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7920 | // Last visibility state we reported to the app token. |
| 7921 | boolean reportedVisible; |
| 7922 | |
| 7923 | // Set to true when the token has been removed from the window mgr. |
| 7924 | boolean removed; |
| 7925 | |
| 7926 | // Have we been asked to have this token keep the screen frozen? |
| 7927 | boolean freezingScreen; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7928 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7929 | boolean animating; |
| 7930 | Animation animation; |
| 7931 | boolean hasTransformation; |
| 7932 | final Transformation transformation = new Transformation(); |
| 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 | // Offset to the window of all layers in the token, for use by |
| 7935 | // AppWindowToken animations. |
| 7936 | int animLayerAdjustment; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7937 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7938 | // Information about an application starting window if displayed. |
| 7939 | StartingData startingData; |
| 7940 | WindowState startingWindow; |
| 7941 | View startingView; |
| 7942 | boolean startingDisplayed; |
| 7943 | boolean startingMoved; |
| 7944 | boolean firstWindowDrawn; |
| 7945 | |
| 7946 | AppWindowToken(IApplicationToken _token) { |
| 7947 | super(_token.asBinder(), |
| 7948 | WindowManager.LayoutParams.TYPE_APPLICATION, true); |
| 7949 | appWindowToken = this; |
| 7950 | appToken = _token; |
| 7951 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7952 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7953 | public void setAnimation(Animation anim) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7954 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7955 | TAG, "Setting animation in " + this + ": " + anim); |
| 7956 | animation = anim; |
| 7957 | animating = false; |
| 7958 | anim.restrictDuration(MAX_ANIMATION_DURATION); |
| 7959 | anim.scaleCurrentDuration(mTransitionAnimationScale); |
| 7960 | int zorder = anim.getZAdjustment(); |
| 7961 | int adj = 0; |
| 7962 | if (zorder == Animation.ZORDER_TOP) { |
| 7963 | adj = TYPE_LAYER_OFFSET; |
| 7964 | } else if (zorder == Animation.ZORDER_BOTTOM) { |
| 7965 | adj = -TYPE_LAYER_OFFSET; |
| 7966 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7967 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7968 | if (animLayerAdjustment != adj) { |
| 7969 | animLayerAdjustment = adj; |
| 7970 | updateLayers(); |
| 7971 | } |
| 7972 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7973 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7974 | public void setDummyAnimation() { |
| 7975 | if (animation == null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7976 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7977 | TAG, "Setting dummy animation in " + this); |
| 7978 | animation = sDummyAnimation; |
| 7979 | } |
| 7980 | } |
| 7981 | |
| 7982 | public void clearAnimation() { |
| 7983 | if (animation != null) { |
| 7984 | animation = null; |
| 7985 | animating = true; |
| 7986 | } |
| 7987 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7988 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7989 | void updateLayers() { |
| 7990 | final int N = allAppWindows.size(); |
| 7991 | final int adj = animLayerAdjustment; |
| 7992 | for (int i=0; i<N; i++) { |
| 7993 | WindowState w = allAppWindows.get(i); |
| 7994 | w.mAnimLayer = w.mLayer + adj; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7995 | if (DEBUG_LAYERS) Slog.v(TAG, "Updating layer " + w + ": " |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7996 | + w.mAnimLayer); |
| 7997 | if (w == mInputMethodTarget) { |
| 7998 | setInputMethodAnimLayerAdjustment(adj); |
| 7999 | } |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 8000 | if (w == mWallpaperTarget && mLowerWallpaperTarget == null) { |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 8001 | setWallpaperAnimLayerAdjustmentLocked(adj); |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 8002 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8003 | } |
| 8004 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8005 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8006 | void sendAppVisibilityToClients() { |
| 8007 | final int N = allAppWindows.size(); |
| 8008 | for (int i=0; i<N; i++) { |
| 8009 | WindowState win = allAppWindows.get(i); |
| 8010 | if (win == startingWindow && clientHidden) { |
| 8011 | // Don't hide the starting window. |
| 8012 | continue; |
| 8013 | } |
| 8014 | try { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8015 | if (DEBUG_VISIBILITY) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8016 | "Setting visibility of " + win + ": " + (!clientHidden)); |
| 8017 | win.mClient.dispatchAppVisibility(!clientHidden); |
| 8018 | } catch (RemoteException e) { |
| 8019 | } |
| 8020 | } |
| 8021 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8022 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8023 | void showAllWindowsLocked() { |
| 8024 | final int NW = allAppWindows.size(); |
| 8025 | for (int i=0; i<NW; i++) { |
| 8026 | WindowState w = allAppWindows.get(i); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8027 | if (DEBUG_VISIBILITY) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8028 | "performing show on: " + w); |
| 8029 | w.performShowLocked(); |
| 8030 | } |
| 8031 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8032 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8033 | // This must be called while inside a transaction. |
| 8034 | boolean stepAnimationLocked(long currentTime, int dw, int dh) { |
| Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 8035 | if (!mDisplayFrozen && mPolicy.isScreenOn()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8036 | // We will run animations as long as the display isn't frozen. |
| 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 | if (animation == sDummyAnimation) { |
| 8039 | // This guy is going to animate, but not yet. For now count |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 8040 | // it as not animating for purposes of scheduling transactions; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8041 | // when it is really time to animate, this will be set to |
| 8042 | // a real animation and the next call will execute normally. |
| 8043 | return false; |
| 8044 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8045 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8046 | if ((allDrawn || animating || startingDisplayed) && animation != null) { |
| 8047 | if (!animating) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8048 | if (DEBUG_ANIM) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8049 | TAG, "Starting animation in " + this + |
| 8050 | " @ " + currentTime + ": dw=" + dw + " dh=" + dh |
| 8051 | + " scale=" + mTransitionAnimationScale |
| 8052 | + " allDrawn=" + allDrawn + " animating=" + animating); |
| 8053 | animation.initialize(dw, dh, dw, dh); |
| 8054 | animation.setStartTime(currentTime); |
| 8055 | animating = true; |
| 8056 | } |
| 8057 | transformation.clear(); |
| 8058 | final boolean more = animation.getTransformation( |
| 8059 | currentTime, transformation); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8060 | if (DEBUG_ANIM) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8061 | TAG, "Stepped animation in " + this + |
| 8062 | ": more=" + more + ", xform=" + transformation); |
| 8063 | if (more) { |
| 8064 | // we're done! |
| 8065 | hasTransformation = true; |
| 8066 | return true; |
| 8067 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8068 | if (DEBUG_ANIM) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8069 | TAG, "Finished animation in " + this + |
| 8070 | " @ " + currentTime); |
| 8071 | animation = null; |
| 8072 | } |
| 8073 | } else if (animation != null) { |
| 8074 | // If the display is frozen, and there is a pending animation, |
| 8075 | // clear it and make sure we run the cleanup code. |
| 8076 | animating = true; |
| 8077 | animation = null; |
| 8078 | } |
| 8079 | |
| 8080 | hasTransformation = false; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8081 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8082 | if (!animating) { |
| 8083 | return false; |
| 8084 | } |
| 8085 | |
| 8086 | clearAnimation(); |
| 8087 | animating = false; |
| 8088 | if (mInputMethodTarget != null && mInputMethodTarget.mAppToken == this) { |
| 8089 | moveInputMethodWindowsIfNeededLocked(true); |
| 8090 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8091 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8092 | if (DEBUG_ANIM) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8093 | TAG, "Animation done in " + this |
| 8094 | + ": reportedVisible=" + reportedVisible); |
| 8095 | |
| 8096 | transformation.clear(); |
| 8097 | if (animLayerAdjustment != 0) { |
| 8098 | animLayerAdjustment = 0; |
| 8099 | updateLayers(); |
| 8100 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8101 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8102 | final int N = windows.size(); |
| 8103 | for (int i=0; i<N; i++) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 8104 | windows.get(i).finishExit(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8105 | } |
| 8106 | updateReportedVisibilityLocked(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8107 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8108 | return false; |
| 8109 | } |
| 8110 | |
| 8111 | void updateReportedVisibilityLocked() { |
| 8112 | if (appToken == null) { |
| 8113 | return; |
| 8114 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8115 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8116 | int numInteresting = 0; |
| 8117 | int numVisible = 0; |
| 8118 | boolean nowGone = true; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8119 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8120 | 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] | 8121 | final int N = allAppWindows.size(); |
| 8122 | for (int i=0; i<N; i++) { |
| 8123 | WindowState win = allAppWindows.get(i); |
| Dianne Hackborn | 6cf67fa | 2009-12-21 16:46:34 -0800 | [diff] [blame] | 8124 | if (win == startingWindow || win.mAppFreezing |
| The Android Open Source Project | 727cec0 | 2010-04-08 11:35:37 -0700 | [diff] [blame] | 8125 | || win.mViewVisibility != View.VISIBLE |
| Ulf Rosdahl | 3935770 | 2010-09-29 12:34:38 +0200 | [diff] [blame] | 8126 | || win.mAttrs.type == TYPE_APPLICATION_STARTING |
| 8127 | || win.mDestroying) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8128 | continue; |
| 8129 | } |
| 8130 | if (DEBUG_VISIBILITY) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8131 | Slog.v(TAG, "Win " + win + ": isDrawn=" |
| Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 8132 | + win.isDrawnLw() |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8133 | + ", isAnimating=" + win.isAnimating()); |
| Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 8134 | if (!win.isDrawnLw()) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8135 | Slog.v(TAG, "Not displayed: s=" + win.mSurface |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8136 | + " pv=" + win.mPolicyVisibility |
| 8137 | + " dp=" + win.mDrawPending |
| 8138 | + " cdp=" + win.mCommitDrawPending |
| 8139 | + " ah=" + win.mAttachedHidden |
| 8140 | + " th=" |
| 8141 | + (win.mAppToken != null |
| 8142 | ? win.mAppToken.hiddenRequested : false) |
| 8143 | + " a=" + win.mAnimating); |
| 8144 | } |
| 8145 | } |
| 8146 | numInteresting++; |
| Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 8147 | if (win.isDrawnLw()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8148 | if (!win.isAnimating()) { |
| 8149 | numVisible++; |
| 8150 | } |
| 8151 | nowGone = false; |
| 8152 | } else if (win.isAnimating()) { |
| 8153 | nowGone = false; |
| 8154 | } |
| 8155 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8156 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8157 | boolean nowVisible = numInteresting > 0 && numVisible >= numInteresting; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8158 | if (DEBUG_VISIBILITY) Slog.v(TAG, "VIS " + this + ": interesting=" |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8159 | + numInteresting + " visible=" + numVisible); |
| 8160 | if (nowVisible != reportedVisible) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8161 | if (DEBUG_VISIBILITY) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8162 | TAG, "Visibility changed in " + this |
| 8163 | + ": vis=" + nowVisible); |
| 8164 | reportedVisible = nowVisible; |
| 8165 | Message m = mH.obtainMessage( |
| 8166 | H.REPORT_APPLICATION_TOKEN_WINDOWS, |
| 8167 | nowVisible ? 1 : 0, |
| 8168 | nowGone ? 1 : 0, |
| 8169 | this); |
| 8170 | mH.sendMessage(m); |
| 8171 | } |
| 8172 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8173 | |
| Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 8174 | WindowState findMainWindow() { |
| 8175 | int j = windows.size(); |
| 8176 | while (j > 0) { |
| 8177 | j--; |
| 8178 | WindowState win = windows.get(j); |
| 8179 | if (win.mAttrs.type == WindowManager.LayoutParams.TYPE_BASE_APPLICATION |
| 8180 | || win.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING) { |
| 8181 | return win; |
| 8182 | } |
| 8183 | } |
| 8184 | return null; |
| 8185 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8186 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8187 | void dump(PrintWriter pw, String prefix) { |
| 8188 | super.dump(pw, prefix); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8189 | if (appToken != null) { |
| 8190 | pw.print(prefix); pw.println("app=true"); |
| 8191 | } |
| 8192 | if (allAppWindows.size() > 0) { |
| 8193 | pw.print(prefix); pw.print("allAppWindows="); pw.println(allAppWindows); |
| 8194 | } |
| 8195 | pw.print(prefix); pw.print("groupId="); pw.print(groupId); |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8196 | pw.print(" appFullscreen="); pw.print(appFullscreen); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8197 | pw.print(" requestedOrientation="); pw.println(requestedOrientation); |
| 8198 | pw.print(prefix); pw.print("hiddenRequested="); pw.print(hiddenRequested); |
| 8199 | pw.print(" clientHidden="); pw.print(clientHidden); |
| 8200 | pw.print(" willBeHidden="); pw.print(willBeHidden); |
| 8201 | pw.print(" reportedVisible="); pw.println(reportedVisible); |
| 8202 | if (paused || freezingScreen) { |
| 8203 | pw.print(prefix); pw.print("paused="); pw.print(paused); |
| 8204 | pw.print(" freezingScreen="); pw.println(freezingScreen); |
| 8205 | } |
| 8206 | if (numInterestingWindows != 0 || numDrawnWindows != 0 |
| 8207 | || inPendingTransaction || allDrawn) { |
| 8208 | pw.print(prefix); pw.print("numInterestingWindows="); |
| 8209 | pw.print(numInterestingWindows); |
| 8210 | pw.print(" numDrawnWindows="); pw.print(numDrawnWindows); |
| 8211 | pw.print(" inPendingTransaction="); pw.print(inPendingTransaction); |
| 8212 | pw.print(" allDrawn="); pw.println(allDrawn); |
| 8213 | } |
| 8214 | if (animating || animation != null) { |
| 8215 | pw.print(prefix); pw.print("animating="); pw.print(animating); |
| 8216 | pw.print(" animation="); pw.println(animation); |
| 8217 | } |
| 8218 | if (animLayerAdjustment != 0) { |
| 8219 | pw.print(prefix); pw.print("animLayerAdjustment="); pw.println(animLayerAdjustment); |
| 8220 | } |
| 8221 | if (hasTransformation) { |
| 8222 | pw.print(prefix); pw.print("hasTransformation="); pw.print(hasTransformation); |
| 8223 | pw.print(" transformation="); transformation.printShortString(pw); |
| 8224 | pw.println(); |
| 8225 | } |
| 8226 | if (startingData != null || removed || firstWindowDrawn) { |
| 8227 | pw.print(prefix); pw.print("startingData="); pw.print(startingData); |
| 8228 | pw.print(" removed="); pw.print(removed); |
| 8229 | pw.print(" firstWindowDrawn="); pw.println(firstWindowDrawn); |
| 8230 | } |
| 8231 | if (startingWindow != null || startingView != null |
| 8232 | || startingDisplayed || startingMoved) { |
| 8233 | pw.print(prefix); pw.print("startingWindow="); pw.print(startingWindow); |
| 8234 | pw.print(" startingView="); pw.print(startingView); |
| 8235 | pw.print(" startingDisplayed="); pw.print(startingDisplayed); |
| 8236 | pw.print(" startingMoved"); pw.println(startingMoved); |
| 8237 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8238 | } |
| 8239 | |
| 8240 | @Override |
| 8241 | public String toString() { |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8242 | if (stringName == null) { |
| 8243 | StringBuilder sb = new StringBuilder(); |
| 8244 | sb.append("AppWindowToken{"); |
| 8245 | sb.append(Integer.toHexString(System.identityHashCode(this))); |
| 8246 | sb.append(" token="); sb.append(token); sb.append('}'); |
| 8247 | stringName = sb.toString(); |
| 8248 | } |
| 8249 | return stringName; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8250 | } |
| 8251 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8252 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8253 | // ------------------------------------------------------------- |
| 8254 | // DummyAnimation |
| 8255 | // ------------------------------------------------------------- |
| 8256 | |
| 8257 | // This is an animation that does nothing: it just immediately finishes |
| 8258 | // itself every time it is called. It is used as a stub animation in cases |
| 8259 | // where we want to synchronize multiple things that may be animating. |
| 8260 | static final class DummyAnimation extends Animation { |
| 8261 | public boolean getTransformation(long currentTime, Transformation outTransformation) { |
| 8262 | return false; |
| 8263 | } |
| 8264 | } |
| 8265 | static final Animation sDummyAnimation = new DummyAnimation(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8266 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8267 | // ------------------------------------------------------------- |
| 8268 | // Async Handler |
| 8269 | // ------------------------------------------------------------- |
| 8270 | |
| 8271 | static final class StartingData { |
| 8272 | final String pkg; |
| 8273 | final int theme; |
| 8274 | final CharSequence nonLocalizedLabel; |
| 8275 | final int labelRes; |
| 8276 | final int icon; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8277 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8278 | StartingData(String _pkg, int _theme, CharSequence _nonLocalizedLabel, |
| 8279 | int _labelRes, int _icon) { |
| 8280 | pkg = _pkg; |
| 8281 | theme = _theme; |
| 8282 | nonLocalizedLabel = _nonLocalizedLabel; |
| 8283 | labelRes = _labelRes; |
| 8284 | icon = _icon; |
| 8285 | } |
| 8286 | } |
| 8287 | |
| 8288 | private final class H extends Handler { |
| 8289 | public static final int REPORT_FOCUS_CHANGE = 2; |
| 8290 | public static final int REPORT_LOSING_FOCUS = 3; |
| 8291 | public static final int ANIMATE = 4; |
| 8292 | public static final int ADD_STARTING = 5; |
| 8293 | public static final int REMOVE_STARTING = 6; |
| 8294 | public static final int FINISHED_STARTING = 7; |
| 8295 | public static final int REPORT_APPLICATION_TOKEN_WINDOWS = 8; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8296 | public static final int WINDOW_FREEZE_TIMEOUT = 11; |
| 8297 | public static final int HOLD_SCREEN_CHANGED = 12; |
| 8298 | public static final int APP_TRANSITION_TIMEOUT = 13; |
| 8299 | public static final int PERSIST_ANIMATION_SCALE = 14; |
| 8300 | public static final int FORCE_GC = 15; |
| 8301 | public static final int ENABLE_SCREEN = 16; |
| 8302 | public static final int APP_FREEZE_TIMEOUT = 17; |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 8303 | public static final int SEND_NEW_CONFIGURATION = 18; |
| Konstantin Lopyrev | 6e0f65f | 2010-07-14 14:55:33 -0700 | [diff] [blame] | 8304 | public static final int REPORT_WINDOWS_CHANGE = 19; |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 8305 | public static final int DRAG_START_TIMEOUT = 20; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8306 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8307 | private Session mLastReportedHold; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8308 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8309 | public H() { |
| 8310 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8311 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8312 | @Override |
| 8313 | public void handleMessage(Message msg) { |
| 8314 | switch (msg.what) { |
| 8315 | case REPORT_FOCUS_CHANGE: { |
| 8316 | WindowState lastFocus; |
| 8317 | WindowState newFocus; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8318 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8319 | synchronized(mWindowMap) { |
| 8320 | lastFocus = mLastFocus; |
| 8321 | newFocus = mCurrentFocus; |
| 8322 | if (lastFocus == newFocus) { |
| 8323 | // Focus is not changing, so nothing to do. |
| 8324 | return; |
| 8325 | } |
| 8326 | mLastFocus = newFocus; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8327 | //Slog.i(TAG, "Focus moving from " + lastFocus |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8328 | // + " to " + newFocus); |
| 8329 | if (newFocus != null && lastFocus != null |
| 8330 | && !newFocus.isDisplayedLw()) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8331 | //Slog.i(TAG, "Delaying loss of focus..."); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8332 | mLosingFocus.add(lastFocus); |
| 8333 | lastFocus = null; |
| 8334 | } |
| 8335 | } |
| 8336 | |
| 8337 | if (lastFocus != newFocus) { |
| 8338 | //System.out.println("Changing focus from " + lastFocus |
| 8339 | // + " to " + newFocus); |
| 8340 | if (newFocus != null) { |
| 8341 | try { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8342 | //Slog.i(TAG, "Gaining focus: " + newFocus); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8343 | newFocus.mClient.windowFocusChanged(true, mInTouchMode); |
| 8344 | } catch (RemoteException e) { |
| 8345 | // Ignore if process has died. |
| 8346 | } |
| Konstantin Lopyrev | 5e7833a | 2010-08-09 17:01:11 -0700 | [diff] [blame] | 8347 | notifyFocusChanged(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8348 | } |
| 8349 | |
| 8350 | if (lastFocus != null) { |
| 8351 | try { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8352 | //Slog.i(TAG, "Losing focus: " + lastFocus); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8353 | lastFocus.mClient.windowFocusChanged(false, mInTouchMode); |
| 8354 | } catch (RemoteException e) { |
| 8355 | // Ignore if process has died. |
| 8356 | } |
| 8357 | } |
| 8358 | } |
| 8359 | } break; |
| 8360 | |
| 8361 | case REPORT_LOSING_FOCUS: { |
| 8362 | ArrayList<WindowState> losers; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8363 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8364 | synchronized(mWindowMap) { |
| 8365 | losers = mLosingFocus; |
| 8366 | mLosingFocus = new ArrayList<WindowState>(); |
| 8367 | } |
| 8368 | |
| 8369 | final int N = losers.size(); |
| 8370 | for (int i=0; i<N; i++) { |
| 8371 | try { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8372 | //Slog.i(TAG, "Losing delayed focus: " + losers.get(i)); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8373 | losers.get(i).mClient.windowFocusChanged(false, mInTouchMode); |
| 8374 | } catch (RemoteException e) { |
| 8375 | // Ignore if process has died. |
| 8376 | } |
| 8377 | } |
| 8378 | } break; |
| 8379 | |
| 8380 | case ANIMATE: { |
| 8381 | synchronized(mWindowMap) { |
| 8382 | mAnimationPending = false; |
| 8383 | performLayoutAndPlaceSurfacesLocked(); |
| 8384 | } |
| 8385 | } break; |
| 8386 | |
| 8387 | case ADD_STARTING: { |
| 8388 | final AppWindowToken wtoken = (AppWindowToken)msg.obj; |
| 8389 | final StartingData sd = wtoken.startingData; |
| 8390 | |
| 8391 | if (sd == null) { |
| 8392 | // Animation has been canceled... do nothing. |
| 8393 | return; |
| 8394 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8395 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8396 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Add starting " |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8397 | + wtoken + ": pkg=" + sd.pkg); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8398 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8399 | View view = null; |
| 8400 | try { |
| 8401 | view = mPolicy.addStartingWindow( |
| 8402 | wtoken.token, sd.pkg, |
| 8403 | sd.theme, sd.nonLocalizedLabel, sd.labelRes, |
| 8404 | sd.icon); |
| 8405 | } catch (Exception e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8406 | Slog.w(TAG, "Exception when adding starting window", e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8407 | } |
| 8408 | |
| 8409 | if (view != null) { |
| 8410 | boolean abort = false; |
| 8411 | |
| 8412 | synchronized(mWindowMap) { |
| 8413 | if (wtoken.removed || wtoken.startingData == null) { |
| 8414 | // If the window was successfully added, then |
| 8415 | // we need to remove it. |
| 8416 | if (wtoken.startingWindow != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8417 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8418 | "Aborted starting " + wtoken |
| 8419 | + ": removed=" + wtoken.removed |
| 8420 | + " startingData=" + wtoken.startingData); |
| 8421 | wtoken.startingWindow = null; |
| 8422 | wtoken.startingData = null; |
| 8423 | abort = true; |
| 8424 | } |
| 8425 | } else { |
| 8426 | wtoken.startingView = view; |
| 8427 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8428 | if (DEBUG_STARTING_WINDOW && !abort) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8429 | "Added starting " + wtoken |
| 8430 | + ": startingWindow=" |
| 8431 | + wtoken.startingWindow + " startingView=" |
| 8432 | + wtoken.startingView); |
| 8433 | } |
| 8434 | |
| 8435 | if (abort) { |
| 8436 | try { |
| 8437 | mPolicy.removeStartingWindow(wtoken.token, view); |
| 8438 | } catch (Exception e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8439 | Slog.w(TAG, "Exception when removing starting window", e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8440 | } |
| 8441 | } |
| 8442 | } |
| 8443 | } break; |
| 8444 | |
| 8445 | case REMOVE_STARTING: { |
| 8446 | final AppWindowToken wtoken = (AppWindowToken)msg.obj; |
| 8447 | IBinder token = null; |
| 8448 | View view = null; |
| 8449 | synchronized (mWindowMap) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8450 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Remove starting " |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8451 | + wtoken + ": startingWindow=" |
| 8452 | + wtoken.startingWindow + " startingView=" |
| 8453 | + wtoken.startingView); |
| 8454 | if (wtoken.startingWindow != null) { |
| 8455 | view = wtoken.startingView; |
| 8456 | token = wtoken.token; |
| 8457 | wtoken.startingData = null; |
| 8458 | wtoken.startingView = null; |
| 8459 | wtoken.startingWindow = null; |
| 8460 | } |
| 8461 | } |
| 8462 | if (view != null) { |
| 8463 | try { |
| 8464 | mPolicy.removeStartingWindow(token, view); |
| 8465 | } catch (Exception e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8466 | Slog.w(TAG, "Exception when removing starting window", e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8467 | } |
| 8468 | } |
| 8469 | } break; |
| 8470 | |
| 8471 | case FINISHED_STARTING: { |
| 8472 | IBinder token = null; |
| 8473 | View view = null; |
| 8474 | while (true) { |
| 8475 | synchronized (mWindowMap) { |
| 8476 | final int N = mFinishedStarting.size(); |
| 8477 | if (N <= 0) { |
| 8478 | break; |
| 8479 | } |
| 8480 | AppWindowToken wtoken = mFinishedStarting.remove(N-1); |
| 8481 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8482 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8483 | "Finished starting " + wtoken |
| 8484 | + ": startingWindow=" + wtoken.startingWindow |
| 8485 | + " startingView=" + wtoken.startingView); |
| 8486 | |
| 8487 | if (wtoken.startingWindow == null) { |
| 8488 | continue; |
| 8489 | } |
| 8490 | |
| 8491 | view = wtoken.startingView; |
| 8492 | token = wtoken.token; |
| 8493 | wtoken.startingData = null; |
| 8494 | wtoken.startingView = null; |
| 8495 | wtoken.startingWindow = null; |
| 8496 | } |
| 8497 | |
| 8498 | try { |
| 8499 | mPolicy.removeStartingWindow(token, view); |
| 8500 | } catch (Exception e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8501 | Slog.w(TAG, "Exception when removing starting window", e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8502 | } |
| 8503 | } |
| 8504 | } break; |
| 8505 | |
| 8506 | case REPORT_APPLICATION_TOKEN_WINDOWS: { |
| 8507 | final AppWindowToken wtoken = (AppWindowToken)msg.obj; |
| 8508 | |
| 8509 | boolean nowVisible = msg.arg1 != 0; |
| 8510 | boolean nowGone = msg.arg2 != 0; |
| 8511 | |
| 8512 | try { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8513 | if (DEBUG_VISIBILITY) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8514 | TAG, "Reporting visible in " + wtoken |
| 8515 | + " visible=" + nowVisible |
| 8516 | + " gone=" + nowGone); |
| 8517 | if (nowVisible) { |
| 8518 | wtoken.appToken.windowsVisible(); |
| 8519 | } else { |
| 8520 | wtoken.appToken.windowsGone(); |
| 8521 | } |
| 8522 | } catch (RemoteException ex) { |
| 8523 | } |
| 8524 | } break; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8525 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8526 | case WINDOW_FREEZE_TIMEOUT: { |
| 8527 | synchronized (mWindowMap) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8528 | Slog.w(TAG, "Window freeze timeout expired."); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8529 | int i = mWindows.size(); |
| 8530 | while (i > 0) { |
| 8531 | i--; |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 8532 | WindowState w = mWindows.get(i); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8533 | if (w.mOrientationChanging) { |
| 8534 | w.mOrientationChanging = false; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8535 | Slog.w(TAG, "Force clearing orientation change: " + w); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8536 | } |
| 8537 | } |
| 8538 | performLayoutAndPlaceSurfacesLocked(); |
| 8539 | } |
| 8540 | break; |
| 8541 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8542 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8543 | case HOLD_SCREEN_CHANGED: { |
| 8544 | Session oldHold; |
| 8545 | Session newHold; |
| 8546 | synchronized (mWindowMap) { |
| 8547 | oldHold = mLastReportedHold; |
| 8548 | newHold = (Session)msg.obj; |
| 8549 | mLastReportedHold = newHold; |
| 8550 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8551 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8552 | if (oldHold != newHold) { |
| 8553 | try { |
| 8554 | if (oldHold != null) { |
| Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 8555 | mBatteryStats.noteStopWakelock(oldHold.mUid, -1, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8556 | "window", |
| 8557 | BatteryStats.WAKE_TYPE_WINDOW); |
| 8558 | } |
| 8559 | if (newHold != null) { |
| Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 8560 | mBatteryStats.noteStartWakelock(newHold.mUid, -1, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8561 | "window", |
| 8562 | BatteryStats.WAKE_TYPE_WINDOW); |
| 8563 | } |
| 8564 | } catch (RemoteException e) { |
| 8565 | } |
| 8566 | } |
| 8567 | break; |
| 8568 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8569 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8570 | case APP_TRANSITION_TIMEOUT: { |
| 8571 | synchronized (mWindowMap) { |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 8572 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8573 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8574 | "*** APP TRANSITION TIMEOUT"); |
| 8575 | mAppTransitionReady = true; |
| 8576 | mAppTransitionTimeout = true; |
| 8577 | performLayoutAndPlaceSurfacesLocked(); |
| 8578 | } |
| 8579 | } |
| 8580 | break; |
| 8581 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8582 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8583 | case PERSIST_ANIMATION_SCALE: { |
| 8584 | Settings.System.putFloat(mContext.getContentResolver(), |
| 8585 | Settings.System.WINDOW_ANIMATION_SCALE, mWindowAnimationScale); |
| 8586 | Settings.System.putFloat(mContext.getContentResolver(), |
| 8587 | Settings.System.TRANSITION_ANIMATION_SCALE, mTransitionAnimationScale); |
| 8588 | break; |
| 8589 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8590 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8591 | case FORCE_GC: { |
| 8592 | synchronized(mWindowMap) { |
| 8593 | if (mAnimationPending) { |
| 8594 | // If we are animating, don't do the gc now but |
| 8595 | // delay a bit so we don't interrupt the animation. |
| 8596 | mH.sendMessageDelayed(mH.obtainMessage(H.FORCE_GC), |
| 8597 | 2000); |
| 8598 | return; |
| 8599 | } |
| 8600 | // If we are currently rotating the display, it will |
| 8601 | // schedule a new message when done. |
| 8602 | if (mDisplayFrozen) { |
| 8603 | return; |
| 8604 | } |
| 8605 | mFreezeGcPending = 0; |
| 8606 | } |
| 8607 | Runtime.getRuntime().gc(); |
| 8608 | break; |
| 8609 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8610 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8611 | case ENABLE_SCREEN: { |
| 8612 | performEnableScreen(); |
| 8613 | break; |
| 8614 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8615 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8616 | case APP_FREEZE_TIMEOUT: { |
| 8617 | synchronized (mWindowMap) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8618 | Slog.w(TAG, "App freeze timeout expired."); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8619 | int i = mAppTokens.size(); |
| 8620 | while (i > 0) { |
| 8621 | i--; |
| 8622 | AppWindowToken tok = mAppTokens.get(i); |
| 8623 | if (tok.freezingScreen) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8624 | Slog.w(TAG, "Force clearing freeze: " + tok); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8625 | unsetAppFreezingScreenLocked(tok, true, true); |
| 8626 | } |
| 8627 | } |
| 8628 | } |
| 8629 | break; |
| 8630 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8631 | |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 8632 | case SEND_NEW_CONFIGURATION: { |
| 8633 | removeMessages(SEND_NEW_CONFIGURATION); |
| 8634 | sendNewConfiguration(); |
| The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 8635 | break; |
| 8636 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8637 | |
| Konstantin Lopyrev | 6e0f65f | 2010-07-14 14:55:33 -0700 | [diff] [blame] | 8638 | case REPORT_WINDOWS_CHANGE: { |
| Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 8639 | if (mWindowsChanged) { |
| 8640 | synchronized (mWindowMap) { |
| 8641 | mWindowsChanged = false; |
| 8642 | } |
| 8643 | notifyWindowsChanged(); |
| 8644 | } |
| 8645 | break; |
| 8646 | } |
| 8647 | |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 8648 | case DRAG_START_TIMEOUT: { |
| 8649 | IBinder win = (IBinder)msg.obj; |
| 8650 | if (DEBUG_DRAG) { |
| 8651 | Slog.w(TAG, "Timeout starting drag by win " + win); |
| 8652 | } |
| 8653 | synchronized (mWindowMap) { |
| 8654 | // !!! TODO: ANR the app that has failed to start the drag in time |
| 8655 | if (mDragState != null) { |
| 8656 | mDragState.reset(); |
| 8657 | mDragState = null; |
| 8658 | } |
| 8659 | } |
| 8660 | } |
| 8661 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8662 | } |
| 8663 | } |
| 8664 | } |
| 8665 | |
| 8666 | // ------------------------------------------------------------- |
| 8667 | // IWindowManager API |
| 8668 | // ------------------------------------------------------------- |
| 8669 | |
| 8670 | public IWindowSession openSession(IInputMethodClient client, |
| 8671 | IInputContext inputContext) { |
| 8672 | if (client == null) throw new IllegalArgumentException("null client"); |
| 8673 | if (inputContext == null) throw new IllegalArgumentException("null inputContext"); |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 8674 | Session session = new Session(client, inputContext); |
| 8675 | return session; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8676 | } |
| 8677 | |
| 8678 | public boolean inputMethodClientHasFocus(IInputMethodClient client) { |
| 8679 | synchronized (mWindowMap) { |
| 8680 | // The focus for the client is the window immediately below |
| 8681 | // where we would place the input method window. |
| 8682 | int idx = findDesiredInputMethodWindowIndexLocked(false); |
| 8683 | WindowState imFocus; |
| 8684 | if (idx > 0) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 8685 | imFocus = mWindows.get(idx-1); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8686 | if (imFocus != null) { |
| 8687 | if (imFocus.mSession.mClient != null && |
| 8688 | imFocus.mSession.mClient.asBinder() == client.asBinder()) { |
| 8689 | return true; |
| 8690 | } |
| 8691 | } |
| 8692 | } |
| 8693 | } |
| 8694 | return false; |
| 8695 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8696 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8697 | // ------------------------------------------------------------- |
| 8698 | // Internals |
| 8699 | // ------------------------------------------------------------- |
| 8700 | |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 8701 | final WindowState windowForClientLocked(Session session, IWindow client, |
| 8702 | boolean throwOnError) { |
| 8703 | return windowForClientLocked(session, client.asBinder(), throwOnError); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8704 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8705 | |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 8706 | final WindowState windowForClientLocked(Session session, IBinder client, |
| 8707 | boolean throwOnError) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8708 | WindowState win = mWindowMap.get(client); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8709 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8710 | TAG, "Looking up client " + client + ": " + win); |
| 8711 | if (win == null) { |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 8712 | RuntimeException ex = new IllegalArgumentException( |
| 8713 | "Requested window " + client + " does not exist"); |
| 8714 | if (throwOnError) { |
| 8715 | throw ex; |
| 8716 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8717 | Slog.w(TAG, "Failed looking up window", ex); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8718 | return null; |
| 8719 | } |
| 8720 | if (session != null && win.mSession != session) { |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 8721 | RuntimeException ex = new IllegalArgumentException( |
| 8722 | "Requested window " + client + " is in session " + |
| 8723 | win.mSession + ", not " + session); |
| 8724 | if (throwOnError) { |
| 8725 | throw ex; |
| 8726 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8727 | Slog.w(TAG, "Failed looking up window", ex); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8728 | return null; |
| 8729 | } |
| 8730 | |
| 8731 | return win; |
| 8732 | } |
| 8733 | |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8734 | final void rebuildAppWindowListLocked() { |
| 8735 | int NW = mWindows.size(); |
| 8736 | int i; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8737 | int lastWallpaper = -1; |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 8738 | int numRemoved = 0; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8739 | |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8740 | // First remove all existing app windows. |
| 8741 | i=0; |
| 8742 | while (i < NW) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 8743 | WindowState w = mWindows.get(i); |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8744 | if (w.mAppToken != null) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 8745 | WindowState win = mWindows.remove(i); |
| Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 8746 | mWindowsChanged = true; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8747 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, |
| Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 8748 | "Rebuild removing window: " + win); |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8749 | NW--; |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 8750 | numRemoved++; |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8751 | continue; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8752 | } else if (w.mAttrs.type == WindowManager.LayoutParams.TYPE_WALLPAPER |
| 8753 | && lastWallpaper == i-1) { |
| 8754 | lastWallpaper = i; |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8755 | } |
| 8756 | i++; |
| 8757 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8758 | |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8759 | // The wallpaper window(s) typically live at the bottom of the stack, |
| 8760 | // so skip them before adding app tokens. |
| 8761 | lastWallpaper++; |
| 8762 | i = lastWallpaper; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8763 | |
| Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 8764 | // First add all of the exiting app tokens... these are no longer |
| 8765 | // in the main app list, but still have windows shown. We put them |
| 8766 | // in the back because now that the animation is over we no longer |
| 8767 | // will care about them. |
| 8768 | int NT = mExitingAppTokens.size(); |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8769 | for (int j=0; j<NT; j++) { |
| Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 8770 | i = reAddAppWindowsLocked(i, mExitingAppTokens.get(j)); |
| 8771 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8772 | |
| Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 8773 | // And add in the still active app tokens in Z order. |
| 8774 | NT = mAppTokens.size(); |
| 8775 | for (int j=0; j<NT; j++) { |
| 8776 | i = reAddAppWindowsLocked(i, mAppTokens.get(j)); |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8777 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8778 | |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8779 | i -= lastWallpaper; |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 8780 | if (i != numRemoved) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8781 | Slog.w(TAG, "Rebuild removed " + numRemoved |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 8782 | + " windows but added " + i); |
| 8783 | } |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8784 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8785 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8786 | private final void assignLayersLocked() { |
| 8787 | int N = mWindows.size(); |
| 8788 | int curBaseLayer = 0; |
| 8789 | int curLayer = 0; |
| 8790 | int i; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8791 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8792 | for (i=0; i<N; i++) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 8793 | WindowState w = mWindows.get(i); |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 8794 | if (w.mBaseLayer == curBaseLayer || w.mIsImWindow |
| 8795 | || (i > 0 && w.mIsWallpaper)) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8796 | curLayer += WINDOW_LAYER_MULTIPLIER; |
| 8797 | w.mLayer = curLayer; |
| 8798 | } else { |
| 8799 | curBaseLayer = curLayer = w.mBaseLayer; |
| 8800 | w.mLayer = curLayer; |
| 8801 | } |
| 8802 | if (w.mTargetAppToken != null) { |
| 8803 | w.mAnimLayer = w.mLayer + w.mTargetAppToken.animLayerAdjustment; |
| 8804 | } else if (w.mAppToken != null) { |
| 8805 | w.mAnimLayer = w.mLayer + w.mAppToken.animLayerAdjustment; |
| 8806 | } else { |
| 8807 | w.mAnimLayer = w.mLayer; |
| 8808 | } |
| 8809 | if (w.mIsImWindow) { |
| 8810 | w.mAnimLayer += mInputMethodAnimLayerAdjustment; |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 8811 | } else if (w.mIsWallpaper) { |
| 8812 | w.mAnimLayer += mWallpaperAnimLayerAdjustment; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8813 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8814 | if (DEBUG_LAYERS) Slog.v(TAG, "Assign layer " + w + ": " |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8815 | + w.mAnimLayer); |
| 8816 | //System.out.println( |
| 8817 | // "Assigned layer " + curLayer + " to " + w.mClient.asBinder()); |
| 8818 | } |
| 8819 | } |
| 8820 | |
| 8821 | private boolean mInLayout = false; |
| 8822 | private final void performLayoutAndPlaceSurfacesLocked() { |
| 8823 | if (mInLayout) { |
| Dave Bort | cfe6524 | 2009-04-09 14:51:04 -0700 | [diff] [blame] | 8824 | if (DEBUG) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8825 | throw new RuntimeException("Recursive call!"); |
| 8826 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8827 | Slog.w(TAG, "performLayoutAndPlaceSurfacesLocked called while in layout"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8828 | return; |
| 8829 | } |
| 8830 | |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 8831 | if (mWaitingForConfig) { |
| 8832 | // Our configuration has changed (most likely rotation), but we |
| 8833 | // don't yet have the complete configuration to report to |
| 8834 | // applications. Don't do any window layout until we have it. |
| 8835 | return; |
| 8836 | } |
| 8837 | |
| Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 8838 | if (mDisplay == null) { |
| 8839 | // Not yet initialized, nothing to do. |
| 8840 | return; |
| 8841 | } |
| 8842 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8843 | boolean recoveringMemory = false; |
| 8844 | if (mForceRemoves != null) { |
| 8845 | recoveringMemory = true; |
| 8846 | // Wait a little it for things to settle down, and off we go. |
| 8847 | for (int i=0; i<mForceRemoves.size(); i++) { |
| 8848 | WindowState ws = mForceRemoves.get(i); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8849 | Slog.i(TAG, "Force removing: " + ws); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8850 | removeWindowInnerLocked(ws.mSession, ws); |
| 8851 | } |
| 8852 | mForceRemoves = null; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8853 | 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] | 8854 | Object tmp = new Object(); |
| 8855 | synchronized (tmp) { |
| 8856 | try { |
| 8857 | tmp.wait(250); |
| 8858 | } catch (InterruptedException e) { |
| 8859 | } |
| 8860 | } |
| 8861 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8862 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8863 | mInLayout = true; |
| 8864 | try { |
| 8865 | performLayoutAndPlaceSurfacesLockedInner(recoveringMemory); |
| 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 | int i = mPendingRemove.size()-1; |
| 8868 | if (i >= 0) { |
| 8869 | while (i >= 0) { |
| 8870 | WindowState w = mPendingRemove.get(i); |
| 8871 | removeWindowInnerLocked(w.mSession, w); |
| 8872 | i--; |
| 8873 | } |
| 8874 | mPendingRemove.clear(); |
| 8875 | |
| 8876 | mInLayout = false; |
| 8877 | assignLayersLocked(); |
| 8878 | mLayoutNeeded = true; |
| 8879 | performLayoutAndPlaceSurfacesLocked(); |
| 8880 | |
| 8881 | } else { |
| 8882 | mInLayout = false; |
| 8883 | if (mLayoutNeeded) { |
| 8884 | requestAnimationLocked(0); |
| 8885 | } |
| 8886 | } |
| Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 8887 | if (mWindowsChanged && !mWindowChangeListeners.isEmpty()) { |
| Konstantin Lopyrev | 6e0f65f | 2010-07-14 14:55:33 -0700 | [diff] [blame] | 8888 | mH.removeMessages(H.REPORT_WINDOWS_CHANGE); |
| 8889 | mH.sendMessage(mH.obtainMessage(H.REPORT_WINDOWS_CHANGE)); |
| Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 8890 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8891 | } catch (RuntimeException e) { |
| 8892 | mInLayout = false; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8893 | 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] | 8894 | } |
| 8895 | } |
| 8896 | |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 8897 | private final int performLayoutLockedInner() { |
| 8898 | if (!mLayoutNeeded) { |
| 8899 | return 0; |
| 8900 | } |
| 8901 | |
| 8902 | mLayoutNeeded = false; |
| 8903 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8904 | final int dw = mDisplay.getWidth(); |
| 8905 | final int dh = mDisplay.getHeight(); |
| 8906 | |
| 8907 | final int N = mWindows.size(); |
| 8908 | int i; |
| 8909 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8910 | if (DEBUG_LAYOUT) Slog.v(TAG, "performLayout: needed=" |
| Dianne Hackborn | 9b52a21 | 2009-12-11 14:51:35 -0800 | [diff] [blame] | 8911 | + mLayoutNeeded + " dw=" + dw + " dh=" + dh); |
| 8912 | |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 8913 | mPolicy.beginLayoutLw(dw, dh); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8914 | |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 8915 | int seq = mLayoutSeq+1; |
| 8916 | if (seq < 0) seq = 0; |
| 8917 | mLayoutSeq = seq; |
| 8918 | |
| 8919 | // First perform layout of any root windows (not attached |
| 8920 | // to another window). |
| 8921 | int topAttached = -1; |
| 8922 | for (i = N-1; i >= 0; i--) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 8923 | WindowState win = mWindows.get(i); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8924 | |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 8925 | // Don't do layout of a window if it is not visible, or |
| 8926 | // soon won't be visible, to avoid wasting time and funky |
| 8927 | // changes while a window is animating away. |
| 8928 | final AppWindowToken atoken = win.mAppToken; |
| 8929 | final boolean gone = win.mViewVisibility == View.GONE |
| 8930 | || !win.mRelayoutCalled |
| 8931 | || win.mRootToken.hidden |
| 8932 | || (atoken != null && atoken.hiddenRequested) |
| 8933 | || win.mAttachedHidden |
| 8934 | || win.mExiting || win.mDestroying; |
| 8935 | |
| 8936 | if (!win.mLayoutAttached) { |
| 8937 | if (DEBUG_LAYOUT) Slog.v(TAG, "First pass " + win |
| 8938 | + ": gone=" + gone + " mHaveFrame=" + win.mHaveFrame |
| 8939 | + " mLayoutAttached=" + win.mLayoutAttached); |
| 8940 | if (DEBUG_LAYOUT && gone) Slog.v(TAG, " (mViewVisibility=" |
| 8941 | + win.mViewVisibility + " mRelayoutCalled=" |
| 8942 | + win.mRelayoutCalled + " hidden=" |
| 8943 | + win.mRootToken.hidden + " hiddenRequested=" |
| 8944 | + (atoken != null && atoken.hiddenRequested) |
| 8945 | + " mAttachedHidden=" + win.mAttachedHidden); |
| 8946 | } |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 8947 | |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 8948 | // If this view is GONE, then skip it -- keep the current |
| 8949 | // frame, and let the caller know so they can ignore it |
| 8950 | // if they want. (We do the normal layout for INVISIBLE |
| 8951 | // windows, since that means "perform layout as normal, |
| 8952 | // just don't display"). |
| 8953 | if (!gone || !win.mHaveFrame) { |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 8954 | if (!win.mLayoutAttached) { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 8955 | mPolicy.layoutWindowLw(win, win.mAttrs, null); |
| 8956 | win.mLayoutSeq = seq; |
| 8957 | if (DEBUG_LAYOUT) Slog.v(TAG, "-> mFrame=" |
| 8958 | + win.mFrame + " mContainingFrame=" |
| 8959 | + win.mContainingFrame + " mDisplayFrame=" |
| 8960 | + win.mDisplayFrame); |
| 8961 | } else { |
| 8962 | if (topAttached < 0) topAttached = i; |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 8963 | } |
| Dianne Hackborn | 958b9ad | 2009-03-31 18:00:36 -0700 | [diff] [blame] | 8964 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8965 | } |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 8966 | |
| 8967 | // Now perform layout of attached windows, which usually |
| 8968 | // depend on the position of the window they are attached to. |
| 8969 | // XXX does not deal with windows that are attached to windows |
| 8970 | // that are themselves attached. |
| 8971 | for (i = topAttached; i >= 0; i--) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 8972 | WindowState win = mWindows.get(i); |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 8973 | |
| 8974 | // If this view is GONE, then skip it -- keep the current |
| 8975 | // frame, and let the caller know so they can ignore it |
| 8976 | // if they want. (We do the normal layout for INVISIBLE |
| 8977 | // windows, since that means "perform layout as normal, |
| 8978 | // just don't display"). |
| 8979 | if (win.mLayoutAttached) { |
| 8980 | if (DEBUG_LAYOUT) Slog.v(TAG, "Second pass " + win |
| 8981 | + " mHaveFrame=" + win.mHaveFrame |
| 8982 | + " mViewVisibility=" + win.mViewVisibility |
| 8983 | + " mRelayoutCalled=" + win.mRelayoutCalled); |
| 8984 | if ((win.mViewVisibility != View.GONE && win.mRelayoutCalled) |
| 8985 | || !win.mHaveFrame) { |
| 8986 | mPolicy.layoutWindowLw(win, win.mAttrs, win.mAttachedWindow); |
| 8987 | win.mLayoutSeq = seq; |
| 8988 | if (DEBUG_LAYOUT) Slog.v(TAG, "-> mFrame=" |
| 8989 | + win.mFrame + " mContainingFrame=" |
| 8990 | + win.mContainingFrame + " mDisplayFrame=" |
| 8991 | + win.mDisplayFrame); |
| 8992 | } |
| 8993 | } |
| 8994 | } |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 8995 | |
| 8996 | // Window frames may have changed. Tell the input dispatcher about it. |
| Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 8997 | mInputMonitor.updateInputWindowsLw(); |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 8998 | |
| 8999 | return mPolicy.finishLayoutLw(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9000 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9001 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9002 | private final void performLayoutAndPlaceSurfacesLockedInner( |
| 9003 | boolean recoveringMemory) { |
| Joe Onorato | 34bcebc | 2010-07-07 18:05:01 -0400 | [diff] [blame] | 9004 | if (mDisplay == null) { |
| 9005 | Slog.i(TAG, "skipping performLayoutAndPlaceSurfacesLockedInner with no mDisplay"); |
| 9006 | return; |
| 9007 | } |
| 9008 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9009 | final long currentTime = SystemClock.uptimeMillis(); |
| 9010 | final int dw = mDisplay.getWidth(); |
| 9011 | final int dh = mDisplay.getHeight(); |
| 9012 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9013 | int i; |
| 9014 | |
| Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 9015 | if (mFocusMayChange) { |
| 9016 | mFocusMayChange = false; |
| 9017 | updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES); |
| 9018 | } |
| 9019 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9020 | // Initialize state of exiting tokens. |
| 9021 | for (i=mExitingTokens.size()-1; i>=0; i--) { |
| 9022 | mExitingTokens.get(i).hasVisible = false; |
| 9023 | } |
| 9024 | |
| 9025 | // Initialize state of exiting applications. |
| 9026 | for (i=mExitingAppTokens.size()-1; i>=0; i--) { |
| 9027 | mExitingAppTokens.get(i).hasVisible = false; |
| 9028 | } |
| 9029 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9030 | boolean orientationChangeComplete = true; |
| 9031 | Session holdScreen = null; |
| 9032 | float screenBrightness = -1; |
| Mike Lockwood | fb73f79 | 2009-11-20 11:31:18 -0500 | [diff] [blame] | 9033 | float buttonBrightness = -1; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9034 | boolean focusDisplayed = false; |
| 9035 | boolean animating = false; |
| Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 9036 | boolean createWatermark = false; |
| 9037 | |
| 9038 | if (mFxSession == null) { |
| 9039 | mFxSession = new SurfaceSession(); |
| 9040 | createWatermark = true; |
| 9041 | } |
| 9042 | |
| 9043 | if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9044 | |
| 9045 | Surface.openTransaction(); |
| Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 9046 | |
| 9047 | if (createWatermark) { |
| 9048 | createWatermark(); |
| 9049 | } |
| 9050 | if (mWatermark != null) { |
| 9051 | mWatermark.positionSurface(dw, dh); |
| 9052 | } |
| 9053 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9054 | try { |
| Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 9055 | boolean wallpaperForceHidingChanged = false; |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9056 | int repeats = 0; |
| 9057 | int changes = 0; |
| 9058 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9059 | do { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9060 | repeats++; |
| 9061 | if (repeats > 6) { |
| 9062 | Slog.w(TAG, "Animation repeat aborted after too many iterations"); |
| 9063 | mLayoutNeeded = false; |
| 9064 | break; |
| 9065 | } |
| 9066 | |
| 9067 | if ((changes&(WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER |
| 9068 | | WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG |
| 9069 | | WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT)) != 0) { |
| 9070 | if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER) != 0) { |
| 9071 | if ((adjustWallpaperWindowsLocked()&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) { |
| 9072 | assignLayersLocked(); |
| 9073 | mLayoutNeeded = true; |
| 9074 | } |
| 9075 | } |
| 9076 | if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG) != 0) { |
| 9077 | if (DEBUG_LAYOUT) Slog.v(TAG, "Computing new config from layout"); |
| 9078 | if (updateOrientationFromAppTokensLocked()) { |
| 9079 | mLayoutNeeded = true; |
| 9080 | mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION); |
| 9081 | } |
| 9082 | } |
| 9083 | if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT) != 0) { |
| 9084 | mLayoutNeeded = true; |
| 9085 | } |
| 9086 | } |
| 9087 | |
| 9088 | // FIRST LOOP: Perform a layout, if needed. |
| 9089 | if (repeats < 4) { |
| 9090 | changes = performLayoutLockedInner(); |
| 9091 | if (changes != 0) { |
| 9092 | continue; |
| 9093 | } |
| 9094 | } else { |
| 9095 | Slog.w(TAG, "Layout repeat skipped after too many iterations"); |
| 9096 | changes = 0; |
| 9097 | } |
| 9098 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9099 | final int transactionSequence = ++mTransactionSequence; |
| 9100 | |
| 9101 | // Update animations of all applications, including those |
| 9102 | // associated with exiting/removed apps |
| 9103 | boolean tokensAnimating = false; |
| 9104 | final int NAT = mAppTokens.size(); |
| 9105 | for (i=0; i<NAT; i++) { |
| 9106 | if (mAppTokens.get(i).stepAnimationLocked(currentTime, dw, dh)) { |
| 9107 | tokensAnimating = true; |
| 9108 | } |
| 9109 | } |
| 9110 | final int NEAT = mExitingAppTokens.size(); |
| 9111 | for (i=0; i<NEAT; i++) { |
| 9112 | if (mExitingAppTokens.get(i).stepAnimationLocked(currentTime, dw, dh)) { |
| 9113 | tokensAnimating = true; |
| 9114 | } |
| 9115 | } |
| 9116 | |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9117 | // SECOND LOOP: Execute animations and update visibility of windows. |
| 9118 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9119 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "*** ANIM STEP: seq=" |
| Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 9120 | + transactionSequence + " tokensAnimating=" |
| 9121 | + tokensAnimating); |
| 9122 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9123 | animating = tokensAnimating; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9124 | |
| 9125 | boolean tokenMayBeDrawn = false; |
| Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 9126 | boolean wallpaperMayChange = false; |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9127 | boolean forceHiding = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9128 | |
| 9129 | mPolicy.beginAnimationLw(dw, dh); |
| 9130 | |
| Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 9131 | final int N = mWindows.size(); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9132 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9133 | for (i=N-1; i>=0; i--) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 9134 | WindowState w = mWindows.get(i); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9135 | |
| 9136 | final WindowManager.LayoutParams attrs = w.mAttrs; |
| 9137 | |
| 9138 | if (w.mSurface != null) { |
| 9139 | // Execute animation. |
| Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 9140 | if (w.commitFinishDrawingLocked(currentTime)) { |
| 9141 | if ((w.mAttrs.flags |
| 9142 | & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER) != 0) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9143 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 9144 | "First draw done in potential wallpaper target " + w); |
| Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 9145 | wallpaperMayChange = true; |
| 9146 | } |
| 9147 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9148 | |
| Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 9149 | boolean wasAnimating = w.mAnimating; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9150 | if (w.stepAnimationLocked(currentTime, dw, dh)) { |
| 9151 | animating = true; |
| 9152 | //w.dump(" "); |
| 9153 | } |
| Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 9154 | if (wasAnimating && !w.mAnimating && mWallpaperTarget == w) { |
| 9155 | wallpaperMayChange = true; |
| 9156 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9157 | |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9158 | if (mPolicy.doesForceHide(w, attrs)) { |
| 9159 | if (!wasAnimating && animating) { |
| Dianne Hackborn | 20cb56e | 2010-03-04 00:58:29 -0800 | [diff] [blame] | 9160 | if (DEBUG_VISIBILITY) Slog.v(TAG, |
| 9161 | "Animation done that could impact force hide: " |
| 9162 | + w); |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9163 | wallpaperForceHidingChanged = true; |
| Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 9164 | mFocusMayChange = true; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9165 | } else if (w.isReadyForDisplay() && w.mAnimation == null) { |
| 9166 | forceHiding = true; |
| 9167 | } |
| 9168 | } else if (mPolicy.canBeForceHidden(w, attrs)) { |
| 9169 | boolean changed; |
| 9170 | if (forceHiding) { |
| 9171 | changed = w.hideLw(false, false); |
| Dianne Hackborn | 20cb56e | 2010-03-04 00:58:29 -0800 | [diff] [blame] | 9172 | if (DEBUG_VISIBILITY && changed) Slog.v(TAG, |
| 9173 | "Now policy hidden: " + w); |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9174 | } else { |
| 9175 | changed = w.showLw(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 shown: " + w); |
| 9178 | if (changed) { |
| 9179 | if (wallpaperForceHidingChanged |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9180 | && w.isVisibleNow() /*w.isReadyForDisplay()*/) { |
| Dianne Hackborn | 20cb56e | 2010-03-04 00:58:29 -0800 | [diff] [blame] | 9181 | // Assume we will need to animate. If |
| 9182 | // we don't (because the wallpaper will |
| 9183 | // stay with the lock screen), then we will |
| 9184 | // clean up later. |
| 9185 | Animation a = mPolicy.createForceHideEnterAnimation(); |
| 9186 | if (a != null) { |
| 9187 | w.setAnimation(a); |
| 9188 | } |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9189 | } |
| Dianne Hackborn | 20cb56e | 2010-03-04 00:58:29 -0800 | [diff] [blame] | 9190 | if (mCurrentFocus == null || |
| 9191 | mCurrentFocus.mLayer < w.mLayer) { |
| 9192 | // We are showing on to of the current |
| 9193 | // focus, so re-evaluate focus to make |
| 9194 | // sure it is correct. |
| 9195 | mFocusMayChange = true; |
| 9196 | } |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9197 | } |
| 9198 | } |
| 9199 | if (changed && (attrs.flags |
| 9200 | & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER) != 0) { |
| 9201 | wallpaperMayChange = true; |
| 9202 | } |
| 9203 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9204 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9205 | mPolicy.animatingWindowLw(w, attrs); |
| 9206 | } |
| 9207 | |
| 9208 | final AppWindowToken atoken = w.mAppToken; |
| 9209 | if (atoken != null && (!atoken.allDrawn || atoken.freezingScreen)) { |
| 9210 | if (atoken.lastTransactionSequence != transactionSequence) { |
| 9211 | atoken.lastTransactionSequence = transactionSequence; |
| 9212 | atoken.numInterestingWindows = atoken.numDrawnWindows = 0; |
| 9213 | atoken.startingDisplayed = false; |
| 9214 | } |
| 9215 | if ((w.isOnScreen() || w.mAttrs.type |
| 9216 | == WindowManager.LayoutParams.TYPE_BASE_APPLICATION) |
| 9217 | && !w.mExiting && !w.mDestroying) { |
| 9218 | if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9219 | Slog.v(TAG, "Eval win " + w + ": isDrawn=" |
| Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 9220 | + w.isDrawnLw() |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9221 | + ", isAnimating=" + w.isAnimating()); |
| Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 9222 | if (!w.isDrawnLw()) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9223 | Slog.v(TAG, "Not displayed: s=" + w.mSurface |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9224 | + " pv=" + w.mPolicyVisibility |
| 9225 | + " dp=" + w.mDrawPending |
| 9226 | + " cdp=" + w.mCommitDrawPending |
| 9227 | + " ah=" + w.mAttachedHidden |
| 9228 | + " th=" + atoken.hiddenRequested |
| 9229 | + " a=" + w.mAnimating); |
| 9230 | } |
| 9231 | } |
| 9232 | if (w != atoken.startingWindow) { |
| 9233 | if (!atoken.freezingScreen || !w.mAppFreezing) { |
| 9234 | atoken.numInterestingWindows++; |
| Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 9235 | if (w.isDrawnLw()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9236 | atoken.numDrawnWindows++; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9237 | if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9238 | "tokenMayBeDrawn: " + atoken |
| 9239 | + " freezingScreen=" + atoken.freezingScreen |
| 9240 | + " mAppFreezing=" + w.mAppFreezing); |
| 9241 | tokenMayBeDrawn = true; |
| 9242 | } |
| 9243 | } |
| Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 9244 | } else if (w.isDrawnLw()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9245 | atoken.startingDisplayed = true; |
| 9246 | } |
| 9247 | } |
| 9248 | } else if (w.mReadyToShow) { |
| 9249 | w.performShowLocked(); |
| 9250 | } |
| 9251 | } |
| 9252 | |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9253 | changes |= mPolicy.finishAnimationLw(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9254 | |
| 9255 | if (tokenMayBeDrawn) { |
| 9256 | // See if any windows have been drawn, so they (and others |
| 9257 | // associated with them) can now be shown. |
| 9258 | final int NT = mTokenList.size(); |
| 9259 | for (i=0; i<NT; i++) { |
| 9260 | AppWindowToken wtoken = mTokenList.get(i).appWindowToken; |
| 9261 | if (wtoken == null) { |
| 9262 | continue; |
| 9263 | } |
| 9264 | if (wtoken.freezingScreen) { |
| 9265 | int numInteresting = wtoken.numInterestingWindows; |
| 9266 | if (numInteresting > 0 && wtoken.numDrawnWindows >= numInteresting) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9267 | if (DEBUG_VISIBILITY) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9268 | "allDrawn: " + wtoken |
| 9269 | + " interesting=" + numInteresting |
| 9270 | + " drawn=" + wtoken.numDrawnWindows); |
| 9271 | wtoken.showAllWindowsLocked(); |
| 9272 | unsetAppFreezingScreenLocked(wtoken, false, true); |
| 9273 | orientationChangeComplete = true; |
| 9274 | } |
| 9275 | } else if (!wtoken.allDrawn) { |
| 9276 | int numInteresting = wtoken.numInterestingWindows; |
| 9277 | if (numInteresting > 0 && wtoken.numDrawnWindows >= numInteresting) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9278 | if (DEBUG_VISIBILITY) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9279 | "allDrawn: " + wtoken |
| 9280 | + " interesting=" + numInteresting |
| 9281 | + " drawn=" + wtoken.numDrawnWindows); |
| 9282 | wtoken.allDrawn = true; |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9283 | changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9284 | |
| 9285 | // We can now show all of the drawn windows! |
| 9286 | if (!mOpeningApps.contains(wtoken)) { |
| 9287 | wtoken.showAllWindowsLocked(); |
| 9288 | } |
| 9289 | } |
| 9290 | } |
| 9291 | } |
| 9292 | } |
| 9293 | |
| 9294 | // If we are ready to perform an app transition, check through |
| 9295 | // all of the app tokens to be shown and see if they are ready |
| 9296 | // to go. |
| 9297 | if (mAppTransitionReady) { |
| 9298 | int NN = mOpeningApps.size(); |
| 9299 | boolean goodToGo = true; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9300 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9301 | "Checking " + NN + " opening apps (frozen=" |
| 9302 | + mDisplayFrozen + " timeout=" |
| 9303 | + mAppTransitionTimeout + ")..."); |
| 9304 | if (!mDisplayFrozen && !mAppTransitionTimeout) { |
| 9305 | // If the display isn't frozen, wait to do anything until |
| 9306 | // all of the apps are ready. Otherwise just go because |
| 9307 | // we'll unfreeze the display when everyone is ready. |
| 9308 | for (i=0; i<NN && goodToGo; i++) { |
| 9309 | AppWindowToken wtoken = mOpeningApps.get(i); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9310 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9311 | "Check opening app" + wtoken + ": allDrawn=" |
| 9312 | + wtoken.allDrawn + " startingDisplayed=" |
| 9313 | + wtoken.startingDisplayed); |
| 9314 | if (!wtoken.allDrawn && !wtoken.startingDisplayed |
| 9315 | && !wtoken.startingMoved) { |
| 9316 | goodToGo = false; |
| 9317 | } |
| 9318 | } |
| 9319 | } |
| 9320 | if (goodToGo) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9321 | 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] | 9322 | int transit = mNextAppTransition; |
| 9323 | if (mSkipAppTransitionAnimation) { |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 9324 | transit = WindowManagerPolicy.TRANSIT_UNSET; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9325 | } |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 9326 | mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9327 | mAppTransitionReady = false; |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9328 | mAppTransitionRunning = true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9329 | mAppTransitionTimeout = false; |
| 9330 | mStartingIconInTransition = false; |
| 9331 | mSkipAppTransitionAnimation = false; |
| 9332 | |
| 9333 | mH.removeMessages(H.APP_TRANSITION_TIMEOUT); |
| 9334 | |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9335 | // If there are applications waiting to come to the |
| 9336 | // top of the stack, now is the time to move their windows. |
| 9337 | // (Note that we don't do apps going to the bottom |
| 9338 | // here -- we want to keep their windows in the old |
| 9339 | // Z-order until the animation completes.) |
| 9340 | if (mToTopApps.size() > 0) { |
| 9341 | NN = mAppTokens.size(); |
| 9342 | for (i=0; i<NN; i++) { |
| 9343 | AppWindowToken wtoken = mAppTokens.get(i); |
| 9344 | if (wtoken.sendingToTop) { |
| 9345 | wtoken.sendingToTop = false; |
| 9346 | moveAppWindowsLocked(wtoken, NN, false); |
| 9347 | } |
| 9348 | } |
| 9349 | mToTopApps.clear(); |
| 9350 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9351 | |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 9352 | WindowState oldWallpaper = mWallpaperTarget; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9353 | |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 9354 | adjustWallpaperWindowsLocked(); |
| Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 9355 | wallpaperMayChange = false; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9356 | |
| Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 9357 | // The top-most window will supply the layout params, |
| 9358 | // and we will determine it below. |
| 9359 | LayoutParams animLp = null; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9360 | AppWindowToken animToken = null; |
| Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 9361 | int bestAnimLayer = -1; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9362 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9363 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 9364 | "New wallpaper target=" + mWallpaperTarget |
| 9365 | + ", lower target=" + mLowerWallpaperTarget |
| 9366 | + ", upper target=" + mUpperWallpaperTarget); |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 9367 | int foundWallpapers = 0; |
| Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 9368 | // Do a first pass through the tokens for two |
| 9369 | // things: |
| 9370 | // (1) Determine if both the closing and opening |
| 9371 | // app token sets are wallpaper targets, in which |
| 9372 | // case special animations are needed |
| 9373 | // (since the wallpaper needs to stay static |
| 9374 | // behind them). |
| 9375 | // (2) Find the layout params of the top-most |
| 9376 | // application window in the tokens, which is |
| 9377 | // what will control the animation theme. |
| 9378 | final int NC = mClosingApps.size(); |
| 9379 | NN = NC + mOpeningApps.size(); |
| 9380 | for (i=0; i<NN; i++) { |
| 9381 | AppWindowToken wtoken; |
| 9382 | int mode; |
| 9383 | if (i < NC) { |
| 9384 | wtoken = mClosingApps.get(i); |
| 9385 | mode = 1; |
| 9386 | } else { |
| 9387 | wtoken = mOpeningApps.get(i-NC); |
| 9388 | mode = 2; |
| 9389 | } |
| 9390 | if (mLowerWallpaperTarget != null) { |
| 9391 | if (mLowerWallpaperTarget.mAppToken == wtoken |
| 9392 | || mUpperWallpaperTarget.mAppToken == wtoken) { |
| 9393 | foundWallpapers |= mode; |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 9394 | } |
| 9395 | } |
| Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 9396 | if (wtoken.appFullscreen) { |
| 9397 | WindowState ws = wtoken.findMainWindow(); |
| 9398 | if (ws != null) { |
| 9399 | // If this is a compatibility mode |
| 9400 | // window, we will always use its anim. |
| 9401 | if ((ws.mAttrs.flags&FLAG_COMPATIBLE_WINDOW) != 0) { |
| 9402 | animLp = ws.mAttrs; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9403 | animToken = ws.mAppToken; |
| Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 9404 | bestAnimLayer = Integer.MAX_VALUE; |
| 9405 | } else if (ws.mLayer > bestAnimLayer) { |
| 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 = ws.mLayer; |
| 9409 | } |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 9410 | } |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 9411 | } |
| 9412 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9413 | |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 9414 | if (foundWallpapers == 3) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9415 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 9416 | "Wallpaper animation!"); |
| 9417 | switch (transit) { |
| 9418 | case WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN: |
| 9419 | case WindowManagerPolicy.TRANSIT_TASK_OPEN: |
| 9420 | case WindowManagerPolicy.TRANSIT_TASK_TO_FRONT: |
| 9421 | transit = WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_OPEN; |
| 9422 | break; |
| 9423 | case WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE: |
| 9424 | case WindowManagerPolicy.TRANSIT_TASK_CLOSE: |
| 9425 | case WindowManagerPolicy.TRANSIT_TASK_TO_BACK: |
| 9426 | transit = WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_CLOSE; |
| 9427 | break; |
| 9428 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9429 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 9430 | "New transit: " + transit); |
| 9431 | } else if (oldWallpaper != null) { |
| 9432 | // We are transitioning from an activity with |
| 9433 | // a wallpaper to one without. |
| 9434 | transit = WindowManagerPolicy.TRANSIT_WALLPAPER_CLOSE; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9435 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 9436 | "New transit away from wallpaper: " + transit); |
| 9437 | } else if (mWallpaperTarget != null) { |
| 9438 | // We are transitioning from an activity without |
| 9439 | // a wallpaper to now showing the wallpaper |
| 9440 | transit = WindowManagerPolicy.TRANSIT_WALLPAPER_OPEN; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9441 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 9442 | "New transit into wallpaper: " + transit); |
| 9443 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9444 | |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9445 | if ((transit&WindowManagerPolicy.TRANSIT_ENTER_MASK) != 0) { |
| 9446 | mLastEnterAnimToken = animToken; |
| 9447 | mLastEnterAnimParams = animLp; |
| 9448 | } else if (mLastEnterAnimParams != null) { |
| 9449 | animLp = mLastEnterAnimParams; |
| 9450 | mLastEnterAnimToken = null; |
| 9451 | mLastEnterAnimParams = null; |
| 9452 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9453 | |
| Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 9454 | // If all closing windows are obscured, then there is |
| 9455 | // no need to do an animation. This is the case, for |
| 9456 | // example, when this transition is being done behind |
| 9457 | // the lock screen. |
| 9458 | if (!mPolicy.allowAppAnimationsLw()) { |
| 9459 | animLp = null; |
| 9460 | } |
| 9461 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9462 | NN = mOpeningApps.size(); |
| 9463 | for (i=0; i<NN; i++) { |
| 9464 | AppWindowToken wtoken = mOpeningApps.get(i); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9465 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9466 | "Now opening app" + wtoken); |
| 9467 | wtoken.reportedVisible = false; |
| 9468 | wtoken.inPendingTransaction = false; |
| Dianne Hackborn | 83360b3 | 2009-08-24 18:43:32 -0700 | [diff] [blame] | 9469 | wtoken.animation = null; |
| Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 9470 | setTokenVisibilityLocked(wtoken, animLp, true, transit, false); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9471 | wtoken.updateReportedVisibilityLocked(); |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9472 | wtoken.waitingToShow = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9473 | wtoken.showAllWindowsLocked(); |
| 9474 | } |
| 9475 | NN = mClosingApps.size(); |
| 9476 | for (i=0; i<NN; i++) { |
| 9477 | AppWindowToken wtoken = mClosingApps.get(i); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9478 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9479 | "Now closing app" + wtoken); |
| 9480 | wtoken.inPendingTransaction = false; |
| Dianne Hackborn | 83360b3 | 2009-08-24 18:43:32 -0700 | [diff] [blame] | 9481 | wtoken.animation = null; |
| Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 9482 | setTokenVisibilityLocked(wtoken, animLp, false, transit, false); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9483 | wtoken.updateReportedVisibilityLocked(); |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9484 | wtoken.waitingToHide = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9485 | // Force the allDrawn flag, because we want to start |
| 9486 | // this guy's animations regardless of whether it's |
| 9487 | // gotten drawn. |
| 9488 | wtoken.allDrawn = true; |
| 9489 | } |
| 9490 | |
| Dianne Hackborn | 8b571a8 | 2009-09-25 16:09:43 -0700 | [diff] [blame] | 9491 | mNextAppTransitionPackage = null; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9492 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9493 | mOpeningApps.clear(); |
| 9494 | mClosingApps.clear(); |
| 9495 | |
| 9496 | // This has changed the visibility of windows, so perform |
| 9497 | // a new layout to get them all up-to-date. |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9498 | changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9499 | mLayoutNeeded = true; |
| Dianne Hackborn | 20583ff | 2009-07-27 21:51:05 -0700 | [diff] [blame] | 9500 | if (!moveInputMethodWindowsIfNeededLocked(true)) { |
| 9501 | assignLayersLocked(); |
| 9502 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9503 | updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES); |
| Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 9504 | mFocusMayChange = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9505 | } |
| 9506 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9507 | |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 9508 | int adjResult = 0; |
| 9509 | |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9510 | if (!animating && mAppTransitionRunning) { |
| 9511 | // We have finished the animation of an app transition. To do |
| 9512 | // this, we have delayed a lot of operations like showing and |
| 9513 | // hiding apps, moving apps in Z-order, etc. The app token list |
| 9514 | // reflects the correct Z-order, but the window list may now |
| 9515 | // be out of sync with it. So here we will just rebuild the |
| 9516 | // entire app window list. Fun! |
| 9517 | mAppTransitionRunning = false; |
| 9518 | // Clear information about apps that were moving. |
| 9519 | mToBottomApps.clear(); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9520 | |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9521 | rebuildAppWindowListLocked(); |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9522 | changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT; |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 9523 | adjResult |= ADJUST_WALLPAPER_LAYERS_CHANGED; |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9524 | moveInputMethodWindowsIfNeededLocked(false); |
| 9525 | wallpaperMayChange = true; |
| Suchi Amalapurapu | c9568e3 | 2009-11-05 18:51:16 -0800 | [diff] [blame] | 9526 | // Since the window list has been rebuilt, focus might |
| 9527 | // have to be recomputed since the actual order of windows |
| 9528 | // might have changed again. |
| Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 9529 | mFocusMayChange = true; |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9530 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9531 | |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9532 | if (wallpaperForceHidingChanged && changes == 0 && !mAppTransitionReady) { |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9533 | // At this point, there was a window with a wallpaper that |
| 9534 | // was force hiding other windows behind it, but now it |
| 9535 | // is going away. This may be simple -- just animate |
| 9536 | // away the wallpaper and its window -- or it may be |
| 9537 | // hard -- the wallpaper now needs to be shown behind |
| 9538 | // something that was hidden. |
| 9539 | WindowState oldWallpaper = mWallpaperTarget; |
| Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 9540 | if (mLowerWallpaperTarget != null |
| 9541 | && mLowerWallpaperTarget.mAppToken != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9542 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
| Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 9543 | "wallpaperForceHiding changed with lower=" |
| 9544 | + mLowerWallpaperTarget); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9545 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
| Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 9546 | "hidden=" + mLowerWallpaperTarget.mAppToken.hidden + |
| 9547 | " hiddenRequested=" + mLowerWallpaperTarget.mAppToken.hiddenRequested); |
| 9548 | if (mLowerWallpaperTarget.mAppToken.hidden) { |
| 9549 | // The lower target has become hidden before we |
| 9550 | // actually started the animation... let's completely |
| 9551 | // re-evaluate everything. |
| 9552 | mLowerWallpaperTarget = mUpperWallpaperTarget = null; |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9553 | changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM; |
| Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 9554 | } |
| 9555 | } |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 9556 | adjResult |= adjustWallpaperWindowsLocked(); |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9557 | wallpaperMayChange = false; |
| Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 9558 | wallpaperForceHidingChanged = false; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9559 | if (DEBUG_WALLPAPER) Slog.v(TAG, "****** OLD: " + oldWallpaper |
| Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 9560 | + " NEW: " + mWallpaperTarget |
| 9561 | + " LOWER: " + mLowerWallpaperTarget); |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9562 | if (mLowerWallpaperTarget == null) { |
| 9563 | // Whoops, we don't need a special wallpaper animation. |
| 9564 | // Clear them out. |
| 9565 | forceHiding = false; |
| 9566 | for (i=N-1; i>=0; i--) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 9567 | WindowState w = mWindows.get(i); |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9568 | if (w.mSurface != null) { |
| 9569 | final WindowManager.LayoutParams attrs = w.mAttrs; |
| Suchi Amalapurapu | c03d28b | 2009-10-28 14:32:05 -0700 | [diff] [blame] | 9570 | if (mPolicy.doesForceHide(w, attrs) && w.isVisibleLw()) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9571 | if (DEBUG_FOCUS) Slog.i(TAG, "win=" + w + " force hides other windows"); |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9572 | forceHiding = true; |
| 9573 | } else if (mPolicy.canBeForceHidden(w, attrs)) { |
| 9574 | if (!w.mAnimating) { |
| 9575 | // We set the animation above so it |
| 9576 | // is not yet running. |
| 9577 | w.clearAnimation(); |
| 9578 | } |
| 9579 | } |
| 9580 | } |
| 9581 | } |
| 9582 | } |
| 9583 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9584 | |
| Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 9585 | if (wallpaperMayChange) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9586 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 9587 | "Wallpaper may change! Adjusting"); |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 9588 | adjResult |= adjustWallpaperWindowsLocked(); |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9589 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9590 | |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9591 | if ((adjResult&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9592 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9593 | "Wallpaper layer changed: assigning layers + relayout"); |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9594 | changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9595 | assignLayersLocked(); |
| 9596 | } else if ((adjResult&ADJUST_WALLPAPER_VISIBILITY_CHANGED) != 0) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9597 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9598 | "Wallpaper visibility changed: relayout"); |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9599 | changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9600 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9601 | |
| Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 9602 | if (mFocusMayChange) { |
| 9603 | mFocusMayChange = false; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9604 | if (updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES)) { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9605 | changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9606 | adjResult = 0; |
| Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 9607 | } |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9608 | } |
| 9609 | |
| 9610 | if (mLayoutNeeded) { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9611 | changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT; |
| Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 9612 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9613 | |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9614 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "*** ANIM STEP: changes=0x" |
| 9615 | + Integer.toHexString(changes)); |
| Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 9616 | |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 9617 | mInputMonitor.updateInputWindowsLw(); |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9618 | } while (changes != 0); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9619 | |
| 9620 | // THIRD LOOP: Update the surfaces of all windows. |
| 9621 | |
| 9622 | final boolean someoneLosingFocus = mLosingFocus.size() != 0; |
| 9623 | |
| 9624 | boolean obscured = false; |
| 9625 | boolean blurring = false; |
| 9626 | boolean dimming = false; |
| 9627 | boolean covered = false; |
| Dianne Hackborn | 9ed4a4b | 2009-03-25 17:10:37 -0700 | [diff] [blame] | 9628 | boolean syswin = false; |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 9629 | boolean backgroundFillerShown = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9630 | |
| Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 9631 | final int N = mWindows.size(); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9632 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9633 | for (i=N-1; i>=0; i--) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 9634 | WindowState w = mWindows.get(i); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9635 | |
| 9636 | boolean displayed = false; |
| 9637 | final WindowManager.LayoutParams attrs = w.mAttrs; |
| 9638 | final int attrFlags = attrs.flags; |
| 9639 | |
| 9640 | if (w.mSurface != null) { |
| Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 9641 | // XXX NOTE: The logic here could be improved. We have |
| 9642 | // the decision about whether to resize a window separated |
| 9643 | // from whether to hide the surface. This can cause us to |
| 9644 | // resize a surface even if we are going to hide it. You |
| 9645 | // can see this by (1) holding device in landscape mode on |
| 9646 | // home screen; (2) tapping browser icon (device will rotate |
| 9647 | // to landscape; (3) tap home. The wallpaper will be resized |
| 9648 | // in step 2 but then immediately hidden, causing us to |
| 9649 | // have to resize and then redraw it again in step 3. It |
| 9650 | // would be nice to figure out how to avoid this, but it is |
| 9651 | // difficult because we do need to resize surfaces in some |
| 9652 | // cases while they are hidden such as when first showing a |
| 9653 | // window. |
| 9654 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9655 | w.computeShownFrameLocked(); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9656 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9657 | TAG, "Placing surface #" + i + " " + w.mSurface |
| 9658 | + ": new=" + w.mShownFrame + ", old=" |
| 9659 | + w.mLastShownFrame); |
| 9660 | |
| 9661 | boolean resize; |
| 9662 | int width, height; |
| 9663 | if ((w.mAttrs.flags & w.mAttrs.FLAG_SCALED) != 0) { |
| 9664 | resize = w.mLastRequestedWidth != w.mRequestedWidth || |
| 9665 | w.mLastRequestedHeight != w.mRequestedHeight; |
| 9666 | // for a scaled surface, we just want to use |
| 9667 | // the requested size. |
| 9668 | width = w.mRequestedWidth; |
| 9669 | height = w.mRequestedHeight; |
| 9670 | w.mLastRequestedWidth = width; |
| 9671 | w.mLastRequestedHeight = height; |
| 9672 | w.mLastShownFrame.set(w.mShownFrame); |
| 9673 | try { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9674 | if (SHOW_TRANSACTIONS) logSurface(w, |
| 9675 | "POS " + w.mShownFrame.left |
| 9676 | + ", " + w.mShownFrame.top, null); |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 9677 | w.mSurfaceX = w.mShownFrame.left; |
| 9678 | w.mSurfaceY = w.mShownFrame.top; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9679 | w.mSurface.setPosition(w.mShownFrame.left, w.mShownFrame.top); |
| 9680 | } catch (RuntimeException e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9681 | Slog.w(TAG, "Error positioning surface in " + w, e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9682 | if (!recoveringMemory) { |
| 9683 | reclaimSomeSurfaceMemoryLocked(w, "position"); |
| 9684 | } |
| 9685 | } |
| 9686 | } else { |
| 9687 | resize = !w.mLastShownFrame.equals(w.mShownFrame); |
| 9688 | width = w.mShownFrame.width(); |
| 9689 | height = w.mShownFrame.height(); |
| 9690 | w.mLastShownFrame.set(w.mShownFrame); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9691 | } |
| 9692 | |
| 9693 | if (resize) { |
| 9694 | if (width < 1) width = 1; |
| 9695 | if (height < 1) height = 1; |
| 9696 | if (w.mSurface != null) { |
| 9697 | try { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9698 | if (SHOW_TRANSACTIONS) logSurface(w, |
| 9699 | "POS " + w.mShownFrame.left + "," |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 9700 | + w.mShownFrame.top + " SIZE " |
| 9701 | + w.mShownFrame.width() + "x" |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9702 | + w.mShownFrame.height(), null); |
| Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 9703 | w.mSurfaceResized = true; |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 9704 | w.mSurfaceW = width; |
| 9705 | w.mSurfaceH = height; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9706 | w.mSurface.setSize(width, height); |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 9707 | w.mSurfaceX = w.mShownFrame.left; |
| 9708 | w.mSurfaceY = w.mShownFrame.top; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9709 | w.mSurface.setPosition(w.mShownFrame.left, |
| 9710 | w.mShownFrame.top); |
| 9711 | } catch (RuntimeException e) { |
| 9712 | // If something goes wrong with the surface (such |
| 9713 | // as running out of memory), don't take down the |
| 9714 | // entire system. |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9715 | Slog.e(TAG, "Failure updating surface of " + w |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9716 | + "size=(" + width + "x" + height |
| 9717 | + "), pos=(" + w.mShownFrame.left |
| 9718 | + "," + w.mShownFrame.top + ")", e); |
| 9719 | if (!recoveringMemory) { |
| 9720 | reclaimSomeSurfaceMemoryLocked(w, "size"); |
| 9721 | } |
| 9722 | } |
| 9723 | } |
| 9724 | } |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 9725 | if (!w.mAppFreezing && w.mLayoutSeq == mLayoutSeq) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9726 | w.mContentInsetsChanged = |
| 9727 | !w.mLastContentInsets.equals(w.mContentInsets); |
| 9728 | w.mVisibleInsetsChanged = |
| 9729 | !w.mLastVisibleInsets.equals(w.mVisibleInsets); |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 9730 | boolean configChanged = |
| 9731 | w.mConfiguration != mCurConfiguration |
| 9732 | && (w.mConfiguration == null |
| 9733 | || mCurConfiguration.diff(w.mConfiguration) != 0); |
| Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 9734 | if (DEBUG_CONFIGURATION && configChanged) { |
| 9735 | Slog.v(TAG, "Win " + w + " config changed: " |
| 9736 | + mCurConfiguration); |
| 9737 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9738 | if (localLOGV) Slog.v(TAG, "Resizing " + w |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 9739 | + ": configChanged=" + configChanged |
| 9740 | + " last=" + w.mLastFrame + " frame=" + w.mFrame); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9741 | if (!w.mLastFrame.equals(w.mFrame) |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9742 | || w.mContentInsetsChanged |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 9743 | || w.mVisibleInsetsChanged |
| Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 9744 | || w.mSurfaceResized |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 9745 | || configChanged) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9746 | w.mLastFrame.set(w.mFrame); |
| 9747 | w.mLastContentInsets.set(w.mContentInsets); |
| 9748 | w.mLastVisibleInsets.set(w.mVisibleInsets); |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 9749 | // If the screen is currently frozen, then keep |
| 9750 | // it frozen until this window draws at its new |
| 9751 | // orientation. |
| 9752 | if (mDisplayFrozen) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9753 | if (DEBUG_ORIENTATION) Slog.v(TAG, |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 9754 | "Resizing while display frozen: " + w); |
| 9755 | w.mOrientationChanging = true; |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 9756 | if (!mWindowsFreezingScreen) { |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 9757 | mWindowsFreezingScreen = true; |
| 9758 | // XXX should probably keep timeout from |
| 9759 | // when we first froze the display. |
| 9760 | mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT); |
| 9761 | mH.sendMessageDelayed(mH.obtainMessage( |
| 9762 | H.WINDOW_FREEZE_TIMEOUT), 2000); |
| 9763 | } |
| 9764 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9765 | // If the orientation is changing, then we need to |
| 9766 | // hold off on unfreezing the display until this |
| 9767 | // window has been redrawn; to do that, we need |
| 9768 | // to go through the process of getting informed |
| 9769 | // by the application when it has finished drawing. |
| 9770 | if (w.mOrientationChanging) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9771 | if (DEBUG_ORIENTATION) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9772 | "Orientation start waiting for draw in " |
| 9773 | + w + ", surface " + w.mSurface); |
| 9774 | w.mDrawPending = true; |
| 9775 | w.mCommitDrawPending = false; |
| 9776 | w.mReadyToShow = false; |
| 9777 | if (w.mAppToken != null) { |
| 9778 | w.mAppToken.allDrawn = false; |
| 9779 | } |
| 9780 | } |
| Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 9781 | if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9782 | "Resizing window " + w + " to " + w.mFrame); |
| 9783 | mResizingWindows.add(w); |
| 9784 | } else if (w.mOrientationChanging) { |
| 9785 | if (!w.mDrawPending && !w.mCommitDrawPending) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9786 | if (DEBUG_ORIENTATION) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9787 | "Orientation not waiting for draw in " |
| 9788 | + w + ", surface " + w.mSurface); |
| 9789 | w.mOrientationChanging = false; |
| 9790 | } |
| 9791 | } |
| 9792 | } |
| 9793 | |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9794 | if (w.mAttachedHidden || !w.isReadyForDisplay()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9795 | if (!w.mLastHidden) { |
| 9796 | //dump(); |
| 9797 | w.mLastHidden = true; |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9798 | if (SHOW_TRANSACTIONS) logSurface(w, |
| 9799 | "HIDE (performLayout)", null); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9800 | if (w.mSurface != null) { |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 9801 | w.mSurfaceShown = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9802 | try { |
| 9803 | w.mSurface.hide(); |
| 9804 | } catch (RuntimeException e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9805 | Slog.w(TAG, "Exception hiding surface in " + w); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9806 | } |
| 9807 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9808 | } |
| 9809 | // If we are waiting for this window to handle an |
| 9810 | // orientation change, well, it is hidden, so |
| 9811 | // doesn't really matter. Note that this does |
| 9812 | // introduce a potential glitch if the window |
| 9813 | // becomes unhidden before it has drawn for the |
| 9814 | // new orientation. |
| 9815 | if (w.mOrientationChanging) { |
| 9816 | w.mOrientationChanging = false; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9817 | if (DEBUG_ORIENTATION) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9818 | "Orientation change skips hidden " + w); |
| 9819 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9820 | } else if (w.mLastLayer != w.mAnimLayer |
| 9821 | || w.mLastAlpha != w.mShownAlpha |
| 9822 | || w.mLastDsDx != w.mDsDx |
| 9823 | || w.mLastDtDx != w.mDtDx |
| 9824 | || w.mLastDsDy != w.mDsDy |
| 9825 | || w.mLastDtDy != w.mDtDy |
| 9826 | || w.mLastHScale != w.mHScale |
| 9827 | || w.mLastVScale != w.mVScale |
| 9828 | || w.mLastHidden) { |
| 9829 | displayed = true; |
| 9830 | w.mLastAlpha = w.mShownAlpha; |
| 9831 | w.mLastLayer = w.mAnimLayer; |
| 9832 | w.mLastDsDx = w.mDsDx; |
| 9833 | w.mLastDtDx = w.mDtDx; |
| 9834 | w.mLastDsDy = w.mDsDy; |
| 9835 | w.mLastDtDy = w.mDtDy; |
| 9836 | w.mLastHScale = w.mHScale; |
| 9837 | w.mLastVScale = w.mVScale; |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9838 | if (SHOW_TRANSACTIONS) logSurface(w, |
| 9839 | "alpha=" + w.mShownAlpha + " layer=" + w.mAnimLayer |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 9840 | + " matrix=[" + (w.mDsDx*w.mHScale) |
| 9841 | + "," + (w.mDtDx*w.mVScale) |
| 9842 | + "][" + (w.mDsDy*w.mHScale) |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9843 | + "," + (w.mDtDy*w.mVScale) + "]", null); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9844 | if (w.mSurface != null) { |
| 9845 | try { |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 9846 | w.mSurfaceAlpha = w.mShownAlpha; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9847 | w.mSurface.setAlpha(w.mShownAlpha); |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 9848 | w.mSurfaceLayer = w.mAnimLayer; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9849 | w.mSurface.setLayer(w.mAnimLayer); |
| 9850 | w.mSurface.setMatrix( |
| 9851 | w.mDsDx*w.mHScale, w.mDtDx*w.mVScale, |
| 9852 | w.mDsDy*w.mHScale, w.mDtDy*w.mVScale); |
| 9853 | } catch (RuntimeException e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9854 | Slog.w(TAG, "Error updating surface in " + w, e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9855 | if (!recoveringMemory) { |
| 9856 | reclaimSomeSurfaceMemoryLocked(w, "update"); |
| 9857 | } |
| 9858 | } |
| 9859 | } |
| 9860 | |
| 9861 | if (w.mLastHidden && !w.mDrawPending |
| 9862 | && !w.mCommitDrawPending |
| 9863 | && !w.mReadyToShow) { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9864 | if (SHOW_TRANSACTIONS) logSurface(w, |
| 9865 | "SHOW (performLayout)", null); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9866 | if (DEBUG_VISIBILITY) Slog.v(TAG, "Showing " + w |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9867 | + " during relayout"); |
| 9868 | if (showSurfaceRobustlyLocked(w)) { |
| 9869 | w.mHasDrawn = true; |
| 9870 | w.mLastHidden = false; |
| 9871 | } else { |
| 9872 | w.mOrientationChanging = false; |
| 9873 | } |
| 9874 | } |
| 9875 | if (w.mSurface != null) { |
| 9876 | w.mToken.hasVisible = true; |
| 9877 | } |
| 9878 | } else { |
| 9879 | displayed = true; |
| 9880 | } |
| 9881 | |
| 9882 | if (displayed) { |
| 9883 | if (!covered) { |
| Romain Guy | 980a938 | 2010-01-08 15:06:28 -0800 | [diff] [blame] | 9884 | if (attrs.width == LayoutParams.MATCH_PARENT |
| 9885 | && attrs.height == LayoutParams.MATCH_PARENT) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9886 | covered = true; |
| 9887 | } |
| 9888 | } |
| 9889 | if (w.mOrientationChanging) { |
| 9890 | if (w.mDrawPending || w.mCommitDrawPending) { |
| 9891 | orientationChangeComplete = false; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9892 | if (DEBUG_ORIENTATION) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9893 | "Orientation continue waiting for draw in " + w); |
| 9894 | } else { |
| 9895 | w.mOrientationChanging = 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 change complete in " + w); |
| 9898 | } |
| 9899 | } |
| 9900 | w.mToken.hasVisible = true; |
| 9901 | } |
| 9902 | } else if (w.mOrientationChanging) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9903 | if (DEBUG_ORIENTATION) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9904 | "Orientation change skips hidden " + w); |
| 9905 | w.mOrientationChanging = false; |
| 9906 | } |
| 9907 | |
| 9908 | final boolean canBeSeen = w.isDisplayedLw(); |
| 9909 | |
| 9910 | if (someoneLosingFocus && w == mCurrentFocus && canBeSeen) { |
| 9911 | focusDisplayed = true; |
| 9912 | } |
| 9913 | |
| Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 9914 | final boolean obscuredChanged = w.mObscured != obscured; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9915 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9916 | // Update effect. |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 9917 | if (!(w.mObscured=obscured)) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9918 | if (w.mSurface != null) { |
| 9919 | if ((attrFlags&FLAG_KEEP_SCREEN_ON) != 0) { |
| 9920 | holdScreen = w.mSession; |
| 9921 | } |
| Dianne Hackborn | 9ed4a4b | 2009-03-25 17:10:37 -0700 | [diff] [blame] | 9922 | if (!syswin && w.mAttrs.screenBrightness >= 0 |
| 9923 | && screenBrightness < 0) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9924 | screenBrightness = w.mAttrs.screenBrightness; |
| 9925 | } |
| Mike Lockwood | fb73f79 | 2009-11-20 11:31:18 -0500 | [diff] [blame] | 9926 | if (!syswin && w.mAttrs.buttonBrightness >= 0 |
| 9927 | && buttonBrightness < 0) { |
| 9928 | buttonBrightness = w.mAttrs.buttonBrightness; |
| 9929 | } |
| Mike Lockwood | 46af6a8 | 2010-03-09 08:28:22 -0500 | [diff] [blame] | 9930 | if (canBeSeen |
| 9931 | && (attrs.type == WindowManager.LayoutParams.TYPE_SYSTEM_DIALOG |
| 9932 | || attrs.type == WindowManager.LayoutParams.TYPE_KEYGUARD |
| 9933 | || attrs.type == WindowManager.LayoutParams.TYPE_SYSTEM_ERROR)) { |
| Dianne Hackborn | 9ed4a4b | 2009-03-25 17:10:37 -0700 | [diff] [blame] | 9934 | syswin = true; |
| 9935 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9936 | } |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 9937 | |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 9938 | boolean opaqueDrawn = canBeSeen && w.isOpaqueDrawn(); |
| 9939 | if (opaqueDrawn && w.isFullscreen(dw, dh)) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9940 | // This window completely covers everything behind it, |
| 9941 | // so we want to leave all of them as unblurred (for |
| 9942 | // performance reasons). |
| 9943 | obscured = true; |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 9944 | } else if (opaqueDrawn && w.needsBackgroundFiller(dw, dh)) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9945 | if (SHOW_TRANSACTIONS) Slog.d(TAG, "showing background filler"); |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 9946 | // This window is in compatibility mode, and needs background filler. |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 9947 | obscured = true; |
| 9948 | if (mBackgroundFillerSurface == null) { |
| 9949 | try { |
| 9950 | mBackgroundFillerSurface = new Surface(mFxSession, 0, |
| Mathias Agopian | 5d26c1e | 2010-03-01 16:09:43 -0800 | [diff] [blame] | 9951 | "BackGroundFiller", |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 9952 | 0, dw, dh, |
| 9953 | PixelFormat.OPAQUE, |
| 9954 | Surface.FX_SURFACE_NORMAL); |
| 9955 | } catch (Exception e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9956 | Slog.e(TAG, "Exception creating filler surface", e); |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 9957 | } |
| 9958 | } |
| 9959 | try { |
| 9960 | mBackgroundFillerSurface.setPosition(0, 0); |
| 9961 | mBackgroundFillerSurface.setSize(dw, dh); |
| 9962 | // Using the same layer as Dim because they will never be shown at the |
| 9963 | // same time. |
| 9964 | mBackgroundFillerSurface.setLayer(w.mAnimLayer - 1); |
| 9965 | mBackgroundFillerSurface.show(); |
| 9966 | } catch (RuntimeException e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9967 | Slog.e(TAG, "Exception showing filler surface"); |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 9968 | } |
| 9969 | backgroundFillerShown = true; |
| 9970 | mBackgroundFillerShown = true; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9971 | } else if (canBeSeen && !obscured && |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9972 | (attrFlags&FLAG_BLUR_BEHIND|FLAG_DIM_BEHIND) != 0) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9973 | if (localLOGV) Slog.v(TAG, "Win " + w |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9974 | + ": blurring=" + blurring |
| 9975 | + " obscured=" + obscured |
| 9976 | + " displayed=" + displayed); |
| 9977 | if ((attrFlags&FLAG_DIM_BEHIND) != 0) { |
| 9978 | if (!dimming) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9979 | //Slog.i(TAG, "DIM BEHIND: " + w); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9980 | dimming = true; |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 9981 | if (mDimAnimator == null) { |
| 9982 | mDimAnimator = new DimAnimator(mFxSession); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9983 | } |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 9984 | mDimAnimator.show(dw, dh); |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 9985 | mDimAnimator.updateParameters(w, currentTime); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9986 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9987 | } |
| 9988 | if ((attrFlags&FLAG_BLUR_BEHIND) != 0) { |
| 9989 | if (!blurring) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9990 | //Slog.i(TAG, "BLUR BEHIND: " + w); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9991 | blurring = true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9992 | if (mBlurSurface == null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9993 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR " |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9994 | + mBlurSurface + ": CREATE"); |
| 9995 | try { |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9996 | mBlurSurface = new Surface(mFxSession, 0, |
| Mathias Agopian | 5d26c1e | 2010-03-01 16:09:43 -0800 | [diff] [blame] | 9997 | "BlurSurface", |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9998 | -1, 16, 16, |
| 9999 | PixelFormat.OPAQUE, |
| 10000 | Surface.FX_SURFACE_BLUR); |
| 10001 | } catch (Exception e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10002 | Slog.e(TAG, "Exception creating Blur surface", e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10003 | } |
| 10004 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10005 | if (mBlurSurface != null) { |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 10006 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR " |
| 10007 | + mBlurSurface + ": pos=(0,0) (" + |
| 10008 | dw + "x" + dh + "), layer=" + (w.mAnimLayer-1)); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10009 | mBlurSurface.setPosition(0, 0); |
| 10010 | mBlurSurface.setSize(dw, dh); |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 10011 | mBlurSurface.setLayer(w.mAnimLayer-2); |
| 10012 | if (!mBlurShown) { |
| 10013 | try { |
| 10014 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR " |
| 10015 | + mBlurSurface + ": SHOW"); |
| 10016 | mBlurSurface.show(); |
| 10017 | } catch (RuntimeException e) { |
| 10018 | Slog.w(TAG, "Failure showing blur surface", e); |
| 10019 | } |
| 10020 | mBlurShown = true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10021 | } |
| 10022 | } |
| 10023 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10024 | } |
| 10025 | } |
| 10026 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10027 | |
| Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 10028 | if (obscuredChanged && mWallpaperTarget == w) { |
| 10029 | // This is the wallpaper target and its obscured state |
| 10030 | // changed... make sure the current wallaper's visibility |
| 10031 | // has been updated accordingly. |
| 10032 | updateWallpaperVisibilityLocked(); |
| 10033 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10034 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10035 | |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 10036 | if (backgroundFillerShown == false && mBackgroundFillerShown) { |
| 10037 | mBackgroundFillerShown = false; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10038 | if (SHOW_TRANSACTIONS) Slog.d(TAG, "hiding background filler"); |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 10039 | try { |
| 10040 | mBackgroundFillerSurface.hide(); |
| 10041 | } catch (RuntimeException e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10042 | Slog.e(TAG, "Exception hiding filler surface", e); |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 10043 | } |
| 10044 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10045 | |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 10046 | if (mDimAnimator != null && mDimAnimator.mDimShown) { |
| Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 10047 | animating |= mDimAnimator.updateSurface(dimming, currentTime, |
| 10048 | mDisplayFrozen || !mPolicy.isScreenOn()); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10049 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10050 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10051 | if (!blurring && mBlurShown) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10052 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR " + mBlurSurface |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10053 | + ": HIDE"); |
| 10054 | try { |
| 10055 | mBlurSurface.hide(); |
| 10056 | } catch (IllegalArgumentException e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10057 | Slog.w(TAG, "Illegal argument exception hiding blur surface"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10058 | } |
| 10059 | mBlurShown = false; |
| 10060 | } |
| 10061 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10062 | if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10063 | } catch (RuntimeException e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10064 | Slog.e(TAG, "Unhandled exception in Window Manager", e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10065 | } |
| 10066 | |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 10067 | mInputMonitor.updateInputWindowsLw(); |
| 10068 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10069 | Surface.closeTransaction(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10070 | |
| Dianne Hackborn | b9fb170 | 2010-08-23 16:49:02 -0700 | [diff] [blame] | 10071 | if (mWatermark != null) { |
| 10072 | mWatermark.drawIfNeeded(); |
| 10073 | } |
| 10074 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10075 | if (DEBUG_ORIENTATION && mDisplayFrozen) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10076 | "With display frozen, orientationChangeComplete=" |
| 10077 | + orientationChangeComplete); |
| 10078 | if (orientationChangeComplete) { |
| 10079 | if (mWindowsFreezingScreen) { |
| 10080 | mWindowsFreezingScreen = false; |
| 10081 | mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT); |
| 10082 | } |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 10083 | stopFreezingDisplayLocked(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10084 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10085 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10086 | i = mResizingWindows.size(); |
| 10087 | if (i > 0) { |
| 10088 | do { |
| 10089 | i--; |
| 10090 | WindowState win = mResizingWindows.get(i); |
| 10091 | try { |
| Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 10092 | if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG, |
| 10093 | "Reporting new frame to " + win + ": " + win.mFrame); |
| Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 10094 | int diff = 0; |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 10095 | boolean configChanged = |
| 10096 | win.mConfiguration != mCurConfiguration |
| 10097 | && (win.mConfiguration == null |
| Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 10098 | || (diff=mCurConfiguration.diff(win.mConfiguration)) != 0); |
| 10099 | if ((DEBUG_RESIZE || DEBUG_ORIENTATION || DEBUG_CONFIGURATION) |
| 10100 | && configChanged) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10101 | Slog.i(TAG, "Sending new config to window " + win + ": " |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 10102 | + win.mFrame.width() + "x" + win.mFrame.height() |
| Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 10103 | + " / " + mCurConfiguration + " / 0x" |
| 10104 | + Integer.toHexString(diff)); |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 10105 | } |
| Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 10106 | win.mConfiguration = mCurConfiguration; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10107 | win.mClient.resized(win.mFrame.width(), |
| 10108 | win.mFrame.height(), win.mLastContentInsets, |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 10109 | win.mLastVisibleInsets, win.mDrawPending, |
| 10110 | configChanged ? win.mConfiguration : null); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10111 | win.mContentInsetsChanged = false; |
| 10112 | win.mVisibleInsetsChanged = false; |
| Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 10113 | win.mSurfaceResized = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10114 | } catch (RemoteException e) { |
| 10115 | win.mOrientationChanging = false; |
| 10116 | } |
| 10117 | } while (i > 0); |
| 10118 | mResizingWindows.clear(); |
| 10119 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10120 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10121 | // Destroy the surface of any windows that are no longer visible. |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 10122 | boolean wallpaperDestroyed = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10123 | i = mDestroySurface.size(); |
| 10124 | if (i > 0) { |
| 10125 | do { |
| 10126 | i--; |
| 10127 | WindowState win = mDestroySurface.get(i); |
| 10128 | win.mDestroying = false; |
| 10129 | if (mInputMethodWindow == win) { |
| 10130 | mInputMethodWindow = null; |
| 10131 | } |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 10132 | if (win == mWallpaperTarget) { |
| 10133 | wallpaperDestroyed = true; |
| 10134 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10135 | win.destroySurfaceLocked(); |
| 10136 | } while (i > 0); |
| 10137 | mDestroySurface.clear(); |
| 10138 | } |
| 10139 | |
| 10140 | // Time to remove any exiting tokens? |
| 10141 | for (i=mExitingTokens.size()-1; i>=0; i--) { |
| 10142 | WindowToken token = mExitingTokens.get(i); |
| 10143 | if (!token.hasVisible) { |
| 10144 | mExitingTokens.remove(i); |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 10145 | if (token.windowType == TYPE_WALLPAPER) { |
| 10146 | mWallpaperTokens.remove(token); |
| 10147 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10148 | } |
| 10149 | } |
| 10150 | |
| 10151 | // Time to remove any exiting applications? |
| 10152 | for (i=mExitingAppTokens.size()-1; i>=0; i--) { |
| 10153 | AppWindowToken token = mExitingAppTokens.get(i); |
| 10154 | if (!token.hasVisible && !mClosingApps.contains(token)) { |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 10155 | // Make sure there is no animation running on this token, |
| 10156 | // so any windows associated with it will be removed as |
| 10157 | // soon as their animations are complete |
| 10158 | token.animation = null; |
| 10159 | token.animating = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10160 | mAppTokens.remove(token); |
| 10161 | mExitingAppTokens.remove(i); |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10162 | if (mLastEnterAnimToken == token) { |
| 10163 | mLastEnterAnimToken = null; |
| 10164 | mLastEnterAnimParams = null; |
| 10165 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10166 | } |
| 10167 | } |
| 10168 | |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 10169 | boolean needRelayout = false; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10170 | |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 10171 | if (!animating && mAppTransitionRunning) { |
| 10172 | // We have finished the animation of an app transition. To do |
| 10173 | // this, we have delayed a lot of operations like showing and |
| 10174 | // hiding apps, moving apps in Z-order, etc. The app token list |
| 10175 | // reflects the correct Z-order, but the window list may now |
| 10176 | // be out of sync with it. So here we will just rebuild the |
| 10177 | // entire app window list. Fun! |
| 10178 | mAppTransitionRunning = false; |
| 10179 | needRelayout = true; |
| 10180 | rebuildAppWindowListLocked(); |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 10181 | assignLayersLocked(); |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 10182 | // Clear information about apps that were moving. |
| 10183 | mToBottomApps.clear(); |
| 10184 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10185 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10186 | if (focusDisplayed) { |
| 10187 | mH.sendEmptyMessage(H.REPORT_LOSING_FOCUS); |
| 10188 | } |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 10189 | if (wallpaperDestroyed) { |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 10190 | needRelayout = adjustWallpaperWindowsLocked() != 0; |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 10191 | } |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 10192 | if (needRelayout) { |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 10193 | requestAnimationLocked(0); |
| 10194 | } else if (animating) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10195 | requestAnimationLocked(currentTime+(1000/60)-SystemClock.uptimeMillis()); |
| 10196 | } |
| Jeff Brown | eb857f1 | 2010-07-16 10:06:33 -0700 | [diff] [blame] | 10197 | |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 10198 | mInputMonitor.updateInputWindowsLw(); |
| Jeff Brown | eb857f1 | 2010-07-16 10:06:33 -0700 | [diff] [blame] | 10199 | |
| Jeff Brown | 8e03b75 | 2010-06-13 19:16:55 -0700 | [diff] [blame] | 10200 | setHoldScreenLocked(holdScreen != null); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10201 | if (screenBrightness < 0 || screenBrightness > 1.0f) { |
| 10202 | mPowerManager.setScreenBrightnessOverride(-1); |
| 10203 | } else { |
| 10204 | mPowerManager.setScreenBrightnessOverride((int) |
| 10205 | (screenBrightness * Power.BRIGHTNESS_ON)); |
| 10206 | } |
| Mike Lockwood | fb73f79 | 2009-11-20 11:31:18 -0500 | [diff] [blame] | 10207 | if (buttonBrightness < 0 || buttonBrightness > 1.0f) { |
| 10208 | mPowerManager.setButtonBrightnessOverride(-1); |
| 10209 | } else { |
| 10210 | mPowerManager.setButtonBrightnessOverride((int) |
| 10211 | (buttonBrightness * Power.BRIGHTNESS_ON)); |
| 10212 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10213 | if (holdScreen != mHoldingScreenOn) { |
| 10214 | mHoldingScreenOn = holdScreen; |
| 10215 | Message m = mH.obtainMessage(H.HOLD_SCREEN_CHANGED, holdScreen); |
| 10216 | mH.sendMessage(m); |
| 10217 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10218 | |
| Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 10219 | if (mTurnOnScreen) { |
| Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 10220 | if (DEBUG_VISIBILITY) Slog.v(TAG, "Turning screen on after layout!"); |
| Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 10221 | mPowerManager.userActivity(SystemClock.uptimeMillis(), false, |
| 10222 | LocalPowerManager.BUTTON_EVENT, true); |
| 10223 | mTurnOnScreen = false; |
| 10224 | } |
| Dianne Hackborn | f3bea9c | 2009-12-09 18:26:21 -0800 | [diff] [blame] | 10225 | |
| 10226 | // Check to see if we are now in a state where the screen should |
| 10227 | // be enabled, because the window obscured flags have changed. |
| 10228 | enableScreenIfNeededLocked(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10229 | } |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 10230 | |
| 10231 | /** |
| 10232 | * Must be called with the main window manager lock held. |
| 10233 | */ |
| 10234 | void setHoldScreenLocked(boolean holding) { |
| 10235 | boolean state = mHoldingScreenWakeLock.isHeld(); |
| 10236 | if (holding != state) { |
| 10237 | if (holding) { |
| 10238 | mHoldingScreenWakeLock.acquire(); |
| 10239 | } else { |
| 10240 | mPolicy.screenOnStoppedLw(); |
| 10241 | mHoldingScreenWakeLock.release(); |
| 10242 | } |
| 10243 | } |
| 10244 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10245 | |
| 10246 | void requestAnimationLocked(long delay) { |
| 10247 | if (!mAnimationPending) { |
| 10248 | mAnimationPending = true; |
| 10249 | mH.sendMessageDelayed(mH.obtainMessage(H.ANIMATE), delay); |
| 10250 | } |
| 10251 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10252 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10253 | /** |
| 10254 | * Have the surface flinger show a surface, robustly dealing with |
| 10255 | * error conditions. In particular, if there is not enough memory |
| 10256 | * to show the surface, then we will try to get rid of other surfaces |
| 10257 | * in order to succeed. |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10258 | * |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10259 | * @return Returns true if the surface was successfully shown. |
| 10260 | */ |
| 10261 | boolean showSurfaceRobustlyLocked(WindowState win) { |
| 10262 | try { |
| 10263 | if (win.mSurface != null) { |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 10264 | win.mSurfaceShown = true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10265 | win.mSurface.show(); |
| Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 10266 | if (win.mTurnOnScreen) { |
| Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 10267 | if (DEBUG_VISIBILITY) Slog.v(TAG, |
| 10268 | "Show surface turning screen on: " + win); |
| Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 10269 | win.mTurnOnScreen = false; |
| 10270 | mTurnOnScreen = true; |
| 10271 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10272 | } |
| 10273 | return true; |
| 10274 | } catch (RuntimeException e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10275 | 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] | 10276 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10277 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10278 | reclaimSomeSurfaceMemoryLocked(win, "show"); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10279 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10280 | return false; |
| 10281 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10282 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10283 | void reclaimSomeSurfaceMemoryLocked(WindowState win, String operation) { |
| 10284 | final Surface surface = win.mSurface; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10285 | |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10286 | EventLog.writeEvent(EventLogTags.WM_NO_SURFACE_MEMORY, win.toString(), |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10287 | win.mSession.mPid, operation); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10288 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10289 | if (mForceRemoves == null) { |
| 10290 | mForceRemoves = new ArrayList<WindowState>(); |
| 10291 | } |
| 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 | long callingIdentity = Binder.clearCallingIdentity(); |
| 10294 | try { |
| 10295 | // There was some problem... first, do a sanity check of the |
| 10296 | // window list to make sure we haven't left any dangling surfaces |
| 10297 | // around. |
| 10298 | int N = mWindows.size(); |
| 10299 | boolean leakedSurface = false; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10300 | 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] | 10301 | for (int i=0; i<N; i++) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 10302 | WindowState ws = mWindows.get(i); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10303 | if (ws.mSurface != null) { |
| 10304 | if (!mSessions.contains(ws.mSession)) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10305 | Slog.w(TAG, "LEAKED SURFACE (session doesn't exist): " |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10306 | + ws + " surface=" + ws.mSurface |
| 10307 | + " token=" + win.mToken |
| 10308 | + " pid=" + ws.mSession.mPid |
| 10309 | + " uid=" + ws.mSession.mUid); |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 10310 | ws.mSurface.destroy(); |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 10311 | ws.mSurfaceShown = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10312 | ws.mSurface = null; |
| 10313 | mForceRemoves.add(ws); |
| 10314 | i--; |
| 10315 | N--; |
| 10316 | leakedSurface = true; |
| 10317 | } else if (win.mAppToken != null && win.mAppToken.clientHidden) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10318 | Slog.w(TAG, "LEAKED SURFACE (app token hidden): " |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10319 | + ws + " surface=" + ws.mSurface |
| 10320 | + " token=" + win.mAppToken); |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 10321 | ws.mSurface.destroy(); |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 10322 | ws.mSurfaceShown = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10323 | ws.mSurface = null; |
| 10324 | leakedSurface = true; |
| 10325 | } |
| 10326 | } |
| 10327 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10328 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10329 | boolean killedApps = false; |
| 10330 | if (!leakedSurface) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10331 | Slog.w(TAG, "No leaked surfaces; killing applicatons!"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10332 | SparseIntArray pidCandidates = new SparseIntArray(); |
| 10333 | for (int i=0; i<N; i++) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 10334 | WindowState ws = mWindows.get(i); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10335 | if (ws.mSurface != null) { |
| 10336 | pidCandidates.append(ws.mSession.mPid, ws.mSession.mPid); |
| 10337 | } |
| 10338 | } |
| 10339 | if (pidCandidates.size() > 0) { |
| 10340 | int[] pids = new int[pidCandidates.size()]; |
| 10341 | for (int i=0; i<pids.length; i++) { |
| 10342 | pids[i] = pidCandidates.keyAt(i); |
| 10343 | } |
| 10344 | try { |
| Suchi Amalapurapu | e99bb5f | 2010-03-19 14:36:49 -0700 | [diff] [blame] | 10345 | if (mActivityManager.killPids(pids, "Free memory")) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10346 | killedApps = true; |
| 10347 | } |
| 10348 | } catch (RemoteException e) { |
| 10349 | } |
| 10350 | } |
| 10351 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10352 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10353 | if (leakedSurface || killedApps) { |
| 10354 | // We managed to reclaim some memory, so get rid of the trouble |
| 10355 | // surface and ask the app to request another one. |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10356 | 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] | 10357 | if (surface != null) { |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 10358 | surface.destroy(); |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 10359 | win.mSurfaceShown = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10360 | win.mSurface = null; |
| 10361 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10362 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10363 | try { |
| 10364 | win.mClient.dispatchGetNewSurface(); |
| 10365 | } catch (RemoteException e) { |
| 10366 | } |
| 10367 | } |
| 10368 | } finally { |
| 10369 | Binder.restoreCallingIdentity(callingIdentity); |
| 10370 | } |
| 10371 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10372 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10373 | private boolean updateFocusedWindowLocked(int mode) { |
| 10374 | WindowState newFocus = computeFocusedWindowLocked(); |
| 10375 | if (mCurrentFocus != newFocus) { |
| 10376 | // This check makes sure that we don't already have the focus |
| 10377 | // change message pending. |
| 10378 | mH.removeMessages(H.REPORT_FOCUS_CHANGE); |
| 10379 | mH.sendEmptyMessage(H.REPORT_FOCUS_CHANGE); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10380 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10381 | TAG, "Changing focus from " + mCurrentFocus + " to " + newFocus); |
| 10382 | final WindowState oldFocus = mCurrentFocus; |
| 10383 | mCurrentFocus = newFocus; |
| 10384 | mLosingFocus.remove(newFocus); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10385 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10386 | final WindowState imWindow = mInputMethodWindow; |
| 10387 | if (newFocus != imWindow && oldFocus != imWindow) { |
| The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 10388 | if (moveInputMethodWindowsIfNeededLocked( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10389 | mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS && |
| The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 10390 | mode != UPDATE_FOCUS_WILL_PLACE_SURFACES)) { |
| 10391 | mLayoutNeeded = true; |
| 10392 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10393 | if (mode == UPDATE_FOCUS_PLACING_SURFACES) { |
| 10394 | performLayoutLockedInner(); |
| The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 10395 | } else if (mode == UPDATE_FOCUS_WILL_PLACE_SURFACES) { |
| 10396 | // Client will do the layout, but we need to assign layers |
| 10397 | // for handleNewWindowLocked() below. |
| 10398 | assignLayersLocked(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10399 | } |
| 10400 | } |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 10401 | |
| 10402 | if (mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS) { |
| 10403 | // If we defer assigning layers, then the caller is responsible for |
| 10404 | // doing this part. |
| 10405 | finishUpdateFocusedWindowAfterAssignLayersLocked(); |
| The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 10406 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10407 | return true; |
| 10408 | } |
| 10409 | return false; |
| 10410 | } |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 10411 | |
| 10412 | private void finishUpdateFocusedWindowAfterAssignLayersLocked() { |
| Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 10413 | mInputMonitor.setInputFocusLw(mCurrentFocus); |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 10414 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10415 | |
| 10416 | private WindowState computeFocusedWindowLocked() { |
| 10417 | WindowState result = null; |
| 10418 | WindowState win; |
| 10419 | |
| 10420 | int i = mWindows.size() - 1; |
| 10421 | int nextAppIndex = mAppTokens.size()-1; |
| 10422 | WindowToken nextApp = nextAppIndex >= 0 |
| 10423 | ? mAppTokens.get(nextAppIndex) : null; |
| 10424 | |
| 10425 | while (i >= 0) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 10426 | win = mWindows.get(i); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10427 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10428 | if (localLOGV || DEBUG_FOCUS) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10429 | TAG, "Looking for focus: " + i |
| 10430 | + " = " + win |
| 10431 | + ", flags=" + win.mAttrs.flags |
| 10432 | + ", canReceive=" + win.canReceiveKeys()); |
| 10433 | |
| 10434 | AppWindowToken thisApp = win.mAppToken; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10435 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10436 | // If this window's application has been removed, just skip it. |
| 10437 | if (thisApp != null && thisApp.removed) { |
| 10438 | i--; |
| 10439 | continue; |
| 10440 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10441 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10442 | // If there is a focused app, don't allow focus to go to any |
| 10443 | // windows below it. If this is an application window, step |
| 10444 | // through the app tokens until we find its app. |
| 10445 | if (thisApp != null && nextApp != null && thisApp != nextApp |
| 10446 | && win.mAttrs.type != TYPE_APPLICATION_STARTING) { |
| 10447 | int origAppIndex = nextAppIndex; |
| 10448 | while (nextAppIndex > 0) { |
| 10449 | if (nextApp == mFocusedApp) { |
| 10450 | // Whoops, we are below the focused app... no focus |
| 10451 | // for you! |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10452 | if (localLOGV || DEBUG_FOCUS) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10453 | TAG, "Reached focused app: " + mFocusedApp); |
| 10454 | return null; |
| 10455 | } |
| 10456 | nextAppIndex--; |
| 10457 | nextApp = mAppTokens.get(nextAppIndex); |
| 10458 | if (nextApp == thisApp) { |
| 10459 | break; |
| 10460 | } |
| 10461 | } |
| 10462 | if (thisApp != nextApp) { |
| 10463 | // Uh oh, the app token doesn't exist! This shouldn't |
| 10464 | // happen, but if it does we can get totally hosed... |
| 10465 | // so restart at the original app. |
| 10466 | nextAppIndex = origAppIndex; |
| 10467 | nextApp = mAppTokens.get(nextAppIndex); |
| 10468 | } |
| 10469 | } |
| 10470 | |
| 10471 | // Dispatch to this window if it is wants key events. |
| 10472 | if (win.canReceiveKeys()) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10473 | if (DEBUG_FOCUS) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10474 | TAG, "Found focus @ " + i + " = " + win); |
| 10475 | result = win; |
| 10476 | break; |
| 10477 | } |
| 10478 | |
| 10479 | i--; |
| 10480 | } |
| 10481 | |
| 10482 | return result; |
| 10483 | } |
| 10484 | |
| 10485 | private void startFreezingDisplayLocked() { |
| 10486 | if (mDisplayFrozen) { |
| 10487 | return; |
| 10488 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10489 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10490 | mScreenFrozenLock.acquire(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10491 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10492 | long now = SystemClock.uptimeMillis(); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10493 | //Slog.i(TAG, "Freezing, gc pending: " + mFreezeGcPending + ", now " + now); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10494 | if (mFreezeGcPending != 0) { |
| 10495 | if (now > (mFreezeGcPending+1000)) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10496 | //Slog.i(TAG, "Gc! " + now + " > " + (mFreezeGcPending+1000)); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10497 | mH.removeMessages(H.FORCE_GC); |
| 10498 | Runtime.getRuntime().gc(); |
| 10499 | mFreezeGcPending = now; |
| 10500 | } |
| 10501 | } else { |
| 10502 | mFreezeGcPending = now; |
| 10503 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10504 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10505 | mDisplayFrozen = true; |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 10506 | |
| Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 10507 | mInputMonitor.freezeInputDispatchingLw(); |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 10508 | |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 10509 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
| 10510 | mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10511 | mNextAppTransitionPackage = null; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10512 | mAppTransitionReady = true; |
| 10513 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10514 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10515 | if (PROFILE_ORIENTATION) { |
| 10516 | File file = new File("/data/system/frozen"); |
| 10517 | Debug.startMethodTracing(file.toString(), 8 * 1024 * 1024); |
| 10518 | } |
| 10519 | Surface.freezeDisplay(0); |
| 10520 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10521 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10522 | private void stopFreezingDisplayLocked() { |
| 10523 | if (!mDisplayFrozen) { |
| 10524 | return; |
| 10525 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10526 | |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 10527 | if (mWaitingForConfig || mAppsFreezingScreen > 0 || mWindowsFreezingScreen) { |
| 10528 | return; |
| 10529 | } |
| 10530 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10531 | mDisplayFrozen = false; |
| 10532 | mH.removeMessages(H.APP_FREEZE_TIMEOUT); |
| 10533 | if (PROFILE_ORIENTATION) { |
| 10534 | Debug.stopMethodTracing(); |
| 10535 | } |
| 10536 | Surface.unfreezeDisplay(0); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10537 | |
| Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 10538 | mInputMonitor.thawInputDispatchingLw(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10539 | |
| Christopher Tate | b696aee | 2010-04-02 19:08:30 -0700 | [diff] [blame] | 10540 | // While the display is frozen we don't re-compute the orientation |
| 10541 | // to avoid inconsistent states. However, something interesting |
| 10542 | // could have actually changed during that time so re-evaluate it |
| 10543 | // now to catch that. |
| 10544 | if (updateOrientationFromAppTokensLocked()) { |
| 10545 | mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION); |
| 10546 | } |
| 10547 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10548 | // A little kludge: a lot could have happened while the |
| 10549 | // display was frozen, so now that we are coming back we |
| 10550 | // do a gc so that any remote references the system |
| 10551 | // processes holds on others can be released if they are |
| 10552 | // no longer needed. |
| 10553 | mH.removeMessages(H.FORCE_GC); |
| 10554 | mH.sendMessageDelayed(mH.obtainMessage(H.FORCE_GC), |
| 10555 | 2000); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10556 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10557 | mScreenFrozenLock.release(); |
| 10558 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10559 | |
| Dianne Hackborn | b9fb170 | 2010-08-23 16:49:02 -0700 | [diff] [blame] | 10560 | static int getPropertyInt(String[] tokens, int index, int defUnits, int defDps, |
| 10561 | DisplayMetrics dm) { |
| 10562 | if (index < tokens.length) { |
| 10563 | String str = tokens[index]; |
| 10564 | if (str != null && str.length() > 0) { |
| 10565 | try { |
| 10566 | int val = Integer.parseInt(str); |
| 10567 | return val; |
| 10568 | } catch (Exception e) { |
| 10569 | } |
| 10570 | } |
| Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 10571 | } |
| 10572 | if (defUnits == TypedValue.COMPLEX_UNIT_PX) { |
| 10573 | return defDps; |
| 10574 | } |
| 10575 | int val = (int)TypedValue.applyDimension(defUnits, defDps, dm); |
| 10576 | return val; |
| 10577 | } |
| 10578 | |
| 10579 | class Watermark { |
| Dianne Hackborn | b9fb170 | 2010-08-23 16:49:02 -0700 | [diff] [blame] | 10580 | final String[] mTokens; |
| 10581 | final String mText; |
| 10582 | final Paint mTextPaint; |
| 10583 | final int mTextWidth; |
| 10584 | final int mTextHeight; |
| 10585 | final int mTextAscent; |
| 10586 | final int mTextDescent; |
| 10587 | final int mDeltaX; |
| 10588 | final int mDeltaY; |
| Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 10589 | |
| Dianne Hackborn | b9fb170 | 2010-08-23 16:49:02 -0700 | [diff] [blame] | 10590 | Surface mSurface; |
| 10591 | int mLastDW; |
| 10592 | int mLastDH; |
| 10593 | boolean mDrawNeeded; |
| 10594 | |
| 10595 | Watermark(SurfaceSession session, String[] tokens) { |
| Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 10596 | final DisplayMetrics dm = new DisplayMetrics(); |
| 10597 | mDisplay.getMetrics(dm); |
| 10598 | |
| Dianne Hackborn | b9fb170 | 2010-08-23 16:49:02 -0700 | [diff] [blame] | 10599 | if (false) { |
| 10600 | Log.i(TAG, "*********************** WATERMARK"); |
| 10601 | for (int i=0; i<tokens.length; i++) { |
| 10602 | Log.i(TAG, " TOKEN #" + i + ": " + tokens[i]); |
| 10603 | } |
| 10604 | } |
| Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 10605 | |
| Dianne Hackborn | b9fb170 | 2010-08-23 16:49:02 -0700 | [diff] [blame] | 10606 | mTokens = tokens; |
| Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 10607 | |
| Dianne Hackborn | b9fb170 | 2010-08-23 16:49:02 -0700 | [diff] [blame] | 10608 | StringBuilder builder = new StringBuilder(32); |
| 10609 | int len = mTokens[0].length(); |
| 10610 | len = len & ~1; |
| 10611 | for (int i=0; i<len; i+=2) { |
| 10612 | int c1 = mTokens[0].charAt(i); |
| 10613 | int c2 = mTokens[0].charAt(i+1); |
| 10614 | if (c1 >= 'a' && c1 <= 'f') c1 = c1 - 'a' + 10; |
| 10615 | else if (c1 >= 'A' && c1 <= 'F') c1 = c1 - 'A' + 10; |
| 10616 | else c1 -= '0'; |
| 10617 | if (c2 >= 'a' && c2 <= 'f') c2 = c2 - 'a' + 10; |
| 10618 | else if (c2 >= 'A' && c2 <= 'F') c2 = c2 - 'A' + 10; |
| 10619 | else c2 -= '0'; |
| 10620 | builder.append((char)(255-((c1*16)+c2))); |
| 10621 | } |
| 10622 | mText = builder.toString(); |
| 10623 | if (false) { |
| 10624 | Log.i(TAG, "Final text: " + mText); |
| 10625 | } |
| 10626 | |
| 10627 | int fontSize = getPropertyInt(tokens, 1, |
| 10628 | TypedValue.COMPLEX_UNIT_DIP, 20, dm); |
| 10629 | |
| 10630 | mTextPaint = new Paint(Paint.ANTI_ALIAS_FLAG); |
| 10631 | mTextPaint.setTextSize(fontSize); |
| 10632 | mTextPaint.setTypeface(Typeface.create(Typeface.SANS_SERIF, Typeface.BOLD)); |
| 10633 | |
| 10634 | FontMetricsInt fm = mTextPaint.getFontMetricsInt(); |
| 10635 | mTextWidth = (int)mTextPaint.measureText(mText); |
| 10636 | mTextAscent = fm.ascent; |
| 10637 | mTextDescent = fm.descent; |
| 10638 | mTextHeight = fm.descent - fm.ascent; |
| 10639 | |
| 10640 | mDeltaX = getPropertyInt(tokens, 2, |
| 10641 | TypedValue.COMPLEX_UNIT_PX, mTextWidth*2, dm); |
| 10642 | mDeltaY = getPropertyInt(tokens, 3, |
| 10643 | TypedValue.COMPLEX_UNIT_PX, mTextHeight*3, dm); |
| 10644 | int shadowColor = getPropertyInt(tokens, 4, |
| 10645 | TypedValue.COMPLEX_UNIT_PX, 0xb0000000, dm); |
| 10646 | int color = getPropertyInt(tokens, 5, |
| 10647 | TypedValue.COMPLEX_UNIT_PX, 0x60ffffff, dm); |
| 10648 | int shadowRadius = getPropertyInt(tokens, 6, |
| 10649 | TypedValue.COMPLEX_UNIT_PX, 7, dm); |
| 10650 | int shadowDx = getPropertyInt(tokens, 8, |
| 10651 | TypedValue.COMPLEX_UNIT_PX, 0, dm); |
| 10652 | int shadowDy = getPropertyInt(tokens, 9, |
| 10653 | TypedValue.COMPLEX_UNIT_PX, 0, dm); |
| 10654 | |
| 10655 | mTextPaint.setColor(color); |
| 10656 | mTextPaint.setShadowLayer(shadowRadius, shadowDx, shadowDy, shadowColor); |
| Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 10657 | |
| 10658 | try { |
| 10659 | mSurface = new Surface(session, 0, |
| Dianne Hackborn | b9fb170 | 2010-08-23 16:49:02 -0700 | [diff] [blame] | 10660 | "WatermarkSurface", -1, 1, 1, PixelFormat.TRANSLUCENT, 0); |
| Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 10661 | mSurface.setLayer(TYPE_LAYER_MULTIPLIER*100); |
| Dianne Hackborn | b9fb170 | 2010-08-23 16:49:02 -0700 | [diff] [blame] | 10662 | mSurface.setPosition(0, 0); |
| Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 10663 | mSurface.show(); |
| 10664 | } catch (OutOfResourcesException e) { |
| 10665 | } |
| 10666 | } |
| 10667 | |
| 10668 | void positionSurface(int dw, int dh) { |
| Dianne Hackborn | b9fb170 | 2010-08-23 16:49:02 -0700 | [diff] [blame] | 10669 | if (mLastDW != dw || mLastDH != dh) { |
| 10670 | mLastDW = dw; |
| 10671 | mLastDH = dh; |
| 10672 | mSurface.setSize(dw, dh); |
| 10673 | mDrawNeeded = true; |
| 10674 | } |
| 10675 | } |
| 10676 | |
| 10677 | void drawIfNeeded() { |
| 10678 | if (mDrawNeeded) { |
| 10679 | final int dw = mLastDW; |
| 10680 | final int dh = mLastDH; |
| 10681 | |
| 10682 | mDrawNeeded = false; |
| 10683 | Rect dirty = new Rect(0, 0, dw, dh); |
| 10684 | Canvas c = null; |
| 10685 | try { |
| 10686 | c = mSurface.lockCanvas(dirty); |
| 10687 | } catch (IllegalArgumentException e) { |
| 10688 | } catch (OutOfResourcesException e) { |
| 10689 | } |
| 10690 | if (c != null) { |
| 10691 | int deltaX = mDeltaX; |
| 10692 | int deltaY = mDeltaY; |
| 10693 | |
| 10694 | // deltaX shouldn't be close to a round fraction of our |
| 10695 | // x step, or else things will line up too much. |
| 10696 | int div = (dw+mTextWidth)/deltaX; |
| 10697 | int rem = (dw+mTextWidth) - (div*deltaX); |
| 10698 | int qdelta = deltaX/4; |
| 10699 | if (rem < qdelta || rem > (deltaX-qdelta)) { |
| 10700 | deltaX += deltaX/3; |
| 10701 | } |
| 10702 | |
| 10703 | int y = -mTextHeight; |
| 10704 | int x = -mTextWidth; |
| 10705 | while (y < (dh+mTextHeight)) { |
| 10706 | c.drawText(mText, x, y, mTextPaint); |
| 10707 | x += deltaX; |
| 10708 | if (x >= dw) { |
| 10709 | x -= (dw+mTextWidth); |
| 10710 | y += deltaY; |
| 10711 | } |
| 10712 | } |
| 10713 | mSurface.unlockCanvasAndPost(c); |
| 10714 | } |
| 10715 | } |
| Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 10716 | } |
| 10717 | } |
| 10718 | |
| 10719 | void createWatermark() { |
| 10720 | if (mWatermark != null) { |
| 10721 | return; |
| 10722 | } |
| 10723 | |
| Dianne Hackborn | b9fb170 | 2010-08-23 16:49:02 -0700 | [diff] [blame] | 10724 | File file = new File("/system/etc/setup.conf"); |
| 10725 | FileInputStream in = null; |
| 10726 | try { |
| 10727 | in = new FileInputStream(file); |
| 10728 | DataInputStream ind = new DataInputStream(in); |
| 10729 | String line = ind.readLine(); |
| 10730 | if (line != null) { |
| 10731 | String[] toks = line.split("%"); |
| 10732 | if (toks != null && toks.length > 0) { |
| 10733 | mWatermark = new Watermark(mFxSession, toks); |
| 10734 | } |
| 10735 | } |
| 10736 | } catch (FileNotFoundException e) { |
| 10737 | } catch (IOException e) { |
| 10738 | } finally { |
| 10739 | if (in != null) { |
| 10740 | try { |
| 10741 | in.close(); |
| 10742 | } catch (IOException e) { |
| 10743 | } |
| 10744 | } |
| Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 10745 | } |
| Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 10746 | } |
| 10747 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10748 | @Override |
| 10749 | public void dump(FileDescriptor fd, PrintWriter pw, String[] args) { |
| 10750 | if (mContext.checkCallingOrSelfPermission("android.permission.DUMP") |
| 10751 | != PackageManager.PERMISSION_GRANTED) { |
| 10752 | pw.println("Permission Denial: can't dump WindowManager from from pid=" |
| 10753 | + Binder.getCallingPid() |
| 10754 | + ", uid=" + Binder.getCallingUid()); |
| 10755 | return; |
| 10756 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10757 | |
| Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 10758 | mInputManager.dump(pw); |
| Dianne Hackborn | a2e9226 | 2010-03-02 17:19:29 -0800 | [diff] [blame] | 10759 | pw.println(" "); |
| 10760 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10761 | synchronized(mWindowMap) { |
| 10762 | pw.println("Current Window Manager state:"); |
| 10763 | for (int i=mWindows.size()-1; i>=0; i--) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 10764 | WindowState w = mWindows.get(i); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10765 | pw.print(" Window #"); pw.print(i); pw.print(' '); |
| 10766 | pw.print(w); pw.println(":"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10767 | w.dump(pw, " "); |
| 10768 | } |
| 10769 | if (mInputMethodDialogs.size() > 0) { |
| 10770 | pw.println(" "); |
| 10771 | pw.println(" Input method dialogs:"); |
| 10772 | for (int i=mInputMethodDialogs.size()-1; i>=0; i--) { |
| 10773 | WindowState w = mInputMethodDialogs.get(i); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10774 | 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] | 10775 | } |
| 10776 | } |
| 10777 | if (mPendingRemove.size() > 0) { |
| 10778 | pw.println(" "); |
| 10779 | pw.println(" Remove pending for:"); |
| 10780 | for (int i=mPendingRemove.size()-1; i>=0; i--) { |
| 10781 | WindowState w = mPendingRemove.get(i); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10782 | pw.print(" Remove #"); pw.print(i); pw.print(' '); |
| 10783 | pw.print(w); pw.println(":"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10784 | w.dump(pw, " "); |
| 10785 | } |
| 10786 | } |
| 10787 | if (mForceRemoves != null && mForceRemoves.size() > 0) { |
| 10788 | pw.println(" "); |
| 10789 | pw.println(" Windows force removing:"); |
| 10790 | for (int i=mForceRemoves.size()-1; i>=0; i--) { |
| 10791 | WindowState w = mForceRemoves.get(i); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10792 | pw.print(" Removing #"); pw.print(i); pw.print(' '); |
| 10793 | pw.print(w); pw.println(":"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10794 | w.dump(pw, " "); |
| 10795 | } |
| 10796 | } |
| 10797 | if (mDestroySurface.size() > 0) { |
| 10798 | pw.println(" "); |
| 10799 | pw.println(" Windows waiting to destroy their surface:"); |
| 10800 | for (int i=mDestroySurface.size()-1; i>=0; i--) { |
| 10801 | WindowState w = mDestroySurface.get(i); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10802 | pw.print(" Destroy #"); pw.print(i); pw.print(' '); |
| 10803 | pw.print(w); pw.println(":"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10804 | w.dump(pw, " "); |
| 10805 | } |
| 10806 | } |
| 10807 | if (mLosingFocus.size() > 0) { |
| 10808 | pw.println(" "); |
| 10809 | pw.println(" Windows losing focus:"); |
| 10810 | for (int i=mLosingFocus.size()-1; i>=0; i--) { |
| 10811 | WindowState w = mLosingFocus.get(i); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10812 | pw.print(" Losing #"); pw.print(i); pw.print(' '); |
| 10813 | pw.print(w); pw.println(":"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10814 | w.dump(pw, " "); |
| 10815 | } |
| 10816 | } |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 10817 | if (mResizingWindows.size() > 0) { |
| 10818 | pw.println(" "); |
| 10819 | pw.println(" Windows waiting to resize:"); |
| 10820 | for (int i=mResizingWindows.size()-1; i>=0; i--) { |
| 10821 | WindowState w = mResizingWindows.get(i); |
| 10822 | pw.print(" Resizing #"); pw.print(i); pw.print(' '); |
| 10823 | pw.print(w); pw.println(":"); |
| 10824 | w.dump(pw, " "); |
| 10825 | } |
| 10826 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10827 | if (mSessions.size() > 0) { |
| 10828 | pw.println(" "); |
| 10829 | pw.println(" All active sessions:"); |
| 10830 | Iterator<Session> it = mSessions.iterator(); |
| 10831 | while (it.hasNext()) { |
| 10832 | Session s = it.next(); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10833 | pw.print(" Session "); pw.print(s); pw.println(':'); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10834 | s.dump(pw, " "); |
| 10835 | } |
| 10836 | } |
| 10837 | if (mTokenMap.size() > 0) { |
| 10838 | pw.println(" "); |
| 10839 | pw.println(" All tokens:"); |
| 10840 | Iterator<WindowToken> it = mTokenMap.values().iterator(); |
| 10841 | while (it.hasNext()) { |
| 10842 | WindowToken token = it.next(); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10843 | pw.print(" Token "); pw.print(token.token); pw.println(':'); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10844 | token.dump(pw, " "); |
| 10845 | } |
| 10846 | } |
| 10847 | if (mTokenList.size() > 0) { |
| 10848 | pw.println(" "); |
| 10849 | pw.println(" Window token list:"); |
| 10850 | for (int i=0; i<mTokenList.size(); i++) { |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10851 | pw.print(" #"); pw.print(i); pw.print(": "); |
| 10852 | pw.println(mTokenList.get(i)); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10853 | } |
| 10854 | } |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 10855 | if (mWallpaperTokens.size() > 0) { |
| 10856 | pw.println(" "); |
| 10857 | pw.println(" Wallpaper tokens:"); |
| 10858 | for (int i=mWallpaperTokens.size()-1; i>=0; i--) { |
| 10859 | WindowToken token = mWallpaperTokens.get(i); |
| 10860 | pw.print(" Wallpaper #"); pw.print(i); |
| 10861 | pw.print(' '); pw.print(token); pw.println(':'); |
| 10862 | token.dump(pw, " "); |
| 10863 | } |
| 10864 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10865 | if (mAppTokens.size() > 0) { |
| 10866 | pw.println(" "); |
| 10867 | pw.println(" Application tokens in Z order:"); |
| 10868 | for (int i=mAppTokens.size()-1; i>=0; i--) { |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10869 | pw.print(" App #"); pw.print(i); pw.print(": "); |
| 10870 | pw.println(mAppTokens.get(i)); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10871 | } |
| 10872 | } |
| 10873 | if (mFinishedStarting.size() > 0) { |
| 10874 | pw.println(" "); |
| 10875 | pw.println(" Finishing start of application tokens:"); |
| 10876 | for (int i=mFinishedStarting.size()-1; i>=0; i--) { |
| 10877 | WindowToken token = mFinishedStarting.get(i); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10878 | pw.print(" Finished Starting #"); pw.print(i); |
| 10879 | pw.print(' '); pw.print(token); pw.println(':'); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10880 | token.dump(pw, " "); |
| 10881 | } |
| 10882 | } |
| 10883 | if (mExitingTokens.size() > 0) { |
| 10884 | pw.println(" "); |
| 10885 | pw.println(" Exiting tokens:"); |
| 10886 | for (int i=mExitingTokens.size()-1; i>=0; i--) { |
| 10887 | WindowToken token = mExitingTokens.get(i); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10888 | pw.print(" Exiting #"); pw.print(i); |
| 10889 | pw.print(' '); pw.print(token); pw.println(':'); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10890 | token.dump(pw, " "); |
| 10891 | } |
| 10892 | } |
| 10893 | if (mExitingAppTokens.size() > 0) { |
| 10894 | pw.println(" "); |
| 10895 | pw.println(" Exiting application tokens:"); |
| 10896 | for (int i=mExitingAppTokens.size()-1; i>=0; i--) { |
| 10897 | WindowToken token = mExitingAppTokens.get(i); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10898 | pw.print(" Exiting App #"); pw.print(i); |
| 10899 | pw.print(' '); pw.print(token); pw.println(':'); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10900 | token.dump(pw, " "); |
| 10901 | } |
| 10902 | } |
| 10903 | pw.println(" "); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10904 | pw.print(" mCurrentFocus="); pw.println(mCurrentFocus); |
| 10905 | pw.print(" mLastFocus="); pw.println(mLastFocus); |
| 10906 | pw.print(" mFocusedApp="); pw.println(mFocusedApp); |
| 10907 | pw.print(" mInputMethodTarget="); pw.println(mInputMethodTarget); |
| 10908 | pw.print(" mInputMethodWindow="); pw.println(mInputMethodWindow); |
| Dianne Hackborn | f21adf6 | 2009-08-13 10:20:21 -0700 | [diff] [blame] | 10909 | pw.print(" mWallpaperTarget="); pw.println(mWallpaperTarget); |
| Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 10910 | if (mLowerWallpaperTarget != null && mUpperWallpaperTarget != null) { |
| 10911 | pw.print(" mLowerWallpaperTarget="); pw.println(mLowerWallpaperTarget); |
| 10912 | pw.print(" mUpperWallpaperTarget="); pw.println(mUpperWallpaperTarget); |
| 10913 | } |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 10914 | pw.print(" mCurConfiguration="); pw.println(this.mCurConfiguration); |
| 10915 | pw.print(" mInTouchMode="); pw.print(mInTouchMode); |
| 10916 | pw.print(" mLayoutSeq="); pw.println(mLayoutSeq); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10917 | pw.print(" mSystemBooted="); pw.print(mSystemBooted); |
| 10918 | pw.print(" mDisplayEnabled="); pw.println(mDisplayEnabled); |
| 10919 | pw.print(" mLayoutNeeded="); pw.print(mLayoutNeeded); |
| 10920 | pw.print(" mBlurShown="); pw.println(mBlurShown); |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 10921 | if (mDimAnimator != null) { |
| 10922 | mDimAnimator.printTo(pw); |
| 10923 | } else { |
| Dianne Hackborn | a2e9226 | 2010-03-02 17:19:29 -0800 | [diff] [blame] | 10924 | pw.println( " no DimAnimator "); |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 10925 | } |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10926 | pw.print(" mInputMethodAnimLayerAdjustment="); |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 10927 | pw.print(mInputMethodAnimLayerAdjustment); |
| 10928 | pw.print(" mWallpaperAnimLayerAdjustment="); |
| 10929 | pw.println(mWallpaperAnimLayerAdjustment); |
| Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 10930 | pw.print(" mLastWallpaperX="); pw.print(mLastWallpaperX); |
| 10931 | pw.print(" mLastWallpaperY="); pw.println(mLastWallpaperY); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10932 | pw.print(" mDisplayFrozen="); pw.print(mDisplayFrozen); |
| 10933 | pw.print(" mWindowsFreezingScreen="); pw.print(mWindowsFreezingScreen); |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 10934 | pw.print(" mAppsFreezingScreen="); pw.print(mAppsFreezingScreen); |
| 10935 | pw.print(" mWaitingForConfig="); pw.println(mWaitingForConfig); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10936 | pw.print(" mRotation="); pw.print(mRotation); |
| 10937 | pw.print(", mForcedAppOrientation="); pw.print(mForcedAppOrientation); |
| 10938 | pw.print(", mRequestedRotation="); pw.println(mRequestedRotation); |
| 10939 | pw.print(" mAnimationPending="); pw.print(mAnimationPending); |
| 10940 | pw.print(" mWindowAnimationScale="); pw.print(mWindowAnimationScale); |
| 10941 | pw.print(" mTransitionWindowAnimationScale="); pw.println(mTransitionAnimationScale); |
| 10942 | pw.print(" mNextAppTransition=0x"); |
| 10943 | pw.print(Integer.toHexString(mNextAppTransition)); |
| 10944 | pw.print(", mAppTransitionReady="); pw.print(mAppTransitionReady); |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 10945 | pw.print(", mAppTransitionRunning="); pw.print(mAppTransitionRunning); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10946 | pw.print(", mAppTransitionTimeout="); pw.println( mAppTransitionTimeout); |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10947 | if (mNextAppTransitionPackage != null) { |
| 10948 | pw.print(" mNextAppTransitionPackage="); |
| 10949 | pw.print(mNextAppTransitionPackage); |
| 10950 | pw.print(", mNextAppTransitionEnter=0x"); |
| 10951 | pw.print(Integer.toHexString(mNextAppTransitionEnter)); |
| 10952 | pw.print(", mNextAppTransitionExit=0x"); |
| 10953 | pw.print(Integer.toHexString(mNextAppTransitionExit)); |
| 10954 | } |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10955 | pw.print(" mStartingIconInTransition="); pw.print(mStartingIconInTransition); |
| 10956 | pw.print(", mSkipAppTransitionAnimation="); pw.println(mSkipAppTransitionAnimation); |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10957 | if (mLastEnterAnimToken != null || mLastEnterAnimToken != null) { |
| 10958 | pw.print(" mLastEnterAnimToken="); pw.print(mLastEnterAnimToken); |
| 10959 | pw.print(", mLastEnterAnimParams="); pw.println(mLastEnterAnimParams); |
| 10960 | } |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10961 | if (mOpeningApps.size() > 0) { |
| 10962 | pw.print(" mOpeningApps="); pw.println(mOpeningApps); |
| 10963 | } |
| 10964 | if (mClosingApps.size() > 0) { |
| 10965 | pw.print(" mClosingApps="); pw.println(mClosingApps); |
| 10966 | } |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 10967 | if (mToTopApps.size() > 0) { |
| 10968 | pw.print(" mToTopApps="); pw.println(mToTopApps); |
| 10969 | } |
| 10970 | if (mToBottomApps.size() > 0) { |
| 10971 | pw.print(" mToBottomApps="); pw.println(mToBottomApps); |
| 10972 | } |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10973 | pw.print(" DisplayWidth="); pw.print(mDisplay.getWidth()); |
| 10974 | pw.print(" DisplayHeight="); pw.println(mDisplay.getHeight()); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10975 | } |
| 10976 | } |
| 10977 | |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 10978 | // 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] | 10979 | public void monitor() { |
| 10980 | synchronized (mWindowMap) { } |
| Mike Lockwood | 983ee09 | 2009-11-22 01:42:24 -0500 | [diff] [blame] | 10981 | synchronized (mKeyguardTokenWatcher) { } |
| Dianne Hackborn | ddca3ee | 2009-07-23 19:01:31 -0700 | [diff] [blame] | 10982 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10983 | |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 10984 | /** |
| 10985 | * DimAnimator class that controls the dim animation. This holds the surface and |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10986 | * all state used for dim animation. |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 10987 | */ |
| 10988 | private static class DimAnimator { |
| 10989 | Surface mDimSurface; |
| 10990 | boolean mDimShown = false; |
| 10991 | float mDimCurrentAlpha; |
| 10992 | float mDimTargetAlpha; |
| 10993 | float mDimDeltaPerMs; |
| 10994 | long mLastDimAnimTime; |
| Dianne Hackborn | f83c555 | 2010-03-31 22:19:32 -0700 | [diff] [blame] | 10995 | |
| 10996 | int mLastDimWidth, mLastDimHeight; |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 10997 | |
| 10998 | DimAnimator (SurfaceSession session) { |
| 10999 | if (mDimSurface == null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 11000 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11001 | + mDimSurface + ": CREATE"); |
| 11002 | try { |
| Mathias Agopian | 5d26c1e | 2010-03-01 16:09:43 -0800 | [diff] [blame] | 11003 | mDimSurface = new Surface(session, 0, |
| 11004 | "DimSurface", |
| 11005 | -1, 16, 16, PixelFormat.OPAQUE, |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11006 | Surface.FX_SURFACE_DIM); |
| Maciej Białka | 9ee5c22 | 2010-03-24 10:25:40 +0100 | [diff] [blame] | 11007 | mDimSurface.setAlpha(0.0f); |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11008 | } catch (Exception e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 11009 | Slog.e(TAG, "Exception creating Dim surface", e); |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11010 | } |
| 11011 | } |
| 11012 | } |
| 11013 | |
| 11014 | /** |
| 11015 | * Show the dim surface. |
| 11016 | */ |
| 11017 | void show(int dw, int dh) { |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 11018 | if (!mDimShown) { |
| 11019 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface + ": SHOW pos=(0,0) (" + |
| 11020 | dw + "x" + dh + ")"); |
| 11021 | mDimShown = true; |
| 11022 | try { |
| Dianne Hackborn | f83c555 | 2010-03-31 22:19:32 -0700 | [diff] [blame] | 11023 | mLastDimWidth = dw; |
| 11024 | mLastDimHeight = dh; |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 11025 | mDimSurface.setPosition(0, 0); |
| 11026 | mDimSurface.setSize(dw, dh); |
| 11027 | mDimSurface.show(); |
| 11028 | } catch (RuntimeException e) { |
| 11029 | Slog.w(TAG, "Failure showing dim surface", e); |
| 11030 | } |
| Dianne Hackborn | f83c555 | 2010-03-31 22:19:32 -0700 | [diff] [blame] | 11031 | } else if (mLastDimWidth != dw || mLastDimHeight != dh) { |
| 11032 | mLastDimWidth = dw; |
| 11033 | mLastDimHeight = dh; |
| 11034 | mDimSurface.setSize(dw, dh); |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11035 | } |
| 11036 | } |
| 11037 | |
| 11038 | /** |
| 11039 | * Set's the dim surface's layer and update dim parameters that will be used in |
| 11040 | * {@link updateSurface} after all windows are examined. |
| 11041 | */ |
| 11042 | void updateParameters(WindowState w, long currentTime) { |
| 11043 | mDimSurface.setLayer(w.mAnimLayer-1); |
| 11044 | |
| 11045 | final float target = w.mExiting ? 0 : w.mAttrs.dimAmount; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 11046 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 11047 | + ": layer=" + (w.mAnimLayer-1) + " target=" + target); |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11048 | if (mDimTargetAlpha != target) { |
| 11049 | // If the desired dim level has changed, then |
| 11050 | // start an animation to it. |
| 11051 | mLastDimAnimTime = currentTime; |
| 11052 | long duration = (w.mAnimating && w.mAnimation != null) |
| 11053 | ? w.mAnimation.computeDurationHint() |
| 11054 | : DEFAULT_DIM_DURATION; |
| 11055 | if (target > mDimTargetAlpha) { |
| 11056 | // This is happening behind the activity UI, |
| 11057 | // so we can make it run a little longer to |
| 11058 | // give a stronger impression without disrupting |
| 11059 | // the user. |
| 11060 | duration *= DIM_DURATION_MULTIPLIER; |
| 11061 | } |
| 11062 | if (duration < 1) { |
| 11063 | // Don't divide by zero |
| 11064 | duration = 1; |
| 11065 | } |
| 11066 | mDimTargetAlpha = target; |
| 11067 | mDimDeltaPerMs = (mDimTargetAlpha-mDimCurrentAlpha) / duration; |
| 11068 | } |
| 11069 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 11070 | |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11071 | /** |
| 11072 | * Updating the surface's alpha. Returns true if the animation continues, or returns |
| 11073 | * false when the animation is finished and the dim surface is hidden. |
| 11074 | */ |
| 11075 | boolean updateSurface(boolean dimming, long currentTime, boolean displayFrozen) { |
| 11076 | if (!dimming) { |
| 11077 | if (mDimTargetAlpha != 0) { |
| 11078 | mLastDimAnimTime = currentTime; |
| 11079 | mDimTargetAlpha = 0; |
| 11080 | mDimDeltaPerMs = (-mDimCurrentAlpha) / DEFAULT_DIM_DURATION; |
| 11081 | } |
| 11082 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 11083 | |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11084 | boolean animating = false; |
| 11085 | if (mLastDimAnimTime != 0) { |
| 11086 | mDimCurrentAlpha += mDimDeltaPerMs |
| 11087 | * (currentTime-mLastDimAnimTime); |
| 11088 | boolean more = true; |
| 11089 | if (displayFrozen) { |
| 11090 | // If the display is frozen, there is no reason to animate. |
| 11091 | more = false; |
| 11092 | } else if (mDimDeltaPerMs > 0) { |
| 11093 | if (mDimCurrentAlpha > mDimTargetAlpha) { |
| 11094 | more = false; |
| 11095 | } |
| 11096 | } else if (mDimDeltaPerMs < 0) { |
| 11097 | if (mDimCurrentAlpha < mDimTargetAlpha) { |
| 11098 | more = false; |
| 11099 | } |
| 11100 | } else { |
| 11101 | more = false; |
| 11102 | } |
| 11103 | |
| 11104 | // Do we need to continue animating? |
| 11105 | if (more) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 11106 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11107 | + mDimSurface + ": alpha=" + mDimCurrentAlpha); |
| 11108 | mLastDimAnimTime = currentTime; |
| 11109 | mDimSurface.setAlpha(mDimCurrentAlpha); |
| 11110 | animating = true; |
| 11111 | } else { |
| 11112 | mDimCurrentAlpha = mDimTargetAlpha; |
| 11113 | mLastDimAnimTime = 0; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 11114 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11115 | + mDimSurface + ": final alpha=" + mDimCurrentAlpha); |
| 11116 | mDimSurface.setAlpha(mDimCurrentAlpha); |
| 11117 | if (!dimming) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 11118 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11119 | + ": HIDE"); |
| 11120 | try { |
| 11121 | mDimSurface.hide(); |
| 11122 | } catch (RuntimeException e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 11123 | Slog.w(TAG, "Illegal argument exception hiding dim surface"); |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11124 | } |
| 11125 | mDimShown = false; |
| 11126 | } |
| 11127 | } |
| 11128 | } |
| 11129 | return animating; |
| 11130 | } |
| 11131 | |
| 11132 | public void printTo(PrintWriter pw) { |
| 11133 | pw.print(" mDimShown="); pw.print(mDimShown); |
| 11134 | pw.print(" current="); pw.print(mDimCurrentAlpha); |
| 11135 | pw.print(" target="); pw.print(mDimTargetAlpha); |
| 11136 | pw.print(" delta="); pw.print(mDimDeltaPerMs); |
| 11137 | pw.print(" lastAnimTime="); pw.println(mLastDimAnimTime); |
| 11138 | } |
| 11139 | } |
| 11140 | |
| 11141 | /** |
| 11142 | * Animation that fade in after 0.5 interpolate time, or fade out in reverse order. |
| 11143 | * This is used for opening/closing transition for apps in compatible mode. |
| 11144 | */ |
| 11145 | private static class FadeInOutAnimation extends Animation { |
| 11146 | int mWidth; |
| 11147 | boolean mFadeIn; |
| 11148 | |
| 11149 | public FadeInOutAnimation(boolean fadeIn) { |
| 11150 | setInterpolator(new AccelerateInterpolator()); |
| 11151 | setDuration(DEFAULT_FADE_IN_OUT_DURATION); |
| 11152 | mFadeIn = fadeIn; |
| 11153 | } |
| 11154 | |
| 11155 | @Override |
| 11156 | protected void applyTransformation(float interpolatedTime, Transformation t) { |
| 11157 | float x = interpolatedTime; |
| 11158 | if (!mFadeIn) { |
| 11159 | x = 1.0f - x; // reverse the interpolation for fade out |
| 11160 | } |
| 11161 | if (x < 0.5) { |
| 11162 | // move the window out of the screen. |
| 11163 | t.getMatrix().setTranslate(mWidth, 0); |
| 11164 | } else { |
| 11165 | t.getMatrix().setTranslate(0, 0);// show |
| 11166 | t.setAlpha((x - 0.5f) * 2); |
| 11167 | } |
| 11168 | } |
| 11169 | |
| 11170 | @Override |
| 11171 | public void initialize(int width, int height, int parentWidth, int parentHeight) { |
| 11172 | // width is the screen width {@see AppWindowToken#stepAnimatinoLocked} |
| 11173 | mWidth = width; |
| 11174 | } |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11175 | |
| 11176 | @Override |
| Mitsuru Oshima | 5a2b91d | 2009-07-16 16:30:02 -0700 | [diff] [blame] | 11177 | public int getZAdjustment() { |
| 11178 | return Animation.ZORDER_TOP; |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11179 | } |
| 11180 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11181 | } |