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 | 46b9ac0 | 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 | 46b9ac0 | 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 | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 491 | PowerManager.WakeLock mHoldingScreenWakeLock; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 492 | |
Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 493 | boolean mTurnOnScreen; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 494 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 495 | /** |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 496 | * Drag/drop state |
| 497 | */ |
| 498 | class DragState { |
| 499 | IBinder mToken; |
| 500 | Surface mSurface; |
| 501 | boolean mLocalOnly; |
| 502 | ClipData mData; |
| 503 | ClipDescription mDataDescription; |
Chris Tate | d4533f14 | 2010-10-19 15:15:08 -0700 | [diff] [blame^] | 504 | boolean mDragResult; |
Chris Tate | b478f46 | 2010-10-15 16:02:26 -0700 | [diff] [blame] | 505 | float mCurrentX, mCurrentY; |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 506 | float mThumbOffsetX, mThumbOffsetY; |
| 507 | InputChannel mServerChannel, mClientChannel; |
| 508 | WindowState mTargetWindow; |
| 509 | ArrayList<WindowState> mNotifiedWindows; |
Christopher Tate | 5ada6cb | 2010-10-05 14:15:29 -0700 | [diff] [blame] | 510 | boolean mDragInProgress; |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 511 | |
| 512 | private final Rect tmpRect = new Rect(); |
| 513 | |
| 514 | DragState(IBinder token, Surface surface, boolean localOnly) { |
| 515 | mToken = token; |
| 516 | mSurface = surface; |
| 517 | mLocalOnly = localOnly; |
| 518 | mNotifiedWindows = new ArrayList<WindowState>(); |
| 519 | } |
| 520 | |
| 521 | void reset() { |
| 522 | if (mSurface != null) { |
| 523 | mSurface.destroy(); |
| 524 | } |
| 525 | mSurface = null; |
| 526 | mLocalOnly = false; |
| 527 | mToken = null; |
| 528 | mData = null; |
| 529 | mThumbOffsetX = mThumbOffsetY = 0; |
| 530 | mNotifiedWindows = null; |
| 531 | } |
| 532 | |
| 533 | void register() { |
| 534 | if (DEBUG_DRAG) Slog.d(TAG, "registering drag input channel"); |
| 535 | if (mClientChannel != null) { |
| 536 | Slog.e(TAG, "Duplicate register of drag input channel"); |
| 537 | } else { |
| 538 | InputChannel[] channels = InputChannel.openInputChannelPair("drag"); |
| 539 | mServerChannel = channels[0]; |
| 540 | mClientChannel = channels[1]; |
| 541 | mInputManager.registerInputChannel(mServerChannel); |
| 542 | InputQueue.registerInputChannel(mClientChannel, mDragInputHandler, |
| 543 | mH.getLooper().getQueue()); |
| 544 | } |
| 545 | } |
| 546 | |
| 547 | void unregister() { |
| 548 | if (DEBUG_DRAG) Slog.d(TAG, "unregistering drag input channel"); |
| 549 | if (mClientChannel == null) { |
| 550 | Slog.e(TAG, "Unregister of nonexistent drag input channel"); |
| 551 | } else { |
| 552 | mInputManager.unregisterInputChannel(mServerChannel); |
| 553 | InputQueue.unregisterInputChannel(mClientChannel); |
| 554 | mClientChannel.dispose(); |
| 555 | mClientChannel = null; |
| 556 | mServerChannel = null; |
| 557 | } |
| 558 | } |
| 559 | |
Chris Tate | a32dcf7 | 2010-10-14 12:13:50 -0700 | [diff] [blame] | 560 | int getDragLayerLw() { |
| 561 | return mPolicy.windowTypeToLayerLw(WindowManager.LayoutParams.TYPE_DRAG) |
| 562 | * TYPE_LAYER_MULTIPLIER |
| 563 | + TYPE_LAYER_OFFSET; |
| 564 | } |
| 565 | |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 566 | /* call out to each visible window/session informing it about the drag |
| 567 | */ |
Chris Tate | b8203e9 | 2010-10-12 14:23:21 -0700 | [diff] [blame] | 568 | void broadcastDragStartedLw(final float touchX, final float touchY) { |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 569 | // Cache a base-class instance of the clip metadata so that parceling |
| 570 | // works correctly in calling out to the apps. |
| 571 | mDataDescription = new ClipDescription(mData); |
| 572 | mNotifiedWindows.clear(); |
Christopher Tate | 5ada6cb | 2010-10-05 14:15:29 -0700 | [diff] [blame] | 573 | mDragInProgress = true; |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 574 | |
| 575 | if (DEBUG_DRAG) { |
Chris Tate | b478f46 | 2010-10-15 16:02:26 -0700 | [diff] [blame] | 576 | Slog.d(TAG, "broadcasting DRAG_STARTED at (" + touchX + ", " + touchY + ")"); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 577 | } |
| 578 | |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 579 | final int N = mWindows.size(); |
| 580 | for (int i = 0; i < N; i++) { |
Chris Tate | b478f46 | 2010-10-15 16:02:26 -0700 | [diff] [blame] | 581 | sendDragStartedLw(mWindows.get(i), touchX, touchY, mDataDescription); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 582 | } |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 583 | } |
| 584 | |
| 585 | /* helper - send a caller-provided event, presumed to be DRAG_STARTED, if the |
| 586 | * designated window is potentially a drop recipient. There are race situations |
| 587 | * around DRAG_ENDED broadcast, so we make sure that once we've declared that |
| 588 | * 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] | 589 | * |
| 590 | * This method clones the 'event' parameter if it's being delivered to the same |
| 591 | * 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] | 592 | */ |
Chris Tate | b478f46 | 2010-10-15 16:02:26 -0700 | [diff] [blame] | 593 | private void sendDragStartedLw(WindowState newWin, float touchX, float touchY, |
| 594 | ClipDescription desc) { |
Christopher Tate | 5ada6cb | 2010-10-05 14:15:29 -0700 | [diff] [blame] | 595 | if (mDragInProgress && newWin.isPotentialDragTarget()) { |
Chris Tate | b478f46 | 2010-10-15 16:02:26 -0700 | [diff] [blame] | 596 | DragEvent event = DragEvent.obtain(DragEvent.ACTION_DRAG_STARTED, |
| 597 | touchX - newWin.mFrame.left, touchY - newWin.mFrame.top, |
Chris Tate | d4533f14 | 2010-10-19 15:15:08 -0700 | [diff] [blame^] | 598 | desc, null, false); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 599 | try { |
| 600 | newWin.mClient.dispatchDragEvent(event); |
| 601 | // track each window that we've notified that the drag is starting |
| 602 | mNotifiedWindows.add(newWin); |
| 603 | } catch (RemoteException e) { |
| 604 | Slog.w(TAG, "Unable to drag-start window " + newWin); |
Chris Tate | b478f46 | 2010-10-15 16:02:26 -0700 | [diff] [blame] | 605 | } finally { |
| 606 | // if the callee was local, the dispatch has already recycled the event |
| 607 | if (Process.myPid() != newWin.mSession.mPid) { |
| 608 | event.recycle(); |
| 609 | } |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 610 | } |
| 611 | } |
| 612 | } |
| 613 | |
| 614 | /* helper - construct and send a DRAG_STARTED event only if the window has not |
| 615 | * previously been notified, i.e. it became visible after the drag operation |
| 616 | * was begun. This is a rare case. |
| 617 | */ |
| 618 | private void sendDragStartedIfNeededLw(WindowState newWin) { |
Christopher Tate | 5ada6cb | 2010-10-05 14:15:29 -0700 | [diff] [blame] | 619 | if (mDragInProgress) { |
| 620 | // If we have sent the drag-started, we needn't do so again |
| 621 | for (WindowState ws : mNotifiedWindows) { |
| 622 | if (ws == newWin) { |
| 623 | return; |
| 624 | } |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 625 | } |
Christopher Tate | 5ada6cb | 2010-10-05 14:15:29 -0700 | [diff] [blame] | 626 | if (DEBUG_DRAG) { |
| 627 | Slog.d(TAG, "sending DRAG_STARTED to new window " + newWin); |
| 628 | } |
Chris Tate | b478f46 | 2010-10-15 16:02:26 -0700 | [diff] [blame] | 629 | sendDragStartedLw(newWin, mCurrentX, mCurrentY, mDataDescription); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 630 | } |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 631 | } |
| 632 | |
Chris Tate | d4533f14 | 2010-10-19 15:15:08 -0700 | [diff] [blame^] | 633 | void broadcastDragEndedLw() { |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 634 | if (DEBUG_DRAG) { |
| 635 | Slog.d(TAG, "broadcasting DRAG_ENDED"); |
| 636 | } |
Chris Tate | d4533f14 | 2010-10-19 15:15:08 -0700 | [diff] [blame^] | 637 | DragEvent evt = DragEvent.obtain(DragEvent.ACTION_DRAG_ENDED, |
| 638 | 0, 0, null, null, mDragResult); |
| 639 | for (WindowState ws: mNotifiedWindows) { |
| 640 | try { |
| 641 | ws.mClient.dispatchDragEvent(evt); |
| 642 | } catch (RemoteException e) { |
| 643 | Slog.w(TAG, "Unable to drag-end window " + ws); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 644 | } |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 645 | } |
Chris Tate | d4533f14 | 2010-10-19 15:15:08 -0700 | [diff] [blame^] | 646 | mNotifiedWindows.clear(); |
| 647 | mDragInProgress = false; |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 648 | evt.recycle(); |
| 649 | } |
| 650 | |
Chris Tate | d4533f14 | 2010-10-19 15:15:08 -0700 | [diff] [blame^] | 651 | void endDragLw() { |
| 652 | mDragState.broadcastDragEndedLw(); |
| 653 | |
| 654 | // stop intercepting input |
| 655 | mDragState.unregister(); |
| 656 | mInputMonitor.updateInputWindowsLw(); |
| 657 | |
| 658 | // free our resources and drop all the object references |
| 659 | mDragState.reset(); |
| 660 | mDragState = null; |
| 661 | } |
| 662 | |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 663 | void notifyMoveLw(float x, float y) { |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 664 | final int myPid = Process.myPid(); |
| 665 | |
| 666 | // Move the surface to the given touch |
| 667 | mSurface.openTransaction(); |
| 668 | mSurface.setPosition((int)(x - mThumbOffsetX), (int)(y - mThumbOffsetY)); |
| 669 | mSurface.closeTransaction(); |
| 670 | |
| 671 | // Tell the affected window |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 672 | WindowState touchedWin = getTouchedWinAtPointLw(x, y); |
| 673 | try { |
| 674 | // have we dragged over a new window? |
| 675 | if ((touchedWin != mTargetWindow) && (mTargetWindow != null)) { |
| 676 | if (DEBUG_DRAG) { |
| 677 | Slog.d(TAG, "sending DRAG_EXITED to " + mTargetWindow); |
| 678 | } |
| 679 | // force DRAG_EXITED_EVENT if appropriate |
| 680 | DragEvent evt = DragEvent.obtain(DragEvent.ACTION_DRAG_EXITED, |
Chris Tate | b478f46 | 2010-10-15 16:02:26 -0700 | [diff] [blame] | 681 | x - mTargetWindow.mFrame.left, y - mTargetWindow.mFrame.top, |
Chris Tate | d4533f14 | 2010-10-19 15:15:08 -0700 | [diff] [blame^] | 682 | null, null, false); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 683 | mTargetWindow.mClient.dispatchDragEvent(evt); |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 684 | if (myPid != mTargetWindow.mSession.mPid) { |
| 685 | evt.recycle(); |
| 686 | } |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 687 | } |
| 688 | if (touchedWin != null) { |
| 689 | if (DEBUG_DRAG) { |
| 690 | Slog.d(TAG, "sending DRAG_LOCATION to " + touchedWin); |
| 691 | } |
| 692 | DragEvent evt = DragEvent.obtain(DragEvent.ACTION_DRAG_LOCATION, |
Chris Tate | b478f46 | 2010-10-15 16:02:26 -0700 | [diff] [blame] | 693 | x - touchedWin.mFrame.left, y - touchedWin.mFrame.top, |
Chris Tate | d4533f14 | 2010-10-19 15:15:08 -0700 | [diff] [blame^] | 694 | null, null, false); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 695 | touchedWin.mClient.dispatchDragEvent(evt); |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 696 | if (myPid != touchedWin.mSession.mPid) { |
| 697 | evt.recycle(); |
| 698 | } |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 699 | } |
| 700 | } catch (RemoteException e) { |
| 701 | Slog.w(TAG, "can't send drag notification to windows"); |
| 702 | } |
| 703 | mTargetWindow = touchedWin; |
| 704 | } |
| 705 | |
Chris Tate | d4533f14 | 2010-10-19 15:15:08 -0700 | [diff] [blame^] | 706 | // Tell the drop target about the data. Returns 'true' if we can immediately |
| 707 | // dispatch the global drag-ended message, 'false' if we need to wait for a |
| 708 | // result from the recipient. |
| 709 | boolean notifyDropLw(float x, float y) { |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 710 | WindowState touchedWin = getTouchedWinAtPointLw(x, y); |
Chris Tate | d4533f14 | 2010-10-19 15:15:08 -0700 | [diff] [blame^] | 711 | if (touchedWin == null) { |
| 712 | // "drop" outside a valid window -- no recipient to apply a |
| 713 | // timeout to, and we can send the drag-ended message immediately. |
| 714 | mDragResult = false; |
| 715 | return true; |
| 716 | } |
| 717 | |
| 718 | if (DEBUG_DRAG) { |
| 719 | Slog.d(TAG, "sending DROP to " + touchedWin); |
| 720 | } |
| 721 | final int myPid = Process.myPid(); |
| 722 | final IBinder token = touchedWin.mClient.asBinder(); |
| 723 | DragEvent evt = DragEvent.obtain(DragEvent.ACTION_DROP, |
| 724 | x - touchedWin.mFrame.left, y - touchedWin.mFrame.top, |
| 725 | null, mData, false); |
| 726 | try { |
| 727 | touchedWin.mClient.dispatchDragEvent(evt); |
| 728 | |
| 729 | // 5 second timeout for this window to respond to the drop |
| 730 | mH.removeMessages(H.DRAG_END_TIMEOUT, token); |
| 731 | Message msg = mH.obtainMessage(H.DRAG_END_TIMEOUT, token); |
| 732 | mH.sendMessageDelayed(msg, 5000); |
| 733 | } catch (RemoteException e) { |
| 734 | Slog.w(TAG, "can't send drop notification to win " + touchedWin); |
| 735 | return true; |
| 736 | } finally { |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 737 | if (myPid != touchedWin.mSession.mPid) { |
| 738 | evt.recycle(); |
| 739 | } |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 740 | } |
Chris Tate | d4533f14 | 2010-10-19 15:15:08 -0700 | [diff] [blame^] | 741 | mToken = token; |
| 742 | return false; |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 743 | } |
| 744 | |
| 745 | // Find the visible, touch-deliverable window under the given point |
| 746 | private WindowState getTouchedWinAtPointLw(float xf, float yf) { |
| 747 | WindowState touchedWin = null; |
| 748 | final int x = (int) xf; |
| 749 | final int y = (int) yf; |
| 750 | final ArrayList<WindowState> windows = mWindows; |
| 751 | final int N = windows.size(); |
| 752 | for (int i = N - 1; i >= 0; i--) { |
| 753 | WindowState child = windows.get(i); |
| 754 | final int flags = child.mAttrs.flags; |
| 755 | if (!child.isVisibleLw()) { |
| 756 | // not visible == don't tell about drags |
| 757 | continue; |
| 758 | } |
| 759 | if ((flags & WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE) != 0) { |
| 760 | // not touchable == don't tell about drags |
| 761 | continue; |
| 762 | } |
| 763 | // account for the window's decor etc |
| 764 | tmpRect.set(child.mFrame); |
| 765 | if (child.mTouchableInsets == ViewTreeObserver |
| 766 | .InternalInsetsInfo.TOUCHABLE_INSETS_CONTENT) { |
| 767 | // The point is inside of the window if it is |
| 768 | // inside the frame, AND the content part of that |
| 769 | // frame that was given by the application. |
| 770 | tmpRect.left += child.mGivenContentInsets.left; |
| 771 | tmpRect.top += child.mGivenContentInsets.top; |
| 772 | tmpRect.right -= child.mGivenContentInsets.right; |
| 773 | tmpRect.bottom -= child.mGivenContentInsets.bottom; |
| 774 | } else if (child.mTouchableInsets == ViewTreeObserver |
| 775 | .InternalInsetsInfo.TOUCHABLE_INSETS_VISIBLE) { |
| 776 | // The point is inside of the window if it is |
| 777 | // inside the frame, AND the visible part of that |
| 778 | // frame that was given by the application. |
| 779 | tmpRect.left += child.mGivenVisibleInsets.left; |
| 780 | tmpRect.top += child.mGivenVisibleInsets.top; |
| 781 | tmpRect.right -= child.mGivenVisibleInsets.right; |
| 782 | tmpRect.bottom -= child.mGivenVisibleInsets.bottom; |
| 783 | } |
| 784 | final int touchFlags = flags & |
| 785 | (WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE |
| 786 | | WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL); |
| 787 | if (tmpRect.contains(x, y) || touchFlags == 0) { |
| 788 | // Found it |
| 789 | touchedWin = child; |
| 790 | break; |
| 791 | } |
| 792 | } |
| 793 | |
| 794 | return touchedWin; |
| 795 | } |
| 796 | } |
| 797 | |
| 798 | DragState mDragState = null; |
| 799 | private final InputHandler mDragInputHandler = new BaseInputHandler() { |
| 800 | @Override |
| 801 | public void handleMotion(MotionEvent event, Runnable finishedCallback) { |
| 802 | boolean endDrag = false; |
| 803 | final float newX = event.getRawX(); |
| 804 | final float newY = event.getRawY(); |
| 805 | |
| 806 | try { |
| 807 | if (mDragState != null) { |
| 808 | switch (event.getAction()) { |
| 809 | case MotionEvent.ACTION_DOWN: { |
| 810 | if (DEBUG_DRAG) { |
| 811 | Slog.w(TAG, "Unexpected ACTION_DOWN in drag layer"); |
| 812 | } |
| 813 | } break; |
| 814 | |
| 815 | case MotionEvent.ACTION_MOVE: { |
| 816 | synchronized (mWindowMap) { |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 817 | // move the surface and tell the involved window(s) where we are |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 818 | mDragState.notifyMoveLw(newX, newY); |
| 819 | } |
| 820 | } break; |
| 821 | |
| 822 | case MotionEvent.ACTION_UP: { |
| 823 | if (DEBUG_DRAG) Slog.d(TAG, "Got UP on move channel; dropping at " |
| 824 | + newX + "," + newY); |
| 825 | synchronized (mWindowMap) { |
Chris Tate | d4533f14 | 2010-10-19 15:15:08 -0700 | [diff] [blame^] | 826 | endDrag = mDragState.notifyDropLw(newX, newY); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 827 | } |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 828 | } break; |
| 829 | |
| 830 | case MotionEvent.ACTION_CANCEL: { |
| 831 | if (DEBUG_DRAG) Slog.d(TAG, "Drag cancelled!"); |
| 832 | endDrag = true; |
| 833 | } break; |
| 834 | } |
| 835 | |
| 836 | if (endDrag) { |
| 837 | if (DEBUG_DRAG) Slog.d(TAG, "Drag ended; tearing down state"); |
| 838 | // tell all the windows that the drag has ended |
Chris Tate | 5994359 | 2010-10-11 20:33:44 -0700 | [diff] [blame] | 839 | synchronized (mWindowMap) { |
Chris Tate | d4533f14 | 2010-10-19 15:15:08 -0700 | [diff] [blame^] | 840 | mDragState.endDragLw(); |
Chris Tate | 5994359 | 2010-10-11 20:33:44 -0700 | [diff] [blame] | 841 | } |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 842 | } |
| 843 | } |
| 844 | } catch (Exception e) { |
| 845 | Slog.e(TAG, "Exception caught by drag handleMotion", e); |
| 846 | } finally { |
| 847 | finishedCallback.run(); |
| 848 | } |
| 849 | } |
| 850 | }; |
| 851 | |
| 852 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 853 | * Whether the UI is currently running in touch mode (not showing |
| 854 | * navigational focus because the user is directly pressing the screen). |
| 855 | */ |
| 856 | boolean mInTouchMode = false; |
| 857 | |
| 858 | private ViewServer mViewServer; |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 859 | private ArrayList<WindowChangeListener> mWindowChangeListeners = |
| 860 | new ArrayList<WindowChangeListener>(); |
| 861 | private boolean mWindowsChanged = false; |
| 862 | |
| 863 | public interface WindowChangeListener { |
| 864 | public void windowsChanged(); |
Konstantin Lopyrev | 6e0f65f | 2010-07-14 14:55:33 -0700 | [diff] [blame] | 865 | public void focusChanged(); |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 866 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 867 | |
Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 868 | final Configuration mTempConfiguration = new Configuration(); |
Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 869 | int mScreenLayout = Configuration.SCREENLAYOUT_SIZE_UNDEFINED; |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 870 | |
| 871 | // The frame use to limit the size of the app running in compatibility mode. |
| 872 | Rect mCompatibleScreenFrame = new Rect(); |
| 873 | // The surface used to fill the outer rim of the app running in compatibility mode. |
| 874 | Surface mBackgroundFillerSurface = null; |
| 875 | boolean mBackgroundFillerShown = false; |
| 876 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 877 | public static WindowManagerService main(Context context, |
| 878 | PowerManagerService pm, boolean haveInputMethods) { |
| 879 | WMThread thr = new WMThread(context, pm, haveInputMethods); |
| 880 | thr.start(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 881 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 882 | synchronized (thr) { |
| 883 | while (thr.mService == null) { |
| 884 | try { |
| 885 | thr.wait(); |
| 886 | } catch (InterruptedException e) { |
| 887 | } |
| 888 | } |
| 889 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 890 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 891 | return thr.mService; |
| 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 | static class WMThread extends Thread { |
| 895 | WindowManagerService mService; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 896 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 897 | private final Context mContext; |
| 898 | private final PowerManagerService mPM; |
| 899 | private final boolean mHaveInputMethods; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 900 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 901 | public WMThread(Context context, PowerManagerService pm, |
| 902 | boolean haveInputMethods) { |
| 903 | super("WindowManager"); |
| 904 | mContext = context; |
| 905 | mPM = pm; |
| 906 | mHaveInputMethods = haveInputMethods; |
| 907 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 908 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 909 | public void run() { |
| 910 | Looper.prepare(); |
| 911 | WindowManagerService s = new WindowManagerService(mContext, mPM, |
| 912 | mHaveInputMethods); |
| 913 | android.os.Process.setThreadPriority( |
| 914 | android.os.Process.THREAD_PRIORITY_DISPLAY); |
Christopher Tate | 160edb3 | 2010-06-30 17:46:30 -0700 | [diff] [blame] | 915 | android.os.Process.setCanSelfBackground(false); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 916 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 917 | synchronized (this) { |
| 918 | mService = s; |
| 919 | notifyAll(); |
| 920 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 921 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 922 | Looper.loop(); |
| 923 | } |
| 924 | } |
| 925 | |
| 926 | static class PolicyThread extends Thread { |
| 927 | private final WindowManagerPolicy mPolicy; |
| 928 | private final WindowManagerService mService; |
| 929 | private final Context mContext; |
| 930 | private final PowerManagerService mPM; |
| 931 | boolean mRunning = false; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 932 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 933 | public PolicyThread(WindowManagerPolicy policy, |
| 934 | WindowManagerService service, Context context, |
| 935 | PowerManagerService pm) { |
| 936 | super("WindowManagerPolicy"); |
| 937 | mPolicy = policy; |
| 938 | mService = service; |
| 939 | mContext = context; |
| 940 | mPM = pm; |
| 941 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 942 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 943 | public void run() { |
| 944 | Looper.prepare(); |
Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 945 | WindowManagerPolicyThread.set(this, Looper.myLooper()); |
| 946 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 947 | //Looper.myLooper().setMessageLogging(new LogPrinter( |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 948 | // Log.VERBOSE, "WindowManagerPolicy", Log.LOG_ID_SYSTEM)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 949 | android.os.Process.setThreadPriority( |
| 950 | android.os.Process.THREAD_PRIORITY_FOREGROUND); |
Christopher Tate | 160edb3 | 2010-06-30 17:46:30 -0700 | [diff] [blame] | 951 | android.os.Process.setCanSelfBackground(false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 952 | mPolicy.init(mContext, mService, mPM); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 953 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 954 | synchronized (this) { |
| 955 | mRunning = true; |
| 956 | notifyAll(); |
| 957 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 958 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 959 | Looper.loop(); |
| 960 | } |
| 961 | } |
| 962 | |
| 963 | private WindowManagerService(Context context, PowerManagerService pm, |
| 964 | boolean haveInputMethods) { |
| 965 | mContext = context; |
| 966 | mHaveInputMethods = haveInputMethods; |
| 967 | mLimitedAlphaCompositing = context.getResources().getBoolean( |
| 968 | com.android.internal.R.bool.config_sf_limitedAlpha); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 969 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 970 | mPowerManager = pm; |
| 971 | mPowerManager.setPolicy(mPolicy); |
| 972 | PowerManager pmc = (PowerManager)context.getSystemService(Context.POWER_SERVICE); |
| 973 | mScreenFrozenLock = pmc.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, |
| 974 | "SCREEN_FROZEN"); |
| 975 | mScreenFrozenLock.setReferenceCounted(false); |
| 976 | |
| 977 | mActivityManager = ActivityManagerNative.getDefault(); |
| 978 | mBatteryStats = BatteryStatsService.getService(); |
| 979 | |
| 980 | // Get persisted window scale setting |
| 981 | mWindowAnimationScale = Settings.System.getFloat(context.getContentResolver(), |
| 982 | Settings.System.WINDOW_ANIMATION_SCALE, mWindowAnimationScale); |
| 983 | mTransitionAnimationScale = Settings.System.getFloat(context.getContentResolver(), |
| 984 | Settings.System.TRANSITION_ANIMATION_SCALE, mTransitionAnimationScale); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 985 | |
Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 986 | // Track changes to DevicePolicyManager state so we can enable/disable keyguard. |
| 987 | IntentFilter filter = new IntentFilter(); |
| 988 | filter.addAction(DevicePolicyManager.ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED); |
| 989 | mContext.registerReceiver(mBroadcastReceiver, filter); |
| 990 | |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 991 | mHoldingScreenWakeLock = pmc.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK, |
| 992 | "KEEP_SCREEN_ON_FLAG"); |
| 993 | mHoldingScreenWakeLock.setReferenceCounted(false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 994 | |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 995 | mInputManager = new InputManager(context, this); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 996 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 997 | PolicyThread thr = new PolicyThread(mPolicy, this, context, pm); |
| 998 | thr.start(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 999 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1000 | synchronized (thr) { |
| 1001 | while (!thr.mRunning) { |
| 1002 | try { |
| 1003 | thr.wait(); |
| 1004 | } catch (InterruptedException e) { |
| 1005 | } |
| 1006 | } |
| 1007 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1008 | |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 1009 | mInputManager.start(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1010 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1011 | // Add ourself to the Watchdog monitors. |
| 1012 | Watchdog.getInstance().addMonitor(this); |
| 1013 | } |
| 1014 | |
| 1015 | @Override |
| 1016 | public boolean onTransact(int code, Parcel data, Parcel reply, int flags) |
| 1017 | throws RemoteException { |
| 1018 | try { |
| 1019 | return super.onTransact(code, data, reply, flags); |
| 1020 | } catch (RuntimeException e) { |
| 1021 | // The window manager only throws security exceptions, so let's |
| 1022 | // log all others. |
| 1023 | if (!(e instanceof SecurityException)) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1024 | Slog.e(TAG, "Window Manager Crash", e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1025 | } |
| 1026 | throw e; |
| 1027 | } |
| 1028 | } |
| 1029 | |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1030 | private void placeWindowAfter(WindowState pos, WindowState window) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1031 | final int i = mWindows.indexOf(pos); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1032 | if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1033 | TAG, "Adding window " + window + " at " |
| 1034 | + (i+1) + " of " + mWindows.size() + " (after " + pos + ")"); |
| 1035 | mWindows.add(i+1, window); |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 1036 | mWindowsChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1037 | } |
| 1038 | |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1039 | private void placeWindowBefore(WindowState pos, WindowState window) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1040 | final int i = mWindows.indexOf(pos); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1041 | if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1042 | TAG, "Adding window " + window + " at " |
| 1043 | + i + " of " + mWindows.size() + " (before " + pos + ")"); |
| 1044 | mWindows.add(i, window); |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 1045 | mWindowsChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1046 | } |
| 1047 | |
| 1048 | //This method finds out the index of a window that has the same app token as |
| 1049 | //win. used for z ordering the windows in mWindows |
| 1050 | private int findIdxBasedOnAppTokens(WindowState win) { |
| 1051 | //use a local variable to cache mWindows |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1052 | ArrayList<WindowState> localmWindows = mWindows; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1053 | int jmax = localmWindows.size(); |
| 1054 | if(jmax == 0) { |
| 1055 | return -1; |
| 1056 | } |
| 1057 | for(int j = (jmax-1); j >= 0; j--) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1058 | WindowState wentry = localmWindows.get(j); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1059 | if(wentry.mAppToken == win.mAppToken) { |
| 1060 | return j; |
| 1061 | } |
| 1062 | } |
| 1063 | return -1; |
| 1064 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1065 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1066 | private void addWindowToListInOrderLocked(WindowState win, boolean addToToken) { |
| 1067 | final IWindow client = win.mClient; |
| 1068 | final WindowToken token = win.mToken; |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1069 | final ArrayList<WindowState> localmWindows = mWindows; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1070 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1071 | final int N = localmWindows.size(); |
| 1072 | final WindowState attached = win.mAttachedWindow; |
| 1073 | int i; |
| 1074 | if (attached == null) { |
| 1075 | int tokenWindowsPos = token.windows.size(); |
| 1076 | if (token.appWindowToken != null) { |
| 1077 | int index = tokenWindowsPos-1; |
| 1078 | if (index >= 0) { |
| 1079 | // If this application has existing windows, we |
| 1080 | // simply place the new window on top of them... but |
| 1081 | // keep the starting window on top. |
| 1082 | if (win.mAttrs.type == TYPE_BASE_APPLICATION) { |
| 1083 | // Base windows go behind everything else. |
| 1084 | placeWindowBefore(token.windows.get(0), win); |
| 1085 | tokenWindowsPos = 0; |
| 1086 | } else { |
| 1087 | AppWindowToken atoken = win.mAppToken; |
| 1088 | if (atoken != null && |
| 1089 | token.windows.get(index) == atoken.startingWindow) { |
| 1090 | placeWindowBefore(token.windows.get(index), win); |
| 1091 | tokenWindowsPos--; |
| 1092 | } else { |
| 1093 | int newIdx = findIdxBasedOnAppTokens(win); |
| 1094 | if(newIdx != -1) { |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1095 | //there is a window above this one associated with the same |
| 1096 | //apptoken note that the window could be a floating window |
| 1097 | //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] | 1098 | //windows associated with this token. |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1099 | if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v( |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 1100 | TAG, "Adding window " + win + " at " |
| 1101 | + (newIdx+1) + " of " + N); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1102 | localmWindows.add(newIdx+1, win); |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 1103 | mWindowsChanged = true; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1104 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1105 | } |
| 1106 | } |
| 1107 | } else { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1108 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1109 | TAG, "Figuring out where to add app window " |
| 1110 | + client.asBinder() + " (token=" + token + ")"); |
| 1111 | // Figure out where the window should go, based on the |
| 1112 | // order of applications. |
| 1113 | final int NA = mAppTokens.size(); |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1114 | WindowState pos = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1115 | for (i=NA-1; i>=0; i--) { |
| 1116 | AppWindowToken t = mAppTokens.get(i); |
| 1117 | if (t == token) { |
| 1118 | i--; |
| 1119 | break; |
| 1120 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1121 | |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 1122 | // We haven't reached the token yet; if this token |
| 1123 | // is not going to the bottom and has windows, we can |
| 1124 | // use it as an anchor for when we do reach the token. |
| 1125 | if (!t.sendingToBottom && t.windows.size() > 0) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1126 | pos = t.windows.get(0); |
| 1127 | } |
| 1128 | } |
| 1129 | // We now know the index into the apps. If we found |
| 1130 | // an app window above, that gives us the position; else |
| 1131 | // we need to look some more. |
| 1132 | if (pos != null) { |
| 1133 | // Move behind any windows attached to this one. |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1134 | WindowToken atoken = mTokenMap.get(pos.mClient.asBinder()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1135 | if (atoken != null) { |
| 1136 | final int NC = atoken.windows.size(); |
| 1137 | if (NC > 0) { |
| 1138 | WindowState bottom = atoken.windows.get(0); |
| 1139 | if (bottom.mSubLayer < 0) { |
| 1140 | pos = bottom; |
| 1141 | } |
| 1142 | } |
| 1143 | } |
| 1144 | placeWindowBefore(pos, win); |
| 1145 | } else { |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 1146 | // Continue looking down until we find the first |
| 1147 | // token that has windows. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1148 | while (i >= 0) { |
| 1149 | AppWindowToken t = mAppTokens.get(i); |
| 1150 | final int NW = t.windows.size(); |
| 1151 | if (NW > 0) { |
| 1152 | pos = t.windows.get(NW-1); |
| 1153 | break; |
| 1154 | } |
| 1155 | i--; |
| 1156 | } |
| 1157 | if (pos != null) { |
| 1158 | // Move in front of any windows attached to this |
| 1159 | // one. |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1160 | WindowToken atoken = mTokenMap.get(pos.mClient.asBinder()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1161 | if (atoken != null) { |
| 1162 | final int NC = atoken.windows.size(); |
| 1163 | if (NC > 0) { |
| 1164 | WindowState top = atoken.windows.get(NC-1); |
| 1165 | if (top.mSubLayer >= 0) { |
| 1166 | pos = top; |
| 1167 | } |
| 1168 | } |
| 1169 | } |
| 1170 | placeWindowAfter(pos, win); |
| 1171 | } else { |
| 1172 | // Just search for the start of this layer. |
| 1173 | final int myLayer = win.mBaseLayer; |
| 1174 | for (i=0; i<N; i++) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1175 | WindowState w = localmWindows.get(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1176 | if (w.mBaseLayer > myLayer) { |
| 1177 | break; |
| 1178 | } |
| 1179 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1180 | if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v( |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 1181 | TAG, "Adding window " + win + " at " |
| 1182 | + i + " of " + N); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1183 | localmWindows.add(i, win); |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 1184 | mWindowsChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1185 | } |
| 1186 | } |
| 1187 | } |
| 1188 | } else { |
| 1189 | // Figure out where window should go, based on layer. |
| 1190 | final int myLayer = win.mBaseLayer; |
| 1191 | for (i=N-1; i>=0; i--) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1192 | if (localmWindows.get(i).mBaseLayer <= myLayer) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1193 | i++; |
| 1194 | break; |
| 1195 | } |
| 1196 | } |
| 1197 | if (i < 0) i = 0; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1198 | if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT) Slog.v( |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 1199 | TAG, "Adding window " + win + " at " |
| 1200 | + i + " of " + N); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1201 | localmWindows.add(i, win); |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 1202 | mWindowsChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1203 | } |
| 1204 | if (addToToken) { |
| 1205 | token.windows.add(tokenWindowsPos, win); |
| 1206 | } |
| 1207 | |
| 1208 | } else { |
| 1209 | // Figure out this window's ordering relative to the window |
| 1210 | // it is attached to. |
| 1211 | final int NA = token.windows.size(); |
| 1212 | final int sublayer = win.mSubLayer; |
| 1213 | int largestSublayer = Integer.MIN_VALUE; |
| 1214 | WindowState windowWithLargestSublayer = null; |
| 1215 | for (i=0; i<NA; i++) { |
| 1216 | WindowState w = token.windows.get(i); |
| 1217 | final int wSublayer = w.mSubLayer; |
| 1218 | if (wSublayer >= largestSublayer) { |
| 1219 | largestSublayer = wSublayer; |
| 1220 | windowWithLargestSublayer = w; |
| 1221 | } |
| 1222 | if (sublayer < 0) { |
| 1223 | // For negative sublayers, we go below all windows |
| 1224 | // in the same sublayer. |
| 1225 | if (wSublayer >= sublayer) { |
| 1226 | if (addToToken) { |
| 1227 | token.windows.add(i, win); |
| 1228 | } |
| 1229 | placeWindowBefore( |
| 1230 | wSublayer >= 0 ? attached : w, win); |
| 1231 | break; |
| 1232 | } |
| 1233 | } else { |
| 1234 | // For positive sublayers, we go above all windows |
| 1235 | // in the same sublayer. |
| 1236 | if (wSublayer > sublayer) { |
| 1237 | if (addToToken) { |
| 1238 | token.windows.add(i, win); |
| 1239 | } |
| 1240 | placeWindowBefore(w, win); |
| 1241 | break; |
| 1242 | } |
| 1243 | } |
| 1244 | } |
| 1245 | if (i >= NA) { |
| 1246 | if (addToToken) { |
| 1247 | token.windows.add(win); |
| 1248 | } |
| 1249 | if (sublayer < 0) { |
| 1250 | placeWindowBefore(attached, win); |
| 1251 | } else { |
| 1252 | placeWindowAfter(largestSublayer >= 0 |
| 1253 | ? windowWithLargestSublayer |
| 1254 | : attached, |
| 1255 | win); |
| 1256 | } |
| 1257 | } |
| 1258 | } |
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 | if (win.mAppToken != null && addToToken) { |
| 1261 | win.mAppToken.allAppWindows.add(win); |
| 1262 | } |
| 1263 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1264 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1265 | static boolean canBeImeTarget(WindowState w) { |
| 1266 | final int fl = w.mAttrs.flags |
| 1267 | & (FLAG_NOT_FOCUSABLE|FLAG_ALT_FOCUSABLE_IM); |
| 1268 | if (fl == 0 || fl == (FLAG_NOT_FOCUSABLE|FLAG_ALT_FOCUSABLE_IM)) { |
| 1269 | return w.isVisibleOrAdding(); |
| 1270 | } |
| 1271 | return false; |
| 1272 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1273 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1274 | int findDesiredInputMethodWindowIndexLocked(boolean willMove) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1275 | final ArrayList<WindowState> localmWindows = mWindows; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1276 | final int N = localmWindows.size(); |
| 1277 | WindowState w = null; |
| 1278 | int i = N; |
| 1279 | while (i > 0) { |
| 1280 | i--; |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1281 | w = localmWindows.get(i); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1282 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1283 | //Slog.i(TAG, "Checking window @" + i + " " + w + " fl=0x" |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1284 | // + Integer.toHexString(w.mAttrs.flags)); |
| 1285 | if (canBeImeTarget(w)) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1286 | //Slog.i(TAG, "Putting input method here!"); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1287 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1288 | // Yet more tricksyness! If this window is a "starting" |
| 1289 | // window, we do actually want to be on top of it, but |
| 1290 | // it is not -really- where input will go. So if the caller |
| 1291 | // is not actually looking to move the IME, look down below |
| 1292 | // for a real window to target... |
| 1293 | if (!willMove |
| 1294 | && w.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING |
| 1295 | && i > 0) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1296 | WindowState wb = localmWindows.get(i-1); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1297 | if (wb.mAppToken == w.mAppToken && canBeImeTarget(wb)) { |
| 1298 | i--; |
| 1299 | w = wb; |
| 1300 | } |
| 1301 | } |
| 1302 | break; |
| 1303 | } |
| 1304 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1305 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1306 | mUpcomingInputMethodTarget = w; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1307 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1308 | 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] | 1309 | + w + " willMove=" + willMove); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1310 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1311 | if (willMove && w != null) { |
| 1312 | final WindowState curTarget = mInputMethodTarget; |
| 1313 | if (curTarget != null && curTarget.mAppToken != null) { |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1314 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1315 | // Now some fun for dealing with window animations that |
| 1316 | // modify the Z order. We need to look at all windows below |
| 1317 | // the current target that are in this app, finding the highest |
| 1318 | // visible one in layering. |
| 1319 | AppWindowToken token = curTarget.mAppToken; |
| 1320 | WindowState highestTarget = null; |
| 1321 | int highestPos = 0; |
| 1322 | if (token.animating || token.animation != null) { |
| 1323 | int pos = 0; |
| 1324 | pos = localmWindows.indexOf(curTarget); |
| 1325 | while (pos >= 0) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1326 | WindowState win = localmWindows.get(pos); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1327 | if (win.mAppToken != token) { |
| 1328 | break; |
| 1329 | } |
| 1330 | if (!win.mRemoved) { |
| 1331 | if (highestTarget == null || win.mAnimLayer > |
| 1332 | highestTarget.mAnimLayer) { |
| 1333 | highestTarget = win; |
| 1334 | highestPos = pos; |
| 1335 | } |
| 1336 | } |
| 1337 | pos--; |
| 1338 | } |
| 1339 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1340 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1341 | if (highestTarget != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1342 | if (DEBUG_INPUT_METHOD) Slog.v(TAG, "mNextAppTransition=" |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1343 | + mNextAppTransition + " " + highestTarget |
| 1344 | + " animating=" + highestTarget.isAnimating() |
| 1345 | + " layer=" + highestTarget.mAnimLayer |
| 1346 | + " new layer=" + w.mAnimLayer); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1347 | |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 1348 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1349 | // If we are currently setting up for an animation, |
| 1350 | // hold everything until we can find out what will happen. |
| 1351 | mInputMethodTargetWaitingAnim = true; |
| 1352 | mInputMethodTarget = highestTarget; |
| 1353 | return highestPos + 1; |
| 1354 | } else if (highestTarget.isAnimating() && |
| 1355 | highestTarget.mAnimLayer > w.mAnimLayer) { |
| 1356 | // If the window we are currently targeting is involved |
| 1357 | // with an animation, and it is on top of the next target |
| 1358 | // we will be over, then hold off on moving until |
| 1359 | // that is done. |
| 1360 | mInputMethodTarget = highestTarget; |
| 1361 | return highestPos + 1; |
| 1362 | } |
| 1363 | } |
| 1364 | } |
| 1365 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1366 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1367 | //Slog.i(TAG, "Placing input method @" + (i+1)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1368 | if (w != null) { |
| 1369 | if (willMove) { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 1370 | if (DEBUG_INPUT_METHOD) { |
| 1371 | RuntimeException e = null; |
| 1372 | if (!HIDE_STACK_CRAWLS) { |
| 1373 | e = new RuntimeException(); |
| 1374 | e.fillInStackTrace(); |
| 1375 | } |
| 1376 | Slog.w(TAG, "Moving IM target from " |
| 1377 | + mInputMethodTarget + " to " + w, e); |
| 1378 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1379 | mInputMethodTarget = w; |
| 1380 | if (w.mAppToken != null) { |
| 1381 | setInputMethodAnimLayerAdjustment(w.mAppToken.animLayerAdjustment); |
| 1382 | } else { |
| 1383 | setInputMethodAnimLayerAdjustment(0); |
| 1384 | } |
| 1385 | } |
| 1386 | return i+1; |
| 1387 | } |
| 1388 | if (willMove) { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 1389 | if (DEBUG_INPUT_METHOD) { |
| 1390 | RuntimeException e = null; |
| 1391 | if (!HIDE_STACK_CRAWLS) { |
| 1392 | e = new RuntimeException(); |
| 1393 | e.fillInStackTrace(); |
| 1394 | } |
| 1395 | Slog.w(TAG, "Moving IM target from " |
| 1396 | + mInputMethodTarget + " to null", e); |
| 1397 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1398 | mInputMethodTarget = null; |
| 1399 | setInputMethodAnimLayerAdjustment(0); |
| 1400 | } |
| 1401 | return -1; |
| 1402 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1403 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1404 | void addInputMethodWindowToListLocked(WindowState win) { |
| 1405 | int pos = findDesiredInputMethodWindowIndexLocked(true); |
| 1406 | if (pos >= 0) { |
| 1407 | win.mTargetAppToken = mInputMethodTarget.mAppToken; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1408 | if (DEBUG_WINDOW_MOVEMENT) Slog.v( |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 1409 | TAG, "Adding input method window " + win + " at " + pos); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1410 | mWindows.add(pos, win); |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 1411 | mWindowsChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1412 | moveInputMethodDialogsLocked(pos+1); |
| 1413 | return; |
| 1414 | } |
| 1415 | win.mTargetAppToken = null; |
| 1416 | addWindowToListInOrderLocked(win, true); |
| 1417 | moveInputMethodDialogsLocked(pos); |
| 1418 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1419 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1420 | void setInputMethodAnimLayerAdjustment(int adj) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1421 | 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] | 1422 | mInputMethodAnimLayerAdjustment = adj; |
| 1423 | WindowState imw = mInputMethodWindow; |
| 1424 | if (imw != null) { |
| 1425 | imw.mAnimLayer = imw.mLayer + adj; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1426 | if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + imw |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1427 | + " anim layer: " + imw.mAnimLayer); |
| 1428 | int wi = imw.mChildWindows.size(); |
| 1429 | while (wi > 0) { |
| 1430 | wi--; |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1431 | WindowState cw = imw.mChildWindows.get(wi); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1432 | cw.mAnimLayer = cw.mLayer + adj; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1433 | if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + cw |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1434 | + " anim layer: " + cw.mAnimLayer); |
| 1435 | } |
| 1436 | } |
| 1437 | int di = mInputMethodDialogs.size(); |
| 1438 | while (di > 0) { |
| 1439 | di --; |
| 1440 | imw = mInputMethodDialogs.get(di); |
| 1441 | imw.mAnimLayer = imw.mLayer + adj; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1442 | if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + imw |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1443 | + " anim layer: " + imw.mAnimLayer); |
| 1444 | } |
| 1445 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1446 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1447 | private int tmpRemoveWindowLocked(int interestingPos, WindowState win) { |
| 1448 | int wpos = mWindows.indexOf(win); |
| 1449 | if (wpos >= 0) { |
| 1450 | if (wpos < interestingPos) interestingPos--; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1451 | 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] | 1452 | mWindows.remove(wpos); |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 1453 | mWindowsChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1454 | int NC = win.mChildWindows.size(); |
| 1455 | while (NC > 0) { |
| 1456 | NC--; |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1457 | WindowState cw = win.mChildWindows.get(NC); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1458 | int cpos = mWindows.indexOf(cw); |
| 1459 | if (cpos >= 0) { |
| 1460 | if (cpos < interestingPos) interestingPos--; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1461 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Temp removing child at " |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 1462 | + cpos + ": " + cw); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1463 | mWindows.remove(cpos); |
| 1464 | } |
| 1465 | } |
| 1466 | } |
| 1467 | return interestingPos; |
| 1468 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1469 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1470 | private void reAddWindowToListInOrderLocked(WindowState win) { |
| 1471 | addWindowToListInOrderLocked(win, false); |
| 1472 | // This is a hack to get all of the child windows added as well |
| 1473 | // at the right position. Child windows should be rare and |
| 1474 | // this case should be rare, so it shouldn't be that big a deal. |
| 1475 | int wpos = mWindows.indexOf(win); |
| 1476 | if (wpos >= 0) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1477 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "ReAdd removing from " + wpos |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 1478 | + ": " + win); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1479 | mWindows.remove(wpos); |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 1480 | mWindowsChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1481 | reAddWindowLocked(wpos, win); |
| 1482 | } |
| 1483 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1484 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1485 | void logWindowList(String prefix) { |
| 1486 | int N = mWindows.size(); |
| 1487 | while (N > 0) { |
| 1488 | N--; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1489 | Slog.v(TAG, prefix + "#" + N + ": " + mWindows.get(N)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1490 | } |
| 1491 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1492 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1493 | void moveInputMethodDialogsLocked(int pos) { |
| 1494 | ArrayList<WindowState> dialogs = mInputMethodDialogs; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1495 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1496 | final int N = dialogs.size(); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1497 | 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] | 1498 | for (int i=0; i<N; i++) { |
| 1499 | pos = tmpRemoveWindowLocked(pos, dialogs.get(i)); |
| 1500 | } |
| 1501 | if (DEBUG_INPUT_METHOD) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1502 | Slog.v(TAG, "Window list w/pos=" + pos); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1503 | logWindowList(" "); |
| 1504 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1505 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1506 | if (pos >= 0) { |
| 1507 | final AppWindowToken targetAppToken = mInputMethodTarget.mAppToken; |
| 1508 | if (pos < mWindows.size()) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1509 | WindowState wp = mWindows.get(pos); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1510 | if (wp == mInputMethodWindow) { |
| 1511 | pos++; |
| 1512 | } |
| 1513 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1514 | 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] | 1515 | for (int i=0; i<N; i++) { |
| 1516 | WindowState win = dialogs.get(i); |
| 1517 | win.mTargetAppToken = targetAppToken; |
| 1518 | pos = reAddWindowLocked(pos, win); |
| 1519 | } |
| 1520 | if (DEBUG_INPUT_METHOD) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1521 | Slog.v(TAG, "Final window list:"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1522 | logWindowList(" "); |
| 1523 | } |
| 1524 | return; |
| 1525 | } |
| 1526 | for (int i=0; i<N; i++) { |
| 1527 | WindowState win = dialogs.get(i); |
| 1528 | win.mTargetAppToken = null; |
| 1529 | reAddWindowToListInOrderLocked(win); |
| 1530 | if (DEBUG_INPUT_METHOD) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1531 | Slog.v(TAG, "No IM target, final list:"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1532 | logWindowList(" "); |
| 1533 | } |
| 1534 | } |
| 1535 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1536 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1537 | boolean moveInputMethodWindowsIfNeededLocked(boolean needAssignLayers) { |
| 1538 | final WindowState imWin = mInputMethodWindow; |
| 1539 | final int DN = mInputMethodDialogs.size(); |
| 1540 | if (imWin == null && DN == 0) { |
| 1541 | return false; |
| 1542 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1543 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1544 | int imPos = findDesiredInputMethodWindowIndexLocked(true); |
| 1545 | if (imPos >= 0) { |
| 1546 | // In this case, the input method windows are to be placed |
| 1547 | // immediately above the window they are targeting. |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1548 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1549 | // First check to see if the input method windows are already |
| 1550 | // located here, and contiguous. |
| 1551 | final int N = mWindows.size(); |
| 1552 | WindowState firstImWin = imPos < N |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1553 | ? mWindows.get(imPos) : null; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1554 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1555 | // Figure out the actual input method window that should be |
| 1556 | // at the bottom of their stack. |
| 1557 | WindowState baseImWin = imWin != null |
| 1558 | ? imWin : mInputMethodDialogs.get(0); |
| 1559 | if (baseImWin.mChildWindows.size() > 0) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1560 | WindowState cw = baseImWin.mChildWindows.get(0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1561 | if (cw.mSubLayer < 0) baseImWin = cw; |
| 1562 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1563 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1564 | if (firstImWin == baseImWin) { |
| 1565 | // The windows haven't moved... but are they still contiguous? |
| 1566 | // First find the top IM window. |
| 1567 | int pos = imPos+1; |
| 1568 | while (pos < N) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1569 | if (!(mWindows.get(pos)).mIsImWindow) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1570 | break; |
| 1571 | } |
| 1572 | pos++; |
| 1573 | } |
| 1574 | pos++; |
| 1575 | // Now there should be no more input method windows above. |
| 1576 | while (pos < N) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1577 | if ((mWindows.get(pos)).mIsImWindow) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1578 | break; |
| 1579 | } |
| 1580 | pos++; |
| 1581 | } |
| 1582 | if (pos >= N) { |
| 1583 | // All is good! |
| 1584 | return false; |
| 1585 | } |
| 1586 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1587 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1588 | if (imWin != null) { |
| 1589 | if (DEBUG_INPUT_METHOD) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1590 | Slog.v(TAG, "Moving IM from " + imPos); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1591 | logWindowList(" "); |
| 1592 | } |
| 1593 | imPos = tmpRemoveWindowLocked(imPos, imWin); |
| 1594 | if (DEBUG_INPUT_METHOD) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1595 | 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] | 1596 | logWindowList(" "); |
| 1597 | } |
| 1598 | imWin.mTargetAppToken = mInputMethodTarget.mAppToken; |
| 1599 | reAddWindowLocked(imPos, imWin); |
| 1600 | if (DEBUG_INPUT_METHOD) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1601 | Slog.v(TAG, "List after moving IM to " + imPos + ":"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1602 | logWindowList(" "); |
| 1603 | } |
| 1604 | if (DN > 0) moveInputMethodDialogsLocked(imPos+1); |
| 1605 | } else { |
| 1606 | moveInputMethodDialogsLocked(imPos); |
| 1607 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1608 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1609 | } else { |
| 1610 | // In this case, the input method windows go in a fixed layer, |
| 1611 | // because they aren't currently associated with a focus window. |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1612 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1613 | if (imWin != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1614 | 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] | 1615 | tmpRemoveWindowLocked(0, imWin); |
| 1616 | imWin.mTargetAppToken = null; |
| 1617 | reAddWindowToListInOrderLocked(imWin); |
| 1618 | if (DEBUG_INPUT_METHOD) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1619 | Slog.v(TAG, "List with no IM target:"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1620 | logWindowList(" "); |
| 1621 | } |
| 1622 | if (DN > 0) moveInputMethodDialogsLocked(-1);; |
| 1623 | } else { |
| 1624 | moveInputMethodDialogsLocked(-1);; |
| 1625 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1626 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1627 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1628 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1629 | if (needAssignLayers) { |
| 1630 | assignLayersLocked(); |
| 1631 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1632 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1633 | return true; |
| 1634 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1635 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1636 | void adjustInputMethodDialogsLocked() { |
| 1637 | moveInputMethodDialogsLocked(findDesiredInputMethodWindowIndexLocked(true)); |
| 1638 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1639 | |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 1640 | final boolean isWallpaperVisible(WindowState wallpaperTarget) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1641 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper vis: target obscured=" |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 1642 | + (wallpaperTarget != null ? Boolean.toString(wallpaperTarget.mObscured) : "??") |
| 1643 | + " anim=" + ((wallpaperTarget != null && wallpaperTarget.mAppToken != null) |
| 1644 | ? wallpaperTarget.mAppToken.animation : null) |
| 1645 | + " upper=" + mUpperWallpaperTarget |
| 1646 | + " lower=" + mLowerWallpaperTarget); |
| 1647 | return (wallpaperTarget != null |
| 1648 | && (!wallpaperTarget.mObscured || (wallpaperTarget.mAppToken != null |
| 1649 | && wallpaperTarget.mAppToken.animation != null))) |
| 1650 | || mUpperWallpaperTarget != null |
| 1651 | || mLowerWallpaperTarget != null; |
| 1652 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1653 | |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 1654 | static final int ADJUST_WALLPAPER_LAYERS_CHANGED = 1<<1; |
| 1655 | static final int ADJUST_WALLPAPER_VISIBILITY_CHANGED = 1<<2; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1656 | |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 1657 | int adjustWallpaperWindowsLocked() { |
| 1658 | int changed = 0; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1659 | |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1660 | final int dw = mDisplay.getWidth(); |
| 1661 | final int dh = mDisplay.getHeight(); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1662 | |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1663 | // First find top-most window that has asked to be on top of the |
| 1664 | // wallpaper; all wallpapers go behind it. |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1665 | final ArrayList<WindowState> localmWindows = mWindows; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1666 | int N = localmWindows.size(); |
| 1667 | WindowState w = null; |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1668 | WindowState foundW = null; |
| 1669 | int foundI = 0; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1670 | WindowState topCurW = null; |
| 1671 | int topCurI = 0; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1672 | int i = N; |
| 1673 | while (i > 0) { |
| 1674 | i--; |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1675 | w = localmWindows.get(i); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1676 | if ((w.mAttrs.type == WindowManager.LayoutParams.TYPE_WALLPAPER)) { |
| 1677 | if (topCurW == null) { |
| 1678 | topCurW = w; |
| 1679 | topCurI = i; |
| 1680 | } |
| 1681 | continue; |
| 1682 | } |
| 1683 | topCurW = null; |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1684 | if (w.mAppToken != null) { |
| 1685 | // If this window's app token is hidden and not animating, |
| 1686 | // it is of no interest to us. |
| 1687 | if (w.mAppToken.hidden && w.mAppToken.animation == null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1688 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1689 | "Skipping hidden or animating token: " + w); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1690 | topCurW = null; |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1691 | continue; |
| 1692 | } |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1693 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1694 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Win " + w + ": readyfordisplay=" |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1695 | + w.isReadyForDisplay() + " drawpending=" + w.mDrawPending |
| 1696 | + " commitdrawpending=" + w.mCommitDrawPending); |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1697 | if ((w.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0 && w.isReadyForDisplay() |
Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 1698 | && (mWallpaperTarget == w |
| 1699 | || (!w.mDrawPending && !w.mCommitDrawPending))) { |
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 | "Found wallpaper activity: #" + i + "=" + w); |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1702 | foundW = w; |
| 1703 | foundI = i; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1704 | if (w == mWallpaperTarget && ((w.mAppToken != null |
| 1705 | && w.mAppToken.animation != null) |
| 1706 | || w.mAnimation != null)) { |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1707 | // The current wallpaper target is animating, so we'll |
| 1708 | // look behind it for another possible target and figure |
| 1709 | // out what is going on below. |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1710 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Win " + w |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1711 | + ": token animating, looking behind."); |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1712 | continue; |
| 1713 | } |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1714 | break; |
| 1715 | } |
| 1716 | } |
| 1717 | |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 1718 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1719 | // If we are currently waiting for an app transition, and either |
| 1720 | // the current target or the next target are involved with it, |
| 1721 | // then hold off on doing anything with the wallpaper. |
| 1722 | // Note that we are checking here for just whether the target |
| 1723 | // is part of an app token... which is potentially overly aggressive |
| 1724 | // (the app token may not be involved in the transition), but good |
| 1725 | // enough (we'll just wait until whatever transition is pending |
| 1726 | // executes). |
| 1727 | if (mWallpaperTarget != null && mWallpaperTarget.mAppToken != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1728 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1729 | "Wallpaper not changing: waiting for app anim in current target"); |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 1730 | return 0; |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1731 | } |
| 1732 | if (foundW != null && foundW.mAppToken != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1733 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1734 | "Wallpaper not changing: waiting for app anim in found target"); |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 1735 | return 0; |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1736 | } |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1737 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1738 | |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1739 | if (mWallpaperTarget != foundW) { |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1740 | if (DEBUG_WALLPAPER) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1741 | Slog.v(TAG, "New wallpaper target: " + foundW |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1742 | + " oldTarget: " + mWallpaperTarget); |
| 1743 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1744 | |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1745 | mLowerWallpaperTarget = null; |
| 1746 | mUpperWallpaperTarget = null; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1747 | |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1748 | WindowState oldW = mWallpaperTarget; |
| 1749 | mWallpaperTarget = foundW; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1750 | |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1751 | // Now what is happening... if the current and new targets are |
| 1752 | // animating, then we are in our super special mode! |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1753 | if (foundW != null && oldW != null) { |
| 1754 | boolean oldAnim = oldW.mAnimation != null |
| 1755 | || (oldW.mAppToken != null && oldW.mAppToken.animation != null); |
| 1756 | boolean foundAnim = foundW.mAnimation != null |
| 1757 | || (foundW.mAppToken != null && foundW.mAppToken.animation != null); |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1758 | if (DEBUG_WALLPAPER) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1759 | Slog.v(TAG, "New animation: " + foundAnim |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1760 | + " old animation: " + oldAnim); |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1761 | } |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1762 | if (foundAnim && oldAnim) { |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1763 | int oldI = localmWindows.indexOf(oldW); |
| 1764 | if (DEBUG_WALLPAPER) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1765 | Slog.v(TAG, "New i: " + foundI + " old i: " + oldI); |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1766 | } |
| 1767 | if (oldI >= 0) { |
| 1768 | if (DEBUG_WALLPAPER) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1769 | Slog.v(TAG, "Animating wallpapers: old#" + oldI |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1770 | + "=" + oldW + "; new#" + foundI |
| 1771 | + "=" + foundW); |
| 1772 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1773 | |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1774 | // Set the new target correctly. |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1775 | if (foundW.mAppToken != null && foundW.mAppToken.hiddenRequested) { |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1776 | if (DEBUG_WALLPAPER) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1777 | Slog.v(TAG, "Old wallpaper still the target."); |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1778 | } |
| 1779 | mWallpaperTarget = oldW; |
| 1780 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1781 | |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1782 | // Now set the upper and lower wallpaper targets |
| 1783 | // correctly, and make sure that we are positioning |
| 1784 | // the wallpaper below the lower. |
| 1785 | if (foundI > oldI) { |
| 1786 | // The new target is on top of the old one. |
| 1787 | if (DEBUG_WALLPAPER) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1788 | Slog.v(TAG, "Found target above old target."); |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1789 | } |
| 1790 | mUpperWallpaperTarget = foundW; |
| 1791 | mLowerWallpaperTarget = oldW; |
| 1792 | foundW = oldW; |
| 1793 | foundI = oldI; |
| 1794 | } else { |
| 1795 | // The new target is below the old one. |
| 1796 | if (DEBUG_WALLPAPER) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1797 | Slog.v(TAG, "Found target below old target."); |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1798 | } |
| 1799 | mUpperWallpaperTarget = oldW; |
| 1800 | mLowerWallpaperTarget = foundW; |
| 1801 | } |
| 1802 | } |
| 1803 | } |
| 1804 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1805 | |
Dianne Hackborn | 6b1cb35 | 2009-09-28 18:27:26 -0700 | [diff] [blame] | 1806 | } else if (mLowerWallpaperTarget != null) { |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1807 | // Is it time to stop animating? |
Dianne Hackborn | 6b1cb35 | 2009-09-28 18:27:26 -0700 | [diff] [blame] | 1808 | boolean lowerAnimating = mLowerWallpaperTarget.mAnimation != null |
| 1809 | || (mLowerWallpaperTarget.mAppToken != null |
| 1810 | && mLowerWallpaperTarget.mAppToken.animation != null); |
| 1811 | boolean upperAnimating = mUpperWallpaperTarget.mAnimation != null |
| 1812 | || (mUpperWallpaperTarget.mAppToken != null |
| 1813 | && mUpperWallpaperTarget.mAppToken.animation != null); |
| 1814 | if (!lowerAnimating || !upperAnimating) { |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1815 | if (DEBUG_WALLPAPER) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1816 | Slog.v(TAG, "No longer animating wallpaper targets!"); |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1817 | } |
| 1818 | mLowerWallpaperTarget = null; |
| 1819 | mUpperWallpaperTarget = null; |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1820 | } |
| 1821 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1822 | |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1823 | boolean visible = foundW != null; |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 1824 | if (visible) { |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1825 | // The window is visible to the compositor... but is it visible |
| 1826 | // to the user? That is what the wallpaper cares about. |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 1827 | visible = isWallpaperVisible(foundW); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1828 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper visibility: " + visible); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1829 | |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1830 | // If the wallpaper target is animating, we may need to copy |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1831 | // its layer adjustment. Only do this if we are not transfering |
| 1832 | // between two wallpaper targets. |
| 1833 | mWallpaperAnimLayerAdjustment = |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1834 | (mLowerWallpaperTarget == null && foundW.mAppToken != null) |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1835 | ? foundW.mAppToken.animLayerAdjustment : 0; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1836 | |
Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 1837 | final int maxLayer = mPolicy.getMaxWallpaperLayer() |
| 1838 | * TYPE_LAYER_MULTIPLIER |
| 1839 | + TYPE_LAYER_OFFSET; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1840 | |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1841 | // Now w is the window we are supposed to be behind... but we |
| 1842 | // 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] | 1843 | // AND any starting window associated with it, AND below the |
| 1844 | // maximum layer the policy allows for wallpapers. |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1845 | while (foundI > 0) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1846 | WindowState wb = localmWindows.get(foundI-1); |
Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 1847 | if (wb.mBaseLayer < maxLayer && |
| 1848 | wb.mAttachedWindow != foundW && |
Pal Szasz | 73dc259 | 2010-09-03 11:46:26 +0200 | [diff] [blame] | 1849 | wb.mAttachedWindow != foundW.mAttachedWindow && |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1850 | (wb.mAttrs.type != TYPE_APPLICATION_STARTING || |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1851 | wb.mToken != foundW.mToken)) { |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1852 | // This window is not related to the previous one in any |
| 1853 | // interesting way, so stop here. |
| 1854 | break; |
| 1855 | } |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1856 | foundW = wb; |
| 1857 | foundI--; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1858 | } |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 1859 | } else { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1860 | if (DEBUG_WALLPAPER) Slog.v(TAG, "No wallpaper target"); |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1861 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1862 | |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1863 | if (foundW == null && topCurW != null) { |
| 1864 | // There is no wallpaper target, so it goes at the bottom. |
| 1865 | // We will assume it is the same place as last time, if known. |
| 1866 | foundW = topCurW; |
| 1867 | foundI = topCurI+1; |
| 1868 | } else { |
| 1869 | // Okay i is the position immediately above the wallpaper. Look at |
| 1870 | // what is below it for later. |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1871 | foundW = foundI > 0 ? localmWindows.get(foundI-1) : null; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1872 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1873 | |
Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 1874 | if (visible) { |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1875 | if (mWallpaperTarget.mWallpaperX >= 0) { |
| 1876 | mLastWallpaperX = mWallpaperTarget.mWallpaperX; |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 1877 | mLastWallpaperXStep = mWallpaperTarget.mWallpaperXStep; |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1878 | } |
| 1879 | if (mWallpaperTarget.mWallpaperY >= 0) { |
| 1880 | mLastWallpaperY = mWallpaperTarget.mWallpaperY; |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 1881 | mLastWallpaperYStep = mWallpaperTarget.mWallpaperYStep; |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1882 | } |
Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 1883 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1884 | |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1885 | // Start stepping backwards from here, ensuring that our wallpaper windows |
| 1886 | // are correctly placed. |
| 1887 | int curTokenIndex = mWallpaperTokens.size(); |
| 1888 | while (curTokenIndex > 0) { |
| 1889 | curTokenIndex--; |
| 1890 | WindowToken token = mWallpaperTokens.get(curTokenIndex); |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 1891 | if (token.hidden == visible) { |
| 1892 | changed |= ADJUST_WALLPAPER_VISIBILITY_CHANGED; |
| 1893 | token.hidden = !visible; |
| 1894 | // Need to do a layout to ensure the wallpaper now has the |
| 1895 | // correct size. |
| 1896 | mLayoutNeeded = true; |
| 1897 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1898 | |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1899 | int curWallpaperIndex = token.windows.size(); |
| 1900 | while (curWallpaperIndex > 0) { |
| 1901 | curWallpaperIndex--; |
| 1902 | WindowState wallpaper = token.windows.get(curWallpaperIndex); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1903 | |
Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 1904 | if (visible) { |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1905 | updateWallpaperOffsetLocked(wallpaper, dw, dh, false); |
Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 1906 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1907 | |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 1908 | // First, make sure the client has the current visibility |
| 1909 | // state. |
| 1910 | if (wallpaper.mWallpaperVisible != visible) { |
| 1911 | wallpaper.mWallpaperVisible = visible; |
| 1912 | try { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1913 | if (DEBUG_VISIBILITY || DEBUG_WALLPAPER) Slog.v(TAG, |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 1914 | "Setting visibility of wallpaper " + wallpaper |
| 1915 | + ": " + visible); |
| 1916 | wallpaper.mClient.dispatchAppVisibility(visible); |
| 1917 | } catch (RemoteException e) { |
| 1918 | } |
| 1919 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1920 | |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 1921 | wallpaper.mAnimLayer = wallpaper.mLayer + mWallpaperAnimLayerAdjustment; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1922 | if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper win " |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1923 | + wallpaper + " anim layer: " + wallpaper.mAnimLayer); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1924 | |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1925 | // First, if this window is at the current index, then all |
| 1926 | // is well. |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1927 | if (wallpaper == foundW) { |
| 1928 | foundI--; |
| 1929 | foundW = foundI > 0 |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1930 | ? localmWindows.get(foundI-1) : null; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1931 | continue; |
| 1932 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1933 | |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1934 | // The window didn't match... the current wallpaper window, |
| 1935 | // wherever it is, is in the wrong place, so make sure it is |
| 1936 | // not in the list. |
| 1937 | int oldIndex = localmWindows.indexOf(wallpaper); |
| 1938 | if (oldIndex >= 0) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1939 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Wallpaper removing at " |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 1940 | + oldIndex + ": " + wallpaper); |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1941 | localmWindows.remove(oldIndex); |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 1942 | mWindowsChanged = true; |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1943 | if (oldIndex < foundI) { |
| 1944 | foundI--; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1945 | } |
| 1946 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1947 | |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1948 | // Now stick it in. |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1949 | if (DEBUG_WALLPAPER || DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 1950 | "Moving wallpaper " + wallpaper |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1951 | + " from " + oldIndex + " to " + foundI); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1952 | |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1953 | localmWindows.add(foundI, wallpaper); |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 1954 | mWindowsChanged = true; |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 1955 | changed |= ADJUST_WALLPAPER_LAYERS_CHANGED; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1956 | } |
| 1957 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1958 | |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1959 | return changed; |
| 1960 | } |
| 1961 | |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 1962 | void setWallpaperAnimLayerAdjustmentLocked(int adj) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1963 | if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG, |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1964 | "Setting wallpaper layer adj to " + adj); |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 1965 | mWallpaperAnimLayerAdjustment = adj; |
| 1966 | int curTokenIndex = mWallpaperTokens.size(); |
| 1967 | while (curTokenIndex > 0) { |
| 1968 | curTokenIndex--; |
| 1969 | WindowToken token = mWallpaperTokens.get(curTokenIndex); |
| 1970 | int curWallpaperIndex = token.windows.size(); |
| 1971 | while (curWallpaperIndex > 0) { |
| 1972 | curWallpaperIndex--; |
| 1973 | WindowState wallpaper = token.windows.get(curWallpaperIndex); |
| 1974 | wallpaper.mAnimLayer = wallpaper.mLayer + adj; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1975 | if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper win " |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1976 | + wallpaper + " anim layer: " + wallpaper.mAnimLayer); |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 1977 | } |
| 1978 | } |
| 1979 | } |
| 1980 | |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1981 | boolean updateWallpaperOffsetLocked(WindowState wallpaperWin, int dw, int dh, |
| 1982 | boolean sync) { |
Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 1983 | boolean changed = false; |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1984 | boolean rawChanged = false; |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1985 | float wpx = mLastWallpaperX >= 0 ? mLastWallpaperX : 0.5f; |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 1986 | float wpxs = mLastWallpaperXStep >= 0 ? mLastWallpaperXStep : -1.0f; |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1987 | int availw = wallpaperWin.mFrame.right-wallpaperWin.mFrame.left-dw; |
| 1988 | int offset = availw > 0 ? -(int)(availw*wpx+.5f) : 0; |
| 1989 | changed = wallpaperWin.mXOffset != offset; |
| 1990 | if (changed) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1991 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Update wallpaper " |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1992 | + wallpaperWin + " x: " + offset); |
| 1993 | wallpaperWin.mXOffset = offset; |
| 1994 | } |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 1995 | if (wallpaperWin.mWallpaperX != wpx || wallpaperWin.mWallpaperXStep != wpxs) { |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1996 | wallpaperWin.mWallpaperX = wpx; |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 1997 | wallpaperWin.mWallpaperXStep = wpxs; |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1998 | rawChanged = true; |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 1999 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2000 | |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 2001 | float wpy = mLastWallpaperY >= 0 ? mLastWallpaperY : 0.5f; |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 2002 | float wpys = mLastWallpaperYStep >= 0 ? mLastWallpaperYStep : -1.0f; |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 2003 | int availh = wallpaperWin.mFrame.bottom-wallpaperWin.mFrame.top-dh; |
| 2004 | offset = availh > 0 ? -(int)(availh*wpy+.5f) : 0; |
| 2005 | if (wallpaperWin.mYOffset != offset) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2006 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Update wallpaper " |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 2007 | + wallpaperWin + " y: " + offset); |
| 2008 | changed = true; |
| 2009 | wallpaperWin.mYOffset = offset; |
| 2010 | } |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 2011 | if (wallpaperWin.mWallpaperY != wpy || wallpaperWin.mWallpaperYStep != wpys) { |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 2012 | wallpaperWin.mWallpaperY = wpy; |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 2013 | wallpaperWin.mWallpaperYStep = wpys; |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 2014 | rawChanged = true; |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 2015 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2016 | |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 2017 | if (rawChanged) { |
Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 2018 | try { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2019 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Report new wp offset " |
Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 2020 | + wallpaperWin + " x=" + wallpaperWin.mWallpaperX |
| 2021 | + " y=" + wallpaperWin.mWallpaperY); |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 2022 | if (sync) { |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 2023 | mWaitingOnWallpaper = wallpaperWin; |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 2024 | } |
Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 2025 | wallpaperWin.mClient.dispatchWallpaperOffsets( |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 2026 | wallpaperWin.mWallpaperX, wallpaperWin.mWallpaperY, |
| 2027 | wallpaperWin.mWallpaperXStep, wallpaperWin.mWallpaperYStep, sync); |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 2028 | if (sync) { |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 2029 | if (mWaitingOnWallpaper != null) { |
| 2030 | long start = SystemClock.uptimeMillis(); |
| 2031 | if ((mLastWallpaperTimeoutTime+WALLPAPER_TIMEOUT_RECOVERY) |
| 2032 | < start) { |
| 2033 | try { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2034 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 2035 | "Waiting for offset complete..."); |
| 2036 | mWindowMap.wait(WALLPAPER_TIMEOUT); |
| 2037 | } catch (InterruptedException e) { |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 2038 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2039 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Offset complete!"); |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 2040 | if ((start+WALLPAPER_TIMEOUT) |
| 2041 | < SystemClock.uptimeMillis()) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2042 | Slog.i(TAG, "Timeout waiting for wallpaper to offset: " |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 2043 | + wallpaperWin); |
| 2044 | mLastWallpaperTimeoutTime = start; |
| 2045 | } |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 2046 | } |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 2047 | mWaitingOnWallpaper = null; |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 2048 | } |
| 2049 | } |
Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 2050 | } catch (RemoteException e) { |
| 2051 | } |
| 2052 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2053 | |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 2054 | return changed; |
| 2055 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2056 | |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 2057 | void wallpaperOffsetsComplete(IBinder window) { |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 2058 | synchronized (mWindowMap) { |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 2059 | if (mWaitingOnWallpaper != null && |
| 2060 | mWaitingOnWallpaper.mClient.asBinder() == window) { |
| 2061 | mWaitingOnWallpaper = null; |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 2062 | mWindowMap.notifyAll(); |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 2063 | } |
| 2064 | } |
| 2065 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2066 | |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 2067 | boolean updateWallpaperOffsetLocked(WindowState changingTarget, boolean sync) { |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 2068 | final int dw = mDisplay.getWidth(); |
| 2069 | final int dh = mDisplay.getHeight(); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2070 | |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 2071 | boolean changed = false; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2072 | |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 2073 | WindowState target = mWallpaperTarget; |
| 2074 | if (target != null) { |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 2075 | if (target.mWallpaperX >= 0) { |
| 2076 | mLastWallpaperX = target.mWallpaperX; |
| 2077 | } else if (changingTarget.mWallpaperX >= 0) { |
| 2078 | mLastWallpaperX = changingTarget.mWallpaperX; |
| 2079 | } |
| 2080 | if (target.mWallpaperY >= 0) { |
| 2081 | mLastWallpaperY = target.mWallpaperY; |
| 2082 | } else if (changingTarget.mWallpaperY >= 0) { |
| 2083 | mLastWallpaperY = changingTarget.mWallpaperY; |
| 2084 | } |
| 2085 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2086 | |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 2087 | int curTokenIndex = mWallpaperTokens.size(); |
| 2088 | while (curTokenIndex > 0) { |
| 2089 | curTokenIndex--; |
| 2090 | WindowToken token = mWallpaperTokens.get(curTokenIndex); |
| 2091 | int curWallpaperIndex = token.windows.size(); |
| 2092 | while (curWallpaperIndex > 0) { |
| 2093 | curWallpaperIndex--; |
| 2094 | WindowState wallpaper = token.windows.get(curWallpaperIndex); |
| 2095 | if (updateWallpaperOffsetLocked(wallpaper, dw, dh, sync)) { |
| 2096 | wallpaper.computeShownFrameLocked(); |
| 2097 | changed = true; |
| 2098 | // We only want to be synchronous with one wallpaper. |
| 2099 | sync = false; |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 2100 | } |
| 2101 | } |
| 2102 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2103 | |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 2104 | return changed; |
| 2105 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2106 | |
Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 2107 | void updateWallpaperVisibilityLocked() { |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 2108 | final boolean visible = isWallpaperVisible(mWallpaperTarget); |
Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 2109 | final int dw = mDisplay.getWidth(); |
| 2110 | final int dh = mDisplay.getHeight(); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2111 | |
Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 2112 | int curTokenIndex = mWallpaperTokens.size(); |
| 2113 | while (curTokenIndex > 0) { |
| 2114 | curTokenIndex--; |
| 2115 | WindowToken token = mWallpaperTokens.get(curTokenIndex); |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 2116 | if (token.hidden == visible) { |
| 2117 | token.hidden = !visible; |
| 2118 | // Need to do a layout to ensure the wallpaper now has the |
| 2119 | // correct size. |
| 2120 | mLayoutNeeded = true; |
| 2121 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2122 | |
Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 2123 | int curWallpaperIndex = token.windows.size(); |
| 2124 | while (curWallpaperIndex > 0) { |
| 2125 | curWallpaperIndex--; |
| 2126 | WindowState wallpaper = token.windows.get(curWallpaperIndex); |
| 2127 | if (visible) { |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 2128 | updateWallpaperOffsetLocked(wallpaper, dw, dh, false); |
Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 2129 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2130 | |
Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 2131 | if (wallpaper.mWallpaperVisible != visible) { |
| 2132 | wallpaper.mWallpaperVisible = visible; |
| 2133 | try { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2134 | if (DEBUG_VISIBILITY || DEBUG_WALLPAPER) Slog.v(TAG, |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 2135 | "Updating visibility of wallpaper " + wallpaper |
Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 2136 | + ": " + visible); |
| 2137 | wallpaper.mClient.dispatchAppVisibility(visible); |
| 2138 | } catch (RemoteException e) { |
| 2139 | } |
| 2140 | } |
| 2141 | } |
| 2142 | } |
| 2143 | } |
Dianne Hackborn | 90d2db3 | 2010-02-11 22:19:06 -0800 | [diff] [blame] | 2144 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2145 | public int addWindow(Session session, IWindow client, |
| 2146 | WindowManager.LayoutParams attrs, int viewVisibility, |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 2147 | Rect outContentInsets, InputChannel outInputChannel) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2148 | int res = mPolicy.checkAddPermission(attrs); |
| 2149 | if (res != WindowManagerImpl.ADD_OKAY) { |
| 2150 | return res; |
| 2151 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2152 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2153 | boolean reportNewConfig = false; |
| 2154 | WindowState attachedWindow = null; |
| 2155 | WindowState win = null; |
Dianne Hackborn | 5132b37 | 2010-07-29 12:51:35 -0700 | [diff] [blame] | 2156 | long origId; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2157 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2158 | synchronized(mWindowMap) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2159 | if (mDisplay == null) { |
Dianne Hackborn | 5132b37 | 2010-07-29 12:51:35 -0700 | [diff] [blame] | 2160 | throw new IllegalStateException("Display has not been initialialized"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2161 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2162 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2163 | if (mWindowMap.containsKey(client.asBinder())) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2164 | Slog.w(TAG, "Window " + client + " is already added"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2165 | return WindowManagerImpl.ADD_DUPLICATE_ADD; |
| 2166 | } |
| 2167 | |
| 2168 | if (attrs.type >= FIRST_SUB_WINDOW && attrs.type <= LAST_SUB_WINDOW) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2169 | attachedWindow = windowForClientLocked(null, attrs.token, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2170 | if (attachedWindow == null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2171 | 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] | 2172 | + attrs.token + ". Aborting."); |
| 2173 | return WindowManagerImpl.ADD_BAD_SUBWINDOW_TOKEN; |
| 2174 | } |
| 2175 | if (attachedWindow.mAttrs.type >= FIRST_SUB_WINDOW |
| 2176 | && attachedWindow.mAttrs.type <= LAST_SUB_WINDOW) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2177 | 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] | 2178 | + attrs.token + ". Aborting."); |
| 2179 | return WindowManagerImpl.ADD_BAD_SUBWINDOW_TOKEN; |
| 2180 | } |
| 2181 | } |
| 2182 | |
| 2183 | boolean addToken = false; |
| 2184 | WindowToken token = mTokenMap.get(attrs.token); |
| 2185 | if (token == null) { |
| 2186 | if (attrs.type >= FIRST_APPLICATION_WINDOW |
| 2187 | && attrs.type <= LAST_APPLICATION_WINDOW) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2188 | 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] | 2189 | + attrs.token + ". Aborting."); |
| 2190 | return WindowManagerImpl.ADD_BAD_APP_TOKEN; |
| 2191 | } |
| 2192 | if (attrs.type == TYPE_INPUT_METHOD) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2193 | 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] | 2194 | + attrs.token + ". Aborting."); |
| 2195 | return WindowManagerImpl.ADD_BAD_APP_TOKEN; |
| 2196 | } |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2197 | if (attrs.type == TYPE_WALLPAPER) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2198 | Slog.w(TAG, "Attempted to add wallpaper window with unknown token " |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2199 | + attrs.token + ". Aborting."); |
| 2200 | return WindowManagerImpl.ADD_BAD_APP_TOKEN; |
| 2201 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2202 | token = new WindowToken(attrs.token, -1, false); |
| 2203 | addToken = true; |
| 2204 | } else if (attrs.type >= FIRST_APPLICATION_WINDOW |
| 2205 | && attrs.type <= LAST_APPLICATION_WINDOW) { |
| 2206 | AppWindowToken atoken = token.appWindowToken; |
| 2207 | if (atoken == null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2208 | 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] | 2209 | + token + ". Aborting."); |
| 2210 | return WindowManagerImpl.ADD_NOT_APP_TOKEN; |
| 2211 | } else if (atoken.removed) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2212 | 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] | 2213 | + token + ". Aborting."); |
| 2214 | return WindowManagerImpl.ADD_APP_EXITING; |
| 2215 | } |
| 2216 | if (attrs.type == TYPE_APPLICATION_STARTING && atoken.firstWindowDrawn) { |
| 2217 | // No need for this guy! |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2218 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2219 | TAG, "**** NO NEED TO START: " + attrs.getTitle()); |
| 2220 | return WindowManagerImpl.ADD_STARTING_NOT_NEEDED; |
| 2221 | } |
| 2222 | } else if (attrs.type == TYPE_INPUT_METHOD) { |
| 2223 | if (token.windowType != TYPE_INPUT_METHOD) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2224 | 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] | 2225 | + attrs.token + ". Aborting."); |
| 2226 | return WindowManagerImpl.ADD_BAD_APP_TOKEN; |
| 2227 | } |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2228 | } else if (attrs.type == TYPE_WALLPAPER) { |
| 2229 | if (token.windowType != TYPE_WALLPAPER) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2230 | Slog.w(TAG, "Attempted to add wallpaper window with bad token " |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2231 | + attrs.token + ". Aborting."); |
| 2232 | return WindowManagerImpl.ADD_BAD_APP_TOKEN; |
| 2233 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2234 | } |
| 2235 | |
| 2236 | win = new WindowState(session, client, token, |
| 2237 | attachedWindow, attrs, viewVisibility); |
| 2238 | if (win.mDeathRecipient == null) { |
| 2239 | // Client has apparently died, so there is no reason to |
| 2240 | // continue. |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2241 | Slog.w(TAG, "Adding window client " + client.asBinder() |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2242 | + " that is dead, aborting."); |
| 2243 | return WindowManagerImpl.ADD_APP_EXITING; |
| 2244 | } |
| 2245 | |
| 2246 | mPolicy.adjustWindowParamsLw(win.mAttrs); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2247 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2248 | res = mPolicy.prepareAddWindowLw(win, attrs); |
| 2249 | if (res != WindowManagerImpl.ADD_OKAY) { |
| 2250 | return res; |
| 2251 | } |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 2252 | |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 2253 | if (outInputChannel != null) { |
| 2254 | String name = win.makeInputChannelName(); |
| 2255 | InputChannel[] inputChannels = InputChannel.openInputChannelPair(name); |
| 2256 | win.mInputChannel = inputChannels[0]; |
| 2257 | inputChannels[1].transferToBinderOutParameter(outInputChannel); |
| 2258 | |
| 2259 | mInputManager.registerInputChannel(win.mInputChannel); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 2260 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2261 | |
| 2262 | // From now on, no exceptions or errors allowed! |
| 2263 | |
| 2264 | res = WindowManagerImpl.ADD_OKAY; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2265 | |
Dianne Hackborn | 5132b37 | 2010-07-29 12:51:35 -0700 | [diff] [blame] | 2266 | origId = Binder.clearCallingIdentity(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2267 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2268 | if (addToken) { |
| 2269 | mTokenMap.put(attrs.token, token); |
| 2270 | mTokenList.add(token); |
| 2271 | } |
| 2272 | win.attach(); |
| 2273 | mWindowMap.put(client.asBinder(), win); |
| 2274 | |
| 2275 | if (attrs.type == TYPE_APPLICATION_STARTING && |
| 2276 | token.appWindowToken != null) { |
| 2277 | token.appWindowToken.startingWindow = win; |
| 2278 | } |
| 2279 | |
| 2280 | boolean imMayMove = true; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2281 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2282 | if (attrs.type == TYPE_INPUT_METHOD) { |
| 2283 | mInputMethodWindow = win; |
| 2284 | addInputMethodWindowToListLocked(win); |
| 2285 | imMayMove = false; |
| 2286 | } else if (attrs.type == TYPE_INPUT_METHOD_DIALOG) { |
| 2287 | mInputMethodDialogs.add(win); |
| 2288 | addWindowToListInOrderLocked(win, true); |
| 2289 | adjustInputMethodDialogsLocked(); |
| 2290 | imMayMove = false; |
| 2291 | } else { |
| 2292 | addWindowToListInOrderLocked(win, true); |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 2293 | if (attrs.type == TYPE_WALLPAPER) { |
| 2294 | mLastWallpaperTimeoutTime = 0; |
| 2295 | adjustWallpaperWindowsLocked(); |
| 2296 | } else if ((attrs.flags&FLAG_SHOW_WALLPAPER) != 0) { |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2297 | adjustWallpaperWindowsLocked(); |
| 2298 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2299 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2300 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2301 | win.mEnterAnimationPending = true; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2302 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2303 | mPolicy.getContentInsetHintLw(attrs, outContentInsets); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2304 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2305 | if (mInTouchMode) { |
| 2306 | res |= WindowManagerImpl.ADD_FLAG_IN_TOUCH_MODE; |
| 2307 | } |
| 2308 | if (win == null || win.mAppToken == null || !win.mAppToken.clientHidden) { |
| 2309 | res |= WindowManagerImpl.ADD_FLAG_APP_VISIBLE; |
| 2310 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2311 | |
The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 2312 | boolean focusChanged = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2313 | if (win.canReceiveKeys()) { |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 2314 | focusChanged = updateFocusedWindowLocked(UPDATE_FOCUS_WILL_ASSIGN_LAYERS); |
| 2315 | if (focusChanged) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2316 | imMayMove = false; |
| 2317 | } |
| 2318 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2319 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2320 | if (imMayMove) { |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2321 | moveInputMethodWindowsIfNeededLocked(false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 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 | assignLayersLocked(); |
| 2325 | // Don't do layout here, the window must call |
| 2326 | // relayout to be displayed, so we'll do it there. |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2327 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2328 | //dump(); |
| 2329 | |
The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 2330 | if (focusChanged) { |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 2331 | finishUpdateFocusedWindowAfterAssignLayersLocked(); |
The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 2332 | } |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 2333 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2334 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2335 | TAG, "New client " + client.asBinder() |
| 2336 | + ": window=" + win); |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2337 | |
| 2338 | if (win.isVisibleOrAdding() && updateOrientationFromAppTokensLocked()) { |
| 2339 | reportNewConfig = true; |
| 2340 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2341 | } |
| 2342 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2343 | if (reportNewConfig) { |
| 2344 | sendNewConfiguration(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2345 | } |
Dianne Hackborn | 5132b37 | 2010-07-29 12:51:35 -0700 | [diff] [blame] | 2346 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2347 | Binder.restoreCallingIdentity(origId); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2348 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2349 | return res; |
| 2350 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2351 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2352 | public void removeWindow(Session session, IWindow client) { |
| 2353 | synchronized(mWindowMap) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2354 | WindowState win = windowForClientLocked(session, client, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2355 | if (win == null) { |
| 2356 | return; |
| 2357 | } |
| 2358 | removeWindowLocked(session, win); |
| 2359 | } |
| 2360 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2361 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2362 | public void removeWindowLocked(Session session, WindowState win) { |
| 2363 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2364 | if (localLOGV || DEBUG_FOCUS) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2365 | TAG, "Remove " + win + " client=" |
| 2366 | + Integer.toHexString(System.identityHashCode( |
| 2367 | win.mClient.asBinder())) |
| 2368 | + ", surface=" + win.mSurface); |
| 2369 | |
| 2370 | final long origId = Binder.clearCallingIdentity(); |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 2371 | |
| 2372 | win.disposeInputChannel(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2373 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2374 | if (DEBUG_APP_TRANSITIONS) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2375 | TAG, "Remove " + win + ": mSurface=" + win.mSurface |
| 2376 | + " mExiting=" + win.mExiting |
| 2377 | + " isAnimating=" + win.isAnimating() |
| 2378 | + " app-animation=" |
| 2379 | + (win.mAppToken != null ? win.mAppToken.animation : null) |
| 2380 | + " inPendingTransaction=" |
| 2381 | + (win.mAppToken != null ? win.mAppToken.inPendingTransaction : false) |
| 2382 | + " mDisplayFrozen=" + mDisplayFrozen); |
| 2383 | // Visibility of the removed window. Will be used later to update orientation later on. |
| 2384 | boolean wasVisible = false; |
| 2385 | // First, see if we need to run an animation. If we do, we have |
| 2386 | // to hold off on removing the window until the animation is done. |
| 2387 | // If the display is frozen, just remove immediately, since the |
| 2388 | // animation wouldn't be seen. |
Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 2389 | if (win.mSurface != null && !mDisplayFrozen && mPolicy.isScreenOn()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2390 | // If we are not currently running the exit animation, we |
| 2391 | // need to see about starting one. |
| 2392 | if (wasVisible=win.isWinVisibleLw()) { |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2393 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2394 | int transit = WindowManagerPolicy.TRANSIT_EXIT; |
| 2395 | if (win.getAttrs().type == TYPE_APPLICATION_STARTING) { |
| 2396 | transit = WindowManagerPolicy.TRANSIT_PREVIEW_DONE; |
| 2397 | } |
| 2398 | // Try starting an animation. |
| 2399 | if (applyAnimationLocked(win, transit, false)) { |
| 2400 | win.mExiting = true; |
| 2401 | } |
| 2402 | } |
| 2403 | if (win.mExiting || win.isAnimating()) { |
| 2404 | // The exit animation is running... wait for it! |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2405 | //Slog.i(TAG, "*** Running exit animation..."); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2406 | win.mExiting = true; |
| 2407 | win.mRemoveOnExit = true; |
| 2408 | mLayoutNeeded = true; |
| 2409 | updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES); |
| 2410 | performLayoutAndPlaceSurfacesLocked(); |
| 2411 | if (win.mAppToken != null) { |
| 2412 | win.mAppToken.updateReportedVisibilityLocked(); |
| 2413 | } |
| 2414 | //dump(); |
| 2415 | Binder.restoreCallingIdentity(origId); |
| 2416 | return; |
| 2417 | } |
| 2418 | } |
| 2419 | |
| 2420 | removeWindowInnerLocked(session, win); |
| 2421 | // Removing a visible window will effect the computed orientation |
| 2422 | // So just update orientation if needed. |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 2423 | if (wasVisible && computeForcedAppOrientationLocked() |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2424 | != mForcedAppOrientation |
| 2425 | && updateOrientationFromAppTokensLocked()) { |
| 2426 | mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2427 | } |
| 2428 | updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL); |
| 2429 | Binder.restoreCallingIdentity(origId); |
| 2430 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2431 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2432 | private void removeWindowInnerLocked(Session session, WindowState win) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2433 | win.mRemoved = true; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2434 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2435 | if (mInputMethodTarget == win) { |
| 2436 | moveInputMethodWindowsIfNeededLocked(false); |
| 2437 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2438 | |
Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 2439 | if (false) { |
| 2440 | RuntimeException e = new RuntimeException("here"); |
| 2441 | e.fillInStackTrace(); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2442 | Slog.w(TAG, "Removing window " + win, e); |
Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 2443 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2444 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2445 | mPolicy.removeWindowLw(win); |
| 2446 | win.removeLocked(); |
| 2447 | |
| 2448 | mWindowMap.remove(win.mClient.asBinder()); |
| 2449 | mWindows.remove(win); |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 2450 | mWindowsChanged = true; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2451 | 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] | 2452 | |
| 2453 | if (mInputMethodWindow == win) { |
| 2454 | mInputMethodWindow = null; |
| 2455 | } else if (win.mAttrs.type == TYPE_INPUT_METHOD_DIALOG) { |
| 2456 | mInputMethodDialogs.remove(win); |
| 2457 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2458 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2459 | final WindowToken token = win.mToken; |
| 2460 | final AppWindowToken atoken = win.mAppToken; |
| 2461 | token.windows.remove(win); |
| 2462 | if (atoken != null) { |
| 2463 | atoken.allAppWindows.remove(win); |
| 2464 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2465 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2466 | TAG, "**** Removing window " + win + ": count=" |
| 2467 | + token.windows.size()); |
| 2468 | if (token.windows.size() == 0) { |
| 2469 | if (!token.explicit) { |
| 2470 | mTokenMap.remove(token.token); |
| 2471 | mTokenList.remove(token); |
| 2472 | } else if (atoken != null) { |
| 2473 | atoken.firstWindowDrawn = false; |
| 2474 | } |
| 2475 | } |
| 2476 | |
| 2477 | if (atoken != null) { |
| 2478 | if (atoken.startingWindow == win) { |
| 2479 | atoken.startingWindow = null; |
| 2480 | } else if (atoken.allAppWindows.size() == 0 && atoken.startingData != null) { |
| 2481 | // If this is the last window and we had requested a starting |
| 2482 | // transition window, well there is no point now. |
| 2483 | atoken.startingData = null; |
| 2484 | } else if (atoken.allAppWindows.size() == 1 && atoken.startingView != null) { |
| 2485 | // If this is the last window except for a starting transition |
| 2486 | // window, we need to get rid of the starting transition. |
| 2487 | if (DEBUG_STARTING_WINDOW) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2488 | Slog.v(TAG, "Schedule remove starting " + token |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2489 | + ": no more real windows"); |
| 2490 | } |
| 2491 | Message m = mH.obtainMessage(H.REMOVE_STARTING, atoken); |
| 2492 | mH.sendMessage(m); |
| 2493 | } |
| 2494 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2495 | |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 2496 | if (win.mAttrs.type == TYPE_WALLPAPER) { |
| 2497 | mLastWallpaperTimeoutTime = 0; |
| 2498 | adjustWallpaperWindowsLocked(); |
| 2499 | } else if ((win.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0) { |
Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 2500 | adjustWallpaperWindowsLocked(); |
| 2501 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2502 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2503 | if (!mInLayout) { |
| 2504 | assignLayersLocked(); |
| 2505 | mLayoutNeeded = true; |
| 2506 | performLayoutAndPlaceSurfacesLocked(); |
| 2507 | if (win.mAppToken != null) { |
| 2508 | win.mAppToken.updateReportedVisibilityLocked(); |
| 2509 | } |
| 2510 | } |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 2511 | |
| 2512 | mInputMonitor.updateInputWindowsLw(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2513 | } |
| 2514 | |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 2515 | private static void logSurface(WindowState w, String msg, RuntimeException where) { |
| 2516 | String str = " SURFACE " + Integer.toHexString(w.hashCode()) |
| 2517 | + ": " + msg + " / " + w.mAttrs.getTitle(); |
| 2518 | if (where != null) { |
| 2519 | Slog.i(TAG, str, where); |
| 2520 | } else { |
| 2521 | Slog.i(TAG, str); |
| 2522 | } |
| 2523 | } |
| 2524 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2525 | private void setTransparentRegionWindow(Session session, IWindow client, Region region) { |
| 2526 | long origId = Binder.clearCallingIdentity(); |
| 2527 | try { |
| 2528 | synchronized (mWindowMap) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2529 | WindowState w = windowForClientLocked(session, client, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2530 | if ((w != null) && (w.mSurface != null)) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2531 | if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2532 | Surface.openTransaction(); |
| 2533 | try { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 2534 | if (SHOW_TRANSACTIONS) logSurface(w, |
| 2535 | "transparentRegionHint=" + region, null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2536 | w.mSurface.setTransparentRegionHint(region); |
| 2537 | } finally { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2538 | if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2539 | Surface.closeTransaction(); |
| 2540 | } |
| 2541 | } |
| 2542 | } |
| 2543 | } finally { |
| 2544 | Binder.restoreCallingIdentity(origId); |
| 2545 | } |
| 2546 | } |
| 2547 | |
| 2548 | void setInsetsWindow(Session session, IWindow client, |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2549 | int touchableInsets, Rect contentInsets, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2550 | Rect visibleInsets) { |
| 2551 | long origId = Binder.clearCallingIdentity(); |
| 2552 | try { |
| 2553 | synchronized (mWindowMap) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2554 | WindowState w = windowForClientLocked(session, client, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2555 | if (w != null) { |
| 2556 | w.mGivenInsetsPending = false; |
| 2557 | w.mGivenContentInsets.set(contentInsets); |
| 2558 | w.mGivenVisibleInsets.set(visibleInsets); |
| 2559 | w.mTouchableInsets = touchableInsets; |
| 2560 | mLayoutNeeded = true; |
| 2561 | performLayoutAndPlaceSurfacesLocked(); |
| 2562 | } |
| 2563 | } |
| 2564 | } finally { |
| 2565 | Binder.restoreCallingIdentity(origId); |
| 2566 | } |
| 2567 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2568 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2569 | public void getWindowDisplayFrame(Session session, IWindow client, |
| 2570 | Rect outDisplayFrame) { |
| 2571 | synchronized(mWindowMap) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2572 | WindowState win = windowForClientLocked(session, client, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2573 | if (win == null) { |
| 2574 | outDisplayFrame.setEmpty(); |
| 2575 | return; |
| 2576 | } |
| 2577 | outDisplayFrame.set(win.mDisplayFrame); |
| 2578 | } |
| 2579 | } |
| 2580 | |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 2581 | public void setWindowWallpaperPositionLocked(WindowState window, float x, float y, |
| 2582 | float xStep, float yStep) { |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 2583 | if (window.mWallpaperX != x || window.mWallpaperY != y) { |
| 2584 | window.mWallpaperX = x; |
| 2585 | window.mWallpaperY = y; |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 2586 | window.mWallpaperXStep = xStep; |
| 2587 | window.mWallpaperYStep = yStep; |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 2588 | if (updateWallpaperOffsetLocked(window, true)) { |
| 2589 | performLayoutAndPlaceSurfacesLocked(); |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 2590 | } |
| 2591 | } |
| 2592 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2593 | |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 2594 | void wallpaperCommandComplete(IBinder window, Bundle result) { |
| 2595 | synchronized (mWindowMap) { |
| 2596 | if (mWaitingOnWallpaper != null && |
| 2597 | mWaitingOnWallpaper.mClient.asBinder() == window) { |
| 2598 | mWaitingOnWallpaper = null; |
| 2599 | mWindowMap.notifyAll(); |
| 2600 | } |
| 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 | public Bundle sendWindowWallpaperCommandLocked(WindowState window, |
| 2605 | String action, int x, int y, int z, Bundle extras, boolean sync) { |
| 2606 | if (window == mWallpaperTarget || window == mLowerWallpaperTarget |
| 2607 | || window == mUpperWallpaperTarget) { |
| 2608 | boolean doWait = sync; |
| 2609 | int curTokenIndex = mWallpaperTokens.size(); |
| 2610 | while (curTokenIndex > 0) { |
| 2611 | curTokenIndex--; |
| 2612 | WindowToken token = mWallpaperTokens.get(curTokenIndex); |
| 2613 | int curWallpaperIndex = token.windows.size(); |
| 2614 | while (curWallpaperIndex > 0) { |
| 2615 | curWallpaperIndex--; |
| 2616 | WindowState wallpaper = token.windows.get(curWallpaperIndex); |
| 2617 | try { |
| 2618 | wallpaper.mClient.dispatchWallpaperCommand(action, |
| 2619 | x, y, z, extras, sync); |
| 2620 | // We only want to be synchronous with one wallpaper. |
| 2621 | sync = false; |
| 2622 | } catch (RemoteException e) { |
| 2623 | } |
| 2624 | } |
| 2625 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2626 | |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 2627 | if (doWait) { |
| 2628 | // XXX Need to wait for result. |
| 2629 | } |
| 2630 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2631 | |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 2632 | return null; |
| 2633 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2634 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2635 | public int relayoutWindow(Session session, IWindow client, |
| 2636 | WindowManager.LayoutParams attrs, int requestedWidth, |
| 2637 | int requestedHeight, int viewVisibility, boolean insetsPending, |
| 2638 | Rect outFrame, Rect outContentInsets, Rect outVisibleInsets, |
Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 2639 | Configuration outConfig, Surface outSurface) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2640 | boolean displayed = false; |
| 2641 | boolean inTouchMode; |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2642 | boolean configChanged; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2643 | long origId = Binder.clearCallingIdentity(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2644 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2645 | synchronized(mWindowMap) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2646 | WindowState win = windowForClientLocked(session, client, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2647 | if (win == null) { |
| 2648 | return 0; |
| 2649 | } |
| 2650 | win.mRequestedWidth = requestedWidth; |
| 2651 | win.mRequestedHeight = requestedHeight; |
| 2652 | |
| 2653 | if (attrs != null) { |
| 2654 | mPolicy.adjustWindowParamsLw(attrs); |
| 2655 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2656 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2657 | int attrChanges = 0; |
| 2658 | int flagChanges = 0; |
| 2659 | if (attrs != null) { |
| 2660 | flagChanges = win.mAttrs.flags ^= attrs.flags; |
| 2661 | attrChanges = win.mAttrs.copyFrom(attrs); |
| 2662 | } |
| 2663 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2664 | 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] | 2665 | |
| 2666 | if ((attrChanges & WindowManager.LayoutParams.ALPHA_CHANGED) != 0) { |
| 2667 | win.mAlpha = attrs.alpha; |
| 2668 | } |
| 2669 | |
| 2670 | final boolean scaledWindow = |
| 2671 | ((win.mAttrs.flags & WindowManager.LayoutParams.FLAG_SCALED) != 0); |
| 2672 | |
| 2673 | if (scaledWindow) { |
| 2674 | // requested{Width|Height} Surface's physical size |
| 2675 | // attrs.{width|height} Size on screen |
| 2676 | win.mHScale = (attrs.width != requestedWidth) ? |
| 2677 | (attrs.width / (float)requestedWidth) : 1.0f; |
| 2678 | win.mVScale = (attrs.height != requestedHeight) ? |
| 2679 | (attrs.height / (float)requestedHeight) : 1.0f; |
Dianne Hackborn | 9b52a21 | 2009-12-11 14:51:35 -0800 | [diff] [blame] | 2680 | } else { |
| 2681 | win.mHScale = win.mVScale = 1; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2682 | } |
| 2683 | |
| 2684 | boolean imMayMove = (flagChanges&( |
| 2685 | WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM | |
| 2686 | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE)) != 0; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2687 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2688 | boolean focusMayChange = win.mViewVisibility != viewVisibility |
| 2689 | || ((flagChanges&WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) != 0) |
| 2690 | || (!win.mRelayoutCalled); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2691 | |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2692 | boolean wallpaperMayMove = win.mViewVisibility != viewVisibility |
| 2693 | && (win.mAttrs.flags & FLAG_SHOW_WALLPAPER) != 0; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2694 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2695 | win.mRelayoutCalled = true; |
| 2696 | final int oldVisibility = win.mViewVisibility; |
| 2697 | win.mViewVisibility = viewVisibility; |
| 2698 | if (viewVisibility == View.VISIBLE && |
| 2699 | (win.mAppToken == null || !win.mAppToken.clientHidden)) { |
| 2700 | displayed = !win.isVisibleLw(); |
| 2701 | if (win.mExiting) { |
| 2702 | win.mExiting = false; |
| 2703 | win.mAnimation = null; |
| 2704 | } |
| 2705 | if (win.mDestroying) { |
| 2706 | win.mDestroying = false; |
| 2707 | mDestroySurface.remove(win); |
| 2708 | } |
| 2709 | if (oldVisibility == View.GONE) { |
| 2710 | win.mEnterAnimationPending = true; |
| 2711 | } |
Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 2712 | if (displayed) { |
| 2713 | if (win.mSurface != null && !win.mDrawPending |
| 2714 | && !win.mCommitDrawPending && !mDisplayFrozen |
| 2715 | && mPolicy.isScreenOn()) { |
| 2716 | applyEnterAnimationLocked(win); |
| 2717 | } |
| 2718 | if ((win.mAttrs.flags |
| 2719 | & WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON) != 0) { |
| 2720 | if (DEBUG_VISIBILITY) Slog.v(TAG, |
| 2721 | "Relayout window turning screen on: " + win); |
| 2722 | win.mTurnOnScreen = true; |
| 2723 | } |
| 2724 | int diff = 0; |
| 2725 | if (win.mConfiguration != mCurConfiguration |
| 2726 | && (win.mConfiguration == null |
| 2727 | || (diff=mCurConfiguration.diff(win.mConfiguration)) != 0)) { |
| 2728 | win.mConfiguration = mCurConfiguration; |
| 2729 | if (DEBUG_CONFIGURATION) { |
| 2730 | Slog.i(TAG, "Window " + win + " visible with new config: " |
| 2731 | + win.mConfiguration + " / 0x" |
| 2732 | + Integer.toHexString(diff)); |
| 2733 | } |
| 2734 | outConfig.setTo(mCurConfiguration); |
| 2735 | } |
Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 2736 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2737 | if ((attrChanges&WindowManager.LayoutParams.FORMAT_CHANGED) != 0) { |
| 2738 | // To change the format, we need to re-build the surface. |
| 2739 | win.destroySurfaceLocked(); |
| 2740 | displayed = true; |
| 2741 | } |
| 2742 | try { |
| 2743 | Surface surface = win.createSurfaceLocked(); |
| 2744 | if (surface != null) { |
| 2745 | outSurface.copyFrom(surface); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2746 | win.mReportDestroySurface = false; |
| 2747 | win.mSurfacePendingDestroy = false; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2748 | if (SHOW_TRANSACTIONS) Slog.i(TAG, |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 2749 | " OUT SURFACE " + outSurface + ": copied"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2750 | } else { |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 2751 | // For some reason there isn't a surface. Clear the |
| 2752 | // caller's object so they see the same state. |
| 2753 | outSurface.release(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2754 | } |
| 2755 | } catch (Exception e) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 2756 | mInputMonitor.updateInputWindowsLw(); |
| 2757 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2758 | Slog.w(TAG, "Exception thrown when creating surface for client " |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 2759 | + client + " (" + win.mAttrs.getTitle() + ")", |
| 2760 | e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2761 | Binder.restoreCallingIdentity(origId); |
| 2762 | return 0; |
| 2763 | } |
| 2764 | if (displayed) { |
| 2765 | focusMayChange = true; |
| 2766 | } |
| 2767 | if (win.mAttrs.type == TYPE_INPUT_METHOD |
| 2768 | && mInputMethodWindow == null) { |
| 2769 | mInputMethodWindow = win; |
| 2770 | imMayMove = true; |
| 2771 | } |
Dianne Hackborn | 558947c | 2009-12-18 16:02:50 -0800 | [diff] [blame] | 2772 | if (win.mAttrs.type == TYPE_BASE_APPLICATION |
| 2773 | && win.mAppToken != null |
| 2774 | && win.mAppToken.startingWindow != null) { |
| 2775 | // Special handling of starting window over the base |
| 2776 | // window of the app: propagate lock screen flags to it, |
| 2777 | // to provide the correct semantics while starting. |
| 2778 | final int mask = |
| 2779 | WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED |
Mike Lockwood | ef73162 | 2010-01-27 17:51:34 -0500 | [diff] [blame] | 2780 | | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD |
| 2781 | | WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON; |
Dianne Hackborn | 558947c | 2009-12-18 16:02:50 -0800 | [diff] [blame] | 2782 | WindowManager.LayoutParams sa = win.mAppToken.startingWindow.mAttrs; |
| 2783 | sa.flags = (sa.flags&~mask) | (win.mAttrs.flags&mask); |
| 2784 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2785 | } else { |
| 2786 | win.mEnterAnimationPending = false; |
| 2787 | if (win.mSurface != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2788 | if (DEBUG_VISIBILITY) Slog.i(TAG, "Relayout invis " + win |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2789 | + ": mExiting=" + win.mExiting |
| 2790 | + " mSurfacePendingDestroy=" + win.mSurfacePendingDestroy); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2791 | // If we are not currently running the exit animation, we |
| 2792 | // need to see about starting one. |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2793 | if (!win.mExiting || win.mSurfacePendingDestroy) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2794 | // Try starting an animation; if there isn't one, we |
| 2795 | // can destroy the surface right away. |
| 2796 | int transit = WindowManagerPolicy.TRANSIT_EXIT; |
| 2797 | if (win.getAttrs().type == TYPE_APPLICATION_STARTING) { |
| 2798 | transit = WindowManagerPolicy.TRANSIT_PREVIEW_DONE; |
| 2799 | } |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2800 | if (!win.mSurfacePendingDestroy && win.isWinVisibleLw() && |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2801 | applyAnimationLocked(win, transit, false)) { |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2802 | focusMayChange = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2803 | win.mExiting = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2804 | } else if (win.isAnimating()) { |
| 2805 | // Currently in a hide animation... turn this into |
| 2806 | // an exit. |
| 2807 | win.mExiting = true; |
Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 2808 | } else if (win == mWallpaperTarget) { |
| 2809 | // If the wallpaper is currently behind this |
| 2810 | // window, we need to change both of them inside |
| 2811 | // of a transaction to avoid artifacts. |
| 2812 | win.mExiting = true; |
| 2813 | win.mAnimating = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2814 | } else { |
| 2815 | if (mInputMethodWindow == win) { |
| 2816 | mInputMethodWindow = null; |
| 2817 | } |
| 2818 | win.destroySurfaceLocked(); |
| 2819 | } |
| 2820 | } |
| 2821 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2822 | |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2823 | if (win.mSurface == null || (win.getAttrs().flags |
| 2824 | & WindowManager.LayoutParams.FLAG_KEEP_SURFACE_WHILE_ANIMATING) == 0 |
| 2825 | || win.mSurfacePendingDestroy) { |
| 2826 | // We are being called from a local process, which |
| 2827 | // means outSurface holds its current surface. Ensure the |
| 2828 | // surface object is cleared, but we don't want it actually |
| 2829 | // destroyed at this point. |
| 2830 | win.mSurfacePendingDestroy = false; |
| 2831 | outSurface.release(); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2832 | if (DEBUG_VISIBILITY) Slog.i(TAG, "Releasing surface in: " + win); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2833 | } else if (win.mSurface != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2834 | if (DEBUG_VISIBILITY) Slog.i(TAG, |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2835 | "Keeping surface, will report destroy: " + win); |
| 2836 | win.mReportDestroySurface = true; |
| 2837 | outSurface.copyFrom(win.mSurface); |
| 2838 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2839 | } |
| 2840 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2841 | if (focusMayChange) { |
| 2842 | //System.out.println("Focus may change: " + win.mAttrs.getTitle()); |
| 2843 | if (updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2844 | imMayMove = false; |
| 2845 | } |
| 2846 | //System.out.println("Relayout " + win + ": focus=" + mCurrentFocus); |
| 2847 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2848 | |
The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 2849 | // updateFocusedWindowLocked() already assigned layers so we only need to |
| 2850 | // reassign them at this point if the IM window state gets shuffled |
| 2851 | boolean assignLayers = false; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2852 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2853 | if (imMayMove) { |
Dianne Hackborn | 8abd5f0 | 2009-11-20 18:09:03 -0800 | [diff] [blame] | 2854 | if (moveInputMethodWindowsIfNeededLocked(false) || displayed) { |
| 2855 | // Little hack here -- we -should- be able to rely on the |
| 2856 | // function to return true if the IME has moved and needs |
| 2857 | // its layer recomputed. However, if the IME was hidden |
| 2858 | // and isn't actually moved in the list, its layer may be |
| 2859 | // 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] | 2860 | assignLayers = true; |
| 2861 | } |
| 2862 | } |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2863 | if (wallpaperMayMove) { |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 2864 | if ((adjustWallpaperWindowsLocked()&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) { |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2865 | assignLayers = true; |
| 2866 | } |
| 2867 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2868 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2869 | mLayoutNeeded = true; |
| 2870 | win.mGivenInsetsPending = insetsPending; |
| 2871 | if (assignLayers) { |
| 2872 | assignLayersLocked(); |
| 2873 | } |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2874 | configChanged = updateOrientationFromAppTokensLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2875 | performLayoutAndPlaceSurfacesLocked(); |
Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 2876 | if (displayed && win.mIsWallpaper) { |
| 2877 | updateWallpaperOffsetLocked(win, mDisplay.getWidth(), |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 2878 | mDisplay.getHeight(), false); |
Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 2879 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2880 | if (win.mAppToken != null) { |
| 2881 | win.mAppToken.updateReportedVisibilityLocked(); |
| 2882 | } |
| 2883 | outFrame.set(win.mFrame); |
| 2884 | outContentInsets.set(win.mContentInsets); |
| 2885 | outVisibleInsets.set(win.mVisibleInsets); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2886 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2887 | TAG, "Relayout given client " + client.asBinder() |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2888 | + ", requestedWidth=" + requestedWidth |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2889 | + ", requestedHeight=" + requestedHeight |
| 2890 | + ", viewVisibility=" + viewVisibility |
| 2891 | + "\nRelayout returning frame=" + outFrame |
| 2892 | + ", surface=" + outSurface); |
| 2893 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2894 | if (localLOGV || DEBUG_FOCUS) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2895 | TAG, "Relayout of " + win + ": focusMayChange=" + focusMayChange); |
| 2896 | |
| 2897 | inTouchMode = mInTouchMode; |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 2898 | |
| 2899 | mInputMonitor.updateInputWindowsLw(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2900 | } |
| 2901 | |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2902 | if (configChanged) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2903 | sendNewConfiguration(); |
| 2904 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2905 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2906 | Binder.restoreCallingIdentity(origId); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2907 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2908 | return (inTouchMode ? WindowManagerImpl.RELAYOUT_IN_TOUCH_MODE : 0) |
| 2909 | | (displayed ? WindowManagerImpl.RELAYOUT_FIRST_TIME : 0); |
| 2910 | } |
| 2911 | |
| 2912 | public void finishDrawingWindow(Session session, IWindow client) { |
| 2913 | final long origId = Binder.clearCallingIdentity(); |
| 2914 | synchronized(mWindowMap) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2915 | WindowState win = windowForClientLocked(session, client, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2916 | if (win != null && win.finishDrawingLocked()) { |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 2917 | if ((win.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0) { |
| 2918 | adjustWallpaperWindowsLocked(); |
| 2919 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2920 | mLayoutNeeded = true; |
| 2921 | performLayoutAndPlaceSurfacesLocked(); |
| 2922 | } |
| 2923 | } |
| 2924 | Binder.restoreCallingIdentity(origId); |
| 2925 | } |
| 2926 | |
| 2927 | private AttributeCache.Entry getCachedAnimations(WindowManager.LayoutParams lp) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2928 | 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] | 2929 | + (lp != null ? lp.packageName : null) |
| 2930 | + " resId=0x" + (lp != null ? Integer.toHexString(lp.windowAnimations) : null)); |
| 2931 | if (lp != null && lp.windowAnimations != 0) { |
| 2932 | // If this is a system resource, don't try to load it from the |
| 2933 | // application resources. It is nice to avoid loading application |
| 2934 | // resources if we can. |
| 2935 | String packageName = lp.packageName != null ? lp.packageName : "android"; |
| 2936 | int resId = lp.windowAnimations; |
| 2937 | if ((resId&0xFF000000) == 0x01000000) { |
| 2938 | packageName = "android"; |
| 2939 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2940 | 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] | 2941 | + packageName); |
| 2942 | return AttributeCache.instance().get(packageName, resId, |
| 2943 | com.android.internal.R.styleable.WindowAnimation); |
| 2944 | } |
| 2945 | return null; |
| 2946 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2947 | |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2948 | private AttributeCache.Entry getCachedAnimations(String packageName, int resId) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2949 | if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: params package=" |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2950 | + packageName + " resId=0x" + Integer.toHexString(resId)); |
| 2951 | if (packageName != null) { |
| 2952 | if ((resId&0xFF000000) == 0x01000000) { |
| 2953 | packageName = "android"; |
| 2954 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2955 | if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: picked package=" |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2956 | + packageName); |
| 2957 | return AttributeCache.instance().get(packageName, resId, |
| 2958 | com.android.internal.R.styleable.WindowAnimation); |
| 2959 | } |
| 2960 | return null; |
| 2961 | } |
| 2962 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2963 | private void applyEnterAnimationLocked(WindowState win) { |
| 2964 | int transit = WindowManagerPolicy.TRANSIT_SHOW; |
| 2965 | if (win.mEnterAnimationPending) { |
| 2966 | win.mEnterAnimationPending = false; |
| 2967 | transit = WindowManagerPolicy.TRANSIT_ENTER; |
| 2968 | } |
| 2969 | |
| 2970 | applyAnimationLocked(win, transit, true); |
| 2971 | } |
| 2972 | |
| 2973 | private boolean applyAnimationLocked(WindowState win, |
| 2974 | int transit, boolean isEntrance) { |
| 2975 | if (win.mLocalAnimating && win.mAnimationIsEntrance == isEntrance) { |
| 2976 | // If we are trying to apply an animation, but already running |
| 2977 | // an animation of the same type, then just leave that one alone. |
| 2978 | return true; |
| 2979 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2980 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2981 | // Only apply an animation if the display isn't frozen. If it is |
| 2982 | // frozen, there is no reason to animate and it can cause strange |
| 2983 | // artifacts when we unfreeze the display if some different animation |
| 2984 | // is running. |
Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 2985 | if (!mDisplayFrozen && mPolicy.isScreenOn()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2986 | int anim = mPolicy.selectAnimationLw(win, transit); |
| 2987 | int attr = -1; |
| 2988 | Animation a = null; |
| 2989 | if (anim != 0) { |
| 2990 | a = AnimationUtils.loadAnimation(mContext, anim); |
| 2991 | } else { |
| 2992 | switch (transit) { |
| 2993 | case WindowManagerPolicy.TRANSIT_ENTER: |
| 2994 | attr = com.android.internal.R.styleable.WindowAnimation_windowEnterAnimation; |
| 2995 | break; |
| 2996 | case WindowManagerPolicy.TRANSIT_EXIT: |
| 2997 | attr = com.android.internal.R.styleable.WindowAnimation_windowExitAnimation; |
| 2998 | break; |
| 2999 | case WindowManagerPolicy.TRANSIT_SHOW: |
| 3000 | attr = com.android.internal.R.styleable.WindowAnimation_windowShowAnimation; |
| 3001 | break; |
| 3002 | case WindowManagerPolicy.TRANSIT_HIDE: |
| 3003 | attr = com.android.internal.R.styleable.WindowAnimation_windowHideAnimation; |
| 3004 | break; |
| 3005 | } |
| 3006 | if (attr >= 0) { |
| 3007 | a = loadAnimation(win.mAttrs, attr); |
| 3008 | } |
| 3009 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3010 | if (DEBUG_ANIM) Slog.v(TAG, "applyAnimation: win=" + win |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3011 | + " anim=" + anim + " attr=0x" + Integer.toHexString(attr) |
| 3012 | + " mAnimation=" + win.mAnimation |
| 3013 | + " isEntrance=" + isEntrance); |
| 3014 | if (a != null) { |
| 3015 | if (DEBUG_ANIM) { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 3016 | RuntimeException e = null; |
| 3017 | if (!HIDE_STACK_CRAWLS) { |
| 3018 | e = new RuntimeException(); |
| 3019 | e.fillInStackTrace(); |
| 3020 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3021 | Slog.v(TAG, "Loaded animation " + a + " for " + win, e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3022 | } |
| 3023 | win.setAnimation(a); |
| 3024 | win.mAnimationIsEntrance = isEntrance; |
| 3025 | } |
| 3026 | } else { |
| 3027 | win.clearAnimation(); |
| 3028 | } |
| 3029 | |
| 3030 | return win.mAnimation != null; |
| 3031 | } |
| 3032 | |
| 3033 | private Animation loadAnimation(WindowManager.LayoutParams lp, int animAttr) { |
| 3034 | int anim = 0; |
| 3035 | Context context = mContext; |
| 3036 | if (animAttr >= 0) { |
| 3037 | AttributeCache.Entry ent = getCachedAnimations(lp); |
| 3038 | if (ent != null) { |
| 3039 | context = ent.context; |
| 3040 | anim = ent.array.getResourceId(animAttr, 0); |
| 3041 | } |
| 3042 | } |
| 3043 | if (anim != 0) { |
| 3044 | return AnimationUtils.loadAnimation(context, anim); |
| 3045 | } |
| 3046 | return null; |
| 3047 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3048 | |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 3049 | private Animation loadAnimation(String packageName, int resId) { |
| 3050 | int anim = 0; |
| 3051 | Context context = mContext; |
| 3052 | if (resId >= 0) { |
| 3053 | AttributeCache.Entry ent = getCachedAnimations(packageName, resId); |
| 3054 | if (ent != null) { |
| 3055 | context = ent.context; |
| 3056 | anim = resId; |
| 3057 | } |
| 3058 | } |
| 3059 | if (anim != 0) { |
| 3060 | return AnimationUtils.loadAnimation(context, anim); |
| 3061 | } |
| 3062 | return null; |
| 3063 | } |
| 3064 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3065 | private boolean applyAnimationLocked(AppWindowToken wtoken, |
| 3066 | WindowManager.LayoutParams lp, int transit, boolean enter) { |
| 3067 | // Only apply an animation if the display isn't frozen. If it is |
| 3068 | // frozen, there is no reason to animate and it can cause strange |
| 3069 | // artifacts when we unfreeze the display if some different animation |
| 3070 | // is running. |
Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 3071 | if (!mDisplayFrozen && mPolicy.isScreenOn()) { |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 3072 | Animation a; |
Mitsuru Oshima | d2967e2 | 2009-07-20 14:01:43 -0700 | [diff] [blame] | 3073 | if (lp != null && (lp.flags & FLAG_COMPATIBLE_WINDOW) != 0) { |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 3074 | a = new FadeInOutAnimation(enter); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3075 | if (DEBUG_ANIM) Slog.v(TAG, |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 3076 | "applying FadeInOutAnimation for a window in compatibility mode"); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 3077 | } else if (mNextAppTransitionPackage != null) { |
| 3078 | a = loadAnimation(mNextAppTransitionPackage, enter ? |
| 3079 | mNextAppTransitionEnter : mNextAppTransitionExit); |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 3080 | } else { |
| 3081 | int animAttr = 0; |
| 3082 | switch (transit) { |
| 3083 | case WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN: |
| 3084 | animAttr = enter |
| 3085 | ? com.android.internal.R.styleable.WindowAnimation_activityOpenEnterAnimation |
| 3086 | : com.android.internal.R.styleable.WindowAnimation_activityOpenExitAnimation; |
| 3087 | break; |
| 3088 | case WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE: |
| 3089 | animAttr = enter |
| 3090 | ? com.android.internal.R.styleable.WindowAnimation_activityCloseEnterAnimation |
| 3091 | : com.android.internal.R.styleable.WindowAnimation_activityCloseExitAnimation; |
| 3092 | break; |
| 3093 | case WindowManagerPolicy.TRANSIT_TASK_OPEN: |
| 3094 | animAttr = enter |
| 3095 | ? com.android.internal.R.styleable.WindowAnimation_taskOpenEnterAnimation |
| 3096 | : com.android.internal.R.styleable.WindowAnimation_taskOpenExitAnimation; |
| 3097 | break; |
| 3098 | case WindowManagerPolicy.TRANSIT_TASK_CLOSE: |
| 3099 | animAttr = enter |
| 3100 | ? com.android.internal.R.styleable.WindowAnimation_taskCloseEnterAnimation |
| 3101 | : com.android.internal.R.styleable.WindowAnimation_taskCloseExitAnimation; |
| 3102 | break; |
| 3103 | case WindowManagerPolicy.TRANSIT_TASK_TO_FRONT: |
| 3104 | animAttr = enter |
| 3105 | ? com.android.internal.R.styleable.WindowAnimation_taskToFrontEnterAnimation |
| 3106 | : com.android.internal.R.styleable.WindowAnimation_taskToFrontExitAnimation; |
| 3107 | break; |
| 3108 | case WindowManagerPolicy.TRANSIT_TASK_TO_BACK: |
| 3109 | animAttr = enter |
Mitsuru Oshima | 5a2b91d | 2009-07-16 16:30:02 -0700 | [diff] [blame] | 3110 | ? com.android.internal.R.styleable.WindowAnimation_taskToBackEnterAnimation |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 3111 | : com.android.internal.R.styleable.WindowAnimation_taskToBackExitAnimation; |
| 3112 | break; |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 3113 | case WindowManagerPolicy.TRANSIT_WALLPAPER_OPEN: |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 3114 | animAttr = enter |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 3115 | ? com.android.internal.R.styleable.WindowAnimation_wallpaperOpenEnterAnimation |
| 3116 | : com.android.internal.R.styleable.WindowAnimation_wallpaperOpenExitAnimation; |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 3117 | break; |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 3118 | case WindowManagerPolicy.TRANSIT_WALLPAPER_CLOSE: |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 3119 | animAttr = enter |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 3120 | ? com.android.internal.R.styleable.WindowAnimation_wallpaperCloseEnterAnimation |
| 3121 | : com.android.internal.R.styleable.WindowAnimation_wallpaperCloseExitAnimation; |
| 3122 | break; |
| 3123 | case WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_OPEN: |
| 3124 | animAttr = enter |
| 3125 | ? com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenEnterAnimation |
| 3126 | : com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenExitAnimation; |
| 3127 | break; |
| 3128 | case WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_CLOSE: |
| 3129 | animAttr = enter |
| 3130 | ? com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseEnterAnimation |
| 3131 | : com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseExitAnimation; |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 3132 | break; |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 3133 | } |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 3134 | a = animAttr != 0 ? loadAnimation(lp, animAttr) : null; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3135 | if (DEBUG_ANIM) Slog.v(TAG, "applyAnimation: wtoken=" + wtoken |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 3136 | + " anim=" + a |
| 3137 | + " animAttr=0x" + Integer.toHexString(animAttr) |
| 3138 | + " transit=" + transit); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3139 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3140 | if (a != null) { |
| 3141 | if (DEBUG_ANIM) { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 3142 | RuntimeException e = null; |
| 3143 | if (!HIDE_STACK_CRAWLS) { |
| 3144 | e = new RuntimeException(); |
| 3145 | e.fillInStackTrace(); |
| 3146 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3147 | Slog.v(TAG, "Loaded animation " + a + " for " + wtoken, e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3148 | } |
| 3149 | wtoken.setAnimation(a); |
| 3150 | } |
| 3151 | } else { |
| 3152 | wtoken.clearAnimation(); |
| 3153 | } |
| 3154 | |
| 3155 | return wtoken.animation != null; |
| 3156 | } |
| 3157 | |
| 3158 | // ------------------------------------------------------------- |
| 3159 | // Application Window Tokens |
| 3160 | // ------------------------------------------------------------- |
| 3161 | |
| 3162 | public void validateAppTokens(List tokens) { |
| 3163 | int v = tokens.size()-1; |
| 3164 | int m = mAppTokens.size()-1; |
| 3165 | while (v >= 0 && m >= 0) { |
| 3166 | AppWindowToken wtoken = mAppTokens.get(m); |
| 3167 | if (wtoken.removed) { |
| 3168 | m--; |
| 3169 | continue; |
| 3170 | } |
| 3171 | if (tokens.get(v) != wtoken.token) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3172 | 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] | 3173 | + " @ " + v + ", internal is " + wtoken.token + " @ " + m); |
| 3174 | } |
| 3175 | v--; |
| 3176 | m--; |
| 3177 | } |
| 3178 | while (v >= 0) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3179 | 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] | 3180 | v--; |
| 3181 | } |
| 3182 | while (m >= 0) { |
| 3183 | AppWindowToken wtoken = mAppTokens.get(m); |
| 3184 | if (!wtoken.removed) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3185 | Slog.w(TAG, "Invalid internal token: " + wtoken.token + " @ " + m); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3186 | } |
| 3187 | m--; |
| 3188 | } |
| 3189 | } |
| 3190 | |
| 3191 | boolean checkCallingPermission(String permission, String func) { |
| 3192 | // Quick check: if the calling permission is me, it's all okay. |
| 3193 | if (Binder.getCallingPid() == Process.myPid()) { |
| 3194 | return true; |
| 3195 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3196 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3197 | if (mContext.checkCallingPermission(permission) |
| 3198 | == PackageManager.PERMISSION_GRANTED) { |
| 3199 | return true; |
| 3200 | } |
| 3201 | String msg = "Permission Denial: " + func + " from pid=" |
| 3202 | + Binder.getCallingPid() |
| 3203 | + ", uid=" + Binder.getCallingUid() |
| 3204 | + " requires " + permission; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3205 | Slog.w(TAG, msg); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3206 | return false; |
| 3207 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3208 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3209 | AppWindowToken findAppWindowToken(IBinder token) { |
| 3210 | WindowToken wtoken = mTokenMap.get(token); |
| 3211 | if (wtoken == null) { |
| 3212 | return null; |
| 3213 | } |
| 3214 | return wtoken.appWindowToken; |
| 3215 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3216 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3217 | public void addWindowToken(IBinder token, int type) { |
| 3218 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3219 | "addWindowToken()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3220 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3221 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3222 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3223 | synchronized(mWindowMap) { |
| 3224 | WindowToken wtoken = mTokenMap.get(token); |
| 3225 | if (wtoken != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3226 | 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] | 3227 | return; |
| 3228 | } |
| 3229 | wtoken = new WindowToken(token, type, true); |
| 3230 | mTokenMap.put(token, wtoken); |
| 3231 | mTokenList.add(wtoken); |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 3232 | if (type == TYPE_WALLPAPER) { |
| 3233 | mWallpaperTokens.add(wtoken); |
| 3234 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3235 | } |
| 3236 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3237 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3238 | public void removeWindowToken(IBinder token) { |
| 3239 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3240 | "removeWindowToken()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3241 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3242 | } |
| 3243 | |
| 3244 | final long origId = Binder.clearCallingIdentity(); |
| 3245 | synchronized(mWindowMap) { |
| 3246 | WindowToken wtoken = mTokenMap.remove(token); |
| 3247 | mTokenList.remove(wtoken); |
| 3248 | if (wtoken != null) { |
| 3249 | boolean delayed = false; |
| 3250 | if (!wtoken.hidden) { |
| 3251 | wtoken.hidden = true; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3252 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3253 | final int N = wtoken.windows.size(); |
| 3254 | boolean changed = false; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3255 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3256 | for (int i=0; i<N; i++) { |
| 3257 | WindowState win = wtoken.windows.get(i); |
| 3258 | |
| 3259 | if (win.isAnimating()) { |
| 3260 | delayed = true; |
| 3261 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3262 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3263 | if (win.isVisibleNow()) { |
| 3264 | applyAnimationLocked(win, |
| 3265 | WindowManagerPolicy.TRANSIT_EXIT, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3266 | changed = true; |
| 3267 | } |
| 3268 | } |
| 3269 | |
| 3270 | if (changed) { |
| 3271 | mLayoutNeeded = true; |
| 3272 | performLayoutAndPlaceSurfacesLocked(); |
| 3273 | updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL); |
| 3274 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3275 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3276 | if (delayed) { |
| 3277 | mExitingTokens.add(wtoken); |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 3278 | } else if (wtoken.windowType == TYPE_WALLPAPER) { |
| 3279 | mWallpaperTokens.remove(wtoken); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3280 | } |
| 3281 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3282 | |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 3283 | mInputMonitor.updateInputWindowsLw(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3284 | } else { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3285 | 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] | 3286 | } |
| 3287 | } |
| 3288 | Binder.restoreCallingIdentity(origId); |
| 3289 | } |
| 3290 | |
| 3291 | public void addAppToken(int addPos, IApplicationToken token, |
| 3292 | int groupId, int requestedOrientation, boolean fullscreen) { |
| 3293 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3294 | "addAppToken()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3295 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3296 | } |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 3297 | |
| 3298 | // Get the dispatching timeout here while we are not holding any locks so that it |
| 3299 | // can be cached by the AppWindowToken. The timeout value is used later by the |
| 3300 | // input dispatcher in code that does hold locks. If we did not cache the value |
| 3301 | // here we would run the chance of introducing a deadlock between the window manager |
| 3302 | // (which holds locks while updating the input dispatcher state) and the activity manager |
| 3303 | // (which holds locks while querying the application token). |
| 3304 | long inputDispatchingTimeoutNanos; |
| 3305 | try { |
| 3306 | inputDispatchingTimeoutNanos = token.getKeyDispatchingTimeout() * 1000000L; |
| 3307 | } catch (RemoteException ex) { |
| 3308 | Slog.w(TAG, "Could not get dispatching timeout.", ex); |
| 3309 | inputDispatchingTimeoutNanos = DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS; |
| 3310 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3311 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3312 | synchronized(mWindowMap) { |
| 3313 | AppWindowToken wtoken = findAppWindowToken(token.asBinder()); |
| 3314 | if (wtoken != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3315 | 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] | 3316 | return; |
| 3317 | } |
| 3318 | wtoken = new AppWindowToken(token); |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 3319 | wtoken.inputDispatchingTimeoutNanos = inputDispatchingTimeoutNanos; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3320 | wtoken.groupId = groupId; |
| 3321 | wtoken.appFullscreen = fullscreen; |
| 3322 | wtoken.requestedOrientation = requestedOrientation; |
| 3323 | mAppTokens.add(addPos, wtoken); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3324 | 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] | 3325 | mTokenMap.put(token.asBinder(), wtoken); |
| 3326 | mTokenList.add(wtoken); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3327 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3328 | // Application tokens start out hidden. |
| 3329 | wtoken.hidden = true; |
| 3330 | wtoken.hiddenRequested = true; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3331 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3332 | //dump(); |
| 3333 | } |
| 3334 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3335 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3336 | public void setAppGroupId(IBinder token, int groupId) { |
| 3337 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3338 | "setAppStartingIcon()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3339 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3340 | } |
| 3341 | |
| 3342 | synchronized(mWindowMap) { |
| 3343 | AppWindowToken wtoken = findAppWindowToken(token); |
| 3344 | if (wtoken == null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3345 | 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] | 3346 | return; |
| 3347 | } |
| 3348 | wtoken.groupId = groupId; |
| 3349 | } |
| 3350 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3351 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3352 | public int getOrientationFromWindowsLocked() { |
| 3353 | int pos = mWindows.size() - 1; |
| 3354 | while (pos >= 0) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 3355 | WindowState wtoken = mWindows.get(pos); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3356 | pos--; |
| 3357 | if (wtoken.mAppToken != null) { |
| 3358 | // We hit an application window. so the orientation will be determined by the |
| 3359 | // app window. No point in continuing further. |
| 3360 | return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
| 3361 | } |
Christopher Tate | b696aee | 2010-04-02 19:08:30 -0700 | [diff] [blame] | 3362 | if (!wtoken.isVisibleLw() || !wtoken.mPolicyVisibilityAfterAnim) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3363 | continue; |
| 3364 | } |
| 3365 | int req = wtoken.mAttrs.screenOrientation; |
| 3366 | if((req == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) || |
| 3367 | (req == ActivityInfo.SCREEN_ORIENTATION_BEHIND)){ |
| 3368 | continue; |
| 3369 | } else { |
| 3370 | return req; |
| 3371 | } |
| 3372 | } |
| 3373 | return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
| 3374 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3375 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3376 | public int getOrientationFromAppTokensLocked() { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3377 | int pos = mAppTokens.size() - 1; |
| 3378 | int curGroup = 0; |
| 3379 | int lastOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
| 3380 | boolean findingBehind = false; |
| 3381 | boolean haveGroup = false; |
| 3382 | boolean lastFullscreen = false; |
| 3383 | while (pos >= 0) { |
| 3384 | AppWindowToken wtoken = mAppTokens.get(pos); |
| 3385 | pos--; |
| 3386 | // if we're about to tear down this window and not seek for |
| 3387 | // the behind activity, don't use it for orientation |
| 3388 | if (!findingBehind |
| 3389 | && (!wtoken.hidden && wtoken.hiddenRequested)) { |
| 3390 | continue; |
| 3391 | } |
| 3392 | |
| 3393 | if (!haveGroup) { |
| 3394 | // We ignore any hidden applications on the top. |
| 3395 | if (wtoken.hiddenRequested || wtoken.willBeHidden) { |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3396 | continue; |
| 3397 | } |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3398 | haveGroup = true; |
| 3399 | curGroup = wtoken.groupId; |
| 3400 | lastOrientation = wtoken.requestedOrientation; |
| 3401 | } else if (curGroup != wtoken.groupId) { |
| 3402 | // If we have hit a new application group, and the bottom |
| 3403 | // of the previous group didn't explicitly say to use |
| 3404 | // the orientation behind it, and the last app was |
| 3405 | // full screen, then we'll stick with the |
| 3406 | // user's orientation. |
| 3407 | if (lastOrientation != ActivityInfo.SCREEN_ORIENTATION_BEHIND |
| 3408 | && lastFullscreen) { |
| 3409 | return lastOrientation; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3410 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3411 | } |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3412 | int or = wtoken.requestedOrientation; |
| 3413 | // If this application is fullscreen, and didn't explicitly say |
| 3414 | // to use the orientation behind it, then just take whatever |
| 3415 | // orientation it has and ignores whatever is under it. |
| 3416 | lastFullscreen = wtoken.appFullscreen; |
| 3417 | if (lastFullscreen |
| 3418 | && or != ActivityInfo.SCREEN_ORIENTATION_BEHIND) { |
| 3419 | return or; |
| 3420 | } |
| 3421 | // If this application has requested an explicit orientation, |
| 3422 | // then use it. |
Dianne Hackborn | e5439f2 | 2010-10-02 16:53:50 -0700 | [diff] [blame] | 3423 | if (or != ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED |
| 3424 | && or != ActivityInfo.SCREEN_ORIENTATION_BEHIND) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3425 | return or; |
| 3426 | } |
| 3427 | findingBehind |= (or == ActivityInfo.SCREEN_ORIENTATION_BEHIND); |
| 3428 | } |
| 3429 | return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3430 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3431 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3432 | public Configuration updateOrientationFromAppTokens( |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3433 | Configuration currentConfig, IBinder freezeThisOneIfNeeded) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3434 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3435 | "updateOrientationFromAppTokens()")) { |
| 3436 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| 3437 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3438 | |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3439 | Configuration config = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3440 | long ident = Binder.clearCallingIdentity(); |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3441 | |
| 3442 | synchronized(mWindowMap) { |
| 3443 | if (updateOrientationFromAppTokensLocked()) { |
| 3444 | if (freezeThisOneIfNeeded != null) { |
| 3445 | AppWindowToken wtoken = findAppWindowToken( |
| 3446 | freezeThisOneIfNeeded); |
| 3447 | if (wtoken != null) { |
| 3448 | startAppFreezingScreenLocked(wtoken, |
| 3449 | ActivityInfo.CONFIG_ORIENTATION); |
| 3450 | } |
| 3451 | } |
| 3452 | config = computeNewConfigurationLocked(); |
| 3453 | |
| 3454 | } else if (currentConfig != null) { |
| 3455 | // No obvious action we need to take, but if our current |
Casey Burkhardt | 0920ba5 | 2010-08-03 12:04:19 -0700 | [diff] [blame] | 3456 | // state mismatches the activity manager's, update it, |
| 3457 | // disregarding font scale, which should remain set to |
| 3458 | // the value of the previous configuration. |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3459 | mTempConfiguration.setToDefaults(); |
Casey Burkhardt | 0920ba5 | 2010-08-03 12:04:19 -0700 | [diff] [blame] | 3460 | mTempConfiguration.fontScale = currentConfig.fontScale; |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3461 | if (computeNewConfigurationLocked(mTempConfiguration)) { |
| 3462 | if (currentConfig.diff(mTempConfiguration) != 0) { |
| 3463 | mWaitingForConfig = true; |
| 3464 | mLayoutNeeded = true; |
| 3465 | startFreezingDisplayLocked(); |
| 3466 | config = new Configuration(mTempConfiguration); |
| 3467 | } |
| 3468 | } |
| 3469 | } |
| 3470 | } |
| 3471 | |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3472 | Binder.restoreCallingIdentity(ident); |
| 3473 | return config; |
| 3474 | } |
| 3475 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3476 | /* |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3477 | * Determine the new desired orientation of the display, returning |
| 3478 | * a non-null new Configuration if it has changed from the current |
| 3479 | * orientation. IF TRUE IS RETURNED SOMEONE MUST CALL |
| 3480 | * setNewConfiguration() TO TELL THE WINDOW MANAGER IT CAN UNFREEZE THE |
| 3481 | * SCREEN. This will typically be done for you if you call |
| 3482 | * sendNewConfiguration(). |
| 3483 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3484 | * The orientation is computed from non-application windows first. If none of |
| 3485 | * the non-application windows specify orientation, the orientation is computed from |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3486 | * application tokens. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3487 | * @see android.view.IWindowManager#updateOrientationFromAppTokens( |
| 3488 | * android.os.IBinder) |
| 3489 | */ |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3490 | boolean updateOrientationFromAppTokensLocked() { |
Christopher Tate | b696aee | 2010-04-02 19:08:30 -0700 | [diff] [blame] | 3491 | if (mDisplayFrozen) { |
| 3492 | // If the display is frozen, some activities may be in the middle |
| 3493 | // of restarting, and thus have removed their old window. If the |
| 3494 | // window has the flag to hide the lock screen, then the lock screen |
| 3495 | // can re-appear and inflict its own orientation on us. Keep the |
| 3496 | // orientation stable until this all settles down. |
| 3497 | return false; |
| 3498 | } |
| 3499 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3500 | boolean changed = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3501 | long ident = Binder.clearCallingIdentity(); |
| 3502 | try { |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 3503 | int req = computeForcedAppOrientationLocked(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3504 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3505 | if (req != mForcedAppOrientation) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3506 | mForcedAppOrientation = req; |
| 3507 | //send a message to Policy indicating orientation change to take |
| 3508 | //action like disabling/enabling sensors etc., |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 3509 | mPolicy.setCurrentOrientationLw(req); |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3510 | if (setRotationUncheckedLocked(WindowManagerPolicy.USE_LAST_ROTATION, |
| 3511 | mLastRotationFlags | Surface.FLAGS_ORIENTATION_ANIMATION_DISABLE)) { |
| 3512 | changed = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3513 | } |
| 3514 | } |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3515 | |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3516 | return changed; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3517 | } finally { |
| 3518 | Binder.restoreCallingIdentity(ident); |
| 3519 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3520 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3521 | |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 3522 | int computeForcedAppOrientationLocked() { |
| 3523 | int req = getOrientationFromWindowsLocked(); |
| 3524 | if (req == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) { |
| 3525 | req = getOrientationFromAppTokensLocked(); |
| 3526 | } |
| 3527 | return req; |
| 3528 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3529 | |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3530 | public void setNewConfiguration(Configuration config) { |
| 3531 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3532 | "setNewConfiguration()")) { |
| 3533 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| 3534 | } |
| 3535 | |
| 3536 | synchronized(mWindowMap) { |
| 3537 | mCurConfiguration = new Configuration(config); |
| 3538 | mWaitingForConfig = false; |
| 3539 | performLayoutAndPlaceSurfacesLocked(); |
| 3540 | } |
| 3541 | } |
| 3542 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3543 | public void setAppOrientation(IApplicationToken token, int requestedOrientation) { |
| 3544 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3545 | "setAppOrientation()")) { |
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 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3548 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3549 | synchronized(mWindowMap) { |
| 3550 | AppWindowToken wtoken = findAppWindowToken(token.asBinder()); |
| 3551 | if (wtoken == null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3552 | 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] | 3553 | return; |
| 3554 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3555 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3556 | wtoken.requestedOrientation = requestedOrientation; |
| 3557 | } |
| 3558 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3559 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3560 | public int getAppOrientation(IApplicationToken token) { |
| 3561 | synchronized(mWindowMap) { |
| 3562 | AppWindowToken wtoken = findAppWindowToken(token.asBinder()); |
| 3563 | if (wtoken == null) { |
| 3564 | return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
| 3565 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3566 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3567 | return wtoken.requestedOrientation; |
| 3568 | } |
| 3569 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3570 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3571 | public void setFocusedApp(IBinder token, boolean moveFocusNow) { |
| 3572 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3573 | "setFocusedApp()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3574 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3575 | } |
| 3576 | |
| 3577 | synchronized(mWindowMap) { |
| 3578 | boolean changed = false; |
| 3579 | if (token == null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3580 | 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] | 3581 | changed = mFocusedApp != null; |
| 3582 | mFocusedApp = null; |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 3583 | if (changed) { |
| 3584 | mInputMonitor.setFocusedAppLw(null); |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 3585 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3586 | } else { |
| 3587 | AppWindowToken newFocus = findAppWindowToken(token); |
| 3588 | if (newFocus == null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3589 | 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] | 3590 | return; |
| 3591 | } |
| 3592 | changed = mFocusedApp != newFocus; |
| 3593 | mFocusedApp = newFocus; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3594 | if (DEBUG_FOCUS) Slog.v(TAG, "Set focused app to: " + mFocusedApp); |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 3595 | if (changed) { |
| 3596 | mInputMonitor.setFocusedAppLw(newFocus); |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 3597 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3598 | } |
| 3599 | |
| 3600 | if (moveFocusNow && changed) { |
| 3601 | final long origId = Binder.clearCallingIdentity(); |
| 3602 | updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL); |
| 3603 | Binder.restoreCallingIdentity(origId); |
| 3604 | } |
| 3605 | } |
| 3606 | } |
| 3607 | |
| 3608 | public void prepareAppTransition(int transit) { |
| 3609 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3610 | "prepareAppTransition()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3611 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3612 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3613 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3614 | synchronized(mWindowMap) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3615 | if (DEBUG_APP_TRANSITIONS) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3616 | TAG, "Prepare app transition: transit=" + transit |
| 3617 | + " mNextAppTransition=" + mNextAppTransition); |
Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 3618 | if (!mDisplayFrozen && mPolicy.isScreenOn()) { |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 3619 | if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET |
| 3620 | || mNextAppTransition == WindowManagerPolicy.TRANSIT_NONE) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3621 | mNextAppTransition = transit; |
Dianne Hackborn | d7cd29d | 2009-07-01 11:22:45 -0700 | [diff] [blame] | 3622 | } else if (transit == WindowManagerPolicy.TRANSIT_TASK_OPEN |
| 3623 | && mNextAppTransition == WindowManagerPolicy.TRANSIT_TASK_CLOSE) { |
| 3624 | // Opening a new task always supersedes a close for the anim. |
| 3625 | mNextAppTransition = transit; |
| 3626 | } else if (transit == WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN |
| 3627 | && mNextAppTransition == WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE) { |
| 3628 | // Opening a new activity always supersedes a close for the anim. |
| 3629 | mNextAppTransition = transit; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3630 | } |
| 3631 | mAppTransitionReady = false; |
| 3632 | mAppTransitionTimeout = false; |
| 3633 | mStartingIconInTransition = false; |
| 3634 | mSkipAppTransitionAnimation = false; |
| 3635 | mH.removeMessages(H.APP_TRANSITION_TIMEOUT); |
| 3636 | mH.sendMessageDelayed(mH.obtainMessage(H.APP_TRANSITION_TIMEOUT), |
| 3637 | 5000); |
| 3638 | } |
| 3639 | } |
| 3640 | } |
| 3641 | |
| 3642 | public int getPendingAppTransition() { |
| 3643 | return mNextAppTransition; |
| 3644 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3645 | |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 3646 | public void overridePendingAppTransition(String packageName, |
| 3647 | int enterAnim, int exitAnim) { |
Dianne Hackborn | 8b571a8 | 2009-09-25 16:09:43 -0700 | [diff] [blame] | 3648 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 3649 | mNextAppTransitionPackage = packageName; |
| 3650 | mNextAppTransitionEnter = enterAnim; |
| 3651 | mNextAppTransitionExit = exitAnim; |
| 3652 | } |
| 3653 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3654 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3655 | public void executeAppTransition() { |
| 3656 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3657 | "executeAppTransition()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3658 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3659 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3660 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3661 | synchronized(mWindowMap) { |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 3662 | if (DEBUG_APP_TRANSITIONS) { |
| 3663 | RuntimeException e = new RuntimeException("here"); |
| 3664 | e.fillInStackTrace(); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3665 | Slog.w(TAG, "Execute app transition: mNextAppTransition=" |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 3666 | + mNextAppTransition, e); |
| 3667 | } |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 3668 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3669 | mAppTransitionReady = true; |
| 3670 | final long origId = Binder.clearCallingIdentity(); |
| 3671 | performLayoutAndPlaceSurfacesLocked(); |
| 3672 | Binder.restoreCallingIdentity(origId); |
| 3673 | } |
| 3674 | } |
| 3675 | } |
| 3676 | |
| 3677 | public void setAppStartingWindow(IBinder token, String pkg, |
| 3678 | int theme, CharSequence nonLocalizedLabel, int labelRes, int icon, |
| 3679 | IBinder transferFrom, boolean createIfNeeded) { |
| 3680 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3681 | "setAppStartingIcon()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3682 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3683 | } |
| 3684 | |
| 3685 | synchronized(mWindowMap) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3686 | if (DEBUG_STARTING_WINDOW) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3687 | TAG, "setAppStartingIcon: token=" + token + " pkg=" + pkg |
| 3688 | + " transferFrom=" + transferFrom); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3689 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3690 | AppWindowToken wtoken = findAppWindowToken(token); |
| 3691 | if (wtoken == null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3692 | 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] | 3693 | return; |
| 3694 | } |
| 3695 | |
| 3696 | // If the display is frozen, we won't do anything until the |
| 3697 | // actual window is displayed so there is no reason to put in |
| 3698 | // the starting window. |
Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 3699 | if (mDisplayFrozen || !mPolicy.isScreenOn()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3700 | return; |
| 3701 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3702 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3703 | if (wtoken.startingData != null) { |
| 3704 | return; |
| 3705 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3706 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3707 | if (transferFrom != null) { |
| 3708 | AppWindowToken ttoken = findAppWindowToken(transferFrom); |
| 3709 | if (ttoken != null) { |
| 3710 | WindowState startingWindow = ttoken.startingWindow; |
| 3711 | if (startingWindow != null) { |
| 3712 | if (mStartingIconInTransition) { |
| 3713 | // In this case, the starting icon has already |
| 3714 | // been displayed, so start letting windows get |
| 3715 | // shown immediately without any more transitions. |
| 3716 | mSkipAppTransitionAnimation = true; |
| 3717 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3718 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3719 | "Moving existing starting from " + ttoken |
| 3720 | + " to " + wtoken); |
| 3721 | final long origId = Binder.clearCallingIdentity(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3722 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3723 | // Transfer the starting window over to the new |
| 3724 | // token. |
| 3725 | wtoken.startingData = ttoken.startingData; |
| 3726 | wtoken.startingView = ttoken.startingView; |
| 3727 | wtoken.startingWindow = startingWindow; |
| 3728 | ttoken.startingData = null; |
| 3729 | ttoken.startingView = null; |
| 3730 | ttoken.startingWindow = null; |
| 3731 | ttoken.startingMoved = true; |
| 3732 | startingWindow.mToken = wtoken; |
Dianne Hackborn | ef49c57 | 2009-03-24 19:27:32 -0700 | [diff] [blame] | 3733 | startingWindow.mRootToken = wtoken; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3734 | startingWindow.mAppToken = wtoken; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3735 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 3736 | "Removing starting window: " + startingWindow); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3737 | mWindows.remove(startingWindow); |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 3738 | mWindowsChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3739 | ttoken.windows.remove(startingWindow); |
| 3740 | ttoken.allAppWindows.remove(startingWindow); |
| 3741 | addWindowToListInOrderLocked(startingWindow, true); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3742 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3743 | // Propagate other interesting state between the |
| 3744 | // tokens. If the old token is displayed, we should |
| 3745 | // immediately force the new one to be displayed. If |
| 3746 | // it is animating, we need to move that animation to |
| 3747 | // the new one. |
| 3748 | if (ttoken.allDrawn) { |
| 3749 | wtoken.allDrawn = true; |
| 3750 | } |
| 3751 | if (ttoken.firstWindowDrawn) { |
| 3752 | wtoken.firstWindowDrawn = true; |
| 3753 | } |
| 3754 | if (!ttoken.hidden) { |
| 3755 | wtoken.hidden = false; |
| 3756 | wtoken.hiddenRequested = false; |
| 3757 | wtoken.willBeHidden = false; |
| 3758 | } |
| 3759 | if (wtoken.clientHidden != ttoken.clientHidden) { |
| 3760 | wtoken.clientHidden = ttoken.clientHidden; |
| 3761 | wtoken.sendAppVisibilityToClients(); |
| 3762 | } |
| 3763 | if (ttoken.animation != null) { |
| 3764 | wtoken.animation = ttoken.animation; |
| 3765 | wtoken.animating = ttoken.animating; |
| 3766 | wtoken.animLayerAdjustment = ttoken.animLayerAdjustment; |
| 3767 | ttoken.animation = null; |
| 3768 | ttoken.animLayerAdjustment = 0; |
| 3769 | wtoken.updateLayers(); |
| 3770 | ttoken.updateLayers(); |
| 3771 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3772 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3773 | updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3774 | mLayoutNeeded = true; |
| 3775 | performLayoutAndPlaceSurfacesLocked(); |
| 3776 | Binder.restoreCallingIdentity(origId); |
| 3777 | return; |
| 3778 | } else if (ttoken.startingData != null) { |
| 3779 | // The previous app was getting ready to show a |
| 3780 | // starting window, but hasn't yet done so. Steal it! |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3781 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3782 | "Moving pending starting from " + ttoken |
| 3783 | + " to " + wtoken); |
| 3784 | wtoken.startingData = ttoken.startingData; |
| 3785 | ttoken.startingData = null; |
| 3786 | ttoken.startingMoved = true; |
| 3787 | Message m = mH.obtainMessage(H.ADD_STARTING, wtoken); |
| 3788 | // Note: we really want to do sendMessageAtFrontOfQueue() because we |
| 3789 | // want to process the message ASAP, before any other queued |
| 3790 | // messages. |
| 3791 | mH.sendMessageAtFrontOfQueue(m); |
| 3792 | return; |
| 3793 | } |
| 3794 | } |
| 3795 | } |
| 3796 | |
| 3797 | // There is no existing starting window, and the caller doesn't |
| 3798 | // want us to create one, so that's it! |
| 3799 | if (!createIfNeeded) { |
| 3800 | return; |
| 3801 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3802 | |
Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 3803 | // If this is a translucent or wallpaper window, then don't |
| 3804 | // show a starting window -- the current effect (a full-screen |
| 3805 | // opaque starting window that fades away to the real contents |
| 3806 | // when it is ready) does not work for this. |
| 3807 | if (theme != 0) { |
| 3808 | AttributeCache.Entry ent = AttributeCache.instance().get(pkg, theme, |
| 3809 | com.android.internal.R.styleable.Window); |
| 3810 | if (ent.array.getBoolean( |
| 3811 | com.android.internal.R.styleable.Window_windowIsTranslucent, false)) { |
| 3812 | return; |
| 3813 | } |
| 3814 | if (ent.array.getBoolean( |
Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 3815 | com.android.internal.R.styleable.Window_windowIsFloating, false)) { |
| 3816 | return; |
| 3817 | } |
| 3818 | if (ent.array.getBoolean( |
Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 3819 | com.android.internal.R.styleable.Window_windowShowWallpaper, false)) { |
| 3820 | return; |
| 3821 | } |
| 3822 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3823 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3824 | mStartingIconInTransition = true; |
| 3825 | wtoken.startingData = new StartingData( |
| 3826 | pkg, theme, nonLocalizedLabel, |
| 3827 | labelRes, icon); |
| 3828 | Message m = mH.obtainMessage(H.ADD_STARTING, wtoken); |
| 3829 | // Note: we really want to do sendMessageAtFrontOfQueue() because we |
| 3830 | // want to process the message ASAP, before any other queued |
| 3831 | // messages. |
| 3832 | mH.sendMessageAtFrontOfQueue(m); |
| 3833 | } |
| 3834 | } |
| 3835 | |
| 3836 | public void setAppWillBeHidden(IBinder token) { |
| 3837 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3838 | "setAppWillBeHidden()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3839 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3840 | } |
| 3841 | |
| 3842 | AppWindowToken wtoken; |
| 3843 | |
| 3844 | synchronized(mWindowMap) { |
| 3845 | wtoken = findAppWindowToken(token); |
| 3846 | if (wtoken == null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3847 | 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] | 3848 | return; |
| 3849 | } |
| 3850 | wtoken.willBeHidden = true; |
| 3851 | } |
| 3852 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3853 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3854 | boolean setTokenVisibilityLocked(AppWindowToken wtoken, WindowManager.LayoutParams lp, |
| 3855 | boolean visible, int transit, boolean performLayout) { |
| 3856 | boolean delayed = false; |
| 3857 | |
| 3858 | if (wtoken.clientHidden == visible) { |
| 3859 | wtoken.clientHidden = !visible; |
| 3860 | wtoken.sendAppVisibilityToClients(); |
| 3861 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3862 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3863 | wtoken.willBeHidden = false; |
| 3864 | if (wtoken.hidden == visible) { |
| 3865 | final int N = wtoken.allAppWindows.size(); |
| 3866 | boolean changed = false; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3867 | if (DEBUG_APP_TRANSITIONS) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3868 | TAG, "Changing app " + wtoken + " hidden=" + wtoken.hidden |
| 3869 | + " performLayout=" + performLayout); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3870 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3871 | boolean runningAppAnimation = false; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3872 | |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 3873 | if (transit != WindowManagerPolicy.TRANSIT_UNSET) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3874 | if (wtoken.animation == sDummyAnimation) { |
| 3875 | wtoken.animation = null; |
| 3876 | } |
| 3877 | applyAnimationLocked(wtoken, lp, transit, visible); |
| 3878 | changed = true; |
| 3879 | if (wtoken.animation != null) { |
| 3880 | delayed = runningAppAnimation = true; |
| 3881 | } |
| 3882 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3883 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3884 | for (int i=0; i<N; i++) { |
| 3885 | WindowState win = wtoken.allAppWindows.get(i); |
| 3886 | if (win == wtoken.startingWindow) { |
| 3887 | continue; |
| 3888 | } |
| 3889 | |
| 3890 | if (win.isAnimating()) { |
| 3891 | delayed = true; |
| 3892 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3893 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3894 | //Slog.i(TAG, "Window " + win + ": vis=" + win.isVisible()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3895 | //win.dump(" "); |
| 3896 | if (visible) { |
| 3897 | if (!win.isVisibleNow()) { |
| 3898 | if (!runningAppAnimation) { |
| 3899 | applyAnimationLocked(win, |
| 3900 | WindowManagerPolicy.TRANSIT_ENTER, true); |
| 3901 | } |
| 3902 | changed = true; |
| 3903 | } |
| 3904 | } else if (win.isVisibleNow()) { |
| 3905 | if (!runningAppAnimation) { |
| 3906 | applyAnimationLocked(win, |
| 3907 | WindowManagerPolicy.TRANSIT_EXIT, false); |
| 3908 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3909 | changed = true; |
| 3910 | } |
| 3911 | } |
| 3912 | |
| 3913 | wtoken.hidden = wtoken.hiddenRequested = !visible; |
| 3914 | if (!visible) { |
| 3915 | unsetAppFreezingScreenLocked(wtoken, true, true); |
| 3916 | } else { |
| 3917 | // If we are being set visible, and the starting window is |
| 3918 | // not yet displayed, then make sure it doesn't get displayed. |
| 3919 | WindowState swin = wtoken.startingWindow; |
| 3920 | if (swin != null && (swin.mDrawPending |
| 3921 | || swin.mCommitDrawPending)) { |
| 3922 | swin.mPolicyVisibility = false; |
| 3923 | swin.mPolicyVisibilityAfterAnim = false; |
| 3924 | } |
| 3925 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3926 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3927 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "setTokenVisibilityLocked: " + wtoken |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3928 | + ": hidden=" + wtoken.hidden + " hiddenRequested=" |
| 3929 | + wtoken.hiddenRequested); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3930 | |
Dianne Hackborn | 9b52a21 | 2009-12-11 14:51:35 -0800 | [diff] [blame] | 3931 | if (changed) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3932 | mLayoutNeeded = true; |
Dianne Hackborn | 9b52a21 | 2009-12-11 14:51:35 -0800 | [diff] [blame] | 3933 | if (performLayout) { |
| 3934 | updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES); |
| 3935 | performLayoutAndPlaceSurfacesLocked(); |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 3936 | } else { |
| 3937 | mInputMonitor.updateInputWindowsLw(); |
Dianne Hackborn | 9b52a21 | 2009-12-11 14:51:35 -0800 | [diff] [blame] | 3938 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3939 | } |
| 3940 | } |
| 3941 | |
| 3942 | if (wtoken.animation != null) { |
| 3943 | delayed = true; |
| 3944 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3945 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3946 | return delayed; |
| 3947 | } |
| 3948 | |
| 3949 | public void setAppVisibility(IBinder token, boolean visible) { |
| 3950 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3951 | "setAppVisibility()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3952 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3953 | } |
| 3954 | |
| 3955 | AppWindowToken wtoken; |
| 3956 | |
| 3957 | synchronized(mWindowMap) { |
| 3958 | wtoken = findAppWindowToken(token); |
| 3959 | if (wtoken == null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3960 | 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] | 3961 | return; |
| 3962 | } |
| 3963 | |
| 3964 | if (DEBUG_APP_TRANSITIONS || DEBUG_ORIENTATION) { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 3965 | RuntimeException e = null; |
| 3966 | if (!HIDE_STACK_CRAWLS) { |
| 3967 | e = new RuntimeException(); |
| 3968 | e.fillInStackTrace(); |
| 3969 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3970 | Slog.v(TAG, "setAppVisibility(" + token + ", " + visible |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3971 | + "): mNextAppTransition=" + mNextAppTransition |
| 3972 | + " hidden=" + wtoken.hidden |
| 3973 | + " hiddenRequested=" + wtoken.hiddenRequested, e); |
| 3974 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3975 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3976 | // If we are preparing an app transition, then delay changing |
| 3977 | // the visibility of this token until we execute that transition. |
Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 3978 | if (!mDisplayFrozen && mPolicy.isScreenOn() |
| 3979 | && mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3980 | // Already in requested state, don't do anything more. |
| 3981 | if (wtoken.hiddenRequested != visible) { |
| 3982 | return; |
| 3983 | } |
| 3984 | wtoken.hiddenRequested = !visible; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3985 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3986 | if (DEBUG_APP_TRANSITIONS) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3987 | TAG, "Setting dummy animation on: " + wtoken); |
| 3988 | wtoken.setDummyAnimation(); |
| 3989 | mOpeningApps.remove(wtoken); |
| 3990 | mClosingApps.remove(wtoken); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 3991 | wtoken.waitingToShow = wtoken.waitingToHide = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3992 | wtoken.inPendingTransaction = true; |
| 3993 | if (visible) { |
| 3994 | mOpeningApps.add(wtoken); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3995 | wtoken.startingDisplayed = false; |
| 3996 | wtoken.startingMoved = false; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3997 | |
Dianne Hackborn | 195f6a0 | 2009-11-24 11:26:00 -0800 | [diff] [blame] | 3998 | // If the token is currently hidden (should be the |
| 3999 | // common case), then we need to set up to wait for |
| 4000 | // its windows to be ready. |
| 4001 | if (wtoken.hidden) { |
| 4002 | wtoken.allDrawn = false; |
| 4003 | wtoken.waitingToShow = true; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 4004 | |
Dianne Hackborn | 195f6a0 | 2009-11-24 11:26:00 -0800 | [diff] [blame] | 4005 | if (wtoken.clientHidden) { |
| 4006 | // In the case where we are making an app visible |
| 4007 | // but holding off for a transition, we still need |
| 4008 | // to tell the client to make its windows visible so |
| 4009 | // they get drawn. Otherwise, we will wait on |
| 4010 | // performing the transition until all windows have |
| 4011 | // been drawn, they never will be, and we are sad. |
| 4012 | wtoken.clientHidden = false; |
| 4013 | wtoken.sendAppVisibilityToClients(); |
| 4014 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4015 | } |
| 4016 | } else { |
| 4017 | mClosingApps.add(wtoken); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 4018 | |
Dianne Hackborn | 195f6a0 | 2009-11-24 11:26:00 -0800 | [diff] [blame] | 4019 | // If the token is currently visible (should be the |
| 4020 | // common case), then set up to wait for it to be hidden. |
| 4021 | if (!wtoken.hidden) { |
| 4022 | wtoken.waitingToHide = true; |
| 4023 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4024 | } |
| 4025 | return; |
| 4026 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4027 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4028 | final long origId = Binder.clearCallingIdentity(); |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 4029 | setTokenVisibilityLocked(wtoken, null, visible, WindowManagerPolicy.TRANSIT_UNSET, true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4030 | wtoken.updateReportedVisibilityLocked(); |
| 4031 | Binder.restoreCallingIdentity(origId); |
| 4032 | } |
| 4033 | } |
| 4034 | |
| 4035 | void unsetAppFreezingScreenLocked(AppWindowToken wtoken, |
| 4036 | boolean unfreezeSurfaceNow, boolean force) { |
| 4037 | if (wtoken.freezingScreen) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4038 | 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] | 4039 | + " force=" + force); |
| 4040 | final int N = wtoken.allAppWindows.size(); |
| 4041 | boolean unfrozeWindows = false; |
| 4042 | for (int i=0; i<N; i++) { |
| 4043 | WindowState w = wtoken.allAppWindows.get(i); |
| 4044 | if (w.mAppFreezing) { |
| 4045 | w.mAppFreezing = false; |
| 4046 | if (w.mSurface != null && !w.mOrientationChanging) { |
| 4047 | w.mOrientationChanging = true; |
| 4048 | } |
| 4049 | unfrozeWindows = true; |
| 4050 | } |
| 4051 | } |
| 4052 | if (force || unfrozeWindows) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4053 | 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] | 4054 | wtoken.freezingScreen = false; |
| 4055 | mAppsFreezingScreen--; |
| 4056 | } |
| 4057 | if (unfreezeSurfaceNow) { |
| 4058 | if (unfrozeWindows) { |
| 4059 | mLayoutNeeded = true; |
| 4060 | performLayoutAndPlaceSurfacesLocked(); |
| 4061 | } |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 4062 | stopFreezingDisplayLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4063 | } |
| 4064 | } |
| 4065 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4066 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4067 | public void startAppFreezingScreenLocked(AppWindowToken wtoken, |
| 4068 | int configChanges) { |
| 4069 | if (DEBUG_ORIENTATION) { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 4070 | RuntimeException e = null; |
| 4071 | if (!HIDE_STACK_CRAWLS) { |
| 4072 | e = new RuntimeException(); |
| 4073 | e.fillInStackTrace(); |
| 4074 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4075 | Slog.i(TAG, "Set freezing of " + wtoken.appToken |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4076 | + ": hidden=" + wtoken.hidden + " freezing=" |
| 4077 | + wtoken.freezingScreen, e); |
| 4078 | } |
| 4079 | if (!wtoken.hiddenRequested) { |
| 4080 | if (!wtoken.freezingScreen) { |
| 4081 | wtoken.freezingScreen = true; |
| 4082 | mAppsFreezingScreen++; |
| 4083 | if (mAppsFreezingScreen == 1) { |
| 4084 | startFreezingDisplayLocked(); |
| 4085 | mH.removeMessages(H.APP_FREEZE_TIMEOUT); |
| 4086 | mH.sendMessageDelayed(mH.obtainMessage(H.APP_FREEZE_TIMEOUT), |
| 4087 | 5000); |
| 4088 | } |
| 4089 | } |
| 4090 | final int N = wtoken.allAppWindows.size(); |
| 4091 | for (int i=0; i<N; i++) { |
| 4092 | WindowState w = wtoken.allAppWindows.get(i); |
| 4093 | w.mAppFreezing = true; |
| 4094 | } |
| 4095 | } |
| 4096 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4097 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4098 | public void startAppFreezingScreen(IBinder token, int configChanges) { |
| 4099 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 4100 | "setAppFreezingScreen()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4101 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4102 | } |
| 4103 | |
| 4104 | synchronized(mWindowMap) { |
Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 4105 | if (configChanges == 0 && !mDisplayFrozen && mPolicy.isScreenOn()) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4106 | 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] | 4107 | return; |
| 4108 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4109 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4110 | AppWindowToken wtoken = findAppWindowToken(token); |
| 4111 | if (wtoken == null || wtoken.appToken == null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4112 | 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] | 4113 | return; |
| 4114 | } |
| 4115 | final long origId = Binder.clearCallingIdentity(); |
| 4116 | startAppFreezingScreenLocked(wtoken, configChanges); |
| 4117 | Binder.restoreCallingIdentity(origId); |
| 4118 | } |
| 4119 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4120 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4121 | public void stopAppFreezingScreen(IBinder token, boolean force) { |
| 4122 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 4123 | "setAppFreezingScreen()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4124 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4125 | } |
| 4126 | |
| 4127 | synchronized(mWindowMap) { |
| 4128 | AppWindowToken wtoken = findAppWindowToken(token); |
| 4129 | if (wtoken == null || wtoken.appToken == null) { |
| 4130 | return; |
| 4131 | } |
| 4132 | final long origId = Binder.clearCallingIdentity(); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4133 | 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] | 4134 | + ": hidden=" + wtoken.hidden + " freezing=" + wtoken.freezingScreen); |
| 4135 | unsetAppFreezingScreenLocked(wtoken, true, force); |
| 4136 | Binder.restoreCallingIdentity(origId); |
| 4137 | } |
| 4138 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4139 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4140 | public void removeAppToken(IBinder token) { |
| 4141 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 4142 | "removeAppToken()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4143 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4144 | } |
| 4145 | |
| 4146 | AppWindowToken wtoken = null; |
| 4147 | AppWindowToken startingToken = null; |
| 4148 | boolean delayed = false; |
| 4149 | |
| 4150 | final long origId = Binder.clearCallingIdentity(); |
| 4151 | synchronized(mWindowMap) { |
| 4152 | WindowToken basewtoken = mTokenMap.remove(token); |
| 4153 | mTokenList.remove(basewtoken); |
| 4154 | if (basewtoken != null && (wtoken=basewtoken.appWindowToken) != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4155 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "Removing app token: " + wtoken); |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 4156 | delayed = setTokenVisibilityLocked(wtoken, null, false, WindowManagerPolicy.TRANSIT_UNSET, true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4157 | wtoken.inPendingTransaction = false; |
| 4158 | mOpeningApps.remove(wtoken); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4159 | wtoken.waitingToShow = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4160 | if (mClosingApps.contains(wtoken)) { |
| 4161 | delayed = true; |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 4162 | } else if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4163 | mClosingApps.add(wtoken); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4164 | wtoken.waitingToHide = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4165 | delayed = true; |
| 4166 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4167 | if (DEBUG_APP_TRANSITIONS) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4168 | TAG, "Removing app " + wtoken + " delayed=" + delayed |
| 4169 | + " animation=" + wtoken.animation |
| 4170 | + " animating=" + wtoken.animating); |
| 4171 | if (delayed) { |
| 4172 | // set the token aside because it has an active animation to be finished |
| 4173 | mExitingAppTokens.add(wtoken); |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 4174 | } else { |
| 4175 | // Make sure there is no animation running on this token, |
| 4176 | // so any windows associated with it will be removed as |
| 4177 | // soon as their animations are complete |
| 4178 | wtoken.animation = null; |
| 4179 | wtoken.animating = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4180 | } |
| 4181 | mAppTokens.remove(wtoken); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 4182 | if (mLastEnterAnimToken == wtoken) { |
| 4183 | mLastEnterAnimToken = null; |
| 4184 | mLastEnterAnimParams = null; |
| 4185 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4186 | wtoken.removed = true; |
| 4187 | if (wtoken.startingData != null) { |
| 4188 | startingToken = wtoken; |
| 4189 | } |
| 4190 | unsetAppFreezingScreenLocked(wtoken, true, true); |
| 4191 | if (mFocusedApp == wtoken) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4192 | 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] | 4193 | mFocusedApp = null; |
| 4194 | updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL); |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 4195 | mInputMonitor.setFocusedAppLw(null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4196 | } |
| 4197 | } else { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4198 | 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] | 4199 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4200 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4201 | if (!delayed && wtoken != null) { |
| 4202 | wtoken.updateReportedVisibilityLocked(); |
| 4203 | } |
| 4204 | } |
| 4205 | Binder.restoreCallingIdentity(origId); |
| 4206 | |
| 4207 | if (startingToken != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4208 | 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] | 4209 | + startingToken + ": app token removed"); |
| 4210 | Message m = mH.obtainMessage(H.REMOVE_STARTING, startingToken); |
| 4211 | mH.sendMessage(m); |
| 4212 | } |
| 4213 | } |
| 4214 | |
| 4215 | private boolean tmpRemoveAppWindowsLocked(WindowToken token) { |
| 4216 | final int NW = token.windows.size(); |
| 4217 | for (int i=0; i<NW; i++) { |
| 4218 | WindowState win = token.windows.get(i); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4219 | 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] | 4220 | mWindows.remove(win); |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 4221 | mWindowsChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4222 | int j = win.mChildWindows.size(); |
| 4223 | while (j > 0) { |
| 4224 | j--; |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 4225 | WindowState cwin = win.mChildWindows.get(j); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4226 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, |
Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 4227 | "Tmp removing child window " + cwin); |
| 4228 | mWindows.remove(cwin); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4229 | } |
| 4230 | } |
| 4231 | return NW > 0; |
| 4232 | } |
| 4233 | |
| 4234 | void dumpAppTokensLocked() { |
| 4235 | for (int i=mAppTokens.size()-1; i>=0; i--) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4236 | Slog.v(TAG, " #" + i + ": " + mAppTokens.get(i).token); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4237 | } |
| 4238 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4239 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4240 | void dumpWindowsLocked() { |
| 4241 | for (int i=mWindows.size()-1; i>=0; i--) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4242 | Slog.v(TAG, " #" + i + ": " + mWindows.get(i)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4243 | } |
| 4244 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4245 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4246 | private int findWindowOffsetLocked(int tokenPos) { |
| 4247 | final int NW = mWindows.size(); |
| 4248 | |
| 4249 | if (tokenPos >= mAppTokens.size()) { |
| 4250 | int i = NW; |
| 4251 | while (i > 0) { |
| 4252 | i--; |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 4253 | WindowState win = mWindows.get(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4254 | if (win.getAppToken() != null) { |
| 4255 | return i+1; |
| 4256 | } |
| 4257 | } |
| 4258 | } |
| 4259 | |
| 4260 | while (tokenPos > 0) { |
| 4261 | // Find the first app token below the new position that has |
| 4262 | // a window displayed. |
| 4263 | final AppWindowToken wtoken = mAppTokens.get(tokenPos-1); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4264 | 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] | 4265 | + tokenPos + " -- " + wtoken.token); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4266 | if (wtoken.sendingToBottom) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4267 | if (DEBUG_REORDER) Slog.v(TAG, |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4268 | "Skipping token -- currently sending to bottom"); |
| 4269 | tokenPos--; |
| 4270 | continue; |
| 4271 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4272 | int i = wtoken.windows.size(); |
| 4273 | while (i > 0) { |
| 4274 | i--; |
| 4275 | WindowState win = wtoken.windows.get(i); |
| 4276 | int j = win.mChildWindows.size(); |
| 4277 | while (j > 0) { |
| 4278 | j--; |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 4279 | WindowState cwin = win.mChildWindows.get(j); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4280 | if (cwin.mSubLayer >= 0) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4281 | for (int pos=NW-1; pos>=0; pos--) { |
| 4282 | if (mWindows.get(pos) == cwin) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4283 | if (DEBUG_REORDER) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4284 | "Found child win @" + (pos+1)); |
| 4285 | return pos+1; |
| 4286 | } |
| 4287 | } |
| 4288 | } |
| 4289 | } |
| 4290 | for (int pos=NW-1; pos>=0; pos--) { |
| 4291 | if (mWindows.get(pos) == win) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4292 | 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] | 4293 | return pos+1; |
| 4294 | } |
| 4295 | } |
| 4296 | } |
| 4297 | tokenPos--; |
| 4298 | } |
| 4299 | |
| 4300 | return 0; |
| 4301 | } |
| 4302 | |
| 4303 | private final int reAddWindowLocked(int index, WindowState win) { |
| 4304 | final int NCW = win.mChildWindows.size(); |
| 4305 | boolean added = false; |
| 4306 | for (int j=0; j<NCW; j++) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 4307 | WindowState cwin = win.mChildWindows.get(j); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4308 | if (!added && cwin.mSubLayer >= 0) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4309 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding child window at " |
Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 4310 | + index + ": " + cwin); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4311 | mWindows.add(index, win); |
| 4312 | index++; |
| 4313 | added = true; |
| 4314 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4315 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding window at " |
Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 4316 | + index + ": " + cwin); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4317 | mWindows.add(index, cwin); |
| 4318 | index++; |
| 4319 | } |
| 4320 | if (!added) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4321 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding window at " |
Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 4322 | + index + ": " + win); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4323 | mWindows.add(index, win); |
| 4324 | index++; |
| 4325 | } |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 4326 | mWindowsChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4327 | return index; |
| 4328 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4329 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4330 | private final int reAddAppWindowsLocked(int index, WindowToken token) { |
| 4331 | final int NW = token.windows.size(); |
| 4332 | for (int i=0; i<NW; i++) { |
| 4333 | index = reAddWindowLocked(index, token.windows.get(i)); |
| 4334 | } |
| 4335 | return index; |
| 4336 | } |
| 4337 | |
| 4338 | public void moveAppToken(int index, IBinder token) { |
| 4339 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 4340 | "moveAppToken()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4341 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4342 | } |
| 4343 | |
| 4344 | synchronized(mWindowMap) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4345 | if (DEBUG_REORDER) Slog.v(TAG, "Initial app tokens:"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4346 | if (DEBUG_REORDER) dumpAppTokensLocked(); |
| 4347 | final AppWindowToken wtoken = findAppWindowToken(token); |
| 4348 | if (wtoken == null || !mAppTokens.remove(wtoken)) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4349 | 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] | 4350 | + token + " (" + wtoken + ")"); |
| 4351 | return; |
| 4352 | } |
| 4353 | mAppTokens.add(index, wtoken); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4354 | 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] | 4355 | if (DEBUG_REORDER) dumpAppTokensLocked(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4356 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4357 | final long origId = Binder.clearCallingIdentity(); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4358 | 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] | 4359 | if (DEBUG_REORDER) dumpWindowsLocked(); |
| 4360 | if (tmpRemoveAppWindowsLocked(wtoken)) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4361 | 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] | 4362 | if (DEBUG_REORDER) dumpWindowsLocked(); |
| 4363 | reAddAppWindowsLocked(findWindowOffsetLocked(index), wtoken); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4364 | if (DEBUG_REORDER) Slog.v(TAG, "Final window list:"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4365 | if (DEBUG_REORDER) dumpWindowsLocked(); |
| 4366 | updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4367 | mLayoutNeeded = true; |
| 4368 | performLayoutAndPlaceSurfacesLocked(); |
| 4369 | } |
| 4370 | Binder.restoreCallingIdentity(origId); |
| 4371 | } |
| 4372 | } |
| 4373 | |
| 4374 | private void removeAppTokensLocked(List<IBinder> tokens) { |
| 4375 | // XXX This should be done more efficiently! |
| 4376 | // (take advantage of the fact that both lists should be |
| 4377 | // ordered in the same way.) |
| 4378 | int N = tokens.size(); |
| 4379 | for (int i=0; i<N; i++) { |
| 4380 | IBinder token = tokens.get(i); |
| 4381 | final AppWindowToken wtoken = findAppWindowToken(token); |
| 4382 | if (!mAppTokens.remove(wtoken)) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4383 | 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] | 4384 | + token + " (" + wtoken + ")"); |
| 4385 | i--; |
| 4386 | N--; |
| 4387 | } |
| 4388 | } |
| 4389 | } |
| 4390 | |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4391 | private void moveAppWindowsLocked(AppWindowToken wtoken, int tokenPos, |
| 4392 | boolean updateFocusAndLayout) { |
| 4393 | // First remove all of the windows from the list. |
| 4394 | tmpRemoveAppWindowsLocked(wtoken); |
| 4395 | |
| 4396 | // Where to start adding? |
| 4397 | int pos = findWindowOffsetLocked(tokenPos); |
| 4398 | |
| 4399 | // And now add them back at the correct place. |
| 4400 | pos = reAddAppWindowsLocked(pos, wtoken); |
| 4401 | |
| 4402 | if (updateFocusAndLayout) { |
| 4403 | if (!updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES)) { |
| 4404 | assignLayersLocked(); |
| 4405 | } |
| 4406 | mLayoutNeeded = true; |
| 4407 | performLayoutAndPlaceSurfacesLocked(); |
| 4408 | } |
| 4409 | } |
| 4410 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4411 | private void moveAppWindowsLocked(List<IBinder> tokens, int tokenPos) { |
| 4412 | // First remove all of the windows from the list. |
| 4413 | final int N = tokens.size(); |
| 4414 | int i; |
| 4415 | for (i=0; i<N; i++) { |
| 4416 | WindowToken token = mTokenMap.get(tokens.get(i)); |
| 4417 | if (token != null) { |
| 4418 | tmpRemoveAppWindowsLocked(token); |
| 4419 | } |
| 4420 | } |
| 4421 | |
| 4422 | // Where to start adding? |
| 4423 | int pos = findWindowOffsetLocked(tokenPos); |
| 4424 | |
| 4425 | // And now add them back at the correct place. |
| 4426 | for (i=0; i<N; i++) { |
| 4427 | WindowToken token = mTokenMap.get(tokens.get(i)); |
| 4428 | if (token != null) { |
| 4429 | pos = reAddAppWindowsLocked(pos, token); |
| 4430 | } |
| 4431 | } |
| 4432 | |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4433 | if (!updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES)) { |
| 4434 | assignLayersLocked(); |
| 4435 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4436 | mLayoutNeeded = true; |
| 4437 | performLayoutAndPlaceSurfacesLocked(); |
| 4438 | |
| 4439 | //dump(); |
| 4440 | } |
| 4441 | |
| 4442 | public void moveAppTokensToTop(List<IBinder> tokens) { |
| 4443 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 4444 | "moveAppTokensToTop()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4445 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4446 | } |
| 4447 | |
| 4448 | final long origId = Binder.clearCallingIdentity(); |
| 4449 | synchronized(mWindowMap) { |
| 4450 | removeAppTokensLocked(tokens); |
| 4451 | final int N = tokens.size(); |
| 4452 | for (int i=0; i<N; i++) { |
| 4453 | AppWindowToken wt = findAppWindowToken(tokens.get(i)); |
| 4454 | if (wt != null) { |
| 4455 | mAppTokens.add(wt); |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 4456 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4457 | mToTopApps.remove(wt); |
| 4458 | mToBottomApps.remove(wt); |
| 4459 | mToTopApps.add(wt); |
| 4460 | wt.sendingToBottom = false; |
| 4461 | wt.sendingToTop = true; |
| 4462 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4463 | } |
| 4464 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 4465 | |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 4466 | if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET) { |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4467 | moveAppWindowsLocked(tokens, mAppTokens.size()); |
| 4468 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4469 | } |
| 4470 | Binder.restoreCallingIdentity(origId); |
| 4471 | } |
| 4472 | |
| 4473 | public void moveAppTokensToBottom(List<IBinder> tokens) { |
| 4474 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 4475 | "moveAppTokensToBottom()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4476 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4477 | } |
| 4478 | |
| 4479 | final long origId = Binder.clearCallingIdentity(); |
| 4480 | synchronized(mWindowMap) { |
| 4481 | removeAppTokensLocked(tokens); |
| 4482 | final int N = tokens.size(); |
| 4483 | int pos = 0; |
| 4484 | for (int i=0; i<N; i++) { |
| 4485 | AppWindowToken wt = findAppWindowToken(tokens.get(i)); |
| 4486 | if (wt != null) { |
| 4487 | mAppTokens.add(pos, wt); |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 4488 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4489 | mToTopApps.remove(wt); |
| 4490 | mToBottomApps.remove(wt); |
| 4491 | mToBottomApps.add(i, wt); |
| 4492 | wt.sendingToTop = false; |
| 4493 | wt.sendingToBottom = true; |
| 4494 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4495 | pos++; |
| 4496 | } |
| 4497 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 4498 | |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 4499 | if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET) { |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4500 | moveAppWindowsLocked(tokens, 0); |
| 4501 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4502 | } |
| 4503 | Binder.restoreCallingIdentity(origId); |
| 4504 | } |
| 4505 | |
| 4506 | // ------------------------------------------------------------- |
| 4507 | // Misc IWindowSession methods |
| 4508 | // ------------------------------------------------------------- |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4509 | |
Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 4510 | private boolean shouldAllowDisableKeyguard() |
Jim Miller | d6b5705 | 2010-06-07 17:52:42 -0700 | [diff] [blame] | 4511 | { |
Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 4512 | // We fail safe and prevent disabling keyguard in the unlikely event this gets |
| 4513 | // called before DevicePolicyManagerService has started. |
| 4514 | if (mAllowDisableKeyguard == ALLOW_DISABLE_UNKNOWN) { |
| 4515 | DevicePolicyManager dpm = (DevicePolicyManager) mContext.getSystemService( |
| 4516 | Context.DEVICE_POLICY_SERVICE); |
| 4517 | if (dpm != null) { |
| 4518 | mAllowDisableKeyguard = dpm.getPasswordQuality(null) |
| 4519 | == DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED ? |
| 4520 | ALLOW_DISABLE_YES : ALLOW_DISABLE_NO; |
| 4521 | } |
Jim Miller | d6b5705 | 2010-06-07 17:52:42 -0700 | [diff] [blame] | 4522 | } |
Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 4523 | return mAllowDisableKeyguard == ALLOW_DISABLE_YES; |
Jim Miller | d6b5705 | 2010-06-07 17:52:42 -0700 | [diff] [blame] | 4524 | } |
| 4525 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4526 | public void disableKeyguard(IBinder token, String tag) { |
Mike Lockwood | 733fdf3 | 2009-09-28 19:08:53 -0400 | [diff] [blame] | 4527 | if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4528 | != PackageManager.PERMISSION_GRANTED) { |
| 4529 | throw new SecurityException("Requires DISABLE_KEYGUARD permission"); |
| 4530 | } |
Jim Miller | d6b5705 | 2010-06-07 17:52:42 -0700 | [diff] [blame] | 4531 | |
Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 4532 | synchronized (mKeyguardTokenWatcher) { |
| 4533 | mKeyguardTokenWatcher.acquire(token, tag); |
Mike Lockwood | dd88468 | 2009-10-11 16:57:08 -0400 | [diff] [blame] | 4534 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4535 | } |
| 4536 | |
| 4537 | public void reenableKeyguard(IBinder token) { |
Mike Lockwood | 733fdf3 | 2009-09-28 19:08:53 -0400 | [diff] [blame] | 4538 | if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4539 | != PackageManager.PERMISSION_GRANTED) { |
| 4540 | throw new SecurityException("Requires DISABLE_KEYGUARD permission"); |
| 4541 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4542 | |
Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 4543 | synchronized (mKeyguardTokenWatcher) { |
| 4544 | mKeyguardTokenWatcher.release(token); |
Jim Miller | d6b5705 | 2010-06-07 17:52:42 -0700 | [diff] [blame] | 4545 | |
Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 4546 | if (!mKeyguardTokenWatcher.isAcquired()) { |
| 4547 | // If we are the last one to reenable the keyguard wait until |
| 4548 | // we have actually finished reenabling until returning. |
| 4549 | // It is possible that reenableKeyguard() can be called before |
| 4550 | // the previous disableKeyguard() is handled, in which case |
| 4551 | // neither mKeyguardTokenWatcher.acquired() or released() would |
| 4552 | // be called. In that case mKeyguardDisabled will be false here |
| 4553 | // and we have nothing to wait for. |
| 4554 | while (mKeyguardDisabled) { |
| 4555 | try { |
| 4556 | mKeyguardTokenWatcher.wait(); |
| 4557 | } catch (InterruptedException e) { |
| 4558 | Thread.currentThread().interrupt(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4559 | } |
| 4560 | } |
| 4561 | } |
| 4562 | } |
| 4563 | } |
| 4564 | |
| 4565 | /** |
| 4566 | * @see android.app.KeyguardManager#exitKeyguardSecurely |
| 4567 | */ |
| 4568 | public void exitKeyguardSecurely(final IOnKeyguardExitResult callback) { |
Mike Lockwood | 733fdf3 | 2009-09-28 19:08:53 -0400 | [diff] [blame] | 4569 | if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4570 | != PackageManager.PERMISSION_GRANTED) { |
| 4571 | throw new SecurityException("Requires DISABLE_KEYGUARD permission"); |
| 4572 | } |
| 4573 | mPolicy.exitKeyguardSecurely(new WindowManagerPolicy.OnKeyguardExitResult() { |
| 4574 | public void onKeyguardExitResult(boolean success) { |
| 4575 | try { |
| 4576 | callback.onKeyguardExitResult(success); |
| 4577 | } catch (RemoteException e) { |
| 4578 | // Client has died, we don't care. |
| 4579 | } |
| 4580 | } |
| 4581 | }); |
| 4582 | } |
| 4583 | |
| 4584 | public boolean inKeyguardRestrictedInputMode() { |
| 4585 | return mPolicy.inKeyguardRestrictedKeyInputMode(); |
| 4586 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4587 | |
Dianne Hackborn | ffa4248 | 2009-09-23 22:20:11 -0700 | [diff] [blame] | 4588 | public void closeSystemDialogs(String reason) { |
| 4589 | synchronized(mWindowMap) { |
| 4590 | for (int i=mWindows.size()-1; i>=0; i--) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 4591 | WindowState w = mWindows.get(i); |
Dianne Hackborn | ffa4248 | 2009-09-23 22:20:11 -0700 | [diff] [blame] | 4592 | if (w.mSurface != null) { |
| 4593 | try { |
| 4594 | w.mClient.closeSystemDialogs(reason); |
| 4595 | } catch (RemoteException e) { |
| 4596 | } |
| 4597 | } |
| 4598 | } |
| 4599 | } |
| 4600 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 4601 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4602 | static float fixScale(float scale) { |
| 4603 | if (scale < 0) scale = 0; |
| 4604 | else if (scale > 20) scale = 20; |
| 4605 | return Math.abs(scale); |
| 4606 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4607 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4608 | public void setAnimationScale(int which, float scale) { |
| 4609 | if (!checkCallingPermission(android.Manifest.permission.SET_ANIMATION_SCALE, |
| 4610 | "setAnimationScale()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4611 | throw new SecurityException("Requires SET_ANIMATION_SCALE permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4612 | } |
| 4613 | |
| 4614 | if (scale < 0) scale = 0; |
| 4615 | else if (scale > 20) scale = 20; |
| 4616 | scale = Math.abs(scale); |
| 4617 | switch (which) { |
| 4618 | case 0: mWindowAnimationScale = fixScale(scale); break; |
| 4619 | case 1: mTransitionAnimationScale = fixScale(scale); break; |
| 4620 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4621 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4622 | // Persist setting |
| 4623 | mH.obtainMessage(H.PERSIST_ANIMATION_SCALE).sendToTarget(); |
| 4624 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4625 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4626 | public void setAnimationScales(float[] scales) { |
| 4627 | if (!checkCallingPermission(android.Manifest.permission.SET_ANIMATION_SCALE, |
| 4628 | "setAnimationScale()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4629 | throw new SecurityException("Requires SET_ANIMATION_SCALE permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4630 | } |
| 4631 | |
| 4632 | if (scales != null) { |
| 4633 | if (scales.length >= 1) { |
| 4634 | mWindowAnimationScale = fixScale(scales[0]); |
| 4635 | } |
| 4636 | if (scales.length >= 2) { |
| 4637 | mTransitionAnimationScale = fixScale(scales[1]); |
| 4638 | } |
| 4639 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4640 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4641 | // Persist setting |
| 4642 | mH.obtainMessage(H.PERSIST_ANIMATION_SCALE).sendToTarget(); |
| 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 float getAnimationScale(int which) { |
| 4646 | switch (which) { |
| 4647 | case 0: return mWindowAnimationScale; |
| 4648 | case 1: return mTransitionAnimationScale; |
| 4649 | } |
| 4650 | return 0; |
| 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 float[] getAnimationScales() { |
| 4654 | return new float[] { mWindowAnimationScale, mTransitionAnimationScale }; |
| 4655 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4656 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4657 | public int getSwitchState(int sw) { |
| 4658 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4659 | "getSwitchState()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4660 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4661 | } |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 4662 | return mInputManager.getSwitchState(-1, InputDevice.SOURCE_ANY, sw); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4663 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4664 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4665 | public int getSwitchStateForDevice(int devid, int sw) { |
| 4666 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4667 | "getSwitchStateForDevice()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4668 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4669 | } |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 4670 | return mInputManager.getSwitchState(devid, InputDevice.SOURCE_ANY, sw); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4671 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4672 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4673 | public int getScancodeState(int sw) { |
| 4674 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4675 | "getScancodeState()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4676 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4677 | } |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 4678 | return mInputManager.getScanCodeState(-1, InputDevice.SOURCE_ANY, sw); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4679 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4680 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4681 | public int getScancodeStateForDevice(int devid, int sw) { |
| 4682 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4683 | "getScancodeStateForDevice()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4684 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4685 | } |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 4686 | return mInputManager.getScanCodeState(devid, InputDevice.SOURCE_ANY, sw); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4687 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4688 | |
Dianne Hackborn | 1d62ea9 | 2009-11-17 12:49:50 -0800 | [diff] [blame] | 4689 | public int getTrackballScancodeState(int sw) { |
| 4690 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4691 | "getTrackballScancodeState()")) { |
| 4692 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
| 4693 | } |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 4694 | return mInputManager.getScanCodeState(-1, InputDevice.SOURCE_TRACKBALL, sw); |
Dianne Hackborn | 1d62ea9 | 2009-11-17 12:49:50 -0800 | [diff] [blame] | 4695 | } |
| 4696 | |
| 4697 | public int getDPadScancodeState(int sw) { |
| 4698 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4699 | "getDPadScancodeState()")) { |
| 4700 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
| 4701 | } |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 4702 | return mInputManager.getScanCodeState(-1, InputDevice.SOURCE_DPAD, sw); |
Dianne Hackborn | 1d62ea9 | 2009-11-17 12:49:50 -0800 | [diff] [blame] | 4703 | } |
| 4704 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4705 | public int getKeycodeState(int sw) { |
| 4706 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4707 | "getKeycodeState()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4708 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4709 | } |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 4710 | return mInputManager.getKeyCodeState(-1, InputDevice.SOURCE_ANY, sw); |
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 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4713 | public int getKeycodeStateForDevice(int devid, int sw) { |
| 4714 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4715 | "getKeycodeStateForDevice()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4716 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4717 | } |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 4718 | return mInputManager.getKeyCodeState(devid, InputDevice.SOURCE_ANY, sw); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4719 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4720 | |
Dianne Hackborn | 1d62ea9 | 2009-11-17 12:49:50 -0800 | [diff] [blame] | 4721 | public int getTrackballKeycodeState(int sw) { |
| 4722 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4723 | "getTrackballKeycodeState()")) { |
| 4724 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
| 4725 | } |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 4726 | return mInputManager.getKeyCodeState(-1, InputDevice.SOURCE_TRACKBALL, sw); |
Dianne Hackborn | 1d62ea9 | 2009-11-17 12:49:50 -0800 | [diff] [blame] | 4727 | } |
| 4728 | |
| 4729 | public int getDPadKeycodeState(int sw) { |
| 4730 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4731 | "getDPadKeycodeState()")) { |
| 4732 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
| 4733 | } |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 4734 | return mInputManager.getKeyCodeState(-1, InputDevice.SOURCE_DPAD, sw); |
Dianne Hackborn | 1d62ea9 | 2009-11-17 12:49:50 -0800 | [diff] [blame] | 4735 | } |
Jeff Brown | a41ca77 | 2010-08-11 14:46:32 -0700 | [diff] [blame] | 4736 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4737 | public boolean hasKeys(int[] keycodes, boolean[] keyExists) { |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 4738 | return mInputManager.hasKeys(-1, InputDevice.SOURCE_ANY, keycodes, keyExists); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4739 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4740 | |
Jeff Brown | a41ca77 | 2010-08-11 14:46:32 -0700 | [diff] [blame] | 4741 | public InputChannel monitorInput(String inputChannelName) { |
| 4742 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4743 | "monitorInput()")) { |
| 4744 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
| 4745 | } |
| 4746 | return mInputManager.monitorInput(inputChannelName); |
| 4747 | } |
| 4748 | |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 4749 | public InputDevice getInputDevice(int deviceId) { |
| 4750 | return mInputManager.getInputDevice(deviceId); |
| 4751 | } |
| 4752 | |
| 4753 | public int[] getInputDeviceIds() { |
| 4754 | return mInputManager.getInputDeviceIds(); |
| 4755 | } |
| 4756 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4757 | public void enableScreenAfterBoot() { |
| 4758 | synchronized(mWindowMap) { |
| 4759 | if (mSystemBooted) { |
| 4760 | return; |
| 4761 | } |
| 4762 | mSystemBooted = true; |
| 4763 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4764 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4765 | performEnableScreen(); |
| 4766 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4767 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4768 | public void enableScreenIfNeededLocked() { |
| 4769 | if (mDisplayEnabled) { |
| 4770 | return; |
| 4771 | } |
| 4772 | if (!mSystemBooted) { |
| 4773 | return; |
| 4774 | } |
| 4775 | mH.sendMessage(mH.obtainMessage(H.ENABLE_SCREEN)); |
| 4776 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4777 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4778 | public void performEnableScreen() { |
| 4779 | synchronized(mWindowMap) { |
| 4780 | if (mDisplayEnabled) { |
| 4781 | return; |
| 4782 | } |
| 4783 | if (!mSystemBooted) { |
| 4784 | return; |
| 4785 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4786 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4787 | // Don't enable the screen until all existing windows |
| 4788 | // have been drawn. |
| 4789 | final int N = mWindows.size(); |
| 4790 | for (int i=0; i<N; i++) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 4791 | WindowState w = mWindows.get(i); |
Dianne Hackborn | f3bea9c | 2009-12-09 18:26:21 -0800 | [diff] [blame] | 4792 | if (w.isVisibleLw() && !w.mObscured && !w.isDrawnLw()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4793 | return; |
| 4794 | } |
| 4795 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4796 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4797 | mDisplayEnabled = true; |
| 4798 | if (false) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4799 | Slog.i(TAG, "ENABLING SCREEN!"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4800 | StringWriter sw = new StringWriter(); |
| 4801 | PrintWriter pw = new PrintWriter(sw); |
| 4802 | this.dump(null, pw, null); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4803 | Slog.i(TAG, sw.toString()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4804 | } |
| 4805 | try { |
| 4806 | IBinder surfaceFlinger = ServiceManager.getService("SurfaceFlinger"); |
| 4807 | if (surfaceFlinger != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4808 | //Slog.i(TAG, "******* TELLING SURFACE FLINGER WE ARE BOOTED!"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4809 | Parcel data = Parcel.obtain(); |
| 4810 | data.writeInterfaceToken("android.ui.ISurfaceComposer"); |
| 4811 | surfaceFlinger.transact(IBinder.FIRST_CALL_TRANSACTION, |
| 4812 | data, null, 0); |
| 4813 | data.recycle(); |
| 4814 | } |
| 4815 | } catch (RemoteException ex) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4816 | Slog.e(TAG, "Boot completed: SurfaceFlinger is dead!"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4817 | } |
| 4818 | } |
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 | mPolicy.enableScreenAfterBoot(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4821 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4822 | // Make sure the last requested orientation has been applied. |
Dianne Hackborn | 321ae68 | 2009-03-27 16:16:03 -0700 | [diff] [blame] | 4823 | setRotationUnchecked(WindowManagerPolicy.USE_LAST_ROTATION, false, |
| 4824 | mLastRotationFlags | Surface.FLAGS_ORIENTATION_ANIMATION_DISABLE); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4825 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4826 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4827 | public void setInTouchMode(boolean mode) { |
| 4828 | synchronized(mWindowMap) { |
| 4829 | mInTouchMode = mode; |
| 4830 | } |
| 4831 | } |
| 4832 | |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4833 | public void setRotation(int rotation, |
Dianne Hackborn | 1e880db | 2009-03-27 16:04:08 -0700 | [diff] [blame] | 4834 | boolean alwaysSendConfiguration, int animFlags) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4835 | if (!checkCallingPermission(android.Manifest.permission.SET_ORIENTATION, |
Dianne Hackborn | 1e880db | 2009-03-27 16:04:08 -0700 | [diff] [blame] | 4836 | "setRotation()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4837 | throw new SecurityException("Requires SET_ORIENTATION permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4838 | } |
| 4839 | |
Dianne Hackborn | 1e880db | 2009-03-27 16:04:08 -0700 | [diff] [blame] | 4840 | setRotationUnchecked(rotation, alwaysSendConfiguration, animFlags); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4841 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4842 | |
Dianne Hackborn | 1e880db | 2009-03-27 16:04:08 -0700 | [diff] [blame] | 4843 | public void setRotationUnchecked(int rotation, |
| 4844 | boolean alwaysSendConfiguration, int animFlags) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4845 | if(DEBUG_ORIENTATION) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4846 | "alwaysSendConfiguration set to "+alwaysSendConfiguration); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4847 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4848 | long origId = Binder.clearCallingIdentity(); |
| 4849 | boolean changed; |
| 4850 | synchronized(mWindowMap) { |
Dianne Hackborn | 1e880db | 2009-03-27 16:04:08 -0700 | [diff] [blame] | 4851 | changed = setRotationUncheckedLocked(rotation, animFlags); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4852 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4853 | |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 4854 | if (changed || alwaysSendConfiguration) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4855 | sendNewConfiguration(); |
| 4856 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4857 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4858 | Binder.restoreCallingIdentity(origId); |
| 4859 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4860 | |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 4861 | /** |
| 4862 | * Apply a new rotation to the screen, respecting the requests of |
| 4863 | * applications. Use WindowManagerPolicy.USE_LAST_ROTATION to simply |
| 4864 | * re-evaluate the desired rotation. |
| 4865 | * |
| 4866 | * Returns null if the rotation has been changed. In this case YOU |
| 4867 | * MUST CALL setNewConfiguration() TO UNFREEZE THE SCREEN. |
| 4868 | */ |
Dianne Hackborn | 1e880db | 2009-03-27 16:04:08 -0700 | [diff] [blame] | 4869 | public boolean setRotationUncheckedLocked(int rotation, int animFlags) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4870 | boolean changed; |
| 4871 | if (rotation == WindowManagerPolicy.USE_LAST_ROTATION) { |
| 4872 | rotation = mRequestedRotation; |
| 4873 | } else { |
| 4874 | mRequestedRotation = rotation; |
Dianne Hackborn | 321ae68 | 2009-03-27 16:16:03 -0700 | [diff] [blame] | 4875 | mLastRotationFlags = animFlags; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4876 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4877 | 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] | 4878 | rotation = mPolicy.rotationForOrientationLw(mForcedAppOrientation, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4879 | mRotation, mDisplayEnabled); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4880 | 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] | 4881 | changed = mDisplayEnabled && mRotation != rotation; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4882 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4883 | if (changed) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4884 | if (DEBUG_ORIENTATION) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4885 | "Rotation changed to " + rotation |
| 4886 | + " from " + mRotation |
| 4887 | + " (forceApp=" + mForcedAppOrientation |
| 4888 | + ", req=" + mRequestedRotation + ")"); |
| 4889 | mRotation = rotation; |
| 4890 | mWindowsFreezingScreen = true; |
| 4891 | mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT); |
| 4892 | mH.sendMessageDelayed(mH.obtainMessage(H.WINDOW_FREEZE_TIMEOUT), |
| 4893 | 2000); |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 4894 | mWaitingForConfig = true; |
| 4895 | mLayoutNeeded = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4896 | startFreezingDisplayLocked(); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4897 | Slog.i(TAG, "Setting rotation to " + rotation + ", animFlags=" + animFlags); |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 4898 | mInputManager.setDisplayOrientation(0, rotation); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4899 | if (mDisplayEnabled) { |
Dianne Hackborn | 321ae68 | 2009-03-27 16:16:03 -0700 | [diff] [blame] | 4900 | Surface.setOrientation(0, rotation, animFlags); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4901 | } |
| 4902 | for (int i=mWindows.size()-1; i>=0; i--) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 4903 | WindowState w = mWindows.get(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4904 | if (w.mSurface != null) { |
| 4905 | w.mOrientationChanging = true; |
| 4906 | } |
| 4907 | } |
| 4908 | for (int i=mRotationWatchers.size()-1; i>=0; i--) { |
| 4909 | try { |
| 4910 | mRotationWatchers.get(i).onRotationChanged(rotation); |
| 4911 | } catch (RemoteException e) { |
| 4912 | } |
| 4913 | } |
| 4914 | } //end if changed |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4915 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4916 | return changed; |
| 4917 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4918 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4919 | public int getRotation() { |
| 4920 | return mRotation; |
| 4921 | } |
| 4922 | |
| 4923 | public int watchRotation(IRotationWatcher watcher) { |
| 4924 | final IBinder watcherBinder = watcher.asBinder(); |
| 4925 | IBinder.DeathRecipient dr = new IBinder.DeathRecipient() { |
| 4926 | public void binderDied() { |
| 4927 | synchronized (mWindowMap) { |
| 4928 | for (int i=0; i<mRotationWatchers.size(); i++) { |
| 4929 | if (watcherBinder == mRotationWatchers.get(i).asBinder()) { |
Suchi Amalapurapu | fff2fda | 2009-06-30 21:36:16 -0700 | [diff] [blame] | 4930 | IRotationWatcher removed = mRotationWatchers.remove(i); |
| 4931 | if (removed != null) { |
| 4932 | removed.asBinder().unlinkToDeath(this, 0); |
| 4933 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4934 | i--; |
| 4935 | } |
| 4936 | } |
| 4937 | } |
| 4938 | } |
| 4939 | }; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4940 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4941 | synchronized (mWindowMap) { |
| 4942 | try { |
| 4943 | watcher.asBinder().linkToDeath(dr, 0); |
| 4944 | mRotationWatchers.add(watcher); |
| 4945 | } catch (RemoteException e) { |
| 4946 | // Client died, no cleanup needed. |
| 4947 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4948 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4949 | return mRotation; |
| 4950 | } |
| 4951 | } |
| 4952 | |
| 4953 | /** |
| 4954 | * Starts the view server on the specified port. |
| 4955 | * |
| 4956 | * @param port The port to listener to. |
| 4957 | * |
| 4958 | * @return True if the server was successfully started, false otherwise. |
| 4959 | * |
| 4960 | * @see com.android.server.ViewServer |
| 4961 | * @see com.android.server.ViewServer#VIEW_SERVER_DEFAULT_PORT |
| 4962 | */ |
| 4963 | public boolean startViewServer(int port) { |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4964 | if (isSystemSecure()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4965 | return false; |
| 4966 | } |
| 4967 | |
| 4968 | if (!checkCallingPermission(Manifest.permission.DUMP, "startViewServer")) { |
| 4969 | return false; |
| 4970 | } |
| 4971 | |
| 4972 | if (port < 1024) { |
| 4973 | return false; |
| 4974 | } |
| 4975 | |
| 4976 | if (mViewServer != null) { |
| 4977 | if (!mViewServer.isRunning()) { |
| 4978 | try { |
| 4979 | return mViewServer.start(); |
| 4980 | } catch (IOException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4981 | Slog.w(TAG, "View server did not start"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4982 | } |
| 4983 | } |
| 4984 | return false; |
| 4985 | } |
| 4986 | |
| 4987 | try { |
| 4988 | mViewServer = new ViewServer(this, port); |
| 4989 | return mViewServer.start(); |
| 4990 | } catch (IOException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4991 | Slog.w(TAG, "View server did not start"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4992 | } |
| 4993 | return false; |
| 4994 | } |
| 4995 | |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4996 | private boolean isSystemSecure() { |
| 4997 | return "1".equals(SystemProperties.get(SYSTEM_SECURE, "1")) && |
| 4998 | "0".equals(SystemProperties.get(SYSTEM_DEBUGGABLE, "0")); |
| 4999 | } |
| 5000 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5001 | /** |
| 5002 | * Stops the view server if it exists. |
| 5003 | * |
| 5004 | * @return True if the server stopped, false if it wasn't started or |
| 5005 | * couldn't be stopped. |
| 5006 | * |
| 5007 | * @see com.android.server.ViewServer |
| 5008 | */ |
| 5009 | public boolean stopViewServer() { |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5010 | if (isSystemSecure()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5011 | return false; |
| 5012 | } |
| 5013 | |
| 5014 | if (!checkCallingPermission(Manifest.permission.DUMP, "stopViewServer")) { |
| 5015 | return false; |
| 5016 | } |
| 5017 | |
| 5018 | if (mViewServer != null) { |
| 5019 | return mViewServer.stop(); |
| 5020 | } |
| 5021 | return false; |
| 5022 | } |
| 5023 | |
| 5024 | /** |
| 5025 | * Indicates whether the view server is running. |
| 5026 | * |
| 5027 | * @return True if the server is running, false otherwise. |
| 5028 | * |
| 5029 | * @see com.android.server.ViewServer |
| 5030 | */ |
| 5031 | public boolean isViewServerRunning() { |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5032 | if (isSystemSecure()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5033 | return false; |
| 5034 | } |
| 5035 | |
| 5036 | if (!checkCallingPermission(Manifest.permission.DUMP, "isViewServerRunning")) { |
| 5037 | return false; |
| 5038 | } |
| 5039 | |
| 5040 | return mViewServer != null && mViewServer.isRunning(); |
| 5041 | } |
| 5042 | |
| 5043 | /** |
| 5044 | * Lists all availble windows in the system. The listing is written in the |
| 5045 | * specified Socket's output stream with the following syntax: |
| 5046 | * windowHashCodeInHexadecimal windowName |
| 5047 | * Each line of the ouput represents a different window. |
| 5048 | * |
| 5049 | * @param client The remote client to send the listing to. |
| 5050 | * @return False if an error occured, true otherwise. |
| 5051 | */ |
| 5052 | boolean viewServerListWindows(Socket client) { |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5053 | if (isSystemSecure()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5054 | return false; |
| 5055 | } |
| 5056 | |
| 5057 | boolean result = true; |
| 5058 | |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 5059 | WindowState[] windows; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5060 | synchronized (mWindowMap) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5061 | //noinspection unchecked |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 5062 | windows = mWindows.toArray(new WindowState[mWindows.size()]); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5063 | } |
| 5064 | |
| 5065 | BufferedWriter out = null; |
| 5066 | |
| 5067 | // Any uncaught exception will crash the system process |
| 5068 | try { |
| 5069 | OutputStream clientStream = client.getOutputStream(); |
| 5070 | out = new BufferedWriter(new OutputStreamWriter(clientStream), 8 * 1024); |
| 5071 | |
| 5072 | final int count = windows.length; |
| 5073 | for (int i = 0; i < count; i++) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 5074 | final WindowState w = windows[i]; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5075 | out.write(Integer.toHexString(System.identityHashCode(w))); |
| 5076 | out.write(' '); |
| 5077 | out.append(w.mAttrs.getTitle()); |
| 5078 | out.write('\n'); |
| 5079 | } |
| 5080 | |
| 5081 | out.write("DONE.\n"); |
| 5082 | out.flush(); |
| 5083 | } catch (Exception e) { |
| 5084 | result = false; |
| 5085 | } finally { |
| 5086 | if (out != null) { |
| 5087 | try { |
| 5088 | out.close(); |
| 5089 | } catch (IOException e) { |
| 5090 | result = false; |
| 5091 | } |
| 5092 | } |
| 5093 | } |
| 5094 | |
| 5095 | return result; |
| 5096 | } |
| 5097 | |
| 5098 | /** |
Konstantin Lopyrev | f962476 | 2010-07-14 17:02:37 -0700 | [diff] [blame] | 5099 | * Returns the focused window in the following format: |
| 5100 | * windowHashCodeInHexadecimal windowName |
| 5101 | * |
| 5102 | * @param client The remote client to send the listing to. |
| 5103 | * @return False if an error occurred, true otherwise. |
| 5104 | */ |
| 5105 | boolean viewServerGetFocusedWindow(Socket client) { |
| 5106 | if (isSystemSecure()) { |
| 5107 | return false; |
| 5108 | } |
| 5109 | |
| 5110 | boolean result = true; |
| 5111 | |
| 5112 | WindowState focusedWindow = getFocusedWindow(); |
| 5113 | |
| 5114 | BufferedWriter out = null; |
| 5115 | |
| 5116 | // Any uncaught exception will crash the system process |
| 5117 | try { |
| 5118 | OutputStream clientStream = client.getOutputStream(); |
| 5119 | out = new BufferedWriter(new OutputStreamWriter(clientStream), 8 * 1024); |
| 5120 | |
| 5121 | if(focusedWindow != null) { |
| 5122 | out.write(Integer.toHexString(System.identityHashCode(focusedWindow))); |
| 5123 | out.write(' '); |
| 5124 | out.append(focusedWindow.mAttrs.getTitle()); |
| 5125 | } |
| 5126 | out.write('\n'); |
| 5127 | out.flush(); |
| 5128 | } catch (Exception e) { |
| 5129 | result = false; |
| 5130 | } finally { |
| 5131 | if (out != null) { |
| 5132 | try { |
| 5133 | out.close(); |
| 5134 | } catch (IOException e) { |
| 5135 | result = false; |
| 5136 | } |
| 5137 | } |
| 5138 | } |
| 5139 | |
| 5140 | return result; |
| 5141 | } |
| 5142 | |
| 5143 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5144 | * Sends a command to a target window. The result of the command, if any, will be |
| 5145 | * written in the output stream of the specified socket. |
| 5146 | * |
| 5147 | * The parameters must follow this syntax: |
| 5148 | * windowHashcode extra |
| 5149 | * |
| 5150 | * Where XX is the length in characeters of the windowTitle. |
| 5151 | * |
| 5152 | * The first parameter is the target window. The window with the specified hashcode |
| 5153 | * will be the target. If no target can be found, nothing happens. The extra parameters |
| 5154 | * will be delivered to the target window and as parameters to the command itself. |
| 5155 | * |
| 5156 | * @param client The remote client to sent the result, if any, to. |
| 5157 | * @param command The command to execute. |
| 5158 | * @param parameters The command parameters. |
| 5159 | * |
| 5160 | * @return True if the command was successfully delivered, false otherwise. This does |
| 5161 | * not indicate whether the command itself was successful. |
| 5162 | */ |
| 5163 | boolean viewServerWindowCommand(Socket client, String command, String parameters) { |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5164 | if (isSystemSecure()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5165 | return false; |
| 5166 | } |
| 5167 | |
| 5168 | boolean success = true; |
| 5169 | Parcel data = null; |
| 5170 | Parcel reply = null; |
| 5171 | |
Konstantin Lopyrev | 43b9b48 | 2010-08-24 22:00:12 -0700 | [diff] [blame] | 5172 | BufferedWriter out = null; |
| 5173 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5174 | // Any uncaught exception will crash the system process |
| 5175 | try { |
| 5176 | // Find the hashcode of the window |
| 5177 | int index = parameters.indexOf(' '); |
| 5178 | if (index == -1) { |
| 5179 | index = parameters.length(); |
| 5180 | } |
| 5181 | final String code = parameters.substring(0, index); |
Romain Guy | 236092a | 2009-12-14 15:31:48 -0800 | [diff] [blame] | 5182 | int hashCode = (int) Long.parseLong(code, 16); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5183 | |
| 5184 | // Extract the command's parameter after the window description |
| 5185 | if (index < parameters.length()) { |
| 5186 | parameters = parameters.substring(index + 1); |
| 5187 | } else { |
| 5188 | parameters = ""; |
| 5189 | } |
| 5190 | |
| 5191 | final WindowManagerService.WindowState window = findWindow(hashCode); |
| 5192 | if (window == null) { |
| 5193 | return false; |
| 5194 | } |
| 5195 | |
| 5196 | data = Parcel.obtain(); |
| 5197 | data.writeInterfaceToken("android.view.IWindow"); |
| 5198 | data.writeString(command); |
| 5199 | data.writeString(parameters); |
| 5200 | data.writeInt(1); |
| 5201 | ParcelFileDescriptor.fromSocket(client).writeToParcel(data, 0); |
| 5202 | |
| 5203 | reply = Parcel.obtain(); |
| 5204 | |
| 5205 | final IBinder binder = window.mClient.asBinder(); |
| 5206 | // TODO: GET THE TRANSACTION CODE IN A SAFER MANNER |
| 5207 | binder.transact(IBinder.FIRST_CALL_TRANSACTION, data, reply, 0); |
| 5208 | |
| 5209 | reply.readException(); |
| 5210 | |
Konstantin Lopyrev | 43b9b48 | 2010-08-24 22:00:12 -0700 | [diff] [blame] | 5211 | if (!client.isOutputShutdown()) { |
| 5212 | out = new BufferedWriter(new OutputStreamWriter(client.getOutputStream())); |
| 5213 | out.write("DONE\n"); |
| 5214 | out.flush(); |
| 5215 | } |
| 5216 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5217 | } catch (Exception e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5218 | 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] | 5219 | success = false; |
| 5220 | } finally { |
| 5221 | if (data != null) { |
| 5222 | data.recycle(); |
| 5223 | } |
| 5224 | if (reply != null) { |
| 5225 | reply.recycle(); |
| 5226 | } |
Konstantin Lopyrev | 43b9b48 | 2010-08-24 22:00:12 -0700 | [diff] [blame] | 5227 | if (out != null) { |
| 5228 | try { |
| 5229 | out.close(); |
| 5230 | } catch (IOException e) { |
| 5231 | |
| 5232 | } |
| 5233 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5234 | } |
| 5235 | |
| 5236 | return success; |
| 5237 | } |
| 5238 | |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 5239 | public void addWindowChangeListener(WindowChangeListener listener) { |
| 5240 | synchronized(mWindowMap) { |
| 5241 | mWindowChangeListeners.add(listener); |
| 5242 | } |
| 5243 | } |
| 5244 | |
| 5245 | public void removeWindowChangeListener(WindowChangeListener listener) { |
| 5246 | synchronized(mWindowMap) { |
| 5247 | mWindowChangeListeners.remove(listener); |
| 5248 | } |
| 5249 | } |
| 5250 | |
| 5251 | private void notifyWindowsChanged() { |
| 5252 | WindowChangeListener[] windowChangeListeners; |
| 5253 | synchronized(mWindowMap) { |
| 5254 | if(mWindowChangeListeners.isEmpty()) { |
| 5255 | return; |
| 5256 | } |
| 5257 | windowChangeListeners = new WindowChangeListener[mWindowChangeListeners.size()]; |
| 5258 | windowChangeListeners = mWindowChangeListeners.toArray(windowChangeListeners); |
| 5259 | } |
| 5260 | int N = windowChangeListeners.length; |
| 5261 | for(int i = 0; i < N; i++) { |
| 5262 | windowChangeListeners[i].windowsChanged(); |
| 5263 | } |
| 5264 | } |
| 5265 | |
Konstantin Lopyrev | 6e0f65f | 2010-07-14 14:55:33 -0700 | [diff] [blame] | 5266 | private void notifyFocusChanged() { |
| 5267 | WindowChangeListener[] windowChangeListeners; |
| 5268 | synchronized(mWindowMap) { |
| 5269 | if(mWindowChangeListeners.isEmpty()) { |
| 5270 | return; |
| 5271 | } |
| 5272 | windowChangeListeners = new WindowChangeListener[mWindowChangeListeners.size()]; |
| 5273 | windowChangeListeners = mWindowChangeListeners.toArray(windowChangeListeners); |
| 5274 | } |
| 5275 | int N = windowChangeListeners.length; |
| 5276 | for(int i = 0; i < N; i++) { |
| 5277 | windowChangeListeners[i].focusChanged(); |
| 5278 | } |
| 5279 | } |
| 5280 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5281 | private WindowState findWindow(int hashCode) { |
| 5282 | if (hashCode == -1) { |
| 5283 | return getFocusedWindow(); |
| 5284 | } |
| 5285 | |
| 5286 | synchronized (mWindowMap) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 5287 | final ArrayList<WindowState> windows = mWindows; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5288 | final int count = windows.size(); |
| 5289 | |
| 5290 | for (int i = 0; i < count; i++) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 5291 | WindowState w = windows.get(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5292 | if (System.identityHashCode(w) == hashCode) { |
| 5293 | return w; |
| 5294 | } |
| 5295 | } |
| 5296 | } |
| 5297 | |
| 5298 | return null; |
| 5299 | } |
| 5300 | |
| 5301 | /* |
| 5302 | * Instruct the Activity Manager to fetch the current configuration and broadcast |
| 5303 | * that to config-changed listeners if appropriate. |
| 5304 | */ |
| 5305 | void sendNewConfiguration() { |
| 5306 | try { |
| 5307 | mActivityManager.updateConfiguration(null); |
| 5308 | } catch (RemoteException e) { |
| 5309 | } |
| 5310 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5311 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5312 | public Configuration computeNewConfiguration() { |
| 5313 | synchronized (mWindowMap) { |
Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 5314 | return computeNewConfigurationLocked(); |
| 5315 | } |
| 5316 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5317 | |
Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 5318 | Configuration computeNewConfigurationLocked() { |
| 5319 | Configuration config = new Configuration(); |
| 5320 | if (!computeNewConfigurationLocked(config)) { |
| 5321 | return null; |
| 5322 | } |
Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 5323 | return config; |
| 5324 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5325 | |
Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 5326 | boolean computeNewConfigurationLocked(Configuration config) { |
| 5327 | if (mDisplay == null) { |
| 5328 | return false; |
| 5329 | } |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 5330 | |
| 5331 | mInputManager.getInputConfiguration(config); |
Christopher Tate | b696aee | 2010-04-02 19:08:30 -0700 | [diff] [blame] | 5332 | |
| 5333 | // Use the effective "visual" dimensions based on current rotation |
| 5334 | final boolean rotated = (mRotation == Surface.ROTATION_90 |
| 5335 | || mRotation == Surface.ROTATION_270); |
| 5336 | final int dw = rotated ? mInitialDisplayHeight : mInitialDisplayWidth; |
| 5337 | final int dh = rotated ? mInitialDisplayWidth : mInitialDisplayHeight; |
| 5338 | |
Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 5339 | int orientation = Configuration.ORIENTATION_SQUARE; |
| 5340 | if (dw < dh) { |
| 5341 | orientation = Configuration.ORIENTATION_PORTRAIT; |
| 5342 | } else if (dw > dh) { |
| 5343 | orientation = Configuration.ORIENTATION_LANDSCAPE; |
| 5344 | } |
| 5345 | config.orientation = orientation; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 5346 | |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 5347 | DisplayMetrics dm = new DisplayMetrics(); |
| 5348 | mDisplay.getMetrics(dm); |
| 5349 | CompatibilityInfo.updateCompatibleScreenFrame(dm, orientation, mCompatibleScreenFrame); |
| 5350 | |
Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 5351 | if (mScreenLayout == Configuration.SCREENLAYOUT_SIZE_UNDEFINED) { |
Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 5352 | // Note we only do this once because at this point we don't |
| 5353 | // expect the screen to change in this way at runtime, and want |
| 5354 | // to avoid all of this computation for every config change. |
Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 5355 | int longSize = dw; |
| 5356 | int shortSize = dh; |
| 5357 | if (longSize < shortSize) { |
| 5358 | int tmp = longSize; |
| 5359 | longSize = shortSize; |
| 5360 | shortSize = tmp; |
| 5361 | } |
| 5362 | longSize = (int)(longSize/dm.density); |
| 5363 | shortSize = (int)(shortSize/dm.density); |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 5364 | |
Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 5365 | // These semi-magic numbers define our compatibility modes for |
| 5366 | // applications with different screens. Don't change unless you |
| 5367 | // make sure to test lots and lots of apps! |
| 5368 | if (longSize < 470) { |
| 5369 | // This is shorter than an HVGA normal density screen (which |
| 5370 | // is 480 pixels on its long side). |
Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 5371 | mScreenLayout = Configuration.SCREENLAYOUT_SIZE_SMALL |
| 5372 | | Configuration.SCREENLAYOUT_LONG_NO; |
Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 5373 | } else { |
Dianne Hackborn | 14cee9f | 2010-04-23 17:51:26 -0700 | [diff] [blame] | 5374 | // What size is this screen screen? |
| 5375 | if (longSize >= 800 && shortSize >= 600) { |
| 5376 | // SVGA or larger screens at medium density are the point |
| 5377 | // at which we consider it to be an extra large screen. |
| 5378 | mScreenLayout = Configuration.SCREENLAYOUT_SIZE_XLARGE; |
| 5379 | } else if (longSize >= 640 && shortSize >= 480) { |
Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 5380 | // VGA or larger screens at medium density are the point |
| 5381 | // at which we consider it to be a large screen. |
| 5382 | mScreenLayout = Configuration.SCREENLAYOUT_SIZE_LARGE; |
| 5383 | } else { |
| 5384 | mScreenLayout = Configuration.SCREENLAYOUT_SIZE_NORMAL; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 5385 | |
Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 5386 | // If this screen is wider than normal HVGA, or taller |
| 5387 | // than FWVGA, then for old apps we want to run in size |
| 5388 | // compatibility mode. |
| 5389 | if (shortSize > 321 || longSize > 570) { |
| 5390 | mScreenLayout |= Configuration.SCREENLAYOUT_COMPAT_NEEDED; |
| 5391 | } |
| 5392 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 5393 | |
Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 5394 | // Is this a long screen? |
| 5395 | if (((longSize*3)/5) >= (shortSize-1)) { |
| 5396 | // Anything wider than WVGA (5:3) is considering to be long. |
| 5397 | mScreenLayout |= Configuration.SCREENLAYOUT_LONG_YES; |
| 5398 | } else { |
| 5399 | mScreenLayout |= Configuration.SCREENLAYOUT_LONG_NO; |
| 5400 | } |
Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 5401 | } |
| 5402 | } |
Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 5403 | config.screenLayout = mScreenLayout; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 5404 | |
Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 5405 | config.keyboardHidden = Configuration.KEYBOARDHIDDEN_NO; |
| 5406 | config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_NO; |
| 5407 | mPolicy.adjustConfigurationLw(config); |
| 5408 | return true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5409 | } |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5410 | |
| 5411 | // ------------------------------------------------------------- |
| 5412 | // Drag and drop |
| 5413 | // ------------------------------------------------------------- |
| 5414 | |
| 5415 | IBinder prepareDragSurface(IWindow window, SurfaceSession session, |
| 5416 | boolean localOnly, int width, int height, Surface outSurface) { |
| 5417 | if (DEBUG_DRAG) { |
| 5418 | Slog.d(TAG, "prepare drag surface: w=" + width + " h=" + height |
| 5419 | + " local=" + localOnly + " win=" + window |
| 5420 | + " asbinder=" + window.asBinder()); |
| 5421 | } |
| 5422 | |
| 5423 | final int callerPid = Binder.getCallingPid(); |
| 5424 | final long origId = Binder.clearCallingIdentity(); |
| 5425 | IBinder token = null; |
| 5426 | |
| 5427 | try { |
| 5428 | synchronized (mWindowMap) { |
| 5429 | try { |
| 5430 | // !!! TODO: fail if the given window does not currently have touch focus? |
| 5431 | |
| 5432 | if (mDragState == null) { |
| 5433 | Surface surface = new Surface(session, callerPid, "drag surface", 0, |
| 5434 | width, height, PixelFormat.TRANSLUCENT, Surface.HIDDEN); |
| 5435 | outSurface.copyFrom(surface); |
| 5436 | token = new Binder(); |
| 5437 | mDragState = new DragState(token, surface, localOnly); |
| 5438 | mDragState.mSurface = surface; |
| 5439 | mDragState.mLocalOnly = localOnly; |
| 5440 | token = mDragState.mToken = new Binder(); |
| 5441 | |
| 5442 | // 5 second timeout for this window to actually begin the drag |
| 5443 | mH.removeMessages(H.DRAG_START_TIMEOUT, window); |
| 5444 | Message msg = mH.obtainMessage(H.DRAG_START_TIMEOUT, window.asBinder()); |
| 5445 | mH.sendMessageDelayed(msg, 5000); |
| 5446 | } else { |
| 5447 | Slog.w(TAG, "Drag already in progress"); |
| 5448 | } |
| 5449 | } catch (Surface.OutOfResourcesException e) { |
| 5450 | Slog.e(TAG, "Can't allocate drag surface w=" + width + " h=" + height, e); |
| 5451 | if (mDragState != null) { |
| 5452 | mDragState.reset(); |
| 5453 | mDragState = null; |
| 5454 | } |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5455 | } |
| 5456 | } |
| 5457 | } finally { |
| 5458 | Binder.restoreCallingIdentity(origId); |
| 5459 | } |
| 5460 | |
| 5461 | return token; |
| 5462 | } |
| 5463 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5464 | // ------------------------------------------------------------- |
| 5465 | // Input Events and Focus Management |
| 5466 | // ------------------------------------------------------------- |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5467 | |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5468 | InputMonitor mInputMonitor = new InputMonitor(); |
| 5469 | |
| 5470 | /* Tracks the progress of input dispatch and ensures that input dispatch state |
| 5471 | * is kept in sync with changes in window focus, visibility, registration, and |
| 5472 | * other relevant Window Manager state transitions. */ |
| 5473 | final class InputMonitor { |
| 5474 | // Current window with input focus for keys and other non-touch events. May be null. |
| 5475 | private WindowState mInputFocus; |
| 5476 | |
| 5477 | // When true, prevents input dispatch from proceeding until set to false again. |
| 5478 | private boolean mInputDispatchFrozen; |
| 5479 | |
| 5480 | // When true, input dispatch proceeds normally. Otherwise all events are dropped. |
| 5481 | private boolean mInputDispatchEnabled = true; |
| 5482 | |
| 5483 | // Temporary list of windows information to provide to the input dispatcher. |
| 5484 | private InputWindowList mTempInputWindows = new InputWindowList(); |
| 5485 | |
| 5486 | // Temporary input application object to provide to the input dispatcher. |
| 5487 | private InputApplication mTempInputApplication = new InputApplication(); |
| 5488 | |
| 5489 | /* Notifies the window manager about a broken input channel. |
| 5490 | * |
| 5491 | * Called by the InputManager. |
| 5492 | */ |
| 5493 | public void notifyInputChannelBroken(InputChannel inputChannel) { |
| 5494 | synchronized (mWindowMap) { |
| 5495 | WindowState windowState = getWindowStateForInputChannelLocked(inputChannel); |
| 5496 | if (windowState == null) { |
| 5497 | return; // irrelevant |
| 5498 | } |
| 5499 | |
| 5500 | Slog.i(TAG, "WINDOW DIED " + windowState); |
| 5501 | removeWindowLocked(windowState.mSession, windowState); |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 5502 | } |
| 5503 | } |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5504 | |
Jeff Brown | 519e024 | 2010-09-15 15:18:56 -0700 | [diff] [blame] | 5505 | /* Notifies the window manager about an application that is not responding. |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 5506 | * 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] | 5507 | * |
| 5508 | * Called by the InputManager. |
| 5509 | */ |
Jeff Brown | 519e024 | 2010-09-15 15:18:56 -0700 | [diff] [blame] | 5510 | public long notifyANR(Object token, InputChannel inputChannel) { |
| 5511 | AppWindowToken appWindowToken = null; |
| 5512 | if (inputChannel != null) { |
| 5513 | synchronized (mWindowMap) { |
| 5514 | WindowState windowState = getWindowStateForInputChannelLocked(inputChannel); |
| 5515 | if (windowState != null) { |
| 5516 | Slog.i(TAG, "Input event dispatching timed out sending to " |
| 5517 | + windowState.mAttrs.getTitle()); |
| 5518 | appWindowToken = windowState.mAppToken; |
| 5519 | } |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5520 | } |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 5521 | } |
| 5522 | |
Jeff Brown | 519e024 | 2010-09-15 15:18:56 -0700 | [diff] [blame] | 5523 | if (appWindowToken == null && token != null) { |
| 5524 | appWindowToken = (AppWindowToken) token; |
| 5525 | Slog.i(TAG, "Input event dispatching timed out sending to application " |
| 5526 | + appWindowToken.stringName); |
| 5527 | } |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5528 | |
Jeff Brown | 519e024 | 2010-09-15 15:18:56 -0700 | [diff] [blame] | 5529 | if (appWindowToken != null && appWindowToken.appToken != null) { |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5530 | try { |
| 5531 | // Notify the activity manager about the timeout and let it decide whether |
| 5532 | // to abort dispatching or keep waiting. |
Jeff Brown | 519e024 | 2010-09-15 15:18:56 -0700 | [diff] [blame] | 5533 | boolean abort = appWindowToken.appToken.keyDispatchingTimedOut(); |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5534 | if (! abort) { |
| 5535 | // The activity manager declined to abort dispatching. |
| 5536 | // Wait a bit longer and timeout again later. |
Jeff Brown | 519e024 | 2010-09-15 15:18:56 -0700 | [diff] [blame] | 5537 | return appWindowToken.inputDispatchingTimeoutNanos; |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 5538 | } |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5539 | } catch (RemoteException ex) { |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 5540 | } |
| 5541 | } |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 5542 | return 0; // abort dispatching |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 5543 | } |
| 5544 | |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5545 | private WindowState getWindowStateForInputChannel(InputChannel inputChannel) { |
| 5546 | synchronized (mWindowMap) { |
| 5547 | return getWindowStateForInputChannelLocked(inputChannel); |
| 5548 | } |
| 5549 | } |
| 5550 | |
| 5551 | private WindowState getWindowStateForInputChannelLocked(InputChannel inputChannel) { |
| 5552 | int windowCount = mWindows.size(); |
| 5553 | for (int i = 0; i < windowCount; i++) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 5554 | WindowState windowState = mWindows.get(i); |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5555 | if (windowState.mInputChannel == inputChannel) { |
| 5556 | return windowState; |
| 5557 | } |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 5558 | } |
| 5559 | |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5560 | return null; |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 5561 | } |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5562 | |
Chris Tate | a32dcf7 | 2010-10-14 12:13:50 -0700 | [diff] [blame] | 5563 | private void addDragInputWindowLw(InputWindowList windowList) { |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5564 | final InputWindow inputWindow = windowList.add(); |
| 5565 | inputWindow.inputChannel = mDragState.mServerChannel; |
| 5566 | inputWindow.name = "drag"; |
| 5567 | inputWindow.layoutParamsFlags = 0; |
| 5568 | inputWindow.layoutParamsType = WindowManager.LayoutParams.TYPE_DRAG; |
| 5569 | inputWindow.dispatchingTimeoutNanos = DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS; |
| 5570 | inputWindow.visible = true; |
| 5571 | inputWindow.canReceiveKeys = false; |
| 5572 | inputWindow.hasFocus = true; |
| 5573 | inputWindow.hasWallpaper = false; |
| 5574 | inputWindow.paused = false; |
Chris Tate | a32dcf7 | 2010-10-14 12:13:50 -0700 | [diff] [blame] | 5575 | inputWindow.layer = mDragState.getDragLayerLw(); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5576 | inputWindow.ownerPid = Process.myPid(); |
| 5577 | inputWindow.ownerUid = Process.myUid(); |
| 5578 | |
| 5579 | // The drag window covers the entire display |
| 5580 | inputWindow.frameLeft = 0; |
| 5581 | inputWindow.frameTop = 0; |
| 5582 | inputWindow.frameRight = mDisplay.getWidth(); |
| 5583 | inputWindow.frameBottom = mDisplay.getHeight(); |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 5584 | |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5585 | inputWindow.visibleFrameLeft = inputWindow.frameLeft; |
| 5586 | inputWindow.visibleFrameTop = inputWindow.frameTop; |
| 5587 | inputWindow.visibleFrameRight = inputWindow.frameRight; |
| 5588 | inputWindow.visibleFrameBottom = inputWindow.frameBottom; |
| 5589 | |
| 5590 | inputWindow.touchableAreaLeft = inputWindow.frameLeft; |
| 5591 | inputWindow.touchableAreaTop = inputWindow.frameTop; |
| 5592 | inputWindow.touchableAreaRight = inputWindow.frameRight; |
| 5593 | inputWindow.touchableAreaBottom = inputWindow.frameBottom; |
| 5594 | } |
| 5595 | |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5596 | /* Updates the cached window information provided to the input dispatcher. */ |
| 5597 | public void updateInputWindowsLw() { |
| 5598 | // Populate the input window list with information about all of the windows that |
| 5599 | // could potentially receive input. |
| 5600 | // As an optimization, we could try to prune the list of windows but this turns |
| 5601 | // out to be difficult because only the native code knows for sure which window |
| 5602 | // currently has touch focus. |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 5603 | final ArrayList<WindowState> windows = mWindows; |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5604 | |
| 5605 | // If there's a drag in flight, provide a pseudowindow to catch drag input |
| 5606 | final boolean inDrag = (mDragState != null); |
| 5607 | if (inDrag) { |
| 5608 | if (DEBUG_DRAG) { |
| 5609 | Log.d(TAG, "Inserting drag window"); |
| 5610 | } |
Chris Tate | a32dcf7 | 2010-10-14 12:13:50 -0700 | [diff] [blame] | 5611 | addDragInputWindowLw(mTempInputWindows); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5612 | } |
| 5613 | |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 5614 | final int N = windows.size(); |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5615 | for (int i = N - 1; i >= 0; i--) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 5616 | final WindowState child = windows.get(i); |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 5617 | if (child.mInputChannel == null || child.mRemoved) { |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5618 | // Skip this window because it cannot possibly receive input. |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 5619 | continue; |
| 5620 | } |
| 5621 | |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5622 | final int flags = child.mAttrs.flags; |
| 5623 | final int type = child.mAttrs.type; |
| 5624 | |
| 5625 | final boolean hasFocus = (child == mInputFocus); |
| 5626 | final boolean isVisible = child.isVisibleLw(); |
| 5627 | final boolean hasWallpaper = (child == mWallpaperTarget) |
| 5628 | && (type != WindowManager.LayoutParams.TYPE_KEYGUARD); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5629 | |
| 5630 | // If there's a drag in progress and 'child' is a potential drop target, |
| 5631 | // make sure it's been told about the drag |
| 5632 | if (inDrag && isVisible) { |
| 5633 | mDragState.sendDragStartedIfNeededLw(child); |
| 5634 | } |
| 5635 | |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5636 | // Add a window to our list of input windows. |
| 5637 | final InputWindow inputWindow = mTempInputWindows.add(); |
| 5638 | inputWindow.inputChannel = child.mInputChannel; |
Jeff Brown | 519e024 | 2010-09-15 15:18:56 -0700 | [diff] [blame] | 5639 | inputWindow.name = child.toString(); |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5640 | inputWindow.layoutParamsFlags = flags; |
| 5641 | inputWindow.layoutParamsType = type; |
| 5642 | inputWindow.dispatchingTimeoutNanos = child.getInputDispatchingTimeoutNanos(); |
| 5643 | inputWindow.visible = isVisible; |
Jeff Brown | 519e024 | 2010-09-15 15:18:56 -0700 | [diff] [blame] | 5644 | inputWindow.canReceiveKeys = child.canReceiveKeys(); |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5645 | inputWindow.hasFocus = hasFocus; |
| 5646 | inputWindow.hasWallpaper = hasWallpaper; |
| 5647 | inputWindow.paused = child.mAppToken != null ? child.mAppToken.paused : false; |
Jeff Brown | 519e024 | 2010-09-15 15:18:56 -0700 | [diff] [blame] | 5648 | inputWindow.layer = child.mLayer; |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5649 | inputWindow.ownerPid = child.mSession.mPid; |
| 5650 | inputWindow.ownerUid = child.mSession.mUid; |
| 5651 | |
| 5652 | final Rect frame = child.mFrame; |
| 5653 | inputWindow.frameLeft = frame.left; |
| 5654 | inputWindow.frameTop = frame.top; |
Jeff Brown | 85a3176 | 2010-09-01 17:01:00 -0700 | [diff] [blame] | 5655 | inputWindow.frameRight = frame.right; |
| 5656 | inputWindow.frameBottom = frame.bottom; |
| 5657 | |
| 5658 | final Rect visibleFrame = child.mVisibleFrame; |
| 5659 | inputWindow.visibleFrameLeft = visibleFrame.left; |
| 5660 | inputWindow.visibleFrameTop = visibleFrame.top; |
| 5661 | inputWindow.visibleFrameRight = visibleFrame.right; |
| 5662 | inputWindow.visibleFrameBottom = visibleFrame.bottom; |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5663 | |
| 5664 | switch (child.mTouchableInsets) { |
| 5665 | default: |
| 5666 | case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME: |
| 5667 | inputWindow.touchableAreaLeft = frame.left; |
| 5668 | inputWindow.touchableAreaTop = frame.top; |
| 5669 | inputWindow.touchableAreaRight = frame.right; |
| 5670 | inputWindow.touchableAreaBottom = frame.bottom; |
| 5671 | break; |
| 5672 | |
| 5673 | case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_CONTENT: { |
| 5674 | Rect inset = child.mGivenContentInsets; |
| 5675 | inputWindow.touchableAreaLeft = frame.left + inset.left; |
| 5676 | inputWindow.touchableAreaTop = frame.top + inset.top; |
| 5677 | inputWindow.touchableAreaRight = frame.right - inset.right; |
| 5678 | inputWindow.touchableAreaBottom = frame.bottom - inset.bottom; |
| 5679 | break; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5680 | } |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5681 | |
| 5682 | case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_VISIBLE: { |
| 5683 | Rect inset = child.mGivenVisibleInsets; |
| 5684 | inputWindow.touchableAreaLeft = frame.left + inset.left; |
| 5685 | inputWindow.touchableAreaTop = frame.top + inset.top; |
| 5686 | inputWindow.touchableAreaRight = frame.right - inset.right; |
| 5687 | inputWindow.touchableAreaBottom = frame.bottom - inset.bottom; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5688 | break; |
| 5689 | } |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5690 | } |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5691 | } |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 5692 | |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5693 | // Send windows to native code. |
| 5694 | mInputManager.setInputWindows(mTempInputWindows.toNullTerminatedArray()); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5695 | |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5696 | // Clear the list in preparation for the next round. |
| 5697 | // Also avoids keeping InputChannel objects referenced unnecessarily. |
| 5698 | mTempInputWindows.clear(); |
| 5699 | } |
| 5700 | |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 5701 | /* Notifies that the lid switch changed state. */ |
| 5702 | public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen) { |
| 5703 | mPolicy.notifyLidSwitchChanged(whenNanos, lidOpen); |
| 5704 | } |
| 5705 | |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5706 | /* Provides an opportunity for the window manager policy to intercept early key |
| 5707 | * processing as soon as the key has been read from the device. */ |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 5708 | public int interceptKeyBeforeQueueing(long whenNanos, int keyCode, boolean down, |
| 5709 | int policyFlags, boolean isScreenOn) { |
| 5710 | return mPolicy.interceptKeyBeforeQueueing(whenNanos, |
| 5711 | keyCode, down, policyFlags, isScreenOn); |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5712 | } |
| 5713 | |
| 5714 | /* Provides an opportunity for the window manager policy to process a key before |
| 5715 | * ordinary dispatch. */ |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 5716 | public boolean interceptKeyBeforeDispatching(InputChannel focus, |
| 5717 | int action, int flags, int keyCode, int metaState, int repeatCount, |
| 5718 | int policyFlags) { |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5719 | WindowState windowState = getWindowStateForInputChannel(focus); |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 5720 | return mPolicy.interceptKeyBeforeDispatching(windowState, action, flags, |
| 5721 | keyCode, metaState, repeatCount, policyFlags); |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5722 | } |
| 5723 | |
| 5724 | /* Called when the current input focus changes. |
| 5725 | * Layer assignment is assumed to be complete by the time this is called. |
| 5726 | */ |
| 5727 | public void setInputFocusLw(WindowState newWindow) { |
| 5728 | if (DEBUG_INPUT) { |
| 5729 | Slog.d(TAG, "Input focus has changed to " + newWindow); |
| 5730 | } |
| 5731 | |
| 5732 | if (newWindow != mInputFocus) { |
| 5733 | if (newWindow != null && newWindow.canReceiveKeys()) { |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5734 | // Displaying a window implicitly causes dispatching to be unpaused. |
| 5735 | // This is to protect against bugs if someone pauses dispatching but |
| 5736 | // forgets to resume. |
| 5737 | newWindow.mToken.paused = false; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5738 | } |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5739 | |
| 5740 | mInputFocus = newWindow; |
| 5741 | updateInputWindowsLw(); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5742 | } |
| 5743 | } |
| 5744 | |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5745 | public void setFocusedAppLw(AppWindowToken newApp) { |
| 5746 | // Focused app has changed. |
| 5747 | if (newApp == null) { |
| 5748 | mInputManager.setFocusedApplication(null); |
| 5749 | } else { |
| 5750 | mTempInputApplication.name = newApp.toString(); |
| 5751 | mTempInputApplication.dispatchingTimeoutNanos = |
| 5752 | newApp.inputDispatchingTimeoutNanos; |
| 5753 | mTempInputApplication.token = newApp; |
| 5754 | |
| 5755 | mInputManager.setFocusedApplication(mTempInputApplication); |
| 5756 | } |
| 5757 | } |
| 5758 | |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5759 | public void pauseDispatchingLw(WindowToken window) { |
| 5760 | if (! window.paused) { |
| 5761 | if (DEBUG_INPUT) { |
| 5762 | Slog.v(TAG, "Pausing WindowToken " + window); |
| 5763 | } |
| 5764 | |
| 5765 | window.paused = true; |
| 5766 | updateInputWindowsLw(); |
| 5767 | } |
| 5768 | } |
| 5769 | |
| 5770 | public void resumeDispatchingLw(WindowToken window) { |
| 5771 | if (window.paused) { |
| 5772 | if (DEBUG_INPUT) { |
| 5773 | Slog.v(TAG, "Resuming WindowToken " + window); |
| 5774 | } |
| 5775 | |
| 5776 | window.paused = false; |
| 5777 | updateInputWindowsLw(); |
| 5778 | } |
| 5779 | } |
| 5780 | |
| 5781 | public void freezeInputDispatchingLw() { |
| 5782 | if (! mInputDispatchFrozen) { |
| 5783 | if (DEBUG_INPUT) { |
| 5784 | Slog.v(TAG, "Freezing input dispatching"); |
| 5785 | } |
| 5786 | |
| 5787 | mInputDispatchFrozen = true; |
| 5788 | updateInputDispatchModeLw(); |
| 5789 | } |
| 5790 | } |
| 5791 | |
| 5792 | public void thawInputDispatchingLw() { |
| 5793 | if (mInputDispatchFrozen) { |
| 5794 | if (DEBUG_INPUT) { |
| 5795 | Slog.v(TAG, "Thawing input dispatching"); |
| 5796 | } |
| 5797 | |
| 5798 | mInputDispatchFrozen = false; |
| 5799 | updateInputDispatchModeLw(); |
| 5800 | } |
| 5801 | } |
| 5802 | |
| 5803 | public void setEventDispatchingLw(boolean enabled) { |
| 5804 | if (mInputDispatchEnabled != enabled) { |
| 5805 | if (DEBUG_INPUT) { |
| 5806 | Slog.v(TAG, "Setting event dispatching to " + enabled); |
| 5807 | } |
| 5808 | |
| 5809 | mInputDispatchEnabled = enabled; |
| 5810 | updateInputDispatchModeLw(); |
| 5811 | } |
| 5812 | } |
| 5813 | |
| 5814 | private void updateInputDispatchModeLw() { |
| 5815 | mInputManager.setInputDispatchMode(mInputDispatchEnabled, mInputDispatchFrozen); |
| 5816 | } |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5817 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5818 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5819 | public void pauseKeyDispatching(IBinder _token) { |
| 5820 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 5821 | "pauseKeyDispatching()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5822 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5823 | } |
| 5824 | |
| 5825 | synchronized (mWindowMap) { |
| 5826 | WindowToken token = mTokenMap.get(_token); |
| 5827 | if (token != null) { |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 5828 | mInputMonitor.pauseDispatchingLw(token); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5829 | } |
| 5830 | } |
| 5831 | } |
| 5832 | |
| 5833 | public void resumeKeyDispatching(IBinder _token) { |
| 5834 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 5835 | "resumeKeyDispatching()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5836 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5837 | } |
| 5838 | |
| 5839 | synchronized (mWindowMap) { |
| 5840 | WindowToken token = mTokenMap.get(_token); |
| 5841 | if (token != null) { |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 5842 | mInputMonitor.resumeDispatchingLw(token); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5843 | } |
| 5844 | } |
| 5845 | } |
| 5846 | |
| 5847 | public void setEventDispatching(boolean enabled) { |
| 5848 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 5849 | "resumeKeyDispatching()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5850 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5851 | } |
| 5852 | |
| 5853 | synchronized (mWindowMap) { |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 5854 | mInputMonitor.setEventDispatchingLw(enabled); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5855 | } |
| 5856 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5857 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5858 | /** |
| 5859 | * Injects a keystroke event into the UI. |
Jeff Brown | bbda99d | 2010-07-28 15:48:59 -0700 | [diff] [blame] | 5860 | * Even when sync is false, this method may block while waiting for current |
| 5861 | * input events to be dispatched. |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5862 | * |
| 5863 | * @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] | 5864 | * {@link SystemClock#uptimeMillis()} as the timebase.) |
| 5865 | * @param sync If true, wait for the event to be completed before returning to the caller. |
| 5866 | * @return Returns true if event was dispatched, false if it was dropped for any reason |
| 5867 | */ |
| 5868 | public boolean injectKeyEvent(KeyEvent ev, boolean sync) { |
| 5869 | long downTime = ev.getDownTime(); |
| 5870 | long eventTime = ev.getEventTime(); |
| 5871 | |
| 5872 | int action = ev.getAction(); |
| 5873 | int code = ev.getKeyCode(); |
| 5874 | int repeatCount = ev.getRepeatCount(); |
| 5875 | int metaState = ev.getMetaState(); |
| 5876 | int deviceId = ev.getDeviceId(); |
| 5877 | int scancode = ev.getScanCode(); |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 5878 | int source = ev.getSource(); |
| 5879 | |
| 5880 | if (source == InputDevice.SOURCE_UNKNOWN) { |
| 5881 | source = InputDevice.SOURCE_KEYBOARD; |
| 5882 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5883 | |
| 5884 | if (eventTime == 0) eventTime = SystemClock.uptimeMillis(); |
| 5885 | if (downTime == 0) downTime = eventTime; |
| 5886 | |
| 5887 | KeyEvent newEvent = new KeyEvent(downTime, eventTime, action, code, repeatCount, metaState, |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 5888 | deviceId, scancode, KeyEvent.FLAG_FROM_SYSTEM, source); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5889 | |
Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5890 | final int pid = Binder.getCallingPid(); |
| 5891 | final int uid = Binder.getCallingUid(); |
| 5892 | final long ident = Binder.clearCallingIdentity(); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5893 | |
Jeff Brown | bbda99d | 2010-07-28 15:48:59 -0700 | [diff] [blame] | 5894 | final int result = mInputManager.injectInputEvent(newEvent, pid, uid, |
| 5895 | sync ? InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH |
| 5896 | : InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT, |
| 5897 | INJECTION_TIMEOUT_MILLIS); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5898 | |
Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5899 | Binder.restoreCallingIdentity(ident); |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 5900 | return reportInjectionResult(result); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5901 | } |
| 5902 | |
| 5903 | /** |
| 5904 | * Inject a pointer (touch) event into the UI. |
Jeff Brown | bbda99d | 2010-07-28 15:48:59 -0700 | [diff] [blame] | 5905 | * Even when sync is false, this method may block while waiting for current |
| 5906 | * input events to be dispatched. |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5907 | * |
| 5908 | * @param ev A motion event describing the pointer (touch) action. (As noted in |
| 5909 | * {@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] | 5910 | * {@link SystemClock#uptimeMillis()} as the timebase.) |
| 5911 | * @param sync If true, wait for the event to be completed before returning to the caller. |
| 5912 | * @return Returns true if event was dispatched, false if it was dropped for any reason |
| 5913 | */ |
| 5914 | public boolean injectPointerEvent(MotionEvent ev, boolean sync) { |
Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5915 | final int pid = Binder.getCallingPid(); |
| 5916 | final int uid = Binder.getCallingUid(); |
| 5917 | final long ident = Binder.clearCallingIdentity(); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5918 | |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 5919 | MotionEvent newEvent = MotionEvent.obtain(ev); |
| 5920 | if ((newEvent.getSource() & InputDevice.SOURCE_CLASS_POINTER) == 0) { |
| 5921 | newEvent.setSource(InputDevice.SOURCE_TOUCHSCREEN); |
| 5922 | } |
| 5923 | |
Jeff Brown | bbda99d | 2010-07-28 15:48:59 -0700 | [diff] [blame] | 5924 | final int result = mInputManager.injectInputEvent(newEvent, pid, uid, |
| 5925 | sync ? InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH |
| 5926 | : InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT, |
| 5927 | INJECTION_TIMEOUT_MILLIS); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5928 | |
Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5929 | Binder.restoreCallingIdentity(ident); |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 5930 | return reportInjectionResult(result); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5931 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5932 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5933 | /** |
| 5934 | * Inject a trackball (navigation device) event into the UI. |
Jeff Brown | bbda99d | 2010-07-28 15:48:59 -0700 | [diff] [blame] | 5935 | * Even when sync is false, this method may block while waiting for current |
| 5936 | * input events to be dispatched. |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5937 | * |
| 5938 | * @param ev A motion event describing the trackball action. (As noted in |
| 5939 | * {@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] | 5940 | * {@link SystemClock#uptimeMillis()} as the timebase.) |
| 5941 | * @param sync If true, wait for the event to be completed before returning to the caller. |
| 5942 | * @return Returns true if event was dispatched, false if it was dropped for any reason |
| 5943 | */ |
| 5944 | public boolean injectTrackballEvent(MotionEvent ev, boolean sync) { |
Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5945 | final int pid = Binder.getCallingPid(); |
| 5946 | final int uid = Binder.getCallingUid(); |
| 5947 | final long ident = Binder.clearCallingIdentity(); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5948 | |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 5949 | MotionEvent newEvent = MotionEvent.obtain(ev); |
| 5950 | if ((newEvent.getSource() & InputDevice.SOURCE_CLASS_TRACKBALL) == 0) { |
| 5951 | newEvent.setSource(InputDevice.SOURCE_TRACKBALL); |
| 5952 | } |
| 5953 | |
Jeff Brown | bbda99d | 2010-07-28 15:48:59 -0700 | [diff] [blame] | 5954 | final int result = mInputManager.injectInputEvent(newEvent, pid, uid, |
| 5955 | sync ? InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH |
| 5956 | : InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT, |
| 5957 | INJECTION_TIMEOUT_MILLIS); |
| 5958 | |
| 5959 | Binder.restoreCallingIdentity(ident); |
| 5960 | return reportInjectionResult(result); |
| 5961 | } |
| 5962 | |
| 5963 | /** |
| 5964 | * Inject an input event into the UI without waiting for dispatch to commence. |
| 5965 | * This variant is useful for fire-and-forget input event injection. It does not |
| 5966 | * block any longer than it takes to enqueue the input event. |
| 5967 | * |
| 5968 | * @param ev An input event. (Be sure to set the input source correctly.) |
| 5969 | * @return Returns true if event was dispatched, false if it was dropped for any reason |
| 5970 | */ |
| 5971 | public boolean injectInputEventNoWait(InputEvent ev) { |
| 5972 | final int pid = Binder.getCallingPid(); |
| 5973 | final int uid = Binder.getCallingUid(); |
| 5974 | final long ident = Binder.clearCallingIdentity(); |
| 5975 | |
| 5976 | final int result = mInputManager.injectInputEvent(ev, pid, uid, |
| 5977 | InputManager.INPUT_EVENT_INJECTION_SYNC_NONE, |
| 5978 | INJECTION_TIMEOUT_MILLIS); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5979 | |
Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5980 | Binder.restoreCallingIdentity(ident); |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 5981 | return reportInjectionResult(result); |
| 5982 | } |
| 5983 | |
| 5984 | private boolean reportInjectionResult(int result) { |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 5985 | switch (result) { |
| 5986 | case InputManager.INPUT_EVENT_INJECTION_PERMISSION_DENIED: |
| 5987 | Slog.w(TAG, "Input event injection permission denied."); |
| 5988 | throw new SecurityException( |
| 5989 | "Injecting to another application requires INJECT_EVENTS permission"); |
| 5990 | case InputManager.INPUT_EVENT_INJECTION_SUCCEEDED: |
Christopher Tate | 09e85dc | 2010-08-02 11:54:41 -0700 | [diff] [blame] | 5991 | //Slog.v(TAG, "Input event injection succeeded."); |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 5992 | return true; |
| 5993 | case InputManager.INPUT_EVENT_INJECTION_TIMED_OUT: |
| 5994 | Slog.w(TAG, "Input event injection timed out."); |
| 5995 | return false; |
| 5996 | case InputManager.INPUT_EVENT_INJECTION_FAILED: |
| 5997 | default: |
| 5998 | Slog.w(TAG, "Input event injection failed."); |
| 5999 | return false; |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 6000 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6001 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6002 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6003 | private WindowState getFocusedWindow() { |
| 6004 | synchronized (mWindowMap) { |
| 6005 | return getFocusedWindowLocked(); |
| 6006 | } |
| 6007 | } |
| 6008 | |
| 6009 | private WindowState getFocusedWindowLocked() { |
| 6010 | return mCurrentFocus; |
| 6011 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6012 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6013 | public boolean detectSafeMode() { |
| 6014 | mSafeMode = mPolicy.detectSafeMode(); |
| 6015 | return mSafeMode; |
| 6016 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6017 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6018 | public void systemReady() { |
Dianne Hackborn | 5132b37 | 2010-07-29 12:51:35 -0700 | [diff] [blame] | 6019 | synchronized(mWindowMap) { |
| 6020 | if (mDisplay != null) { |
| 6021 | throw new IllegalStateException("Display already initialized"); |
| 6022 | } |
| 6023 | WindowManager wm = (WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE); |
| 6024 | mDisplay = wm.getDefaultDisplay(); |
| 6025 | mInitialDisplayWidth = mDisplay.getWidth(); |
| 6026 | mInitialDisplayHeight = mDisplay.getHeight(); |
| 6027 | mInputManager.setDisplaySize(0, mInitialDisplayWidth, mInitialDisplayHeight); |
| 6028 | } |
| 6029 | |
| 6030 | try { |
| 6031 | mActivityManager.updateConfiguration(null); |
| 6032 | } catch (RemoteException e) { |
| 6033 | } |
Dianne Hackborn | 154db5f | 2010-07-29 19:15:19 -0700 | [diff] [blame] | 6034 | |
| 6035 | mPolicy.systemReady(); |
Dianne Hackborn | 5132b37 | 2010-07-29 12:51:35 -0700 | [diff] [blame] | 6036 | } |
| 6037 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6038 | // ------------------------------------------------------------- |
| 6039 | // Client Session State |
| 6040 | // ------------------------------------------------------------- |
| 6041 | |
| 6042 | private final class Session extends IWindowSession.Stub |
| 6043 | implements IBinder.DeathRecipient { |
| 6044 | final IInputMethodClient mClient; |
| 6045 | final IInputContext mInputContext; |
| 6046 | final int mUid; |
| 6047 | final int mPid; |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 6048 | final String mStringName; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6049 | SurfaceSession mSurfaceSession; |
| 6050 | int mNumWindow = 0; |
| 6051 | boolean mClientDead = false; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6052 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6053 | public Session(IInputMethodClient client, IInputContext inputContext) { |
| 6054 | mClient = client; |
| 6055 | mInputContext = inputContext; |
| 6056 | mUid = Binder.getCallingUid(); |
| 6057 | mPid = Binder.getCallingPid(); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 6058 | StringBuilder sb = new StringBuilder(); |
| 6059 | sb.append("Session{"); |
| 6060 | sb.append(Integer.toHexString(System.identityHashCode(this))); |
| 6061 | sb.append(" uid "); |
| 6062 | sb.append(mUid); |
| 6063 | sb.append("}"); |
| 6064 | mStringName = sb.toString(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6065 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6066 | synchronized (mWindowMap) { |
| 6067 | if (mInputMethodManager == null && mHaveInputMethods) { |
| 6068 | IBinder b = ServiceManager.getService( |
| 6069 | Context.INPUT_METHOD_SERVICE); |
| 6070 | mInputMethodManager = IInputMethodManager.Stub.asInterface(b); |
| 6071 | } |
| 6072 | } |
| 6073 | long ident = Binder.clearCallingIdentity(); |
| 6074 | try { |
| 6075 | // Note: it is safe to call in to the input method manager |
| 6076 | // here because we are not holding our lock. |
| 6077 | if (mInputMethodManager != null) { |
| 6078 | mInputMethodManager.addClient(client, inputContext, |
| 6079 | mUid, mPid); |
| 6080 | } else { |
| 6081 | client.setUsingInputMethod(false); |
| 6082 | } |
| 6083 | client.asBinder().linkToDeath(this, 0); |
| 6084 | } catch (RemoteException e) { |
| 6085 | // The caller has died, so we can just forget about this. |
| 6086 | try { |
| 6087 | if (mInputMethodManager != null) { |
| 6088 | mInputMethodManager.removeClient(client); |
| 6089 | } |
| 6090 | } catch (RemoteException ee) { |
| 6091 | } |
| 6092 | } finally { |
| 6093 | Binder.restoreCallingIdentity(ident); |
| 6094 | } |
| 6095 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6096 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6097 | @Override |
| 6098 | public boolean onTransact(int code, Parcel data, Parcel reply, int flags) |
| 6099 | throws RemoteException { |
| 6100 | try { |
| 6101 | return super.onTransact(code, data, reply, flags); |
| 6102 | } catch (RuntimeException e) { |
| 6103 | // Log all 'real' exceptions thrown to the caller |
| 6104 | if (!(e instanceof SecurityException)) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6105 | Slog.e(TAG, "Window Session Crash", e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6106 | } |
| 6107 | throw e; |
| 6108 | } |
| 6109 | } |
| 6110 | |
| 6111 | public void binderDied() { |
| 6112 | // Note: it is safe to call in to the input method manager |
| 6113 | // here because we are not holding our lock. |
| 6114 | try { |
| 6115 | if (mInputMethodManager != null) { |
| 6116 | mInputMethodManager.removeClient(mClient); |
| 6117 | } |
| 6118 | } catch (RemoteException e) { |
| 6119 | } |
| 6120 | synchronized(mWindowMap) { |
Suchi Amalapurapu | fff2fda | 2009-06-30 21:36:16 -0700 | [diff] [blame] | 6121 | mClient.asBinder().unlinkToDeath(this, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6122 | mClientDead = true; |
| 6123 | killSessionLocked(); |
| 6124 | } |
| 6125 | } |
| 6126 | |
| 6127 | public int add(IWindow window, WindowManager.LayoutParams attrs, |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 6128 | int viewVisibility, Rect outContentInsets, InputChannel outInputChannel) { |
| 6129 | return addWindow(this, window, attrs, viewVisibility, outContentInsets, |
| 6130 | outInputChannel); |
| 6131 | } |
| 6132 | |
| 6133 | public int addWithoutInputChannel(IWindow window, WindowManager.LayoutParams attrs, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6134 | int viewVisibility, Rect outContentInsets) { |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 6135 | return addWindow(this, window, attrs, viewVisibility, outContentInsets, null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 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 remove(IWindow window) { |
| 6139 | removeWindow(this, window); |
| 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 int relayout(IWindow window, WindowManager.LayoutParams attrs, |
| 6143 | int requestedWidth, int requestedHeight, int viewFlags, |
| 6144 | boolean insetsPending, Rect outFrame, Rect outContentInsets, |
Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 6145 | Rect outVisibleInsets, Configuration outConfig, Surface outSurface) { |
Dianne Hackborn | f123e49 | 2010-09-24 11:16:23 -0700 | [diff] [blame] | 6146 | //Log.d(TAG, ">>>>>> ENTERED relayout from " + Binder.getCallingPid()); |
| 6147 | int res = relayoutWindow(this, window, attrs, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6148 | requestedWidth, requestedHeight, viewFlags, insetsPending, |
Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 6149 | outFrame, outContentInsets, outVisibleInsets, outConfig, outSurface); |
Dianne Hackborn | f123e49 | 2010-09-24 11:16:23 -0700 | [diff] [blame] | 6150 | //Log.d(TAG, "<<<<<< EXITING relayout to " + Binder.getCallingPid()); |
| 6151 | return res; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6152 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6153 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6154 | public void setTransparentRegion(IWindow window, Region region) { |
| 6155 | setTransparentRegionWindow(this, window, region); |
| 6156 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6157 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6158 | public void setInsets(IWindow window, int touchableInsets, |
| 6159 | Rect contentInsets, Rect visibleInsets) { |
| 6160 | setInsetsWindow(this, window, touchableInsets, contentInsets, |
| 6161 | visibleInsets); |
| 6162 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6163 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6164 | public void getDisplayFrame(IWindow window, Rect outDisplayFrame) { |
| 6165 | getWindowDisplayFrame(this, window, outDisplayFrame); |
| 6166 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6167 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6168 | public void finishDrawing(IWindow window) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6169 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6170 | TAG, "IWindow finishDrawing called for " + window); |
| 6171 | finishDrawingWindow(this, window); |
| 6172 | } |
| 6173 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6174 | public void setInTouchMode(boolean mode) { |
| 6175 | synchronized(mWindowMap) { |
| 6176 | mInTouchMode = mode; |
| 6177 | } |
| 6178 | } |
| 6179 | |
| 6180 | public boolean getInTouchMode() { |
| 6181 | synchronized(mWindowMap) { |
| 6182 | return mInTouchMode; |
| 6183 | } |
| 6184 | } |
| 6185 | |
| 6186 | public boolean performHapticFeedback(IWindow window, int effectId, |
| 6187 | boolean always) { |
| 6188 | synchronized(mWindowMap) { |
| 6189 | long ident = Binder.clearCallingIdentity(); |
| 6190 | try { |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 6191 | return mPolicy.performHapticFeedbackLw( |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 6192 | windowForClientLocked(this, window, true), |
| 6193 | effectId, always); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6194 | } finally { |
| 6195 | Binder.restoreCallingIdentity(ident); |
| 6196 | } |
| 6197 | } |
| 6198 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6199 | |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 6200 | /* Drag/drop */ |
| 6201 | public IBinder prepareDrag(IWindow window, boolean localOnly, |
| 6202 | int width, int height, Surface outSurface) { |
| 6203 | return prepareDragSurface(window, mSurfaceSession, localOnly, |
| 6204 | width, height, outSurface); |
| 6205 | } |
| 6206 | |
| 6207 | public boolean performDrag(IWindow window, IBinder dragToken, |
| 6208 | float touchX, float touchY, float thumbCenterX, float thumbCenterY, |
| 6209 | ClipData data) { |
| 6210 | if (DEBUG_DRAG) { |
| 6211 | Slog.d(TAG, "perform drag: win=" + window + " data=" + data); |
| 6212 | } |
| 6213 | |
| 6214 | synchronized (mWindowMap) { |
| 6215 | if (mDragState == null) { |
| 6216 | Slog.w(TAG, "No drag prepared"); |
| 6217 | throw new IllegalStateException("performDrag() without prepareDrag()"); |
| 6218 | } |
| 6219 | |
| 6220 | if (dragToken != mDragState.mToken) { |
| 6221 | Slog.w(TAG, "Performing mismatched drag"); |
| 6222 | throw new IllegalStateException("performDrag() does not match prepareDrag()"); |
| 6223 | } |
| 6224 | |
| 6225 | WindowState callingWin = windowForClientLocked(null, window, false); |
| 6226 | if (callingWin == null) { |
| 6227 | Slog.w(TAG, "Bad requesting window " + window); |
| 6228 | return false; // !!! TODO: throw here? |
| 6229 | } |
| 6230 | |
| 6231 | // !!! TODO: if input is not still focused on the initiating window, fail |
| 6232 | // the drag initiation (e.g. an alarm window popped up just as the application |
| 6233 | // called performDrag() |
| 6234 | |
| 6235 | mH.removeMessages(H.DRAG_START_TIMEOUT, window.asBinder()); |
| 6236 | |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 6237 | // !!! TODO: extract the current touch (x, y) in screen coordinates. That |
| 6238 | // will let us eliminate the (touchX,touchY) parameters from the API. |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 6239 | |
Chris Tate | b478f46 | 2010-10-15 16:02:26 -0700 | [diff] [blame] | 6240 | // !!! FIXME: put all this heavy stuff onto the mH looper, as well as |
| 6241 | // the actual drag event dispatch stuff in the dragstate |
| 6242 | |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 6243 | mDragState.register(); |
| 6244 | mInputMonitor.updateInputWindowsLw(); |
| 6245 | mInputManager.transferTouchFocus(callingWin.mInputChannel, |
| 6246 | mDragState.mServerChannel); |
| 6247 | |
| 6248 | mDragState.mData = data; |
Chris Tate | b478f46 | 2010-10-15 16:02:26 -0700 | [diff] [blame] | 6249 | mDragState.mCurrentX = touchX; |
| 6250 | mDragState.mCurrentY = touchY; |
Chris Tate | b8203e9 | 2010-10-12 14:23:21 -0700 | [diff] [blame] | 6251 | mDragState.broadcastDragStartedLw(touchX, touchY); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 6252 | |
| 6253 | // remember the thumb offsets for later |
| 6254 | mDragState.mThumbOffsetX = thumbCenterX; |
| 6255 | mDragState.mThumbOffsetY = thumbCenterY; |
| 6256 | |
| 6257 | // Make the surface visible at the proper location |
| 6258 | final Surface surface = mDragState.mSurface; |
Chris Tate | b478f46 | 2010-10-15 16:02:26 -0700 | [diff] [blame] | 6259 | Surface.openTransaction(); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 6260 | try { |
| 6261 | surface.setPosition((int)(touchX - thumbCenterX), |
| 6262 | (int)(touchY - thumbCenterY)); |
Chris Tate | b478f46 | 2010-10-15 16:02:26 -0700 | [diff] [blame] | 6263 | surface.setAlpha(.7071f); |
Chris Tate | a32dcf7 | 2010-10-14 12:13:50 -0700 | [diff] [blame] | 6264 | surface.setLayer(mDragState.getDragLayerLw()); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 6265 | surface.show(); |
| 6266 | } finally { |
Chris Tate | b478f46 | 2010-10-15 16:02:26 -0700 | [diff] [blame] | 6267 | Surface.closeTransaction(); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 6268 | } |
| 6269 | } |
| 6270 | |
| 6271 | return true; // success! |
| 6272 | } |
| 6273 | |
Chris Tate | d4533f14 | 2010-10-19 15:15:08 -0700 | [diff] [blame^] | 6274 | public void reportDropResult(IWindow window, boolean consumed) { |
| 6275 | IBinder token = window.asBinder(); |
| 6276 | if (DEBUG_DRAG) { |
| 6277 | Slog.d(TAG, "Drop result=" + consumed + " reported by " + token); |
| 6278 | } |
| 6279 | |
| 6280 | synchronized (mWindowMap) { |
| 6281 | if (mDragState.mToken != token) { |
| 6282 | Slog.w(TAG, "Invalid drop-result claim by " + window); |
| 6283 | throw new IllegalStateException("reportDropResult() by non-recipient"); |
| 6284 | } |
| 6285 | |
| 6286 | // The right window has responded, even if it's no longer around, |
| 6287 | // so be sure to halt the timeout even if the later WindowState |
| 6288 | // lookup fails. |
| 6289 | mH.removeMessages(H.DRAG_END_TIMEOUT, window.asBinder()); |
| 6290 | |
| 6291 | WindowState callingWin = windowForClientLocked(null, window, false); |
| 6292 | if (callingWin == null) { |
| 6293 | Slog.w(TAG, "Bad result-reporting window " + window); |
| 6294 | return; // !!! TODO: throw here? |
| 6295 | } |
| 6296 | |
| 6297 | mDragState.mDragResult = consumed; |
| 6298 | mDragState.endDragLw(); |
| 6299 | } |
| 6300 | } |
| 6301 | |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 6302 | public void dragRecipientEntered(IWindow window) { |
| 6303 | if (DEBUG_DRAG) { |
Chris Tate | d4533f14 | 2010-10-19 15:15:08 -0700 | [diff] [blame^] | 6304 | Slog.d(TAG, "Drag into new candidate view @ " + window.asBinder()); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 6305 | } |
| 6306 | } |
| 6307 | |
| 6308 | public void dragRecipientExited(IWindow window) { |
| 6309 | if (DEBUG_DRAG) { |
Chris Tate | d4533f14 | 2010-10-19 15:15:08 -0700 | [diff] [blame^] | 6310 | Slog.d(TAG, "Drag from old candidate view @ " + window.asBinder()); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 6311 | } |
| 6312 | } |
| 6313 | |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 6314 | 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] | 6315 | synchronized(mWindowMap) { |
| 6316 | long ident = Binder.clearCallingIdentity(); |
| 6317 | try { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 6318 | setWindowWallpaperPositionLocked( |
| 6319 | windowForClientLocked(this, window, true), |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 6320 | x, y, xStep, yStep); |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 6321 | } finally { |
| 6322 | Binder.restoreCallingIdentity(ident); |
| 6323 | } |
| 6324 | } |
| 6325 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6326 | |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 6327 | public void wallpaperOffsetsComplete(IBinder window) { |
| 6328 | WindowManagerService.this.wallpaperOffsetsComplete(window); |
| 6329 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6330 | |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 6331 | public Bundle sendWallpaperCommand(IBinder window, String action, int x, int y, |
| 6332 | int z, Bundle extras, boolean sync) { |
| 6333 | synchronized(mWindowMap) { |
| 6334 | long ident = Binder.clearCallingIdentity(); |
| 6335 | try { |
| 6336 | return sendWindowWallpaperCommandLocked( |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 6337 | windowForClientLocked(this, window, true), |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 6338 | action, x, y, z, extras, sync); |
| 6339 | } finally { |
| 6340 | Binder.restoreCallingIdentity(ident); |
| 6341 | } |
| 6342 | } |
| 6343 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6344 | |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 6345 | public void wallpaperCommandComplete(IBinder window, Bundle result) { |
| 6346 | WindowManagerService.this.wallpaperCommandComplete(window, result); |
| 6347 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6348 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6349 | void windowAddedLocked() { |
| 6350 | if (mSurfaceSession == null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6351 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6352 | TAG, "First window added to " + this + ", creating SurfaceSession"); |
| 6353 | mSurfaceSession = new SurfaceSession(); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6354 | if (SHOW_TRANSACTIONS) Slog.i( |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 6355 | TAG, " NEW SURFACE SESSION " + mSurfaceSession); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6356 | mSessions.add(this); |
| 6357 | } |
| 6358 | mNumWindow++; |
| 6359 | } |
| 6360 | |
| 6361 | void windowRemovedLocked() { |
| 6362 | mNumWindow--; |
| 6363 | killSessionLocked(); |
| 6364 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6365 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6366 | void killSessionLocked() { |
| 6367 | if (mNumWindow <= 0 && mClientDead) { |
| 6368 | mSessions.remove(this); |
| 6369 | if (mSurfaceSession != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6370 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6371 | TAG, "Last window removed from " + this |
| 6372 | + ", destroying " + mSurfaceSession); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6373 | if (SHOW_TRANSACTIONS) Slog.i( |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 6374 | TAG, " KILL SURFACE SESSION " + mSurfaceSession); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6375 | try { |
| 6376 | mSurfaceSession.kill(); |
| 6377 | } catch (Exception e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6378 | Slog.w(TAG, "Exception thrown when killing surface session " |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6379 | + mSurfaceSession + " in session " + this |
| 6380 | + ": " + e.toString()); |
| 6381 | } |
| 6382 | mSurfaceSession = null; |
| 6383 | } |
| 6384 | } |
| 6385 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6386 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6387 | void dump(PrintWriter pw, String prefix) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 6388 | pw.print(prefix); pw.print("mNumWindow="); pw.print(mNumWindow); |
| 6389 | pw.print(" mClientDead="); pw.print(mClientDead); |
| 6390 | pw.print(" mSurfaceSession="); pw.println(mSurfaceSession); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6391 | } |
| 6392 | |
| 6393 | @Override |
| 6394 | public String toString() { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 6395 | return mStringName; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6396 | } |
| 6397 | } |
| 6398 | |
| 6399 | // ------------------------------------------------------------- |
| 6400 | // Client Window State |
| 6401 | // ------------------------------------------------------------- |
| 6402 | |
| 6403 | private final class WindowState implements WindowManagerPolicy.WindowState { |
| 6404 | final Session mSession; |
| 6405 | final IWindow mClient; |
| 6406 | WindowToken mToken; |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 6407 | WindowToken mRootToken; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6408 | AppWindowToken mAppToken; |
| 6409 | AppWindowToken mTargetAppToken; |
| 6410 | final WindowManager.LayoutParams mAttrs = new WindowManager.LayoutParams(); |
| 6411 | final DeathRecipient mDeathRecipient; |
| 6412 | final WindowState mAttachedWindow; |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 6413 | final ArrayList<WindowState> mChildWindows = new ArrayList<WindowState>(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6414 | final int mBaseLayer; |
| 6415 | final int mSubLayer; |
| 6416 | final boolean mLayoutAttached; |
| 6417 | final boolean mIsImWindow; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 6418 | final boolean mIsWallpaper; |
| 6419 | final boolean mIsFloatingLayer; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6420 | int mViewVisibility; |
| 6421 | boolean mPolicyVisibility = true; |
| 6422 | boolean mPolicyVisibilityAfterAnim = true; |
| 6423 | boolean mAppFreezing; |
| 6424 | Surface mSurface; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 6425 | boolean mReportDestroySurface; |
| 6426 | boolean mSurfacePendingDestroy; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6427 | boolean mAttachedHidden; // is our parent window hidden? |
| 6428 | boolean mLastHidden; // was this window last hidden? |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 6429 | boolean mWallpaperVisible; // for wallpaper, what was last vis report? |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6430 | int mRequestedWidth; |
| 6431 | int mRequestedHeight; |
| 6432 | int mLastRequestedWidth; |
| 6433 | int mLastRequestedHeight; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6434 | int mLayer; |
| 6435 | int mAnimLayer; |
| 6436 | int mLastLayer; |
| 6437 | boolean mHaveFrame; |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 6438 | boolean mObscured; |
Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 6439 | boolean mTurnOnScreen; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6440 | |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 6441 | int mLayoutSeq = -1; |
| 6442 | |
| 6443 | Configuration mConfiguration = null; |
| 6444 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6445 | // Actual frame shown on-screen (may be modified by animation) |
| 6446 | final Rect mShownFrame = new Rect(); |
| 6447 | final Rect mLastShownFrame = new Rect(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6448 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6449 | /** |
Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 6450 | * Set when we have changed the size of the surface, to know that |
| 6451 | * we must tell them application to resize (and thus redraw itself). |
| 6452 | */ |
| 6453 | boolean mSurfaceResized; |
| 6454 | |
| 6455 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6456 | * Insets that determine the actually visible area |
| 6457 | */ |
| 6458 | final Rect mVisibleInsets = new Rect(); |
| 6459 | final Rect mLastVisibleInsets = new Rect(); |
| 6460 | boolean mVisibleInsetsChanged; |
| 6461 | |
| 6462 | /** |
| 6463 | * Insets that are covered by system windows |
| 6464 | */ |
| 6465 | final Rect mContentInsets = new Rect(); |
| 6466 | final Rect mLastContentInsets = new Rect(); |
| 6467 | boolean mContentInsetsChanged; |
| 6468 | |
| 6469 | /** |
| 6470 | * Set to true if we are waiting for this window to receive its |
| 6471 | * given internal insets before laying out other windows based on it. |
| 6472 | */ |
| 6473 | boolean mGivenInsetsPending; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6474 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6475 | /** |
| 6476 | * These are the content insets that were given during layout for |
| 6477 | * this window, to be applied to windows behind it. |
| 6478 | */ |
| 6479 | final Rect mGivenContentInsets = new Rect(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6480 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6481 | /** |
| 6482 | * These are the visible insets that were given during layout for |
| 6483 | * this window, to be applied to windows behind it. |
| 6484 | */ |
| 6485 | final Rect mGivenVisibleInsets = new Rect(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6486 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6487 | /** |
| 6488 | * Flag indicating whether the touchable region should be adjusted by |
| 6489 | * the visible insets; if false the area outside the visible insets is |
| 6490 | * NOT touchable, so we must use those to adjust the frame during hit |
| 6491 | * tests. |
| 6492 | */ |
| 6493 | int mTouchableInsets = ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6494 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6495 | // Current transformation being applied. |
| 6496 | float mDsDx=1, mDtDx=0, mDsDy=0, mDtDy=1; |
| 6497 | float mLastDsDx=1, mLastDtDx=0, mLastDsDy=0, mLastDtDy=1; |
| 6498 | float mHScale=1, mVScale=1; |
| 6499 | float mLastHScale=1, mLastVScale=1; |
| 6500 | final Matrix mTmpMatrix = new Matrix(); |
| 6501 | |
| 6502 | // "Real" frame that the application sees. |
| 6503 | final Rect mFrame = new Rect(); |
| 6504 | final Rect mLastFrame = new Rect(); |
| 6505 | |
| 6506 | final Rect mContainingFrame = new Rect(); |
| 6507 | final Rect mDisplayFrame = new Rect(); |
| 6508 | final Rect mContentFrame = new Rect(); |
| 6509 | final Rect mVisibleFrame = new Rect(); |
| 6510 | |
| 6511 | float mShownAlpha = 1; |
| 6512 | float mAlpha = 1; |
| 6513 | float mLastAlpha = 1; |
| 6514 | |
| 6515 | // Set to true if, when the window gets displayed, it should perform |
| 6516 | // an enter animation. |
| 6517 | boolean mEnterAnimationPending; |
| 6518 | |
| 6519 | // Currently running animation. |
| 6520 | boolean mAnimating; |
| 6521 | boolean mLocalAnimating; |
| 6522 | Animation mAnimation; |
| 6523 | boolean mAnimationIsEntrance; |
| 6524 | boolean mHasTransformation; |
| 6525 | boolean mHasLocalTransformation; |
| 6526 | final Transformation mTransformation = new Transformation(); |
| 6527 | |
Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 6528 | // If a window showing a wallpaper: the requested offset for the |
| 6529 | // wallpaper; if a wallpaper window: the currently applied offset. |
| 6530 | float mWallpaperX = -1; |
| 6531 | float mWallpaperY = -1; |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 6532 | |
| 6533 | // If a window showing a wallpaper: what fraction of the offset |
| 6534 | // range corresponds to a full virtual screen. |
| 6535 | float mWallpaperXStep = -1; |
| 6536 | float mWallpaperYStep = -1; |
| 6537 | |
Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 6538 | // Wallpaper windows: pixels offset based on above variables. |
| 6539 | int mXOffset; |
| 6540 | int mYOffset; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6541 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6542 | // This is set after IWindowSession.relayout() has been called at |
| 6543 | // least once for the window. It allows us to detect the situation |
| 6544 | // where we don't yet have a surface, but should have one soon, so |
| 6545 | // we can give the window focus before waiting for the relayout. |
| 6546 | boolean mRelayoutCalled; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6547 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6548 | // This is set after the Surface has been created but before the |
| 6549 | // window has been drawn. During this time the surface is hidden. |
| 6550 | boolean mDrawPending; |
| 6551 | |
| 6552 | // This is set after the window has finished drawing for the first |
| 6553 | // time but before its surface is shown. The surface will be |
| 6554 | // displayed when the next layout is run. |
| 6555 | boolean mCommitDrawPending; |
| 6556 | |
| 6557 | // This is set during the time after the window's drawing has been |
| 6558 | // committed, and before its surface is actually shown. It is used |
| 6559 | // to delay showing the surface until all windows in a token are ready |
| 6560 | // to be shown. |
| 6561 | boolean mReadyToShow; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6562 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6563 | // Set when the window has been shown in the screen the first time. |
| 6564 | boolean mHasDrawn; |
| 6565 | |
| 6566 | // Currently running an exit animation? |
| 6567 | boolean mExiting; |
| 6568 | |
| 6569 | // Currently on the mDestroySurface list? |
| 6570 | boolean mDestroying; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6571 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6572 | // Completely remove from window manager after exit animation? |
| 6573 | boolean mRemoveOnExit; |
| 6574 | |
| 6575 | // Set when the orientation is changing and this window has not yet |
| 6576 | // been updated for the new orientation. |
| 6577 | boolean mOrientationChanging; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6578 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6579 | // Is this window now (or just being) removed? |
| 6580 | boolean mRemoved; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6581 | |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 6582 | // For debugging, this is the last information given to the surface flinger. |
| 6583 | boolean mSurfaceShown; |
| 6584 | int mSurfaceX, mSurfaceY, mSurfaceW, mSurfaceH; |
| 6585 | int mSurfaceLayer; |
| 6586 | float mSurfaceAlpha; |
| 6587 | |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 6588 | // Input channel |
| 6589 | InputChannel mInputChannel; |
| 6590 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6591 | WindowState(Session s, IWindow c, WindowToken token, |
| 6592 | WindowState attachedWindow, WindowManager.LayoutParams a, |
| 6593 | int viewVisibility) { |
| 6594 | mSession = s; |
| 6595 | mClient = c; |
| 6596 | mToken = token; |
| 6597 | mAttrs.copyFrom(a); |
| 6598 | mViewVisibility = viewVisibility; |
| 6599 | DeathRecipient deathRecipient = new DeathRecipient(); |
| 6600 | mAlpha = a.alpha; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6601 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6602 | TAG, "Window " + this + " client=" + c.asBinder() |
| 6603 | + " token=" + token + " (" + mAttrs.token + ")"); |
| 6604 | try { |
| 6605 | c.asBinder().linkToDeath(deathRecipient, 0); |
| 6606 | } catch (RemoteException e) { |
| 6607 | mDeathRecipient = null; |
| 6608 | mAttachedWindow = null; |
| 6609 | mLayoutAttached = false; |
| 6610 | mIsImWindow = false; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 6611 | mIsWallpaper = false; |
| 6612 | mIsFloatingLayer = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6613 | mBaseLayer = 0; |
| 6614 | mSubLayer = 0; |
| 6615 | return; |
| 6616 | } |
| 6617 | mDeathRecipient = deathRecipient; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6618 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6619 | if ((mAttrs.type >= FIRST_SUB_WINDOW && |
| 6620 | mAttrs.type <= LAST_SUB_WINDOW)) { |
| 6621 | // The multiplier here is to reserve space for multiple |
| 6622 | // windows in the same type layer. |
| 6623 | mBaseLayer = mPolicy.windowTypeToLayerLw( |
| 6624 | attachedWindow.mAttrs.type) * TYPE_LAYER_MULTIPLIER |
| 6625 | + TYPE_LAYER_OFFSET; |
| 6626 | mSubLayer = mPolicy.subWindowTypeToLayerLw(a.type); |
| 6627 | mAttachedWindow = attachedWindow; |
| 6628 | mAttachedWindow.mChildWindows.add(this); |
| 6629 | mLayoutAttached = mAttrs.type != |
| 6630 | WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG; |
| 6631 | mIsImWindow = attachedWindow.mAttrs.type == TYPE_INPUT_METHOD |
| 6632 | || attachedWindow.mAttrs.type == TYPE_INPUT_METHOD_DIALOG; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 6633 | mIsWallpaper = attachedWindow.mAttrs.type == TYPE_WALLPAPER; |
| 6634 | mIsFloatingLayer = mIsImWindow || mIsWallpaper; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6635 | } else { |
| 6636 | // The multiplier here is to reserve space for multiple |
| 6637 | // windows in the same type layer. |
| 6638 | mBaseLayer = mPolicy.windowTypeToLayerLw(a.type) |
| 6639 | * TYPE_LAYER_MULTIPLIER |
| 6640 | + TYPE_LAYER_OFFSET; |
| 6641 | mSubLayer = 0; |
| 6642 | mAttachedWindow = null; |
| 6643 | mLayoutAttached = false; |
| 6644 | mIsImWindow = mAttrs.type == TYPE_INPUT_METHOD |
| 6645 | || mAttrs.type == TYPE_INPUT_METHOD_DIALOG; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 6646 | mIsWallpaper = mAttrs.type == TYPE_WALLPAPER; |
| 6647 | mIsFloatingLayer = mIsImWindow || mIsWallpaper; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6648 | } |
| 6649 | |
| 6650 | WindowState appWin = this; |
| 6651 | while (appWin.mAttachedWindow != null) { |
| 6652 | appWin = mAttachedWindow; |
| 6653 | } |
| 6654 | WindowToken appToken = appWin.mToken; |
| 6655 | while (appToken.appWindowToken == null) { |
| 6656 | WindowToken parent = mTokenMap.get(appToken.token); |
| 6657 | if (parent == null || appToken == parent) { |
| 6658 | break; |
| 6659 | } |
| 6660 | appToken = parent; |
| 6661 | } |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 6662 | mRootToken = appToken; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6663 | mAppToken = appToken.appWindowToken; |
| 6664 | |
| 6665 | mSurface = null; |
| 6666 | mRequestedWidth = 0; |
| 6667 | mRequestedHeight = 0; |
| 6668 | mLastRequestedWidth = 0; |
| 6669 | mLastRequestedHeight = 0; |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 6670 | mXOffset = 0; |
| 6671 | mYOffset = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6672 | mLayer = 0; |
| 6673 | mAnimLayer = 0; |
| 6674 | mLastLayer = 0; |
| 6675 | } |
| 6676 | |
| 6677 | void attach() { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6678 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6679 | TAG, "Attaching " + this + " token=" + mToken |
| 6680 | + ", list=" + mToken.windows); |
| 6681 | mSession.windowAddedLocked(); |
| 6682 | } |
| 6683 | |
| 6684 | public void computeFrameLw(Rect pf, Rect df, Rect cf, Rect vf) { |
| 6685 | mHaveFrame = true; |
| 6686 | |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 6687 | final Rect container = mContainingFrame; |
| 6688 | container.set(pf); |
| 6689 | |
| 6690 | final Rect display = mDisplayFrame; |
| 6691 | display.set(df); |
| 6692 | |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 6693 | if ((mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0) { |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 6694 | container.intersect(mCompatibleScreenFrame); |
Mitsuru Oshima | d2967e2 | 2009-07-20 14:01:43 -0700 | [diff] [blame] | 6695 | if ((mAttrs.flags & FLAG_LAYOUT_NO_LIMITS) == 0) { |
| 6696 | display.intersect(mCompatibleScreenFrame); |
| 6697 | } |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 6698 | } |
| 6699 | |
| 6700 | final int pw = container.right - container.left; |
| 6701 | final int ph = container.bottom - container.top; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6702 | |
| 6703 | int w,h; |
| 6704 | if ((mAttrs.flags & mAttrs.FLAG_SCALED) != 0) { |
| 6705 | w = mAttrs.width < 0 ? pw : mAttrs.width; |
| 6706 | h = mAttrs.height< 0 ? ph : mAttrs.height; |
| 6707 | } else { |
Romain Guy | 980a938 | 2010-01-08 15:06:28 -0800 | [diff] [blame] | 6708 | w = mAttrs.width == mAttrs.MATCH_PARENT ? pw : mRequestedWidth; |
| 6709 | h = mAttrs.height== mAttrs.MATCH_PARENT ? ph : mRequestedHeight; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6710 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6711 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6712 | final Rect content = mContentFrame; |
| 6713 | content.set(cf); |
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 | final Rect visible = mVisibleFrame; |
| 6716 | visible.set(vf); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6717 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6718 | final Rect frame = mFrame; |
Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 6719 | final int fw = frame.width(); |
| 6720 | final int fh = frame.height(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6721 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6722 | //System.out.println("In: w=" + w + " h=" + h + " container=" + |
| 6723 | // container + " x=" + mAttrs.x + " y=" + mAttrs.y); |
| 6724 | |
| 6725 | Gravity.apply(mAttrs.gravity, w, h, container, |
| 6726 | (int) (mAttrs.x + mAttrs.horizontalMargin * pw), |
| 6727 | (int) (mAttrs.y + mAttrs.verticalMargin * ph), frame); |
| 6728 | |
| 6729 | //System.out.println("Out: " + mFrame); |
| 6730 | |
| 6731 | // Now make sure the window fits in the overall display. |
| 6732 | Gravity.applyDisplay(mAttrs.gravity, df, frame); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6733 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6734 | // Make sure the content and visible frames are inside of the |
| 6735 | // final window frame. |
| 6736 | if (content.left < frame.left) content.left = frame.left; |
| 6737 | if (content.top < frame.top) content.top = frame.top; |
| 6738 | if (content.right > frame.right) content.right = frame.right; |
| 6739 | if (content.bottom > frame.bottom) content.bottom = frame.bottom; |
| 6740 | if (visible.left < frame.left) visible.left = frame.left; |
| 6741 | if (visible.top < frame.top) visible.top = frame.top; |
| 6742 | if (visible.right > frame.right) visible.right = frame.right; |
| 6743 | if (visible.bottom > frame.bottom) visible.bottom = frame.bottom; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6744 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6745 | final Rect contentInsets = mContentInsets; |
| 6746 | contentInsets.left = content.left-frame.left; |
| 6747 | contentInsets.top = content.top-frame.top; |
| 6748 | contentInsets.right = frame.right-content.right; |
| 6749 | contentInsets.bottom = frame.bottom-content.bottom; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6750 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6751 | final Rect visibleInsets = mVisibleInsets; |
| 6752 | visibleInsets.left = visible.left-frame.left; |
| 6753 | visibleInsets.top = visible.top-frame.top; |
| 6754 | visibleInsets.right = frame.right-visible.right; |
| 6755 | visibleInsets.bottom = frame.bottom-visible.bottom; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6756 | |
Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 6757 | if (mIsWallpaper && (fw != frame.width() || fh != frame.height())) { |
| 6758 | updateWallpaperOffsetLocked(this, mDisplay.getWidth(), |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 6759 | mDisplay.getHeight(), false); |
Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 6760 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6761 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6762 | if (localLOGV) { |
| 6763 | //if ("com.google.android.youtube".equals(mAttrs.packageName) |
| 6764 | // && mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_PANEL) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6765 | Slog.v(TAG, "Resolving (mRequestedWidth=" |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6766 | + mRequestedWidth + ", mRequestedheight=" |
| 6767 | + mRequestedHeight + ") to" + " (pw=" + pw + ", ph=" + ph |
| 6768 | + "): frame=" + mFrame.toShortString() |
| 6769 | + " ci=" + contentInsets.toShortString() |
| 6770 | + " vi=" + visibleInsets.toShortString()); |
| 6771 | //} |
| 6772 | } |
| 6773 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6774 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6775 | public Rect getFrameLw() { |
| 6776 | return mFrame; |
| 6777 | } |
| 6778 | |
| 6779 | public Rect getShownFrameLw() { |
| 6780 | return mShownFrame; |
| 6781 | } |
| 6782 | |
| 6783 | public Rect getDisplayFrameLw() { |
| 6784 | return mDisplayFrame; |
| 6785 | } |
| 6786 | |
| 6787 | public Rect getContentFrameLw() { |
| 6788 | return mContentFrame; |
| 6789 | } |
| 6790 | |
| 6791 | public Rect getVisibleFrameLw() { |
| 6792 | return mVisibleFrame; |
| 6793 | } |
| 6794 | |
| 6795 | public boolean getGivenInsetsPendingLw() { |
| 6796 | return mGivenInsetsPending; |
| 6797 | } |
| 6798 | |
| 6799 | public Rect getGivenContentInsetsLw() { |
| 6800 | return mGivenContentInsets; |
| 6801 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6802 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6803 | public Rect getGivenVisibleInsetsLw() { |
| 6804 | return mGivenVisibleInsets; |
| 6805 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6806 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6807 | public WindowManager.LayoutParams getAttrs() { |
| 6808 | return mAttrs; |
| 6809 | } |
| 6810 | |
| 6811 | public int getSurfaceLayer() { |
| 6812 | return mLayer; |
| 6813 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6814 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6815 | public IApplicationToken getAppToken() { |
| 6816 | return mAppToken != null ? mAppToken.appToken : null; |
| 6817 | } |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 6818 | |
| 6819 | public long getInputDispatchingTimeoutNanos() { |
| 6820 | return mAppToken != null |
| 6821 | ? mAppToken.inputDispatchingTimeoutNanos |
| 6822 | : DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS; |
| 6823 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6824 | |
| 6825 | public boolean hasAppShownWindows() { |
| 6826 | return mAppToken != null ? mAppToken.firstWindowDrawn : false; |
| 6827 | } |
| 6828 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6829 | public void setAnimation(Animation anim) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6830 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6831 | TAG, "Setting animation in " + this + ": " + anim); |
| 6832 | mAnimating = false; |
| 6833 | mLocalAnimating = false; |
| 6834 | mAnimation = anim; |
| 6835 | mAnimation.restrictDuration(MAX_ANIMATION_DURATION); |
| 6836 | mAnimation.scaleCurrentDuration(mWindowAnimationScale); |
| 6837 | } |
| 6838 | |
| 6839 | public void clearAnimation() { |
| 6840 | if (mAnimation != null) { |
| 6841 | mAnimating = true; |
| 6842 | mLocalAnimating = false; |
| 6843 | mAnimation = null; |
| 6844 | } |
| 6845 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6846 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6847 | Surface createSurfaceLocked() { |
| 6848 | if (mSurface == null) { |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 6849 | mReportDestroySurface = false; |
| 6850 | mSurfacePendingDestroy = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6851 | mDrawPending = true; |
| 6852 | mCommitDrawPending = false; |
| 6853 | mReadyToShow = false; |
| 6854 | if (mAppToken != null) { |
| 6855 | mAppToken.allDrawn = false; |
| 6856 | } |
| 6857 | |
| 6858 | int flags = 0; |
Mathias Agopian | 317a628 | 2009-08-13 17:29:02 -0700 | [diff] [blame] | 6859 | if (mAttrs.memoryType == MEMORY_TYPE_PUSH_BUFFERS) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6860 | flags |= Surface.PUSH_BUFFERS; |
| 6861 | } |
| 6862 | |
| 6863 | if ((mAttrs.flags&WindowManager.LayoutParams.FLAG_SECURE) != 0) { |
| 6864 | flags |= Surface.SECURE; |
| 6865 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6866 | if (DEBUG_VISIBILITY) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6867 | TAG, "Creating surface in session " |
| 6868 | + mSession.mSurfaceSession + " window " + this |
| 6869 | + " w=" + mFrame.width() |
| 6870 | + " h=" + mFrame.height() + " format=" |
| 6871 | + mAttrs.format + " flags=" + flags); |
| 6872 | |
| 6873 | int w = mFrame.width(); |
| 6874 | int h = mFrame.height(); |
| 6875 | if ((mAttrs.flags & LayoutParams.FLAG_SCALED) != 0) { |
| 6876 | // for a scaled surface, we always want the requested |
| 6877 | // size. |
| 6878 | w = mRequestedWidth; |
| 6879 | h = mRequestedHeight; |
| 6880 | } |
| 6881 | |
Romain Guy | 9825ec6 | 2009-10-01 00:58:09 -0700 | [diff] [blame] | 6882 | // Something is wrong and SurfaceFlinger will not like this, |
| 6883 | // try to revert to sane values |
| 6884 | if (w <= 0) w = 1; |
| 6885 | if (h <= 0) h = 1; |
| 6886 | |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 6887 | mSurfaceShown = false; |
| 6888 | mSurfaceLayer = 0; |
| 6889 | mSurfaceAlpha = 1; |
| 6890 | mSurfaceX = 0; |
| 6891 | mSurfaceY = 0; |
| 6892 | mSurfaceW = w; |
| 6893 | mSurfaceH = h; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6894 | try { |
Romain Guy | d10cd57 | 2010-10-10 13:33:22 -0700 | [diff] [blame] | 6895 | final boolean isHwAccelerated = (mAttrs.flags & |
| 6896 | WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED) != 0; |
| 6897 | final int format = isHwAccelerated ? PixelFormat.TRANSLUCENT : mAttrs.format; |
| 6898 | if (isHwAccelerated && mAttrs.format == PixelFormat.OPAQUE) { |
| 6899 | flags |= Surface.OPAQUE; |
| 6900 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6901 | mSurface = new Surface( |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6902 | mSession.mSurfaceSession, mSession.mPid, |
Mathias Agopian | 5d26c1e | 2010-03-01 16:09:43 -0800 | [diff] [blame] | 6903 | mAttrs.getTitle().toString(), |
Romain Guy | d10cd57 | 2010-10-10 13:33:22 -0700 | [diff] [blame] | 6904 | 0, w, h, format, flags); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6905 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " CREATE SURFACE " |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 6906 | + mSurface + " IN SESSION " |
| 6907 | + mSession.mSurfaceSession |
| 6908 | + ": pid=" + mSession.mPid + " format=" |
| 6909 | + mAttrs.format + " flags=0x" |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 6910 | + Integer.toHexString(flags) |
| 6911 | + " / " + this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6912 | } catch (Surface.OutOfResourcesException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6913 | Slog.w(TAG, "OutOfResourcesException creating surface"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6914 | reclaimSomeSurfaceMemoryLocked(this, "create"); |
| 6915 | return null; |
| 6916 | } catch (Exception e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6917 | Slog.e(TAG, "Exception creating surface", e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6918 | return null; |
| 6919 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6920 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6921 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6922 | TAG, "Got surface: " + mSurface |
| 6923 | + ", set left=" + mFrame.left + " top=" + mFrame.top |
| 6924 | + ", animLayer=" + mAnimLayer); |
| 6925 | if (SHOW_TRANSACTIONS) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6926 | Slog.i(TAG, ">>> OPEN TRANSACTION"); |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 6927 | if (SHOW_TRANSACTIONS) logSurface(this, |
| 6928 | "CREATE pos=(" + mFrame.left + "," + mFrame.top + ") (" + |
| 6929 | mFrame.width() + "x" + mFrame.height() + "), layer=" + |
| 6930 | mAnimLayer + " HIDE", null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6931 | } |
| 6932 | Surface.openTransaction(); |
| 6933 | try { |
| 6934 | try { |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 6935 | mSurfaceX = mFrame.left + mXOffset; |
Dianne Hackborn | 529bef6 | 2010-03-25 11:48:43 -0700 | [diff] [blame] | 6936 | mSurfaceY = mFrame.top + mYOffset; |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 6937 | mSurface.setPosition(mSurfaceX, mSurfaceY); |
| 6938 | mSurfaceLayer = mAnimLayer; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6939 | mSurface.setLayer(mAnimLayer); |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 6940 | mSurfaceShown = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6941 | mSurface.hide(); |
| 6942 | if ((mAttrs.flags&WindowManager.LayoutParams.FLAG_DITHER) != 0) { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 6943 | if (SHOW_TRANSACTIONS) logSurface(this, "DITHER", null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6944 | mSurface.setFlags(Surface.SURFACE_DITHER, |
| 6945 | Surface.SURFACE_DITHER); |
| 6946 | } |
| 6947 | } catch (RuntimeException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6948 | Slog.w(TAG, "Error creating surface in " + w, e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6949 | reclaimSomeSurfaceMemoryLocked(this, "create-init"); |
| 6950 | } |
| 6951 | mLastHidden = true; |
| 6952 | } finally { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6953 | if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6954 | Surface.closeTransaction(); |
| 6955 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6956 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6957 | TAG, "Created surface " + this); |
| 6958 | } |
| 6959 | return mSurface; |
| 6960 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6961 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6962 | void destroySurfaceLocked() { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6963 | if (mAppToken != null && this == mAppToken.startingWindow) { |
| 6964 | mAppToken.startingDisplayed = false; |
| 6965 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6966 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6967 | if (mSurface != null) { |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 6968 | mDrawPending = false; |
| 6969 | mCommitDrawPending = false; |
| 6970 | mReadyToShow = false; |
| 6971 | |
| 6972 | int i = mChildWindows.size(); |
| 6973 | while (i > 0) { |
| 6974 | i--; |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 6975 | WindowState c = mChildWindows.get(i); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 6976 | c.mAttachedHidden = true; |
| 6977 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6978 | |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 6979 | if (mReportDestroySurface) { |
| 6980 | mReportDestroySurface = false; |
| 6981 | mSurfacePendingDestroy = true; |
| 6982 | try { |
| 6983 | mClient.dispatchGetNewSurface(); |
| 6984 | // We'll really destroy on the next time around. |
| 6985 | return; |
| 6986 | } catch (RemoteException e) { |
| 6987 | } |
| 6988 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6989 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6990 | try { |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 6991 | if (DEBUG_VISIBILITY) { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 6992 | RuntimeException e = null; |
| 6993 | if (!HIDE_STACK_CRAWLS) { |
| 6994 | e = new RuntimeException(); |
| 6995 | e.fillInStackTrace(); |
| 6996 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6997 | Slog.w(TAG, "Window " + this + " destroying surface " |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 6998 | + mSurface + ", session " + mSession, e); |
| 6999 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7000 | if (SHOW_TRANSACTIONS) { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 7001 | RuntimeException e = null; |
| 7002 | if (!HIDE_STACK_CRAWLS) { |
| 7003 | e = new RuntimeException(); |
| 7004 | e.fillInStackTrace(); |
| 7005 | } |
| 7006 | if (SHOW_TRANSACTIONS) logSurface(this, "DESTROY", e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7007 | } |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 7008 | mSurface.destroy(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7009 | } catch (RuntimeException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7010 | Slog.w(TAG, "Exception thrown when destroying Window " + this |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7011 | + " surface " + mSurface + " session " + mSession |
| 7012 | + ": " + e.toString()); |
| 7013 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7014 | |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 7015 | mSurfaceShown = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7016 | mSurface = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7017 | } |
| 7018 | } |
| 7019 | |
| 7020 | boolean finishDrawingLocked() { |
| 7021 | if (mDrawPending) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7022 | if (SHOW_TRANSACTIONS || DEBUG_ORIENTATION) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7023 | TAG, "finishDrawingLocked: " + mSurface); |
| 7024 | mCommitDrawPending = true; |
| 7025 | mDrawPending = false; |
| 7026 | return true; |
| 7027 | } |
| 7028 | return false; |
| 7029 | } |
| 7030 | |
| 7031 | // This must be called while inside a transaction. |
Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 7032 | boolean commitFinishDrawingLocked(long currentTime) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7033 | //Slog.i(TAG, "commitFinishDrawingLocked: " + mSurface); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7034 | if (!mCommitDrawPending) { |
Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 7035 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7036 | } |
| 7037 | mCommitDrawPending = false; |
| 7038 | mReadyToShow = true; |
| 7039 | final boolean starting = mAttrs.type == TYPE_APPLICATION_STARTING; |
| 7040 | final AppWindowToken atoken = mAppToken; |
| 7041 | if (atoken == null || atoken.allDrawn || starting) { |
| 7042 | performShowLocked(); |
| 7043 | } |
Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 7044 | return true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7045 | } |
| 7046 | |
| 7047 | // This must be called while inside a transaction. |
| 7048 | boolean performShowLocked() { |
| 7049 | if (DEBUG_VISIBILITY) { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 7050 | RuntimeException e = null; |
| 7051 | if (!HIDE_STACK_CRAWLS) { |
| 7052 | e = new RuntimeException(); |
| 7053 | e.fillInStackTrace(); |
| 7054 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7055 | Slog.v(TAG, "performShow on " + this |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7056 | + ": readyToShow=" + mReadyToShow + " readyForDisplay=" + isReadyForDisplay() |
| 7057 | + " starting=" + (mAttrs.type == TYPE_APPLICATION_STARTING), e); |
| 7058 | } |
| 7059 | if (mReadyToShow && isReadyForDisplay()) { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 7060 | if (SHOW_TRANSACTIONS || DEBUG_ORIENTATION) logSurface(this, |
| 7061 | "SHOW (performShowLocked)", null); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7062 | if (DEBUG_VISIBILITY) Slog.v(TAG, "Showing " + this |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7063 | + " during animation: policyVis=" + mPolicyVisibility |
| 7064 | + " attHidden=" + mAttachedHidden |
| 7065 | + " tok.hiddenRequested=" |
| 7066 | + (mAppToken != null ? mAppToken.hiddenRequested : false) |
Dianne Hackborn | 248b188 | 2009-09-16 16:46:44 -0700 | [diff] [blame] | 7067 | + " tok.hidden=" |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7068 | + (mAppToken != null ? mAppToken.hidden : false) |
| 7069 | + " animating=" + mAnimating |
| 7070 | + " tok animating=" |
| 7071 | + (mAppToken != null ? mAppToken.animating : false)); |
| 7072 | if (!showSurfaceRobustlyLocked(this)) { |
| 7073 | return false; |
| 7074 | } |
| 7075 | mLastAlpha = -1; |
| 7076 | mHasDrawn = true; |
| 7077 | mLastHidden = false; |
| 7078 | mReadyToShow = false; |
| 7079 | enableScreenIfNeededLocked(); |
| 7080 | |
| 7081 | applyEnterAnimationLocked(this); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7082 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7083 | int i = mChildWindows.size(); |
| 7084 | while (i > 0) { |
| 7085 | i--; |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 7086 | WindowState c = mChildWindows.get(i); |
Dianne Hackborn | f09c1a2 | 2010-04-22 15:59:21 -0700 | [diff] [blame] | 7087 | if (c.mAttachedHidden) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7088 | c.mAttachedHidden = false; |
Dianne Hackborn | f09c1a2 | 2010-04-22 15:59:21 -0700 | [diff] [blame] | 7089 | if (c.mSurface != null) { |
| 7090 | c.performShowLocked(); |
| 7091 | // It hadn't been shown, which means layout not |
| 7092 | // performed on it, so now we want to make sure to |
| 7093 | // do a layout. If called from within the transaction |
| 7094 | // loop, this will cause it to restart with a new |
| 7095 | // layout. |
| 7096 | mLayoutNeeded = true; |
| 7097 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7098 | } |
| 7099 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7100 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7101 | if (mAttrs.type != TYPE_APPLICATION_STARTING |
| 7102 | && mAppToken != null) { |
| 7103 | mAppToken.firstWindowDrawn = true; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7104 | |
Dianne Hackborn | 248b188 | 2009-09-16 16:46:44 -0700 | [diff] [blame] | 7105 | if (mAppToken.startingData != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7106 | if (DEBUG_STARTING_WINDOW || DEBUG_ANIM) Slog.v(TAG, |
Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 7107 | "Finish starting " + mToken |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7108 | + ": first real window is shown, no animation"); |
Dianne Hackborn | 248b188 | 2009-09-16 16:46:44 -0700 | [diff] [blame] | 7109 | // If this initial window is animating, stop it -- we |
| 7110 | // will do an animation to reveal it from behind the |
| 7111 | // starting window, so there is no need for it to also |
| 7112 | // be doing its own stuff. |
| 7113 | if (mAnimation != null) { |
| 7114 | mAnimation = null; |
| 7115 | // Make sure we clean up the animation. |
| 7116 | mAnimating = true; |
| 7117 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7118 | mFinishedStarting.add(mAppToken); |
| 7119 | mH.sendEmptyMessage(H.FINISHED_STARTING); |
| 7120 | } |
| 7121 | mAppToken.updateReportedVisibilityLocked(); |
| 7122 | } |
| 7123 | } |
| 7124 | return true; |
| 7125 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7126 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7127 | // This must be called while inside a transaction. Returns true if |
| 7128 | // there is more animation to run. |
| 7129 | boolean stepAnimationLocked(long currentTime, int dw, int dh) { |
Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 7130 | if (!mDisplayFrozen && mPolicy.isScreenOn()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7131 | // We will run animations as long as the display isn't frozen. |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7132 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7133 | if (!mDrawPending && !mCommitDrawPending && mAnimation != null) { |
| 7134 | mHasTransformation = true; |
| 7135 | mHasLocalTransformation = true; |
| 7136 | if (!mLocalAnimating) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7137 | if (DEBUG_ANIM) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7138 | TAG, "Starting animation in " + this + |
| 7139 | " @ " + currentTime + ": ww=" + mFrame.width() + " wh=" + mFrame.height() + |
| 7140 | " dw=" + dw + " dh=" + dh + " scale=" + mWindowAnimationScale); |
| 7141 | mAnimation.initialize(mFrame.width(), mFrame.height(), dw, dh); |
| 7142 | mAnimation.setStartTime(currentTime); |
| 7143 | mLocalAnimating = true; |
| 7144 | mAnimating = true; |
| 7145 | } |
| 7146 | mTransformation.clear(); |
| 7147 | final boolean more = mAnimation.getTransformation( |
| 7148 | currentTime, mTransformation); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7149 | if (DEBUG_ANIM) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7150 | TAG, "Stepped animation in " + this + |
| 7151 | ": more=" + more + ", xform=" + mTransformation); |
| 7152 | if (more) { |
| 7153 | // we're not done! |
| 7154 | return true; |
| 7155 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7156 | if (DEBUG_ANIM) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7157 | TAG, "Finished animation in " + this + |
| 7158 | " @ " + currentTime); |
| 7159 | mAnimation = null; |
| 7160 | //WindowManagerService.this.dump(); |
| 7161 | } |
| 7162 | mHasLocalTransformation = false; |
| 7163 | if ((!mLocalAnimating || mAnimationIsEntrance) && mAppToken != null |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 7164 | && mAppToken.animation != null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7165 | // When our app token is animating, we kind-of pretend like |
| 7166 | // we are as well. Note the mLocalAnimating mAnimationIsEntrance |
| 7167 | // part of this check means that we will only do this if |
| 7168 | // our window is not currently exiting, or it is not |
| 7169 | // locally animating itself. The idea being that one that |
| 7170 | // is exiting and doing a local animation should be removed |
| 7171 | // once that animation is done. |
| 7172 | mAnimating = true; |
| 7173 | mHasTransformation = true; |
| 7174 | mTransformation.clear(); |
| 7175 | return false; |
| 7176 | } else if (mHasTransformation) { |
| 7177 | // Little trick to get through the path below to act like |
| 7178 | // we have finished an animation. |
| 7179 | mAnimating = true; |
| 7180 | } else if (isAnimating()) { |
| 7181 | mAnimating = true; |
| 7182 | } |
| 7183 | } else if (mAnimation != null) { |
| 7184 | // If the display is frozen, and there is a pending animation, |
| 7185 | // clear it and make sure we run the cleanup code. |
| 7186 | mAnimating = true; |
| 7187 | mLocalAnimating = true; |
| 7188 | mAnimation = null; |
| 7189 | } |
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 | if (!mAnimating && !mLocalAnimating) { |
| 7192 | return false; |
| 7193 | } |
| 7194 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7195 | if (DEBUG_ANIM) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7196 | TAG, "Animation done in " + this + ": exiting=" + mExiting |
| 7197 | + ", reportedVisible=" |
| 7198 | + (mAppToken != null ? mAppToken.reportedVisible : false)); |
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 | mAnimating = false; |
| 7201 | mLocalAnimating = false; |
| 7202 | mAnimation = null; |
| 7203 | mAnimLayer = mLayer; |
| 7204 | if (mIsImWindow) { |
| 7205 | mAnimLayer += mInputMethodAnimLayerAdjustment; |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 7206 | } else if (mIsWallpaper) { |
| 7207 | mAnimLayer += mWallpaperAnimLayerAdjustment; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7208 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7209 | if (DEBUG_LAYERS) Slog.v(TAG, "Stepping win " + this |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7210 | + " anim layer: " + mAnimLayer); |
| 7211 | mHasTransformation = false; |
| 7212 | mHasLocalTransformation = false; |
Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 7213 | if (mPolicyVisibility != mPolicyVisibilityAfterAnim) { |
| 7214 | if (DEBUG_VISIBILITY) { |
| 7215 | Slog.v(TAG, "Policy visibility changing after anim in " + this + ": " |
| 7216 | + mPolicyVisibilityAfterAnim); |
| 7217 | } |
| 7218 | mPolicyVisibility = mPolicyVisibilityAfterAnim; |
| 7219 | if (!mPolicyVisibility) { |
| 7220 | if (mCurrentFocus == this) { |
| 7221 | mFocusMayChange = true; |
| 7222 | } |
| 7223 | // Window is no longer visible -- make sure if we were waiting |
| 7224 | // for it to be displayed before enabling the display, that |
| 7225 | // we allow the display to be enabled now. |
| 7226 | enableScreenIfNeededLocked(); |
| 7227 | } |
Dianne Hackborn | f3bea9c | 2009-12-09 18:26:21 -0800 | [diff] [blame] | 7228 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7229 | mTransformation.clear(); |
| 7230 | if (mHasDrawn |
| 7231 | && mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING |
| 7232 | && mAppToken != null |
| 7233 | && mAppToken.firstWindowDrawn |
| 7234 | && mAppToken.startingData != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7235 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Finish starting " |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7236 | + mToken + ": first real window done animating"); |
| 7237 | mFinishedStarting.add(mAppToken); |
| 7238 | mH.sendEmptyMessage(H.FINISHED_STARTING); |
| 7239 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7240 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7241 | finishExit(); |
| 7242 | |
| 7243 | if (mAppToken != null) { |
| 7244 | mAppToken.updateReportedVisibilityLocked(); |
| 7245 | } |
| 7246 | |
| 7247 | return false; |
| 7248 | } |
| 7249 | |
| 7250 | void finishExit() { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7251 | if (DEBUG_ANIM) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7252 | TAG, "finishExit in " + this |
| 7253 | + ": exiting=" + mExiting |
| 7254 | + " remove=" + mRemoveOnExit |
| 7255 | + " windowAnimating=" + isWindowAnimating()); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7256 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7257 | final int N = mChildWindows.size(); |
| 7258 | for (int i=0; i<N; i++) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 7259 | mChildWindows.get(i).finishExit(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7260 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7261 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7262 | if (!mExiting) { |
| 7263 | return; |
| 7264 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7265 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7266 | if (isWindowAnimating()) { |
| 7267 | return; |
| 7268 | } |
| 7269 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7270 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7271 | TAG, "Exit animation finished in " + this |
| 7272 | + ": remove=" + mRemoveOnExit); |
| 7273 | if (mSurface != null) { |
| 7274 | mDestroySurface.add(this); |
| 7275 | mDestroying = true; |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 7276 | if (SHOW_TRANSACTIONS) logSurface(this, "HIDE (finishExit)", null); |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 7277 | mSurfaceShown = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7278 | try { |
| 7279 | mSurface.hide(); |
| 7280 | } catch (RuntimeException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7281 | Slog.w(TAG, "Error hiding surface in " + this, e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7282 | } |
| 7283 | mLastHidden = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7284 | } |
| 7285 | mExiting = false; |
| 7286 | if (mRemoveOnExit) { |
| 7287 | mPendingRemove.add(this); |
| 7288 | mRemoveOnExit = false; |
| 7289 | } |
| 7290 | } |
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 | boolean isIdentityMatrix(float dsdx, float dtdx, float dsdy, float dtdy) { |
| 7293 | if (dsdx < .99999f || dsdx > 1.00001f) return false; |
| 7294 | if (dtdy < .99999f || dtdy > 1.00001f) return false; |
| 7295 | if (dtdx < -.000001f || dtdx > .000001f) return false; |
| 7296 | if (dsdy < -.000001f || dsdy > .000001f) return false; |
| 7297 | return true; |
| 7298 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7299 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7300 | void computeShownFrameLocked() { |
| 7301 | final boolean selfTransformation = mHasLocalTransformation; |
| 7302 | Transformation attachedTransformation = |
| 7303 | (mAttachedWindow != null && mAttachedWindow.mHasLocalTransformation) |
| 7304 | ? mAttachedWindow.mTransformation : null; |
| 7305 | Transformation appTransformation = |
| 7306 | (mAppToken != null && mAppToken.hasTransformation) |
| 7307 | ? mAppToken.transformation : null; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7308 | |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 7309 | // Wallpapers are animated based on the "real" window they |
| 7310 | // are currently targeting. |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 7311 | if (mAttrs.type == TYPE_WALLPAPER && mLowerWallpaperTarget == null |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 7312 | && mWallpaperTarget != null) { |
Dianne Hackborn | 5baba16 | 2009-09-23 17:01:12 -0700 | [diff] [blame] | 7313 | if (mWallpaperTarget.mHasLocalTransformation && |
| 7314 | mWallpaperTarget.mAnimation != null && |
| 7315 | !mWallpaperTarget.mAnimation.getDetachWallpaper()) { |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 7316 | attachedTransformation = mWallpaperTarget.mTransformation; |
Dianne Hackborn | 5baba16 | 2009-09-23 17:01:12 -0700 | [diff] [blame] | 7317 | if (DEBUG_WALLPAPER && attachedTransformation != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7318 | Slog.v(TAG, "WP target attached xform: " + attachedTransformation); |
Dianne Hackborn | 5baba16 | 2009-09-23 17:01:12 -0700 | [diff] [blame] | 7319 | } |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 7320 | } |
| 7321 | if (mWallpaperTarget.mAppToken != null && |
Dianne Hackborn | 5baba16 | 2009-09-23 17:01:12 -0700 | [diff] [blame] | 7322 | mWallpaperTarget.mAppToken.hasTransformation && |
| 7323 | mWallpaperTarget.mAppToken.animation != null && |
| 7324 | !mWallpaperTarget.mAppToken.animation.getDetachWallpaper()) { |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 7325 | appTransformation = mWallpaperTarget.mAppToken.transformation; |
Dianne Hackborn | 5baba16 | 2009-09-23 17:01:12 -0700 | [diff] [blame] | 7326 | if (DEBUG_WALLPAPER && appTransformation != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7327 | Slog.v(TAG, "WP target app xform: " + appTransformation); |
Dianne Hackborn | 5baba16 | 2009-09-23 17:01:12 -0700 | [diff] [blame] | 7328 | } |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 7329 | } |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 7330 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7331 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7332 | if (selfTransformation || attachedTransformation != null |
| 7333 | || appTransformation != null) { |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7334 | // cache often used attributes locally |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7335 | final Rect frame = mFrame; |
| 7336 | final float tmpFloats[] = mTmpFloats; |
| 7337 | final Matrix tmpMatrix = mTmpMatrix; |
| 7338 | |
| 7339 | // Compute the desired transformation. |
Dianne Hackborn | 65c2387 | 2009-09-18 17:47:02 -0700 | [diff] [blame] | 7340 | tmpMatrix.setTranslate(0, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7341 | if (selfTransformation) { |
Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 7342 | tmpMatrix.postConcat(mTransformation.getMatrix()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7343 | } |
Dianne Hackborn | 65c2387 | 2009-09-18 17:47:02 -0700 | [diff] [blame] | 7344 | tmpMatrix.postTranslate(frame.left, frame.top); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7345 | if (attachedTransformation != null) { |
Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 7346 | tmpMatrix.postConcat(attachedTransformation.getMatrix()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7347 | } |
| 7348 | if (appTransformation != null) { |
Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 7349 | tmpMatrix.postConcat(appTransformation.getMatrix()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7350 | } |
| 7351 | |
| 7352 | // "convert" it into SurfaceFlinger's format |
| 7353 | // (a 2x2 matrix + an offset) |
| 7354 | // Here we must not transform the position of the surface |
| 7355 | // since it is already included in the transformation. |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7356 | //Slog.i(TAG, "Transform: " + matrix); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7357 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7358 | tmpMatrix.getValues(tmpFloats); |
| 7359 | mDsDx = tmpFloats[Matrix.MSCALE_X]; |
| 7360 | mDtDx = tmpFloats[Matrix.MSKEW_X]; |
| 7361 | mDsDy = tmpFloats[Matrix.MSKEW_Y]; |
| 7362 | mDtDy = tmpFloats[Matrix.MSCALE_Y]; |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 7363 | int x = (int)tmpFloats[Matrix.MTRANS_X] + mXOffset; |
| 7364 | int y = (int)tmpFloats[Matrix.MTRANS_Y] + mYOffset; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7365 | int w = frame.width(); |
| 7366 | int h = frame.height(); |
| 7367 | mShownFrame.set(x, y, x+w, y+h); |
| 7368 | |
| 7369 | // Now set the alpha... but because our current hardware |
| 7370 | // can't do alpha transformation on a non-opaque surface, |
| 7371 | // turn it off if we are running an animation that is also |
| 7372 | // transforming since it is more important to have that |
| 7373 | // animation be smooth. |
| 7374 | mShownAlpha = mAlpha; |
| 7375 | if (!mLimitedAlphaCompositing |
| 7376 | || (!PixelFormat.formatHasAlpha(mAttrs.format) |
| 7377 | || (isIdentityMatrix(mDsDx, mDtDx, mDsDy, mDtDy) |
| 7378 | && x == frame.left && y == frame.top))) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7379 | //Slog.i(TAG, "Applying alpha transform"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7380 | if (selfTransformation) { |
| 7381 | mShownAlpha *= mTransformation.getAlpha(); |
| 7382 | } |
| 7383 | if (attachedTransformation != null) { |
| 7384 | mShownAlpha *= attachedTransformation.getAlpha(); |
| 7385 | } |
| 7386 | if (appTransformation != null) { |
| 7387 | mShownAlpha *= appTransformation.getAlpha(); |
| 7388 | } |
| 7389 | } else { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7390 | //Slog.i(TAG, "Not applying alpha transform"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7391 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7392 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7393 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7394 | TAG, "Continuing animation in " + this + |
| 7395 | ": " + mShownFrame + |
| 7396 | ", alpha=" + mTransformation.getAlpha()); |
| 7397 | return; |
| 7398 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7399 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7400 | mShownFrame.set(mFrame); |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 7401 | if (mXOffset != 0 || mYOffset != 0) { |
| 7402 | mShownFrame.offset(mXOffset, mYOffset); |
| 7403 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7404 | mShownAlpha = mAlpha; |
| 7405 | mDsDx = 1; |
| 7406 | mDtDx = 0; |
| 7407 | mDsDy = 0; |
| 7408 | mDtDy = 1; |
| 7409 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7410 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7411 | /** |
| 7412 | * Is this window visible? It is not visible if there is no |
| 7413 | * surface, or we are in the process of running an exit animation |
| 7414 | * that will remove the surface, or its app token has been hidden. |
| 7415 | */ |
| 7416 | public boolean isVisibleLw() { |
| 7417 | final AppWindowToken atoken = mAppToken; |
| 7418 | return mSurface != null && mPolicyVisibility && !mAttachedHidden |
| 7419 | && (atoken == null || !atoken.hiddenRequested) |
| 7420 | && !mExiting && !mDestroying; |
| 7421 | } |
| 7422 | |
| 7423 | /** |
Dianne Hackborn | 3d163f07 | 2009-10-07 21:26:57 -0700 | [diff] [blame] | 7424 | * Like {@link #isVisibleLw}, but also counts a window that is currently |
| 7425 | * "hidden" behind the keyguard as visible. This allows us to apply |
| 7426 | * things like window flags that impact the keyguard. |
| 7427 | * XXX I am starting to think we need to have ANOTHER visibility flag |
| 7428 | * for this "hidden behind keyguard" state rather than overloading |
| 7429 | * mPolicyVisibility. Ungh. |
| 7430 | */ |
| 7431 | public boolean isVisibleOrBehindKeyguardLw() { |
| 7432 | final AppWindowToken atoken = mAppToken; |
| 7433 | return mSurface != null && !mAttachedHidden |
| 7434 | && (atoken == null ? mPolicyVisibility : !atoken.hiddenRequested) |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 7435 | && !mDrawPending && !mCommitDrawPending |
Dianne Hackborn | 3d163f07 | 2009-10-07 21:26:57 -0700 | [diff] [blame] | 7436 | && !mExiting && !mDestroying; |
| 7437 | } |
| 7438 | |
| 7439 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7440 | * Is this window visible, ignoring its app token? It is not visible |
| 7441 | * if there is no surface, or we are in the process of running an exit animation |
| 7442 | * that will remove the surface. |
| 7443 | */ |
| 7444 | public boolean isWinVisibleLw() { |
| 7445 | final AppWindowToken atoken = mAppToken; |
| 7446 | return mSurface != null && mPolicyVisibility && !mAttachedHidden |
| 7447 | && (atoken == null || !atoken.hiddenRequested || atoken.animating) |
| 7448 | && !mExiting && !mDestroying; |
| 7449 | } |
| 7450 | |
| 7451 | /** |
| 7452 | * The same as isVisible(), but follows the current hidden state of |
| 7453 | * the associated app token, not the pending requested hidden state. |
| 7454 | */ |
| 7455 | boolean isVisibleNow() { |
| 7456 | return mSurface != null && mPolicyVisibility && !mAttachedHidden |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 7457 | && !mRootToken.hidden && !mExiting && !mDestroying; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7458 | } |
| 7459 | |
| 7460 | /** |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 7461 | * Can this window possibly be a drag/drop target? The test here is |
| 7462 | * a combination of the above "visible now" with the check that the |
| 7463 | * Input Manager uses when discarding windows from input consideration. |
| 7464 | */ |
| 7465 | boolean isPotentialDragTarget() { |
| 7466 | return isVisibleNow() && (mInputChannel != null) && !mRemoved; |
| 7467 | } |
| 7468 | |
| 7469 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7470 | * Same as isVisible(), but we also count it as visible between the |
| 7471 | * call to IWindowSession.add() and the first relayout(). |
| 7472 | */ |
| 7473 | boolean isVisibleOrAdding() { |
| 7474 | final AppWindowToken atoken = mAppToken; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 7475 | return ((mSurface != null && !mReportDestroySurface) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7476 | || (!mRelayoutCalled && mViewVisibility == View.VISIBLE)) |
| 7477 | && mPolicyVisibility && !mAttachedHidden |
| 7478 | && (atoken == null || !atoken.hiddenRequested) |
| 7479 | && !mExiting && !mDestroying; |
| 7480 | } |
| 7481 | |
| 7482 | /** |
| 7483 | * Is this window currently on-screen? It is on-screen either if it |
| 7484 | * is visible or it is currently running an animation before no longer |
| 7485 | * being visible. |
| 7486 | */ |
| 7487 | boolean isOnScreen() { |
| 7488 | final AppWindowToken atoken = mAppToken; |
| 7489 | if (atoken != null) { |
| 7490 | return mSurface != null && mPolicyVisibility && !mDestroying |
| 7491 | && ((!mAttachedHidden && !atoken.hiddenRequested) |
Dianne Hackborn | 0cd4887 | 2009-08-13 18:51:59 -0700 | [diff] [blame] | 7492 | || mAnimation != null || atoken.animation != null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7493 | } else { |
| 7494 | return mSurface != null && mPolicyVisibility && !mDestroying |
Dianne Hackborn | 0cd4887 | 2009-08-13 18:51:59 -0700 | [diff] [blame] | 7495 | && (!mAttachedHidden || mAnimation != null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7496 | } |
| 7497 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7498 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7499 | /** |
| 7500 | * Like isOnScreen(), but we don't return true if the window is part |
| 7501 | * of a transition that has not yet been started. |
| 7502 | */ |
| 7503 | boolean isReadyForDisplay() { |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 7504 | if (mRootToken.waitingToShow && |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 7505 | mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 7506 | return false; |
| 7507 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7508 | final AppWindowToken atoken = mAppToken; |
Dianne Hackborn | 0cd4887 | 2009-08-13 18:51:59 -0700 | [diff] [blame] | 7509 | final boolean animating = atoken != null |
| 7510 | ? (atoken.animation != null) : false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7511 | return mSurface != null && mPolicyVisibility && !mDestroying |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 7512 | && ((!mAttachedHidden && mViewVisibility == View.VISIBLE |
| 7513 | && !mRootToken.hidden) |
Dianne Hackborn | 0cd4887 | 2009-08-13 18:51:59 -0700 | [diff] [blame] | 7514 | || mAnimation != null || animating); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7515 | } |
| 7516 | |
| 7517 | /** Is the window or its container currently animating? */ |
| 7518 | boolean isAnimating() { |
| 7519 | final WindowState attached = mAttachedWindow; |
| 7520 | final AppWindowToken atoken = mAppToken; |
| 7521 | return mAnimation != null |
| 7522 | || (attached != null && attached.mAnimation != null) |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7523 | || (atoken != null && |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7524 | (atoken.animation != null |
| 7525 | || atoken.inPendingTransaction)); |
| 7526 | } |
| 7527 | |
| 7528 | /** Is this window currently animating? */ |
| 7529 | boolean isWindowAnimating() { |
| 7530 | return mAnimation != null; |
| 7531 | } |
| 7532 | |
| 7533 | /** |
| 7534 | * Like isOnScreen, but returns false if the surface hasn't yet |
| 7535 | * been drawn. |
| 7536 | */ |
| 7537 | public boolean isDisplayedLw() { |
| 7538 | final AppWindowToken atoken = mAppToken; |
| 7539 | return mSurface != null && mPolicyVisibility && !mDestroying |
| 7540 | && !mDrawPending && !mCommitDrawPending |
| 7541 | && ((!mAttachedHidden && |
| 7542 | (atoken == null || !atoken.hiddenRequested)) |
| 7543 | || mAnimating); |
| 7544 | } |
| 7545 | |
Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 7546 | /** |
| 7547 | * Returns true if the window has a surface that it has drawn a |
| 7548 | * complete UI in to. |
| 7549 | */ |
| 7550 | public boolean isDrawnLw() { |
| 7551 | final AppWindowToken atoken = mAppToken; |
| 7552 | return mSurface != null && !mDestroying |
| 7553 | && !mDrawPending && !mCommitDrawPending; |
| 7554 | } |
| 7555 | |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 7556 | /** |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 7557 | * Return true if the window is opaque and fully drawn. This indicates |
| 7558 | * it may obscure windows behind it. |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 7559 | */ |
| 7560 | boolean isOpaqueDrawn() { |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 7561 | return (mAttrs.format == PixelFormat.OPAQUE |
| 7562 | || mAttrs.type == TYPE_WALLPAPER) |
| 7563 | && mSurface != null && mAnimation == null |
| 7564 | && (mAppToken == null || mAppToken.animation == null) |
| 7565 | && !mDrawPending && !mCommitDrawPending; |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 7566 | } |
| 7567 | |
| 7568 | boolean needsBackgroundFiller(int screenWidth, int screenHeight) { |
| 7569 | return |
| 7570 | // only if the application is requesting compatible window |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 7571 | (mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0 && |
| 7572 | // only if it's visible |
| 7573 | mHasDrawn && mViewVisibility == View.VISIBLE && |
Mitsuru Oshima | d2967e2 | 2009-07-20 14:01:43 -0700 | [diff] [blame] | 7574 | // and only if the application fills the compatible screen |
| 7575 | mFrame.left <= mCompatibleScreenFrame.left && |
| 7576 | mFrame.top <= mCompatibleScreenFrame.top && |
| 7577 | mFrame.right >= mCompatibleScreenFrame.right && |
| 7578 | mFrame.bottom >= mCompatibleScreenFrame.bottom && |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 7579 | // and starting window do not need background filler |
Mitsuru Oshima | d2967e2 | 2009-07-20 14:01:43 -0700 | [diff] [blame] | 7580 | mAttrs.type != mAttrs.TYPE_APPLICATION_STARTING; |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 7581 | } |
| 7582 | |
| 7583 | boolean isFullscreen(int screenWidth, int screenHeight) { |
| 7584 | return mFrame.left <= 0 && mFrame.top <= 0 && |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 7585 | mFrame.right >= screenWidth && mFrame.bottom >= screenHeight; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7586 | } |
| 7587 | |
| 7588 | void removeLocked() { |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 7589 | disposeInputChannel(); |
| 7590 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7591 | if (mAttachedWindow != null) { |
| 7592 | mAttachedWindow.mChildWindows.remove(this); |
| 7593 | } |
| 7594 | destroySurfaceLocked(); |
| 7595 | mSession.windowRemovedLocked(); |
| 7596 | try { |
| 7597 | mClient.asBinder().unlinkToDeath(mDeathRecipient, 0); |
| 7598 | } catch (RuntimeException e) { |
| 7599 | // Ignore if it has already been removed (usually because |
| 7600 | // we are doing this as part of processing a death note.) |
| 7601 | } |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 7602 | } |
| 7603 | |
| 7604 | void disposeInputChannel() { |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 7605 | if (mInputChannel != null) { |
| 7606 | mInputManager.unregisterInputChannel(mInputChannel); |
| 7607 | |
| 7608 | mInputChannel.dispose(); |
| 7609 | mInputChannel = null; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 7610 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7611 | } |
| 7612 | |
| 7613 | private class DeathRecipient implements IBinder.DeathRecipient { |
| 7614 | public void binderDied() { |
| 7615 | try { |
| 7616 | synchronized(mWindowMap) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 7617 | WindowState win = windowForClientLocked(mSession, mClient, false); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7618 | Slog.i(TAG, "WIN DEATH: " + win); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7619 | if (win != null) { |
| 7620 | removeWindowLocked(mSession, win); |
| 7621 | } |
| 7622 | } |
| 7623 | } catch (IllegalArgumentException ex) { |
| 7624 | // This will happen if the window has already been |
| 7625 | // removed. |
| 7626 | } |
| 7627 | } |
| 7628 | } |
| 7629 | |
| 7630 | /** Returns true if this window desires key events. */ |
| 7631 | public final boolean canReceiveKeys() { |
| 7632 | return isVisibleOrAdding() |
| 7633 | && (mViewVisibility == View.VISIBLE) |
| 7634 | && ((mAttrs.flags & WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) == 0); |
| 7635 | } |
| 7636 | |
| 7637 | public boolean hasDrawnLw() { |
| 7638 | return mHasDrawn; |
| 7639 | } |
| 7640 | |
| 7641 | public boolean showLw(boolean doAnimation) { |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 7642 | return showLw(doAnimation, true); |
| 7643 | } |
| 7644 | |
| 7645 | boolean showLw(boolean doAnimation, boolean requestAnim) { |
| 7646 | if (mPolicyVisibility && mPolicyVisibilityAfterAnim) { |
| 7647 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7648 | } |
Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 7649 | if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility true: " + this); |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 7650 | if (doAnimation) { |
| 7651 | if (DEBUG_VISIBILITY) Slog.v(TAG, "doAnimation: mPolicyVisibility=" |
| 7652 | + mPolicyVisibility + " mAnimation=" + mAnimation); |
| 7653 | if (mDisplayFrozen || !mPolicy.isScreenOn()) { |
| 7654 | doAnimation = false; |
| 7655 | } else if (mPolicyVisibility && mAnimation == null) { |
| 7656 | // Check for the case where we are currently visible and |
| 7657 | // not animating; we do not want to do animation at such a |
| 7658 | // point to become visible when we already are. |
| 7659 | doAnimation = false; |
| 7660 | } |
| 7661 | } |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 7662 | mPolicyVisibility = true; |
| 7663 | mPolicyVisibilityAfterAnim = true; |
| 7664 | if (doAnimation) { |
| 7665 | applyAnimationLocked(this, WindowManagerPolicy.TRANSIT_ENTER, true); |
| 7666 | } |
| 7667 | if (requestAnim) { |
| 7668 | requestAnimationLocked(0); |
| 7669 | } |
| 7670 | return true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7671 | } |
| 7672 | |
| 7673 | public boolean hideLw(boolean doAnimation) { |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 7674 | return hideLw(doAnimation, true); |
| 7675 | } |
| 7676 | |
| 7677 | boolean hideLw(boolean doAnimation, boolean requestAnim) { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 7678 | if (doAnimation) { |
| 7679 | if (mDisplayFrozen || !mPolicy.isScreenOn()) { |
| 7680 | doAnimation = false; |
| 7681 | } |
| 7682 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7683 | boolean current = doAnimation ? mPolicyVisibilityAfterAnim |
| 7684 | : mPolicyVisibility; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 7685 | if (!current) { |
| 7686 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7687 | } |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 7688 | if (doAnimation) { |
| 7689 | applyAnimationLocked(this, WindowManagerPolicy.TRANSIT_EXIT, false); |
| 7690 | if (mAnimation == null) { |
| 7691 | doAnimation = false; |
| 7692 | } |
| 7693 | } |
| 7694 | if (doAnimation) { |
| 7695 | mPolicyVisibilityAfterAnim = false; |
| 7696 | } else { |
Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 7697 | if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility false: " + this); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 7698 | mPolicyVisibilityAfterAnim = false; |
| 7699 | mPolicyVisibility = false; |
Dianne Hackborn | f3bea9c | 2009-12-09 18:26:21 -0800 | [diff] [blame] | 7700 | // Window is no longer visible -- make sure if we were waiting |
| 7701 | // for it to be displayed before enabling the display, that |
| 7702 | // we allow the display to be enabled now. |
| 7703 | enableScreenIfNeededLocked(); |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 7704 | if (mCurrentFocus == this) { |
| 7705 | mFocusMayChange = true; |
| 7706 | } |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 7707 | } |
| 7708 | if (requestAnim) { |
| 7709 | requestAnimationLocked(0); |
| 7710 | } |
| 7711 | return true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7712 | } |
| 7713 | |
| 7714 | void dump(PrintWriter pw, String prefix) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7715 | pw.print(prefix); pw.print("mSession="); pw.print(mSession); |
| 7716 | pw.print(" mClient="); pw.println(mClient.asBinder()); |
| 7717 | pw.print(prefix); pw.print("mAttrs="); pw.println(mAttrs); |
| 7718 | if (mAttachedWindow != null || mLayoutAttached) { |
| 7719 | pw.print(prefix); pw.print("mAttachedWindow="); pw.print(mAttachedWindow); |
| 7720 | pw.print(" mLayoutAttached="); pw.println(mLayoutAttached); |
| 7721 | } |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 7722 | if (mIsImWindow || mIsWallpaper || mIsFloatingLayer) { |
| 7723 | pw.print(prefix); pw.print("mIsImWindow="); pw.print(mIsImWindow); |
| 7724 | pw.print(" mIsWallpaper="); pw.print(mIsWallpaper); |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 7725 | pw.print(" mIsFloatingLayer="); pw.print(mIsFloatingLayer); |
| 7726 | pw.print(" mWallpaperVisible="); pw.println(mWallpaperVisible); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7727 | } |
| 7728 | pw.print(prefix); pw.print("mBaseLayer="); pw.print(mBaseLayer); |
| 7729 | pw.print(" mSubLayer="); pw.print(mSubLayer); |
| 7730 | pw.print(" mAnimLayer="); pw.print(mLayer); pw.print("+"); |
| 7731 | pw.print((mTargetAppToken != null ? mTargetAppToken.animLayerAdjustment |
| 7732 | : (mAppToken != null ? mAppToken.animLayerAdjustment : 0))); |
| 7733 | pw.print("="); pw.print(mAnimLayer); |
| 7734 | pw.print(" mLastLayer="); pw.println(mLastLayer); |
| 7735 | if (mSurface != null) { |
| 7736 | pw.print(prefix); pw.print("mSurface="); pw.println(mSurface); |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 7737 | pw.print(prefix); pw.print("Surface: shown="); pw.print(mSurfaceShown); |
| 7738 | pw.print(" layer="); pw.print(mSurfaceLayer); |
| 7739 | pw.print(" alpha="); pw.print(mSurfaceAlpha); |
| 7740 | pw.print(" rect=("); pw.print(mSurfaceX); |
| 7741 | pw.print(","); pw.print(mSurfaceY); |
| 7742 | pw.print(") "); pw.print(mSurfaceW); |
| 7743 | pw.print(" x "); pw.println(mSurfaceH); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7744 | } |
| 7745 | pw.print(prefix); pw.print("mToken="); pw.println(mToken); |
| 7746 | pw.print(prefix); pw.print("mRootToken="); pw.println(mRootToken); |
| 7747 | if (mAppToken != null) { |
| 7748 | pw.print(prefix); pw.print("mAppToken="); pw.println(mAppToken); |
| 7749 | } |
| 7750 | if (mTargetAppToken != null) { |
| 7751 | pw.print(prefix); pw.print("mTargetAppToken="); pw.println(mTargetAppToken); |
| 7752 | } |
| 7753 | pw.print(prefix); pw.print("mViewVisibility=0x"); |
| 7754 | pw.print(Integer.toHexString(mViewVisibility)); |
| 7755 | pw.print(" mLastHidden="); pw.print(mLastHidden); |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 7756 | pw.print(" mHaveFrame="); pw.print(mHaveFrame); |
| 7757 | pw.print(" mObscured="); pw.println(mObscured); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7758 | if (!mPolicyVisibility || !mPolicyVisibilityAfterAnim || mAttachedHidden) { |
| 7759 | pw.print(prefix); pw.print("mPolicyVisibility="); |
| 7760 | pw.print(mPolicyVisibility); |
| 7761 | pw.print(" mPolicyVisibilityAfterAnim="); |
| 7762 | pw.print(mPolicyVisibilityAfterAnim); |
| 7763 | pw.print(" mAttachedHidden="); pw.println(mAttachedHidden); |
| 7764 | } |
Dianne Hackborn | 9b52a21 | 2009-12-11 14:51:35 -0800 | [diff] [blame] | 7765 | if (!mRelayoutCalled) { |
| 7766 | pw.print(prefix); pw.print("mRelayoutCalled="); pw.println(mRelayoutCalled); |
| 7767 | } |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7768 | pw.print(prefix); pw.print("Requested w="); pw.print(mRequestedWidth); |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 7769 | pw.print(" h="); pw.print(mRequestedHeight); |
| 7770 | pw.print(" mLayoutSeq="); pw.println(mLayoutSeq); |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 7771 | if (mXOffset != 0 || mYOffset != 0) { |
| 7772 | pw.print(prefix); pw.print("Offsets x="); pw.print(mXOffset); |
| 7773 | pw.print(" y="); pw.println(mYOffset); |
| 7774 | } |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7775 | pw.print(prefix); pw.print("mGivenContentInsets="); |
| 7776 | mGivenContentInsets.printShortString(pw); |
| 7777 | pw.print(" mGivenVisibleInsets="); |
| 7778 | mGivenVisibleInsets.printShortString(pw); |
| 7779 | pw.println(); |
| 7780 | if (mTouchableInsets != 0 || mGivenInsetsPending) { |
| 7781 | pw.print(prefix); pw.print("mTouchableInsets="); pw.print(mTouchableInsets); |
| 7782 | pw.print(" mGivenInsetsPending="); pw.println(mGivenInsetsPending); |
| 7783 | } |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 7784 | pw.print(prefix); pw.print("mConfiguration="); pw.println(mConfiguration); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7785 | pw.print(prefix); pw.print("mShownFrame="); |
| 7786 | mShownFrame.printShortString(pw); |
| 7787 | pw.print(" last="); mLastShownFrame.printShortString(pw); |
| 7788 | pw.println(); |
| 7789 | pw.print(prefix); pw.print("mFrame="); mFrame.printShortString(pw); |
| 7790 | pw.print(" last="); mLastFrame.printShortString(pw); |
| 7791 | pw.println(); |
| 7792 | pw.print(prefix); pw.print("mContainingFrame="); |
| 7793 | mContainingFrame.printShortString(pw); |
| 7794 | pw.print(" mDisplayFrame="); |
| 7795 | mDisplayFrame.printShortString(pw); |
| 7796 | pw.println(); |
| 7797 | pw.print(prefix); pw.print("mContentFrame="); mContentFrame.printShortString(pw); |
| 7798 | pw.print(" mVisibleFrame="); mVisibleFrame.printShortString(pw); |
| 7799 | pw.println(); |
| 7800 | pw.print(prefix); pw.print("mContentInsets="); mContentInsets.printShortString(pw); |
| 7801 | pw.print(" last="); mLastContentInsets.printShortString(pw); |
| 7802 | pw.print(" mVisibleInsets="); mVisibleInsets.printShortString(pw); |
| 7803 | pw.print(" last="); mLastVisibleInsets.printShortString(pw); |
| 7804 | pw.println(); |
| 7805 | if (mShownAlpha != 1 || mAlpha != 1 || mLastAlpha != 1) { |
| 7806 | pw.print(prefix); pw.print("mShownAlpha="); pw.print(mShownAlpha); |
| 7807 | pw.print(" mAlpha="); pw.print(mAlpha); |
| 7808 | pw.print(" mLastAlpha="); pw.println(mLastAlpha); |
| 7809 | } |
| 7810 | if (mAnimating || mLocalAnimating || mAnimationIsEntrance |
| 7811 | || mAnimation != null) { |
| 7812 | pw.print(prefix); pw.print("mAnimating="); pw.print(mAnimating); |
| 7813 | pw.print(" mLocalAnimating="); pw.print(mLocalAnimating); |
| 7814 | pw.print(" mAnimationIsEntrance="); pw.print(mAnimationIsEntrance); |
| 7815 | pw.print(" mAnimation="); pw.println(mAnimation); |
| 7816 | } |
| 7817 | if (mHasTransformation || mHasLocalTransformation) { |
| 7818 | pw.print(prefix); pw.print("XForm: has="); |
| 7819 | pw.print(mHasTransformation); |
| 7820 | pw.print(" hasLocal="); pw.print(mHasLocalTransformation); |
| 7821 | pw.print(" "); mTransformation.printShortString(pw); |
| 7822 | pw.println(); |
| 7823 | } |
| 7824 | pw.print(prefix); pw.print("mDrawPending="); pw.print(mDrawPending); |
| 7825 | pw.print(" mCommitDrawPending="); pw.print(mCommitDrawPending); |
| 7826 | pw.print(" mReadyToShow="); pw.print(mReadyToShow); |
| 7827 | pw.print(" mHasDrawn="); pw.println(mHasDrawn); |
| 7828 | if (mExiting || mRemoveOnExit || mDestroying || mRemoved) { |
| 7829 | pw.print(prefix); pw.print("mExiting="); pw.print(mExiting); |
| 7830 | pw.print(" mRemoveOnExit="); pw.print(mRemoveOnExit); |
| 7831 | pw.print(" mDestroying="); pw.print(mDestroying); |
| 7832 | pw.print(" mRemoved="); pw.println(mRemoved); |
| 7833 | } |
Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 7834 | if (mOrientationChanging || mAppFreezing || mTurnOnScreen) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7835 | pw.print(prefix); pw.print("mOrientationChanging="); |
| 7836 | pw.print(mOrientationChanging); |
Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 7837 | pw.print(" mAppFreezing="); pw.print(mAppFreezing); |
| 7838 | pw.print(" mTurnOnScreen="); pw.println(mTurnOnScreen); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7839 | } |
Mitsuru Oshima | 589cebe | 2009-07-22 20:38:58 -0700 | [diff] [blame] | 7840 | if (mHScale != 1 || mVScale != 1) { |
| 7841 | pw.print(prefix); pw.print("mHScale="); pw.print(mHScale); |
| 7842 | pw.print(" mVScale="); pw.println(mVScale); |
| 7843 | } |
Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 7844 | if (mWallpaperX != -1 || mWallpaperY != -1) { |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 7845 | pw.print(prefix); pw.print("mWallpaperX="); pw.print(mWallpaperX); |
| 7846 | pw.print(" mWallpaperY="); pw.println(mWallpaperY); |
| 7847 | } |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 7848 | if (mWallpaperXStep != -1 || mWallpaperYStep != -1) { |
| 7849 | pw.print(prefix); pw.print("mWallpaperXStep="); pw.print(mWallpaperXStep); |
| 7850 | pw.print(" mWallpaperYStep="); pw.println(mWallpaperYStep); |
| 7851 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7852 | } |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 7853 | |
| 7854 | String makeInputChannelName() { |
| 7855 | return Integer.toHexString(System.identityHashCode(this)) |
| 7856 | + " " + mAttrs.getTitle(); |
| 7857 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7858 | |
| 7859 | @Override |
| 7860 | public String toString() { |
| 7861 | return "Window{" |
| 7862 | + Integer.toHexString(System.identityHashCode(this)) |
| 7863 | + " " + mAttrs.getTitle() + " paused=" + mToken.paused + "}"; |
| 7864 | } |
| 7865 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7866 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7867 | // ------------------------------------------------------------- |
| 7868 | // Window Token State |
| 7869 | // ------------------------------------------------------------- |
| 7870 | |
| 7871 | class WindowToken { |
| 7872 | // The actual token. |
| 7873 | final IBinder token; |
| 7874 | |
| 7875 | // The type of window this token is for, as per WindowManager.LayoutParams. |
| 7876 | final int windowType; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7877 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7878 | // Set if this token was explicitly added by a client, so should |
| 7879 | // not be removed when all windows are removed. |
| 7880 | final boolean explicit; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7881 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7882 | // For printing. |
| 7883 | String stringName; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7884 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7885 | // If this is an AppWindowToken, this is non-null. |
| 7886 | AppWindowToken appWindowToken; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7887 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7888 | // All of the windows associated with this token. |
| 7889 | final ArrayList<WindowState> windows = new ArrayList<WindowState>(); |
| 7890 | |
| 7891 | // Is key dispatching paused for this token? |
| 7892 | boolean paused = false; |
| 7893 | |
| 7894 | // Should this token's windows be hidden? |
| 7895 | boolean hidden; |
| 7896 | |
| 7897 | // Temporary for finding which tokens no longer have visible windows. |
| 7898 | boolean hasVisible; |
| 7899 | |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 7900 | // Set to true when this token is in a pending transaction where it |
| 7901 | // will be shown. |
| 7902 | boolean waitingToShow; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7903 | |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 7904 | // Set to true when this token is in a pending transaction where it |
| 7905 | // will be hidden. |
| 7906 | boolean waitingToHide; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7907 | |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 7908 | // Set to true when this token is in a pending transaction where its |
| 7909 | // windows will be put to the bottom of the list. |
| 7910 | boolean sendingToBottom; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7911 | |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 7912 | // Set to true when this token is in a pending transaction where its |
| 7913 | // windows will be put to the top of the list. |
| 7914 | boolean sendingToTop; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7915 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7916 | WindowToken(IBinder _token, int type, boolean _explicit) { |
| 7917 | token = _token; |
| 7918 | windowType = type; |
| 7919 | explicit = _explicit; |
| 7920 | } |
| 7921 | |
| 7922 | void dump(PrintWriter pw, String prefix) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7923 | pw.print(prefix); pw.print("token="); pw.println(token); |
| 7924 | pw.print(prefix); pw.print("windows="); pw.println(windows); |
| 7925 | pw.print(prefix); pw.print("windowType="); pw.print(windowType); |
| 7926 | pw.print(" hidden="); pw.print(hidden); |
| 7927 | pw.print(" hasVisible="); pw.println(hasVisible); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 7928 | if (waitingToShow || waitingToHide || sendingToBottom || sendingToTop) { |
| 7929 | pw.print(prefix); pw.print("waitingToShow="); pw.print(waitingToShow); |
| 7930 | pw.print(" waitingToHide="); pw.print(waitingToHide); |
| 7931 | pw.print(" sendingToBottom="); pw.print(sendingToBottom); |
| 7932 | pw.print(" sendingToTop="); pw.println(sendingToTop); |
| 7933 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7934 | } |
| 7935 | |
| 7936 | @Override |
| 7937 | public String toString() { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 7938 | if (stringName == null) { |
| 7939 | StringBuilder sb = new StringBuilder(); |
| 7940 | sb.append("WindowToken{"); |
| 7941 | sb.append(Integer.toHexString(System.identityHashCode(this))); |
| 7942 | sb.append(" token="); sb.append(token); sb.append('}'); |
| 7943 | stringName = sb.toString(); |
| 7944 | } |
| 7945 | return stringName; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7946 | } |
| 7947 | }; |
| 7948 | |
| 7949 | class AppWindowToken extends WindowToken { |
| 7950 | // Non-null only for application tokens. |
| 7951 | final IApplicationToken appToken; |
| 7952 | |
| 7953 | // All of the windows and child windows that are included in this |
| 7954 | // application token. Note this list is NOT sorted! |
| 7955 | final ArrayList<WindowState> allAppWindows = new ArrayList<WindowState>(); |
| 7956 | |
| 7957 | int groupId = -1; |
| 7958 | boolean appFullscreen; |
| 7959 | int requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 7960 | |
| 7961 | // The input dispatching timeout for this application token in nanoseconds. |
| 7962 | long inputDispatchingTimeoutNanos; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7963 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7964 | // These are used for determining when all windows associated with |
| 7965 | // an activity have been drawn, so they can be made visible together |
| 7966 | // at the same time. |
| 7967 | int lastTransactionSequence = mTransactionSequence-1; |
| 7968 | int numInterestingWindows; |
| 7969 | int numDrawnWindows; |
| 7970 | boolean inPendingTransaction; |
| 7971 | boolean allDrawn; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7972 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7973 | // Is this token going to be hidden in a little while? If so, it |
| 7974 | // won't be taken into account for setting the screen orientation. |
| 7975 | boolean willBeHidden; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7976 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7977 | // Is this window's surface needed? This is almost like hidden, except |
| 7978 | // it will sometimes be true a little earlier: when the token has |
| 7979 | // been shown, but is still waiting for its app transition to execute |
| 7980 | // before making its windows shown. |
| 7981 | boolean hiddenRequested; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7982 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7983 | // Have we told the window clients to hide themselves? |
| 7984 | boolean clientHidden; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7985 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7986 | // Last visibility state we reported to the app token. |
| 7987 | boolean reportedVisible; |
| 7988 | |
| 7989 | // Set to true when the token has been removed from the window mgr. |
| 7990 | boolean removed; |
| 7991 | |
| 7992 | // Have we been asked to have this token keep the screen frozen? |
| 7993 | boolean freezingScreen; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7994 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7995 | boolean animating; |
| 7996 | Animation animation; |
| 7997 | boolean hasTransformation; |
| 7998 | final Transformation transformation = new Transformation(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7999 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8000 | // Offset to the window of all layers in the token, for use by |
| 8001 | // AppWindowToken animations. |
| 8002 | int animLayerAdjustment; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8003 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8004 | // Information about an application starting window if displayed. |
| 8005 | StartingData startingData; |
| 8006 | WindowState startingWindow; |
| 8007 | View startingView; |
| 8008 | boolean startingDisplayed; |
| 8009 | boolean startingMoved; |
| 8010 | boolean firstWindowDrawn; |
| 8011 | |
| 8012 | AppWindowToken(IApplicationToken _token) { |
| 8013 | super(_token.asBinder(), |
| 8014 | WindowManager.LayoutParams.TYPE_APPLICATION, true); |
| 8015 | appWindowToken = this; |
| 8016 | appToken = _token; |
| 8017 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8018 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8019 | public void setAnimation(Animation anim) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8020 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8021 | TAG, "Setting animation in " + this + ": " + anim); |
| 8022 | animation = anim; |
| 8023 | animating = false; |
| 8024 | anim.restrictDuration(MAX_ANIMATION_DURATION); |
| 8025 | anim.scaleCurrentDuration(mTransitionAnimationScale); |
| 8026 | int zorder = anim.getZAdjustment(); |
| 8027 | int adj = 0; |
| 8028 | if (zorder == Animation.ZORDER_TOP) { |
| 8029 | adj = TYPE_LAYER_OFFSET; |
| 8030 | } else if (zorder == Animation.ZORDER_BOTTOM) { |
| 8031 | adj = -TYPE_LAYER_OFFSET; |
| 8032 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8033 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8034 | if (animLayerAdjustment != adj) { |
| 8035 | animLayerAdjustment = adj; |
| 8036 | updateLayers(); |
| 8037 | } |
| 8038 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8039 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8040 | public void setDummyAnimation() { |
| 8041 | if (animation == null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8042 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8043 | TAG, "Setting dummy animation in " + this); |
| 8044 | animation = sDummyAnimation; |
| 8045 | } |
| 8046 | } |
| 8047 | |
| 8048 | public void clearAnimation() { |
| 8049 | if (animation != null) { |
| 8050 | animation = null; |
| 8051 | animating = true; |
| 8052 | } |
| 8053 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8054 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8055 | void updateLayers() { |
| 8056 | final int N = allAppWindows.size(); |
| 8057 | final int adj = animLayerAdjustment; |
| 8058 | for (int i=0; i<N; i++) { |
| 8059 | WindowState w = allAppWindows.get(i); |
| 8060 | w.mAnimLayer = w.mLayer + adj; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8061 | if (DEBUG_LAYERS) Slog.v(TAG, "Updating layer " + w + ": " |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8062 | + w.mAnimLayer); |
| 8063 | if (w == mInputMethodTarget) { |
| 8064 | setInputMethodAnimLayerAdjustment(adj); |
| 8065 | } |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 8066 | if (w == mWallpaperTarget && mLowerWallpaperTarget == null) { |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 8067 | setWallpaperAnimLayerAdjustmentLocked(adj); |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 8068 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8069 | } |
| 8070 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8071 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8072 | void sendAppVisibilityToClients() { |
| 8073 | final int N = allAppWindows.size(); |
| 8074 | for (int i=0; i<N; i++) { |
| 8075 | WindowState win = allAppWindows.get(i); |
| 8076 | if (win == startingWindow && clientHidden) { |
| 8077 | // Don't hide the starting window. |
| 8078 | continue; |
| 8079 | } |
| 8080 | try { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8081 | if (DEBUG_VISIBILITY) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8082 | "Setting visibility of " + win + ": " + (!clientHidden)); |
| 8083 | win.mClient.dispatchAppVisibility(!clientHidden); |
| 8084 | } catch (RemoteException e) { |
| 8085 | } |
| 8086 | } |
| 8087 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8088 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8089 | void showAllWindowsLocked() { |
| 8090 | final int NW = allAppWindows.size(); |
| 8091 | for (int i=0; i<NW; i++) { |
| 8092 | WindowState w = allAppWindows.get(i); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8093 | if (DEBUG_VISIBILITY) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8094 | "performing show on: " + w); |
| 8095 | w.performShowLocked(); |
| 8096 | } |
| 8097 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8098 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8099 | // This must be called while inside a transaction. |
| 8100 | boolean stepAnimationLocked(long currentTime, int dw, int dh) { |
Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 8101 | if (!mDisplayFrozen && mPolicy.isScreenOn()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8102 | // We will run animations as long as the display isn't frozen. |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8103 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8104 | if (animation == sDummyAnimation) { |
| 8105 | // This guy is going to animate, but not yet. For now count |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 8106 | // it as not animating for purposes of scheduling transactions; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8107 | // when it is really time to animate, this will be set to |
| 8108 | // a real animation and the next call will execute normally. |
| 8109 | return false; |
| 8110 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8111 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8112 | if ((allDrawn || animating || startingDisplayed) && animation != null) { |
| 8113 | if (!animating) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8114 | if (DEBUG_ANIM) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8115 | TAG, "Starting animation in " + this + |
| 8116 | " @ " + currentTime + ": dw=" + dw + " dh=" + dh |
| 8117 | + " scale=" + mTransitionAnimationScale |
| 8118 | + " allDrawn=" + allDrawn + " animating=" + animating); |
| 8119 | animation.initialize(dw, dh, dw, dh); |
| 8120 | animation.setStartTime(currentTime); |
| 8121 | animating = true; |
| 8122 | } |
| 8123 | transformation.clear(); |
| 8124 | final boolean more = animation.getTransformation( |
| 8125 | currentTime, transformation); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8126 | if (DEBUG_ANIM) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8127 | TAG, "Stepped animation in " + this + |
| 8128 | ": more=" + more + ", xform=" + transformation); |
| 8129 | if (more) { |
| 8130 | // we're done! |
| 8131 | hasTransformation = true; |
| 8132 | return true; |
| 8133 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8134 | if (DEBUG_ANIM) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8135 | TAG, "Finished animation in " + this + |
| 8136 | " @ " + currentTime); |
| 8137 | animation = null; |
| 8138 | } |
| 8139 | } else if (animation != null) { |
| 8140 | // If the display is frozen, and there is a pending animation, |
| 8141 | // clear it and make sure we run the cleanup code. |
| 8142 | animating = true; |
| 8143 | animation = null; |
| 8144 | } |
| 8145 | |
| 8146 | hasTransformation = false; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8147 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8148 | if (!animating) { |
| 8149 | return false; |
| 8150 | } |
| 8151 | |
| 8152 | clearAnimation(); |
| 8153 | animating = false; |
| 8154 | if (mInputMethodTarget != null && mInputMethodTarget.mAppToken == this) { |
| 8155 | moveInputMethodWindowsIfNeededLocked(true); |
| 8156 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8157 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8158 | if (DEBUG_ANIM) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8159 | TAG, "Animation done in " + this |
| 8160 | + ": reportedVisible=" + reportedVisible); |
| 8161 | |
| 8162 | transformation.clear(); |
| 8163 | if (animLayerAdjustment != 0) { |
| 8164 | animLayerAdjustment = 0; |
| 8165 | updateLayers(); |
| 8166 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8167 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8168 | final int N = windows.size(); |
| 8169 | for (int i=0; i<N; i++) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 8170 | windows.get(i).finishExit(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8171 | } |
| 8172 | updateReportedVisibilityLocked(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8173 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8174 | return false; |
| 8175 | } |
| 8176 | |
| 8177 | void updateReportedVisibilityLocked() { |
| 8178 | if (appToken == null) { |
| 8179 | return; |
| 8180 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8181 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8182 | int numInteresting = 0; |
| 8183 | int numVisible = 0; |
| 8184 | boolean nowGone = true; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8185 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8186 | 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] | 8187 | final int N = allAppWindows.size(); |
| 8188 | for (int i=0; i<N; i++) { |
| 8189 | WindowState win = allAppWindows.get(i); |
Dianne Hackborn | 6cf67fa | 2009-12-21 16:46:34 -0800 | [diff] [blame] | 8190 | if (win == startingWindow || win.mAppFreezing |
The Android Open Source Project | 727cec0 | 2010-04-08 11:35:37 -0700 | [diff] [blame] | 8191 | || win.mViewVisibility != View.VISIBLE |
Ulf Rosdahl | 3935770 | 2010-09-29 12:34:38 +0200 | [diff] [blame] | 8192 | || win.mAttrs.type == TYPE_APPLICATION_STARTING |
| 8193 | || win.mDestroying) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8194 | continue; |
| 8195 | } |
| 8196 | if (DEBUG_VISIBILITY) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8197 | Slog.v(TAG, "Win " + win + ": isDrawn=" |
Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 8198 | + win.isDrawnLw() |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8199 | + ", isAnimating=" + win.isAnimating()); |
Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 8200 | if (!win.isDrawnLw()) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8201 | Slog.v(TAG, "Not displayed: s=" + win.mSurface |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8202 | + " pv=" + win.mPolicyVisibility |
| 8203 | + " dp=" + win.mDrawPending |
| 8204 | + " cdp=" + win.mCommitDrawPending |
| 8205 | + " ah=" + win.mAttachedHidden |
| 8206 | + " th=" |
| 8207 | + (win.mAppToken != null |
| 8208 | ? win.mAppToken.hiddenRequested : false) |
| 8209 | + " a=" + win.mAnimating); |
| 8210 | } |
| 8211 | } |
| 8212 | numInteresting++; |
Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 8213 | if (win.isDrawnLw()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8214 | if (!win.isAnimating()) { |
| 8215 | numVisible++; |
| 8216 | } |
| 8217 | nowGone = false; |
| 8218 | } else if (win.isAnimating()) { |
| 8219 | nowGone = false; |
| 8220 | } |
| 8221 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8222 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8223 | boolean nowVisible = numInteresting > 0 && numVisible >= numInteresting; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8224 | if (DEBUG_VISIBILITY) Slog.v(TAG, "VIS " + this + ": interesting=" |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8225 | + numInteresting + " visible=" + numVisible); |
| 8226 | if (nowVisible != reportedVisible) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8227 | if (DEBUG_VISIBILITY) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8228 | TAG, "Visibility changed in " + this |
| 8229 | + ": vis=" + nowVisible); |
| 8230 | reportedVisible = nowVisible; |
| 8231 | Message m = mH.obtainMessage( |
| 8232 | H.REPORT_APPLICATION_TOKEN_WINDOWS, |
| 8233 | nowVisible ? 1 : 0, |
| 8234 | nowGone ? 1 : 0, |
| 8235 | this); |
| 8236 | mH.sendMessage(m); |
| 8237 | } |
| 8238 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8239 | |
Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 8240 | WindowState findMainWindow() { |
| 8241 | int j = windows.size(); |
| 8242 | while (j > 0) { |
| 8243 | j--; |
| 8244 | WindowState win = windows.get(j); |
| 8245 | if (win.mAttrs.type == WindowManager.LayoutParams.TYPE_BASE_APPLICATION |
| 8246 | || win.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING) { |
| 8247 | return win; |
| 8248 | } |
| 8249 | } |
| 8250 | return null; |
| 8251 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8252 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8253 | void dump(PrintWriter pw, String prefix) { |
| 8254 | super.dump(pw, prefix); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8255 | if (appToken != null) { |
| 8256 | pw.print(prefix); pw.println("app=true"); |
| 8257 | } |
| 8258 | if (allAppWindows.size() > 0) { |
| 8259 | pw.print(prefix); pw.print("allAppWindows="); pw.println(allAppWindows); |
| 8260 | } |
| 8261 | pw.print(prefix); pw.print("groupId="); pw.print(groupId); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8262 | pw.print(" appFullscreen="); pw.print(appFullscreen); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8263 | pw.print(" requestedOrientation="); pw.println(requestedOrientation); |
| 8264 | pw.print(prefix); pw.print("hiddenRequested="); pw.print(hiddenRequested); |
| 8265 | pw.print(" clientHidden="); pw.print(clientHidden); |
| 8266 | pw.print(" willBeHidden="); pw.print(willBeHidden); |
| 8267 | pw.print(" reportedVisible="); pw.println(reportedVisible); |
| 8268 | if (paused || freezingScreen) { |
| 8269 | pw.print(prefix); pw.print("paused="); pw.print(paused); |
| 8270 | pw.print(" freezingScreen="); pw.println(freezingScreen); |
| 8271 | } |
| 8272 | if (numInterestingWindows != 0 || numDrawnWindows != 0 |
| 8273 | || inPendingTransaction || allDrawn) { |
| 8274 | pw.print(prefix); pw.print("numInterestingWindows="); |
| 8275 | pw.print(numInterestingWindows); |
| 8276 | pw.print(" numDrawnWindows="); pw.print(numDrawnWindows); |
| 8277 | pw.print(" inPendingTransaction="); pw.print(inPendingTransaction); |
| 8278 | pw.print(" allDrawn="); pw.println(allDrawn); |
| 8279 | } |
| 8280 | if (animating || animation != null) { |
| 8281 | pw.print(prefix); pw.print("animating="); pw.print(animating); |
| 8282 | pw.print(" animation="); pw.println(animation); |
| 8283 | } |
| 8284 | if (animLayerAdjustment != 0) { |
| 8285 | pw.print(prefix); pw.print("animLayerAdjustment="); pw.println(animLayerAdjustment); |
| 8286 | } |
| 8287 | if (hasTransformation) { |
| 8288 | pw.print(prefix); pw.print("hasTransformation="); pw.print(hasTransformation); |
| 8289 | pw.print(" transformation="); transformation.printShortString(pw); |
| 8290 | pw.println(); |
| 8291 | } |
| 8292 | if (startingData != null || removed || firstWindowDrawn) { |
| 8293 | pw.print(prefix); pw.print("startingData="); pw.print(startingData); |
| 8294 | pw.print(" removed="); pw.print(removed); |
| 8295 | pw.print(" firstWindowDrawn="); pw.println(firstWindowDrawn); |
| 8296 | } |
| 8297 | if (startingWindow != null || startingView != null |
| 8298 | || startingDisplayed || startingMoved) { |
| 8299 | pw.print(prefix); pw.print("startingWindow="); pw.print(startingWindow); |
| 8300 | pw.print(" startingView="); pw.print(startingView); |
| 8301 | pw.print(" startingDisplayed="); pw.print(startingDisplayed); |
| 8302 | pw.print(" startingMoved"); pw.println(startingMoved); |
| 8303 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8304 | } |
| 8305 | |
| 8306 | @Override |
| 8307 | public String toString() { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8308 | if (stringName == null) { |
| 8309 | StringBuilder sb = new StringBuilder(); |
| 8310 | sb.append("AppWindowToken{"); |
| 8311 | sb.append(Integer.toHexString(System.identityHashCode(this))); |
| 8312 | sb.append(" token="); sb.append(token); sb.append('}'); |
| 8313 | stringName = sb.toString(); |
| 8314 | } |
| 8315 | return stringName; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8316 | } |
| 8317 | } |
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 | // ------------------------------------------------------------- |
| 8320 | // DummyAnimation |
| 8321 | // ------------------------------------------------------------- |
| 8322 | |
| 8323 | // This is an animation that does nothing: it just immediately finishes |
| 8324 | // itself every time it is called. It is used as a stub animation in cases |
| 8325 | // where we want to synchronize multiple things that may be animating. |
| 8326 | static final class DummyAnimation extends Animation { |
| 8327 | public boolean getTransformation(long currentTime, Transformation outTransformation) { |
| 8328 | return false; |
| 8329 | } |
| 8330 | } |
| 8331 | static final Animation sDummyAnimation = new DummyAnimation(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8332 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8333 | // ------------------------------------------------------------- |
| 8334 | // Async Handler |
| 8335 | // ------------------------------------------------------------- |
| 8336 | |
| 8337 | static final class StartingData { |
| 8338 | final String pkg; |
| 8339 | final int theme; |
| 8340 | final CharSequence nonLocalizedLabel; |
| 8341 | final int labelRes; |
| 8342 | final int icon; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8343 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8344 | StartingData(String _pkg, int _theme, CharSequence _nonLocalizedLabel, |
| 8345 | int _labelRes, int _icon) { |
| 8346 | pkg = _pkg; |
| 8347 | theme = _theme; |
| 8348 | nonLocalizedLabel = _nonLocalizedLabel; |
| 8349 | labelRes = _labelRes; |
| 8350 | icon = _icon; |
| 8351 | } |
| 8352 | } |
| 8353 | |
| 8354 | private final class H extends Handler { |
| 8355 | public static final int REPORT_FOCUS_CHANGE = 2; |
| 8356 | public static final int REPORT_LOSING_FOCUS = 3; |
| 8357 | public static final int ANIMATE = 4; |
| 8358 | public static final int ADD_STARTING = 5; |
| 8359 | public static final int REMOVE_STARTING = 6; |
| 8360 | public static final int FINISHED_STARTING = 7; |
| 8361 | public static final int REPORT_APPLICATION_TOKEN_WINDOWS = 8; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8362 | public static final int WINDOW_FREEZE_TIMEOUT = 11; |
| 8363 | public static final int HOLD_SCREEN_CHANGED = 12; |
| 8364 | public static final int APP_TRANSITION_TIMEOUT = 13; |
| 8365 | public static final int PERSIST_ANIMATION_SCALE = 14; |
| 8366 | public static final int FORCE_GC = 15; |
| 8367 | public static final int ENABLE_SCREEN = 16; |
| 8368 | public static final int APP_FREEZE_TIMEOUT = 17; |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 8369 | public static final int SEND_NEW_CONFIGURATION = 18; |
Konstantin Lopyrev | 6e0f65f | 2010-07-14 14:55:33 -0700 | [diff] [blame] | 8370 | public static final int REPORT_WINDOWS_CHANGE = 19; |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 8371 | public static final int DRAG_START_TIMEOUT = 20; |
Chris Tate | d4533f14 | 2010-10-19 15:15:08 -0700 | [diff] [blame^] | 8372 | public static final int DRAG_END_TIMEOUT = 21; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8373 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8374 | private Session mLastReportedHold; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8375 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8376 | public H() { |
| 8377 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8378 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8379 | @Override |
| 8380 | public void handleMessage(Message msg) { |
| 8381 | switch (msg.what) { |
| 8382 | case REPORT_FOCUS_CHANGE: { |
| 8383 | WindowState lastFocus; |
| 8384 | WindowState newFocus; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8385 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8386 | synchronized(mWindowMap) { |
| 8387 | lastFocus = mLastFocus; |
| 8388 | newFocus = mCurrentFocus; |
| 8389 | if (lastFocus == newFocus) { |
| 8390 | // Focus is not changing, so nothing to do. |
| 8391 | return; |
| 8392 | } |
| 8393 | mLastFocus = newFocus; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8394 | //Slog.i(TAG, "Focus moving from " + lastFocus |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8395 | // + " to " + newFocus); |
| 8396 | if (newFocus != null && lastFocus != null |
| 8397 | && !newFocus.isDisplayedLw()) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8398 | //Slog.i(TAG, "Delaying loss of focus..."); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8399 | mLosingFocus.add(lastFocus); |
| 8400 | lastFocus = null; |
| 8401 | } |
| 8402 | } |
| 8403 | |
| 8404 | if (lastFocus != newFocus) { |
| 8405 | //System.out.println("Changing focus from " + lastFocus |
| 8406 | // + " to " + newFocus); |
| 8407 | if (newFocus != null) { |
| 8408 | try { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8409 | //Slog.i(TAG, "Gaining focus: " + newFocus); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8410 | newFocus.mClient.windowFocusChanged(true, mInTouchMode); |
| 8411 | } catch (RemoteException e) { |
| 8412 | // Ignore if process has died. |
| 8413 | } |
Konstantin Lopyrev | 5e7833a | 2010-08-09 17:01:11 -0700 | [diff] [blame] | 8414 | notifyFocusChanged(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8415 | } |
| 8416 | |
| 8417 | if (lastFocus != null) { |
| 8418 | try { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8419 | //Slog.i(TAG, "Losing focus: " + lastFocus); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8420 | lastFocus.mClient.windowFocusChanged(false, mInTouchMode); |
| 8421 | } catch (RemoteException e) { |
| 8422 | // Ignore if process has died. |
| 8423 | } |
| 8424 | } |
| 8425 | } |
| 8426 | } break; |
| 8427 | |
| 8428 | case REPORT_LOSING_FOCUS: { |
| 8429 | ArrayList<WindowState> losers; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8430 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8431 | synchronized(mWindowMap) { |
| 8432 | losers = mLosingFocus; |
| 8433 | mLosingFocus = new ArrayList<WindowState>(); |
| 8434 | } |
| 8435 | |
| 8436 | final int N = losers.size(); |
| 8437 | for (int i=0; i<N; i++) { |
| 8438 | try { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8439 | //Slog.i(TAG, "Losing delayed focus: " + losers.get(i)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8440 | losers.get(i).mClient.windowFocusChanged(false, mInTouchMode); |
| 8441 | } catch (RemoteException e) { |
| 8442 | // Ignore if process has died. |
| 8443 | } |
| 8444 | } |
| 8445 | } break; |
| 8446 | |
| 8447 | case ANIMATE: { |
| 8448 | synchronized(mWindowMap) { |
| 8449 | mAnimationPending = false; |
| 8450 | performLayoutAndPlaceSurfacesLocked(); |
| 8451 | } |
| 8452 | } break; |
| 8453 | |
| 8454 | case ADD_STARTING: { |
| 8455 | final AppWindowToken wtoken = (AppWindowToken)msg.obj; |
| 8456 | final StartingData sd = wtoken.startingData; |
| 8457 | |
| 8458 | if (sd == null) { |
| 8459 | // Animation has been canceled... do nothing. |
| 8460 | return; |
| 8461 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8462 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8463 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Add starting " |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8464 | + wtoken + ": pkg=" + sd.pkg); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8465 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8466 | View view = null; |
| 8467 | try { |
| 8468 | view = mPolicy.addStartingWindow( |
| 8469 | wtoken.token, sd.pkg, |
| 8470 | sd.theme, sd.nonLocalizedLabel, sd.labelRes, |
| 8471 | sd.icon); |
| 8472 | } catch (Exception e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8473 | Slog.w(TAG, "Exception when adding starting window", e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8474 | } |
| 8475 | |
| 8476 | if (view != null) { |
| 8477 | boolean abort = false; |
| 8478 | |
| 8479 | synchronized(mWindowMap) { |
| 8480 | if (wtoken.removed || wtoken.startingData == null) { |
| 8481 | // If the window was successfully added, then |
| 8482 | // we need to remove it. |
| 8483 | if (wtoken.startingWindow != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8484 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8485 | "Aborted starting " + wtoken |
| 8486 | + ": removed=" + wtoken.removed |
| 8487 | + " startingData=" + wtoken.startingData); |
| 8488 | wtoken.startingWindow = null; |
| 8489 | wtoken.startingData = null; |
| 8490 | abort = true; |
| 8491 | } |
| 8492 | } else { |
| 8493 | wtoken.startingView = view; |
| 8494 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8495 | if (DEBUG_STARTING_WINDOW && !abort) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8496 | "Added starting " + wtoken |
| 8497 | + ": startingWindow=" |
| 8498 | + wtoken.startingWindow + " startingView=" |
| 8499 | + wtoken.startingView); |
| 8500 | } |
| 8501 | |
| 8502 | if (abort) { |
| 8503 | try { |
| 8504 | mPolicy.removeStartingWindow(wtoken.token, view); |
| 8505 | } catch (Exception e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8506 | Slog.w(TAG, "Exception when removing starting window", e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8507 | } |
| 8508 | } |
| 8509 | } |
| 8510 | } break; |
| 8511 | |
| 8512 | case REMOVE_STARTING: { |
| 8513 | final AppWindowToken wtoken = (AppWindowToken)msg.obj; |
| 8514 | IBinder token = null; |
| 8515 | View view = null; |
| 8516 | synchronized (mWindowMap) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8517 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Remove starting " |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8518 | + wtoken + ": startingWindow=" |
| 8519 | + wtoken.startingWindow + " startingView=" |
| 8520 | + wtoken.startingView); |
| 8521 | if (wtoken.startingWindow != null) { |
| 8522 | view = wtoken.startingView; |
| 8523 | token = wtoken.token; |
| 8524 | wtoken.startingData = null; |
| 8525 | wtoken.startingView = null; |
| 8526 | wtoken.startingWindow = null; |
| 8527 | } |
| 8528 | } |
| 8529 | if (view != null) { |
| 8530 | try { |
| 8531 | mPolicy.removeStartingWindow(token, view); |
| 8532 | } catch (Exception e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8533 | Slog.w(TAG, "Exception when removing starting window", e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8534 | } |
| 8535 | } |
| 8536 | } break; |
| 8537 | |
| 8538 | case FINISHED_STARTING: { |
| 8539 | IBinder token = null; |
| 8540 | View view = null; |
| 8541 | while (true) { |
| 8542 | synchronized (mWindowMap) { |
| 8543 | final int N = mFinishedStarting.size(); |
| 8544 | if (N <= 0) { |
| 8545 | break; |
| 8546 | } |
| 8547 | AppWindowToken wtoken = mFinishedStarting.remove(N-1); |
| 8548 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8549 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8550 | "Finished starting " + wtoken |
| 8551 | + ": startingWindow=" + wtoken.startingWindow |
| 8552 | + " startingView=" + wtoken.startingView); |
| 8553 | |
| 8554 | if (wtoken.startingWindow == null) { |
| 8555 | continue; |
| 8556 | } |
| 8557 | |
| 8558 | view = wtoken.startingView; |
| 8559 | token = wtoken.token; |
| 8560 | wtoken.startingData = null; |
| 8561 | wtoken.startingView = null; |
| 8562 | wtoken.startingWindow = null; |
| 8563 | } |
| 8564 | |
| 8565 | try { |
| 8566 | mPolicy.removeStartingWindow(token, view); |
| 8567 | } catch (Exception e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8568 | Slog.w(TAG, "Exception when removing starting window", e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8569 | } |
| 8570 | } |
| 8571 | } break; |
| 8572 | |
| 8573 | case REPORT_APPLICATION_TOKEN_WINDOWS: { |
| 8574 | final AppWindowToken wtoken = (AppWindowToken)msg.obj; |
| 8575 | |
| 8576 | boolean nowVisible = msg.arg1 != 0; |
| 8577 | boolean nowGone = msg.arg2 != 0; |
| 8578 | |
| 8579 | try { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8580 | if (DEBUG_VISIBILITY) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8581 | TAG, "Reporting visible in " + wtoken |
| 8582 | + " visible=" + nowVisible |
| 8583 | + " gone=" + nowGone); |
| 8584 | if (nowVisible) { |
| 8585 | wtoken.appToken.windowsVisible(); |
| 8586 | } else { |
| 8587 | wtoken.appToken.windowsGone(); |
| 8588 | } |
| 8589 | } catch (RemoteException ex) { |
| 8590 | } |
| 8591 | } break; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8592 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8593 | case WINDOW_FREEZE_TIMEOUT: { |
| 8594 | synchronized (mWindowMap) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8595 | Slog.w(TAG, "Window freeze timeout expired."); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8596 | int i = mWindows.size(); |
| 8597 | while (i > 0) { |
| 8598 | i--; |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 8599 | WindowState w = mWindows.get(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8600 | if (w.mOrientationChanging) { |
| 8601 | w.mOrientationChanging = false; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8602 | Slog.w(TAG, "Force clearing orientation change: " + w); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8603 | } |
| 8604 | } |
| 8605 | performLayoutAndPlaceSurfacesLocked(); |
| 8606 | } |
| 8607 | break; |
| 8608 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8609 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8610 | case HOLD_SCREEN_CHANGED: { |
| 8611 | Session oldHold; |
| 8612 | Session newHold; |
| 8613 | synchronized (mWindowMap) { |
| 8614 | oldHold = mLastReportedHold; |
| 8615 | newHold = (Session)msg.obj; |
| 8616 | mLastReportedHold = newHold; |
| 8617 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8618 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8619 | if (oldHold != newHold) { |
| 8620 | try { |
| 8621 | if (oldHold != null) { |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 8622 | mBatteryStats.noteStopWakelock(oldHold.mUid, -1, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8623 | "window", |
| 8624 | BatteryStats.WAKE_TYPE_WINDOW); |
| 8625 | } |
| 8626 | if (newHold != null) { |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 8627 | mBatteryStats.noteStartWakelock(newHold.mUid, -1, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8628 | "window", |
| 8629 | BatteryStats.WAKE_TYPE_WINDOW); |
| 8630 | } |
| 8631 | } catch (RemoteException e) { |
| 8632 | } |
| 8633 | } |
| 8634 | break; |
| 8635 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8636 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8637 | case APP_TRANSITION_TIMEOUT: { |
| 8638 | synchronized (mWindowMap) { |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 8639 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8640 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8641 | "*** APP TRANSITION TIMEOUT"); |
| 8642 | mAppTransitionReady = true; |
| 8643 | mAppTransitionTimeout = true; |
| 8644 | performLayoutAndPlaceSurfacesLocked(); |
| 8645 | } |
| 8646 | } |
| 8647 | break; |
| 8648 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8649 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8650 | case PERSIST_ANIMATION_SCALE: { |
| 8651 | Settings.System.putFloat(mContext.getContentResolver(), |
| 8652 | Settings.System.WINDOW_ANIMATION_SCALE, mWindowAnimationScale); |
| 8653 | Settings.System.putFloat(mContext.getContentResolver(), |
| 8654 | Settings.System.TRANSITION_ANIMATION_SCALE, mTransitionAnimationScale); |
| 8655 | break; |
| 8656 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8657 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8658 | case FORCE_GC: { |
| 8659 | synchronized(mWindowMap) { |
| 8660 | if (mAnimationPending) { |
| 8661 | // If we are animating, don't do the gc now but |
| 8662 | // delay a bit so we don't interrupt the animation. |
| 8663 | mH.sendMessageDelayed(mH.obtainMessage(H.FORCE_GC), |
| 8664 | 2000); |
| 8665 | return; |
| 8666 | } |
| 8667 | // If we are currently rotating the display, it will |
| 8668 | // schedule a new message when done. |
| 8669 | if (mDisplayFrozen) { |
| 8670 | return; |
| 8671 | } |
| 8672 | mFreezeGcPending = 0; |
| 8673 | } |
| 8674 | Runtime.getRuntime().gc(); |
| 8675 | break; |
| 8676 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8677 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8678 | case ENABLE_SCREEN: { |
| 8679 | performEnableScreen(); |
| 8680 | break; |
| 8681 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8682 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8683 | case APP_FREEZE_TIMEOUT: { |
| 8684 | synchronized (mWindowMap) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8685 | Slog.w(TAG, "App freeze timeout expired."); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8686 | int i = mAppTokens.size(); |
| 8687 | while (i > 0) { |
| 8688 | i--; |
| 8689 | AppWindowToken tok = mAppTokens.get(i); |
| 8690 | if (tok.freezingScreen) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8691 | Slog.w(TAG, "Force clearing freeze: " + tok); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8692 | unsetAppFreezingScreenLocked(tok, true, true); |
| 8693 | } |
| 8694 | } |
| 8695 | } |
| 8696 | break; |
| 8697 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8698 | |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 8699 | case SEND_NEW_CONFIGURATION: { |
| 8700 | removeMessages(SEND_NEW_CONFIGURATION); |
| 8701 | sendNewConfiguration(); |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 8702 | break; |
| 8703 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8704 | |
Konstantin Lopyrev | 6e0f65f | 2010-07-14 14:55:33 -0700 | [diff] [blame] | 8705 | case REPORT_WINDOWS_CHANGE: { |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 8706 | if (mWindowsChanged) { |
| 8707 | synchronized (mWindowMap) { |
| 8708 | mWindowsChanged = false; |
| 8709 | } |
| 8710 | notifyWindowsChanged(); |
| 8711 | } |
| 8712 | break; |
| 8713 | } |
| 8714 | |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 8715 | case DRAG_START_TIMEOUT: { |
| 8716 | IBinder win = (IBinder)msg.obj; |
| 8717 | if (DEBUG_DRAG) { |
| 8718 | Slog.w(TAG, "Timeout starting drag by win " + win); |
| 8719 | } |
| 8720 | synchronized (mWindowMap) { |
| 8721 | // !!! TODO: ANR the app that has failed to start the drag in time |
| 8722 | if (mDragState != null) { |
Chris Tate | d4533f14 | 2010-10-19 15:15:08 -0700 | [diff] [blame^] | 8723 | mDragState.unregister(); |
| 8724 | mInputMonitor.updateInputWindowsLw(); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 8725 | mDragState.reset(); |
| 8726 | mDragState = null; |
| 8727 | } |
| 8728 | } |
Chris Tate | d4533f14 | 2010-10-19 15:15:08 -0700 | [diff] [blame^] | 8729 | break; |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 8730 | } |
| 8731 | |
Chris Tate | d4533f14 | 2010-10-19 15:15:08 -0700 | [diff] [blame^] | 8732 | case DRAG_END_TIMEOUT: { |
| 8733 | IBinder win = (IBinder)msg.obj; |
| 8734 | if (DEBUG_DRAG) { |
| 8735 | Slog.w(TAG, "Timeout ending drag to win " + win); |
| 8736 | } |
| 8737 | synchronized (mWindowMap) { |
| 8738 | // !!! TODO: ANR the drag-receiving app |
| 8739 | mDragState.mDragResult = false; |
| 8740 | mDragState.endDragLw(); |
| 8741 | } |
| 8742 | break; |
| 8743 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8744 | } |
| 8745 | } |
| 8746 | } |
| 8747 | |
| 8748 | // ------------------------------------------------------------- |
| 8749 | // IWindowManager API |
| 8750 | // ------------------------------------------------------------- |
| 8751 | |
| 8752 | public IWindowSession openSession(IInputMethodClient client, |
| 8753 | IInputContext inputContext) { |
| 8754 | if (client == null) throw new IllegalArgumentException("null client"); |
| 8755 | if (inputContext == null) throw new IllegalArgumentException("null inputContext"); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 8756 | Session session = new Session(client, inputContext); |
| 8757 | return session; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8758 | } |
| 8759 | |
| 8760 | public boolean inputMethodClientHasFocus(IInputMethodClient client) { |
| 8761 | synchronized (mWindowMap) { |
| 8762 | // The focus for the client is the window immediately below |
| 8763 | // where we would place the input method window. |
| 8764 | int idx = findDesiredInputMethodWindowIndexLocked(false); |
| 8765 | WindowState imFocus; |
| 8766 | if (idx > 0) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 8767 | imFocus = mWindows.get(idx-1); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8768 | if (imFocus != null) { |
| 8769 | if (imFocus.mSession.mClient != null && |
| 8770 | imFocus.mSession.mClient.asBinder() == client.asBinder()) { |
| 8771 | return true; |
| 8772 | } |
| 8773 | } |
| 8774 | } |
| 8775 | } |
| 8776 | return false; |
| 8777 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8778 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8779 | // ------------------------------------------------------------- |
| 8780 | // Internals |
| 8781 | // ------------------------------------------------------------- |
| 8782 | |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 8783 | final WindowState windowForClientLocked(Session session, IWindow client, |
| 8784 | boolean throwOnError) { |
| 8785 | return windowForClientLocked(session, client.asBinder(), throwOnError); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8786 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8787 | |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 8788 | final WindowState windowForClientLocked(Session session, IBinder client, |
| 8789 | boolean throwOnError) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8790 | WindowState win = mWindowMap.get(client); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8791 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8792 | TAG, "Looking up client " + client + ": " + win); |
| 8793 | if (win == null) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 8794 | RuntimeException ex = new IllegalArgumentException( |
| 8795 | "Requested window " + client + " does not exist"); |
| 8796 | if (throwOnError) { |
| 8797 | throw ex; |
| 8798 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8799 | Slog.w(TAG, "Failed looking up window", ex); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8800 | return null; |
| 8801 | } |
| 8802 | if (session != null && win.mSession != session) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 8803 | RuntimeException ex = new IllegalArgumentException( |
| 8804 | "Requested window " + client + " is in session " + |
| 8805 | win.mSession + ", not " + session); |
| 8806 | if (throwOnError) { |
| 8807 | throw ex; |
| 8808 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8809 | Slog.w(TAG, "Failed looking up window", ex); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8810 | return null; |
| 8811 | } |
| 8812 | |
| 8813 | return win; |
| 8814 | } |
| 8815 | |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8816 | final void rebuildAppWindowListLocked() { |
| 8817 | int NW = mWindows.size(); |
| 8818 | int i; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8819 | int lastWallpaper = -1; |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 8820 | int numRemoved = 0; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8821 | |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8822 | // First remove all existing app windows. |
| 8823 | i=0; |
| 8824 | while (i < NW) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 8825 | WindowState w = mWindows.get(i); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8826 | if (w.mAppToken != null) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 8827 | WindowState win = mWindows.remove(i); |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 8828 | mWindowsChanged = true; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8829 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, |
Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 8830 | "Rebuild removing window: " + win); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8831 | NW--; |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 8832 | numRemoved++; |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8833 | continue; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8834 | } else if (w.mAttrs.type == WindowManager.LayoutParams.TYPE_WALLPAPER |
| 8835 | && lastWallpaper == i-1) { |
| 8836 | lastWallpaper = i; |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8837 | } |
| 8838 | i++; |
| 8839 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8840 | |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8841 | // The wallpaper window(s) typically live at the bottom of the stack, |
| 8842 | // so skip them before adding app tokens. |
| 8843 | lastWallpaper++; |
| 8844 | i = lastWallpaper; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8845 | |
Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 8846 | // First add all of the exiting app tokens... these are no longer |
| 8847 | // in the main app list, but still have windows shown. We put them |
| 8848 | // in the back because now that the animation is over we no longer |
| 8849 | // will care about them. |
| 8850 | int NT = mExitingAppTokens.size(); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8851 | for (int j=0; j<NT; j++) { |
Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 8852 | i = reAddAppWindowsLocked(i, mExitingAppTokens.get(j)); |
| 8853 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8854 | |
Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 8855 | // And add in the still active app tokens in Z order. |
| 8856 | NT = mAppTokens.size(); |
| 8857 | for (int j=0; j<NT; j++) { |
| 8858 | i = reAddAppWindowsLocked(i, mAppTokens.get(j)); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8859 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8860 | |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8861 | i -= lastWallpaper; |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 8862 | if (i != numRemoved) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8863 | Slog.w(TAG, "Rebuild removed " + numRemoved |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 8864 | + " windows but added " + i); |
| 8865 | } |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8866 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8867 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8868 | private final void assignLayersLocked() { |
| 8869 | int N = mWindows.size(); |
| 8870 | int curBaseLayer = 0; |
| 8871 | int curLayer = 0; |
| 8872 | int i; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8873 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8874 | for (i=0; i<N; i++) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 8875 | WindowState w = mWindows.get(i); |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 8876 | if (w.mBaseLayer == curBaseLayer || w.mIsImWindow |
| 8877 | || (i > 0 && w.mIsWallpaper)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8878 | curLayer += WINDOW_LAYER_MULTIPLIER; |
| 8879 | w.mLayer = curLayer; |
| 8880 | } else { |
| 8881 | curBaseLayer = curLayer = w.mBaseLayer; |
| 8882 | w.mLayer = curLayer; |
| 8883 | } |
| 8884 | if (w.mTargetAppToken != null) { |
| 8885 | w.mAnimLayer = w.mLayer + w.mTargetAppToken.animLayerAdjustment; |
| 8886 | } else if (w.mAppToken != null) { |
| 8887 | w.mAnimLayer = w.mLayer + w.mAppToken.animLayerAdjustment; |
| 8888 | } else { |
| 8889 | w.mAnimLayer = w.mLayer; |
| 8890 | } |
| 8891 | if (w.mIsImWindow) { |
| 8892 | w.mAnimLayer += mInputMethodAnimLayerAdjustment; |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 8893 | } else if (w.mIsWallpaper) { |
| 8894 | w.mAnimLayer += mWallpaperAnimLayerAdjustment; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8895 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8896 | if (DEBUG_LAYERS) Slog.v(TAG, "Assign layer " + w + ": " |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8897 | + w.mAnimLayer); |
| 8898 | //System.out.println( |
| 8899 | // "Assigned layer " + curLayer + " to " + w.mClient.asBinder()); |
| 8900 | } |
| 8901 | } |
| 8902 | |
| 8903 | private boolean mInLayout = false; |
| 8904 | private final void performLayoutAndPlaceSurfacesLocked() { |
| 8905 | if (mInLayout) { |
Dave Bort | cfe6524 | 2009-04-09 14:51:04 -0700 | [diff] [blame] | 8906 | if (DEBUG) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8907 | throw new RuntimeException("Recursive call!"); |
| 8908 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8909 | Slog.w(TAG, "performLayoutAndPlaceSurfacesLocked called while in layout"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8910 | return; |
| 8911 | } |
| 8912 | |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 8913 | if (mWaitingForConfig) { |
| 8914 | // Our configuration has changed (most likely rotation), but we |
| 8915 | // don't yet have the complete configuration to report to |
| 8916 | // applications. Don't do any window layout until we have it. |
| 8917 | return; |
| 8918 | } |
| 8919 | |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 8920 | if (mDisplay == null) { |
| 8921 | // Not yet initialized, nothing to do. |
| 8922 | return; |
| 8923 | } |
| 8924 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8925 | boolean recoveringMemory = false; |
| 8926 | if (mForceRemoves != null) { |
| 8927 | recoveringMemory = true; |
| 8928 | // Wait a little it for things to settle down, and off we go. |
| 8929 | for (int i=0; i<mForceRemoves.size(); i++) { |
| 8930 | WindowState ws = mForceRemoves.get(i); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8931 | Slog.i(TAG, "Force removing: " + ws); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8932 | removeWindowInnerLocked(ws.mSession, ws); |
| 8933 | } |
| 8934 | mForceRemoves = null; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8935 | 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] | 8936 | Object tmp = new Object(); |
| 8937 | synchronized (tmp) { |
| 8938 | try { |
| 8939 | tmp.wait(250); |
| 8940 | } catch (InterruptedException e) { |
| 8941 | } |
| 8942 | } |
| 8943 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8944 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8945 | mInLayout = true; |
| 8946 | try { |
| 8947 | performLayoutAndPlaceSurfacesLockedInner(recoveringMemory); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8948 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8949 | int i = mPendingRemove.size()-1; |
| 8950 | if (i >= 0) { |
| 8951 | while (i >= 0) { |
| 8952 | WindowState w = mPendingRemove.get(i); |
| 8953 | removeWindowInnerLocked(w.mSession, w); |
| 8954 | i--; |
| 8955 | } |
| 8956 | mPendingRemove.clear(); |
| 8957 | |
| 8958 | mInLayout = false; |
| 8959 | assignLayersLocked(); |
| 8960 | mLayoutNeeded = true; |
| 8961 | performLayoutAndPlaceSurfacesLocked(); |
| 8962 | |
| 8963 | } else { |
| 8964 | mInLayout = false; |
| 8965 | if (mLayoutNeeded) { |
| 8966 | requestAnimationLocked(0); |
| 8967 | } |
| 8968 | } |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 8969 | if (mWindowsChanged && !mWindowChangeListeners.isEmpty()) { |
Konstantin Lopyrev | 6e0f65f | 2010-07-14 14:55:33 -0700 | [diff] [blame] | 8970 | mH.removeMessages(H.REPORT_WINDOWS_CHANGE); |
| 8971 | mH.sendMessage(mH.obtainMessage(H.REPORT_WINDOWS_CHANGE)); |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 8972 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8973 | } catch (RuntimeException e) { |
| 8974 | mInLayout = false; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8975 | 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] | 8976 | } |
| 8977 | } |
| 8978 | |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 8979 | private final int performLayoutLockedInner() { |
| 8980 | if (!mLayoutNeeded) { |
| 8981 | return 0; |
| 8982 | } |
| 8983 | |
| 8984 | mLayoutNeeded = false; |
| 8985 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8986 | final int dw = mDisplay.getWidth(); |
| 8987 | final int dh = mDisplay.getHeight(); |
| 8988 | |
| 8989 | final int N = mWindows.size(); |
| 8990 | int i; |
| 8991 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8992 | if (DEBUG_LAYOUT) Slog.v(TAG, "performLayout: needed=" |
Dianne Hackborn | 9b52a21 | 2009-12-11 14:51:35 -0800 | [diff] [blame] | 8993 | + mLayoutNeeded + " dw=" + dw + " dh=" + dh); |
| 8994 | |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 8995 | mPolicy.beginLayoutLw(dw, dh); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8996 | |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 8997 | int seq = mLayoutSeq+1; |
| 8998 | if (seq < 0) seq = 0; |
| 8999 | mLayoutSeq = seq; |
| 9000 | |
| 9001 | // First perform layout of any root windows (not attached |
| 9002 | // to another window). |
| 9003 | int topAttached = -1; |
| 9004 | for (i = N-1; i >= 0; i--) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 9005 | WindowState win = mWindows.get(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9006 | |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9007 | // Don't do layout of a window if it is not visible, or |
| 9008 | // soon won't be visible, to avoid wasting time and funky |
| 9009 | // changes while a window is animating away. |
| 9010 | final AppWindowToken atoken = win.mAppToken; |
| 9011 | final boolean gone = win.mViewVisibility == View.GONE |
| 9012 | || !win.mRelayoutCalled |
| 9013 | || win.mRootToken.hidden |
| 9014 | || (atoken != null && atoken.hiddenRequested) |
| 9015 | || win.mAttachedHidden |
| 9016 | || win.mExiting || win.mDestroying; |
| 9017 | |
| 9018 | if (!win.mLayoutAttached) { |
| 9019 | if (DEBUG_LAYOUT) Slog.v(TAG, "First pass " + win |
| 9020 | + ": gone=" + gone + " mHaveFrame=" + win.mHaveFrame |
| 9021 | + " mLayoutAttached=" + win.mLayoutAttached); |
| 9022 | if (DEBUG_LAYOUT && gone) Slog.v(TAG, " (mViewVisibility=" |
| 9023 | + win.mViewVisibility + " mRelayoutCalled=" |
| 9024 | + win.mRelayoutCalled + " hidden=" |
| 9025 | + win.mRootToken.hidden + " hiddenRequested=" |
| 9026 | + (atoken != null && atoken.hiddenRequested) |
| 9027 | + " mAttachedHidden=" + win.mAttachedHidden); |
| 9028 | } |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 9029 | |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9030 | // If this view is GONE, then skip it -- keep the current |
| 9031 | // frame, and let the caller know so they can ignore it |
| 9032 | // if they want. (We do the normal layout for INVISIBLE |
| 9033 | // windows, since that means "perform layout as normal, |
| 9034 | // just don't display"). |
| 9035 | if (!gone || !win.mHaveFrame) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 9036 | if (!win.mLayoutAttached) { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9037 | mPolicy.layoutWindowLw(win, win.mAttrs, null); |
| 9038 | win.mLayoutSeq = seq; |
| 9039 | if (DEBUG_LAYOUT) Slog.v(TAG, "-> mFrame=" |
| 9040 | + win.mFrame + " mContainingFrame=" |
| 9041 | + win.mContainingFrame + " mDisplayFrame=" |
| 9042 | + win.mDisplayFrame); |
| 9043 | } else { |
| 9044 | if (topAttached < 0) topAttached = i; |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 9045 | } |
Dianne Hackborn | 958b9ad | 2009-03-31 18:00:36 -0700 | [diff] [blame] | 9046 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9047 | } |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9048 | |
| 9049 | // Now perform layout of attached windows, which usually |
| 9050 | // depend on the position of the window they are attached to. |
| 9051 | // XXX does not deal with windows that are attached to windows |
| 9052 | // that are themselves attached. |
| 9053 | for (i = topAttached; i >= 0; i--) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 9054 | WindowState win = mWindows.get(i); |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9055 | |
| 9056 | // If this view is GONE, then skip it -- keep the current |
| 9057 | // frame, and let the caller know so they can ignore it |
| 9058 | // if they want. (We do the normal layout for INVISIBLE |
| 9059 | // windows, since that means "perform layout as normal, |
| 9060 | // just don't display"). |
| 9061 | if (win.mLayoutAttached) { |
| 9062 | if (DEBUG_LAYOUT) Slog.v(TAG, "Second pass " + win |
| 9063 | + " mHaveFrame=" + win.mHaveFrame |
| 9064 | + " mViewVisibility=" + win.mViewVisibility |
| 9065 | + " mRelayoutCalled=" + win.mRelayoutCalled); |
| 9066 | if ((win.mViewVisibility != View.GONE && win.mRelayoutCalled) |
| 9067 | || !win.mHaveFrame) { |
| 9068 | mPolicy.layoutWindowLw(win, win.mAttrs, win.mAttachedWindow); |
| 9069 | win.mLayoutSeq = seq; |
| 9070 | if (DEBUG_LAYOUT) Slog.v(TAG, "-> mFrame=" |
| 9071 | + win.mFrame + " mContainingFrame=" |
| 9072 | + win.mContainingFrame + " mDisplayFrame=" |
| 9073 | + win.mDisplayFrame); |
| 9074 | } |
| 9075 | } |
| 9076 | } |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 9077 | |
| 9078 | // Window frames may have changed. Tell the input dispatcher about it. |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 9079 | mInputMonitor.updateInputWindowsLw(); |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9080 | |
| 9081 | return mPolicy.finishLayoutLw(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9082 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9083 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9084 | private final void performLayoutAndPlaceSurfacesLockedInner( |
| 9085 | boolean recoveringMemory) { |
Joe Onorato | 34bcebc | 2010-07-07 18:05:01 -0400 | [diff] [blame] | 9086 | if (mDisplay == null) { |
| 9087 | Slog.i(TAG, "skipping performLayoutAndPlaceSurfacesLockedInner with no mDisplay"); |
| 9088 | return; |
| 9089 | } |
| 9090 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9091 | final long currentTime = SystemClock.uptimeMillis(); |
| 9092 | final int dw = mDisplay.getWidth(); |
| 9093 | final int dh = mDisplay.getHeight(); |
| 9094 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9095 | int i; |
| 9096 | |
Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 9097 | if (mFocusMayChange) { |
| 9098 | mFocusMayChange = false; |
| 9099 | updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES); |
| 9100 | } |
| 9101 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9102 | // Initialize state of exiting tokens. |
| 9103 | for (i=mExitingTokens.size()-1; i>=0; i--) { |
| 9104 | mExitingTokens.get(i).hasVisible = false; |
| 9105 | } |
| 9106 | |
| 9107 | // Initialize state of exiting applications. |
| 9108 | for (i=mExitingAppTokens.size()-1; i>=0; i--) { |
| 9109 | mExitingAppTokens.get(i).hasVisible = false; |
| 9110 | } |
| 9111 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9112 | boolean orientationChangeComplete = true; |
| 9113 | Session holdScreen = null; |
| 9114 | float screenBrightness = -1; |
Mike Lockwood | fb73f79 | 2009-11-20 11:31:18 -0500 | [diff] [blame] | 9115 | float buttonBrightness = -1; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9116 | boolean focusDisplayed = false; |
| 9117 | boolean animating = false; |
Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 9118 | boolean createWatermark = false; |
| 9119 | |
| 9120 | if (mFxSession == null) { |
| 9121 | mFxSession = new SurfaceSession(); |
| 9122 | createWatermark = true; |
| 9123 | } |
| 9124 | |
| 9125 | if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9126 | |
| 9127 | Surface.openTransaction(); |
Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 9128 | |
| 9129 | if (createWatermark) { |
| 9130 | createWatermark(); |
| 9131 | } |
| 9132 | if (mWatermark != null) { |
| 9133 | mWatermark.positionSurface(dw, dh); |
| 9134 | } |
| 9135 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9136 | try { |
Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 9137 | boolean wallpaperForceHidingChanged = false; |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9138 | int repeats = 0; |
| 9139 | int changes = 0; |
| 9140 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9141 | do { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9142 | repeats++; |
| 9143 | if (repeats > 6) { |
| 9144 | Slog.w(TAG, "Animation repeat aborted after too many iterations"); |
| 9145 | mLayoutNeeded = false; |
| 9146 | break; |
| 9147 | } |
| 9148 | |
| 9149 | if ((changes&(WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER |
| 9150 | | WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG |
| 9151 | | WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT)) != 0) { |
| 9152 | if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER) != 0) { |
| 9153 | if ((adjustWallpaperWindowsLocked()&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) { |
| 9154 | assignLayersLocked(); |
| 9155 | mLayoutNeeded = true; |
| 9156 | } |
| 9157 | } |
| 9158 | if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG) != 0) { |
| 9159 | if (DEBUG_LAYOUT) Slog.v(TAG, "Computing new config from layout"); |
| 9160 | if (updateOrientationFromAppTokensLocked()) { |
| 9161 | mLayoutNeeded = true; |
| 9162 | mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION); |
| 9163 | } |
| 9164 | } |
| 9165 | if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT) != 0) { |
| 9166 | mLayoutNeeded = true; |
| 9167 | } |
| 9168 | } |
| 9169 | |
| 9170 | // FIRST LOOP: Perform a layout, if needed. |
| 9171 | if (repeats < 4) { |
| 9172 | changes = performLayoutLockedInner(); |
| 9173 | if (changes != 0) { |
| 9174 | continue; |
| 9175 | } |
| 9176 | } else { |
| 9177 | Slog.w(TAG, "Layout repeat skipped after too many iterations"); |
| 9178 | changes = 0; |
| 9179 | } |
| 9180 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9181 | final int transactionSequence = ++mTransactionSequence; |
| 9182 | |
| 9183 | // Update animations of all applications, including those |
| 9184 | // associated with exiting/removed apps |
| 9185 | boolean tokensAnimating = false; |
| 9186 | final int NAT = mAppTokens.size(); |
| 9187 | for (i=0; i<NAT; i++) { |
| 9188 | if (mAppTokens.get(i).stepAnimationLocked(currentTime, dw, dh)) { |
| 9189 | tokensAnimating = true; |
| 9190 | } |
| 9191 | } |
| 9192 | final int NEAT = mExitingAppTokens.size(); |
| 9193 | for (i=0; i<NEAT; i++) { |
| 9194 | if (mExitingAppTokens.get(i).stepAnimationLocked(currentTime, dw, dh)) { |
| 9195 | tokensAnimating = true; |
| 9196 | } |
| 9197 | } |
| 9198 | |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9199 | // SECOND LOOP: Execute animations and update visibility of windows. |
| 9200 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9201 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "*** ANIM STEP: seq=" |
Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 9202 | + transactionSequence + " tokensAnimating=" |
| 9203 | + tokensAnimating); |
| 9204 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9205 | animating = tokensAnimating; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9206 | |
| 9207 | boolean tokenMayBeDrawn = false; |
Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 9208 | boolean wallpaperMayChange = false; |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9209 | boolean forceHiding = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9210 | |
| 9211 | mPolicy.beginAnimationLw(dw, dh); |
| 9212 | |
Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 9213 | final int N = mWindows.size(); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9214 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9215 | for (i=N-1; i>=0; i--) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 9216 | WindowState w = mWindows.get(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9217 | |
| 9218 | final WindowManager.LayoutParams attrs = w.mAttrs; |
| 9219 | |
| 9220 | if (w.mSurface != null) { |
| 9221 | // Execute animation. |
Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 9222 | if (w.commitFinishDrawingLocked(currentTime)) { |
| 9223 | if ((w.mAttrs.flags |
| 9224 | & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER) != 0) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9225 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 9226 | "First draw done in potential wallpaper target " + w); |
Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 9227 | wallpaperMayChange = true; |
| 9228 | } |
| 9229 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9230 | |
Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 9231 | boolean wasAnimating = w.mAnimating; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9232 | if (w.stepAnimationLocked(currentTime, dw, dh)) { |
| 9233 | animating = true; |
| 9234 | //w.dump(" "); |
| 9235 | } |
Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 9236 | if (wasAnimating && !w.mAnimating && mWallpaperTarget == w) { |
| 9237 | wallpaperMayChange = true; |
| 9238 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9239 | |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9240 | if (mPolicy.doesForceHide(w, attrs)) { |
| 9241 | if (!wasAnimating && animating) { |
Dianne Hackborn | 20cb56e | 2010-03-04 00:58:29 -0800 | [diff] [blame] | 9242 | if (DEBUG_VISIBILITY) Slog.v(TAG, |
| 9243 | "Animation done that could impact force hide: " |
| 9244 | + w); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9245 | wallpaperForceHidingChanged = true; |
Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 9246 | mFocusMayChange = true; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9247 | } else if (w.isReadyForDisplay() && w.mAnimation == null) { |
| 9248 | forceHiding = true; |
| 9249 | } |
| 9250 | } else if (mPolicy.canBeForceHidden(w, attrs)) { |
| 9251 | boolean changed; |
| 9252 | if (forceHiding) { |
| 9253 | changed = w.hideLw(false, false); |
Dianne Hackborn | 20cb56e | 2010-03-04 00:58:29 -0800 | [diff] [blame] | 9254 | if (DEBUG_VISIBILITY && changed) Slog.v(TAG, |
| 9255 | "Now policy hidden: " + w); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9256 | } else { |
| 9257 | changed = w.showLw(false, false); |
Dianne Hackborn | 20cb56e | 2010-03-04 00:58:29 -0800 | [diff] [blame] | 9258 | if (DEBUG_VISIBILITY && changed) Slog.v(TAG, |
| 9259 | "Now policy shown: " + w); |
| 9260 | if (changed) { |
| 9261 | if (wallpaperForceHidingChanged |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9262 | && w.isVisibleNow() /*w.isReadyForDisplay()*/) { |
Dianne Hackborn | 20cb56e | 2010-03-04 00:58:29 -0800 | [diff] [blame] | 9263 | // Assume we will need to animate. If |
| 9264 | // we don't (because the wallpaper will |
| 9265 | // stay with the lock screen), then we will |
| 9266 | // clean up later. |
| 9267 | Animation a = mPolicy.createForceHideEnterAnimation(); |
| 9268 | if (a != null) { |
| 9269 | w.setAnimation(a); |
| 9270 | } |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9271 | } |
Dianne Hackborn | 20cb56e | 2010-03-04 00:58:29 -0800 | [diff] [blame] | 9272 | if (mCurrentFocus == null || |
| 9273 | mCurrentFocus.mLayer < w.mLayer) { |
| 9274 | // We are showing on to of the current |
| 9275 | // focus, so re-evaluate focus to make |
| 9276 | // sure it is correct. |
| 9277 | mFocusMayChange = true; |
| 9278 | } |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9279 | } |
| 9280 | } |
| 9281 | if (changed && (attrs.flags |
| 9282 | & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER) != 0) { |
| 9283 | wallpaperMayChange = true; |
| 9284 | } |
| 9285 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9286 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9287 | mPolicy.animatingWindowLw(w, attrs); |
| 9288 | } |
| 9289 | |
| 9290 | final AppWindowToken atoken = w.mAppToken; |
| 9291 | if (atoken != null && (!atoken.allDrawn || atoken.freezingScreen)) { |
| 9292 | if (atoken.lastTransactionSequence != transactionSequence) { |
| 9293 | atoken.lastTransactionSequence = transactionSequence; |
| 9294 | atoken.numInterestingWindows = atoken.numDrawnWindows = 0; |
| 9295 | atoken.startingDisplayed = false; |
| 9296 | } |
| 9297 | if ((w.isOnScreen() || w.mAttrs.type |
| 9298 | == WindowManager.LayoutParams.TYPE_BASE_APPLICATION) |
| 9299 | && !w.mExiting && !w.mDestroying) { |
| 9300 | if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9301 | Slog.v(TAG, "Eval win " + w + ": isDrawn=" |
Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 9302 | + w.isDrawnLw() |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9303 | + ", isAnimating=" + w.isAnimating()); |
Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 9304 | if (!w.isDrawnLw()) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9305 | Slog.v(TAG, "Not displayed: s=" + w.mSurface |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9306 | + " pv=" + w.mPolicyVisibility |
| 9307 | + " dp=" + w.mDrawPending |
| 9308 | + " cdp=" + w.mCommitDrawPending |
| 9309 | + " ah=" + w.mAttachedHidden |
| 9310 | + " th=" + atoken.hiddenRequested |
| 9311 | + " a=" + w.mAnimating); |
| 9312 | } |
| 9313 | } |
| 9314 | if (w != atoken.startingWindow) { |
| 9315 | if (!atoken.freezingScreen || !w.mAppFreezing) { |
| 9316 | atoken.numInterestingWindows++; |
Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 9317 | if (w.isDrawnLw()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9318 | atoken.numDrawnWindows++; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9319 | if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9320 | "tokenMayBeDrawn: " + atoken |
| 9321 | + " freezingScreen=" + atoken.freezingScreen |
| 9322 | + " mAppFreezing=" + w.mAppFreezing); |
| 9323 | tokenMayBeDrawn = true; |
| 9324 | } |
| 9325 | } |
Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 9326 | } else if (w.isDrawnLw()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9327 | atoken.startingDisplayed = true; |
| 9328 | } |
| 9329 | } |
| 9330 | } else if (w.mReadyToShow) { |
| 9331 | w.performShowLocked(); |
| 9332 | } |
| 9333 | } |
| 9334 | |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9335 | changes |= mPolicy.finishAnimationLw(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9336 | |
| 9337 | if (tokenMayBeDrawn) { |
| 9338 | // See if any windows have been drawn, so they (and others |
| 9339 | // associated with them) can now be shown. |
| 9340 | final int NT = mTokenList.size(); |
| 9341 | for (i=0; i<NT; i++) { |
| 9342 | AppWindowToken wtoken = mTokenList.get(i).appWindowToken; |
| 9343 | if (wtoken == null) { |
| 9344 | continue; |
| 9345 | } |
| 9346 | if (wtoken.freezingScreen) { |
| 9347 | int numInteresting = wtoken.numInterestingWindows; |
| 9348 | if (numInteresting > 0 && wtoken.numDrawnWindows >= numInteresting) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9349 | if (DEBUG_VISIBILITY) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9350 | "allDrawn: " + wtoken |
| 9351 | + " interesting=" + numInteresting |
| 9352 | + " drawn=" + wtoken.numDrawnWindows); |
| 9353 | wtoken.showAllWindowsLocked(); |
| 9354 | unsetAppFreezingScreenLocked(wtoken, false, true); |
| 9355 | orientationChangeComplete = true; |
| 9356 | } |
| 9357 | } else if (!wtoken.allDrawn) { |
| 9358 | int numInteresting = wtoken.numInterestingWindows; |
| 9359 | if (numInteresting > 0 && wtoken.numDrawnWindows >= numInteresting) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9360 | if (DEBUG_VISIBILITY) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9361 | "allDrawn: " + wtoken |
| 9362 | + " interesting=" + numInteresting |
| 9363 | + " drawn=" + wtoken.numDrawnWindows); |
| 9364 | wtoken.allDrawn = true; |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9365 | changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9366 | |
| 9367 | // We can now show all of the drawn windows! |
| 9368 | if (!mOpeningApps.contains(wtoken)) { |
| 9369 | wtoken.showAllWindowsLocked(); |
| 9370 | } |
| 9371 | } |
| 9372 | } |
| 9373 | } |
| 9374 | } |
| 9375 | |
| 9376 | // If we are ready to perform an app transition, check through |
| 9377 | // all of the app tokens to be shown and see if they are ready |
| 9378 | // to go. |
| 9379 | if (mAppTransitionReady) { |
| 9380 | int NN = mOpeningApps.size(); |
| 9381 | boolean goodToGo = true; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9382 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9383 | "Checking " + NN + " opening apps (frozen=" |
| 9384 | + mDisplayFrozen + " timeout=" |
| 9385 | + mAppTransitionTimeout + ")..."); |
| 9386 | if (!mDisplayFrozen && !mAppTransitionTimeout) { |
| 9387 | // If the display isn't frozen, wait to do anything until |
| 9388 | // all of the apps are ready. Otherwise just go because |
| 9389 | // we'll unfreeze the display when everyone is ready. |
| 9390 | for (i=0; i<NN && goodToGo; i++) { |
| 9391 | AppWindowToken wtoken = mOpeningApps.get(i); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9392 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9393 | "Check opening app" + wtoken + ": allDrawn=" |
| 9394 | + wtoken.allDrawn + " startingDisplayed=" |
| 9395 | + wtoken.startingDisplayed); |
| 9396 | if (!wtoken.allDrawn && !wtoken.startingDisplayed |
| 9397 | && !wtoken.startingMoved) { |
| 9398 | goodToGo = false; |
| 9399 | } |
| 9400 | } |
| 9401 | } |
| 9402 | if (goodToGo) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9403 | 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] | 9404 | int transit = mNextAppTransition; |
| 9405 | if (mSkipAppTransitionAnimation) { |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 9406 | transit = WindowManagerPolicy.TRANSIT_UNSET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9407 | } |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 9408 | mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9409 | mAppTransitionReady = false; |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9410 | mAppTransitionRunning = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9411 | mAppTransitionTimeout = false; |
| 9412 | mStartingIconInTransition = false; |
| 9413 | mSkipAppTransitionAnimation = false; |
| 9414 | |
| 9415 | mH.removeMessages(H.APP_TRANSITION_TIMEOUT); |
| 9416 | |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9417 | // If there are applications waiting to come to the |
| 9418 | // top of the stack, now is the time to move their windows. |
| 9419 | // (Note that we don't do apps going to the bottom |
| 9420 | // here -- we want to keep their windows in the old |
| 9421 | // Z-order until the animation completes.) |
| 9422 | if (mToTopApps.size() > 0) { |
| 9423 | NN = mAppTokens.size(); |
| 9424 | for (i=0; i<NN; i++) { |
| 9425 | AppWindowToken wtoken = mAppTokens.get(i); |
| 9426 | if (wtoken.sendingToTop) { |
| 9427 | wtoken.sendingToTop = false; |
| 9428 | moveAppWindowsLocked(wtoken, NN, false); |
| 9429 | } |
| 9430 | } |
| 9431 | mToTopApps.clear(); |
| 9432 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9433 | |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 9434 | WindowState oldWallpaper = mWallpaperTarget; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9435 | |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 9436 | adjustWallpaperWindowsLocked(); |
Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 9437 | wallpaperMayChange = false; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9438 | |
Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 9439 | // The top-most window will supply the layout params, |
| 9440 | // and we will determine it below. |
| 9441 | LayoutParams animLp = null; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9442 | AppWindowToken animToken = null; |
Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 9443 | int bestAnimLayer = -1; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9444 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9445 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 9446 | "New wallpaper target=" + mWallpaperTarget |
| 9447 | + ", lower target=" + mLowerWallpaperTarget |
| 9448 | + ", upper target=" + mUpperWallpaperTarget); |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 9449 | int foundWallpapers = 0; |
Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 9450 | // Do a first pass through the tokens for two |
| 9451 | // things: |
| 9452 | // (1) Determine if both the closing and opening |
| 9453 | // app token sets are wallpaper targets, in which |
| 9454 | // case special animations are needed |
| 9455 | // (since the wallpaper needs to stay static |
| 9456 | // behind them). |
| 9457 | // (2) Find the layout params of the top-most |
| 9458 | // application window in the tokens, which is |
| 9459 | // what will control the animation theme. |
| 9460 | final int NC = mClosingApps.size(); |
| 9461 | NN = NC + mOpeningApps.size(); |
| 9462 | for (i=0; i<NN; i++) { |
| 9463 | AppWindowToken wtoken; |
| 9464 | int mode; |
| 9465 | if (i < NC) { |
| 9466 | wtoken = mClosingApps.get(i); |
| 9467 | mode = 1; |
| 9468 | } else { |
| 9469 | wtoken = mOpeningApps.get(i-NC); |
| 9470 | mode = 2; |
| 9471 | } |
| 9472 | if (mLowerWallpaperTarget != null) { |
| 9473 | if (mLowerWallpaperTarget.mAppToken == wtoken |
| 9474 | || mUpperWallpaperTarget.mAppToken == wtoken) { |
| 9475 | foundWallpapers |= mode; |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 9476 | } |
| 9477 | } |
Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 9478 | if (wtoken.appFullscreen) { |
| 9479 | WindowState ws = wtoken.findMainWindow(); |
| 9480 | if (ws != null) { |
| 9481 | // If this is a compatibility mode |
| 9482 | // window, we will always use its anim. |
| 9483 | if ((ws.mAttrs.flags&FLAG_COMPATIBLE_WINDOW) != 0) { |
| 9484 | animLp = ws.mAttrs; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9485 | animToken = ws.mAppToken; |
Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 9486 | bestAnimLayer = Integer.MAX_VALUE; |
| 9487 | } else if (ws.mLayer > bestAnimLayer) { |
| 9488 | animLp = ws.mAttrs; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9489 | animToken = ws.mAppToken; |
Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 9490 | bestAnimLayer = ws.mLayer; |
| 9491 | } |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 9492 | } |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 9493 | } |
| 9494 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9495 | |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 9496 | if (foundWallpapers == 3) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9497 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 9498 | "Wallpaper animation!"); |
| 9499 | switch (transit) { |
| 9500 | case WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN: |
| 9501 | case WindowManagerPolicy.TRANSIT_TASK_OPEN: |
| 9502 | case WindowManagerPolicy.TRANSIT_TASK_TO_FRONT: |
| 9503 | transit = WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_OPEN; |
| 9504 | break; |
| 9505 | case WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE: |
| 9506 | case WindowManagerPolicy.TRANSIT_TASK_CLOSE: |
| 9507 | case WindowManagerPolicy.TRANSIT_TASK_TO_BACK: |
| 9508 | transit = WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_CLOSE; |
| 9509 | break; |
| 9510 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9511 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 9512 | "New transit: " + transit); |
| 9513 | } else if (oldWallpaper != null) { |
| 9514 | // We are transitioning from an activity with |
| 9515 | // a wallpaper to one without. |
| 9516 | transit = WindowManagerPolicy.TRANSIT_WALLPAPER_CLOSE; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9517 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 9518 | "New transit away from wallpaper: " + transit); |
| 9519 | } else if (mWallpaperTarget != null) { |
| 9520 | // We are transitioning from an activity without |
| 9521 | // a wallpaper to now showing the wallpaper |
| 9522 | transit = WindowManagerPolicy.TRANSIT_WALLPAPER_OPEN; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9523 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 9524 | "New transit into wallpaper: " + transit); |
| 9525 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9526 | |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9527 | if ((transit&WindowManagerPolicy.TRANSIT_ENTER_MASK) != 0) { |
| 9528 | mLastEnterAnimToken = animToken; |
| 9529 | mLastEnterAnimParams = animLp; |
| 9530 | } else if (mLastEnterAnimParams != null) { |
| 9531 | animLp = mLastEnterAnimParams; |
| 9532 | mLastEnterAnimToken = null; |
| 9533 | mLastEnterAnimParams = null; |
| 9534 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9535 | |
Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 9536 | // If all closing windows are obscured, then there is |
| 9537 | // no need to do an animation. This is the case, for |
| 9538 | // example, when this transition is being done behind |
| 9539 | // the lock screen. |
| 9540 | if (!mPolicy.allowAppAnimationsLw()) { |
| 9541 | animLp = null; |
| 9542 | } |
| 9543 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9544 | NN = mOpeningApps.size(); |
| 9545 | for (i=0; i<NN; i++) { |
| 9546 | AppWindowToken wtoken = mOpeningApps.get(i); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9547 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9548 | "Now opening app" + wtoken); |
| 9549 | wtoken.reportedVisible = false; |
| 9550 | wtoken.inPendingTransaction = false; |
Dianne Hackborn | 83360b3 | 2009-08-24 18:43:32 -0700 | [diff] [blame] | 9551 | wtoken.animation = null; |
Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 9552 | setTokenVisibilityLocked(wtoken, animLp, true, transit, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9553 | wtoken.updateReportedVisibilityLocked(); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9554 | wtoken.waitingToShow = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9555 | wtoken.showAllWindowsLocked(); |
| 9556 | } |
| 9557 | NN = mClosingApps.size(); |
| 9558 | for (i=0; i<NN; i++) { |
| 9559 | AppWindowToken wtoken = mClosingApps.get(i); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9560 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9561 | "Now closing app" + wtoken); |
| 9562 | wtoken.inPendingTransaction = false; |
Dianne Hackborn | 83360b3 | 2009-08-24 18:43:32 -0700 | [diff] [blame] | 9563 | wtoken.animation = null; |
Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 9564 | setTokenVisibilityLocked(wtoken, animLp, false, transit, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9565 | wtoken.updateReportedVisibilityLocked(); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9566 | wtoken.waitingToHide = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9567 | // Force the allDrawn flag, because we want to start |
| 9568 | // this guy's animations regardless of whether it's |
| 9569 | // gotten drawn. |
| 9570 | wtoken.allDrawn = true; |
| 9571 | } |
| 9572 | |
Dianne Hackborn | 8b571a8 | 2009-09-25 16:09:43 -0700 | [diff] [blame] | 9573 | mNextAppTransitionPackage = null; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9574 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9575 | mOpeningApps.clear(); |
| 9576 | mClosingApps.clear(); |
| 9577 | |
| 9578 | // This has changed the visibility of windows, so perform |
| 9579 | // a new layout to get them all up-to-date. |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9580 | changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9581 | mLayoutNeeded = true; |
Dianne Hackborn | 20583ff | 2009-07-27 21:51:05 -0700 | [diff] [blame] | 9582 | if (!moveInputMethodWindowsIfNeededLocked(true)) { |
| 9583 | assignLayersLocked(); |
| 9584 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9585 | updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES); |
Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 9586 | mFocusMayChange = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9587 | } |
| 9588 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9589 | |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 9590 | int adjResult = 0; |
| 9591 | |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9592 | if (!animating && mAppTransitionRunning) { |
| 9593 | // We have finished the animation of an app transition. To do |
| 9594 | // this, we have delayed a lot of operations like showing and |
| 9595 | // hiding apps, moving apps in Z-order, etc. The app token list |
| 9596 | // reflects the correct Z-order, but the window list may now |
| 9597 | // be out of sync with it. So here we will just rebuild the |
| 9598 | // entire app window list. Fun! |
| 9599 | mAppTransitionRunning = false; |
| 9600 | // Clear information about apps that were moving. |
| 9601 | mToBottomApps.clear(); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9602 | |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9603 | rebuildAppWindowListLocked(); |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9604 | changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT; |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 9605 | adjResult |= ADJUST_WALLPAPER_LAYERS_CHANGED; |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9606 | moveInputMethodWindowsIfNeededLocked(false); |
| 9607 | wallpaperMayChange = true; |
Suchi Amalapurapu | c9568e3 | 2009-11-05 18:51:16 -0800 | [diff] [blame] | 9608 | // Since the window list has been rebuilt, focus might |
| 9609 | // have to be recomputed since the actual order of windows |
| 9610 | // might have changed again. |
Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 9611 | mFocusMayChange = true; |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -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 (wallpaperForceHidingChanged && changes == 0 && !mAppTransitionReady) { |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9615 | // At this point, there was a window with a wallpaper that |
| 9616 | // was force hiding other windows behind it, but now it |
| 9617 | // is going away. This may be simple -- just animate |
| 9618 | // away the wallpaper and its window -- or it may be |
| 9619 | // hard -- the wallpaper now needs to be shown behind |
| 9620 | // something that was hidden. |
| 9621 | WindowState oldWallpaper = mWallpaperTarget; |
Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 9622 | if (mLowerWallpaperTarget != null |
| 9623 | && mLowerWallpaperTarget.mAppToken != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9624 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 9625 | "wallpaperForceHiding changed with lower=" |
| 9626 | + mLowerWallpaperTarget); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9627 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 9628 | "hidden=" + mLowerWallpaperTarget.mAppToken.hidden + |
| 9629 | " hiddenRequested=" + mLowerWallpaperTarget.mAppToken.hiddenRequested); |
| 9630 | if (mLowerWallpaperTarget.mAppToken.hidden) { |
| 9631 | // The lower target has become hidden before we |
| 9632 | // actually started the animation... let's completely |
| 9633 | // re-evaluate everything. |
| 9634 | mLowerWallpaperTarget = mUpperWallpaperTarget = null; |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9635 | changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM; |
Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 9636 | } |
| 9637 | } |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 9638 | adjResult |= adjustWallpaperWindowsLocked(); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9639 | wallpaperMayChange = false; |
Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 9640 | wallpaperForceHidingChanged = false; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9641 | if (DEBUG_WALLPAPER) Slog.v(TAG, "****** OLD: " + oldWallpaper |
Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 9642 | + " NEW: " + mWallpaperTarget |
| 9643 | + " LOWER: " + mLowerWallpaperTarget); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9644 | if (mLowerWallpaperTarget == null) { |
| 9645 | // Whoops, we don't need a special wallpaper animation. |
| 9646 | // Clear them out. |
| 9647 | forceHiding = false; |
| 9648 | for (i=N-1; i>=0; i--) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 9649 | WindowState w = mWindows.get(i); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9650 | if (w.mSurface != null) { |
| 9651 | final WindowManager.LayoutParams attrs = w.mAttrs; |
Suchi Amalapurapu | c03d28b | 2009-10-28 14:32:05 -0700 | [diff] [blame] | 9652 | if (mPolicy.doesForceHide(w, attrs) && w.isVisibleLw()) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9653 | if (DEBUG_FOCUS) Slog.i(TAG, "win=" + w + " force hides other windows"); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9654 | forceHiding = true; |
| 9655 | } else if (mPolicy.canBeForceHidden(w, attrs)) { |
| 9656 | if (!w.mAnimating) { |
| 9657 | // We set the animation above so it |
| 9658 | // is not yet running. |
| 9659 | w.clearAnimation(); |
| 9660 | } |
| 9661 | } |
| 9662 | } |
| 9663 | } |
| 9664 | } |
| 9665 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9666 | |
Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 9667 | if (wallpaperMayChange) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9668 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 9669 | "Wallpaper may change! Adjusting"); |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 9670 | adjResult |= adjustWallpaperWindowsLocked(); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9671 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9672 | |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9673 | if ((adjResult&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9674 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9675 | "Wallpaper layer changed: assigning layers + relayout"); |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9676 | changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9677 | assignLayersLocked(); |
| 9678 | } else if ((adjResult&ADJUST_WALLPAPER_VISIBILITY_CHANGED) != 0) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9679 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9680 | "Wallpaper visibility changed: relayout"); |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9681 | changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9682 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9683 | |
Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 9684 | if (mFocusMayChange) { |
| 9685 | mFocusMayChange = false; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9686 | if (updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES)) { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9687 | changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9688 | adjResult = 0; |
Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 9689 | } |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9690 | } |
| 9691 | |
| 9692 | if (mLayoutNeeded) { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9693 | changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT; |
Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 9694 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9695 | |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9696 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "*** ANIM STEP: changes=0x" |
| 9697 | + Integer.toHexString(changes)); |
Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 9698 | |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 9699 | mInputMonitor.updateInputWindowsLw(); |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9700 | } while (changes != 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9701 | |
| 9702 | // THIRD LOOP: Update the surfaces of all windows. |
| 9703 | |
| 9704 | final boolean someoneLosingFocus = mLosingFocus.size() != 0; |
| 9705 | |
| 9706 | boolean obscured = false; |
| 9707 | boolean blurring = false; |
| 9708 | boolean dimming = false; |
| 9709 | boolean covered = false; |
Dianne Hackborn | 9ed4a4b | 2009-03-25 17:10:37 -0700 | [diff] [blame] | 9710 | boolean syswin = false; |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 9711 | boolean backgroundFillerShown = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9712 | |
Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 9713 | final int N = mWindows.size(); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9714 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9715 | for (i=N-1; i>=0; i--) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 9716 | WindowState w = mWindows.get(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9717 | |
| 9718 | boolean displayed = false; |
| 9719 | final WindowManager.LayoutParams attrs = w.mAttrs; |
| 9720 | final int attrFlags = attrs.flags; |
| 9721 | |
| 9722 | if (w.mSurface != null) { |
Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 9723 | // XXX NOTE: The logic here could be improved. We have |
| 9724 | // the decision about whether to resize a window separated |
| 9725 | // from whether to hide the surface. This can cause us to |
| 9726 | // resize a surface even if we are going to hide it. You |
| 9727 | // can see this by (1) holding device in landscape mode on |
| 9728 | // home screen; (2) tapping browser icon (device will rotate |
| 9729 | // to landscape; (3) tap home. The wallpaper will be resized |
| 9730 | // in step 2 but then immediately hidden, causing us to |
| 9731 | // have to resize and then redraw it again in step 3. It |
| 9732 | // would be nice to figure out how to avoid this, but it is |
| 9733 | // difficult because we do need to resize surfaces in some |
| 9734 | // cases while they are hidden such as when first showing a |
| 9735 | // window. |
| 9736 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9737 | w.computeShownFrameLocked(); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9738 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9739 | TAG, "Placing surface #" + i + " " + w.mSurface |
| 9740 | + ": new=" + w.mShownFrame + ", old=" |
| 9741 | + w.mLastShownFrame); |
| 9742 | |
| 9743 | boolean resize; |
| 9744 | int width, height; |
| 9745 | if ((w.mAttrs.flags & w.mAttrs.FLAG_SCALED) != 0) { |
| 9746 | resize = w.mLastRequestedWidth != w.mRequestedWidth || |
| 9747 | w.mLastRequestedHeight != w.mRequestedHeight; |
| 9748 | // for a scaled surface, we just want to use |
| 9749 | // the requested size. |
| 9750 | width = w.mRequestedWidth; |
| 9751 | height = w.mRequestedHeight; |
| 9752 | w.mLastRequestedWidth = width; |
| 9753 | w.mLastRequestedHeight = height; |
| 9754 | w.mLastShownFrame.set(w.mShownFrame); |
| 9755 | try { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9756 | if (SHOW_TRANSACTIONS) logSurface(w, |
| 9757 | "POS " + w.mShownFrame.left |
| 9758 | + ", " + w.mShownFrame.top, null); |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 9759 | w.mSurfaceX = w.mShownFrame.left; |
| 9760 | w.mSurfaceY = w.mShownFrame.top; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9761 | w.mSurface.setPosition(w.mShownFrame.left, w.mShownFrame.top); |
| 9762 | } catch (RuntimeException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9763 | Slog.w(TAG, "Error positioning surface in " + w, e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9764 | if (!recoveringMemory) { |
| 9765 | reclaimSomeSurfaceMemoryLocked(w, "position"); |
| 9766 | } |
| 9767 | } |
| 9768 | } else { |
| 9769 | resize = !w.mLastShownFrame.equals(w.mShownFrame); |
| 9770 | width = w.mShownFrame.width(); |
| 9771 | height = w.mShownFrame.height(); |
| 9772 | w.mLastShownFrame.set(w.mShownFrame); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9773 | } |
| 9774 | |
| 9775 | if (resize) { |
| 9776 | if (width < 1) width = 1; |
| 9777 | if (height < 1) height = 1; |
| 9778 | if (w.mSurface != null) { |
| 9779 | try { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9780 | if (SHOW_TRANSACTIONS) logSurface(w, |
| 9781 | "POS " + w.mShownFrame.left + "," |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 9782 | + w.mShownFrame.top + " SIZE " |
| 9783 | + w.mShownFrame.width() + "x" |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9784 | + w.mShownFrame.height(), null); |
Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 9785 | w.mSurfaceResized = true; |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 9786 | w.mSurfaceW = width; |
| 9787 | w.mSurfaceH = height; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9788 | w.mSurface.setSize(width, height); |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 9789 | w.mSurfaceX = w.mShownFrame.left; |
| 9790 | w.mSurfaceY = w.mShownFrame.top; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9791 | w.mSurface.setPosition(w.mShownFrame.left, |
| 9792 | w.mShownFrame.top); |
| 9793 | } catch (RuntimeException e) { |
| 9794 | // If something goes wrong with the surface (such |
| 9795 | // as running out of memory), don't take down the |
| 9796 | // entire system. |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9797 | Slog.e(TAG, "Failure updating surface of " + w |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9798 | + "size=(" + width + "x" + height |
| 9799 | + "), pos=(" + w.mShownFrame.left |
| 9800 | + "," + w.mShownFrame.top + ")", e); |
| 9801 | if (!recoveringMemory) { |
| 9802 | reclaimSomeSurfaceMemoryLocked(w, "size"); |
| 9803 | } |
| 9804 | } |
| 9805 | } |
| 9806 | } |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 9807 | if (!w.mAppFreezing && w.mLayoutSeq == mLayoutSeq) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9808 | w.mContentInsetsChanged = |
| 9809 | !w.mLastContentInsets.equals(w.mContentInsets); |
| 9810 | w.mVisibleInsetsChanged = |
| 9811 | !w.mLastVisibleInsets.equals(w.mVisibleInsets); |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 9812 | boolean configChanged = |
| 9813 | w.mConfiguration != mCurConfiguration |
| 9814 | && (w.mConfiguration == null |
| 9815 | || mCurConfiguration.diff(w.mConfiguration) != 0); |
Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 9816 | if (DEBUG_CONFIGURATION && configChanged) { |
| 9817 | Slog.v(TAG, "Win " + w + " config changed: " |
| 9818 | + mCurConfiguration); |
| 9819 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9820 | if (localLOGV) Slog.v(TAG, "Resizing " + w |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 9821 | + ": configChanged=" + configChanged |
| 9822 | + " last=" + w.mLastFrame + " frame=" + w.mFrame); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9823 | if (!w.mLastFrame.equals(w.mFrame) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9824 | || w.mContentInsetsChanged |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 9825 | || w.mVisibleInsetsChanged |
Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 9826 | || w.mSurfaceResized |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 9827 | || configChanged) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9828 | w.mLastFrame.set(w.mFrame); |
| 9829 | w.mLastContentInsets.set(w.mContentInsets); |
| 9830 | w.mLastVisibleInsets.set(w.mVisibleInsets); |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 9831 | // If the screen is currently frozen, then keep |
| 9832 | // it frozen until this window draws at its new |
| 9833 | // orientation. |
| 9834 | if (mDisplayFrozen) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9835 | if (DEBUG_ORIENTATION) Slog.v(TAG, |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 9836 | "Resizing while display frozen: " + w); |
| 9837 | w.mOrientationChanging = true; |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 9838 | if (!mWindowsFreezingScreen) { |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 9839 | mWindowsFreezingScreen = true; |
| 9840 | // XXX should probably keep timeout from |
| 9841 | // when we first froze the display. |
| 9842 | mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT); |
| 9843 | mH.sendMessageDelayed(mH.obtainMessage( |
| 9844 | H.WINDOW_FREEZE_TIMEOUT), 2000); |
| 9845 | } |
| 9846 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9847 | // If the orientation is changing, then we need to |
| 9848 | // hold off on unfreezing the display until this |
| 9849 | // window has been redrawn; to do that, we need |
| 9850 | // to go through the process of getting informed |
| 9851 | // by the application when it has finished drawing. |
| 9852 | if (w.mOrientationChanging) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9853 | if (DEBUG_ORIENTATION) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9854 | "Orientation start waiting for draw in " |
| 9855 | + w + ", surface " + w.mSurface); |
| 9856 | w.mDrawPending = true; |
| 9857 | w.mCommitDrawPending = false; |
| 9858 | w.mReadyToShow = false; |
| 9859 | if (w.mAppToken != null) { |
| 9860 | w.mAppToken.allDrawn = false; |
| 9861 | } |
| 9862 | } |
Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 9863 | if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9864 | "Resizing window " + w + " to " + w.mFrame); |
| 9865 | mResizingWindows.add(w); |
| 9866 | } else if (w.mOrientationChanging) { |
| 9867 | if (!w.mDrawPending && !w.mCommitDrawPending) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9868 | if (DEBUG_ORIENTATION) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9869 | "Orientation not waiting for draw in " |
| 9870 | + w + ", surface " + w.mSurface); |
| 9871 | w.mOrientationChanging = false; |
| 9872 | } |
| 9873 | } |
| 9874 | } |
| 9875 | |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9876 | if (w.mAttachedHidden || !w.isReadyForDisplay()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9877 | if (!w.mLastHidden) { |
| 9878 | //dump(); |
| 9879 | w.mLastHidden = true; |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9880 | if (SHOW_TRANSACTIONS) logSurface(w, |
| 9881 | "HIDE (performLayout)", null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9882 | if (w.mSurface != null) { |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 9883 | w.mSurfaceShown = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9884 | try { |
| 9885 | w.mSurface.hide(); |
| 9886 | } catch (RuntimeException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9887 | Slog.w(TAG, "Exception hiding surface in " + w); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9888 | } |
| 9889 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9890 | } |
| 9891 | // If we are waiting for this window to handle an |
| 9892 | // orientation change, well, it is hidden, so |
| 9893 | // doesn't really matter. Note that this does |
| 9894 | // introduce a potential glitch if the window |
| 9895 | // becomes unhidden before it has drawn for the |
| 9896 | // new orientation. |
| 9897 | if (w.mOrientationChanging) { |
| 9898 | w.mOrientationChanging = false; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9899 | if (DEBUG_ORIENTATION) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9900 | "Orientation change skips hidden " + w); |
| 9901 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9902 | } else if (w.mLastLayer != w.mAnimLayer |
| 9903 | || w.mLastAlpha != w.mShownAlpha |
| 9904 | || w.mLastDsDx != w.mDsDx |
| 9905 | || w.mLastDtDx != w.mDtDx |
| 9906 | || w.mLastDsDy != w.mDsDy |
| 9907 | || w.mLastDtDy != w.mDtDy |
| 9908 | || w.mLastHScale != w.mHScale |
| 9909 | || w.mLastVScale != w.mVScale |
| 9910 | || w.mLastHidden) { |
| 9911 | displayed = true; |
| 9912 | w.mLastAlpha = w.mShownAlpha; |
| 9913 | w.mLastLayer = w.mAnimLayer; |
| 9914 | w.mLastDsDx = w.mDsDx; |
| 9915 | w.mLastDtDx = w.mDtDx; |
| 9916 | w.mLastDsDy = w.mDsDy; |
| 9917 | w.mLastDtDy = w.mDtDy; |
| 9918 | w.mLastHScale = w.mHScale; |
| 9919 | w.mLastVScale = w.mVScale; |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9920 | if (SHOW_TRANSACTIONS) logSurface(w, |
| 9921 | "alpha=" + w.mShownAlpha + " layer=" + w.mAnimLayer |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 9922 | + " matrix=[" + (w.mDsDx*w.mHScale) |
| 9923 | + "," + (w.mDtDx*w.mVScale) |
| 9924 | + "][" + (w.mDsDy*w.mHScale) |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9925 | + "," + (w.mDtDy*w.mVScale) + "]", null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9926 | if (w.mSurface != null) { |
| 9927 | try { |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 9928 | w.mSurfaceAlpha = w.mShownAlpha; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9929 | w.mSurface.setAlpha(w.mShownAlpha); |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 9930 | w.mSurfaceLayer = w.mAnimLayer; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9931 | w.mSurface.setLayer(w.mAnimLayer); |
| 9932 | w.mSurface.setMatrix( |
| 9933 | w.mDsDx*w.mHScale, w.mDtDx*w.mVScale, |
| 9934 | w.mDsDy*w.mHScale, w.mDtDy*w.mVScale); |
| 9935 | } catch (RuntimeException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9936 | Slog.w(TAG, "Error updating surface in " + w, e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9937 | if (!recoveringMemory) { |
| 9938 | reclaimSomeSurfaceMemoryLocked(w, "update"); |
| 9939 | } |
| 9940 | } |
| 9941 | } |
| 9942 | |
| 9943 | if (w.mLastHidden && !w.mDrawPending |
| 9944 | && !w.mCommitDrawPending |
| 9945 | && !w.mReadyToShow) { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9946 | if (SHOW_TRANSACTIONS) logSurface(w, |
| 9947 | "SHOW (performLayout)", null); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9948 | if (DEBUG_VISIBILITY) Slog.v(TAG, "Showing " + w |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9949 | + " during relayout"); |
| 9950 | if (showSurfaceRobustlyLocked(w)) { |
| 9951 | w.mHasDrawn = true; |
| 9952 | w.mLastHidden = false; |
| 9953 | } else { |
| 9954 | w.mOrientationChanging = false; |
| 9955 | } |
| 9956 | } |
| 9957 | if (w.mSurface != null) { |
| 9958 | w.mToken.hasVisible = true; |
| 9959 | } |
| 9960 | } else { |
| 9961 | displayed = true; |
| 9962 | } |
| 9963 | |
| 9964 | if (displayed) { |
| 9965 | if (!covered) { |
Romain Guy | 980a938 | 2010-01-08 15:06:28 -0800 | [diff] [blame] | 9966 | if (attrs.width == LayoutParams.MATCH_PARENT |
| 9967 | && attrs.height == LayoutParams.MATCH_PARENT) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9968 | covered = true; |
| 9969 | } |
| 9970 | } |
| 9971 | if (w.mOrientationChanging) { |
| 9972 | if (w.mDrawPending || w.mCommitDrawPending) { |
| 9973 | orientationChangeComplete = false; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9974 | if (DEBUG_ORIENTATION) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9975 | "Orientation continue waiting for draw in " + w); |
| 9976 | } else { |
| 9977 | w.mOrientationChanging = false; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9978 | if (DEBUG_ORIENTATION) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9979 | "Orientation change complete in " + w); |
| 9980 | } |
| 9981 | } |
| 9982 | w.mToken.hasVisible = true; |
| 9983 | } |
| 9984 | } else if (w.mOrientationChanging) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9985 | if (DEBUG_ORIENTATION) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9986 | "Orientation change skips hidden " + w); |
| 9987 | w.mOrientationChanging = false; |
| 9988 | } |
| 9989 | |
| 9990 | final boolean canBeSeen = w.isDisplayedLw(); |
| 9991 | |
| 9992 | if (someoneLosingFocus && w == mCurrentFocus && canBeSeen) { |
| 9993 | focusDisplayed = true; |
| 9994 | } |
| 9995 | |
Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 9996 | final boolean obscuredChanged = w.mObscured != obscured; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9997 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9998 | // Update effect. |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 9999 | if (!(w.mObscured=obscured)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10000 | if (w.mSurface != null) { |
| 10001 | if ((attrFlags&FLAG_KEEP_SCREEN_ON) != 0) { |
| 10002 | holdScreen = w.mSession; |
| 10003 | } |
Dianne Hackborn | 9ed4a4b | 2009-03-25 17:10:37 -0700 | [diff] [blame] | 10004 | if (!syswin && w.mAttrs.screenBrightness >= 0 |
| 10005 | && screenBrightness < 0) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10006 | screenBrightness = w.mAttrs.screenBrightness; |
| 10007 | } |
Mike Lockwood | fb73f79 | 2009-11-20 11:31:18 -0500 | [diff] [blame] | 10008 | if (!syswin && w.mAttrs.buttonBrightness >= 0 |
| 10009 | && buttonBrightness < 0) { |
| 10010 | buttonBrightness = w.mAttrs.buttonBrightness; |
| 10011 | } |
Mike Lockwood | 46af6a8 | 2010-03-09 08:28:22 -0500 | [diff] [blame] | 10012 | if (canBeSeen |
| 10013 | && (attrs.type == WindowManager.LayoutParams.TYPE_SYSTEM_DIALOG |
| 10014 | || attrs.type == WindowManager.LayoutParams.TYPE_KEYGUARD |
| 10015 | || attrs.type == WindowManager.LayoutParams.TYPE_SYSTEM_ERROR)) { |
Dianne Hackborn | 9ed4a4b | 2009-03-25 17:10:37 -0700 | [diff] [blame] | 10016 | syswin = true; |
| 10017 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10018 | } |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 10019 | |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 10020 | boolean opaqueDrawn = canBeSeen && w.isOpaqueDrawn(); |
| 10021 | if (opaqueDrawn && w.isFullscreen(dw, dh)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10022 | // This window completely covers everything behind it, |
| 10023 | // so we want to leave all of them as unblurred (for |
| 10024 | // performance reasons). |
| 10025 | obscured = true; |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 10026 | } else if (opaqueDrawn && w.needsBackgroundFiller(dw, dh)) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10027 | if (SHOW_TRANSACTIONS) Slog.d(TAG, "showing background filler"); |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 10028 | // This window is in compatibility mode, and needs background filler. |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 10029 | obscured = true; |
| 10030 | if (mBackgroundFillerSurface == null) { |
| 10031 | try { |
| 10032 | mBackgroundFillerSurface = new Surface(mFxSession, 0, |
Mathias Agopian | 5d26c1e | 2010-03-01 16:09:43 -0800 | [diff] [blame] | 10033 | "BackGroundFiller", |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 10034 | 0, dw, dh, |
| 10035 | PixelFormat.OPAQUE, |
| 10036 | Surface.FX_SURFACE_NORMAL); |
| 10037 | } catch (Exception e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10038 | Slog.e(TAG, "Exception creating filler surface", e); |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 10039 | } |
| 10040 | } |
| 10041 | try { |
| 10042 | mBackgroundFillerSurface.setPosition(0, 0); |
| 10043 | mBackgroundFillerSurface.setSize(dw, dh); |
| 10044 | // Using the same layer as Dim because they will never be shown at the |
| 10045 | // same time. |
| 10046 | mBackgroundFillerSurface.setLayer(w.mAnimLayer - 1); |
| 10047 | mBackgroundFillerSurface.show(); |
| 10048 | } catch (RuntimeException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10049 | Slog.e(TAG, "Exception showing filler surface"); |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 10050 | } |
| 10051 | backgroundFillerShown = true; |
| 10052 | mBackgroundFillerShown = true; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10053 | } else if (canBeSeen && !obscured && |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10054 | (attrFlags&FLAG_BLUR_BEHIND|FLAG_DIM_BEHIND) != 0) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10055 | if (localLOGV) Slog.v(TAG, "Win " + w |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10056 | + ": blurring=" + blurring |
| 10057 | + " obscured=" + obscured |
| 10058 | + " displayed=" + displayed); |
| 10059 | if ((attrFlags&FLAG_DIM_BEHIND) != 0) { |
| 10060 | if (!dimming) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10061 | //Slog.i(TAG, "DIM BEHIND: " + w); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10062 | dimming = true; |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 10063 | if (mDimAnimator == null) { |
| 10064 | mDimAnimator = new DimAnimator(mFxSession); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10065 | } |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 10066 | mDimAnimator.show(dw, dh); |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 10067 | mDimAnimator.updateParameters(w, currentTime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10068 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10069 | } |
| 10070 | if ((attrFlags&FLAG_BLUR_BEHIND) != 0) { |
| 10071 | if (!blurring) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10072 | //Slog.i(TAG, "BLUR BEHIND: " + w); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10073 | blurring = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10074 | if (mBlurSurface == null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10075 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR " |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10076 | + mBlurSurface + ": CREATE"); |
| 10077 | try { |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10078 | mBlurSurface = new Surface(mFxSession, 0, |
Mathias Agopian | 5d26c1e | 2010-03-01 16:09:43 -0800 | [diff] [blame] | 10079 | "BlurSurface", |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10080 | -1, 16, 16, |
| 10081 | PixelFormat.OPAQUE, |
| 10082 | Surface.FX_SURFACE_BLUR); |
| 10083 | } catch (Exception e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10084 | Slog.e(TAG, "Exception creating Blur surface", e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10085 | } |
| 10086 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10087 | if (mBlurSurface != null) { |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 10088 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR " |
| 10089 | + mBlurSurface + ": pos=(0,0) (" + |
| 10090 | dw + "x" + dh + "), layer=" + (w.mAnimLayer-1)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10091 | mBlurSurface.setPosition(0, 0); |
| 10092 | mBlurSurface.setSize(dw, dh); |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 10093 | mBlurSurface.setLayer(w.mAnimLayer-2); |
| 10094 | if (!mBlurShown) { |
| 10095 | try { |
| 10096 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR " |
| 10097 | + mBlurSurface + ": SHOW"); |
| 10098 | mBlurSurface.show(); |
| 10099 | } catch (RuntimeException e) { |
| 10100 | Slog.w(TAG, "Failure showing blur surface", e); |
| 10101 | } |
| 10102 | mBlurShown = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10103 | } |
| 10104 | } |
| 10105 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10106 | } |
| 10107 | } |
| 10108 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10109 | |
Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 10110 | if (obscuredChanged && mWallpaperTarget == w) { |
| 10111 | // This is the wallpaper target and its obscured state |
| 10112 | // changed... make sure the current wallaper's visibility |
| 10113 | // has been updated accordingly. |
| 10114 | updateWallpaperVisibilityLocked(); |
| 10115 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10116 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10117 | |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 10118 | if (backgroundFillerShown == false && mBackgroundFillerShown) { |
| 10119 | mBackgroundFillerShown = false; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10120 | if (SHOW_TRANSACTIONS) Slog.d(TAG, "hiding background filler"); |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 10121 | try { |
| 10122 | mBackgroundFillerSurface.hide(); |
| 10123 | } catch (RuntimeException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10124 | Slog.e(TAG, "Exception hiding filler surface", e); |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 10125 | } |
| 10126 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10127 | |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 10128 | if (mDimAnimator != null && mDimAnimator.mDimShown) { |
Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 10129 | animating |= mDimAnimator.updateSurface(dimming, currentTime, |
| 10130 | mDisplayFrozen || !mPolicy.isScreenOn()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10131 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10132 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10133 | if (!blurring && mBlurShown) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10134 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR " + mBlurSurface |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10135 | + ": HIDE"); |
| 10136 | try { |
| 10137 | mBlurSurface.hide(); |
| 10138 | } catch (IllegalArgumentException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10139 | Slog.w(TAG, "Illegal argument exception hiding blur surface"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10140 | } |
| 10141 | mBlurShown = false; |
| 10142 | } |
| 10143 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10144 | if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10145 | } catch (RuntimeException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10146 | Slog.e(TAG, "Unhandled exception in Window Manager", e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10147 | } |
| 10148 | |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 10149 | mInputMonitor.updateInputWindowsLw(); |
| 10150 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10151 | Surface.closeTransaction(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10152 | |
Dianne Hackborn | b9fb170 | 2010-08-23 16:49:02 -0700 | [diff] [blame] | 10153 | if (mWatermark != null) { |
| 10154 | mWatermark.drawIfNeeded(); |
| 10155 | } |
| 10156 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10157 | if (DEBUG_ORIENTATION && mDisplayFrozen) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10158 | "With display frozen, orientationChangeComplete=" |
| 10159 | + orientationChangeComplete); |
| 10160 | if (orientationChangeComplete) { |
| 10161 | if (mWindowsFreezingScreen) { |
| 10162 | mWindowsFreezingScreen = false; |
| 10163 | mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT); |
| 10164 | } |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 10165 | stopFreezingDisplayLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10166 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10167 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10168 | i = mResizingWindows.size(); |
| 10169 | if (i > 0) { |
| 10170 | do { |
| 10171 | i--; |
| 10172 | WindowState win = mResizingWindows.get(i); |
| 10173 | try { |
Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 10174 | if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG, |
| 10175 | "Reporting new frame to " + win + ": " + win.mFrame); |
Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 10176 | int diff = 0; |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 10177 | boolean configChanged = |
| 10178 | win.mConfiguration != mCurConfiguration |
| 10179 | && (win.mConfiguration == null |
Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 10180 | || (diff=mCurConfiguration.diff(win.mConfiguration)) != 0); |
| 10181 | if ((DEBUG_RESIZE || DEBUG_ORIENTATION || DEBUG_CONFIGURATION) |
| 10182 | && configChanged) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10183 | Slog.i(TAG, "Sending new config to window " + win + ": " |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 10184 | + win.mFrame.width() + "x" + win.mFrame.height() |
Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 10185 | + " / " + mCurConfiguration + " / 0x" |
| 10186 | + Integer.toHexString(diff)); |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 10187 | } |
Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 10188 | win.mConfiguration = mCurConfiguration; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10189 | win.mClient.resized(win.mFrame.width(), |
| 10190 | win.mFrame.height(), win.mLastContentInsets, |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 10191 | win.mLastVisibleInsets, win.mDrawPending, |
| 10192 | configChanged ? win.mConfiguration : null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10193 | win.mContentInsetsChanged = false; |
| 10194 | win.mVisibleInsetsChanged = false; |
Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 10195 | win.mSurfaceResized = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10196 | } catch (RemoteException e) { |
| 10197 | win.mOrientationChanging = false; |
| 10198 | } |
| 10199 | } while (i > 0); |
| 10200 | mResizingWindows.clear(); |
| 10201 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10202 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10203 | // Destroy the surface of any windows that are no longer visible. |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 10204 | boolean wallpaperDestroyed = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10205 | i = mDestroySurface.size(); |
| 10206 | if (i > 0) { |
| 10207 | do { |
| 10208 | i--; |
| 10209 | WindowState win = mDestroySurface.get(i); |
| 10210 | win.mDestroying = false; |
| 10211 | if (mInputMethodWindow == win) { |
| 10212 | mInputMethodWindow = null; |
| 10213 | } |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 10214 | if (win == mWallpaperTarget) { |
| 10215 | wallpaperDestroyed = true; |
| 10216 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10217 | win.destroySurfaceLocked(); |
| 10218 | } while (i > 0); |
| 10219 | mDestroySurface.clear(); |
| 10220 | } |
| 10221 | |
| 10222 | // Time to remove any exiting tokens? |
| 10223 | for (i=mExitingTokens.size()-1; i>=0; i--) { |
| 10224 | WindowToken token = mExitingTokens.get(i); |
| 10225 | if (!token.hasVisible) { |
| 10226 | mExitingTokens.remove(i); |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 10227 | if (token.windowType == TYPE_WALLPAPER) { |
| 10228 | mWallpaperTokens.remove(token); |
| 10229 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10230 | } |
| 10231 | } |
| 10232 | |
| 10233 | // Time to remove any exiting applications? |
| 10234 | for (i=mExitingAppTokens.size()-1; i>=0; i--) { |
| 10235 | AppWindowToken token = mExitingAppTokens.get(i); |
| 10236 | if (!token.hasVisible && !mClosingApps.contains(token)) { |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 10237 | // Make sure there is no animation running on this token, |
| 10238 | // so any windows associated with it will be removed as |
| 10239 | // soon as their animations are complete |
| 10240 | token.animation = null; |
| 10241 | token.animating = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10242 | mAppTokens.remove(token); |
| 10243 | mExitingAppTokens.remove(i); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10244 | if (mLastEnterAnimToken == token) { |
| 10245 | mLastEnterAnimToken = null; |
| 10246 | mLastEnterAnimParams = null; |
| 10247 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10248 | } |
| 10249 | } |
| 10250 | |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 10251 | boolean needRelayout = false; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10252 | |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 10253 | if (!animating && mAppTransitionRunning) { |
| 10254 | // We have finished the animation of an app transition. To do |
| 10255 | // this, we have delayed a lot of operations like showing and |
| 10256 | // hiding apps, moving apps in Z-order, etc. The app token list |
| 10257 | // reflects the correct Z-order, but the window list may now |
| 10258 | // be out of sync with it. So here we will just rebuild the |
| 10259 | // entire app window list. Fun! |
| 10260 | mAppTransitionRunning = false; |
| 10261 | needRelayout = true; |
| 10262 | rebuildAppWindowListLocked(); |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 10263 | assignLayersLocked(); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 10264 | // Clear information about apps that were moving. |
| 10265 | mToBottomApps.clear(); |
| 10266 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10267 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10268 | if (focusDisplayed) { |
| 10269 | mH.sendEmptyMessage(H.REPORT_LOSING_FOCUS); |
| 10270 | } |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 10271 | if (wallpaperDestroyed) { |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 10272 | needRelayout = adjustWallpaperWindowsLocked() != 0; |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 10273 | } |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 10274 | if (needRelayout) { |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 10275 | requestAnimationLocked(0); |
| 10276 | } else if (animating) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10277 | requestAnimationLocked(currentTime+(1000/60)-SystemClock.uptimeMillis()); |
| 10278 | } |
Jeff Brown | eb857f1 | 2010-07-16 10:06:33 -0700 | [diff] [blame] | 10279 | |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 10280 | mInputMonitor.updateInputWindowsLw(); |
Jeff Brown | eb857f1 | 2010-07-16 10:06:33 -0700 | [diff] [blame] | 10281 | |
Jeff Brown | 8e03b75 | 2010-06-13 19:16:55 -0700 | [diff] [blame] | 10282 | setHoldScreenLocked(holdScreen != null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10283 | if (screenBrightness < 0 || screenBrightness > 1.0f) { |
| 10284 | mPowerManager.setScreenBrightnessOverride(-1); |
| 10285 | } else { |
| 10286 | mPowerManager.setScreenBrightnessOverride((int) |
| 10287 | (screenBrightness * Power.BRIGHTNESS_ON)); |
| 10288 | } |
Mike Lockwood | fb73f79 | 2009-11-20 11:31:18 -0500 | [diff] [blame] | 10289 | if (buttonBrightness < 0 || buttonBrightness > 1.0f) { |
| 10290 | mPowerManager.setButtonBrightnessOverride(-1); |
| 10291 | } else { |
| 10292 | mPowerManager.setButtonBrightnessOverride((int) |
| 10293 | (buttonBrightness * Power.BRIGHTNESS_ON)); |
| 10294 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10295 | if (holdScreen != mHoldingScreenOn) { |
| 10296 | mHoldingScreenOn = holdScreen; |
| 10297 | Message m = mH.obtainMessage(H.HOLD_SCREEN_CHANGED, holdScreen); |
| 10298 | mH.sendMessage(m); |
| 10299 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10300 | |
Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 10301 | if (mTurnOnScreen) { |
Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 10302 | if (DEBUG_VISIBILITY) Slog.v(TAG, "Turning screen on after layout!"); |
Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 10303 | mPowerManager.userActivity(SystemClock.uptimeMillis(), false, |
| 10304 | LocalPowerManager.BUTTON_EVENT, true); |
| 10305 | mTurnOnScreen = false; |
| 10306 | } |
Dianne Hackborn | f3bea9c | 2009-12-09 18:26:21 -0800 | [diff] [blame] | 10307 | |
| 10308 | // Check to see if we are now in a state where the screen should |
| 10309 | // be enabled, because the window obscured flags have changed. |
| 10310 | enableScreenIfNeededLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10311 | } |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 10312 | |
| 10313 | /** |
| 10314 | * Must be called with the main window manager lock held. |
| 10315 | */ |
| 10316 | void setHoldScreenLocked(boolean holding) { |
| 10317 | boolean state = mHoldingScreenWakeLock.isHeld(); |
| 10318 | if (holding != state) { |
| 10319 | if (holding) { |
| 10320 | mHoldingScreenWakeLock.acquire(); |
| 10321 | } else { |
| 10322 | mPolicy.screenOnStoppedLw(); |
| 10323 | mHoldingScreenWakeLock.release(); |
| 10324 | } |
| 10325 | } |
| 10326 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10327 | |
| 10328 | void requestAnimationLocked(long delay) { |
| 10329 | if (!mAnimationPending) { |
| 10330 | mAnimationPending = true; |
| 10331 | mH.sendMessageDelayed(mH.obtainMessage(H.ANIMATE), delay); |
| 10332 | } |
| 10333 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10334 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10335 | /** |
| 10336 | * Have the surface flinger show a surface, robustly dealing with |
| 10337 | * error conditions. In particular, if there is not enough memory |
| 10338 | * to show the surface, then we will try to get rid of other surfaces |
| 10339 | * in order to succeed. |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10340 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10341 | * @return Returns true if the surface was successfully shown. |
| 10342 | */ |
| 10343 | boolean showSurfaceRobustlyLocked(WindowState win) { |
| 10344 | try { |
| 10345 | if (win.mSurface != null) { |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 10346 | win.mSurfaceShown = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10347 | win.mSurface.show(); |
Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 10348 | if (win.mTurnOnScreen) { |
Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 10349 | if (DEBUG_VISIBILITY) Slog.v(TAG, |
| 10350 | "Show surface turning screen on: " + win); |
Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 10351 | win.mTurnOnScreen = false; |
| 10352 | mTurnOnScreen = true; |
| 10353 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10354 | } |
| 10355 | return true; |
| 10356 | } catch (RuntimeException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10357 | 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] | 10358 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10359 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10360 | reclaimSomeSurfaceMemoryLocked(win, "show"); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10361 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10362 | return false; |
| 10363 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10364 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10365 | void reclaimSomeSurfaceMemoryLocked(WindowState win, String operation) { |
| 10366 | final Surface surface = win.mSurface; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10367 | |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10368 | EventLog.writeEvent(EventLogTags.WM_NO_SURFACE_MEMORY, win.toString(), |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10369 | win.mSession.mPid, operation); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10370 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10371 | if (mForceRemoves == null) { |
| 10372 | mForceRemoves = new ArrayList<WindowState>(); |
| 10373 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10374 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10375 | long callingIdentity = Binder.clearCallingIdentity(); |
| 10376 | try { |
| 10377 | // There was some problem... first, do a sanity check of the |
| 10378 | // window list to make sure we haven't left any dangling surfaces |
| 10379 | // around. |
| 10380 | int N = mWindows.size(); |
| 10381 | boolean leakedSurface = false; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10382 | 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] | 10383 | for (int i=0; i<N; i++) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 10384 | WindowState ws = mWindows.get(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10385 | if (ws.mSurface != null) { |
| 10386 | if (!mSessions.contains(ws.mSession)) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10387 | Slog.w(TAG, "LEAKED SURFACE (session doesn't exist): " |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10388 | + ws + " surface=" + ws.mSurface |
| 10389 | + " token=" + win.mToken |
| 10390 | + " pid=" + ws.mSession.mPid |
| 10391 | + " uid=" + ws.mSession.mUid); |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 10392 | ws.mSurface.destroy(); |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 10393 | ws.mSurfaceShown = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10394 | ws.mSurface = null; |
| 10395 | mForceRemoves.add(ws); |
| 10396 | i--; |
| 10397 | N--; |
| 10398 | leakedSurface = true; |
| 10399 | } else if (win.mAppToken != null && win.mAppToken.clientHidden) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10400 | Slog.w(TAG, "LEAKED SURFACE (app token hidden): " |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10401 | + ws + " surface=" + ws.mSurface |
| 10402 | + " token=" + win.mAppToken); |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 10403 | ws.mSurface.destroy(); |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 10404 | ws.mSurfaceShown = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10405 | ws.mSurface = null; |
| 10406 | leakedSurface = true; |
| 10407 | } |
| 10408 | } |
| 10409 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10410 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10411 | boolean killedApps = false; |
| 10412 | if (!leakedSurface) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10413 | Slog.w(TAG, "No leaked surfaces; killing applicatons!"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10414 | SparseIntArray pidCandidates = new SparseIntArray(); |
| 10415 | for (int i=0; i<N; i++) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 10416 | WindowState ws = mWindows.get(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10417 | if (ws.mSurface != null) { |
| 10418 | pidCandidates.append(ws.mSession.mPid, ws.mSession.mPid); |
| 10419 | } |
| 10420 | } |
| 10421 | if (pidCandidates.size() > 0) { |
| 10422 | int[] pids = new int[pidCandidates.size()]; |
| 10423 | for (int i=0; i<pids.length; i++) { |
| 10424 | pids[i] = pidCandidates.keyAt(i); |
| 10425 | } |
| 10426 | try { |
Suchi Amalapurapu | e99bb5f | 2010-03-19 14:36:49 -0700 | [diff] [blame] | 10427 | if (mActivityManager.killPids(pids, "Free memory")) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10428 | killedApps = true; |
| 10429 | } |
| 10430 | } catch (RemoteException e) { |
| 10431 | } |
| 10432 | } |
| 10433 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10434 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10435 | if (leakedSurface || killedApps) { |
| 10436 | // We managed to reclaim some memory, so get rid of the trouble |
| 10437 | // surface and ask the app to request another one. |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10438 | 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] | 10439 | if (surface != null) { |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 10440 | surface.destroy(); |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 10441 | win.mSurfaceShown = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10442 | win.mSurface = null; |
| 10443 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10444 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10445 | try { |
| 10446 | win.mClient.dispatchGetNewSurface(); |
| 10447 | } catch (RemoteException e) { |
| 10448 | } |
| 10449 | } |
| 10450 | } finally { |
| 10451 | Binder.restoreCallingIdentity(callingIdentity); |
| 10452 | } |
| 10453 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10454 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10455 | private boolean updateFocusedWindowLocked(int mode) { |
| 10456 | WindowState newFocus = computeFocusedWindowLocked(); |
| 10457 | if (mCurrentFocus != newFocus) { |
| 10458 | // This check makes sure that we don't already have the focus |
| 10459 | // change message pending. |
| 10460 | mH.removeMessages(H.REPORT_FOCUS_CHANGE); |
| 10461 | mH.sendEmptyMessage(H.REPORT_FOCUS_CHANGE); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10462 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10463 | TAG, "Changing focus from " + mCurrentFocus + " to " + newFocus); |
| 10464 | final WindowState oldFocus = mCurrentFocus; |
| 10465 | mCurrentFocus = newFocus; |
| 10466 | mLosingFocus.remove(newFocus); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10467 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10468 | final WindowState imWindow = mInputMethodWindow; |
| 10469 | if (newFocus != imWindow && oldFocus != imWindow) { |
The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 10470 | if (moveInputMethodWindowsIfNeededLocked( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10471 | mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS && |
The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 10472 | mode != UPDATE_FOCUS_WILL_PLACE_SURFACES)) { |
| 10473 | mLayoutNeeded = true; |
| 10474 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10475 | if (mode == UPDATE_FOCUS_PLACING_SURFACES) { |
| 10476 | performLayoutLockedInner(); |
The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 10477 | } else if (mode == UPDATE_FOCUS_WILL_PLACE_SURFACES) { |
| 10478 | // Client will do the layout, but we need to assign layers |
| 10479 | // for handleNewWindowLocked() below. |
| 10480 | assignLayersLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10481 | } |
| 10482 | } |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 10483 | |
| 10484 | if (mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS) { |
| 10485 | // If we defer assigning layers, then the caller is responsible for |
| 10486 | // doing this part. |
| 10487 | finishUpdateFocusedWindowAfterAssignLayersLocked(); |
The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 10488 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10489 | return true; |
| 10490 | } |
| 10491 | return false; |
| 10492 | } |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 10493 | |
| 10494 | private void finishUpdateFocusedWindowAfterAssignLayersLocked() { |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 10495 | mInputMonitor.setInputFocusLw(mCurrentFocus); |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 10496 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10497 | |
| 10498 | private WindowState computeFocusedWindowLocked() { |
| 10499 | WindowState result = null; |
| 10500 | WindowState win; |
| 10501 | |
| 10502 | int i = mWindows.size() - 1; |
| 10503 | int nextAppIndex = mAppTokens.size()-1; |
| 10504 | WindowToken nextApp = nextAppIndex >= 0 |
| 10505 | ? mAppTokens.get(nextAppIndex) : null; |
| 10506 | |
| 10507 | while (i >= 0) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 10508 | win = mWindows.get(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10509 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10510 | if (localLOGV || DEBUG_FOCUS) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10511 | TAG, "Looking for focus: " + i |
| 10512 | + " = " + win |
| 10513 | + ", flags=" + win.mAttrs.flags |
| 10514 | + ", canReceive=" + win.canReceiveKeys()); |
| 10515 | |
| 10516 | AppWindowToken thisApp = win.mAppToken; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10517 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10518 | // If this window's application has been removed, just skip it. |
| 10519 | if (thisApp != null && thisApp.removed) { |
| 10520 | i--; |
| 10521 | continue; |
| 10522 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10523 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10524 | // If there is a focused app, don't allow focus to go to any |
| 10525 | // windows below it. If this is an application window, step |
| 10526 | // through the app tokens until we find its app. |
| 10527 | if (thisApp != null && nextApp != null && thisApp != nextApp |
| 10528 | && win.mAttrs.type != TYPE_APPLICATION_STARTING) { |
| 10529 | int origAppIndex = nextAppIndex; |
| 10530 | while (nextAppIndex > 0) { |
| 10531 | if (nextApp == mFocusedApp) { |
| 10532 | // Whoops, we are below the focused app... no focus |
| 10533 | // for you! |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10534 | if (localLOGV || DEBUG_FOCUS) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10535 | TAG, "Reached focused app: " + mFocusedApp); |
| 10536 | return null; |
| 10537 | } |
| 10538 | nextAppIndex--; |
| 10539 | nextApp = mAppTokens.get(nextAppIndex); |
| 10540 | if (nextApp == thisApp) { |
| 10541 | break; |
| 10542 | } |
| 10543 | } |
| 10544 | if (thisApp != nextApp) { |
| 10545 | // Uh oh, the app token doesn't exist! This shouldn't |
| 10546 | // happen, but if it does we can get totally hosed... |
| 10547 | // so restart at the original app. |
| 10548 | nextAppIndex = origAppIndex; |
| 10549 | nextApp = mAppTokens.get(nextAppIndex); |
| 10550 | } |
| 10551 | } |
| 10552 | |
| 10553 | // Dispatch to this window if it is wants key events. |
| 10554 | if (win.canReceiveKeys()) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10555 | if (DEBUG_FOCUS) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10556 | TAG, "Found focus @ " + i + " = " + win); |
| 10557 | result = win; |
| 10558 | break; |
| 10559 | } |
| 10560 | |
| 10561 | i--; |
| 10562 | } |
| 10563 | |
| 10564 | return result; |
| 10565 | } |
| 10566 | |
| 10567 | private void startFreezingDisplayLocked() { |
| 10568 | if (mDisplayFrozen) { |
| 10569 | return; |
| 10570 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10571 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10572 | mScreenFrozenLock.acquire(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10573 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10574 | long now = SystemClock.uptimeMillis(); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10575 | //Slog.i(TAG, "Freezing, gc pending: " + mFreezeGcPending + ", now " + now); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10576 | if (mFreezeGcPending != 0) { |
| 10577 | if (now > (mFreezeGcPending+1000)) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10578 | //Slog.i(TAG, "Gc! " + now + " > " + (mFreezeGcPending+1000)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10579 | mH.removeMessages(H.FORCE_GC); |
| 10580 | Runtime.getRuntime().gc(); |
| 10581 | mFreezeGcPending = now; |
| 10582 | } |
| 10583 | } else { |
| 10584 | mFreezeGcPending = now; |
| 10585 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10586 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10587 | mDisplayFrozen = true; |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 10588 | |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 10589 | mInputMonitor.freezeInputDispatchingLw(); |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 10590 | |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 10591 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
| 10592 | mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10593 | mNextAppTransitionPackage = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10594 | mAppTransitionReady = true; |
| 10595 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10596 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10597 | if (PROFILE_ORIENTATION) { |
| 10598 | File file = new File("/data/system/frozen"); |
| 10599 | Debug.startMethodTracing(file.toString(), 8 * 1024 * 1024); |
| 10600 | } |
| 10601 | Surface.freezeDisplay(0); |
| 10602 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10603 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10604 | private void stopFreezingDisplayLocked() { |
| 10605 | if (!mDisplayFrozen) { |
| 10606 | return; |
| 10607 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10608 | |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 10609 | if (mWaitingForConfig || mAppsFreezingScreen > 0 || mWindowsFreezingScreen) { |
| 10610 | return; |
| 10611 | } |
| 10612 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10613 | mDisplayFrozen = false; |
| 10614 | mH.removeMessages(H.APP_FREEZE_TIMEOUT); |
| 10615 | if (PROFILE_ORIENTATION) { |
| 10616 | Debug.stopMethodTracing(); |
| 10617 | } |
| 10618 | Surface.unfreezeDisplay(0); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10619 | |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 10620 | mInputMonitor.thawInputDispatchingLw(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10621 | |
Christopher Tate | b696aee | 2010-04-02 19:08:30 -0700 | [diff] [blame] | 10622 | // While the display is frozen we don't re-compute the orientation |
| 10623 | // to avoid inconsistent states. However, something interesting |
| 10624 | // could have actually changed during that time so re-evaluate it |
| 10625 | // now to catch that. |
| 10626 | if (updateOrientationFromAppTokensLocked()) { |
| 10627 | mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION); |
| 10628 | } |
| 10629 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10630 | // A little kludge: a lot could have happened while the |
| 10631 | // display was frozen, so now that we are coming back we |
| 10632 | // do a gc so that any remote references the system |
| 10633 | // processes holds on others can be released if they are |
| 10634 | // no longer needed. |
| 10635 | mH.removeMessages(H.FORCE_GC); |
| 10636 | mH.sendMessageDelayed(mH.obtainMessage(H.FORCE_GC), |
| 10637 | 2000); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10638 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10639 | mScreenFrozenLock.release(); |
| 10640 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10641 | |
Dianne Hackborn | b9fb170 | 2010-08-23 16:49:02 -0700 | [diff] [blame] | 10642 | static int getPropertyInt(String[] tokens, int index, int defUnits, int defDps, |
| 10643 | DisplayMetrics dm) { |
| 10644 | if (index < tokens.length) { |
| 10645 | String str = tokens[index]; |
| 10646 | if (str != null && str.length() > 0) { |
| 10647 | try { |
| 10648 | int val = Integer.parseInt(str); |
| 10649 | return val; |
| 10650 | } catch (Exception e) { |
| 10651 | } |
| 10652 | } |
Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 10653 | } |
| 10654 | if (defUnits == TypedValue.COMPLEX_UNIT_PX) { |
| 10655 | return defDps; |
| 10656 | } |
| 10657 | int val = (int)TypedValue.applyDimension(defUnits, defDps, dm); |
| 10658 | return val; |
| 10659 | } |
| 10660 | |
| 10661 | class Watermark { |
Dianne Hackborn | b9fb170 | 2010-08-23 16:49:02 -0700 | [diff] [blame] | 10662 | final String[] mTokens; |
| 10663 | final String mText; |
| 10664 | final Paint mTextPaint; |
| 10665 | final int mTextWidth; |
| 10666 | final int mTextHeight; |
| 10667 | final int mTextAscent; |
| 10668 | final int mTextDescent; |
| 10669 | final int mDeltaX; |
| 10670 | final int mDeltaY; |
Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 10671 | |
Dianne Hackborn | b9fb170 | 2010-08-23 16:49:02 -0700 | [diff] [blame] | 10672 | Surface mSurface; |
| 10673 | int mLastDW; |
| 10674 | int mLastDH; |
| 10675 | boolean mDrawNeeded; |
| 10676 | |
| 10677 | Watermark(SurfaceSession session, String[] tokens) { |
Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 10678 | final DisplayMetrics dm = new DisplayMetrics(); |
| 10679 | mDisplay.getMetrics(dm); |
| 10680 | |
Dianne Hackborn | b9fb170 | 2010-08-23 16:49:02 -0700 | [diff] [blame] | 10681 | if (false) { |
| 10682 | Log.i(TAG, "*********************** WATERMARK"); |
| 10683 | for (int i=0; i<tokens.length; i++) { |
| 10684 | Log.i(TAG, " TOKEN #" + i + ": " + tokens[i]); |
| 10685 | } |
| 10686 | } |
Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 10687 | |
Dianne Hackborn | b9fb170 | 2010-08-23 16:49:02 -0700 | [diff] [blame] | 10688 | mTokens = tokens; |
Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 10689 | |
Dianne Hackborn | b9fb170 | 2010-08-23 16:49:02 -0700 | [diff] [blame] | 10690 | StringBuilder builder = new StringBuilder(32); |
| 10691 | int len = mTokens[0].length(); |
| 10692 | len = len & ~1; |
| 10693 | for (int i=0; i<len; i+=2) { |
| 10694 | int c1 = mTokens[0].charAt(i); |
| 10695 | int c2 = mTokens[0].charAt(i+1); |
| 10696 | if (c1 >= 'a' && c1 <= 'f') c1 = c1 - 'a' + 10; |
| 10697 | else if (c1 >= 'A' && c1 <= 'F') c1 = c1 - 'A' + 10; |
| 10698 | else c1 -= '0'; |
| 10699 | if (c2 >= 'a' && c2 <= 'f') c2 = c2 - 'a' + 10; |
| 10700 | else if (c2 >= 'A' && c2 <= 'F') c2 = c2 - 'A' + 10; |
| 10701 | else c2 -= '0'; |
| 10702 | builder.append((char)(255-((c1*16)+c2))); |
| 10703 | } |
| 10704 | mText = builder.toString(); |
| 10705 | if (false) { |
| 10706 | Log.i(TAG, "Final text: " + mText); |
| 10707 | } |
| 10708 | |
| 10709 | int fontSize = getPropertyInt(tokens, 1, |
| 10710 | TypedValue.COMPLEX_UNIT_DIP, 20, dm); |
| 10711 | |
| 10712 | mTextPaint = new Paint(Paint.ANTI_ALIAS_FLAG); |
| 10713 | mTextPaint.setTextSize(fontSize); |
| 10714 | mTextPaint.setTypeface(Typeface.create(Typeface.SANS_SERIF, Typeface.BOLD)); |
| 10715 | |
| 10716 | FontMetricsInt fm = mTextPaint.getFontMetricsInt(); |
| 10717 | mTextWidth = (int)mTextPaint.measureText(mText); |
| 10718 | mTextAscent = fm.ascent; |
| 10719 | mTextDescent = fm.descent; |
| 10720 | mTextHeight = fm.descent - fm.ascent; |
| 10721 | |
| 10722 | mDeltaX = getPropertyInt(tokens, 2, |
| 10723 | TypedValue.COMPLEX_UNIT_PX, mTextWidth*2, dm); |
| 10724 | mDeltaY = getPropertyInt(tokens, 3, |
| 10725 | TypedValue.COMPLEX_UNIT_PX, mTextHeight*3, dm); |
| 10726 | int shadowColor = getPropertyInt(tokens, 4, |
| 10727 | TypedValue.COMPLEX_UNIT_PX, 0xb0000000, dm); |
| 10728 | int color = getPropertyInt(tokens, 5, |
| 10729 | TypedValue.COMPLEX_UNIT_PX, 0x60ffffff, dm); |
| 10730 | int shadowRadius = getPropertyInt(tokens, 6, |
| 10731 | TypedValue.COMPLEX_UNIT_PX, 7, dm); |
| 10732 | int shadowDx = getPropertyInt(tokens, 8, |
| 10733 | TypedValue.COMPLEX_UNIT_PX, 0, dm); |
| 10734 | int shadowDy = getPropertyInt(tokens, 9, |
| 10735 | TypedValue.COMPLEX_UNIT_PX, 0, dm); |
| 10736 | |
| 10737 | mTextPaint.setColor(color); |
| 10738 | mTextPaint.setShadowLayer(shadowRadius, shadowDx, shadowDy, shadowColor); |
Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 10739 | |
| 10740 | try { |
| 10741 | mSurface = new Surface(session, 0, |
Dianne Hackborn | b9fb170 | 2010-08-23 16:49:02 -0700 | [diff] [blame] | 10742 | "WatermarkSurface", -1, 1, 1, PixelFormat.TRANSLUCENT, 0); |
Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 10743 | mSurface.setLayer(TYPE_LAYER_MULTIPLIER*100); |
Dianne Hackborn | b9fb170 | 2010-08-23 16:49:02 -0700 | [diff] [blame] | 10744 | mSurface.setPosition(0, 0); |
Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 10745 | mSurface.show(); |
| 10746 | } catch (OutOfResourcesException e) { |
| 10747 | } |
| 10748 | } |
| 10749 | |
| 10750 | void positionSurface(int dw, int dh) { |
Dianne Hackborn | b9fb170 | 2010-08-23 16:49:02 -0700 | [diff] [blame] | 10751 | if (mLastDW != dw || mLastDH != dh) { |
| 10752 | mLastDW = dw; |
| 10753 | mLastDH = dh; |
| 10754 | mSurface.setSize(dw, dh); |
| 10755 | mDrawNeeded = true; |
| 10756 | } |
| 10757 | } |
| 10758 | |
| 10759 | void drawIfNeeded() { |
| 10760 | if (mDrawNeeded) { |
| 10761 | final int dw = mLastDW; |
| 10762 | final int dh = mLastDH; |
| 10763 | |
| 10764 | mDrawNeeded = false; |
| 10765 | Rect dirty = new Rect(0, 0, dw, dh); |
| 10766 | Canvas c = null; |
| 10767 | try { |
| 10768 | c = mSurface.lockCanvas(dirty); |
| 10769 | } catch (IllegalArgumentException e) { |
| 10770 | } catch (OutOfResourcesException e) { |
| 10771 | } |
| 10772 | if (c != null) { |
| 10773 | int deltaX = mDeltaX; |
| 10774 | int deltaY = mDeltaY; |
| 10775 | |
| 10776 | // deltaX shouldn't be close to a round fraction of our |
| 10777 | // x step, or else things will line up too much. |
| 10778 | int div = (dw+mTextWidth)/deltaX; |
| 10779 | int rem = (dw+mTextWidth) - (div*deltaX); |
| 10780 | int qdelta = deltaX/4; |
| 10781 | if (rem < qdelta || rem > (deltaX-qdelta)) { |
| 10782 | deltaX += deltaX/3; |
| 10783 | } |
| 10784 | |
| 10785 | int y = -mTextHeight; |
| 10786 | int x = -mTextWidth; |
| 10787 | while (y < (dh+mTextHeight)) { |
| 10788 | c.drawText(mText, x, y, mTextPaint); |
| 10789 | x += deltaX; |
| 10790 | if (x >= dw) { |
| 10791 | x -= (dw+mTextWidth); |
| 10792 | y += deltaY; |
| 10793 | } |
| 10794 | } |
| 10795 | mSurface.unlockCanvasAndPost(c); |
| 10796 | } |
| 10797 | } |
Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 10798 | } |
| 10799 | } |
| 10800 | |
| 10801 | void createWatermark() { |
| 10802 | if (mWatermark != null) { |
| 10803 | return; |
| 10804 | } |
| 10805 | |
Dianne Hackborn | b9fb170 | 2010-08-23 16:49:02 -0700 | [diff] [blame] | 10806 | File file = new File("/system/etc/setup.conf"); |
| 10807 | FileInputStream in = null; |
| 10808 | try { |
| 10809 | in = new FileInputStream(file); |
| 10810 | DataInputStream ind = new DataInputStream(in); |
| 10811 | String line = ind.readLine(); |
| 10812 | if (line != null) { |
| 10813 | String[] toks = line.split("%"); |
| 10814 | if (toks != null && toks.length > 0) { |
| 10815 | mWatermark = new Watermark(mFxSession, toks); |
| 10816 | } |
| 10817 | } |
| 10818 | } catch (FileNotFoundException e) { |
| 10819 | } catch (IOException e) { |
| 10820 | } finally { |
| 10821 | if (in != null) { |
| 10822 | try { |
| 10823 | in.close(); |
| 10824 | } catch (IOException e) { |
| 10825 | } |
| 10826 | } |
Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 10827 | } |
Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 10828 | } |
| 10829 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10830 | @Override |
| 10831 | public void dump(FileDescriptor fd, PrintWriter pw, String[] args) { |
| 10832 | if (mContext.checkCallingOrSelfPermission("android.permission.DUMP") |
| 10833 | != PackageManager.PERMISSION_GRANTED) { |
| 10834 | pw.println("Permission Denial: can't dump WindowManager from from pid=" |
| 10835 | + Binder.getCallingPid() |
| 10836 | + ", uid=" + Binder.getCallingUid()); |
| 10837 | return; |
| 10838 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10839 | |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 10840 | mInputManager.dump(pw); |
Dianne Hackborn | a2e9226 | 2010-03-02 17:19:29 -0800 | [diff] [blame] | 10841 | pw.println(" "); |
| 10842 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10843 | synchronized(mWindowMap) { |
| 10844 | pw.println("Current Window Manager state:"); |
| 10845 | for (int i=mWindows.size()-1; i>=0; i--) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 10846 | WindowState w = mWindows.get(i); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10847 | pw.print(" Window #"); pw.print(i); pw.print(' '); |
| 10848 | pw.print(w); pw.println(":"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10849 | w.dump(pw, " "); |
| 10850 | } |
| 10851 | if (mInputMethodDialogs.size() > 0) { |
| 10852 | pw.println(" "); |
| 10853 | pw.println(" Input method dialogs:"); |
| 10854 | for (int i=mInputMethodDialogs.size()-1; i>=0; i--) { |
| 10855 | WindowState w = mInputMethodDialogs.get(i); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10856 | 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] | 10857 | } |
| 10858 | } |
| 10859 | if (mPendingRemove.size() > 0) { |
| 10860 | pw.println(" "); |
| 10861 | pw.println(" Remove pending for:"); |
| 10862 | for (int i=mPendingRemove.size()-1; i>=0; i--) { |
| 10863 | WindowState w = mPendingRemove.get(i); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10864 | pw.print(" Remove #"); pw.print(i); pw.print(' '); |
| 10865 | pw.print(w); pw.println(":"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10866 | w.dump(pw, " "); |
| 10867 | } |
| 10868 | } |
| 10869 | if (mForceRemoves != null && mForceRemoves.size() > 0) { |
| 10870 | pw.println(" "); |
| 10871 | pw.println(" Windows force removing:"); |
| 10872 | for (int i=mForceRemoves.size()-1; i>=0; i--) { |
| 10873 | WindowState w = mForceRemoves.get(i); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10874 | pw.print(" Removing #"); pw.print(i); pw.print(' '); |
| 10875 | pw.print(w); pw.println(":"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10876 | w.dump(pw, " "); |
| 10877 | } |
| 10878 | } |
| 10879 | if (mDestroySurface.size() > 0) { |
| 10880 | pw.println(" "); |
| 10881 | pw.println(" Windows waiting to destroy their surface:"); |
| 10882 | for (int i=mDestroySurface.size()-1; i>=0; i--) { |
| 10883 | WindowState w = mDestroySurface.get(i); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10884 | pw.print(" Destroy #"); pw.print(i); pw.print(' '); |
| 10885 | pw.print(w); pw.println(":"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10886 | w.dump(pw, " "); |
| 10887 | } |
| 10888 | } |
| 10889 | if (mLosingFocus.size() > 0) { |
| 10890 | pw.println(" "); |
| 10891 | pw.println(" Windows losing focus:"); |
| 10892 | for (int i=mLosingFocus.size()-1; i>=0; i--) { |
| 10893 | WindowState w = mLosingFocus.get(i); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10894 | pw.print(" Losing #"); pw.print(i); pw.print(' '); |
| 10895 | pw.print(w); pw.println(":"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10896 | w.dump(pw, " "); |
| 10897 | } |
| 10898 | } |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 10899 | if (mResizingWindows.size() > 0) { |
| 10900 | pw.println(" "); |
| 10901 | pw.println(" Windows waiting to resize:"); |
| 10902 | for (int i=mResizingWindows.size()-1; i>=0; i--) { |
| 10903 | WindowState w = mResizingWindows.get(i); |
| 10904 | pw.print(" Resizing #"); pw.print(i); pw.print(' '); |
| 10905 | pw.print(w); pw.println(":"); |
| 10906 | w.dump(pw, " "); |
| 10907 | } |
| 10908 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10909 | if (mSessions.size() > 0) { |
| 10910 | pw.println(" "); |
| 10911 | pw.println(" All active sessions:"); |
| 10912 | Iterator<Session> it = mSessions.iterator(); |
| 10913 | while (it.hasNext()) { |
| 10914 | Session s = it.next(); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10915 | pw.print(" Session "); pw.print(s); pw.println(':'); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10916 | s.dump(pw, " "); |
| 10917 | } |
| 10918 | } |
| 10919 | if (mTokenMap.size() > 0) { |
| 10920 | pw.println(" "); |
| 10921 | pw.println(" All tokens:"); |
| 10922 | Iterator<WindowToken> it = mTokenMap.values().iterator(); |
| 10923 | while (it.hasNext()) { |
| 10924 | WindowToken token = it.next(); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10925 | pw.print(" Token "); pw.print(token.token); pw.println(':'); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10926 | token.dump(pw, " "); |
| 10927 | } |
| 10928 | } |
| 10929 | if (mTokenList.size() > 0) { |
| 10930 | pw.println(" "); |
| 10931 | pw.println(" Window token list:"); |
| 10932 | for (int i=0; i<mTokenList.size(); i++) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10933 | pw.print(" #"); pw.print(i); pw.print(": "); |
| 10934 | pw.println(mTokenList.get(i)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10935 | } |
| 10936 | } |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 10937 | if (mWallpaperTokens.size() > 0) { |
| 10938 | pw.println(" "); |
| 10939 | pw.println(" Wallpaper tokens:"); |
| 10940 | for (int i=mWallpaperTokens.size()-1; i>=0; i--) { |
| 10941 | WindowToken token = mWallpaperTokens.get(i); |
| 10942 | pw.print(" Wallpaper #"); pw.print(i); |
| 10943 | pw.print(' '); pw.print(token); pw.println(':'); |
| 10944 | token.dump(pw, " "); |
| 10945 | } |
| 10946 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10947 | if (mAppTokens.size() > 0) { |
| 10948 | pw.println(" "); |
| 10949 | pw.println(" Application tokens in Z order:"); |
| 10950 | for (int i=mAppTokens.size()-1; i>=0; i--) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10951 | pw.print(" App #"); pw.print(i); pw.print(": "); |
| 10952 | pw.println(mAppTokens.get(i)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10953 | } |
| 10954 | } |
| 10955 | if (mFinishedStarting.size() > 0) { |
| 10956 | pw.println(" "); |
| 10957 | pw.println(" Finishing start of application tokens:"); |
| 10958 | for (int i=mFinishedStarting.size()-1; i>=0; i--) { |
| 10959 | WindowToken token = mFinishedStarting.get(i); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10960 | pw.print(" Finished Starting #"); pw.print(i); |
| 10961 | pw.print(' '); pw.print(token); pw.println(':'); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10962 | token.dump(pw, " "); |
| 10963 | } |
| 10964 | } |
| 10965 | if (mExitingTokens.size() > 0) { |
| 10966 | pw.println(" "); |
| 10967 | pw.println(" Exiting tokens:"); |
| 10968 | for (int i=mExitingTokens.size()-1; i>=0; i--) { |
| 10969 | WindowToken token = mExitingTokens.get(i); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10970 | pw.print(" Exiting #"); pw.print(i); |
| 10971 | pw.print(' '); pw.print(token); pw.println(':'); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10972 | token.dump(pw, " "); |
| 10973 | } |
| 10974 | } |
| 10975 | if (mExitingAppTokens.size() > 0) { |
| 10976 | pw.println(" "); |
| 10977 | pw.println(" Exiting application tokens:"); |
| 10978 | for (int i=mExitingAppTokens.size()-1; i>=0; i--) { |
| 10979 | WindowToken token = mExitingAppTokens.get(i); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10980 | pw.print(" Exiting App #"); pw.print(i); |
| 10981 | pw.print(' '); pw.print(token); pw.println(':'); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10982 | token.dump(pw, " "); |
| 10983 | } |
| 10984 | } |
| 10985 | pw.println(" "); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10986 | pw.print(" mCurrentFocus="); pw.println(mCurrentFocus); |
| 10987 | pw.print(" mLastFocus="); pw.println(mLastFocus); |
| 10988 | pw.print(" mFocusedApp="); pw.println(mFocusedApp); |
| 10989 | pw.print(" mInputMethodTarget="); pw.println(mInputMethodTarget); |
| 10990 | pw.print(" mInputMethodWindow="); pw.println(mInputMethodWindow); |
Dianne Hackborn | f21adf6 | 2009-08-13 10:20:21 -0700 | [diff] [blame] | 10991 | pw.print(" mWallpaperTarget="); pw.println(mWallpaperTarget); |
Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 10992 | if (mLowerWallpaperTarget != null && mUpperWallpaperTarget != null) { |
| 10993 | pw.print(" mLowerWallpaperTarget="); pw.println(mLowerWallpaperTarget); |
| 10994 | pw.print(" mUpperWallpaperTarget="); pw.println(mUpperWallpaperTarget); |
| 10995 | } |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 10996 | pw.print(" mCurConfiguration="); pw.println(this.mCurConfiguration); |
| 10997 | pw.print(" mInTouchMode="); pw.print(mInTouchMode); |
| 10998 | pw.print(" mLayoutSeq="); pw.println(mLayoutSeq); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 10999 | pw.print(" mSystemBooted="); pw.print(mSystemBooted); |
| 11000 | pw.print(" mDisplayEnabled="); pw.println(mDisplayEnabled); |
| 11001 | pw.print(" mLayoutNeeded="); pw.print(mLayoutNeeded); |
| 11002 | pw.print(" mBlurShown="); pw.println(mBlurShown); |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11003 | if (mDimAnimator != null) { |
| 11004 | mDimAnimator.printTo(pw); |
| 11005 | } else { |
Dianne Hackborn | a2e9226 | 2010-03-02 17:19:29 -0800 | [diff] [blame] | 11006 | pw.println( " no DimAnimator "); |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11007 | } |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11008 | pw.print(" mInputMethodAnimLayerAdjustment="); |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 11009 | pw.print(mInputMethodAnimLayerAdjustment); |
| 11010 | pw.print(" mWallpaperAnimLayerAdjustment="); |
| 11011 | pw.println(mWallpaperAnimLayerAdjustment); |
Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 11012 | pw.print(" mLastWallpaperX="); pw.print(mLastWallpaperX); |
| 11013 | pw.print(" mLastWallpaperY="); pw.println(mLastWallpaperY); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11014 | pw.print(" mDisplayFrozen="); pw.print(mDisplayFrozen); |
| 11015 | pw.print(" mWindowsFreezingScreen="); pw.print(mWindowsFreezingScreen); |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 11016 | pw.print(" mAppsFreezingScreen="); pw.print(mAppsFreezingScreen); |
| 11017 | pw.print(" mWaitingForConfig="); pw.println(mWaitingForConfig); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11018 | pw.print(" mRotation="); pw.print(mRotation); |
| 11019 | pw.print(", mForcedAppOrientation="); pw.print(mForcedAppOrientation); |
| 11020 | pw.print(", mRequestedRotation="); pw.println(mRequestedRotation); |
| 11021 | pw.print(" mAnimationPending="); pw.print(mAnimationPending); |
| 11022 | pw.print(" mWindowAnimationScale="); pw.print(mWindowAnimationScale); |
| 11023 | pw.print(" mTransitionWindowAnimationScale="); pw.println(mTransitionAnimationScale); |
| 11024 | pw.print(" mNextAppTransition=0x"); |
| 11025 | pw.print(Integer.toHexString(mNextAppTransition)); |
| 11026 | pw.print(", mAppTransitionReady="); pw.print(mAppTransitionReady); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 11027 | pw.print(", mAppTransitionRunning="); pw.print(mAppTransitionRunning); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11028 | pw.print(", mAppTransitionTimeout="); pw.println( mAppTransitionTimeout); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 11029 | if (mNextAppTransitionPackage != null) { |
| 11030 | pw.print(" mNextAppTransitionPackage="); |
| 11031 | pw.print(mNextAppTransitionPackage); |
| 11032 | pw.print(", mNextAppTransitionEnter=0x"); |
| 11033 | pw.print(Integer.toHexString(mNextAppTransitionEnter)); |
| 11034 | pw.print(", mNextAppTransitionExit=0x"); |
| 11035 | pw.print(Integer.toHexString(mNextAppTransitionExit)); |
| 11036 | } |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11037 | pw.print(" mStartingIconInTransition="); pw.print(mStartingIconInTransition); |
| 11038 | pw.print(", mSkipAppTransitionAnimation="); pw.println(mSkipAppTransitionAnimation); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 11039 | if (mLastEnterAnimToken != null || mLastEnterAnimToken != null) { |
| 11040 | pw.print(" mLastEnterAnimToken="); pw.print(mLastEnterAnimToken); |
| 11041 | pw.print(", mLastEnterAnimParams="); pw.println(mLastEnterAnimParams); |
| 11042 | } |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11043 | if (mOpeningApps.size() > 0) { |
| 11044 | pw.print(" mOpeningApps="); pw.println(mOpeningApps); |
| 11045 | } |
| 11046 | if (mClosingApps.size() > 0) { |
| 11047 | pw.print(" mClosingApps="); pw.println(mClosingApps); |
| 11048 | } |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 11049 | if (mToTopApps.size() > 0) { |
| 11050 | pw.print(" mToTopApps="); pw.println(mToTopApps); |
| 11051 | } |
| 11052 | if (mToBottomApps.size() > 0) { |
| 11053 | pw.print(" mToBottomApps="); pw.println(mToBottomApps); |
| 11054 | } |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11055 | pw.print(" DisplayWidth="); pw.print(mDisplay.getWidth()); |
| 11056 | pw.print(" DisplayHeight="); pw.println(mDisplay.getHeight()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11057 | } |
| 11058 | } |
| 11059 | |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 11060 | // 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] | 11061 | public void monitor() { |
| 11062 | synchronized (mWindowMap) { } |
Mike Lockwood | 983ee09 | 2009-11-22 01:42:24 -0500 | [diff] [blame] | 11063 | synchronized (mKeyguardTokenWatcher) { } |
Dianne Hackborn | ddca3ee | 2009-07-23 19:01:31 -0700 | [diff] [blame] | 11064 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 11065 | |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11066 | /** |
| 11067 | * DimAnimator class that controls the dim animation. This holds the surface and |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 11068 | * all state used for dim animation. |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11069 | */ |
| 11070 | private static class DimAnimator { |
| 11071 | Surface mDimSurface; |
| 11072 | boolean mDimShown = false; |
| 11073 | float mDimCurrentAlpha; |
| 11074 | float mDimTargetAlpha; |
| 11075 | float mDimDeltaPerMs; |
| 11076 | long mLastDimAnimTime; |
Dianne Hackborn | f83c555 | 2010-03-31 22:19:32 -0700 | [diff] [blame] | 11077 | |
| 11078 | int mLastDimWidth, mLastDimHeight; |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11079 | |
| 11080 | DimAnimator (SurfaceSession session) { |
| 11081 | if (mDimSurface == null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 11082 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11083 | + mDimSurface + ": CREATE"); |
| 11084 | try { |
Mathias Agopian | 5d26c1e | 2010-03-01 16:09:43 -0800 | [diff] [blame] | 11085 | mDimSurface = new Surface(session, 0, |
| 11086 | "DimSurface", |
| 11087 | -1, 16, 16, PixelFormat.OPAQUE, |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11088 | Surface.FX_SURFACE_DIM); |
Maciej Białka | 9ee5c22 | 2010-03-24 10:25:40 +0100 | [diff] [blame] | 11089 | mDimSurface.setAlpha(0.0f); |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11090 | } catch (Exception e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 11091 | Slog.e(TAG, "Exception creating Dim surface", e); |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11092 | } |
| 11093 | } |
| 11094 | } |
| 11095 | |
| 11096 | /** |
| 11097 | * Show the dim surface. |
| 11098 | */ |
| 11099 | void show(int dw, int dh) { |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 11100 | if (!mDimShown) { |
| 11101 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface + ": SHOW pos=(0,0) (" + |
| 11102 | dw + "x" + dh + ")"); |
| 11103 | mDimShown = true; |
| 11104 | try { |
Dianne Hackborn | f83c555 | 2010-03-31 22:19:32 -0700 | [diff] [blame] | 11105 | mLastDimWidth = dw; |
| 11106 | mLastDimHeight = dh; |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 11107 | mDimSurface.setPosition(0, 0); |
| 11108 | mDimSurface.setSize(dw, dh); |
| 11109 | mDimSurface.show(); |
| 11110 | } catch (RuntimeException e) { |
| 11111 | Slog.w(TAG, "Failure showing dim surface", e); |
| 11112 | } |
Dianne Hackborn | f83c555 | 2010-03-31 22:19:32 -0700 | [diff] [blame] | 11113 | } else if (mLastDimWidth != dw || mLastDimHeight != dh) { |
| 11114 | mLastDimWidth = dw; |
| 11115 | mLastDimHeight = dh; |
| 11116 | mDimSurface.setSize(dw, dh); |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11117 | } |
| 11118 | } |
| 11119 | |
| 11120 | /** |
| 11121 | * Set's the dim surface's layer and update dim parameters that will be used in |
| 11122 | * {@link updateSurface} after all windows are examined. |
| 11123 | */ |
| 11124 | void updateParameters(WindowState w, long currentTime) { |
| 11125 | mDimSurface.setLayer(w.mAnimLayer-1); |
| 11126 | |
| 11127 | final float target = w.mExiting ? 0 : w.mAttrs.dimAmount; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 11128 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 11129 | + ": layer=" + (w.mAnimLayer-1) + " target=" + target); |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11130 | if (mDimTargetAlpha != target) { |
| 11131 | // If the desired dim level has changed, then |
| 11132 | // start an animation to it. |
| 11133 | mLastDimAnimTime = currentTime; |
| 11134 | long duration = (w.mAnimating && w.mAnimation != null) |
| 11135 | ? w.mAnimation.computeDurationHint() |
| 11136 | : DEFAULT_DIM_DURATION; |
| 11137 | if (target > mDimTargetAlpha) { |
| 11138 | // This is happening behind the activity UI, |
| 11139 | // so we can make it run a little longer to |
| 11140 | // give a stronger impression without disrupting |
| 11141 | // the user. |
| 11142 | duration *= DIM_DURATION_MULTIPLIER; |
| 11143 | } |
| 11144 | if (duration < 1) { |
| 11145 | // Don't divide by zero |
| 11146 | duration = 1; |
| 11147 | } |
| 11148 | mDimTargetAlpha = target; |
| 11149 | mDimDeltaPerMs = (mDimTargetAlpha-mDimCurrentAlpha) / duration; |
| 11150 | } |
| 11151 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 11152 | |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11153 | /** |
| 11154 | * Updating the surface's alpha. Returns true if the animation continues, or returns |
| 11155 | * false when the animation is finished and the dim surface is hidden. |
| 11156 | */ |
| 11157 | boolean updateSurface(boolean dimming, long currentTime, boolean displayFrozen) { |
| 11158 | if (!dimming) { |
| 11159 | if (mDimTargetAlpha != 0) { |
| 11160 | mLastDimAnimTime = currentTime; |
| 11161 | mDimTargetAlpha = 0; |
| 11162 | mDimDeltaPerMs = (-mDimCurrentAlpha) / DEFAULT_DIM_DURATION; |
| 11163 | } |
| 11164 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 11165 | |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11166 | boolean animating = false; |
| 11167 | if (mLastDimAnimTime != 0) { |
| 11168 | mDimCurrentAlpha += mDimDeltaPerMs |
| 11169 | * (currentTime-mLastDimAnimTime); |
| 11170 | boolean more = true; |
| 11171 | if (displayFrozen) { |
| 11172 | // If the display is frozen, there is no reason to animate. |
| 11173 | more = false; |
| 11174 | } else if (mDimDeltaPerMs > 0) { |
| 11175 | if (mDimCurrentAlpha > mDimTargetAlpha) { |
| 11176 | more = false; |
| 11177 | } |
| 11178 | } else if (mDimDeltaPerMs < 0) { |
| 11179 | if (mDimCurrentAlpha < mDimTargetAlpha) { |
| 11180 | more = false; |
| 11181 | } |
| 11182 | } else { |
| 11183 | more = false; |
| 11184 | } |
| 11185 | |
| 11186 | // Do we need to continue animating? |
| 11187 | if (more) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 11188 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11189 | + mDimSurface + ": alpha=" + mDimCurrentAlpha); |
| 11190 | mLastDimAnimTime = currentTime; |
| 11191 | mDimSurface.setAlpha(mDimCurrentAlpha); |
| 11192 | animating = true; |
| 11193 | } else { |
| 11194 | mDimCurrentAlpha = mDimTargetAlpha; |
| 11195 | mLastDimAnimTime = 0; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 11196 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11197 | + mDimSurface + ": final alpha=" + mDimCurrentAlpha); |
| 11198 | mDimSurface.setAlpha(mDimCurrentAlpha); |
| 11199 | if (!dimming) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 11200 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11201 | + ": HIDE"); |
| 11202 | try { |
| 11203 | mDimSurface.hide(); |
| 11204 | } catch (RuntimeException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 11205 | Slog.w(TAG, "Illegal argument exception hiding dim surface"); |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11206 | } |
| 11207 | mDimShown = false; |
| 11208 | } |
| 11209 | } |
| 11210 | } |
| 11211 | return animating; |
| 11212 | } |
| 11213 | |
| 11214 | public void printTo(PrintWriter pw) { |
| 11215 | pw.print(" mDimShown="); pw.print(mDimShown); |
| 11216 | pw.print(" current="); pw.print(mDimCurrentAlpha); |
| 11217 | pw.print(" target="); pw.print(mDimTargetAlpha); |
| 11218 | pw.print(" delta="); pw.print(mDimDeltaPerMs); |
| 11219 | pw.print(" lastAnimTime="); pw.println(mLastDimAnimTime); |
| 11220 | } |
| 11221 | } |
| 11222 | |
| 11223 | /** |
| 11224 | * Animation that fade in after 0.5 interpolate time, or fade out in reverse order. |
| 11225 | * This is used for opening/closing transition for apps in compatible mode. |
| 11226 | */ |
| 11227 | private static class FadeInOutAnimation extends Animation { |
| 11228 | int mWidth; |
| 11229 | boolean mFadeIn; |
| 11230 | |
| 11231 | public FadeInOutAnimation(boolean fadeIn) { |
| 11232 | setInterpolator(new AccelerateInterpolator()); |
| 11233 | setDuration(DEFAULT_FADE_IN_OUT_DURATION); |
| 11234 | mFadeIn = fadeIn; |
| 11235 | } |
| 11236 | |
| 11237 | @Override |
| 11238 | protected void applyTransformation(float interpolatedTime, Transformation t) { |
| 11239 | float x = interpolatedTime; |
| 11240 | if (!mFadeIn) { |
| 11241 | x = 1.0f - x; // reverse the interpolation for fade out |
| 11242 | } |
| 11243 | if (x < 0.5) { |
| 11244 | // move the window out of the screen. |
| 11245 | t.getMatrix().setTranslate(mWidth, 0); |
| 11246 | } else { |
| 11247 | t.getMatrix().setTranslate(0, 0);// show |
| 11248 | t.setAlpha((x - 0.5f) * 2); |
| 11249 | } |
| 11250 | } |
| 11251 | |
| 11252 | @Override |
| 11253 | public void initialize(int width, int height, int parentWidth, int parentHeight) { |
| 11254 | // width is the screen width {@see AppWindowToken#stepAnimatinoLocked} |
| 11255 | mWidth = width; |
| 11256 | } |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11257 | |
| 11258 | @Override |
Mitsuru Oshima | 5a2b91d | 2009-07-16 16:30:02 -0700 | [diff] [blame] | 11259 | public int getZAdjustment() { |
| 11260 | return Animation.ZORDER_TOP; |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11261 | } |
| 11262 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11263 | } |