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 | |
Dianne Hackborn | a924dc0d | 2011-02-17 14:22:17 -0800 | [diff] [blame] | 17 | package com.android.server.wm; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 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; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 25 | import static android.view.WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE; |
| 26 | import static android.view.WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 27 | import static android.view.WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 28 | import static android.view.WindowManager.LayoutParams.LAST_APPLICATION_WINDOW; |
| 29 | import static android.view.WindowManager.LayoutParams.LAST_SUB_WINDOW; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 30 | import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_STARTING; |
| 31 | import static android.view.WindowManager.LayoutParams.TYPE_BASE_APPLICATION; |
| 32 | import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD; |
| 33 | import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 34 | import static android.view.WindowManager.LayoutParams.TYPE_WALLPAPER; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 35 | |
| 36 | import com.android.internal.app.IBatteryStats; |
| 37 | import com.android.internal.policy.PolicyManager; |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 38 | import com.android.internal.policy.impl.PhoneWindowManager; |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 39 | import com.android.internal.view.BaseInputHandler; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 40 | import com.android.internal.view.IInputContext; |
| 41 | import com.android.internal.view.IInputMethodClient; |
| 42 | import com.android.internal.view.IInputMethodManager; |
Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 43 | import com.android.internal.view.WindowManagerPolicyThread; |
Dianne Hackborn | a924dc0d | 2011-02-17 14:22:17 -0800 | [diff] [blame] | 44 | import com.android.server.AttributeCache; |
| 45 | import com.android.server.EventLogTags; |
| 46 | import com.android.server.PowerManagerService; |
| 47 | import com.android.server.Watchdog; |
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; |
Joe Onorato | ac0ee89 | 2011-01-30 15:38:30 -0800 | [diff] [blame] | 53 | import android.app.StatusBarManager; |
Jim Miller | d6b5705 | 2010-06-07 17:52:42 -0700 | [diff] [blame] | 54 | import android.app.admin.DevicePolicyManager; |
Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 55 | import android.content.BroadcastReceiver; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 56 | import android.content.Context; |
Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 57 | import android.content.Intent; |
| 58 | import android.content.IntentFilter; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 59 | import android.content.pm.ActivityInfo; |
| 60 | import android.content.pm.PackageManager; |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 61 | import android.content.res.CompatibilityInfo; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 62 | import android.content.res.Configuration; |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 63 | import android.graphics.Bitmap; |
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; |
| 66 | import android.graphics.PixelFormat; |
| 67 | import android.graphics.Rect; |
| 68 | import android.graphics.Region; |
| 69 | import android.os.BatteryStats; |
| 70 | import android.os.Binder; |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 71 | import android.os.Bundle; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 72 | import android.os.Debug; |
| 73 | import android.os.Handler; |
| 74 | import android.os.IBinder; |
| 75 | import android.os.LocalPowerManager; |
| 76 | import android.os.Looper; |
| 77 | import android.os.Message; |
| 78 | import android.os.Parcel; |
| 79 | import android.os.ParcelFileDescriptor; |
| 80 | import android.os.Power; |
| 81 | import android.os.PowerManager; |
| 82 | import android.os.Process; |
| 83 | import android.os.RemoteException; |
| 84 | import android.os.ServiceManager; |
Brad Fitzpatrick | ec062f6 | 2010-11-03 09:56:54 -0700 | [diff] [blame] | 85 | import android.os.StrictMode; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 86 | import android.os.SystemClock; |
| 87 | import android.os.SystemProperties; |
| 88 | import android.os.TokenWatcher; |
| 89 | import android.provider.Settings; |
Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 90 | import android.util.DisplayMetrics; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 91 | import android.util.EventLog; |
Jim Miller | d6b5705 | 2010-06-07 17:52:42 -0700 | [diff] [blame] | 92 | import android.util.Log; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 93 | import android.util.Slog; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 94 | import android.util.SparseIntArray; |
Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 95 | import android.util.TypedValue; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 96 | import android.view.Display; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 97 | import android.view.IApplicationToken; |
| 98 | import android.view.IOnKeyguardExitResult; |
| 99 | import android.view.IRotationWatcher; |
| 100 | import android.view.IWindow; |
| 101 | import android.view.IWindowManager; |
| 102 | import android.view.IWindowSession; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 103 | import android.view.InputChannel; |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 104 | import android.view.InputDevice; |
Jeff Brown | bbda99d | 2010-07-28 15:48:59 -0700 | [diff] [blame] | 105 | import android.view.InputEvent; |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 106 | import android.view.InputHandler; |
| 107 | import android.view.InputQueue; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 108 | import android.view.KeyEvent; |
| 109 | import android.view.MotionEvent; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 110 | import android.view.Surface; |
| 111 | import android.view.SurfaceSession; |
| 112 | import android.view.View; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 113 | import android.view.WindowManager; |
| 114 | import android.view.WindowManagerImpl; |
| 115 | import android.view.WindowManagerPolicy; |
| 116 | import android.view.WindowManager.LayoutParams; |
| 117 | import android.view.animation.Animation; |
| 118 | import android.view.animation.AnimationUtils; |
| 119 | import android.view.animation.Transformation; |
| 120 | |
| 121 | import java.io.BufferedWriter; |
Dianne Hackborn | b9fb170 | 2010-08-23 16:49:02 -0700 | [diff] [blame] | 122 | import java.io.DataInputStream; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 123 | import java.io.File; |
| 124 | import java.io.FileDescriptor; |
Dianne Hackborn | b9fb170 | 2010-08-23 16:49:02 -0700 | [diff] [blame] | 125 | import java.io.FileInputStream; |
| 126 | import java.io.FileNotFoundException; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 127 | import java.io.IOException; |
| 128 | import java.io.OutputStream; |
| 129 | import java.io.OutputStreamWriter; |
| 130 | import java.io.PrintWriter; |
| 131 | import java.io.StringWriter; |
| 132 | import java.net.Socket; |
| 133 | import java.util.ArrayList; |
| 134 | import java.util.HashMap; |
| 135 | import java.util.HashSet; |
| 136 | import java.util.Iterator; |
| 137 | import java.util.List; |
| 138 | |
| 139 | /** {@hide} */ |
Dianne Hackborn | ddca3ee | 2009-07-23 19:01:31 -0700 | [diff] [blame] | 140 | public class WindowManagerService extends IWindowManager.Stub |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 141 | implements Watchdog.Monitor { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 142 | static final String TAG = "WindowManager"; |
| 143 | static final boolean DEBUG = false; |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 144 | static final boolean DEBUG_ADD_REMOVE = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 145 | static final boolean DEBUG_FOCUS = false; |
| 146 | static final boolean DEBUG_ANIM = false; |
Dianne Hackborn | 9b52a21 | 2009-12-11 14:51:35 -0800 | [diff] [blame] | 147 | static final boolean DEBUG_LAYOUT = false; |
Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 148 | static final boolean DEBUG_RESIZE = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 149 | static final boolean DEBUG_LAYERS = false; |
| 150 | static final boolean DEBUG_INPUT = false; |
| 151 | static final boolean DEBUG_INPUT_METHOD = false; |
| 152 | static final boolean DEBUG_VISIBILITY = false; |
Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 153 | static final boolean DEBUG_WINDOW_MOVEMENT = false; |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 154 | static final boolean DEBUG_TOKEN_MOVEMENT = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 155 | static final boolean DEBUG_ORIENTATION = false; |
Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 156 | static final boolean DEBUG_CONFIGURATION = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 157 | static final boolean DEBUG_APP_TRANSITIONS = false; |
| 158 | static final boolean DEBUG_STARTING_WINDOW = false; |
| 159 | static final boolean DEBUG_REORDER = false; |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 160 | static final boolean DEBUG_WALLPAPER = false; |
Christopher Tate | 994ef92 | 2011-01-12 20:06:07 -0800 | [diff] [blame] | 161 | static final boolean DEBUG_DRAG = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 162 | static final boolean SHOW_TRANSACTIONS = false; |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 163 | static final boolean HIDE_STACK_CRAWLS = true; |
Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 164 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 165 | static final boolean PROFILE_ORIENTATION = false; |
| 166 | static final boolean BLUR = true; |
Dave Bort | cfe6524 | 2009-04-09 14:51:04 -0700 | [diff] [blame] | 167 | static final boolean localLOGV = DEBUG; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 168 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 169 | /** How much to multiply the policy's type layer, to reserve room |
| 170 | * for multiple windows of the same type and Z-ordering adjustment |
| 171 | * with TYPE_LAYER_OFFSET. */ |
| 172 | static final int TYPE_LAYER_MULTIPLIER = 10000; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 173 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 174 | /** Offset from TYPE_LAYER_MULTIPLIER for moving a group of windows above |
| 175 | * or below others in the same layer. */ |
| 176 | static final int TYPE_LAYER_OFFSET = 1000; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 177 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 178 | /** How much to increment the layer for each window, to reserve room |
| 179 | * for effect surfaces between them. |
| 180 | */ |
| 181 | static final int WINDOW_LAYER_MULTIPLIER = 5; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 182 | |
Dianne Hackborn | de75cb4 | 2011-03-02 17:11:21 -0800 | [diff] [blame] | 183 | /** |
| 184 | * Dim surface layer is immediately below target window. |
| 185 | */ |
| 186 | static final int LAYER_OFFSET_DIM = 1; |
| 187 | |
| 188 | /** |
| 189 | * Blur surface layer is immediately below dim layer. |
| 190 | */ |
| 191 | static final int LAYER_OFFSET_BLUR = 2; |
| 192 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 193 | /** The maximum length we will accept for a loaded animation duration: |
| 194 | * this is 10 seconds. |
| 195 | */ |
| 196 | static final int MAX_ANIMATION_DURATION = 10*1000; |
| 197 | |
| 198 | /** Amount of time (in milliseconds) to animate the dim surface from one |
| 199 | * value to another, when no window animation is driving it. |
| 200 | */ |
| 201 | static final int DEFAULT_DIM_DURATION = 200; |
| 202 | |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 203 | /** Amount of time (in milliseconds) to animate the fade-in-out transition for |
| 204 | * compatible windows. |
| 205 | */ |
| 206 | static final int DEFAULT_FADE_IN_OUT_DURATION = 400; |
| 207 | |
Dianne Hackborn | a111187 | 2010-11-23 20:55:11 -0800 | [diff] [blame] | 208 | /** |
| 209 | * If true, the window manager will do its own custom freezing and general |
| 210 | * management of the screen during rotation. |
| 211 | */ |
| 212 | static final boolean CUSTOM_SCREEN_ROTATION = true; |
| 213 | |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 214 | // Maximum number of milliseconds to wait for input event injection. |
| 215 | // FIXME is this value reasonable? |
| 216 | private static final int INJECTION_TIMEOUT_MILLIS = 30 * 1000; |
Jeff Brown | b09abc1 | 2011-01-13 21:08:27 -0800 | [diff] [blame] | 217 | |
| 218 | // Maximum number of milliseconds to wait for input devices to be enumerated before |
| 219 | // proceding with safe mode detection. |
| 220 | private static final int INPUT_DEVICES_READY_FOR_SAFE_MODE_DETECTION_TIMEOUT_MILLIS = 1000; |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 221 | |
| 222 | // Default input dispatching timeout in nanoseconds. |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 223 | static final long DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS = 5000 * 1000000L; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 224 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 225 | static final int UPDATE_FOCUS_NORMAL = 0; |
| 226 | static final int UPDATE_FOCUS_WILL_ASSIGN_LAYERS = 1; |
| 227 | static final int UPDATE_FOCUS_PLACING_SURFACES = 2; |
| 228 | static final int UPDATE_FOCUS_WILL_PLACE_SURFACES = 3; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 229 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 230 | private static final String SYSTEM_SECURE = "ro.secure"; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 231 | private static final String SYSTEM_DEBUGGABLE = "ro.debuggable"; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 232 | |
| 233 | /** |
| 234 | * Condition waited on by {@link #reenableKeyguard} to know the call to |
| 235 | * the window policy has finished. |
Mike Lockwood | 983ee09 | 2009-11-22 01:42:24 -0500 | [diff] [blame] | 236 | * This is set to true only if mKeyguardTokenWatcher.acquired() has |
| 237 | * actually disabled the keyguard. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 238 | */ |
Mike Lockwood | 983ee09 | 2009-11-22 01:42:24 -0500 | [diff] [blame] | 239 | private boolean mKeyguardDisabled = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 240 | |
Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 241 | private static final int ALLOW_DISABLE_YES = 1; |
| 242 | private static final int ALLOW_DISABLE_NO = 0; |
| 243 | private static final int ALLOW_DISABLE_UNKNOWN = -1; // check with DevicePolicyManager |
| 244 | private int mAllowDisableKeyguard = ALLOW_DISABLE_UNKNOWN; // sync'd by mKeyguardTokenWatcher |
| 245 | |
Mike Lockwood | 983ee09 | 2009-11-22 01:42:24 -0500 | [diff] [blame] | 246 | final TokenWatcher mKeyguardTokenWatcher = new TokenWatcher( |
| 247 | new Handler(), "WindowManagerService.mKeyguardTokenWatcher") { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 248 | public void acquired() { |
Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 249 | if (shouldAllowDisableKeyguard()) { |
| 250 | mPolicy.enableKeyguard(false); |
| 251 | mKeyguardDisabled = true; |
| 252 | } else { |
| 253 | Log.v(TAG, "Not disabling keyguard since device policy is enforced"); |
| 254 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 255 | } |
| 256 | public void released() { |
Dianne Hackborn | a33e3f7 | 2009-09-29 17:28:24 -0700 | [diff] [blame] | 257 | mPolicy.enableKeyguard(true); |
Mike Lockwood | 983ee09 | 2009-11-22 01:42:24 -0500 | [diff] [blame] | 258 | synchronized (mKeyguardTokenWatcher) { |
| 259 | mKeyguardDisabled = false; |
| 260 | mKeyguardTokenWatcher.notifyAll(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 261 | } |
| 262 | } |
| 263 | }; |
| 264 | |
Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 265 | final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() { |
| 266 | @Override |
| 267 | public void onReceive(Context context, Intent intent) { |
| 268 | mPolicy.enableKeyguard(true); |
| 269 | synchronized(mKeyguardTokenWatcher) { |
| 270 | // lazily evaluate this next time we're asked to disable keyguard |
| 271 | mAllowDisableKeyguard = ALLOW_DISABLE_UNKNOWN; |
| 272 | mKeyguardDisabled = false; |
| 273 | } |
| 274 | } |
| 275 | }; |
| 276 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 277 | final Context mContext; |
| 278 | |
| 279 | final boolean mHaveInputMethods; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 280 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 281 | final boolean mLimitedAlphaCompositing; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 282 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 283 | final WindowManagerPolicy mPolicy = PolicyManager.makeNewWindowManager(); |
| 284 | |
| 285 | final IActivityManager mActivityManager; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 286 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 287 | final IBatteryStats mBatteryStats; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 288 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 289 | /** |
| 290 | * All currently active sessions with clients. |
| 291 | */ |
| 292 | final HashSet<Session> mSessions = new HashSet<Session>(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 293 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 294 | /** |
| 295 | * Mapping from an IWindow IBinder to the server's Window object. |
| 296 | * This is also used as the lock for all of our state. |
| 297 | */ |
| 298 | final HashMap<IBinder, WindowState> mWindowMap = new HashMap<IBinder, WindowState>(); |
| 299 | |
| 300 | /** |
| 301 | * Mapping from a token IBinder to a WindowToken object. |
| 302 | */ |
| 303 | final HashMap<IBinder, WindowToken> mTokenMap = |
| 304 | new HashMap<IBinder, WindowToken>(); |
| 305 | |
| 306 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 307 | * Window tokens that are in the process of exiting, but still |
| 308 | * on screen for animations. |
| 309 | */ |
| 310 | final ArrayList<WindowToken> mExitingTokens = new ArrayList<WindowToken>(); |
| 311 | |
| 312 | /** |
| 313 | * Z-ordered (bottom-most first) list of all application tokens, for |
| 314 | * controlling the ordering of windows in different applications. This |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 315 | * contains AppWindowToken objects. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 316 | */ |
| 317 | final ArrayList<AppWindowToken> mAppTokens = new ArrayList<AppWindowToken>(); |
| 318 | |
| 319 | /** |
| 320 | * Application tokens that are in the process of exiting, but still |
| 321 | * on screen for animations. |
| 322 | */ |
| 323 | final ArrayList<AppWindowToken> mExitingAppTokens = new ArrayList<AppWindowToken>(); |
| 324 | |
| 325 | /** |
| 326 | * List of window tokens that have finished starting their application, |
| 327 | * and now need to have the policy remove their windows. |
| 328 | */ |
| 329 | final ArrayList<AppWindowToken> mFinishedStarting = new ArrayList<AppWindowToken>(); |
| 330 | |
| 331 | /** |
| 332 | * Z-ordered (bottom-most first) list of all Window objects. |
| 333 | */ |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 334 | final ArrayList<WindowState> mWindows = new ArrayList<WindowState>(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 335 | |
| 336 | /** |
| 337 | * Windows that are being resized. Used so we can tell the client about |
| 338 | * the resize after closing the transaction in which we resized the |
| 339 | * underlying surface. |
| 340 | */ |
| 341 | final ArrayList<WindowState> mResizingWindows = new ArrayList<WindowState>(); |
| 342 | |
| 343 | /** |
| 344 | * Windows whose animations have ended and now must be removed. |
| 345 | */ |
| 346 | final ArrayList<WindowState> mPendingRemove = new ArrayList<WindowState>(); |
| 347 | |
| 348 | /** |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 349 | * Used when processing mPendingRemove to avoid working on the original array. |
| 350 | */ |
| 351 | WindowState[] mPendingRemoveTmp = new WindowState[20]; |
| 352 | |
| 353 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 354 | * Windows whose surface should be destroyed. |
| 355 | */ |
| 356 | final ArrayList<WindowState> mDestroySurface = new ArrayList<WindowState>(); |
| 357 | |
| 358 | /** |
| 359 | * Windows that have lost input focus and are waiting for the new |
| 360 | * focus window to be displayed before they are told about this. |
| 361 | */ |
| 362 | ArrayList<WindowState> mLosingFocus = new ArrayList<WindowState>(); |
| 363 | |
| 364 | /** |
| 365 | * This is set when we have run out of memory, and will either be an empty |
| 366 | * list or contain windows that need to be force removed. |
| 367 | */ |
| 368 | ArrayList<WindowState> mForceRemoves; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 369 | |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 370 | /** |
| 371 | * Used when rebuilding window list to keep track of windows that have |
| 372 | * been removed. |
| 373 | */ |
| 374 | WindowState[] mRebuildTmp = new WindowState[20]; |
| 375 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 376 | IInputMethodManager mInputMethodManager; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 377 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 378 | SurfaceSession mFxSession; |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 379 | private DimAnimator mDimAnimator = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 380 | Surface mBlurSurface; |
| 381 | boolean mBlurShown; |
Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 382 | Watermark mWatermark; |
Brad Fitzpatrick | 6804433 | 2010-11-22 18:19:48 -0800 | [diff] [blame] | 383 | StrictModeFlash mStrictModeFlash; |
Dianne Hackborn | a111187 | 2010-11-23 20:55:11 -0800 | [diff] [blame] | 384 | ScreenRotationAnimation mScreenRotationAnimation; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 385 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 386 | int mTransactionSequence = 0; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 387 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 388 | final float[] mTmpFloats = new float[9]; |
| 389 | |
| 390 | boolean mSafeMode; |
| 391 | boolean mDisplayEnabled = false; |
| 392 | boolean mSystemBooted = false; |
Christopher Tate | b696aee | 2010-04-02 19:08:30 -0700 | [diff] [blame] | 393 | int mInitialDisplayWidth = 0; |
| 394 | int mInitialDisplayHeight = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 395 | int mRotation = 0; |
| 396 | int mRequestedRotation = 0; |
| 397 | int mForcedAppOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
Dianne Hackborn | 321ae68 | 2009-03-27 16:16:03 -0700 | [diff] [blame] | 398 | int mLastRotationFlags; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 399 | ArrayList<IRotationWatcher> mRotationWatchers |
| 400 | = new ArrayList<IRotationWatcher>(); |
Dianne Hackborn | 89ba675 | 2011-01-23 16:51:16 -0800 | [diff] [blame] | 401 | int mDeferredRotation; |
| 402 | int mDeferredRotationAnimFlags; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 403 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 404 | boolean mLayoutNeeded = true; |
| 405 | boolean mAnimationPending = false; |
| 406 | boolean mDisplayFrozen = false; |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 407 | boolean mWaitingForConfig = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 408 | boolean mWindowsFreezingScreen = false; |
| 409 | long mFreezeGcPending = 0; |
| 410 | int mAppsFreezingScreen = 0; |
| 411 | |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 412 | int mLayoutSeq = 0; |
| 413 | |
Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 414 | // State while inside of layoutAndPlaceSurfacesLocked(). |
| 415 | boolean mFocusMayChange; |
| 416 | |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 417 | Configuration mCurConfiguration = new Configuration(); |
| 418 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 419 | // This is held as long as we have the screen frozen, to give us time to |
| 420 | // perform a rotation animation when turning off shows the lock screen which |
| 421 | // changes the orientation. |
| 422 | PowerManager.WakeLock mScreenFrozenLock; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 423 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 424 | // State management of app transitions. When we are preparing for a |
| 425 | // transition, mNextAppTransition will be the kind of transition to |
| 426 | // perform or TRANSIT_NONE if we are not waiting. If we are waiting, |
| 427 | // mOpeningApps and mClosingApps are the lists of tokens that will be |
| 428 | // made visible or hidden at the next transition. |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 429 | int mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 430 | String mNextAppTransitionPackage; |
| 431 | int mNextAppTransitionEnter; |
| 432 | int mNextAppTransitionExit; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 433 | boolean mAppTransitionReady = false; |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 434 | boolean mAppTransitionRunning = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 435 | boolean mAppTransitionTimeout = false; |
| 436 | boolean mStartingIconInTransition = false; |
| 437 | boolean mSkipAppTransitionAnimation = false; |
| 438 | final ArrayList<AppWindowToken> mOpeningApps = new ArrayList<AppWindowToken>(); |
| 439 | final ArrayList<AppWindowToken> mClosingApps = new ArrayList<AppWindowToken>(); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 440 | final ArrayList<AppWindowToken> mToTopApps = new ArrayList<AppWindowToken>(); |
| 441 | final ArrayList<AppWindowToken> mToBottomApps = new ArrayList<AppWindowToken>(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 442 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 443 | Display mDisplay; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 444 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 445 | H mH = new H(); |
| 446 | |
| 447 | WindowState mCurrentFocus = null; |
| 448 | WindowState mLastFocus = null; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 449 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 450 | // This just indicates the window the input method is on top of, not |
| 451 | // necessarily the window its input is going to. |
| 452 | WindowState mInputMethodTarget = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 453 | boolean mInputMethodTargetWaitingAnim; |
| 454 | int mInputMethodAnimLayerAdjustment; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 455 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 456 | WindowState mInputMethodWindow = null; |
| 457 | final ArrayList<WindowState> mInputMethodDialogs = new ArrayList<WindowState>(); |
| 458 | |
Jeff Brown | 2992ea7 | 2011-01-28 22:04:14 -0800 | [diff] [blame] | 459 | boolean mHardKeyboardAvailable; |
| 460 | boolean mHardKeyboardEnabled; |
| 461 | OnHardKeyboardStatusChangeListener mHardKeyboardStatusChangeListener; |
| 462 | |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 463 | final ArrayList<WindowToken> mWallpaperTokens = new ArrayList<WindowToken>(); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 464 | |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 465 | // If non-null, this is the currently visible window that is associated |
| 466 | // with the wallpaper. |
| 467 | WindowState mWallpaperTarget = null; |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 468 | // If non-null, we are in the middle of animating from one wallpaper target |
| 469 | // to another, and this is the lower one in Z-order. |
| 470 | WindowState mLowerWallpaperTarget = null; |
| 471 | // If non-null, we are in the middle of animating from one wallpaper target |
| 472 | // to another, and this is the higher one in Z-order. |
| 473 | WindowState mUpperWallpaperTarget = null; |
Dianne Hackborn | 6c8e20f | 2010-11-09 18:59:09 -0800 | [diff] [blame] | 474 | // Window currently running an animation that has requested it be detached |
| 475 | // from the wallpaper. This means we need to ensure the wallpaper is |
| 476 | // visible behind it in case it animates in a way that would allow it to be |
| 477 | // seen. |
| 478 | WindowState mWindowDetachedWallpaper = null; |
Dianne Hackborn | de75cb4 | 2011-03-02 17:11:21 -0800 | [diff] [blame] | 479 | DimSurface mWindowAnimationBackgroundSurface = null; |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 480 | int mWallpaperAnimLayerAdjustment; |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 481 | float mLastWallpaperX = -1; |
| 482 | float mLastWallpaperY = -1; |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 483 | float mLastWallpaperXStep = -1; |
| 484 | float mLastWallpaperYStep = -1; |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 485 | // This is set when we are waiting for a wallpaper to tell us it is done |
| 486 | // changing its scroll position. |
| 487 | WindowState mWaitingOnWallpaper; |
| 488 | // The last time we had a timeout when waiting for a wallpaper. |
| 489 | long mLastWallpaperTimeoutTime; |
| 490 | // We give a wallpaper up to 150ms to finish scrolling. |
| 491 | static final long WALLPAPER_TIMEOUT = 150; |
| 492 | // Time we wait after a timeout before trying to wait again. |
| 493 | static final long WALLPAPER_TIMEOUT_RECOVERY = 10000; |
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 | AppWindowToken mFocusedApp = null; |
| 496 | |
| 497 | PowerManagerService mPowerManager; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 498 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 499 | float mWindowAnimationScale = 1.0f; |
| 500 | float mTransitionAnimationScale = 1.0f; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 501 | |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 502 | final InputManager mInputManager; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 503 | |
| 504 | // Who is holding the screen on. |
| 505 | Session mHoldingScreenOn; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 506 | PowerManager.WakeLock mHoldingScreenWakeLock; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 507 | |
Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 508 | boolean mTurnOnScreen; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 509 | |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 510 | DragState mDragState = null; |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 511 | final InputHandler mDragInputHandler = new BaseInputHandler() { |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 512 | @Override |
Jeff Brown | 3915bb8 | 2010-11-05 15:02:16 -0700 | [diff] [blame] | 513 | public void handleMotion(MotionEvent event, InputQueue.FinishedCallback finishedCallback) { |
| 514 | boolean handled = false; |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 515 | try { |
Jeff Brown | 3915bb8 | 2010-11-05 15:02:16 -0700 | [diff] [blame] | 516 | if ((event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0 |
| 517 | && mDragState != null) { |
| 518 | boolean endDrag = false; |
| 519 | final float newX = event.getRawX(); |
| 520 | final float newY = event.getRawY(); |
| 521 | |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 522 | switch (event.getAction()) { |
| 523 | case MotionEvent.ACTION_DOWN: { |
| 524 | if (DEBUG_DRAG) { |
| 525 | Slog.w(TAG, "Unexpected ACTION_DOWN in drag layer"); |
| 526 | } |
| 527 | } break; |
| 528 | |
| 529 | case MotionEvent.ACTION_MOVE: { |
| 530 | synchronized (mWindowMap) { |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 531 | // move the surface and tell the involved window(s) where we are |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 532 | mDragState.notifyMoveLw(newX, newY); |
| 533 | } |
| 534 | } break; |
| 535 | |
| 536 | case MotionEvent.ACTION_UP: { |
| 537 | if (DEBUG_DRAG) Slog.d(TAG, "Got UP on move channel; dropping at " |
| 538 | + newX + "," + newY); |
| 539 | synchronized (mWindowMap) { |
Chris Tate | d4533f1 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 540 | endDrag = mDragState.notifyDropLw(newX, newY); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 541 | } |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 542 | } break; |
| 543 | |
| 544 | case MotionEvent.ACTION_CANCEL: { |
| 545 | if (DEBUG_DRAG) Slog.d(TAG, "Drag cancelled!"); |
| 546 | endDrag = true; |
| 547 | } break; |
| 548 | } |
| 549 | |
| 550 | if (endDrag) { |
| 551 | if (DEBUG_DRAG) Slog.d(TAG, "Drag ended; tearing down state"); |
| 552 | // tell all the windows that the drag has ended |
Chris Tate | 5994359 | 2010-10-11 20:33:44 -0700 | [diff] [blame] | 553 | synchronized (mWindowMap) { |
Chris Tate | d4533f1 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 554 | mDragState.endDragLw(); |
Chris Tate | 5994359 | 2010-10-11 20:33:44 -0700 | [diff] [blame] | 555 | } |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 556 | } |
Jeff Brown | 3915bb8 | 2010-11-05 15:02:16 -0700 | [diff] [blame] | 557 | |
| 558 | handled = true; |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 559 | } |
| 560 | } catch (Exception e) { |
| 561 | Slog.e(TAG, "Exception caught by drag handleMotion", e); |
| 562 | } finally { |
Jeff Brown | 3915bb8 | 2010-11-05 15:02:16 -0700 | [diff] [blame] | 563 | finishedCallback.finished(handled); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 564 | } |
| 565 | } |
| 566 | }; |
| 567 | |
| 568 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 569 | * Whether the UI is currently running in touch mode (not showing |
| 570 | * navigational focus because the user is directly pressing the screen). |
| 571 | */ |
| 572 | boolean mInTouchMode = false; |
| 573 | |
| 574 | private ViewServer mViewServer; |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 575 | private ArrayList<WindowChangeListener> mWindowChangeListeners = |
| 576 | new ArrayList<WindowChangeListener>(); |
| 577 | private boolean mWindowsChanged = false; |
| 578 | |
| 579 | public interface WindowChangeListener { |
| 580 | public void windowsChanged(); |
Konstantin Lopyrev | 6e0f65f | 2010-07-14 14:55:33 -0700 | [diff] [blame] | 581 | public void focusChanged(); |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 582 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 583 | |
Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 584 | final Configuration mTempConfiguration = new Configuration(); |
Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 585 | int mScreenLayout = Configuration.SCREENLAYOUT_SIZE_UNDEFINED; |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 586 | |
| 587 | // The frame use to limit the size of the app running in compatibility mode. |
| 588 | Rect mCompatibleScreenFrame = new Rect(); |
| 589 | // The surface used to fill the outer rim of the app running in compatibility mode. |
| 590 | Surface mBackgroundFillerSurface = null; |
Dianne Hackborn | ac1471a | 2011-02-03 13:46:06 -0800 | [diff] [blame] | 591 | WindowState mBackgroundFillerTarget = null; |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 592 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 593 | public static WindowManagerService main(Context context, |
| 594 | PowerManagerService pm, boolean haveInputMethods) { |
| 595 | WMThread thr = new WMThread(context, pm, haveInputMethods); |
| 596 | thr.start(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 597 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 598 | synchronized (thr) { |
| 599 | while (thr.mService == null) { |
| 600 | try { |
| 601 | thr.wait(); |
| 602 | } catch (InterruptedException e) { |
| 603 | } |
| 604 | } |
Jozef BABJAK | 06e57b5 | 2011-01-20 08:09:25 +0100 | [diff] [blame] | 605 | return thr.mService; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 606 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 607 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 608 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 609 | static class WMThread extends Thread { |
| 610 | WindowManagerService mService; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 611 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 612 | private final Context mContext; |
| 613 | private final PowerManagerService mPM; |
| 614 | private final boolean mHaveInputMethods; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 615 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 616 | public WMThread(Context context, PowerManagerService pm, |
| 617 | boolean haveInputMethods) { |
| 618 | super("WindowManager"); |
| 619 | mContext = context; |
| 620 | mPM = pm; |
| 621 | mHaveInputMethods = haveInputMethods; |
| 622 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 623 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 624 | public void run() { |
| 625 | Looper.prepare(); |
| 626 | WindowManagerService s = new WindowManagerService(mContext, mPM, |
| 627 | mHaveInputMethods); |
| 628 | android.os.Process.setThreadPriority( |
| 629 | android.os.Process.THREAD_PRIORITY_DISPLAY); |
Christopher Tate | 160edb3 | 2010-06-30 17:46:30 -0700 | [diff] [blame] | 630 | android.os.Process.setCanSelfBackground(false); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 631 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 632 | synchronized (this) { |
| 633 | mService = s; |
| 634 | notifyAll(); |
| 635 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 636 | |
Brad Fitzpatrick | ec062f6 | 2010-11-03 09:56:54 -0700 | [diff] [blame] | 637 | // For debug builds, log event loop stalls to dropbox for analysis. |
| 638 | if (StrictMode.conditionallyEnableDebugLogging()) { |
| 639 | Slog.i(TAG, "Enabled StrictMode logging for WMThread's Looper"); |
| 640 | } |
| 641 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 642 | Looper.loop(); |
| 643 | } |
| 644 | } |
| 645 | |
| 646 | static class PolicyThread extends Thread { |
| 647 | private final WindowManagerPolicy mPolicy; |
| 648 | private final WindowManagerService mService; |
| 649 | private final Context mContext; |
| 650 | private final PowerManagerService mPM; |
| 651 | boolean mRunning = false; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 652 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 653 | public PolicyThread(WindowManagerPolicy policy, |
| 654 | WindowManagerService service, Context context, |
| 655 | PowerManagerService pm) { |
| 656 | super("WindowManagerPolicy"); |
| 657 | mPolicy = policy; |
| 658 | mService = service; |
| 659 | mContext = context; |
| 660 | mPM = pm; |
| 661 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 662 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 663 | public void run() { |
| 664 | Looper.prepare(); |
Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 665 | WindowManagerPolicyThread.set(this, Looper.myLooper()); |
| 666 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 667 | //Looper.myLooper().setMessageLogging(new LogPrinter( |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 668 | // Log.VERBOSE, "WindowManagerPolicy", Log.LOG_ID_SYSTEM)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 669 | android.os.Process.setThreadPriority( |
| 670 | android.os.Process.THREAD_PRIORITY_FOREGROUND); |
Christopher Tate | 160edb3 | 2010-06-30 17:46:30 -0700 | [diff] [blame] | 671 | android.os.Process.setCanSelfBackground(false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 672 | mPolicy.init(mContext, mService, mPM); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 673 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 674 | synchronized (this) { |
| 675 | mRunning = true; |
| 676 | notifyAll(); |
| 677 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 678 | |
Brad Fitzpatrick | ec062f6 | 2010-11-03 09:56:54 -0700 | [diff] [blame] | 679 | // For debug builds, log event loop stalls to dropbox for analysis. |
| 680 | if (StrictMode.conditionallyEnableDebugLogging()) { |
| 681 | Slog.i(TAG, "Enabled StrictMode for PolicyThread's Looper"); |
| 682 | } |
| 683 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 684 | Looper.loop(); |
| 685 | } |
| 686 | } |
| 687 | |
| 688 | private WindowManagerService(Context context, PowerManagerService pm, |
| 689 | boolean haveInputMethods) { |
| 690 | mContext = context; |
| 691 | mHaveInputMethods = haveInputMethods; |
| 692 | mLimitedAlphaCompositing = context.getResources().getBoolean( |
| 693 | com.android.internal.R.bool.config_sf_limitedAlpha); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 694 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 695 | mPowerManager = pm; |
| 696 | mPowerManager.setPolicy(mPolicy); |
| 697 | PowerManager pmc = (PowerManager)context.getSystemService(Context.POWER_SERVICE); |
| 698 | mScreenFrozenLock = pmc.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, |
| 699 | "SCREEN_FROZEN"); |
| 700 | mScreenFrozenLock.setReferenceCounted(false); |
| 701 | |
| 702 | mActivityManager = ActivityManagerNative.getDefault(); |
| 703 | mBatteryStats = BatteryStatsService.getService(); |
| 704 | |
| 705 | // Get persisted window scale setting |
| 706 | mWindowAnimationScale = Settings.System.getFloat(context.getContentResolver(), |
| 707 | Settings.System.WINDOW_ANIMATION_SCALE, mWindowAnimationScale); |
| 708 | mTransitionAnimationScale = Settings.System.getFloat(context.getContentResolver(), |
| 709 | Settings.System.TRANSITION_ANIMATION_SCALE, mTransitionAnimationScale); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 710 | |
Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 711 | // Track changes to DevicePolicyManager state so we can enable/disable keyguard. |
| 712 | IntentFilter filter = new IntentFilter(); |
| 713 | filter.addAction(DevicePolicyManager.ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED); |
| 714 | mContext.registerReceiver(mBroadcastReceiver, filter); |
| 715 | |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 716 | mHoldingScreenWakeLock = pmc.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK, |
| 717 | "KEEP_SCREEN_ON_FLAG"); |
| 718 | mHoldingScreenWakeLock.setReferenceCounted(false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 719 | |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 720 | mInputManager = new InputManager(context, this); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 721 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 722 | PolicyThread thr = new PolicyThread(mPolicy, this, context, pm); |
| 723 | thr.start(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 724 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 725 | synchronized (thr) { |
| 726 | while (!thr.mRunning) { |
| 727 | try { |
| 728 | thr.wait(); |
| 729 | } catch (InterruptedException e) { |
| 730 | } |
| 731 | } |
| 732 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 733 | |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 734 | mInputManager.start(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 735 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 736 | // Add ourself to the Watchdog monitors. |
| 737 | Watchdog.getInstance().addMonitor(this); |
| 738 | } |
| 739 | |
| 740 | @Override |
| 741 | public boolean onTransact(int code, Parcel data, Parcel reply, int flags) |
| 742 | throws RemoteException { |
| 743 | try { |
| 744 | return super.onTransact(code, data, reply, flags); |
| 745 | } catch (RuntimeException e) { |
| 746 | // The window manager only throws security exceptions, so let's |
| 747 | // log all others. |
| 748 | if (!(e instanceof SecurityException)) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 749 | Slog.e(TAG, "Window Manager Crash", e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 750 | } |
| 751 | throw e; |
| 752 | } |
| 753 | } |
| 754 | |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 755 | private void placeWindowAfter(WindowState pos, WindowState window) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 756 | final int i = mWindows.indexOf(pos); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 757 | if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 758 | TAG, "Adding window " + window + " at " |
| 759 | + (i+1) + " of " + mWindows.size() + " (after " + pos + ")"); |
| 760 | mWindows.add(i+1, window); |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 761 | mWindowsChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 762 | } |
| 763 | |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 764 | private void placeWindowBefore(WindowState pos, WindowState window) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 765 | final int i = mWindows.indexOf(pos); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 766 | if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 767 | TAG, "Adding window " + window + " at " |
| 768 | + i + " of " + mWindows.size() + " (before " + pos + ")"); |
| 769 | mWindows.add(i, window); |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 770 | mWindowsChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 771 | } |
| 772 | |
| 773 | //This method finds out the index of a window that has the same app token as |
| 774 | //win. used for z ordering the windows in mWindows |
| 775 | private int findIdxBasedOnAppTokens(WindowState win) { |
| 776 | //use a local variable to cache mWindows |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 777 | ArrayList<WindowState> localmWindows = mWindows; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 778 | int jmax = localmWindows.size(); |
| 779 | if(jmax == 0) { |
| 780 | return -1; |
| 781 | } |
| 782 | for(int j = (jmax-1); j >= 0; j--) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 783 | WindowState wentry = localmWindows.get(j); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 784 | if(wentry.mAppToken == win.mAppToken) { |
| 785 | return j; |
| 786 | } |
| 787 | } |
| 788 | return -1; |
| 789 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 790 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 791 | private void addWindowToListInOrderLocked(WindowState win, boolean addToToken) { |
| 792 | final IWindow client = win.mClient; |
| 793 | final WindowToken token = win.mToken; |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 794 | final ArrayList<WindowState> localmWindows = mWindows; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 795 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 796 | final int N = localmWindows.size(); |
| 797 | final WindowState attached = win.mAttachedWindow; |
| 798 | int i; |
| 799 | if (attached == null) { |
| 800 | int tokenWindowsPos = token.windows.size(); |
| 801 | if (token.appWindowToken != null) { |
| 802 | int index = tokenWindowsPos-1; |
| 803 | if (index >= 0) { |
| 804 | // If this application has existing windows, we |
| 805 | // simply place the new window on top of them... but |
| 806 | // keep the starting window on top. |
| 807 | if (win.mAttrs.type == TYPE_BASE_APPLICATION) { |
| 808 | // Base windows go behind everything else. |
| 809 | placeWindowBefore(token.windows.get(0), win); |
| 810 | tokenWindowsPos = 0; |
| 811 | } else { |
| 812 | AppWindowToken atoken = win.mAppToken; |
| 813 | if (atoken != null && |
| 814 | token.windows.get(index) == atoken.startingWindow) { |
| 815 | placeWindowBefore(token.windows.get(index), win); |
| 816 | tokenWindowsPos--; |
| 817 | } else { |
| 818 | int newIdx = findIdxBasedOnAppTokens(win); |
| 819 | if(newIdx != -1) { |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 820 | //there is a window above this one associated with the same |
| 821 | //apptoken note that the window could be a floating window |
| 822 | //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] | 823 | //windows associated with this token. |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 824 | if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) { |
| 825 | Slog.v(TAG, "Adding window " + win + " at " |
| 826 | + (newIdx+1) + " of " + N); |
| 827 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 828 | localmWindows.add(newIdx+1, win); |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 829 | mWindowsChanged = true; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 830 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 831 | } |
| 832 | } |
| 833 | } else { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 834 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 835 | TAG, "Figuring out where to add app window " |
| 836 | + client.asBinder() + " (token=" + token + ")"); |
| 837 | // Figure out where the window should go, based on the |
| 838 | // order of applications. |
| 839 | final int NA = mAppTokens.size(); |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 840 | WindowState pos = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 841 | for (i=NA-1; i>=0; i--) { |
| 842 | AppWindowToken t = mAppTokens.get(i); |
| 843 | if (t == token) { |
| 844 | i--; |
| 845 | break; |
| 846 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 847 | |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 848 | // We haven't reached the token yet; if this token |
| 849 | // is not going to the bottom and has windows, we can |
| 850 | // use it as an anchor for when we do reach the token. |
| 851 | if (!t.sendingToBottom && t.windows.size() > 0) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 852 | pos = t.windows.get(0); |
| 853 | } |
| 854 | } |
| 855 | // We now know the index into the apps. If we found |
| 856 | // an app window above, that gives us the position; else |
| 857 | // we need to look some more. |
| 858 | if (pos != null) { |
| 859 | // Move behind any windows attached to this one. |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 860 | WindowToken atoken = mTokenMap.get(pos.mClient.asBinder()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 861 | if (atoken != null) { |
| 862 | final int NC = atoken.windows.size(); |
| 863 | if (NC > 0) { |
| 864 | WindowState bottom = atoken.windows.get(0); |
| 865 | if (bottom.mSubLayer < 0) { |
| 866 | pos = bottom; |
| 867 | } |
| 868 | } |
| 869 | } |
| 870 | placeWindowBefore(pos, win); |
| 871 | } else { |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 872 | // Continue looking down until we find the first |
| 873 | // token that has windows. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 874 | while (i >= 0) { |
| 875 | AppWindowToken t = mAppTokens.get(i); |
| 876 | final int NW = t.windows.size(); |
| 877 | if (NW > 0) { |
| 878 | pos = t.windows.get(NW-1); |
| 879 | break; |
| 880 | } |
| 881 | i--; |
| 882 | } |
| 883 | if (pos != null) { |
| 884 | // Move in front of any windows attached to this |
| 885 | // one. |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 886 | WindowToken atoken = mTokenMap.get(pos.mClient.asBinder()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 887 | if (atoken != null) { |
| 888 | final int NC = atoken.windows.size(); |
| 889 | if (NC > 0) { |
| 890 | WindowState top = atoken.windows.get(NC-1); |
| 891 | if (top.mSubLayer >= 0) { |
| 892 | pos = top; |
| 893 | } |
| 894 | } |
| 895 | } |
| 896 | placeWindowAfter(pos, win); |
| 897 | } else { |
| 898 | // Just search for the start of this layer. |
| 899 | final int myLayer = win.mBaseLayer; |
| 900 | for (i=0; i<N; i++) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 901 | WindowState w = localmWindows.get(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 902 | if (w.mBaseLayer > myLayer) { |
| 903 | break; |
| 904 | } |
| 905 | } |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 906 | if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) { |
| 907 | Slog.v(TAG, "Adding window " + win + " at " |
| 908 | + i + " of " + N); |
| 909 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 910 | localmWindows.add(i, win); |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 911 | mWindowsChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 912 | } |
| 913 | } |
| 914 | } |
| 915 | } else { |
| 916 | // Figure out where window should go, based on layer. |
| 917 | final int myLayer = win.mBaseLayer; |
| 918 | for (i=N-1; i>=0; i--) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 919 | if (localmWindows.get(i).mBaseLayer <= myLayer) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 920 | i++; |
| 921 | break; |
| 922 | } |
| 923 | } |
| 924 | if (i < 0) i = 0; |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 925 | if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) Slog.v( |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 926 | TAG, "Adding window " + win + " at " |
| 927 | + i + " of " + N); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 928 | localmWindows.add(i, win); |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 929 | mWindowsChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 930 | } |
| 931 | if (addToToken) { |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 932 | if (DEBUG_ADD_REMOVE) Slog.v(TAG, "Adding " + win + " to " + token); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 933 | token.windows.add(tokenWindowsPos, win); |
| 934 | } |
| 935 | |
| 936 | } else { |
| 937 | // Figure out this window's ordering relative to the window |
| 938 | // it is attached to. |
| 939 | final int NA = token.windows.size(); |
| 940 | final int sublayer = win.mSubLayer; |
| 941 | int largestSublayer = Integer.MIN_VALUE; |
| 942 | WindowState windowWithLargestSublayer = null; |
| 943 | for (i=0; i<NA; i++) { |
| 944 | WindowState w = token.windows.get(i); |
| 945 | final int wSublayer = w.mSubLayer; |
| 946 | if (wSublayer >= largestSublayer) { |
| 947 | largestSublayer = wSublayer; |
| 948 | windowWithLargestSublayer = w; |
| 949 | } |
| 950 | if (sublayer < 0) { |
| 951 | // For negative sublayers, we go below all windows |
| 952 | // in the same sublayer. |
| 953 | if (wSublayer >= sublayer) { |
| 954 | if (addToToken) { |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 955 | if (DEBUG_ADD_REMOVE) Slog.v(TAG, "Adding " + win + " to " + token); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 956 | token.windows.add(i, win); |
| 957 | } |
| 958 | placeWindowBefore( |
| 959 | wSublayer >= 0 ? attached : w, win); |
| 960 | break; |
| 961 | } |
| 962 | } else { |
| 963 | // For positive sublayers, we go above all windows |
| 964 | // in the same sublayer. |
| 965 | if (wSublayer > sublayer) { |
| 966 | if (addToToken) { |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 967 | if (DEBUG_ADD_REMOVE) Slog.v(TAG, "Adding " + win + " to " + token); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 968 | token.windows.add(i, win); |
| 969 | } |
| 970 | placeWindowBefore(w, win); |
| 971 | break; |
| 972 | } |
| 973 | } |
| 974 | } |
| 975 | if (i >= NA) { |
| 976 | if (addToToken) { |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 977 | if (DEBUG_ADD_REMOVE) Slog.v(TAG, "Adding " + win + " to " + token); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 978 | token.windows.add(win); |
| 979 | } |
| 980 | if (sublayer < 0) { |
| 981 | placeWindowBefore(attached, win); |
| 982 | } else { |
| 983 | placeWindowAfter(largestSublayer >= 0 |
| 984 | ? windowWithLargestSublayer |
| 985 | : attached, |
| 986 | win); |
| 987 | } |
| 988 | } |
| 989 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 990 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 991 | if (win.mAppToken != null && addToToken) { |
| 992 | win.mAppToken.allAppWindows.add(win); |
| 993 | } |
| 994 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 995 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 996 | static boolean canBeImeTarget(WindowState w) { |
| 997 | final int fl = w.mAttrs.flags |
| 998 | & (FLAG_NOT_FOCUSABLE|FLAG_ALT_FOCUSABLE_IM); |
Dianne Hackborn | e75d872 | 2011-01-27 19:37:40 -0800 | [diff] [blame] | 999 | if (fl == 0 || fl == (FLAG_NOT_FOCUSABLE|FLAG_ALT_FOCUSABLE_IM) |
| 1000 | || w.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING) { |
| 1001 | if (DEBUG_INPUT_METHOD) { |
| 1002 | Slog.i(TAG, "isVisibleOrAdding " + w + ": " + w.isVisibleOrAdding()); |
| 1003 | if (!w.isVisibleOrAdding()) { |
| 1004 | Slog.i(TAG, " mSurface=" + w.mSurface + " reportDestroy=" + w.mReportDestroySurface |
| 1005 | + " relayoutCalled=" + w.mRelayoutCalled + " viewVis=" + w.mViewVisibility |
| 1006 | + " policyVis=" + w.mPolicyVisibility + " attachHid=" + w.mAttachedHidden |
| 1007 | + " exiting=" + w.mExiting + " destroying=" + w.mDestroying); |
| 1008 | if (w.mAppToken != null) { |
| 1009 | Slog.i(TAG, " mAppToken.hiddenRequested=" + w.mAppToken.hiddenRequested); |
| 1010 | } |
| 1011 | } |
| 1012 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1013 | return w.isVisibleOrAdding(); |
| 1014 | } |
| 1015 | return false; |
| 1016 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1017 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1018 | int findDesiredInputMethodWindowIndexLocked(boolean willMove) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1019 | final ArrayList<WindowState> localmWindows = mWindows; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1020 | final int N = localmWindows.size(); |
| 1021 | WindowState w = null; |
| 1022 | int i = N; |
| 1023 | while (i > 0) { |
| 1024 | i--; |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1025 | w = localmWindows.get(i); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1026 | |
Dianne Hackborn | e75d872 | 2011-01-27 19:37:40 -0800 | [diff] [blame] | 1027 | if (DEBUG_INPUT_METHOD && willMove) Slog.i(TAG, "Checking window @" + i |
| 1028 | + " " + w + " fl=0x" + Integer.toHexString(w.mAttrs.flags)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1029 | if (canBeImeTarget(w)) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1030 | //Slog.i(TAG, "Putting input method here!"); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1031 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1032 | // Yet more tricksyness! If this window is a "starting" |
| 1033 | // window, we do actually want to be on top of it, but |
| 1034 | // it is not -really- where input will go. So if the caller |
| 1035 | // is not actually looking to move the IME, look down below |
| 1036 | // for a real window to target... |
| 1037 | if (!willMove |
| 1038 | && w.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING |
| 1039 | && i > 0) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1040 | WindowState wb = localmWindows.get(i-1); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1041 | if (wb.mAppToken == w.mAppToken && canBeImeTarget(wb)) { |
| 1042 | i--; |
| 1043 | w = wb; |
| 1044 | } |
| 1045 | } |
| 1046 | break; |
| 1047 | } |
| 1048 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1049 | |
Dianne Hackborn | e75d872 | 2011-01-27 19:37:40 -0800 | [diff] [blame] | 1050 | if (DEBUG_INPUT_METHOD && willMove) Slog.v(TAG, "Proposed new IME target: " + w); |
| 1051 | |
Dianne Hackborn | 7eab094 | 2011-01-01 13:21:50 -0800 | [diff] [blame] | 1052 | // Now, a special case -- if the last target's window is in the |
| 1053 | // process of exiting, and is above the new target, keep on the |
| 1054 | // last target to avoid flicker. Consider for example a Dialog with |
| 1055 | // the IME shown: when the Dialog is dismissed, we want to keep |
| 1056 | // the IME above it until it is completely gone so it doesn't drop |
| 1057 | // behind the dialog or its full-screen scrim. |
| 1058 | if (mInputMethodTarget != null && w != null |
| 1059 | && mInputMethodTarget.isDisplayedLw() |
| 1060 | && mInputMethodTarget.mExiting) { |
| 1061 | if (mInputMethodTarget.mAnimLayer > w.mAnimLayer) { |
| 1062 | w = mInputMethodTarget; |
| 1063 | i = localmWindows.indexOf(w); |
Dianne Hackborn | e75d872 | 2011-01-27 19:37:40 -0800 | [diff] [blame] | 1064 | if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Current target higher, switching to: " + w); |
Dianne Hackborn | 7eab094 | 2011-01-01 13:21:50 -0800 | [diff] [blame] | 1065 | } |
| 1066 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1067 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1068 | 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] | 1069 | + w + " willMove=" + willMove); |
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 | if (willMove && w != null) { |
| 1072 | final WindowState curTarget = mInputMethodTarget; |
| 1073 | if (curTarget != null && curTarget.mAppToken != null) { |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1074 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1075 | // Now some fun for dealing with window animations that |
| 1076 | // modify the Z order. We need to look at all windows below |
| 1077 | // the current target that are in this app, finding the highest |
| 1078 | // visible one in layering. |
| 1079 | AppWindowToken token = curTarget.mAppToken; |
| 1080 | WindowState highestTarget = null; |
| 1081 | int highestPos = 0; |
| 1082 | if (token.animating || token.animation != null) { |
| 1083 | int pos = 0; |
| 1084 | pos = localmWindows.indexOf(curTarget); |
| 1085 | while (pos >= 0) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1086 | WindowState win = localmWindows.get(pos); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1087 | if (win.mAppToken != token) { |
| 1088 | break; |
| 1089 | } |
| 1090 | if (!win.mRemoved) { |
| 1091 | if (highestTarget == null || win.mAnimLayer > |
| 1092 | highestTarget.mAnimLayer) { |
| 1093 | highestTarget = win; |
| 1094 | highestPos = pos; |
| 1095 | } |
| 1096 | } |
| 1097 | pos--; |
| 1098 | } |
| 1099 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1100 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1101 | if (highestTarget != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1102 | if (DEBUG_INPUT_METHOD) Slog.v(TAG, "mNextAppTransition=" |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1103 | + mNextAppTransition + " " + highestTarget |
| 1104 | + " animating=" + highestTarget.isAnimating() |
| 1105 | + " layer=" + highestTarget.mAnimLayer |
| 1106 | + " new layer=" + w.mAnimLayer); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1107 | |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 1108 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1109 | // If we are currently setting up for an animation, |
| 1110 | // hold everything until we can find out what will happen. |
| 1111 | mInputMethodTargetWaitingAnim = true; |
| 1112 | mInputMethodTarget = highestTarget; |
| 1113 | return highestPos + 1; |
| 1114 | } else if (highestTarget.isAnimating() && |
| 1115 | highestTarget.mAnimLayer > w.mAnimLayer) { |
| 1116 | // If the window we are currently targeting is involved |
| 1117 | // with an animation, and it is on top of the next target |
| 1118 | // we will be over, then hold off on moving until |
| 1119 | // that is done. |
Dianne Hackborn | e75d872 | 2011-01-27 19:37:40 -0800 | [diff] [blame] | 1120 | mInputMethodTargetWaitingAnim = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1121 | mInputMethodTarget = highestTarget; |
| 1122 | return highestPos + 1; |
| 1123 | } |
| 1124 | } |
| 1125 | } |
| 1126 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1127 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1128 | //Slog.i(TAG, "Placing input method @" + (i+1)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1129 | if (w != null) { |
| 1130 | if (willMove) { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 1131 | if (DEBUG_INPUT_METHOD) { |
| 1132 | RuntimeException e = null; |
| 1133 | if (!HIDE_STACK_CRAWLS) { |
| 1134 | e = new RuntimeException(); |
| 1135 | e.fillInStackTrace(); |
| 1136 | } |
| 1137 | Slog.w(TAG, "Moving IM target from " |
| 1138 | + mInputMethodTarget + " to " + w, e); |
| 1139 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1140 | mInputMethodTarget = w; |
Dianne Hackborn | e75d872 | 2011-01-27 19:37:40 -0800 | [diff] [blame] | 1141 | mInputMethodTargetWaitingAnim = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1142 | if (w.mAppToken != null) { |
| 1143 | setInputMethodAnimLayerAdjustment(w.mAppToken.animLayerAdjustment); |
| 1144 | } else { |
| 1145 | setInputMethodAnimLayerAdjustment(0); |
| 1146 | } |
| 1147 | } |
| 1148 | return i+1; |
| 1149 | } |
| 1150 | if (willMove) { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 1151 | if (DEBUG_INPUT_METHOD) { |
| 1152 | RuntimeException e = null; |
| 1153 | if (!HIDE_STACK_CRAWLS) { |
| 1154 | e = new RuntimeException(); |
| 1155 | e.fillInStackTrace(); |
| 1156 | } |
| 1157 | Slog.w(TAG, "Moving IM target from " |
| 1158 | + mInputMethodTarget + " to null", e); |
| 1159 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1160 | mInputMethodTarget = null; |
| 1161 | setInputMethodAnimLayerAdjustment(0); |
| 1162 | } |
| 1163 | return -1; |
| 1164 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1165 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1166 | void addInputMethodWindowToListLocked(WindowState win) { |
| 1167 | int pos = findDesiredInputMethodWindowIndexLocked(true); |
| 1168 | if (pos >= 0) { |
| 1169 | win.mTargetAppToken = mInputMethodTarget.mAppToken; |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 1170 | if (DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) Slog.v( |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 1171 | TAG, "Adding input method window " + win + " at " + pos); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1172 | mWindows.add(pos, win); |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 1173 | mWindowsChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1174 | moveInputMethodDialogsLocked(pos+1); |
| 1175 | return; |
| 1176 | } |
| 1177 | win.mTargetAppToken = null; |
| 1178 | addWindowToListInOrderLocked(win, true); |
| 1179 | moveInputMethodDialogsLocked(pos); |
| 1180 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1181 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1182 | void setInputMethodAnimLayerAdjustment(int adj) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1183 | 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] | 1184 | mInputMethodAnimLayerAdjustment = adj; |
| 1185 | WindowState imw = mInputMethodWindow; |
| 1186 | if (imw != null) { |
| 1187 | imw.mAnimLayer = imw.mLayer + adj; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1188 | if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + imw |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1189 | + " anim layer: " + imw.mAnimLayer); |
| 1190 | int wi = imw.mChildWindows.size(); |
| 1191 | while (wi > 0) { |
| 1192 | wi--; |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1193 | WindowState cw = imw.mChildWindows.get(wi); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1194 | cw.mAnimLayer = cw.mLayer + adj; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1195 | if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + cw |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1196 | + " anim layer: " + cw.mAnimLayer); |
| 1197 | } |
| 1198 | } |
| 1199 | int di = mInputMethodDialogs.size(); |
| 1200 | while (di > 0) { |
| 1201 | di --; |
| 1202 | imw = mInputMethodDialogs.get(di); |
| 1203 | imw.mAnimLayer = imw.mLayer + adj; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1204 | if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + imw |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1205 | + " anim layer: " + imw.mAnimLayer); |
| 1206 | } |
| 1207 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1208 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1209 | private int tmpRemoveWindowLocked(int interestingPos, WindowState win) { |
| 1210 | int wpos = mWindows.indexOf(win); |
| 1211 | if (wpos >= 0) { |
| 1212 | if (wpos < interestingPos) interestingPos--; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1213 | 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] | 1214 | mWindows.remove(wpos); |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 1215 | mWindowsChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1216 | int NC = win.mChildWindows.size(); |
| 1217 | while (NC > 0) { |
| 1218 | NC--; |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1219 | WindowState cw = win.mChildWindows.get(NC); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1220 | int cpos = mWindows.indexOf(cw); |
| 1221 | if (cpos >= 0) { |
| 1222 | if (cpos < interestingPos) interestingPos--; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1223 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Temp removing child at " |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 1224 | + cpos + ": " + cw); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1225 | mWindows.remove(cpos); |
| 1226 | } |
| 1227 | } |
| 1228 | } |
| 1229 | return interestingPos; |
| 1230 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1231 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1232 | private void reAddWindowToListInOrderLocked(WindowState win) { |
| 1233 | addWindowToListInOrderLocked(win, false); |
| 1234 | // This is a hack to get all of the child windows added as well |
| 1235 | // at the right position. Child windows should be rare and |
| 1236 | // this case should be rare, so it shouldn't be that big a deal. |
| 1237 | int wpos = mWindows.indexOf(win); |
| 1238 | if (wpos >= 0) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1239 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "ReAdd removing from " + wpos |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 1240 | + ": " + win); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1241 | mWindows.remove(wpos); |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 1242 | mWindowsChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1243 | reAddWindowLocked(wpos, win); |
| 1244 | } |
| 1245 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1246 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1247 | void logWindowList(String prefix) { |
| 1248 | int N = mWindows.size(); |
| 1249 | while (N > 0) { |
| 1250 | N--; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1251 | Slog.v(TAG, prefix + "#" + N + ": " + mWindows.get(N)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1252 | } |
| 1253 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1254 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1255 | void moveInputMethodDialogsLocked(int pos) { |
| 1256 | ArrayList<WindowState> dialogs = mInputMethodDialogs; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1257 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1258 | final int N = dialogs.size(); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1259 | 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] | 1260 | for (int i=0; i<N; i++) { |
| 1261 | pos = tmpRemoveWindowLocked(pos, dialogs.get(i)); |
| 1262 | } |
| 1263 | if (DEBUG_INPUT_METHOD) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1264 | Slog.v(TAG, "Window list w/pos=" + pos); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1265 | logWindowList(" "); |
| 1266 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1267 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1268 | if (pos >= 0) { |
| 1269 | final AppWindowToken targetAppToken = mInputMethodTarget.mAppToken; |
| 1270 | if (pos < mWindows.size()) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1271 | WindowState wp = mWindows.get(pos); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1272 | if (wp == mInputMethodWindow) { |
| 1273 | pos++; |
| 1274 | } |
| 1275 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1276 | 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] | 1277 | for (int i=0; i<N; i++) { |
| 1278 | WindowState win = dialogs.get(i); |
| 1279 | win.mTargetAppToken = targetAppToken; |
| 1280 | pos = reAddWindowLocked(pos, win); |
| 1281 | } |
| 1282 | if (DEBUG_INPUT_METHOD) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1283 | Slog.v(TAG, "Final window list:"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1284 | logWindowList(" "); |
| 1285 | } |
| 1286 | return; |
| 1287 | } |
| 1288 | for (int i=0; i<N; i++) { |
| 1289 | WindowState win = dialogs.get(i); |
| 1290 | win.mTargetAppToken = null; |
| 1291 | reAddWindowToListInOrderLocked(win); |
| 1292 | if (DEBUG_INPUT_METHOD) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1293 | Slog.v(TAG, "No IM target, final list:"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1294 | logWindowList(" "); |
| 1295 | } |
| 1296 | } |
| 1297 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1298 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1299 | boolean moveInputMethodWindowsIfNeededLocked(boolean needAssignLayers) { |
| 1300 | final WindowState imWin = mInputMethodWindow; |
| 1301 | final int DN = mInputMethodDialogs.size(); |
| 1302 | if (imWin == null && DN == 0) { |
| 1303 | return false; |
| 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 | int imPos = findDesiredInputMethodWindowIndexLocked(true); |
| 1307 | if (imPos >= 0) { |
| 1308 | // In this case, the input method windows are to be placed |
| 1309 | // immediately above the window they are targeting. |
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 | // First check to see if the input method windows are already |
| 1312 | // located here, and contiguous. |
| 1313 | final int N = mWindows.size(); |
| 1314 | WindowState firstImWin = imPos < N |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1315 | ? mWindows.get(imPos) : null; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1316 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1317 | // Figure out the actual input method window that should be |
| 1318 | // at the bottom of their stack. |
| 1319 | WindowState baseImWin = imWin != null |
| 1320 | ? imWin : mInputMethodDialogs.get(0); |
| 1321 | if (baseImWin.mChildWindows.size() > 0) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1322 | WindowState cw = baseImWin.mChildWindows.get(0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1323 | if (cw.mSubLayer < 0) baseImWin = cw; |
| 1324 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1325 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1326 | if (firstImWin == baseImWin) { |
| 1327 | // The windows haven't moved... but are they still contiguous? |
| 1328 | // First find the top IM window. |
| 1329 | int pos = imPos+1; |
| 1330 | while (pos < N) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1331 | if (!(mWindows.get(pos)).mIsImWindow) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1332 | break; |
| 1333 | } |
| 1334 | pos++; |
| 1335 | } |
| 1336 | pos++; |
| 1337 | // Now there should be no more input method windows above. |
| 1338 | while (pos < N) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1339 | if ((mWindows.get(pos)).mIsImWindow) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1340 | break; |
| 1341 | } |
| 1342 | pos++; |
| 1343 | } |
| 1344 | if (pos >= N) { |
| 1345 | // All is good! |
| 1346 | return false; |
| 1347 | } |
| 1348 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1349 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1350 | if (imWin != null) { |
| 1351 | if (DEBUG_INPUT_METHOD) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1352 | Slog.v(TAG, "Moving IM from " + imPos); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1353 | logWindowList(" "); |
| 1354 | } |
| 1355 | imPos = tmpRemoveWindowLocked(imPos, imWin); |
| 1356 | if (DEBUG_INPUT_METHOD) { |
Dianne Hackborn | 7eab094 | 2011-01-01 13:21:50 -0800 | [diff] [blame] | 1357 | Slog.v(TAG, "List after removing with new pos " + imPos + ":"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1358 | logWindowList(" "); |
| 1359 | } |
| 1360 | imWin.mTargetAppToken = mInputMethodTarget.mAppToken; |
| 1361 | reAddWindowLocked(imPos, imWin); |
| 1362 | if (DEBUG_INPUT_METHOD) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1363 | Slog.v(TAG, "List after moving IM to " + imPos + ":"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1364 | logWindowList(" "); |
| 1365 | } |
| 1366 | if (DN > 0) moveInputMethodDialogsLocked(imPos+1); |
| 1367 | } else { |
| 1368 | moveInputMethodDialogsLocked(imPos); |
| 1369 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1370 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1371 | } else { |
| 1372 | // In this case, the input method windows go in a fixed layer, |
| 1373 | // because they aren't currently associated with a focus window. |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1374 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1375 | if (imWin != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1376 | 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] | 1377 | tmpRemoveWindowLocked(0, imWin); |
| 1378 | imWin.mTargetAppToken = null; |
| 1379 | reAddWindowToListInOrderLocked(imWin); |
| 1380 | if (DEBUG_INPUT_METHOD) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1381 | Slog.v(TAG, "List with no IM target:"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1382 | logWindowList(" "); |
| 1383 | } |
| 1384 | if (DN > 0) moveInputMethodDialogsLocked(-1);; |
| 1385 | } else { |
| 1386 | moveInputMethodDialogsLocked(-1);; |
| 1387 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1388 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1389 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1390 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1391 | if (needAssignLayers) { |
| 1392 | assignLayersLocked(); |
| 1393 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1394 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1395 | return true; |
| 1396 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1397 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1398 | void adjustInputMethodDialogsLocked() { |
| 1399 | moveInputMethodDialogsLocked(findDesiredInputMethodWindowIndexLocked(true)); |
| 1400 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1401 | |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 1402 | final boolean isWallpaperVisible(WindowState wallpaperTarget) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1403 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper vis: target obscured=" |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 1404 | + (wallpaperTarget != null ? Boolean.toString(wallpaperTarget.mObscured) : "??") |
| 1405 | + " anim=" + ((wallpaperTarget != null && wallpaperTarget.mAppToken != null) |
| 1406 | ? wallpaperTarget.mAppToken.animation : null) |
| 1407 | + " upper=" + mUpperWallpaperTarget |
| 1408 | + " lower=" + mLowerWallpaperTarget); |
| 1409 | return (wallpaperTarget != null |
| 1410 | && (!wallpaperTarget.mObscured || (wallpaperTarget.mAppToken != null |
| 1411 | && wallpaperTarget.mAppToken.animation != null))) |
| 1412 | || mUpperWallpaperTarget != null |
| 1413 | || mLowerWallpaperTarget != null; |
| 1414 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1415 | |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 1416 | static final int ADJUST_WALLPAPER_LAYERS_CHANGED = 1<<1; |
| 1417 | static final int ADJUST_WALLPAPER_VISIBILITY_CHANGED = 1<<2; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1418 | |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 1419 | int adjustWallpaperWindowsLocked() { |
| 1420 | int changed = 0; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1421 | |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1422 | final int dw = mDisplay.getWidth(); |
| 1423 | final int dh = mDisplay.getHeight(); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1424 | |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1425 | // First find top-most window that has asked to be on top of the |
| 1426 | // wallpaper; all wallpapers go behind it. |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1427 | final ArrayList<WindowState> localmWindows = mWindows; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1428 | int N = localmWindows.size(); |
| 1429 | WindowState w = null; |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1430 | WindowState foundW = null; |
| 1431 | int foundI = 0; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1432 | WindowState topCurW = null; |
| 1433 | int topCurI = 0; |
Dianne Hackborn | 6c8e20f | 2010-11-09 18:59:09 -0800 | [diff] [blame] | 1434 | int windowDetachedI = -1; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1435 | int i = N; |
| 1436 | while (i > 0) { |
| 1437 | i--; |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1438 | w = localmWindows.get(i); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1439 | if ((w.mAttrs.type == WindowManager.LayoutParams.TYPE_WALLPAPER)) { |
| 1440 | if (topCurW == null) { |
| 1441 | topCurW = w; |
| 1442 | topCurI = i; |
| 1443 | } |
| 1444 | continue; |
| 1445 | } |
| 1446 | topCurW = null; |
Dianne Hackborn | 6c8e20f | 2010-11-09 18:59:09 -0800 | [diff] [blame] | 1447 | if (w != mWindowDetachedWallpaper && w.mAppToken != null) { |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1448 | // If this window's app token is hidden and not animating, |
| 1449 | // it is of no interest to us. |
| 1450 | if (w.mAppToken.hidden && w.mAppToken.animation == null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1451 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
Dianne Hackborn | 6c8e20f | 2010-11-09 18:59:09 -0800 | [diff] [blame] | 1452 | "Skipping not hidden or animating token: " + w); |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1453 | continue; |
| 1454 | } |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1455 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1456 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Win " + w + ": readyfordisplay=" |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1457 | + w.isReadyForDisplay() + " drawpending=" + w.mDrawPending |
| 1458 | + " commitdrawpending=" + w.mCommitDrawPending); |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1459 | if ((w.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0 && w.isReadyForDisplay() |
Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 1460 | && (mWallpaperTarget == w |
| 1461 | || (!w.mDrawPending && !w.mCommitDrawPending))) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1462 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1463 | "Found wallpaper activity: #" + i + "=" + w); |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1464 | foundW = w; |
| 1465 | foundI = i; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1466 | if (w == mWallpaperTarget && ((w.mAppToken != null |
| 1467 | && w.mAppToken.animation != null) |
| 1468 | || w.mAnimation != null)) { |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1469 | // The current wallpaper target is animating, so we'll |
| 1470 | // look behind it for another possible target and figure |
| 1471 | // out what is going on below. |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1472 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Win " + w |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1473 | + ": token animating, looking behind."); |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1474 | continue; |
| 1475 | } |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1476 | break; |
Dianne Hackborn | 6c8e20f | 2010-11-09 18:59:09 -0800 | [diff] [blame] | 1477 | } else if (w == mWindowDetachedWallpaper) { |
| 1478 | windowDetachedI = i; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1479 | } |
| 1480 | } |
| 1481 | |
Dianne Hackborn | 6c8e20f | 2010-11-09 18:59:09 -0800 | [diff] [blame] | 1482 | if (foundW == null && windowDetachedI >= 0) { |
| 1483 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
| 1484 | "Found animating detached wallpaper activity: #" + i + "=" + w); |
| 1485 | foundW = w; |
| 1486 | foundI = windowDetachedI; |
| 1487 | } |
| 1488 | |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 1489 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1490 | // If we are currently waiting for an app transition, and either |
| 1491 | // the current target or the next target are involved with it, |
| 1492 | // then hold off on doing anything with the wallpaper. |
| 1493 | // Note that we are checking here for just whether the target |
| 1494 | // is part of an app token... which is potentially overly aggressive |
| 1495 | // (the app token may not be involved in the transition), but good |
| 1496 | // enough (we'll just wait until whatever transition is pending |
| 1497 | // executes). |
| 1498 | if (mWallpaperTarget != null && mWallpaperTarget.mAppToken != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1499 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1500 | "Wallpaper not changing: waiting for app anim in current target"); |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 1501 | return 0; |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1502 | } |
| 1503 | if (foundW != null && foundW.mAppToken != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1504 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1505 | "Wallpaper not changing: waiting for app anim in found target"); |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 1506 | return 0; |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1507 | } |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1508 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1509 | |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1510 | if (mWallpaperTarget != foundW) { |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1511 | if (DEBUG_WALLPAPER) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1512 | Slog.v(TAG, "New wallpaper target: " + foundW |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1513 | + " oldTarget: " + mWallpaperTarget); |
| 1514 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1515 | |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1516 | mLowerWallpaperTarget = null; |
| 1517 | mUpperWallpaperTarget = null; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1518 | |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1519 | WindowState oldW = mWallpaperTarget; |
| 1520 | mWallpaperTarget = foundW; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1521 | |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1522 | // Now what is happening... if the current and new targets are |
| 1523 | // animating, then we are in our super special mode! |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1524 | if (foundW != null && oldW != null) { |
| 1525 | boolean oldAnim = oldW.mAnimation != null |
| 1526 | || (oldW.mAppToken != null && oldW.mAppToken.animation != null); |
| 1527 | boolean foundAnim = foundW.mAnimation != null |
| 1528 | || (foundW.mAppToken != null && foundW.mAppToken.animation != null); |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1529 | if (DEBUG_WALLPAPER) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1530 | Slog.v(TAG, "New animation: " + foundAnim |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1531 | + " old animation: " + oldAnim); |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1532 | } |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1533 | if (foundAnim && oldAnim) { |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1534 | int oldI = localmWindows.indexOf(oldW); |
| 1535 | if (DEBUG_WALLPAPER) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1536 | Slog.v(TAG, "New i: " + foundI + " old i: " + oldI); |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1537 | } |
| 1538 | if (oldI >= 0) { |
| 1539 | if (DEBUG_WALLPAPER) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1540 | Slog.v(TAG, "Animating wallpapers: old#" + oldI |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1541 | + "=" + oldW + "; new#" + foundI |
| 1542 | + "=" + foundW); |
| 1543 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1544 | |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1545 | // Set the new target correctly. |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1546 | if (foundW.mAppToken != null && foundW.mAppToken.hiddenRequested) { |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1547 | if (DEBUG_WALLPAPER) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1548 | Slog.v(TAG, "Old wallpaper still the target."); |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1549 | } |
| 1550 | mWallpaperTarget = oldW; |
| 1551 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1552 | |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1553 | // Now set the upper and lower wallpaper targets |
| 1554 | // correctly, and make sure that we are positioning |
| 1555 | // the wallpaper below the lower. |
| 1556 | if (foundI > oldI) { |
| 1557 | // The new target is on top of the old one. |
| 1558 | if (DEBUG_WALLPAPER) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1559 | Slog.v(TAG, "Found target above old target."); |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1560 | } |
| 1561 | mUpperWallpaperTarget = foundW; |
| 1562 | mLowerWallpaperTarget = oldW; |
| 1563 | foundW = oldW; |
| 1564 | foundI = oldI; |
| 1565 | } else { |
| 1566 | // The new target is below the old one. |
| 1567 | if (DEBUG_WALLPAPER) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1568 | Slog.v(TAG, "Found target below old target."); |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1569 | } |
| 1570 | mUpperWallpaperTarget = oldW; |
| 1571 | mLowerWallpaperTarget = foundW; |
| 1572 | } |
| 1573 | } |
| 1574 | } |
| 1575 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1576 | |
Dianne Hackborn | 6b1cb35 | 2009-09-28 18:27:26 -0700 | [diff] [blame] | 1577 | } else if (mLowerWallpaperTarget != null) { |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1578 | // Is it time to stop animating? |
Dianne Hackborn | 6b1cb35 | 2009-09-28 18:27:26 -0700 | [diff] [blame] | 1579 | boolean lowerAnimating = mLowerWallpaperTarget.mAnimation != null |
| 1580 | || (mLowerWallpaperTarget.mAppToken != null |
| 1581 | && mLowerWallpaperTarget.mAppToken.animation != null); |
| 1582 | boolean upperAnimating = mUpperWallpaperTarget.mAnimation != null |
| 1583 | || (mUpperWallpaperTarget.mAppToken != null |
| 1584 | && mUpperWallpaperTarget.mAppToken.animation != null); |
| 1585 | if (!lowerAnimating || !upperAnimating) { |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1586 | if (DEBUG_WALLPAPER) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1587 | Slog.v(TAG, "No longer animating wallpaper targets!"); |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1588 | } |
| 1589 | mLowerWallpaperTarget = null; |
| 1590 | mUpperWallpaperTarget = null; |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1591 | } |
| 1592 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1593 | |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1594 | boolean visible = foundW != null; |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 1595 | if (visible) { |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1596 | // The window is visible to the compositor... but is it visible |
| 1597 | // to the user? That is what the wallpaper cares about. |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 1598 | visible = isWallpaperVisible(foundW); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1599 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper visibility: " + visible); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1600 | |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1601 | // If the wallpaper target is animating, we may need to copy |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1602 | // its layer adjustment. Only do this if we are not transfering |
| 1603 | // between two wallpaper targets. |
| 1604 | mWallpaperAnimLayerAdjustment = |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1605 | (mLowerWallpaperTarget == null && foundW.mAppToken != null) |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1606 | ? foundW.mAppToken.animLayerAdjustment : 0; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1607 | |
Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 1608 | final int maxLayer = mPolicy.getMaxWallpaperLayer() |
| 1609 | * TYPE_LAYER_MULTIPLIER |
| 1610 | + TYPE_LAYER_OFFSET; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1611 | |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1612 | // Now w is the window we are supposed to be behind... but we |
| 1613 | // 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] | 1614 | // AND any starting window associated with it, AND below the |
| 1615 | // maximum layer the policy allows for wallpapers. |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1616 | while (foundI > 0) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1617 | WindowState wb = localmWindows.get(foundI-1); |
Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 1618 | if (wb.mBaseLayer < maxLayer && |
| 1619 | wb.mAttachedWindow != foundW && |
Dianne Hackborn | 428ecb6 | 2011-01-26 14:53:23 -0800 | [diff] [blame] | 1620 | (foundW.mAttachedWindow == null || |
| 1621 | wb.mAttachedWindow != foundW.mAttachedWindow) && |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1622 | (wb.mAttrs.type != TYPE_APPLICATION_STARTING || |
Dianne Hackborn | 428ecb6 | 2011-01-26 14:53:23 -0800 | [diff] [blame] | 1623 | foundW.mToken == null || wb.mToken != foundW.mToken)) { |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1624 | // This window is not related to the previous one in any |
| 1625 | // interesting way, so stop here. |
| 1626 | break; |
| 1627 | } |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1628 | foundW = wb; |
| 1629 | foundI--; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1630 | } |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 1631 | } else { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1632 | if (DEBUG_WALLPAPER) Slog.v(TAG, "No wallpaper target"); |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1633 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1634 | |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1635 | if (foundW == null && topCurW != null) { |
| 1636 | // There is no wallpaper target, so it goes at the bottom. |
| 1637 | // We will assume it is the same place as last time, if known. |
| 1638 | foundW = topCurW; |
| 1639 | foundI = topCurI+1; |
| 1640 | } else { |
| 1641 | // Okay i is the position immediately above the wallpaper. Look at |
| 1642 | // what is below it for later. |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1643 | foundW = foundI > 0 ? localmWindows.get(foundI-1) : null; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1644 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1645 | |
Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 1646 | if (visible) { |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1647 | if (mWallpaperTarget.mWallpaperX >= 0) { |
| 1648 | mLastWallpaperX = mWallpaperTarget.mWallpaperX; |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 1649 | mLastWallpaperXStep = mWallpaperTarget.mWallpaperXStep; |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1650 | } |
| 1651 | if (mWallpaperTarget.mWallpaperY >= 0) { |
| 1652 | mLastWallpaperY = mWallpaperTarget.mWallpaperY; |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 1653 | mLastWallpaperYStep = mWallpaperTarget.mWallpaperYStep; |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1654 | } |
Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 1655 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1656 | |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1657 | // Start stepping backwards from here, ensuring that our wallpaper windows |
| 1658 | // are correctly placed. |
| 1659 | int curTokenIndex = mWallpaperTokens.size(); |
| 1660 | while (curTokenIndex > 0) { |
| 1661 | curTokenIndex--; |
| 1662 | WindowToken token = mWallpaperTokens.get(curTokenIndex); |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 1663 | if (token.hidden == visible) { |
| 1664 | changed |= ADJUST_WALLPAPER_VISIBILITY_CHANGED; |
| 1665 | token.hidden = !visible; |
| 1666 | // Need to do a layout to ensure the wallpaper now has the |
| 1667 | // correct size. |
| 1668 | mLayoutNeeded = true; |
| 1669 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1670 | |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1671 | int curWallpaperIndex = token.windows.size(); |
| 1672 | while (curWallpaperIndex > 0) { |
| 1673 | curWallpaperIndex--; |
| 1674 | WindowState wallpaper = token.windows.get(curWallpaperIndex); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1675 | |
Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 1676 | if (visible) { |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1677 | updateWallpaperOffsetLocked(wallpaper, dw, dh, false); |
Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 1678 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1679 | |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 1680 | // First, make sure the client has the current visibility |
| 1681 | // state. |
| 1682 | if (wallpaper.mWallpaperVisible != visible) { |
| 1683 | wallpaper.mWallpaperVisible = visible; |
| 1684 | try { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1685 | if (DEBUG_VISIBILITY || DEBUG_WALLPAPER) Slog.v(TAG, |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 1686 | "Setting visibility of wallpaper " + wallpaper |
| 1687 | + ": " + visible); |
| 1688 | wallpaper.mClient.dispatchAppVisibility(visible); |
| 1689 | } catch (RemoteException e) { |
| 1690 | } |
| 1691 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1692 | |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 1693 | wallpaper.mAnimLayer = wallpaper.mLayer + mWallpaperAnimLayerAdjustment; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1694 | if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper win " |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1695 | + wallpaper + " anim layer: " + wallpaper.mAnimLayer); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1696 | |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1697 | // First, if this window is at the current index, then all |
| 1698 | // is well. |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1699 | if (wallpaper == foundW) { |
| 1700 | foundI--; |
| 1701 | foundW = foundI > 0 |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1702 | ? localmWindows.get(foundI-1) : null; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1703 | continue; |
| 1704 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1705 | |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1706 | // The window didn't match... the current wallpaper window, |
| 1707 | // wherever it is, is in the wrong place, so make sure it is |
| 1708 | // not in the list. |
| 1709 | int oldIndex = localmWindows.indexOf(wallpaper); |
| 1710 | if (oldIndex >= 0) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1711 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Wallpaper removing at " |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 1712 | + oldIndex + ": " + wallpaper); |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1713 | localmWindows.remove(oldIndex); |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 1714 | mWindowsChanged = true; |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1715 | if (oldIndex < foundI) { |
| 1716 | foundI--; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1717 | } |
| 1718 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1719 | |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1720 | // Now stick it in. |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 1721 | if (DEBUG_WALLPAPER || DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) { |
| 1722 | Slog.v(TAG, "Moving wallpaper " + wallpaper |
| 1723 | + " from " + oldIndex + " to " + foundI); |
| 1724 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1725 | |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1726 | localmWindows.add(foundI, wallpaper); |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 1727 | mWindowsChanged = true; |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 1728 | changed |= ADJUST_WALLPAPER_LAYERS_CHANGED; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1729 | } |
| 1730 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1731 | |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1732 | return changed; |
| 1733 | } |
| 1734 | |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 1735 | void setWallpaperAnimLayerAdjustmentLocked(int adj) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1736 | if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG, |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1737 | "Setting wallpaper layer adj to " + adj); |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 1738 | mWallpaperAnimLayerAdjustment = adj; |
| 1739 | int curTokenIndex = mWallpaperTokens.size(); |
| 1740 | while (curTokenIndex > 0) { |
| 1741 | curTokenIndex--; |
| 1742 | WindowToken token = mWallpaperTokens.get(curTokenIndex); |
| 1743 | int curWallpaperIndex = token.windows.size(); |
| 1744 | while (curWallpaperIndex > 0) { |
| 1745 | curWallpaperIndex--; |
| 1746 | WindowState wallpaper = token.windows.get(curWallpaperIndex); |
| 1747 | wallpaper.mAnimLayer = wallpaper.mLayer + adj; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1748 | if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper win " |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1749 | + wallpaper + " anim layer: " + wallpaper.mAnimLayer); |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 1750 | } |
| 1751 | } |
| 1752 | } |
| 1753 | |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1754 | boolean updateWallpaperOffsetLocked(WindowState wallpaperWin, int dw, int dh, |
| 1755 | boolean sync) { |
Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 1756 | boolean changed = false; |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1757 | boolean rawChanged = false; |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1758 | float wpx = mLastWallpaperX >= 0 ? mLastWallpaperX : 0.5f; |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 1759 | float wpxs = mLastWallpaperXStep >= 0 ? mLastWallpaperXStep : -1.0f; |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1760 | int availw = wallpaperWin.mFrame.right-wallpaperWin.mFrame.left-dw; |
| 1761 | int offset = availw > 0 ? -(int)(availw*wpx+.5f) : 0; |
| 1762 | changed = wallpaperWin.mXOffset != offset; |
| 1763 | if (changed) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1764 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Update wallpaper " |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1765 | + wallpaperWin + " x: " + offset); |
| 1766 | wallpaperWin.mXOffset = offset; |
| 1767 | } |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 1768 | if (wallpaperWin.mWallpaperX != wpx || wallpaperWin.mWallpaperXStep != wpxs) { |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1769 | wallpaperWin.mWallpaperX = wpx; |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 1770 | wallpaperWin.mWallpaperXStep = wpxs; |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1771 | rawChanged = true; |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 1772 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1773 | |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1774 | float wpy = mLastWallpaperY >= 0 ? mLastWallpaperY : 0.5f; |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 1775 | float wpys = mLastWallpaperYStep >= 0 ? mLastWallpaperYStep : -1.0f; |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1776 | int availh = wallpaperWin.mFrame.bottom-wallpaperWin.mFrame.top-dh; |
| 1777 | offset = availh > 0 ? -(int)(availh*wpy+.5f) : 0; |
| 1778 | if (wallpaperWin.mYOffset != offset) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1779 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Update wallpaper " |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1780 | + wallpaperWin + " y: " + offset); |
| 1781 | changed = true; |
| 1782 | wallpaperWin.mYOffset = offset; |
| 1783 | } |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 1784 | if (wallpaperWin.mWallpaperY != wpy || wallpaperWin.mWallpaperYStep != wpys) { |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1785 | wallpaperWin.mWallpaperY = wpy; |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 1786 | wallpaperWin.mWallpaperYStep = wpys; |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1787 | rawChanged = true; |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 1788 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1789 | |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1790 | if (rawChanged) { |
Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 1791 | try { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1792 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Report new wp offset " |
Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 1793 | + wallpaperWin + " x=" + wallpaperWin.mWallpaperX |
| 1794 | + " y=" + wallpaperWin.mWallpaperY); |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1795 | if (sync) { |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 1796 | mWaitingOnWallpaper = wallpaperWin; |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1797 | } |
Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 1798 | wallpaperWin.mClient.dispatchWallpaperOffsets( |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 1799 | wallpaperWin.mWallpaperX, wallpaperWin.mWallpaperY, |
| 1800 | wallpaperWin.mWallpaperXStep, wallpaperWin.mWallpaperYStep, sync); |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1801 | if (sync) { |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 1802 | if (mWaitingOnWallpaper != null) { |
| 1803 | long start = SystemClock.uptimeMillis(); |
| 1804 | if ((mLastWallpaperTimeoutTime+WALLPAPER_TIMEOUT_RECOVERY) |
| 1805 | < start) { |
| 1806 | try { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1807 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 1808 | "Waiting for offset complete..."); |
| 1809 | mWindowMap.wait(WALLPAPER_TIMEOUT); |
| 1810 | } catch (InterruptedException e) { |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1811 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1812 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Offset complete!"); |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 1813 | if ((start+WALLPAPER_TIMEOUT) |
| 1814 | < SystemClock.uptimeMillis()) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1815 | Slog.i(TAG, "Timeout waiting for wallpaper to offset: " |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 1816 | + wallpaperWin); |
| 1817 | mLastWallpaperTimeoutTime = start; |
| 1818 | } |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1819 | } |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 1820 | mWaitingOnWallpaper = null; |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1821 | } |
| 1822 | } |
Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 1823 | } catch (RemoteException e) { |
| 1824 | } |
| 1825 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1826 | |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 1827 | return changed; |
| 1828 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1829 | |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1830 | void wallpaperOffsetsComplete(IBinder window) { |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 1831 | synchronized (mWindowMap) { |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1832 | if (mWaitingOnWallpaper != null && |
| 1833 | mWaitingOnWallpaper.mClient.asBinder() == window) { |
| 1834 | mWaitingOnWallpaper = null; |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 1835 | mWindowMap.notifyAll(); |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1836 | } |
| 1837 | } |
| 1838 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1839 | |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1840 | boolean updateWallpaperOffsetLocked(WindowState changingTarget, boolean sync) { |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 1841 | final int dw = mDisplay.getWidth(); |
| 1842 | final int dh = mDisplay.getHeight(); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1843 | |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 1844 | boolean changed = false; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1845 | |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 1846 | WindowState target = mWallpaperTarget; |
| 1847 | if (target != null) { |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1848 | if (target.mWallpaperX >= 0) { |
| 1849 | mLastWallpaperX = target.mWallpaperX; |
| 1850 | } else if (changingTarget.mWallpaperX >= 0) { |
| 1851 | mLastWallpaperX = changingTarget.mWallpaperX; |
| 1852 | } |
| 1853 | if (target.mWallpaperY >= 0) { |
| 1854 | mLastWallpaperY = target.mWallpaperY; |
| 1855 | } else if (changingTarget.mWallpaperY >= 0) { |
| 1856 | mLastWallpaperY = changingTarget.mWallpaperY; |
| 1857 | } |
| 1858 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1859 | |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1860 | int curTokenIndex = mWallpaperTokens.size(); |
| 1861 | while (curTokenIndex > 0) { |
| 1862 | curTokenIndex--; |
| 1863 | WindowToken token = mWallpaperTokens.get(curTokenIndex); |
| 1864 | int curWallpaperIndex = token.windows.size(); |
| 1865 | while (curWallpaperIndex > 0) { |
| 1866 | curWallpaperIndex--; |
| 1867 | WindowState wallpaper = token.windows.get(curWallpaperIndex); |
| 1868 | if (updateWallpaperOffsetLocked(wallpaper, dw, dh, sync)) { |
| 1869 | wallpaper.computeShownFrameLocked(); |
| 1870 | changed = true; |
| 1871 | // We only want to be synchronous with one wallpaper. |
| 1872 | sync = false; |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 1873 | } |
| 1874 | } |
| 1875 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1876 | |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 1877 | return changed; |
| 1878 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1879 | |
Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 1880 | void updateWallpaperVisibilityLocked() { |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 1881 | final boolean visible = isWallpaperVisible(mWallpaperTarget); |
Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 1882 | final int dw = mDisplay.getWidth(); |
| 1883 | final int dh = mDisplay.getHeight(); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1884 | |
Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 1885 | int curTokenIndex = mWallpaperTokens.size(); |
| 1886 | while (curTokenIndex > 0) { |
| 1887 | curTokenIndex--; |
| 1888 | WindowToken token = mWallpaperTokens.get(curTokenIndex); |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 1889 | if (token.hidden == visible) { |
| 1890 | token.hidden = !visible; |
| 1891 | // Need to do a layout to ensure the wallpaper now has the |
| 1892 | // correct size. |
| 1893 | mLayoutNeeded = true; |
| 1894 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1895 | |
Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 1896 | int curWallpaperIndex = token.windows.size(); |
| 1897 | while (curWallpaperIndex > 0) { |
| 1898 | curWallpaperIndex--; |
| 1899 | WindowState wallpaper = token.windows.get(curWallpaperIndex); |
| 1900 | if (visible) { |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1901 | updateWallpaperOffsetLocked(wallpaper, dw, dh, false); |
Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 1902 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1903 | |
Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 1904 | if (wallpaper.mWallpaperVisible != visible) { |
| 1905 | wallpaper.mWallpaperVisible = visible; |
| 1906 | try { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1907 | if (DEBUG_VISIBILITY || DEBUG_WALLPAPER) Slog.v(TAG, |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 1908 | "Updating visibility of wallpaper " + wallpaper |
Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 1909 | + ": " + visible); |
| 1910 | wallpaper.mClient.dispatchAppVisibility(visible); |
| 1911 | } catch (RemoteException e) { |
| 1912 | } |
| 1913 | } |
| 1914 | } |
| 1915 | } |
| 1916 | } |
Dianne Hackborn | 90d2db3 | 2010-02-11 22:19:06 -0800 | [diff] [blame] | 1917 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1918 | public int addWindow(Session session, IWindow client, |
| 1919 | WindowManager.LayoutParams attrs, int viewVisibility, |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1920 | Rect outContentInsets, InputChannel outInputChannel) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1921 | int res = mPolicy.checkAddPermission(attrs); |
| 1922 | if (res != WindowManagerImpl.ADD_OKAY) { |
| 1923 | return res; |
| 1924 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1925 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1926 | boolean reportNewConfig = false; |
| 1927 | WindowState attachedWindow = null; |
| 1928 | WindowState win = null; |
Dianne Hackborn | 5132b37 | 2010-07-29 12:51:35 -0700 | [diff] [blame] | 1929 | long origId; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1930 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1931 | synchronized(mWindowMap) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1932 | if (mDisplay == null) { |
Dianne Hackborn | 5132b37 | 2010-07-29 12:51:35 -0700 | [diff] [blame] | 1933 | throw new IllegalStateException("Display has not been initialialized"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1934 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1935 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1936 | if (mWindowMap.containsKey(client.asBinder())) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1937 | Slog.w(TAG, "Window " + client + " is already added"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1938 | return WindowManagerImpl.ADD_DUPLICATE_ADD; |
| 1939 | } |
| 1940 | |
| 1941 | if (attrs.type >= FIRST_SUB_WINDOW && attrs.type <= LAST_SUB_WINDOW) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 1942 | attachedWindow = windowForClientLocked(null, attrs.token, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1943 | if (attachedWindow == null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1944 | 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] | 1945 | + attrs.token + ". Aborting."); |
| 1946 | return WindowManagerImpl.ADD_BAD_SUBWINDOW_TOKEN; |
| 1947 | } |
| 1948 | if (attachedWindow.mAttrs.type >= FIRST_SUB_WINDOW |
| 1949 | && attachedWindow.mAttrs.type <= LAST_SUB_WINDOW) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1950 | 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] | 1951 | + attrs.token + ". Aborting."); |
| 1952 | return WindowManagerImpl.ADD_BAD_SUBWINDOW_TOKEN; |
| 1953 | } |
| 1954 | } |
| 1955 | |
| 1956 | boolean addToken = false; |
| 1957 | WindowToken token = mTokenMap.get(attrs.token); |
| 1958 | if (token == null) { |
| 1959 | if (attrs.type >= FIRST_APPLICATION_WINDOW |
| 1960 | && attrs.type <= LAST_APPLICATION_WINDOW) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1961 | 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] | 1962 | + attrs.token + ". Aborting."); |
| 1963 | return WindowManagerImpl.ADD_BAD_APP_TOKEN; |
| 1964 | } |
| 1965 | if (attrs.type == TYPE_INPUT_METHOD) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1966 | 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] | 1967 | + attrs.token + ". Aborting."); |
| 1968 | return WindowManagerImpl.ADD_BAD_APP_TOKEN; |
| 1969 | } |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1970 | if (attrs.type == TYPE_WALLPAPER) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1971 | Slog.w(TAG, "Attempted to add wallpaper window with unknown token " |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1972 | + attrs.token + ". Aborting."); |
| 1973 | return WindowManagerImpl.ADD_BAD_APP_TOKEN; |
| 1974 | } |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 1975 | token = new WindowToken(this, attrs.token, -1, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1976 | addToken = true; |
| 1977 | } else if (attrs.type >= FIRST_APPLICATION_WINDOW |
| 1978 | && attrs.type <= LAST_APPLICATION_WINDOW) { |
| 1979 | AppWindowToken atoken = token.appWindowToken; |
| 1980 | if (atoken == null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1981 | 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] | 1982 | + token + ". Aborting."); |
| 1983 | return WindowManagerImpl.ADD_NOT_APP_TOKEN; |
| 1984 | } else if (atoken.removed) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1985 | 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] | 1986 | + token + ". Aborting."); |
| 1987 | return WindowManagerImpl.ADD_APP_EXITING; |
| 1988 | } |
| 1989 | if (attrs.type == TYPE_APPLICATION_STARTING && atoken.firstWindowDrawn) { |
| 1990 | // No need for this guy! |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1991 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1992 | TAG, "**** NO NEED TO START: " + attrs.getTitle()); |
| 1993 | return WindowManagerImpl.ADD_STARTING_NOT_NEEDED; |
| 1994 | } |
| 1995 | } else if (attrs.type == TYPE_INPUT_METHOD) { |
| 1996 | if (token.windowType != TYPE_INPUT_METHOD) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1997 | 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] | 1998 | + attrs.token + ". Aborting."); |
| 1999 | return WindowManagerImpl.ADD_BAD_APP_TOKEN; |
| 2000 | } |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2001 | } else if (attrs.type == TYPE_WALLPAPER) { |
| 2002 | if (token.windowType != TYPE_WALLPAPER) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2003 | Slog.w(TAG, "Attempted to add wallpaper window with bad token " |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2004 | + attrs.token + ". Aborting."); |
| 2005 | return WindowManagerImpl.ADD_BAD_APP_TOKEN; |
| 2006 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2007 | } |
| 2008 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 2009 | win = new WindowState(this, session, client, token, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2010 | attachedWindow, attrs, viewVisibility); |
| 2011 | if (win.mDeathRecipient == null) { |
| 2012 | // Client has apparently died, so there is no reason to |
| 2013 | // continue. |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2014 | Slog.w(TAG, "Adding window client " + client.asBinder() |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2015 | + " that is dead, aborting."); |
| 2016 | return WindowManagerImpl.ADD_APP_EXITING; |
| 2017 | } |
| 2018 | |
| 2019 | mPolicy.adjustWindowParamsLw(win.mAttrs); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2020 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2021 | res = mPolicy.prepareAddWindowLw(win, attrs); |
| 2022 | if (res != WindowManagerImpl.ADD_OKAY) { |
| 2023 | return res; |
| 2024 | } |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 2025 | |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 2026 | if (outInputChannel != null) { |
| 2027 | String name = win.makeInputChannelName(); |
| 2028 | InputChannel[] inputChannels = InputChannel.openInputChannelPair(name); |
| 2029 | win.mInputChannel = inputChannels[0]; |
| 2030 | inputChannels[1].transferToBinderOutParameter(outInputChannel); |
| 2031 | |
Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame] | 2032 | mInputManager.registerInputChannel(win.mInputChannel, win.mInputWindowHandle); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 2033 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2034 | |
| 2035 | // From now on, no exceptions or errors allowed! |
| 2036 | |
| 2037 | res = WindowManagerImpl.ADD_OKAY; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2038 | |
Dianne Hackborn | 5132b37 | 2010-07-29 12:51:35 -0700 | [diff] [blame] | 2039 | origId = Binder.clearCallingIdentity(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2040 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2041 | if (addToken) { |
| 2042 | mTokenMap.put(attrs.token, token); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2043 | } |
| 2044 | win.attach(); |
| 2045 | mWindowMap.put(client.asBinder(), win); |
| 2046 | |
| 2047 | if (attrs.type == TYPE_APPLICATION_STARTING && |
| 2048 | token.appWindowToken != null) { |
| 2049 | token.appWindowToken.startingWindow = win; |
| 2050 | } |
| 2051 | |
| 2052 | boolean imMayMove = true; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2053 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2054 | if (attrs.type == TYPE_INPUT_METHOD) { |
| 2055 | mInputMethodWindow = win; |
| 2056 | addInputMethodWindowToListLocked(win); |
| 2057 | imMayMove = false; |
| 2058 | } else if (attrs.type == TYPE_INPUT_METHOD_DIALOG) { |
| 2059 | mInputMethodDialogs.add(win); |
| 2060 | addWindowToListInOrderLocked(win, true); |
| 2061 | adjustInputMethodDialogsLocked(); |
| 2062 | imMayMove = false; |
| 2063 | } else { |
| 2064 | addWindowToListInOrderLocked(win, true); |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 2065 | if (attrs.type == TYPE_WALLPAPER) { |
| 2066 | mLastWallpaperTimeoutTime = 0; |
| 2067 | adjustWallpaperWindowsLocked(); |
| 2068 | } else if ((attrs.flags&FLAG_SHOW_WALLPAPER) != 0) { |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2069 | adjustWallpaperWindowsLocked(); |
| 2070 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2071 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2072 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2073 | win.mEnterAnimationPending = true; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2074 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2075 | mPolicy.getContentInsetHintLw(attrs, outContentInsets); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2076 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2077 | if (mInTouchMode) { |
| 2078 | res |= WindowManagerImpl.ADD_FLAG_IN_TOUCH_MODE; |
| 2079 | } |
| 2080 | if (win == null || win.mAppToken == null || !win.mAppToken.clientHidden) { |
| 2081 | res |= WindowManagerImpl.ADD_FLAG_APP_VISIBLE; |
| 2082 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2083 | |
Jeff Brown | 2e44b07 | 2011-01-24 15:21:56 -0800 | [diff] [blame] | 2084 | mInputMonitor.setUpdateInputWindowsNeededLw(); |
| 2085 | |
The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 2086 | boolean focusChanged = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2087 | if (win.canReceiveKeys()) { |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 2088 | focusChanged = updateFocusedWindowLocked(UPDATE_FOCUS_WILL_ASSIGN_LAYERS, |
| 2089 | false /*updateInputWindows*/); |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 2090 | if (focusChanged) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2091 | imMayMove = false; |
| 2092 | } |
| 2093 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2094 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2095 | if (imMayMove) { |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2096 | moveInputMethodWindowsIfNeededLocked(false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2097 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2098 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2099 | assignLayersLocked(); |
| 2100 | // Don't do layout here, the window must call |
| 2101 | // relayout to be displayed, so we'll do it there. |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2102 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2103 | //dump(); |
| 2104 | |
The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 2105 | if (focusChanged) { |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 2106 | finishUpdateFocusedWindowAfterAssignLayersLocked(false /*updateInputWindows*/); |
The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 2107 | } |
Jeff Brown | 2e44b07 | 2011-01-24 15:21:56 -0800 | [diff] [blame] | 2108 | mInputMonitor.updateInputWindowsLw(false /*force*/); |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 2109 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2110 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2111 | TAG, "New client " + client.asBinder() |
| 2112 | + ": window=" + win); |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2113 | |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 2114 | if (win.isVisibleOrAdding() && updateOrientationFromAppTokensLocked(false)) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2115 | reportNewConfig = true; |
| 2116 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2117 | } |
| 2118 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2119 | if (reportNewConfig) { |
| 2120 | sendNewConfiguration(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2121 | } |
Dianne Hackborn | 5132b37 | 2010-07-29 12:51:35 -0700 | [diff] [blame] | 2122 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2123 | Binder.restoreCallingIdentity(origId); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2124 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2125 | return res; |
| 2126 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2127 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2128 | public void removeWindow(Session session, IWindow client) { |
| 2129 | synchronized(mWindowMap) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2130 | WindowState win = windowForClientLocked(session, client, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2131 | if (win == null) { |
| 2132 | return; |
| 2133 | } |
| 2134 | removeWindowLocked(session, win); |
| 2135 | } |
| 2136 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2137 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2138 | public void removeWindowLocked(Session session, WindowState win) { |
| 2139 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2140 | if (localLOGV || DEBUG_FOCUS) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2141 | TAG, "Remove " + win + " client=" |
| 2142 | + Integer.toHexString(System.identityHashCode( |
| 2143 | win.mClient.asBinder())) |
| 2144 | + ", surface=" + win.mSurface); |
| 2145 | |
| 2146 | final long origId = Binder.clearCallingIdentity(); |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 2147 | |
| 2148 | win.disposeInputChannel(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2149 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2150 | if (DEBUG_APP_TRANSITIONS) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2151 | TAG, "Remove " + win + ": mSurface=" + win.mSurface |
| 2152 | + " mExiting=" + win.mExiting |
| 2153 | + " isAnimating=" + win.isAnimating() |
| 2154 | + " app-animation=" |
| 2155 | + (win.mAppToken != null ? win.mAppToken.animation : null) |
| 2156 | + " inPendingTransaction=" |
| 2157 | + (win.mAppToken != null ? win.mAppToken.inPendingTransaction : false) |
| 2158 | + " mDisplayFrozen=" + mDisplayFrozen); |
| 2159 | // Visibility of the removed window. Will be used later to update orientation later on. |
| 2160 | boolean wasVisible = false; |
| 2161 | // First, see if we need to run an animation. If we do, we have |
| 2162 | // to hold off on removing the window until the animation is done. |
| 2163 | // If the display is frozen, just remove immediately, since the |
| 2164 | // animation wouldn't be seen. |
Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 2165 | if (win.mSurface != null && !mDisplayFrozen && mPolicy.isScreenOn()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2166 | // If we are not currently running the exit animation, we |
| 2167 | // need to see about starting one. |
| 2168 | if (wasVisible=win.isWinVisibleLw()) { |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2169 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2170 | int transit = WindowManagerPolicy.TRANSIT_EXIT; |
| 2171 | if (win.getAttrs().type == TYPE_APPLICATION_STARTING) { |
| 2172 | transit = WindowManagerPolicy.TRANSIT_PREVIEW_DONE; |
| 2173 | } |
| 2174 | // Try starting an animation. |
| 2175 | if (applyAnimationLocked(win, transit, false)) { |
| 2176 | win.mExiting = true; |
| 2177 | } |
| 2178 | } |
| 2179 | if (win.mExiting || win.isAnimating()) { |
| 2180 | // The exit animation is running... wait for it! |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2181 | //Slog.i(TAG, "*** Running exit animation..."); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2182 | win.mExiting = true; |
| 2183 | win.mRemoveOnExit = true; |
| 2184 | mLayoutNeeded = true; |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 2185 | updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES, |
| 2186 | false /*updateInputWindows*/); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2187 | performLayoutAndPlaceSurfacesLocked(); |
Jeff Brown | 2e44b07 | 2011-01-24 15:21:56 -0800 | [diff] [blame] | 2188 | mInputMonitor.updateInputWindowsLw(false /*force*/); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2189 | if (win.mAppToken != null) { |
| 2190 | win.mAppToken.updateReportedVisibilityLocked(); |
| 2191 | } |
| 2192 | //dump(); |
| 2193 | Binder.restoreCallingIdentity(origId); |
| 2194 | return; |
| 2195 | } |
| 2196 | } |
| 2197 | |
| 2198 | removeWindowInnerLocked(session, win); |
| 2199 | // Removing a visible window will effect the computed orientation |
| 2200 | // So just update orientation if needed. |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 2201 | if (wasVisible && computeForcedAppOrientationLocked() |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2202 | != mForcedAppOrientation |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 2203 | && updateOrientationFromAppTokensLocked(false)) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2204 | mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2205 | } |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 2206 | updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL, true /*updateInputWindows*/); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2207 | Binder.restoreCallingIdentity(origId); |
| 2208 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2209 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2210 | private void removeWindowInnerLocked(Session session, WindowState win) { |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 2211 | if (win.mRemoved) { |
| 2212 | // Nothing to do. |
| 2213 | return; |
| 2214 | } |
| 2215 | |
| 2216 | for (int i=win.mChildWindows.size()-1; i>=0; i--) { |
| 2217 | WindowState cwin = win.mChildWindows.get(i); |
| 2218 | Slog.w(TAG, "Force-removing child win " + cwin + " from container " |
| 2219 | + win); |
| 2220 | removeWindowInnerLocked(cwin.mSession, cwin); |
| 2221 | } |
| 2222 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2223 | win.mRemoved = true; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2224 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2225 | if (mInputMethodTarget == win) { |
| 2226 | moveInputMethodWindowsIfNeededLocked(false); |
| 2227 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2228 | |
Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 2229 | if (false) { |
| 2230 | RuntimeException e = new RuntimeException("here"); |
| 2231 | e.fillInStackTrace(); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2232 | Slog.w(TAG, "Removing window " + win, e); |
Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 2233 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2234 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2235 | mPolicy.removeWindowLw(win); |
| 2236 | win.removeLocked(); |
| 2237 | |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 2238 | if (DEBUG_ADD_REMOVE) Slog.v(TAG, "removeWindowInnerLocked: " + win); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2239 | mWindowMap.remove(win.mClient.asBinder()); |
| 2240 | mWindows.remove(win); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 2241 | mPendingRemove.remove(win); |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 2242 | mWindowsChanged = true; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2243 | 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] | 2244 | |
| 2245 | if (mInputMethodWindow == win) { |
| 2246 | mInputMethodWindow = null; |
| 2247 | } else if (win.mAttrs.type == TYPE_INPUT_METHOD_DIALOG) { |
| 2248 | mInputMethodDialogs.remove(win); |
| 2249 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2250 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2251 | final WindowToken token = win.mToken; |
| 2252 | final AppWindowToken atoken = win.mAppToken; |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 2253 | if (DEBUG_ADD_REMOVE) Slog.v(TAG, "Removing " + win + " from " + token); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2254 | token.windows.remove(win); |
| 2255 | if (atoken != null) { |
| 2256 | atoken.allAppWindows.remove(win); |
| 2257 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2258 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2259 | TAG, "**** Removing window " + win + ": count=" |
| 2260 | + token.windows.size()); |
| 2261 | if (token.windows.size() == 0) { |
| 2262 | if (!token.explicit) { |
| 2263 | mTokenMap.remove(token.token); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2264 | } else if (atoken != null) { |
| 2265 | atoken.firstWindowDrawn = false; |
| 2266 | } |
| 2267 | } |
| 2268 | |
| 2269 | if (atoken != null) { |
| 2270 | if (atoken.startingWindow == win) { |
| 2271 | atoken.startingWindow = null; |
| 2272 | } else if (atoken.allAppWindows.size() == 0 && atoken.startingData != null) { |
| 2273 | // If this is the last window and we had requested a starting |
| 2274 | // transition window, well there is no point now. |
| 2275 | atoken.startingData = null; |
| 2276 | } else if (atoken.allAppWindows.size() == 1 && atoken.startingView != null) { |
| 2277 | // If this is the last window except for a starting transition |
| 2278 | // window, we need to get rid of the starting transition. |
| 2279 | if (DEBUG_STARTING_WINDOW) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2280 | Slog.v(TAG, "Schedule remove starting " + token |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2281 | + ": no more real windows"); |
| 2282 | } |
| 2283 | Message m = mH.obtainMessage(H.REMOVE_STARTING, atoken); |
| 2284 | mH.sendMessage(m); |
| 2285 | } |
| 2286 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2287 | |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 2288 | if (win.mAttrs.type == TYPE_WALLPAPER) { |
| 2289 | mLastWallpaperTimeoutTime = 0; |
| 2290 | adjustWallpaperWindowsLocked(); |
| 2291 | } else if ((win.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0) { |
Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 2292 | adjustWallpaperWindowsLocked(); |
| 2293 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2294 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2295 | if (!mInLayout) { |
| 2296 | assignLayersLocked(); |
| 2297 | mLayoutNeeded = true; |
| 2298 | performLayoutAndPlaceSurfacesLocked(); |
| 2299 | if (win.mAppToken != null) { |
| 2300 | win.mAppToken.updateReportedVisibilityLocked(); |
| 2301 | } |
| 2302 | } |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 2303 | |
Jeff Brown | 2e44b07 | 2011-01-24 15:21:56 -0800 | [diff] [blame] | 2304 | mInputMonitor.updateInputWindowsLw(true /*force*/); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2305 | } |
| 2306 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 2307 | static void logSurface(WindowState w, String msg, RuntimeException where) { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 2308 | String str = " SURFACE " + Integer.toHexString(w.hashCode()) |
| 2309 | + ": " + msg + " / " + w.mAttrs.getTitle(); |
| 2310 | if (where != null) { |
| 2311 | Slog.i(TAG, str, where); |
| 2312 | } else { |
| 2313 | Slog.i(TAG, str); |
| 2314 | } |
| 2315 | } |
| 2316 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 2317 | void setTransparentRegionWindow(Session session, IWindow client, Region region) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2318 | long origId = Binder.clearCallingIdentity(); |
| 2319 | try { |
| 2320 | synchronized (mWindowMap) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2321 | WindowState w = windowForClientLocked(session, client, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2322 | if ((w != null) && (w.mSurface != null)) { |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 2323 | if (SHOW_TRANSACTIONS) Slog.i(TAG, |
| 2324 | ">>> OPEN TRANSACTION setTransparentRegion"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2325 | Surface.openTransaction(); |
| 2326 | try { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 2327 | if (SHOW_TRANSACTIONS) logSurface(w, |
| 2328 | "transparentRegionHint=" + region, null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2329 | w.mSurface.setTransparentRegionHint(region); |
| 2330 | } finally { |
| 2331 | Surface.closeTransaction(); |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 2332 | if (SHOW_TRANSACTIONS) Slog.i(TAG, |
| 2333 | "<<< CLOSE TRANSACTION setTransparentRegion"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2334 | } |
| 2335 | } |
| 2336 | } |
| 2337 | } finally { |
| 2338 | Binder.restoreCallingIdentity(origId); |
| 2339 | } |
| 2340 | } |
| 2341 | |
| 2342 | void setInsetsWindow(Session session, IWindow client, |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2343 | int touchableInsets, Rect contentInsets, |
Jeff Brown | fbf0977 | 2011-01-16 14:06:57 -0800 | [diff] [blame] | 2344 | Rect visibleInsets, Region touchableRegion) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2345 | long origId = Binder.clearCallingIdentity(); |
| 2346 | try { |
| 2347 | synchronized (mWindowMap) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2348 | WindowState w = windowForClientLocked(session, client, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2349 | if (w != null) { |
| 2350 | w.mGivenInsetsPending = false; |
| 2351 | w.mGivenContentInsets.set(contentInsets); |
| 2352 | w.mGivenVisibleInsets.set(visibleInsets); |
Jeff Brown | fbf0977 | 2011-01-16 14:06:57 -0800 | [diff] [blame] | 2353 | w.mGivenTouchableRegion.set(touchableRegion); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2354 | w.mTouchableInsets = touchableInsets; |
| 2355 | mLayoutNeeded = true; |
| 2356 | performLayoutAndPlaceSurfacesLocked(); |
| 2357 | } |
| 2358 | } |
| 2359 | } finally { |
| 2360 | Binder.restoreCallingIdentity(origId); |
| 2361 | } |
| 2362 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2363 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2364 | public void getWindowDisplayFrame(Session session, IWindow client, |
| 2365 | Rect outDisplayFrame) { |
| 2366 | synchronized(mWindowMap) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2367 | WindowState win = windowForClientLocked(session, client, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2368 | if (win == null) { |
| 2369 | outDisplayFrame.setEmpty(); |
| 2370 | return; |
| 2371 | } |
| 2372 | outDisplayFrame.set(win.mDisplayFrame); |
| 2373 | } |
| 2374 | } |
| 2375 | |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 2376 | public void setWindowWallpaperPositionLocked(WindowState window, float x, float y, |
| 2377 | float xStep, float yStep) { |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 2378 | if (window.mWallpaperX != x || window.mWallpaperY != y) { |
| 2379 | window.mWallpaperX = x; |
| 2380 | window.mWallpaperY = y; |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 2381 | window.mWallpaperXStep = xStep; |
| 2382 | window.mWallpaperYStep = yStep; |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 2383 | if (updateWallpaperOffsetLocked(window, true)) { |
| 2384 | performLayoutAndPlaceSurfacesLocked(); |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 2385 | } |
| 2386 | } |
| 2387 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2388 | |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 2389 | void wallpaperCommandComplete(IBinder window, Bundle result) { |
| 2390 | synchronized (mWindowMap) { |
| 2391 | if (mWaitingOnWallpaper != null && |
| 2392 | mWaitingOnWallpaper.mClient.asBinder() == window) { |
| 2393 | mWaitingOnWallpaper = null; |
| 2394 | mWindowMap.notifyAll(); |
| 2395 | } |
| 2396 | } |
| 2397 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2398 | |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 2399 | public Bundle sendWindowWallpaperCommandLocked(WindowState window, |
| 2400 | String action, int x, int y, int z, Bundle extras, boolean sync) { |
| 2401 | if (window == mWallpaperTarget || window == mLowerWallpaperTarget |
| 2402 | || window == mUpperWallpaperTarget) { |
| 2403 | boolean doWait = sync; |
| 2404 | int curTokenIndex = mWallpaperTokens.size(); |
| 2405 | while (curTokenIndex > 0) { |
| 2406 | curTokenIndex--; |
| 2407 | WindowToken token = mWallpaperTokens.get(curTokenIndex); |
| 2408 | int curWallpaperIndex = token.windows.size(); |
| 2409 | while (curWallpaperIndex > 0) { |
| 2410 | curWallpaperIndex--; |
| 2411 | WindowState wallpaper = token.windows.get(curWallpaperIndex); |
| 2412 | try { |
| 2413 | wallpaper.mClient.dispatchWallpaperCommand(action, |
| 2414 | x, y, z, extras, sync); |
| 2415 | // We only want to be synchronous with one wallpaper. |
| 2416 | sync = false; |
| 2417 | } catch (RemoteException e) { |
| 2418 | } |
| 2419 | } |
| 2420 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2421 | |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 2422 | if (doWait) { |
| 2423 | // XXX Need to wait for result. |
| 2424 | } |
| 2425 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2426 | |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 2427 | return null; |
| 2428 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2429 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2430 | public int relayoutWindow(Session session, IWindow client, |
| 2431 | WindowManager.LayoutParams attrs, int requestedWidth, |
| 2432 | int requestedHeight, int viewVisibility, boolean insetsPending, |
| 2433 | Rect outFrame, Rect outContentInsets, Rect outVisibleInsets, |
Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 2434 | Configuration outConfig, Surface outSurface) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2435 | boolean displayed = false; |
| 2436 | boolean inTouchMode; |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2437 | boolean configChanged; |
Joe Onorato | ac0ee89 | 2011-01-30 15:38:30 -0800 | [diff] [blame] | 2438 | |
| 2439 | // if they don't have this permission, mask out the status bar bits |
| 2440 | if (attrs != null) { |
| 2441 | if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.STATUS_BAR) |
| 2442 | != PackageManager.PERMISSION_GRANTED) { |
| 2443 | attrs.systemUiVisibility &= ~StatusBarManager.DISABLE_MASK; |
| 2444 | attrs.subtreeSystemUiVisibility &= ~StatusBarManager.DISABLE_MASK; |
| 2445 | } |
| 2446 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2447 | long origId = Binder.clearCallingIdentity(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2448 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2449 | synchronized(mWindowMap) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2450 | WindowState win = windowForClientLocked(session, client, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2451 | if (win == null) { |
| 2452 | return 0; |
| 2453 | } |
| 2454 | win.mRequestedWidth = requestedWidth; |
| 2455 | win.mRequestedHeight = requestedHeight; |
| 2456 | |
| 2457 | if (attrs != null) { |
| 2458 | mPolicy.adjustWindowParamsLw(attrs); |
| 2459 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2460 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2461 | int attrChanges = 0; |
| 2462 | int flagChanges = 0; |
| 2463 | if (attrs != null) { |
| 2464 | flagChanges = win.mAttrs.flags ^= attrs.flags; |
| 2465 | attrChanges = win.mAttrs.copyFrom(attrs); |
| 2466 | } |
| 2467 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2468 | 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] | 2469 | |
| 2470 | if ((attrChanges & WindowManager.LayoutParams.ALPHA_CHANGED) != 0) { |
| 2471 | win.mAlpha = attrs.alpha; |
| 2472 | } |
| 2473 | |
| 2474 | final boolean scaledWindow = |
| 2475 | ((win.mAttrs.flags & WindowManager.LayoutParams.FLAG_SCALED) != 0); |
| 2476 | |
| 2477 | if (scaledWindow) { |
| 2478 | // requested{Width|Height} Surface's physical size |
| 2479 | // attrs.{width|height} Size on screen |
| 2480 | win.mHScale = (attrs.width != requestedWidth) ? |
| 2481 | (attrs.width / (float)requestedWidth) : 1.0f; |
| 2482 | win.mVScale = (attrs.height != requestedHeight) ? |
| 2483 | (attrs.height / (float)requestedHeight) : 1.0f; |
Dianne Hackborn | 9b52a21 | 2009-12-11 14:51:35 -0800 | [diff] [blame] | 2484 | } else { |
| 2485 | win.mHScale = win.mVScale = 1; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2486 | } |
| 2487 | |
| 2488 | boolean imMayMove = (flagChanges&( |
| 2489 | WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM | |
| 2490 | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE)) != 0; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2491 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2492 | boolean focusMayChange = win.mViewVisibility != viewVisibility |
| 2493 | || ((flagChanges&WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) != 0) |
| 2494 | || (!win.mRelayoutCalled); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2495 | |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2496 | boolean wallpaperMayMove = win.mViewVisibility != viewVisibility |
| 2497 | && (win.mAttrs.flags & FLAG_SHOW_WALLPAPER) != 0; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2498 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2499 | win.mRelayoutCalled = true; |
| 2500 | final int oldVisibility = win.mViewVisibility; |
| 2501 | win.mViewVisibility = viewVisibility; |
| 2502 | if (viewVisibility == View.VISIBLE && |
| 2503 | (win.mAppToken == null || !win.mAppToken.clientHidden)) { |
| 2504 | displayed = !win.isVisibleLw(); |
| 2505 | if (win.mExiting) { |
| 2506 | win.mExiting = false; |
Brad Fitzpatrick | 3fe3851 | 2010-11-03 11:46:54 -0700 | [diff] [blame] | 2507 | if (win.mAnimation != null) { |
| 2508 | win.mAnimation.cancel(); |
| 2509 | win.mAnimation = null; |
| 2510 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2511 | } |
| 2512 | if (win.mDestroying) { |
| 2513 | win.mDestroying = false; |
| 2514 | mDestroySurface.remove(win); |
| 2515 | } |
| 2516 | if (oldVisibility == View.GONE) { |
| 2517 | win.mEnterAnimationPending = true; |
| 2518 | } |
Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 2519 | if (displayed) { |
| 2520 | if (win.mSurface != null && !win.mDrawPending |
| 2521 | && !win.mCommitDrawPending && !mDisplayFrozen |
| 2522 | && mPolicy.isScreenOn()) { |
| 2523 | applyEnterAnimationLocked(win); |
| 2524 | } |
| 2525 | if ((win.mAttrs.flags |
| 2526 | & WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON) != 0) { |
| 2527 | if (DEBUG_VISIBILITY) Slog.v(TAG, |
| 2528 | "Relayout window turning screen on: " + win); |
| 2529 | win.mTurnOnScreen = true; |
| 2530 | } |
| 2531 | int diff = 0; |
| 2532 | if (win.mConfiguration != mCurConfiguration |
| 2533 | && (win.mConfiguration == null |
| 2534 | || (diff=mCurConfiguration.diff(win.mConfiguration)) != 0)) { |
| 2535 | win.mConfiguration = mCurConfiguration; |
| 2536 | if (DEBUG_CONFIGURATION) { |
| 2537 | Slog.i(TAG, "Window " + win + " visible with new config: " |
| 2538 | + win.mConfiguration + " / 0x" |
| 2539 | + Integer.toHexString(diff)); |
| 2540 | } |
| 2541 | outConfig.setTo(mCurConfiguration); |
| 2542 | } |
Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 2543 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2544 | if ((attrChanges&WindowManager.LayoutParams.FORMAT_CHANGED) != 0) { |
| 2545 | // To change the format, we need to re-build the surface. |
| 2546 | win.destroySurfaceLocked(); |
| 2547 | displayed = true; |
| 2548 | } |
| 2549 | try { |
| 2550 | Surface surface = win.createSurfaceLocked(); |
| 2551 | if (surface != null) { |
| 2552 | outSurface.copyFrom(surface); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2553 | win.mReportDestroySurface = false; |
| 2554 | win.mSurfacePendingDestroy = false; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2555 | if (SHOW_TRANSACTIONS) Slog.i(TAG, |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 2556 | " OUT SURFACE " + outSurface + ": copied"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2557 | } else { |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 2558 | // For some reason there isn't a surface. Clear the |
| 2559 | // caller's object so they see the same state. |
| 2560 | outSurface.release(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2561 | } |
| 2562 | } catch (Exception e) { |
Jeff Brown | 2e44b07 | 2011-01-24 15:21:56 -0800 | [diff] [blame] | 2563 | mInputMonitor.updateInputWindowsLw(true /*force*/); |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 2564 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2565 | Slog.w(TAG, "Exception thrown when creating surface for client " |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 2566 | + client + " (" + win.mAttrs.getTitle() + ")", |
| 2567 | e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2568 | Binder.restoreCallingIdentity(origId); |
| 2569 | return 0; |
| 2570 | } |
| 2571 | if (displayed) { |
| 2572 | focusMayChange = true; |
| 2573 | } |
| 2574 | if (win.mAttrs.type == TYPE_INPUT_METHOD |
| 2575 | && mInputMethodWindow == null) { |
| 2576 | mInputMethodWindow = win; |
| 2577 | imMayMove = true; |
| 2578 | } |
Dianne Hackborn | 558947c | 2009-12-18 16:02:50 -0800 | [diff] [blame] | 2579 | if (win.mAttrs.type == TYPE_BASE_APPLICATION |
| 2580 | && win.mAppToken != null |
| 2581 | && win.mAppToken.startingWindow != null) { |
| 2582 | // Special handling of starting window over the base |
| 2583 | // window of the app: propagate lock screen flags to it, |
| 2584 | // to provide the correct semantics while starting. |
| 2585 | final int mask = |
| 2586 | WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED |
Mike Lockwood | ef73162 | 2010-01-27 17:51:34 -0500 | [diff] [blame] | 2587 | | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD |
| 2588 | | WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON; |
Dianne Hackborn | 558947c | 2009-12-18 16:02:50 -0800 | [diff] [blame] | 2589 | WindowManager.LayoutParams sa = win.mAppToken.startingWindow.mAttrs; |
| 2590 | sa.flags = (sa.flags&~mask) | (win.mAttrs.flags&mask); |
| 2591 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2592 | } else { |
| 2593 | win.mEnterAnimationPending = false; |
| 2594 | if (win.mSurface != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2595 | if (DEBUG_VISIBILITY) Slog.i(TAG, "Relayout invis " + win |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2596 | + ": mExiting=" + win.mExiting |
| 2597 | + " mSurfacePendingDestroy=" + win.mSurfacePendingDestroy); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2598 | // If we are not currently running the exit animation, we |
| 2599 | // need to see about starting one. |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2600 | if (!win.mExiting || win.mSurfacePendingDestroy) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2601 | // Try starting an animation; if there isn't one, we |
| 2602 | // can destroy the surface right away. |
| 2603 | int transit = WindowManagerPolicy.TRANSIT_EXIT; |
| 2604 | if (win.getAttrs().type == TYPE_APPLICATION_STARTING) { |
| 2605 | transit = WindowManagerPolicy.TRANSIT_PREVIEW_DONE; |
| 2606 | } |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2607 | if (!win.mSurfacePendingDestroy && win.isWinVisibleLw() && |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2608 | applyAnimationLocked(win, transit, false)) { |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2609 | focusMayChange = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2610 | win.mExiting = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2611 | } else if (win.isAnimating()) { |
| 2612 | // Currently in a hide animation... turn this into |
| 2613 | // an exit. |
| 2614 | win.mExiting = true; |
Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 2615 | } else if (win == mWallpaperTarget) { |
| 2616 | // If the wallpaper is currently behind this |
| 2617 | // window, we need to change both of them inside |
| 2618 | // of a transaction to avoid artifacts. |
| 2619 | win.mExiting = true; |
| 2620 | win.mAnimating = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2621 | } else { |
| 2622 | if (mInputMethodWindow == win) { |
| 2623 | mInputMethodWindow = null; |
| 2624 | } |
| 2625 | win.destroySurfaceLocked(); |
| 2626 | } |
| 2627 | } |
| 2628 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2629 | |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2630 | if (win.mSurface == null || (win.getAttrs().flags |
| 2631 | & WindowManager.LayoutParams.FLAG_KEEP_SURFACE_WHILE_ANIMATING) == 0 |
| 2632 | || win.mSurfacePendingDestroy) { |
| 2633 | // We are being called from a local process, which |
| 2634 | // means outSurface holds its current surface. Ensure the |
| 2635 | // surface object is cleared, but we don't want it actually |
| 2636 | // destroyed at this point. |
| 2637 | win.mSurfacePendingDestroy = false; |
| 2638 | outSurface.release(); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2639 | if (DEBUG_VISIBILITY) Slog.i(TAG, "Releasing surface in: " + win); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2640 | } else if (win.mSurface != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2641 | if (DEBUG_VISIBILITY) Slog.i(TAG, |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2642 | "Keeping surface, will report destroy: " + win); |
| 2643 | win.mReportDestroySurface = true; |
| 2644 | outSurface.copyFrom(win.mSurface); |
| 2645 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2646 | } |
| 2647 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2648 | if (focusMayChange) { |
| 2649 | //System.out.println("Focus may change: " + win.mAttrs.getTitle()); |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 2650 | if (updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES, |
| 2651 | false /*updateInputWindows*/)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2652 | imMayMove = false; |
| 2653 | } |
| 2654 | //System.out.println("Relayout " + win + ": focus=" + mCurrentFocus); |
| 2655 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2656 | |
The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 2657 | // updateFocusedWindowLocked() already assigned layers so we only need to |
| 2658 | // reassign them at this point if the IM window state gets shuffled |
| 2659 | boolean assignLayers = false; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2660 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2661 | if (imMayMove) { |
Dianne Hackborn | 8abd5f0 | 2009-11-20 18:09:03 -0800 | [diff] [blame] | 2662 | if (moveInputMethodWindowsIfNeededLocked(false) || displayed) { |
| 2663 | // Little hack here -- we -should- be able to rely on the |
| 2664 | // function to return true if the IME has moved and needs |
| 2665 | // its layer recomputed. However, if the IME was hidden |
| 2666 | // and isn't actually moved in the list, its layer may be |
| 2667 | // 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] | 2668 | assignLayers = true; |
| 2669 | } |
| 2670 | } |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2671 | if (wallpaperMayMove) { |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 2672 | if ((adjustWallpaperWindowsLocked()&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) { |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2673 | assignLayers = true; |
| 2674 | } |
| 2675 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2676 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2677 | mLayoutNeeded = true; |
| 2678 | win.mGivenInsetsPending = insetsPending; |
| 2679 | if (assignLayers) { |
| 2680 | assignLayersLocked(); |
| 2681 | } |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 2682 | configChanged = updateOrientationFromAppTokensLocked(false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2683 | performLayoutAndPlaceSurfacesLocked(); |
Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 2684 | if (displayed && win.mIsWallpaper) { |
| 2685 | updateWallpaperOffsetLocked(win, mDisplay.getWidth(), |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 2686 | mDisplay.getHeight(), false); |
Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 2687 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2688 | if (win.mAppToken != null) { |
| 2689 | win.mAppToken.updateReportedVisibilityLocked(); |
| 2690 | } |
| 2691 | outFrame.set(win.mFrame); |
| 2692 | outContentInsets.set(win.mContentInsets); |
| 2693 | outVisibleInsets.set(win.mVisibleInsets); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2694 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2695 | TAG, "Relayout given client " + client.asBinder() |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2696 | + ", requestedWidth=" + requestedWidth |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2697 | + ", requestedHeight=" + requestedHeight |
| 2698 | + ", viewVisibility=" + viewVisibility |
| 2699 | + "\nRelayout returning frame=" + outFrame |
| 2700 | + ", surface=" + outSurface); |
| 2701 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2702 | if (localLOGV || DEBUG_FOCUS) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2703 | TAG, "Relayout of " + win + ": focusMayChange=" + focusMayChange); |
| 2704 | |
| 2705 | inTouchMode = mInTouchMode; |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 2706 | |
Jeff Brown | 2e44b07 | 2011-01-24 15:21:56 -0800 | [diff] [blame] | 2707 | mInputMonitor.updateInputWindowsLw(true /*force*/); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2708 | } |
| 2709 | |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2710 | if (configChanged) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2711 | sendNewConfiguration(); |
| 2712 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2713 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2714 | Binder.restoreCallingIdentity(origId); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2715 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2716 | return (inTouchMode ? WindowManagerImpl.RELAYOUT_IN_TOUCH_MODE : 0) |
| 2717 | | (displayed ? WindowManagerImpl.RELAYOUT_FIRST_TIME : 0); |
| 2718 | } |
| 2719 | |
Dianne Hackborn | 6482517 | 2011-03-02 21:32:58 -0800 | [diff] [blame] | 2720 | public boolean outOfMemoryWindow(Session session, IWindow client) { |
| 2721 | long origId = Binder.clearCallingIdentity(); |
| 2722 | |
| 2723 | try { |
| 2724 | synchronized(mWindowMap) { |
| 2725 | WindowState win = windowForClientLocked(session, client, false); |
| 2726 | if (win == null) { |
| 2727 | return false; |
| 2728 | } |
| 2729 | return reclaimSomeSurfaceMemoryLocked(win, "from-client", false); |
| 2730 | } |
| 2731 | } finally { |
| 2732 | Binder.restoreCallingIdentity(origId); |
| 2733 | } |
| 2734 | } |
| 2735 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2736 | public void finishDrawingWindow(Session session, IWindow client) { |
| 2737 | final long origId = Binder.clearCallingIdentity(); |
| 2738 | synchronized(mWindowMap) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2739 | WindowState win = windowForClientLocked(session, client, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2740 | if (win != null && win.finishDrawingLocked()) { |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 2741 | if ((win.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0) { |
| 2742 | adjustWallpaperWindowsLocked(); |
| 2743 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2744 | mLayoutNeeded = true; |
| 2745 | performLayoutAndPlaceSurfacesLocked(); |
| 2746 | } |
| 2747 | } |
| 2748 | Binder.restoreCallingIdentity(origId); |
| 2749 | } |
| 2750 | |
| 2751 | private AttributeCache.Entry getCachedAnimations(WindowManager.LayoutParams lp) { |
Dianne Hackborn | 08121bc | 2011-01-17 17:54:31 -0800 | [diff] [blame] | 2752 | if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: layout params pkg=" |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2753 | + (lp != null ? lp.packageName : null) |
| 2754 | + " resId=0x" + (lp != null ? Integer.toHexString(lp.windowAnimations) : null)); |
| 2755 | if (lp != null && lp.windowAnimations != 0) { |
| 2756 | // If this is a system resource, don't try to load it from the |
| 2757 | // application resources. It is nice to avoid loading application |
| 2758 | // resources if we can. |
| 2759 | String packageName = lp.packageName != null ? lp.packageName : "android"; |
| 2760 | int resId = lp.windowAnimations; |
| 2761 | if ((resId&0xFF000000) == 0x01000000) { |
| 2762 | packageName = "android"; |
| 2763 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2764 | 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] | 2765 | + packageName); |
| 2766 | return AttributeCache.instance().get(packageName, resId, |
| 2767 | com.android.internal.R.styleable.WindowAnimation); |
| 2768 | } |
| 2769 | return null; |
| 2770 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2771 | |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2772 | private AttributeCache.Entry getCachedAnimations(String packageName, int resId) { |
Dianne Hackborn | 08121bc | 2011-01-17 17:54:31 -0800 | [diff] [blame] | 2773 | if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: package=" |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2774 | + packageName + " resId=0x" + Integer.toHexString(resId)); |
| 2775 | if (packageName != null) { |
| 2776 | if ((resId&0xFF000000) == 0x01000000) { |
| 2777 | packageName = "android"; |
| 2778 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2779 | if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: picked package=" |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2780 | + packageName); |
| 2781 | return AttributeCache.instance().get(packageName, resId, |
| 2782 | com.android.internal.R.styleable.WindowAnimation); |
| 2783 | } |
| 2784 | return null; |
| 2785 | } |
| 2786 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 2787 | void applyEnterAnimationLocked(WindowState win) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2788 | int transit = WindowManagerPolicy.TRANSIT_SHOW; |
| 2789 | if (win.mEnterAnimationPending) { |
| 2790 | win.mEnterAnimationPending = false; |
| 2791 | transit = WindowManagerPolicy.TRANSIT_ENTER; |
| 2792 | } |
| 2793 | |
| 2794 | applyAnimationLocked(win, transit, true); |
| 2795 | } |
| 2796 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 2797 | boolean applyAnimationLocked(WindowState win, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2798 | int transit, boolean isEntrance) { |
| 2799 | if (win.mLocalAnimating && win.mAnimationIsEntrance == isEntrance) { |
| 2800 | // If we are trying to apply an animation, but already running |
| 2801 | // an animation of the same type, then just leave that one alone. |
| 2802 | return true; |
| 2803 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2804 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2805 | // Only apply an animation if the display isn't frozen. If it is |
| 2806 | // frozen, there is no reason to animate and it can cause strange |
| 2807 | // artifacts when we unfreeze the display if some different animation |
| 2808 | // is running. |
Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 2809 | if (!mDisplayFrozen && mPolicy.isScreenOn()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2810 | int anim = mPolicy.selectAnimationLw(win, transit); |
| 2811 | int attr = -1; |
| 2812 | Animation a = null; |
| 2813 | if (anim != 0) { |
| 2814 | a = AnimationUtils.loadAnimation(mContext, anim); |
| 2815 | } else { |
| 2816 | switch (transit) { |
| 2817 | case WindowManagerPolicy.TRANSIT_ENTER: |
| 2818 | attr = com.android.internal.R.styleable.WindowAnimation_windowEnterAnimation; |
| 2819 | break; |
| 2820 | case WindowManagerPolicy.TRANSIT_EXIT: |
| 2821 | attr = com.android.internal.R.styleable.WindowAnimation_windowExitAnimation; |
| 2822 | break; |
| 2823 | case WindowManagerPolicy.TRANSIT_SHOW: |
| 2824 | attr = com.android.internal.R.styleable.WindowAnimation_windowShowAnimation; |
| 2825 | break; |
| 2826 | case WindowManagerPolicy.TRANSIT_HIDE: |
| 2827 | attr = com.android.internal.R.styleable.WindowAnimation_windowHideAnimation; |
| 2828 | break; |
| 2829 | } |
| 2830 | if (attr >= 0) { |
| 2831 | a = loadAnimation(win.mAttrs, attr); |
| 2832 | } |
| 2833 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2834 | if (DEBUG_ANIM) Slog.v(TAG, "applyAnimation: win=" + win |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2835 | + " anim=" + anim + " attr=0x" + Integer.toHexString(attr) |
| 2836 | + " mAnimation=" + win.mAnimation |
| 2837 | + " isEntrance=" + isEntrance); |
| 2838 | if (a != null) { |
| 2839 | if (DEBUG_ANIM) { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 2840 | RuntimeException e = null; |
| 2841 | if (!HIDE_STACK_CRAWLS) { |
| 2842 | e = new RuntimeException(); |
| 2843 | e.fillInStackTrace(); |
| 2844 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2845 | Slog.v(TAG, "Loaded animation " + a + " for " + win, e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2846 | } |
| 2847 | win.setAnimation(a); |
| 2848 | win.mAnimationIsEntrance = isEntrance; |
| 2849 | } |
| 2850 | } else { |
| 2851 | win.clearAnimation(); |
| 2852 | } |
| 2853 | |
| 2854 | return win.mAnimation != null; |
| 2855 | } |
| 2856 | |
| 2857 | private Animation loadAnimation(WindowManager.LayoutParams lp, int animAttr) { |
| 2858 | int anim = 0; |
| 2859 | Context context = mContext; |
| 2860 | if (animAttr >= 0) { |
| 2861 | AttributeCache.Entry ent = getCachedAnimations(lp); |
| 2862 | if (ent != null) { |
| 2863 | context = ent.context; |
| 2864 | anim = ent.array.getResourceId(animAttr, 0); |
| 2865 | } |
| 2866 | } |
| 2867 | if (anim != 0) { |
| 2868 | return AnimationUtils.loadAnimation(context, anim); |
| 2869 | } |
| 2870 | return null; |
| 2871 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2872 | |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2873 | private Animation loadAnimation(String packageName, int resId) { |
| 2874 | int anim = 0; |
| 2875 | Context context = mContext; |
| 2876 | if (resId >= 0) { |
| 2877 | AttributeCache.Entry ent = getCachedAnimations(packageName, resId); |
| 2878 | if (ent != null) { |
| 2879 | context = ent.context; |
| 2880 | anim = resId; |
| 2881 | } |
| 2882 | } |
| 2883 | if (anim != 0) { |
| 2884 | return AnimationUtils.loadAnimation(context, anim); |
| 2885 | } |
| 2886 | return null; |
| 2887 | } |
| 2888 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2889 | private boolean applyAnimationLocked(AppWindowToken wtoken, |
| 2890 | WindowManager.LayoutParams lp, int transit, boolean enter) { |
| 2891 | // Only apply an animation if the display isn't frozen. If it is |
| 2892 | // frozen, there is no reason to animate and it can cause strange |
| 2893 | // artifacts when we unfreeze the display if some different animation |
| 2894 | // is running. |
Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 2895 | if (!mDisplayFrozen && mPolicy.isScreenOn()) { |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 2896 | Animation a; |
Mitsuru Oshima | d2967e2 | 2009-07-20 14:01:43 -0700 | [diff] [blame] | 2897 | if (lp != null && (lp.flags & FLAG_COMPATIBLE_WINDOW) != 0) { |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 2898 | a = new FadeInOutAnimation(enter); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2899 | if (DEBUG_ANIM) Slog.v(TAG, |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 2900 | "applying FadeInOutAnimation for a window in compatibility mode"); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2901 | } else if (mNextAppTransitionPackage != null) { |
| 2902 | a = loadAnimation(mNextAppTransitionPackage, enter ? |
| 2903 | mNextAppTransitionEnter : mNextAppTransitionExit); |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 2904 | } else { |
| 2905 | int animAttr = 0; |
| 2906 | switch (transit) { |
| 2907 | case WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN: |
| 2908 | animAttr = enter |
| 2909 | ? com.android.internal.R.styleable.WindowAnimation_activityOpenEnterAnimation |
| 2910 | : com.android.internal.R.styleable.WindowAnimation_activityOpenExitAnimation; |
| 2911 | break; |
| 2912 | case WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE: |
| 2913 | animAttr = enter |
| 2914 | ? com.android.internal.R.styleable.WindowAnimation_activityCloseEnterAnimation |
| 2915 | : com.android.internal.R.styleable.WindowAnimation_activityCloseExitAnimation; |
| 2916 | break; |
| 2917 | case WindowManagerPolicy.TRANSIT_TASK_OPEN: |
| 2918 | animAttr = enter |
| 2919 | ? com.android.internal.R.styleable.WindowAnimation_taskOpenEnterAnimation |
| 2920 | : com.android.internal.R.styleable.WindowAnimation_taskOpenExitAnimation; |
| 2921 | break; |
| 2922 | case WindowManagerPolicy.TRANSIT_TASK_CLOSE: |
| 2923 | animAttr = enter |
| 2924 | ? com.android.internal.R.styleable.WindowAnimation_taskCloseEnterAnimation |
| 2925 | : com.android.internal.R.styleable.WindowAnimation_taskCloseExitAnimation; |
| 2926 | break; |
| 2927 | case WindowManagerPolicy.TRANSIT_TASK_TO_FRONT: |
| 2928 | animAttr = enter |
| 2929 | ? com.android.internal.R.styleable.WindowAnimation_taskToFrontEnterAnimation |
| 2930 | : com.android.internal.R.styleable.WindowAnimation_taskToFrontExitAnimation; |
| 2931 | break; |
| 2932 | case WindowManagerPolicy.TRANSIT_TASK_TO_BACK: |
| 2933 | animAttr = enter |
Mitsuru Oshima | 5a2b91d | 2009-07-16 16:30:02 -0700 | [diff] [blame] | 2934 | ? com.android.internal.R.styleable.WindowAnimation_taskToBackEnterAnimation |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 2935 | : com.android.internal.R.styleable.WindowAnimation_taskToBackExitAnimation; |
| 2936 | break; |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 2937 | case WindowManagerPolicy.TRANSIT_WALLPAPER_OPEN: |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 2938 | animAttr = enter |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 2939 | ? com.android.internal.R.styleable.WindowAnimation_wallpaperOpenEnterAnimation |
| 2940 | : com.android.internal.R.styleable.WindowAnimation_wallpaperOpenExitAnimation; |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 2941 | break; |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 2942 | case WindowManagerPolicy.TRANSIT_WALLPAPER_CLOSE: |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 2943 | animAttr = enter |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 2944 | ? com.android.internal.R.styleable.WindowAnimation_wallpaperCloseEnterAnimation |
| 2945 | : com.android.internal.R.styleable.WindowAnimation_wallpaperCloseExitAnimation; |
| 2946 | break; |
| 2947 | case WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_OPEN: |
| 2948 | animAttr = enter |
| 2949 | ? com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenEnterAnimation |
| 2950 | : com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenExitAnimation; |
| 2951 | break; |
| 2952 | case WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_CLOSE: |
| 2953 | animAttr = enter |
| 2954 | ? com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseEnterAnimation |
| 2955 | : com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseExitAnimation; |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 2956 | break; |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 2957 | } |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 2958 | a = animAttr != 0 ? loadAnimation(lp, animAttr) : null; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2959 | if (DEBUG_ANIM) Slog.v(TAG, "applyAnimation: wtoken=" + wtoken |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 2960 | + " anim=" + a |
| 2961 | + " animAttr=0x" + Integer.toHexString(animAttr) |
| 2962 | + " transit=" + transit); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2963 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2964 | if (a != null) { |
| 2965 | if (DEBUG_ANIM) { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 2966 | RuntimeException e = null; |
| 2967 | if (!HIDE_STACK_CRAWLS) { |
| 2968 | e = new RuntimeException(); |
| 2969 | e.fillInStackTrace(); |
| 2970 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2971 | Slog.v(TAG, "Loaded animation " + a + " for " + wtoken, e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2972 | } |
| 2973 | wtoken.setAnimation(a); |
| 2974 | } |
| 2975 | } else { |
| 2976 | wtoken.clearAnimation(); |
| 2977 | } |
| 2978 | |
| 2979 | return wtoken.animation != null; |
| 2980 | } |
| 2981 | |
| 2982 | // ------------------------------------------------------------- |
| 2983 | // Application Window Tokens |
| 2984 | // ------------------------------------------------------------- |
| 2985 | |
| 2986 | public void validateAppTokens(List tokens) { |
| 2987 | int v = tokens.size()-1; |
| 2988 | int m = mAppTokens.size()-1; |
| 2989 | while (v >= 0 && m >= 0) { |
| 2990 | AppWindowToken wtoken = mAppTokens.get(m); |
| 2991 | if (wtoken.removed) { |
| 2992 | m--; |
| 2993 | continue; |
| 2994 | } |
| 2995 | if (tokens.get(v) != wtoken.token) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2996 | 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] | 2997 | + " @ " + v + ", internal is " + wtoken.token + " @ " + m); |
| 2998 | } |
| 2999 | v--; |
| 3000 | m--; |
| 3001 | } |
| 3002 | while (v >= 0) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3003 | 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] | 3004 | v--; |
| 3005 | } |
| 3006 | while (m >= 0) { |
| 3007 | AppWindowToken wtoken = mAppTokens.get(m); |
| 3008 | if (!wtoken.removed) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3009 | Slog.w(TAG, "Invalid internal token: " + wtoken.token + " @ " + m); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3010 | } |
| 3011 | m--; |
| 3012 | } |
| 3013 | } |
| 3014 | |
| 3015 | boolean checkCallingPermission(String permission, String func) { |
| 3016 | // Quick check: if the calling permission is me, it's all okay. |
| 3017 | if (Binder.getCallingPid() == Process.myPid()) { |
| 3018 | return true; |
| 3019 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3020 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3021 | if (mContext.checkCallingPermission(permission) |
| 3022 | == PackageManager.PERMISSION_GRANTED) { |
| 3023 | return true; |
| 3024 | } |
| 3025 | String msg = "Permission Denial: " + func + " from pid=" |
| 3026 | + Binder.getCallingPid() |
| 3027 | + ", uid=" + Binder.getCallingUid() |
| 3028 | + " requires " + permission; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3029 | Slog.w(TAG, msg); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3030 | return false; |
| 3031 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3032 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3033 | AppWindowToken findAppWindowToken(IBinder token) { |
| 3034 | WindowToken wtoken = mTokenMap.get(token); |
| 3035 | if (wtoken == null) { |
| 3036 | return null; |
| 3037 | } |
| 3038 | return wtoken.appWindowToken; |
| 3039 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3040 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3041 | public void addWindowToken(IBinder token, int type) { |
| 3042 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3043 | "addWindowToken()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3044 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3045 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3046 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3047 | synchronized(mWindowMap) { |
| 3048 | WindowToken wtoken = mTokenMap.get(token); |
| 3049 | if (wtoken != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3050 | 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] | 3051 | return; |
| 3052 | } |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 3053 | wtoken = new WindowToken(this, token, type, true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3054 | mTokenMap.put(token, wtoken); |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 3055 | if (type == TYPE_WALLPAPER) { |
| 3056 | mWallpaperTokens.add(wtoken); |
| 3057 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3058 | } |
| 3059 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3060 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3061 | public void removeWindowToken(IBinder token) { |
| 3062 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3063 | "removeWindowToken()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3064 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3065 | } |
| 3066 | |
| 3067 | final long origId = Binder.clearCallingIdentity(); |
| 3068 | synchronized(mWindowMap) { |
| 3069 | WindowToken wtoken = mTokenMap.remove(token); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3070 | if (wtoken != null) { |
| 3071 | boolean delayed = false; |
| 3072 | if (!wtoken.hidden) { |
| 3073 | wtoken.hidden = true; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3074 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3075 | final int N = wtoken.windows.size(); |
| 3076 | boolean changed = false; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3077 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3078 | for (int i=0; i<N; i++) { |
| 3079 | WindowState win = wtoken.windows.get(i); |
| 3080 | |
| 3081 | if (win.isAnimating()) { |
| 3082 | delayed = true; |
| 3083 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3084 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3085 | if (win.isVisibleNow()) { |
| 3086 | applyAnimationLocked(win, |
| 3087 | WindowManagerPolicy.TRANSIT_EXIT, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3088 | changed = true; |
| 3089 | } |
| 3090 | } |
| 3091 | |
| 3092 | if (changed) { |
| 3093 | mLayoutNeeded = true; |
| 3094 | performLayoutAndPlaceSurfacesLocked(); |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 3095 | updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL, |
| 3096 | false /*updateInputWindows*/); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3097 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3098 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3099 | if (delayed) { |
| 3100 | mExitingTokens.add(wtoken); |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 3101 | } else if (wtoken.windowType == TYPE_WALLPAPER) { |
| 3102 | mWallpaperTokens.remove(wtoken); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3103 | } |
| 3104 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3105 | |
Jeff Brown | 2e44b07 | 2011-01-24 15:21:56 -0800 | [diff] [blame] | 3106 | mInputMonitor.updateInputWindowsLw(true /*force*/); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3107 | } else { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3108 | 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] | 3109 | } |
| 3110 | } |
| 3111 | Binder.restoreCallingIdentity(origId); |
| 3112 | } |
| 3113 | |
| 3114 | public void addAppToken(int addPos, IApplicationToken token, |
| 3115 | int groupId, int requestedOrientation, boolean fullscreen) { |
| 3116 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3117 | "addAppToken()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3118 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3119 | } |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 3120 | |
| 3121 | // Get the dispatching timeout here while we are not holding any locks so that it |
| 3122 | // can be cached by the AppWindowToken. The timeout value is used later by the |
| 3123 | // input dispatcher in code that does hold locks. If we did not cache the value |
| 3124 | // here we would run the chance of introducing a deadlock between the window manager |
| 3125 | // (which holds locks while updating the input dispatcher state) and the activity manager |
| 3126 | // (which holds locks while querying the application token). |
| 3127 | long inputDispatchingTimeoutNanos; |
| 3128 | try { |
| 3129 | inputDispatchingTimeoutNanos = token.getKeyDispatchingTimeout() * 1000000L; |
| 3130 | } catch (RemoteException ex) { |
| 3131 | Slog.w(TAG, "Could not get dispatching timeout.", ex); |
| 3132 | inputDispatchingTimeoutNanos = DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS; |
| 3133 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3134 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3135 | synchronized(mWindowMap) { |
| 3136 | AppWindowToken wtoken = findAppWindowToken(token.asBinder()); |
| 3137 | if (wtoken != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3138 | 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] | 3139 | return; |
| 3140 | } |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 3141 | wtoken = new AppWindowToken(this, token); |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 3142 | wtoken.inputDispatchingTimeoutNanos = inputDispatchingTimeoutNanos; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3143 | wtoken.groupId = groupId; |
| 3144 | wtoken.appFullscreen = fullscreen; |
| 3145 | wtoken.requestedOrientation = requestedOrientation; |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 3146 | if (DEBUG_TOKEN_MOVEMENT || DEBUG_ADD_REMOVE) Slog.v(TAG, "addAppToken: " + wtoken); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3147 | mAppTokens.add(addPos, wtoken); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3148 | mTokenMap.put(token.asBinder(), wtoken); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3149 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3150 | // Application tokens start out hidden. |
| 3151 | wtoken.hidden = true; |
| 3152 | wtoken.hiddenRequested = true; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3153 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3154 | //dump(); |
| 3155 | } |
| 3156 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3157 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3158 | public void setAppGroupId(IBinder token, int groupId) { |
| 3159 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3160 | "setAppStartingIcon()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3161 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3162 | } |
| 3163 | |
| 3164 | synchronized(mWindowMap) { |
| 3165 | AppWindowToken wtoken = findAppWindowToken(token); |
| 3166 | if (wtoken == null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3167 | 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] | 3168 | return; |
| 3169 | } |
| 3170 | wtoken.groupId = groupId; |
| 3171 | } |
| 3172 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3173 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3174 | public int getOrientationFromWindowsLocked() { |
| 3175 | int pos = mWindows.size() - 1; |
| 3176 | while (pos >= 0) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 3177 | WindowState wtoken = mWindows.get(pos); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3178 | pos--; |
| 3179 | if (wtoken.mAppToken != null) { |
| 3180 | // We hit an application window. so the orientation will be determined by the |
| 3181 | // app window. No point in continuing further. |
| 3182 | return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
| 3183 | } |
Christopher Tate | b696aee | 2010-04-02 19:08:30 -0700 | [diff] [blame] | 3184 | if (!wtoken.isVisibleLw() || !wtoken.mPolicyVisibilityAfterAnim) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3185 | continue; |
| 3186 | } |
| 3187 | int req = wtoken.mAttrs.screenOrientation; |
| 3188 | if((req == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) || |
| 3189 | (req == ActivityInfo.SCREEN_ORIENTATION_BEHIND)){ |
| 3190 | continue; |
| 3191 | } else { |
| 3192 | return req; |
| 3193 | } |
| 3194 | } |
| 3195 | return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
| 3196 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3197 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3198 | public int getOrientationFromAppTokensLocked() { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3199 | int pos = mAppTokens.size() - 1; |
| 3200 | int curGroup = 0; |
| 3201 | int lastOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
| 3202 | boolean findingBehind = false; |
| 3203 | boolean haveGroup = false; |
| 3204 | boolean lastFullscreen = false; |
| 3205 | while (pos >= 0) { |
| 3206 | AppWindowToken wtoken = mAppTokens.get(pos); |
| 3207 | pos--; |
| 3208 | // if we're about to tear down this window and not seek for |
| 3209 | // the behind activity, don't use it for orientation |
| 3210 | if (!findingBehind |
| 3211 | && (!wtoken.hidden && wtoken.hiddenRequested)) { |
| 3212 | continue; |
| 3213 | } |
| 3214 | |
| 3215 | if (!haveGroup) { |
| 3216 | // We ignore any hidden applications on the top. |
| 3217 | if (wtoken.hiddenRequested || wtoken.willBeHidden) { |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3218 | continue; |
| 3219 | } |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3220 | haveGroup = true; |
| 3221 | curGroup = wtoken.groupId; |
| 3222 | lastOrientation = wtoken.requestedOrientation; |
| 3223 | } else if (curGroup != wtoken.groupId) { |
| 3224 | // If we have hit a new application group, and the bottom |
| 3225 | // of the previous group didn't explicitly say to use |
| 3226 | // the orientation behind it, and the last app was |
| 3227 | // full screen, then we'll stick with the |
| 3228 | // user's orientation. |
| 3229 | if (lastOrientation != ActivityInfo.SCREEN_ORIENTATION_BEHIND |
| 3230 | && lastFullscreen) { |
| 3231 | return lastOrientation; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3232 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3233 | } |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3234 | int or = wtoken.requestedOrientation; |
| 3235 | // If this application is fullscreen, and didn't explicitly say |
| 3236 | // to use the orientation behind it, then just take whatever |
| 3237 | // orientation it has and ignores whatever is under it. |
| 3238 | lastFullscreen = wtoken.appFullscreen; |
| 3239 | if (lastFullscreen |
| 3240 | && or != ActivityInfo.SCREEN_ORIENTATION_BEHIND) { |
| 3241 | return or; |
| 3242 | } |
| 3243 | // If this application has requested an explicit orientation, |
| 3244 | // then use it. |
Dianne Hackborn | e5439f2 | 2010-10-02 16:53:50 -0700 | [diff] [blame] | 3245 | if (or != ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED |
| 3246 | && or != ActivityInfo.SCREEN_ORIENTATION_BEHIND) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3247 | return or; |
| 3248 | } |
| 3249 | findingBehind |= (or == ActivityInfo.SCREEN_ORIENTATION_BEHIND); |
| 3250 | } |
| 3251 | return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3252 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3253 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3254 | public Configuration updateOrientationFromAppTokens( |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3255 | Configuration currentConfig, IBinder freezeThisOneIfNeeded) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3256 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3257 | "updateOrientationFromAppTokens()")) { |
| 3258 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| 3259 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3260 | |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3261 | Configuration config = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3262 | long ident = Binder.clearCallingIdentity(); |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3263 | |
| 3264 | synchronized(mWindowMap) { |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 3265 | if (updateOrientationFromAppTokensLocked(false)) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3266 | if (freezeThisOneIfNeeded != null) { |
| 3267 | AppWindowToken wtoken = findAppWindowToken( |
| 3268 | freezeThisOneIfNeeded); |
| 3269 | if (wtoken != null) { |
| 3270 | startAppFreezingScreenLocked(wtoken, |
| 3271 | ActivityInfo.CONFIG_ORIENTATION); |
| 3272 | } |
| 3273 | } |
| 3274 | config = computeNewConfigurationLocked(); |
| 3275 | |
| 3276 | } else if (currentConfig != null) { |
| 3277 | // No obvious action we need to take, but if our current |
Casey Burkhardt | 0920ba5 | 2010-08-03 12:04:19 -0700 | [diff] [blame] | 3278 | // state mismatches the activity manager's, update it, |
| 3279 | // disregarding font scale, which should remain set to |
| 3280 | // the value of the previous configuration. |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3281 | mTempConfiguration.setToDefaults(); |
Casey Burkhardt | 0920ba5 | 2010-08-03 12:04:19 -0700 | [diff] [blame] | 3282 | mTempConfiguration.fontScale = currentConfig.fontScale; |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3283 | if (computeNewConfigurationLocked(mTempConfiguration)) { |
| 3284 | if (currentConfig.diff(mTempConfiguration) != 0) { |
| 3285 | mWaitingForConfig = true; |
| 3286 | mLayoutNeeded = true; |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 3287 | startFreezingDisplayLocked(false); |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3288 | config = new Configuration(mTempConfiguration); |
| 3289 | } |
| 3290 | } |
| 3291 | } |
| 3292 | } |
| 3293 | |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3294 | Binder.restoreCallingIdentity(ident); |
| 3295 | return config; |
| 3296 | } |
| 3297 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3298 | /* |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3299 | * Determine the new desired orientation of the display, returning |
| 3300 | * a non-null new Configuration if it has changed from the current |
| 3301 | * orientation. IF TRUE IS RETURNED SOMEONE MUST CALL |
| 3302 | * setNewConfiguration() TO TELL THE WINDOW MANAGER IT CAN UNFREEZE THE |
| 3303 | * SCREEN. This will typically be done for you if you call |
| 3304 | * sendNewConfiguration(). |
| 3305 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3306 | * The orientation is computed from non-application windows first. If none of |
| 3307 | * the non-application windows specify orientation, the orientation is computed from |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3308 | * application tokens. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3309 | * @see android.view.IWindowManager#updateOrientationFromAppTokens( |
| 3310 | * android.os.IBinder) |
| 3311 | */ |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 3312 | boolean updateOrientationFromAppTokensLocked(boolean inTransaction) { |
| 3313 | if (mDisplayFrozen || mOpeningApps.size() > 0 || mClosingApps.size() > 0) { |
Christopher Tate | b696aee | 2010-04-02 19:08:30 -0700 | [diff] [blame] | 3314 | // If the display is frozen, some activities may be in the middle |
| 3315 | // of restarting, and thus have removed their old window. If the |
| 3316 | // window has the flag to hide the lock screen, then the lock screen |
| 3317 | // can re-appear and inflict its own orientation on us. Keep the |
| 3318 | // orientation stable until this all settles down. |
| 3319 | return false; |
| 3320 | } |
| 3321 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3322 | boolean changed = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3323 | long ident = Binder.clearCallingIdentity(); |
| 3324 | try { |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 3325 | int req = computeForcedAppOrientationLocked(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3326 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3327 | if (req != mForcedAppOrientation) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3328 | mForcedAppOrientation = req; |
| 3329 | //send a message to Policy indicating orientation change to take |
| 3330 | //action like disabling/enabling sensors etc., |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 3331 | mPolicy.setCurrentOrientationLw(req); |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3332 | if (setRotationUncheckedLocked(WindowManagerPolicy.USE_LAST_ROTATION, |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 3333 | mLastRotationFlags | Surface.FLAGS_ORIENTATION_ANIMATION_DISABLE, |
| 3334 | inTransaction)) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3335 | changed = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3336 | } |
| 3337 | } |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3338 | |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3339 | return changed; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3340 | } finally { |
| 3341 | Binder.restoreCallingIdentity(ident); |
| 3342 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3343 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3344 | |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 3345 | int computeForcedAppOrientationLocked() { |
| 3346 | int req = getOrientationFromWindowsLocked(); |
| 3347 | if (req == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) { |
| 3348 | req = getOrientationFromAppTokensLocked(); |
| 3349 | } |
| 3350 | return req; |
| 3351 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3352 | |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3353 | public void setNewConfiguration(Configuration config) { |
| 3354 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3355 | "setNewConfiguration()")) { |
| 3356 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| 3357 | } |
| 3358 | |
| 3359 | synchronized(mWindowMap) { |
| 3360 | mCurConfiguration = new Configuration(config); |
| 3361 | mWaitingForConfig = false; |
| 3362 | performLayoutAndPlaceSurfacesLocked(); |
| 3363 | } |
| 3364 | } |
| 3365 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3366 | public void setAppOrientation(IApplicationToken token, int requestedOrientation) { |
| 3367 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3368 | "setAppOrientation()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3369 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3370 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3371 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3372 | synchronized(mWindowMap) { |
| 3373 | AppWindowToken wtoken = findAppWindowToken(token.asBinder()); |
| 3374 | if (wtoken == null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3375 | 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] | 3376 | return; |
| 3377 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3378 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3379 | wtoken.requestedOrientation = requestedOrientation; |
| 3380 | } |
| 3381 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3382 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3383 | public int getAppOrientation(IApplicationToken token) { |
| 3384 | synchronized(mWindowMap) { |
| 3385 | AppWindowToken wtoken = findAppWindowToken(token.asBinder()); |
| 3386 | if (wtoken == null) { |
| 3387 | return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
| 3388 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3389 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3390 | return wtoken.requestedOrientation; |
| 3391 | } |
| 3392 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3393 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3394 | public void setFocusedApp(IBinder token, boolean moveFocusNow) { |
| 3395 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3396 | "setFocusedApp()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3397 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3398 | } |
| 3399 | |
| 3400 | synchronized(mWindowMap) { |
| 3401 | boolean changed = false; |
| 3402 | if (token == null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3403 | 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] | 3404 | changed = mFocusedApp != null; |
| 3405 | mFocusedApp = null; |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 3406 | if (changed) { |
| 3407 | mInputMonitor.setFocusedAppLw(null); |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 3408 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3409 | } else { |
| 3410 | AppWindowToken newFocus = findAppWindowToken(token); |
| 3411 | if (newFocus == null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3412 | 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] | 3413 | return; |
| 3414 | } |
| 3415 | changed = mFocusedApp != newFocus; |
| 3416 | mFocusedApp = newFocus; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3417 | if (DEBUG_FOCUS) Slog.v(TAG, "Set focused app to: " + mFocusedApp); |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 3418 | if (changed) { |
| 3419 | mInputMonitor.setFocusedAppLw(newFocus); |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 3420 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3421 | } |
| 3422 | |
| 3423 | if (moveFocusNow && changed) { |
| 3424 | final long origId = Binder.clearCallingIdentity(); |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 3425 | updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL, true /*updateInputWindows*/); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3426 | Binder.restoreCallingIdentity(origId); |
| 3427 | } |
| 3428 | } |
| 3429 | } |
| 3430 | |
Dianne Hackborn | 7da6ac3 | 2010-12-09 19:22:04 -0800 | [diff] [blame] | 3431 | public void prepareAppTransition(int transit, boolean alwaysKeepCurrent) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3432 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3433 | "prepareAppTransition()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3434 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3435 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3436 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3437 | synchronized(mWindowMap) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3438 | if (DEBUG_APP_TRANSITIONS) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3439 | TAG, "Prepare app transition: transit=" + transit |
| 3440 | + " mNextAppTransition=" + mNextAppTransition); |
Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 3441 | if (!mDisplayFrozen && mPolicy.isScreenOn()) { |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 3442 | if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET |
| 3443 | || mNextAppTransition == WindowManagerPolicy.TRANSIT_NONE) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3444 | mNextAppTransition = transit; |
Dianne Hackborn | 7da6ac3 | 2010-12-09 19:22:04 -0800 | [diff] [blame] | 3445 | } else if (!alwaysKeepCurrent) { |
| 3446 | if (transit == WindowManagerPolicy.TRANSIT_TASK_OPEN |
| 3447 | && mNextAppTransition == WindowManagerPolicy.TRANSIT_TASK_CLOSE) { |
| 3448 | // Opening a new task always supersedes a close for the anim. |
| 3449 | mNextAppTransition = transit; |
| 3450 | } else if (transit == WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN |
| 3451 | && mNextAppTransition == WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE) { |
| 3452 | // Opening a new activity always supersedes a close for the anim. |
| 3453 | mNextAppTransition = transit; |
| 3454 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3455 | } |
| 3456 | mAppTransitionReady = false; |
| 3457 | mAppTransitionTimeout = false; |
| 3458 | mStartingIconInTransition = false; |
| 3459 | mSkipAppTransitionAnimation = false; |
| 3460 | mH.removeMessages(H.APP_TRANSITION_TIMEOUT); |
| 3461 | mH.sendMessageDelayed(mH.obtainMessage(H.APP_TRANSITION_TIMEOUT), |
| 3462 | 5000); |
| 3463 | } |
| 3464 | } |
| 3465 | } |
| 3466 | |
| 3467 | public int getPendingAppTransition() { |
| 3468 | return mNextAppTransition; |
| 3469 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3470 | |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 3471 | public void overridePendingAppTransition(String packageName, |
| 3472 | int enterAnim, int exitAnim) { |
Dianne Hackborn | 8b571a8 | 2009-09-25 16:09:43 -0700 | [diff] [blame] | 3473 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 3474 | mNextAppTransitionPackage = packageName; |
| 3475 | mNextAppTransitionEnter = enterAnim; |
| 3476 | mNextAppTransitionExit = exitAnim; |
| 3477 | } |
| 3478 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3479 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3480 | public void executeAppTransition() { |
| 3481 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3482 | "executeAppTransition()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3483 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3484 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3485 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3486 | synchronized(mWindowMap) { |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 3487 | if (DEBUG_APP_TRANSITIONS) { |
| 3488 | RuntimeException e = new RuntimeException("here"); |
| 3489 | e.fillInStackTrace(); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3490 | Slog.w(TAG, "Execute app transition: mNextAppTransition=" |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 3491 | + mNextAppTransition, e); |
| 3492 | } |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 3493 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3494 | mAppTransitionReady = true; |
| 3495 | final long origId = Binder.clearCallingIdentity(); |
| 3496 | performLayoutAndPlaceSurfacesLocked(); |
| 3497 | Binder.restoreCallingIdentity(origId); |
| 3498 | } |
| 3499 | } |
| 3500 | } |
| 3501 | |
| 3502 | public void setAppStartingWindow(IBinder token, String pkg, |
| 3503 | int theme, CharSequence nonLocalizedLabel, int labelRes, int icon, |
Dianne Hackborn | 7eec10e | 2010-11-12 18:03:47 -0800 | [diff] [blame] | 3504 | int windowFlags, IBinder transferFrom, boolean createIfNeeded) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3505 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3506 | "setAppStartingIcon()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3507 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3508 | } |
| 3509 | |
| 3510 | synchronized(mWindowMap) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3511 | if (DEBUG_STARTING_WINDOW) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3512 | TAG, "setAppStartingIcon: token=" + token + " pkg=" + pkg |
| 3513 | + " transferFrom=" + transferFrom); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3514 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3515 | AppWindowToken wtoken = findAppWindowToken(token); |
| 3516 | if (wtoken == null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3517 | 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] | 3518 | return; |
| 3519 | } |
| 3520 | |
| 3521 | // If the display is frozen, we won't do anything until the |
| 3522 | // actual window is displayed so there is no reason to put in |
| 3523 | // the starting window. |
Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 3524 | if (mDisplayFrozen || !mPolicy.isScreenOn()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3525 | return; |
| 3526 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3527 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3528 | if (wtoken.startingData != null) { |
| 3529 | return; |
| 3530 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3531 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3532 | if (transferFrom != null) { |
| 3533 | AppWindowToken ttoken = findAppWindowToken(transferFrom); |
| 3534 | if (ttoken != null) { |
| 3535 | WindowState startingWindow = ttoken.startingWindow; |
| 3536 | if (startingWindow != null) { |
| 3537 | if (mStartingIconInTransition) { |
| 3538 | // In this case, the starting icon has already |
| 3539 | // been displayed, so start letting windows get |
| 3540 | // shown immediately without any more transitions. |
| 3541 | mSkipAppTransitionAnimation = true; |
| 3542 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3543 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3544 | "Moving existing starting from " + ttoken |
| 3545 | + " to " + wtoken); |
| 3546 | final long origId = Binder.clearCallingIdentity(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3547 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3548 | // Transfer the starting window over to the new |
| 3549 | // token. |
| 3550 | wtoken.startingData = ttoken.startingData; |
| 3551 | wtoken.startingView = ttoken.startingView; |
| 3552 | wtoken.startingWindow = startingWindow; |
| 3553 | ttoken.startingData = null; |
| 3554 | ttoken.startingView = null; |
| 3555 | ttoken.startingWindow = null; |
| 3556 | ttoken.startingMoved = true; |
| 3557 | startingWindow.mToken = wtoken; |
Dianne Hackborn | ef49c57 | 2009-03-24 19:27:32 -0700 | [diff] [blame] | 3558 | startingWindow.mRootToken = wtoken; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3559 | startingWindow.mAppToken = wtoken; |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 3560 | if (DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) Slog.v(TAG, |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 3561 | "Removing starting window: " + startingWindow); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3562 | mWindows.remove(startingWindow); |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 3563 | mWindowsChanged = true; |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 3564 | if (DEBUG_ADD_REMOVE) Slog.v(TAG, "Removing starting " + startingWindow |
| 3565 | + " from " + ttoken); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3566 | ttoken.windows.remove(startingWindow); |
| 3567 | ttoken.allAppWindows.remove(startingWindow); |
| 3568 | addWindowToListInOrderLocked(startingWindow, true); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3569 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3570 | // Propagate other interesting state between the |
| 3571 | // tokens. If the old token is displayed, we should |
| 3572 | // immediately force the new one to be displayed. If |
| 3573 | // it is animating, we need to move that animation to |
| 3574 | // the new one. |
| 3575 | if (ttoken.allDrawn) { |
| 3576 | wtoken.allDrawn = true; |
| 3577 | } |
| 3578 | if (ttoken.firstWindowDrawn) { |
| 3579 | wtoken.firstWindowDrawn = true; |
| 3580 | } |
| 3581 | if (!ttoken.hidden) { |
| 3582 | wtoken.hidden = false; |
| 3583 | wtoken.hiddenRequested = false; |
| 3584 | wtoken.willBeHidden = false; |
| 3585 | } |
| 3586 | if (wtoken.clientHidden != ttoken.clientHidden) { |
| 3587 | wtoken.clientHidden = ttoken.clientHidden; |
| 3588 | wtoken.sendAppVisibilityToClients(); |
| 3589 | } |
| 3590 | if (ttoken.animation != null) { |
| 3591 | wtoken.animation = ttoken.animation; |
| 3592 | wtoken.animating = ttoken.animating; |
| 3593 | wtoken.animLayerAdjustment = ttoken.animLayerAdjustment; |
| 3594 | ttoken.animation = null; |
| 3595 | ttoken.animLayerAdjustment = 0; |
| 3596 | wtoken.updateLayers(); |
| 3597 | ttoken.updateLayers(); |
| 3598 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3599 | |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 3600 | updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES, |
| 3601 | true /*updateInputWindows*/); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3602 | mLayoutNeeded = true; |
| 3603 | performLayoutAndPlaceSurfacesLocked(); |
| 3604 | Binder.restoreCallingIdentity(origId); |
| 3605 | return; |
| 3606 | } else if (ttoken.startingData != null) { |
| 3607 | // The previous app was getting ready to show a |
| 3608 | // starting window, but hasn't yet done so. Steal it! |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3609 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3610 | "Moving pending starting from " + ttoken |
| 3611 | + " to " + wtoken); |
| 3612 | wtoken.startingData = ttoken.startingData; |
| 3613 | ttoken.startingData = null; |
| 3614 | ttoken.startingMoved = true; |
| 3615 | Message m = mH.obtainMessage(H.ADD_STARTING, wtoken); |
| 3616 | // Note: we really want to do sendMessageAtFrontOfQueue() because we |
| 3617 | // want to process the message ASAP, before any other queued |
| 3618 | // messages. |
| 3619 | mH.sendMessageAtFrontOfQueue(m); |
| 3620 | return; |
| 3621 | } |
| 3622 | } |
| 3623 | } |
| 3624 | |
| 3625 | // There is no existing starting window, and the caller doesn't |
| 3626 | // want us to create one, so that's it! |
| 3627 | if (!createIfNeeded) { |
| 3628 | return; |
| 3629 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3630 | |
Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 3631 | // If this is a translucent or wallpaper window, then don't |
| 3632 | // show a starting window -- the current effect (a full-screen |
| 3633 | // opaque starting window that fades away to the real contents |
| 3634 | // when it is ready) does not work for this. |
| 3635 | if (theme != 0) { |
| 3636 | AttributeCache.Entry ent = AttributeCache.instance().get(pkg, theme, |
| 3637 | com.android.internal.R.styleable.Window); |
| 3638 | if (ent.array.getBoolean( |
| 3639 | com.android.internal.R.styleable.Window_windowIsTranslucent, false)) { |
| 3640 | return; |
| 3641 | } |
| 3642 | if (ent.array.getBoolean( |
Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 3643 | com.android.internal.R.styleable.Window_windowIsFloating, false)) { |
| 3644 | return; |
| 3645 | } |
| 3646 | if (ent.array.getBoolean( |
Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 3647 | com.android.internal.R.styleable.Window_windowShowWallpaper, false)) { |
| 3648 | return; |
| 3649 | } |
| 3650 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3651 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3652 | mStartingIconInTransition = true; |
| 3653 | wtoken.startingData = new StartingData( |
| 3654 | pkg, theme, nonLocalizedLabel, |
Dianne Hackborn | 7eec10e | 2010-11-12 18:03:47 -0800 | [diff] [blame] | 3655 | labelRes, icon, windowFlags); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3656 | Message m = mH.obtainMessage(H.ADD_STARTING, wtoken); |
| 3657 | // Note: we really want to do sendMessageAtFrontOfQueue() because we |
| 3658 | // want to process the message ASAP, before any other queued |
| 3659 | // messages. |
| 3660 | mH.sendMessageAtFrontOfQueue(m); |
| 3661 | } |
| 3662 | } |
| 3663 | |
| 3664 | public void setAppWillBeHidden(IBinder token) { |
| 3665 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3666 | "setAppWillBeHidden()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3667 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3668 | } |
| 3669 | |
| 3670 | AppWindowToken wtoken; |
| 3671 | |
| 3672 | synchronized(mWindowMap) { |
| 3673 | wtoken = findAppWindowToken(token); |
| 3674 | if (wtoken == null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3675 | 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] | 3676 | return; |
| 3677 | } |
| 3678 | wtoken.willBeHidden = true; |
| 3679 | } |
| 3680 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3681 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3682 | boolean setTokenVisibilityLocked(AppWindowToken wtoken, WindowManager.LayoutParams lp, |
| 3683 | boolean visible, int transit, boolean performLayout) { |
| 3684 | boolean delayed = false; |
| 3685 | |
| 3686 | if (wtoken.clientHidden == visible) { |
| 3687 | wtoken.clientHidden = !visible; |
| 3688 | wtoken.sendAppVisibilityToClients(); |
| 3689 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3690 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3691 | wtoken.willBeHidden = false; |
| 3692 | if (wtoken.hidden == visible) { |
| 3693 | final int N = wtoken.allAppWindows.size(); |
| 3694 | boolean changed = false; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3695 | if (DEBUG_APP_TRANSITIONS) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3696 | TAG, "Changing app " + wtoken + " hidden=" + wtoken.hidden |
| 3697 | + " performLayout=" + performLayout); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3698 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3699 | boolean runningAppAnimation = false; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3700 | |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 3701 | if (transit != WindowManagerPolicy.TRANSIT_UNSET) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3702 | if (wtoken.animation == sDummyAnimation) { |
| 3703 | wtoken.animation = null; |
| 3704 | } |
| 3705 | applyAnimationLocked(wtoken, lp, transit, visible); |
| 3706 | changed = true; |
| 3707 | if (wtoken.animation != null) { |
| 3708 | delayed = runningAppAnimation = true; |
| 3709 | } |
| 3710 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3711 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3712 | for (int i=0; i<N; i++) { |
| 3713 | WindowState win = wtoken.allAppWindows.get(i); |
| 3714 | if (win == wtoken.startingWindow) { |
| 3715 | continue; |
| 3716 | } |
| 3717 | |
| 3718 | if (win.isAnimating()) { |
| 3719 | delayed = true; |
| 3720 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3721 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3722 | //Slog.i(TAG, "Window " + win + ": vis=" + win.isVisible()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3723 | //win.dump(" "); |
| 3724 | if (visible) { |
| 3725 | if (!win.isVisibleNow()) { |
| 3726 | if (!runningAppAnimation) { |
| 3727 | applyAnimationLocked(win, |
| 3728 | WindowManagerPolicy.TRANSIT_ENTER, true); |
| 3729 | } |
| 3730 | changed = true; |
| 3731 | } |
| 3732 | } else if (win.isVisibleNow()) { |
| 3733 | if (!runningAppAnimation) { |
| 3734 | applyAnimationLocked(win, |
| 3735 | WindowManagerPolicy.TRANSIT_EXIT, false); |
| 3736 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3737 | changed = true; |
| 3738 | } |
| 3739 | } |
| 3740 | |
| 3741 | wtoken.hidden = wtoken.hiddenRequested = !visible; |
| 3742 | if (!visible) { |
| 3743 | unsetAppFreezingScreenLocked(wtoken, true, true); |
| 3744 | } else { |
| 3745 | // If we are being set visible, and the starting window is |
| 3746 | // not yet displayed, then make sure it doesn't get displayed. |
| 3747 | WindowState swin = wtoken.startingWindow; |
| 3748 | if (swin != null && (swin.mDrawPending |
| 3749 | || swin.mCommitDrawPending)) { |
| 3750 | swin.mPolicyVisibility = false; |
| 3751 | swin.mPolicyVisibilityAfterAnim = false; |
| 3752 | } |
| 3753 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3754 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3755 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "setTokenVisibilityLocked: " + wtoken |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3756 | + ": hidden=" + wtoken.hidden + " hiddenRequested=" |
| 3757 | + wtoken.hiddenRequested); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3758 | |
Dianne Hackborn | 9b52a21 | 2009-12-11 14:51:35 -0800 | [diff] [blame] | 3759 | if (changed) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3760 | mLayoutNeeded = true; |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 3761 | mInputMonitor.setUpdateInputWindowsNeededLw(); |
Dianne Hackborn | 9b52a21 | 2009-12-11 14:51:35 -0800 | [diff] [blame] | 3762 | if (performLayout) { |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 3763 | updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES, |
| 3764 | false /*updateInputWindows*/); |
Dianne Hackborn | 9b52a21 | 2009-12-11 14:51:35 -0800 | [diff] [blame] | 3765 | performLayoutAndPlaceSurfacesLocked(); |
| 3766 | } |
Jeff Brown | 2e44b07 | 2011-01-24 15:21:56 -0800 | [diff] [blame] | 3767 | mInputMonitor.updateInputWindowsLw(false /*force*/); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3768 | } |
| 3769 | } |
| 3770 | |
| 3771 | if (wtoken.animation != null) { |
| 3772 | delayed = true; |
| 3773 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3774 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3775 | return delayed; |
| 3776 | } |
| 3777 | |
| 3778 | public void setAppVisibility(IBinder token, boolean visible) { |
| 3779 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3780 | "setAppVisibility()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3781 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3782 | } |
| 3783 | |
| 3784 | AppWindowToken wtoken; |
| 3785 | |
| 3786 | synchronized(mWindowMap) { |
| 3787 | wtoken = findAppWindowToken(token); |
| 3788 | if (wtoken == null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3789 | 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] | 3790 | return; |
| 3791 | } |
| 3792 | |
| 3793 | if (DEBUG_APP_TRANSITIONS || DEBUG_ORIENTATION) { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 3794 | RuntimeException e = null; |
| 3795 | if (!HIDE_STACK_CRAWLS) { |
| 3796 | e = new RuntimeException(); |
| 3797 | e.fillInStackTrace(); |
| 3798 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3799 | Slog.v(TAG, "setAppVisibility(" + token + ", " + visible |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3800 | + "): mNextAppTransition=" + mNextAppTransition |
| 3801 | + " hidden=" + wtoken.hidden |
| 3802 | + " hiddenRequested=" + wtoken.hiddenRequested, e); |
| 3803 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3804 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3805 | // If we are preparing an app transition, then delay changing |
| 3806 | // the visibility of this token until we execute that transition. |
Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 3807 | if (!mDisplayFrozen && mPolicy.isScreenOn() |
| 3808 | && mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3809 | // Already in requested state, don't do anything more. |
| 3810 | if (wtoken.hiddenRequested != visible) { |
| 3811 | return; |
| 3812 | } |
| 3813 | wtoken.hiddenRequested = !visible; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3814 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3815 | if (DEBUG_APP_TRANSITIONS) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3816 | TAG, "Setting dummy animation on: " + wtoken); |
| 3817 | wtoken.setDummyAnimation(); |
| 3818 | mOpeningApps.remove(wtoken); |
| 3819 | mClosingApps.remove(wtoken); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 3820 | wtoken.waitingToShow = wtoken.waitingToHide = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3821 | wtoken.inPendingTransaction = true; |
| 3822 | if (visible) { |
| 3823 | mOpeningApps.add(wtoken); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3824 | wtoken.startingDisplayed = false; |
| 3825 | wtoken.startingMoved = false; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3826 | |
Dianne Hackborn | 195f6a0 | 2009-11-24 11:26:00 -0800 | [diff] [blame] | 3827 | // If the token is currently hidden (should be the |
| 3828 | // common case), then we need to set up to wait for |
| 3829 | // its windows to be ready. |
| 3830 | if (wtoken.hidden) { |
| 3831 | wtoken.allDrawn = false; |
| 3832 | wtoken.waitingToShow = true; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3833 | |
Dianne Hackborn | 195f6a0 | 2009-11-24 11:26:00 -0800 | [diff] [blame] | 3834 | if (wtoken.clientHidden) { |
| 3835 | // In the case where we are making an app visible |
| 3836 | // but holding off for a transition, we still need |
| 3837 | // to tell the client to make its windows visible so |
| 3838 | // they get drawn. Otherwise, we will wait on |
| 3839 | // performing the transition until all windows have |
| 3840 | // been drawn, they never will be, and we are sad. |
| 3841 | wtoken.clientHidden = false; |
| 3842 | wtoken.sendAppVisibilityToClients(); |
| 3843 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3844 | } |
| 3845 | } else { |
| 3846 | mClosingApps.add(wtoken); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3847 | |
Dianne Hackborn | 195f6a0 | 2009-11-24 11:26:00 -0800 | [diff] [blame] | 3848 | // If the token is currently visible (should be the |
| 3849 | // common case), then set up to wait for it to be hidden. |
| 3850 | if (!wtoken.hidden) { |
| 3851 | wtoken.waitingToHide = true; |
| 3852 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3853 | } |
| 3854 | return; |
| 3855 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3856 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3857 | final long origId = Binder.clearCallingIdentity(); |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 3858 | setTokenVisibilityLocked(wtoken, null, visible, WindowManagerPolicy.TRANSIT_UNSET, true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3859 | wtoken.updateReportedVisibilityLocked(); |
| 3860 | Binder.restoreCallingIdentity(origId); |
| 3861 | } |
| 3862 | } |
| 3863 | |
| 3864 | void unsetAppFreezingScreenLocked(AppWindowToken wtoken, |
| 3865 | boolean unfreezeSurfaceNow, boolean force) { |
| 3866 | if (wtoken.freezingScreen) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3867 | 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] | 3868 | + " force=" + force); |
| 3869 | final int N = wtoken.allAppWindows.size(); |
| 3870 | boolean unfrozeWindows = false; |
| 3871 | for (int i=0; i<N; i++) { |
| 3872 | WindowState w = wtoken.allAppWindows.get(i); |
| 3873 | if (w.mAppFreezing) { |
| 3874 | w.mAppFreezing = false; |
| 3875 | if (w.mSurface != null && !w.mOrientationChanging) { |
| 3876 | w.mOrientationChanging = true; |
| 3877 | } |
| 3878 | unfrozeWindows = true; |
| 3879 | } |
| 3880 | } |
| 3881 | if (force || unfrozeWindows) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3882 | 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] | 3883 | wtoken.freezingScreen = false; |
| 3884 | mAppsFreezingScreen--; |
| 3885 | } |
| 3886 | if (unfreezeSurfaceNow) { |
| 3887 | if (unfrozeWindows) { |
| 3888 | mLayoutNeeded = true; |
| 3889 | performLayoutAndPlaceSurfacesLocked(); |
| 3890 | } |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3891 | stopFreezingDisplayLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3892 | } |
| 3893 | } |
| 3894 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3895 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3896 | public void startAppFreezingScreenLocked(AppWindowToken wtoken, |
| 3897 | int configChanges) { |
| 3898 | if (DEBUG_ORIENTATION) { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 3899 | RuntimeException e = null; |
| 3900 | if (!HIDE_STACK_CRAWLS) { |
| 3901 | e = new RuntimeException(); |
| 3902 | e.fillInStackTrace(); |
| 3903 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3904 | Slog.i(TAG, "Set freezing of " + wtoken.appToken |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3905 | + ": hidden=" + wtoken.hidden + " freezing=" |
| 3906 | + wtoken.freezingScreen, e); |
| 3907 | } |
| 3908 | if (!wtoken.hiddenRequested) { |
| 3909 | if (!wtoken.freezingScreen) { |
| 3910 | wtoken.freezingScreen = true; |
| 3911 | mAppsFreezingScreen++; |
| 3912 | if (mAppsFreezingScreen == 1) { |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 3913 | startFreezingDisplayLocked(false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3914 | mH.removeMessages(H.APP_FREEZE_TIMEOUT); |
| 3915 | mH.sendMessageDelayed(mH.obtainMessage(H.APP_FREEZE_TIMEOUT), |
| 3916 | 5000); |
| 3917 | } |
| 3918 | } |
| 3919 | final int N = wtoken.allAppWindows.size(); |
| 3920 | for (int i=0; i<N; i++) { |
| 3921 | WindowState w = wtoken.allAppWindows.get(i); |
| 3922 | w.mAppFreezing = true; |
| 3923 | } |
| 3924 | } |
| 3925 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3926 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3927 | public void startAppFreezingScreen(IBinder token, int configChanges) { |
| 3928 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3929 | "setAppFreezingScreen()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3930 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3931 | } |
| 3932 | |
| 3933 | synchronized(mWindowMap) { |
Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 3934 | if (configChanges == 0 && !mDisplayFrozen && mPolicy.isScreenOn()) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3935 | 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] | 3936 | return; |
| 3937 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3938 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3939 | AppWindowToken wtoken = findAppWindowToken(token); |
| 3940 | if (wtoken == null || wtoken.appToken == null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3941 | 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] | 3942 | return; |
| 3943 | } |
| 3944 | final long origId = Binder.clearCallingIdentity(); |
| 3945 | startAppFreezingScreenLocked(wtoken, configChanges); |
| 3946 | Binder.restoreCallingIdentity(origId); |
| 3947 | } |
| 3948 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3949 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3950 | public void stopAppFreezingScreen(IBinder token, boolean force) { |
| 3951 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3952 | "setAppFreezingScreen()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3953 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3954 | } |
| 3955 | |
| 3956 | synchronized(mWindowMap) { |
| 3957 | AppWindowToken wtoken = findAppWindowToken(token); |
| 3958 | if (wtoken == null || wtoken.appToken == null) { |
| 3959 | return; |
| 3960 | } |
| 3961 | final long origId = Binder.clearCallingIdentity(); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3962 | 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] | 3963 | + ": hidden=" + wtoken.hidden + " freezing=" + wtoken.freezingScreen); |
| 3964 | unsetAppFreezingScreenLocked(wtoken, true, force); |
| 3965 | Binder.restoreCallingIdentity(origId); |
| 3966 | } |
| 3967 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3968 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3969 | public void removeAppToken(IBinder token) { |
| 3970 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3971 | "removeAppToken()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3972 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3973 | } |
| 3974 | |
| 3975 | AppWindowToken wtoken = null; |
| 3976 | AppWindowToken startingToken = null; |
| 3977 | boolean delayed = false; |
| 3978 | |
| 3979 | final long origId = Binder.clearCallingIdentity(); |
| 3980 | synchronized(mWindowMap) { |
| 3981 | WindowToken basewtoken = mTokenMap.remove(token); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3982 | if (basewtoken != null && (wtoken=basewtoken.appWindowToken) != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3983 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "Removing app token: " + wtoken); |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 3984 | delayed = setTokenVisibilityLocked(wtoken, null, false, WindowManagerPolicy.TRANSIT_UNSET, true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3985 | wtoken.inPendingTransaction = false; |
| 3986 | mOpeningApps.remove(wtoken); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 3987 | wtoken.waitingToShow = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3988 | if (mClosingApps.contains(wtoken)) { |
| 3989 | delayed = true; |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 3990 | } else if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3991 | mClosingApps.add(wtoken); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 3992 | wtoken.waitingToHide = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3993 | delayed = true; |
| 3994 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3995 | if (DEBUG_APP_TRANSITIONS) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3996 | TAG, "Removing app " + wtoken + " delayed=" + delayed |
| 3997 | + " animation=" + wtoken.animation |
| 3998 | + " animating=" + wtoken.animating); |
| 3999 | if (delayed) { |
| 4000 | // set the token aside because it has an active animation to be finished |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 4001 | if (DEBUG_ADD_REMOVE || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG, |
| 4002 | "removeAppToken make exiting: " + wtoken); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4003 | mExitingAppTokens.add(wtoken); |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 4004 | } else { |
| 4005 | // Make sure there is no animation running on this token, |
| 4006 | // so any windows associated with it will be removed as |
| 4007 | // soon as their animations are complete |
| 4008 | wtoken.animation = null; |
| 4009 | wtoken.animating = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4010 | } |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 4011 | if (DEBUG_ADD_REMOVE || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG, |
| 4012 | "removeAppToken: " + wtoken); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4013 | mAppTokens.remove(wtoken); |
| 4014 | wtoken.removed = true; |
| 4015 | if (wtoken.startingData != null) { |
| 4016 | startingToken = wtoken; |
| 4017 | } |
| 4018 | unsetAppFreezingScreenLocked(wtoken, true, true); |
| 4019 | if (mFocusedApp == wtoken) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4020 | 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] | 4021 | mFocusedApp = null; |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 4022 | updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL, true /*updateInputWindows*/); |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 4023 | mInputMonitor.setFocusedAppLw(null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4024 | } |
| 4025 | } else { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4026 | 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] | 4027 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4028 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4029 | if (!delayed && wtoken != null) { |
| 4030 | wtoken.updateReportedVisibilityLocked(); |
| 4031 | } |
| 4032 | } |
| 4033 | Binder.restoreCallingIdentity(origId); |
| 4034 | |
| 4035 | if (startingToken != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4036 | 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] | 4037 | + startingToken + ": app token removed"); |
| 4038 | Message m = mH.obtainMessage(H.REMOVE_STARTING, startingToken); |
| 4039 | mH.sendMessage(m); |
| 4040 | } |
| 4041 | } |
| 4042 | |
| 4043 | private boolean tmpRemoveAppWindowsLocked(WindowToken token) { |
| 4044 | final int NW = token.windows.size(); |
| 4045 | for (int i=0; i<NW; i++) { |
| 4046 | WindowState win = token.windows.get(i); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4047 | 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] | 4048 | mWindows.remove(win); |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 4049 | mWindowsChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4050 | int j = win.mChildWindows.size(); |
| 4051 | while (j > 0) { |
| 4052 | j--; |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 4053 | WindowState cwin = win.mChildWindows.get(j); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4054 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, |
Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 4055 | "Tmp removing child window " + cwin); |
| 4056 | mWindows.remove(cwin); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4057 | } |
| 4058 | } |
| 4059 | return NW > 0; |
| 4060 | } |
| 4061 | |
| 4062 | void dumpAppTokensLocked() { |
| 4063 | for (int i=mAppTokens.size()-1; i>=0; i--) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4064 | Slog.v(TAG, " #" + i + ": " + mAppTokens.get(i).token); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4065 | } |
| 4066 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4067 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4068 | void dumpWindowsLocked() { |
| 4069 | for (int i=mWindows.size()-1; i>=0; i--) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4070 | Slog.v(TAG, " #" + i + ": " + mWindows.get(i)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4071 | } |
| 4072 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4073 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4074 | private int findWindowOffsetLocked(int tokenPos) { |
| 4075 | final int NW = mWindows.size(); |
| 4076 | |
| 4077 | if (tokenPos >= mAppTokens.size()) { |
| 4078 | int i = NW; |
| 4079 | while (i > 0) { |
| 4080 | i--; |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 4081 | WindowState win = mWindows.get(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4082 | if (win.getAppToken() != null) { |
| 4083 | return i+1; |
| 4084 | } |
| 4085 | } |
| 4086 | } |
| 4087 | |
| 4088 | while (tokenPos > 0) { |
| 4089 | // Find the first app token below the new position that has |
| 4090 | // a window displayed. |
| 4091 | final AppWindowToken wtoken = mAppTokens.get(tokenPos-1); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4092 | 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] | 4093 | + tokenPos + " -- " + wtoken.token); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4094 | if (wtoken.sendingToBottom) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4095 | if (DEBUG_REORDER) Slog.v(TAG, |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4096 | "Skipping token -- currently sending to bottom"); |
| 4097 | tokenPos--; |
| 4098 | continue; |
| 4099 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4100 | int i = wtoken.windows.size(); |
| 4101 | while (i > 0) { |
| 4102 | i--; |
| 4103 | WindowState win = wtoken.windows.get(i); |
| 4104 | int j = win.mChildWindows.size(); |
| 4105 | while (j > 0) { |
| 4106 | j--; |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 4107 | WindowState cwin = win.mChildWindows.get(j); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4108 | if (cwin.mSubLayer >= 0) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4109 | for (int pos=NW-1; pos>=0; pos--) { |
| 4110 | if (mWindows.get(pos) == cwin) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4111 | if (DEBUG_REORDER) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4112 | "Found child win @" + (pos+1)); |
| 4113 | return pos+1; |
| 4114 | } |
| 4115 | } |
| 4116 | } |
| 4117 | } |
| 4118 | for (int pos=NW-1; pos>=0; pos--) { |
| 4119 | if (mWindows.get(pos) == win) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4120 | 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] | 4121 | return pos+1; |
| 4122 | } |
| 4123 | } |
| 4124 | } |
| 4125 | tokenPos--; |
| 4126 | } |
| 4127 | |
| 4128 | return 0; |
| 4129 | } |
| 4130 | |
| 4131 | private final int reAddWindowLocked(int index, WindowState win) { |
| 4132 | final int NCW = win.mChildWindows.size(); |
| 4133 | boolean added = false; |
| 4134 | for (int j=0; j<NCW; j++) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 4135 | WindowState cwin = win.mChildWindows.get(j); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4136 | if (!added && cwin.mSubLayer >= 0) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4137 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding child window at " |
Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 4138 | + index + ": " + cwin); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 4139 | win.mRebuilding = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4140 | mWindows.add(index, win); |
| 4141 | index++; |
| 4142 | added = true; |
| 4143 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4144 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding window at " |
Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 4145 | + index + ": " + cwin); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 4146 | cwin.mRebuilding = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4147 | mWindows.add(index, cwin); |
| 4148 | index++; |
| 4149 | } |
| 4150 | if (!added) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4151 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding window at " |
Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 4152 | + index + ": " + win); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 4153 | win.mRebuilding = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4154 | mWindows.add(index, win); |
| 4155 | index++; |
| 4156 | } |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 4157 | mWindowsChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4158 | return index; |
| 4159 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4160 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4161 | private final int reAddAppWindowsLocked(int index, WindowToken token) { |
| 4162 | final int NW = token.windows.size(); |
| 4163 | for (int i=0; i<NW; i++) { |
| 4164 | index = reAddWindowLocked(index, token.windows.get(i)); |
| 4165 | } |
| 4166 | return index; |
| 4167 | } |
| 4168 | |
| 4169 | public void moveAppToken(int index, IBinder token) { |
| 4170 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 4171 | "moveAppToken()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4172 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4173 | } |
| 4174 | |
| 4175 | synchronized(mWindowMap) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4176 | if (DEBUG_REORDER) Slog.v(TAG, "Initial app tokens:"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4177 | if (DEBUG_REORDER) dumpAppTokensLocked(); |
| 4178 | final AppWindowToken wtoken = findAppWindowToken(token); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 4179 | if (DEBUG_TOKEN_MOVEMENT || DEBUG_REORDER) Slog.v(TAG, |
| 4180 | "Start moving token " + wtoken + " initially at " |
| 4181 | + mAppTokens.indexOf(wtoken)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4182 | if (wtoken == null || !mAppTokens.remove(wtoken)) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4183 | 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] | 4184 | + token + " (" + wtoken + ")"); |
| 4185 | return; |
| 4186 | } |
| 4187 | mAppTokens.add(index, wtoken); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4188 | if (DEBUG_REORDER) Slog.v(TAG, "Moved " + token + " to " + index + ":"); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 4189 | else if (DEBUG_TOKEN_MOVEMENT) Slog.v(TAG, "Moved " + token + " to " + index); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4190 | if (DEBUG_REORDER) dumpAppTokensLocked(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4191 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4192 | final long origId = Binder.clearCallingIdentity(); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4193 | 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] | 4194 | if (DEBUG_REORDER) dumpWindowsLocked(); |
| 4195 | if (tmpRemoveAppWindowsLocked(wtoken)) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4196 | 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] | 4197 | if (DEBUG_REORDER) dumpWindowsLocked(); |
| 4198 | reAddAppWindowsLocked(findWindowOffsetLocked(index), wtoken); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4199 | if (DEBUG_REORDER) Slog.v(TAG, "Final window list:"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4200 | if (DEBUG_REORDER) dumpWindowsLocked(); |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 4201 | updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES, |
| 4202 | false /*updateInputWindows*/); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4203 | mLayoutNeeded = true; |
Jeff Brown | 2e44b07 | 2011-01-24 15:21:56 -0800 | [diff] [blame] | 4204 | mInputMonitor.setUpdateInputWindowsNeededLw(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4205 | performLayoutAndPlaceSurfacesLocked(); |
Jeff Brown | 2e44b07 | 2011-01-24 15:21:56 -0800 | [diff] [blame] | 4206 | mInputMonitor.updateInputWindowsLw(false /*force*/); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4207 | } |
| 4208 | Binder.restoreCallingIdentity(origId); |
| 4209 | } |
| 4210 | } |
| 4211 | |
| 4212 | private void removeAppTokensLocked(List<IBinder> tokens) { |
| 4213 | // XXX This should be done more efficiently! |
| 4214 | // (take advantage of the fact that both lists should be |
| 4215 | // ordered in the same way.) |
| 4216 | int N = tokens.size(); |
| 4217 | for (int i=0; i<N; i++) { |
| 4218 | IBinder token = tokens.get(i); |
| 4219 | final AppWindowToken wtoken = findAppWindowToken(token); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 4220 | if (DEBUG_REORDER || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG, |
| 4221 | "Temporarily removing " + wtoken + " from " + mAppTokens.indexOf(wtoken)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4222 | if (!mAppTokens.remove(wtoken)) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4223 | 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] | 4224 | + token + " (" + wtoken + ")"); |
| 4225 | i--; |
| 4226 | N--; |
| 4227 | } |
| 4228 | } |
| 4229 | } |
| 4230 | |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4231 | private void moveAppWindowsLocked(AppWindowToken wtoken, int tokenPos, |
| 4232 | boolean updateFocusAndLayout) { |
| 4233 | // First remove all of the windows from the list. |
| 4234 | tmpRemoveAppWindowsLocked(wtoken); |
| 4235 | |
| 4236 | // Where to start adding? |
| 4237 | int pos = findWindowOffsetLocked(tokenPos); |
| 4238 | |
| 4239 | // And now add them back at the correct place. |
| 4240 | pos = reAddAppWindowsLocked(pos, wtoken); |
| 4241 | |
| 4242 | if (updateFocusAndLayout) { |
Jeff Brown | 2e44b07 | 2011-01-24 15:21:56 -0800 | [diff] [blame] | 4243 | mInputMonitor.setUpdateInputWindowsNeededLw(); |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 4244 | if (!updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES, |
| 4245 | false /*updateInputWindows*/)) { |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4246 | assignLayersLocked(); |
| 4247 | } |
| 4248 | mLayoutNeeded = true; |
| 4249 | performLayoutAndPlaceSurfacesLocked(); |
Jeff Brown | 2e44b07 | 2011-01-24 15:21:56 -0800 | [diff] [blame] | 4250 | mInputMonitor.updateInputWindowsLw(false /*force*/); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4251 | } |
| 4252 | } |
| 4253 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4254 | private void moveAppWindowsLocked(List<IBinder> tokens, int tokenPos) { |
| 4255 | // First remove all of the windows from the list. |
| 4256 | final int N = tokens.size(); |
| 4257 | int i; |
| 4258 | for (i=0; i<N; i++) { |
| 4259 | WindowToken token = mTokenMap.get(tokens.get(i)); |
| 4260 | if (token != null) { |
| 4261 | tmpRemoveAppWindowsLocked(token); |
| 4262 | } |
| 4263 | } |
| 4264 | |
| 4265 | // Where to start adding? |
| 4266 | int pos = findWindowOffsetLocked(tokenPos); |
| 4267 | |
| 4268 | // And now add them back at the correct place. |
| 4269 | for (i=0; i<N; i++) { |
| 4270 | WindowToken token = mTokenMap.get(tokens.get(i)); |
| 4271 | if (token != null) { |
| 4272 | pos = reAddAppWindowsLocked(pos, token); |
| 4273 | } |
| 4274 | } |
| 4275 | |
Jeff Brown | 2e44b07 | 2011-01-24 15:21:56 -0800 | [diff] [blame] | 4276 | mInputMonitor.setUpdateInputWindowsNeededLw(); |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 4277 | if (!updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES, |
| 4278 | false /*updateInputWindows*/)) { |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4279 | assignLayersLocked(); |
| 4280 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4281 | mLayoutNeeded = true; |
| 4282 | performLayoutAndPlaceSurfacesLocked(); |
Jeff Brown | 2e44b07 | 2011-01-24 15:21:56 -0800 | [diff] [blame] | 4283 | mInputMonitor.updateInputWindowsLw(false /*force*/); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4284 | |
| 4285 | //dump(); |
| 4286 | } |
| 4287 | |
| 4288 | public void moveAppTokensToTop(List<IBinder> tokens) { |
| 4289 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 4290 | "moveAppTokensToTop()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4291 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4292 | } |
| 4293 | |
| 4294 | final long origId = Binder.clearCallingIdentity(); |
| 4295 | synchronized(mWindowMap) { |
| 4296 | removeAppTokensLocked(tokens); |
| 4297 | final int N = tokens.size(); |
| 4298 | for (int i=0; i<N; i++) { |
| 4299 | AppWindowToken wt = findAppWindowToken(tokens.get(i)); |
| 4300 | if (wt != null) { |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 4301 | if (DEBUG_TOKEN_MOVEMENT || DEBUG_REORDER) Slog.v(TAG, |
| 4302 | "Adding next to top: " + wt); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4303 | mAppTokens.add(wt); |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 4304 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4305 | mToTopApps.remove(wt); |
| 4306 | mToBottomApps.remove(wt); |
| 4307 | mToTopApps.add(wt); |
| 4308 | wt.sendingToBottom = false; |
| 4309 | wt.sendingToTop = true; |
| 4310 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4311 | } |
| 4312 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 4313 | |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 4314 | if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET) { |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4315 | moveAppWindowsLocked(tokens, mAppTokens.size()); |
| 4316 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4317 | } |
| 4318 | Binder.restoreCallingIdentity(origId); |
| 4319 | } |
| 4320 | |
| 4321 | public void moveAppTokensToBottom(List<IBinder> tokens) { |
| 4322 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 4323 | "moveAppTokensToBottom()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4324 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4325 | } |
| 4326 | |
| 4327 | final long origId = Binder.clearCallingIdentity(); |
| 4328 | synchronized(mWindowMap) { |
| 4329 | removeAppTokensLocked(tokens); |
| 4330 | final int N = tokens.size(); |
| 4331 | int pos = 0; |
| 4332 | for (int i=0; i<N; i++) { |
| 4333 | AppWindowToken wt = findAppWindowToken(tokens.get(i)); |
| 4334 | if (wt != null) { |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 4335 | if (DEBUG_TOKEN_MOVEMENT) Slog.v(TAG, |
| 4336 | "Adding next to bottom: " + wt + " at " + pos); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4337 | mAppTokens.add(pos, wt); |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 4338 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4339 | mToTopApps.remove(wt); |
| 4340 | mToBottomApps.remove(wt); |
| 4341 | mToBottomApps.add(i, wt); |
| 4342 | wt.sendingToTop = false; |
| 4343 | wt.sendingToBottom = true; |
| 4344 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4345 | pos++; |
| 4346 | } |
| 4347 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 4348 | |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 4349 | if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET) { |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4350 | moveAppWindowsLocked(tokens, 0); |
| 4351 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4352 | } |
| 4353 | Binder.restoreCallingIdentity(origId); |
| 4354 | } |
| 4355 | |
| 4356 | // ------------------------------------------------------------- |
| 4357 | // Misc IWindowSession methods |
| 4358 | // ------------------------------------------------------------- |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4359 | |
Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 4360 | private boolean shouldAllowDisableKeyguard() |
Jim Miller | d6b5705 | 2010-06-07 17:52:42 -0700 | [diff] [blame] | 4361 | { |
Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 4362 | // We fail safe and prevent disabling keyguard in the unlikely event this gets |
| 4363 | // called before DevicePolicyManagerService has started. |
| 4364 | if (mAllowDisableKeyguard == ALLOW_DISABLE_UNKNOWN) { |
| 4365 | DevicePolicyManager dpm = (DevicePolicyManager) mContext.getSystemService( |
| 4366 | Context.DEVICE_POLICY_SERVICE); |
| 4367 | if (dpm != null) { |
| 4368 | mAllowDisableKeyguard = dpm.getPasswordQuality(null) |
| 4369 | == DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED ? |
| 4370 | ALLOW_DISABLE_YES : ALLOW_DISABLE_NO; |
| 4371 | } |
Jim Miller | d6b5705 | 2010-06-07 17:52:42 -0700 | [diff] [blame] | 4372 | } |
Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 4373 | return mAllowDisableKeyguard == ALLOW_DISABLE_YES; |
Jim Miller | d6b5705 | 2010-06-07 17:52:42 -0700 | [diff] [blame] | 4374 | } |
| 4375 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4376 | public void disableKeyguard(IBinder token, String tag) { |
Mike Lockwood | 733fdf3 | 2009-09-28 19:08:53 -0400 | [diff] [blame] | 4377 | if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4378 | != PackageManager.PERMISSION_GRANTED) { |
| 4379 | throw new SecurityException("Requires DISABLE_KEYGUARD permission"); |
| 4380 | } |
Jim Miller | d6b5705 | 2010-06-07 17:52:42 -0700 | [diff] [blame] | 4381 | |
Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 4382 | synchronized (mKeyguardTokenWatcher) { |
| 4383 | mKeyguardTokenWatcher.acquire(token, tag); |
Mike Lockwood | dd88468 | 2009-10-11 16:57:08 -0400 | [diff] [blame] | 4384 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4385 | } |
| 4386 | |
| 4387 | public void reenableKeyguard(IBinder token) { |
Mike Lockwood | 733fdf3 | 2009-09-28 19:08:53 -0400 | [diff] [blame] | 4388 | if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4389 | != PackageManager.PERMISSION_GRANTED) { |
| 4390 | throw new SecurityException("Requires DISABLE_KEYGUARD permission"); |
| 4391 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4392 | |
Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 4393 | synchronized (mKeyguardTokenWatcher) { |
| 4394 | mKeyguardTokenWatcher.release(token); |
Jim Miller | d6b5705 | 2010-06-07 17:52:42 -0700 | [diff] [blame] | 4395 | |
Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 4396 | if (!mKeyguardTokenWatcher.isAcquired()) { |
| 4397 | // If we are the last one to reenable the keyguard wait until |
| 4398 | // we have actually finished reenabling until returning. |
| 4399 | // It is possible that reenableKeyguard() can be called before |
| 4400 | // the previous disableKeyguard() is handled, in which case |
| 4401 | // neither mKeyguardTokenWatcher.acquired() or released() would |
| 4402 | // be called. In that case mKeyguardDisabled will be false here |
| 4403 | // and we have nothing to wait for. |
| 4404 | while (mKeyguardDisabled) { |
| 4405 | try { |
| 4406 | mKeyguardTokenWatcher.wait(); |
| 4407 | } catch (InterruptedException e) { |
| 4408 | Thread.currentThread().interrupt(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4409 | } |
| 4410 | } |
| 4411 | } |
| 4412 | } |
| 4413 | } |
| 4414 | |
| 4415 | /** |
| 4416 | * @see android.app.KeyguardManager#exitKeyguardSecurely |
| 4417 | */ |
| 4418 | public void exitKeyguardSecurely(final IOnKeyguardExitResult callback) { |
Mike Lockwood | 733fdf3 | 2009-09-28 19:08:53 -0400 | [diff] [blame] | 4419 | if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4420 | != PackageManager.PERMISSION_GRANTED) { |
| 4421 | throw new SecurityException("Requires DISABLE_KEYGUARD permission"); |
| 4422 | } |
| 4423 | mPolicy.exitKeyguardSecurely(new WindowManagerPolicy.OnKeyguardExitResult() { |
| 4424 | public void onKeyguardExitResult(boolean success) { |
| 4425 | try { |
| 4426 | callback.onKeyguardExitResult(success); |
| 4427 | } catch (RemoteException e) { |
| 4428 | // Client has died, we don't care. |
| 4429 | } |
| 4430 | } |
| 4431 | }); |
| 4432 | } |
| 4433 | |
| 4434 | public boolean inKeyguardRestrictedInputMode() { |
| 4435 | return mPolicy.inKeyguardRestrictedKeyInputMode(); |
| 4436 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4437 | |
Mike Lockwood | 520d8bc | 2011-02-18 13:23:13 -0500 | [diff] [blame] | 4438 | public boolean isKeyguardLocked() { |
| 4439 | return mPolicy.isKeyguardLocked(); |
| 4440 | } |
| 4441 | |
| 4442 | public boolean isKeyguardSecure() { |
| 4443 | return mPolicy.isKeyguardSecure(); |
| 4444 | } |
| 4445 | |
Dianne Hackborn | ffa4248 | 2009-09-23 22:20:11 -0700 | [diff] [blame] | 4446 | public void closeSystemDialogs(String reason) { |
| 4447 | synchronized(mWindowMap) { |
| 4448 | for (int i=mWindows.size()-1; i>=0; i--) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 4449 | WindowState w = mWindows.get(i); |
Dianne Hackborn | ffa4248 | 2009-09-23 22:20:11 -0700 | [diff] [blame] | 4450 | if (w.mSurface != null) { |
| 4451 | try { |
| 4452 | w.mClient.closeSystemDialogs(reason); |
| 4453 | } catch (RemoteException e) { |
| 4454 | } |
| 4455 | } |
| 4456 | } |
| 4457 | } |
| 4458 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 4459 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4460 | static float fixScale(float scale) { |
| 4461 | if (scale < 0) scale = 0; |
| 4462 | else if (scale > 20) scale = 20; |
| 4463 | return Math.abs(scale); |
| 4464 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4465 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4466 | public void setAnimationScale(int which, float scale) { |
| 4467 | if (!checkCallingPermission(android.Manifest.permission.SET_ANIMATION_SCALE, |
| 4468 | "setAnimationScale()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4469 | throw new SecurityException("Requires SET_ANIMATION_SCALE permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4470 | } |
| 4471 | |
| 4472 | if (scale < 0) scale = 0; |
| 4473 | else if (scale > 20) scale = 20; |
| 4474 | scale = Math.abs(scale); |
| 4475 | switch (which) { |
| 4476 | case 0: mWindowAnimationScale = fixScale(scale); break; |
| 4477 | case 1: mTransitionAnimationScale = fixScale(scale); break; |
| 4478 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4479 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4480 | // Persist setting |
| 4481 | mH.obtainMessage(H.PERSIST_ANIMATION_SCALE).sendToTarget(); |
| 4482 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4483 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4484 | public void setAnimationScales(float[] scales) { |
| 4485 | if (!checkCallingPermission(android.Manifest.permission.SET_ANIMATION_SCALE, |
| 4486 | "setAnimationScale()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4487 | throw new SecurityException("Requires SET_ANIMATION_SCALE permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4488 | } |
| 4489 | |
| 4490 | if (scales != null) { |
| 4491 | if (scales.length >= 1) { |
| 4492 | mWindowAnimationScale = fixScale(scales[0]); |
| 4493 | } |
| 4494 | if (scales.length >= 2) { |
| 4495 | mTransitionAnimationScale = fixScale(scales[1]); |
| 4496 | } |
| 4497 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4498 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4499 | // Persist setting |
| 4500 | mH.obtainMessage(H.PERSIST_ANIMATION_SCALE).sendToTarget(); |
| 4501 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4502 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4503 | public float getAnimationScale(int which) { |
| 4504 | switch (which) { |
| 4505 | case 0: return mWindowAnimationScale; |
| 4506 | case 1: return mTransitionAnimationScale; |
| 4507 | } |
| 4508 | return 0; |
| 4509 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4510 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4511 | public float[] getAnimationScales() { |
| 4512 | return new float[] { mWindowAnimationScale, mTransitionAnimationScale }; |
| 4513 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4514 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4515 | public int getSwitchState(int sw) { |
| 4516 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4517 | "getSwitchState()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4518 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4519 | } |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 4520 | return mInputManager.getSwitchState(-1, InputDevice.SOURCE_ANY, sw); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4521 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4522 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4523 | public int getSwitchStateForDevice(int devid, int sw) { |
| 4524 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4525 | "getSwitchStateForDevice()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4526 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4527 | } |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 4528 | return mInputManager.getSwitchState(devid, InputDevice.SOURCE_ANY, sw); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4529 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4530 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4531 | public int getScancodeState(int sw) { |
| 4532 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4533 | "getScancodeState()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4534 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4535 | } |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 4536 | return mInputManager.getScanCodeState(-1, InputDevice.SOURCE_ANY, sw); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4537 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4538 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4539 | public int getScancodeStateForDevice(int devid, int sw) { |
| 4540 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4541 | "getScancodeStateForDevice()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4542 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4543 | } |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 4544 | return mInputManager.getScanCodeState(devid, InputDevice.SOURCE_ANY, sw); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4545 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4546 | |
Dianne Hackborn | 1d62ea9 | 2009-11-17 12:49:50 -0800 | [diff] [blame] | 4547 | public int getTrackballScancodeState(int sw) { |
| 4548 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4549 | "getTrackballScancodeState()")) { |
| 4550 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
| 4551 | } |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 4552 | return mInputManager.getScanCodeState(-1, InputDevice.SOURCE_TRACKBALL, sw); |
Dianne Hackborn | 1d62ea9 | 2009-11-17 12:49:50 -0800 | [diff] [blame] | 4553 | } |
| 4554 | |
| 4555 | public int getDPadScancodeState(int sw) { |
| 4556 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4557 | "getDPadScancodeState()")) { |
| 4558 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
| 4559 | } |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 4560 | return mInputManager.getScanCodeState(-1, InputDevice.SOURCE_DPAD, sw); |
Dianne Hackborn | 1d62ea9 | 2009-11-17 12:49:50 -0800 | [diff] [blame] | 4561 | } |
| 4562 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4563 | public int getKeycodeState(int sw) { |
| 4564 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4565 | "getKeycodeState()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4566 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4567 | } |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 4568 | return mInputManager.getKeyCodeState(-1, InputDevice.SOURCE_ANY, sw); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4569 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4570 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4571 | public int getKeycodeStateForDevice(int devid, int sw) { |
| 4572 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4573 | "getKeycodeStateForDevice()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4574 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4575 | } |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 4576 | return mInputManager.getKeyCodeState(devid, InputDevice.SOURCE_ANY, sw); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4577 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4578 | |
Dianne Hackborn | 1d62ea9 | 2009-11-17 12:49:50 -0800 | [diff] [blame] | 4579 | public int getTrackballKeycodeState(int sw) { |
| 4580 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4581 | "getTrackballKeycodeState()")) { |
| 4582 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
| 4583 | } |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 4584 | return mInputManager.getKeyCodeState(-1, InputDevice.SOURCE_TRACKBALL, sw); |
Dianne Hackborn | 1d62ea9 | 2009-11-17 12:49:50 -0800 | [diff] [blame] | 4585 | } |
| 4586 | |
| 4587 | public int getDPadKeycodeState(int sw) { |
| 4588 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4589 | "getDPadKeycodeState()")) { |
| 4590 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
| 4591 | } |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 4592 | return mInputManager.getKeyCodeState(-1, InputDevice.SOURCE_DPAD, sw); |
Dianne Hackborn | 1d62ea9 | 2009-11-17 12:49:50 -0800 | [diff] [blame] | 4593 | } |
Jeff Brown | a41ca77 | 2010-08-11 14:46:32 -0700 | [diff] [blame] | 4594 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4595 | public boolean hasKeys(int[] keycodes, boolean[] keyExists) { |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 4596 | return mInputManager.hasKeys(-1, InputDevice.SOURCE_ANY, keycodes, keyExists); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4597 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4598 | |
Jeff Brown | a41ca77 | 2010-08-11 14:46:32 -0700 | [diff] [blame] | 4599 | public InputChannel monitorInput(String inputChannelName) { |
| 4600 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4601 | "monitorInput()")) { |
| 4602 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
| 4603 | } |
| 4604 | return mInputManager.monitorInput(inputChannelName); |
| 4605 | } |
| 4606 | |
Jeff Brown | 0029c66 | 2011-03-30 02:25:18 -0700 | [diff] [blame] | 4607 | public void setInputFilter(InputFilter filter) { |
| 4608 | mInputManager.setInputFilter(filter); |
| 4609 | } |
| 4610 | |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 4611 | public InputDevice getInputDevice(int deviceId) { |
| 4612 | return mInputManager.getInputDevice(deviceId); |
| 4613 | } |
| 4614 | |
| 4615 | public int[] getInputDeviceIds() { |
| 4616 | return mInputManager.getInputDeviceIds(); |
| 4617 | } |
| 4618 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4619 | public void enableScreenAfterBoot() { |
| 4620 | synchronized(mWindowMap) { |
| 4621 | if (mSystemBooted) { |
| 4622 | return; |
| 4623 | } |
| 4624 | mSystemBooted = true; |
| 4625 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4626 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4627 | performEnableScreen(); |
| 4628 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4629 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4630 | public void enableScreenIfNeededLocked() { |
| 4631 | if (mDisplayEnabled) { |
| 4632 | return; |
| 4633 | } |
| 4634 | if (!mSystemBooted) { |
| 4635 | return; |
| 4636 | } |
| 4637 | mH.sendMessage(mH.obtainMessage(H.ENABLE_SCREEN)); |
| 4638 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4639 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4640 | public void performEnableScreen() { |
| 4641 | synchronized(mWindowMap) { |
| 4642 | if (mDisplayEnabled) { |
| 4643 | return; |
| 4644 | } |
| 4645 | if (!mSystemBooted) { |
| 4646 | return; |
| 4647 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4648 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4649 | // Don't enable the screen until all existing windows |
| 4650 | // have been drawn. |
| 4651 | final int N = mWindows.size(); |
| 4652 | for (int i=0; i<N; i++) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 4653 | WindowState w = mWindows.get(i); |
Dianne Hackborn | f3bea9c | 2009-12-09 18:26:21 -0800 | [diff] [blame] | 4654 | if (w.isVisibleLw() && !w.mObscured && !w.isDrawnLw()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4655 | return; |
| 4656 | } |
| 4657 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4658 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4659 | mDisplayEnabled = true; |
| 4660 | if (false) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4661 | Slog.i(TAG, "ENABLING SCREEN!"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4662 | StringWriter sw = new StringWriter(); |
| 4663 | PrintWriter pw = new PrintWriter(sw); |
| 4664 | this.dump(null, pw, null); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4665 | Slog.i(TAG, sw.toString()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4666 | } |
| 4667 | try { |
| 4668 | IBinder surfaceFlinger = ServiceManager.getService("SurfaceFlinger"); |
| 4669 | if (surfaceFlinger != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4670 | //Slog.i(TAG, "******* TELLING SURFACE FLINGER WE ARE BOOTED!"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4671 | Parcel data = Parcel.obtain(); |
| 4672 | data.writeInterfaceToken("android.ui.ISurfaceComposer"); |
| 4673 | surfaceFlinger.transact(IBinder.FIRST_CALL_TRANSACTION, |
| 4674 | data, null, 0); |
| 4675 | data.recycle(); |
| 4676 | } |
| 4677 | } catch (RemoteException ex) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4678 | Slog.e(TAG, "Boot completed: SurfaceFlinger is dead!"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4679 | } |
| 4680 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4681 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4682 | mPolicy.enableScreenAfterBoot(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4683 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4684 | // Make sure the last requested orientation has been applied. |
Dianne Hackborn | 321ae68 | 2009-03-27 16:16:03 -0700 | [diff] [blame] | 4685 | setRotationUnchecked(WindowManagerPolicy.USE_LAST_ROTATION, false, |
| 4686 | mLastRotationFlags | Surface.FLAGS_ORIENTATION_ANIMATION_DISABLE); |
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 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4689 | public void setInTouchMode(boolean mode) { |
| 4690 | synchronized(mWindowMap) { |
| 4691 | mInTouchMode = mode; |
| 4692 | } |
| 4693 | } |
| 4694 | |
Brad Fitzpatrick | 6804433 | 2010-11-22 18:19:48 -0800 | [diff] [blame] | 4695 | // TODO: more accounting of which pid(s) turned it on, keep count, |
| 4696 | // only allow disables from pids which have count on, etc. |
| 4697 | public void showStrictModeViolation(boolean on) { |
| 4698 | int pid = Binder.getCallingPid(); |
| 4699 | synchronized(mWindowMap) { |
| 4700 | // Ignoring requests to enable the red border from clients |
| 4701 | // which aren't on screen. (e.g. Broadcast Receivers in |
| 4702 | // the background..) |
| 4703 | if (on) { |
| 4704 | boolean isVisible = false; |
| 4705 | for (WindowState ws : mWindows) { |
| 4706 | if (ws.mSession.mPid == pid && ws.isVisibleLw()) { |
| 4707 | isVisible = true; |
| 4708 | break; |
| 4709 | } |
| 4710 | } |
| 4711 | if (!isVisible) { |
| 4712 | return; |
| 4713 | } |
| 4714 | } |
| 4715 | |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 4716 | if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION showStrictModeViolation"); |
Brad Fitzpatrick | 6804433 | 2010-11-22 18:19:48 -0800 | [diff] [blame] | 4717 | Surface.openTransaction(); |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 4718 | try { |
| 4719 | if (mStrictModeFlash == null) { |
| 4720 | mStrictModeFlash = new StrictModeFlash(mDisplay, mFxSession); |
| 4721 | } |
| 4722 | mStrictModeFlash.setVisibility(on); |
| 4723 | } finally { |
| 4724 | Surface.closeTransaction(); |
| 4725 | if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION showStrictModeViolation"); |
Brad Fitzpatrick | 6804433 | 2010-11-22 18:19:48 -0800 | [diff] [blame] | 4726 | } |
Brad Fitzpatrick | 6804433 | 2010-11-22 18:19:48 -0800 | [diff] [blame] | 4727 | } |
| 4728 | } |
| 4729 | |
Brad Fitzpatrick | c1a968a | 2010-11-24 08:56:40 -0800 | [diff] [blame] | 4730 | public void setStrictModeVisualIndicatorPreference(String value) { |
| 4731 | SystemProperties.set(StrictMode.VISUAL_PROPERTY, value); |
| 4732 | } |
| 4733 | |
Jim Miller | e70d506 | 2011-03-08 21:38:39 -0800 | [diff] [blame] | 4734 | /** |
| 4735 | * Takes a snapshot of the screen. In landscape mode this grabs the whole screen. |
| 4736 | * In portrait mode, it grabs the upper region of the screen based on the vertical dimension |
| 4737 | * of the target image. |
| 4738 | * |
| 4739 | * @param width the width of the target bitmap |
| 4740 | * @param height the height of the target bitmap |
| 4741 | */ |
| 4742 | public Bitmap screenshotApplications(IBinder appToken, int width, int height) { |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 4743 | if (!checkCallingPermission(android.Manifest.permission.READ_FRAME_BUFFER, |
| 4744 | "screenshotApplications()")) { |
| 4745 | throw new SecurityException("Requires READ_FRAME_BUFFER permission"); |
| 4746 | } |
| 4747 | |
| 4748 | Bitmap rawss; |
| 4749 | |
Dianne Hackborn | d283593 | 2010-12-13 16:28:46 -0800 | [diff] [blame] | 4750 | int maxLayer = 0; |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 4751 | final Rect frame = new Rect(); |
| 4752 | |
| 4753 | float scale; |
Jim Miller | e70d506 | 2011-03-08 21:38:39 -0800 | [diff] [blame] | 4754 | int dw, dh; |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 4755 | int rot; |
| 4756 | |
| 4757 | synchronized(mWindowMap) { |
| 4758 | long ident = Binder.clearCallingIdentity(); |
| 4759 | |
Dianne Hackborn | 428ecb6 | 2011-01-26 14:53:23 -0800 | [diff] [blame] | 4760 | dw = mDisplay.getWidth(); |
| 4761 | dh = mDisplay.getHeight(); |
| 4762 | |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 4763 | int aboveAppLayer = mPolicy.windowTypeToLayerLw( |
| 4764 | WindowManager.LayoutParams.TYPE_APPLICATION) * TYPE_LAYER_MULTIPLIER |
| 4765 | + TYPE_LAYER_OFFSET; |
| 4766 | aboveAppLayer += TYPE_LAYER_MULTIPLIER; |
| 4767 | |
Dianne Hackborn | 428ecb6 | 2011-01-26 14:53:23 -0800 | [diff] [blame] | 4768 | boolean isImeTarget = mInputMethodTarget != null |
| 4769 | && mInputMethodTarget.mAppToken != null |
| 4770 | && mInputMethodTarget.mAppToken.appToken != null |
| 4771 | && mInputMethodTarget.mAppToken.appToken.asBinder() == appToken; |
| 4772 | |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 4773 | // Figure out the part of the screen that is actually the app. |
Dianne Hackborn | 428ecb6 | 2011-01-26 14:53:23 -0800 | [diff] [blame] | 4774 | boolean including = false; |
| 4775 | for (int i=mWindows.size()-1; i>=0; i--) { |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 4776 | WindowState ws = mWindows.get(i); |
| 4777 | if (ws.mSurface == null) { |
| 4778 | continue; |
| 4779 | } |
| 4780 | if (ws.mLayer >= aboveAppLayer) { |
Dianne Hackborn | d283593 | 2010-12-13 16:28:46 -0800 | [diff] [blame] | 4781 | continue; |
| 4782 | } |
Dianne Hackborn | 428ecb6 | 2011-01-26 14:53:23 -0800 | [diff] [blame] | 4783 | // When we will skip windows: when we are not including |
| 4784 | // ones behind a window we didn't skip, and we are actually |
| 4785 | // taking a screenshot of a specific app. |
| 4786 | if (!including && appToken != null) { |
| 4787 | // Also, we can possibly skip this window if it is not |
| 4788 | // an IME target or the application for the screenshot |
| 4789 | // is not the current IME target. |
| 4790 | if (!ws.mIsImWindow || !isImeTarget) { |
| 4791 | // And finally, this window is of no interest if it |
| 4792 | // is not associated with the screenshot app. |
| 4793 | if (ws.mAppToken == null || ws.mAppToken.token != appToken) { |
| 4794 | continue; |
| 4795 | } |
| 4796 | } |
| 4797 | } |
| 4798 | |
| 4799 | // We keep on including windows until we go past a full-screen |
| 4800 | // window. |
| 4801 | including = !ws.mIsImWindow && !ws.isFullscreen(dw, dh); |
| 4802 | |
Dianne Hackborn | d283593 | 2010-12-13 16:28:46 -0800 | [diff] [blame] | 4803 | if (maxLayer < ws.mAnimLayer) { |
| 4804 | maxLayer = ws.mAnimLayer; |
| 4805 | } |
Jim Miller | 2aded18 | 2011-03-08 15:32:42 -0800 | [diff] [blame] | 4806 | |
| 4807 | // Don't include wallpaper in bounds calculation |
| 4808 | if (!ws.mIsWallpaper) { |
| 4809 | final Rect wf = ws.mFrame; |
| 4810 | final Rect cr = ws.mContentInsets; |
| 4811 | int left = wf.left + cr.left; |
| 4812 | int top = wf.top + cr.top; |
| 4813 | int right = wf.right - cr.right; |
| 4814 | int bottom = wf.bottom - cr.bottom; |
| 4815 | frame.union(left, top, right, bottom); |
| 4816 | } |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 4817 | } |
| 4818 | Binder.restoreCallingIdentity(ident); |
| 4819 | |
Dianne Hackborn | dd962ee | 2011-02-02 11:11:50 -0800 | [diff] [blame] | 4820 | // Constrain frame to the screen size. |
| 4821 | frame.intersect(0, 0, dw, dh); |
Jim Miller | e70d506 | 2011-03-08 21:38:39 -0800 | [diff] [blame] | 4822 | |
Dianne Hackborn | cb8f0e0 | 2010-12-16 11:15:18 -0800 | [diff] [blame] | 4823 | if (frame.isEmpty() || maxLayer == 0) { |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 4824 | return null; |
| 4825 | } |
| 4826 | |
| 4827 | // The screenshot API does not apply the current screen rotation. |
| 4828 | rot = mDisplay.getRotation(); |
| 4829 | int fw = frame.width(); |
| 4830 | int fh = frame.height(); |
| 4831 | |
| 4832 | // First try reducing to fit in x dimension. |
Jim Miller | e70d506 | 2011-03-08 21:38:39 -0800 | [diff] [blame] | 4833 | scale = width/(float)fw; |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 4834 | |
| 4835 | // The screen shot will contain the entire screen. |
Dianne Hackborn | 428ecb6 | 2011-01-26 14:53:23 -0800 | [diff] [blame] | 4836 | dw = (int)(dw*scale); |
| 4837 | dh = (int)(dh*scale); |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 4838 | if (rot == Surface.ROTATION_90 || rot == Surface.ROTATION_270) { |
| 4839 | int tmp = dw; |
| 4840 | dw = dh; |
| 4841 | dh = tmp; |
| 4842 | rot = (rot == Surface.ROTATION_90) ? Surface.ROTATION_270 : Surface.ROTATION_90; |
| 4843 | } |
Dianne Hackborn | d283593 | 2010-12-13 16:28:46 -0800 | [diff] [blame] | 4844 | rawss = Surface.screenshot(dw, dh, 0, maxLayer); |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 4845 | } |
| 4846 | |
Dianne Hackborn | cb8f0e0 | 2010-12-16 11:15:18 -0800 | [diff] [blame] | 4847 | if (rawss == null) { |
Dianne Hackborn | 88b03bd | 2010-12-16 11:15:18 -0800 | [diff] [blame] | 4848 | Log.w(TAG, "Failure taking screenshot for (" + dw + "x" + dh |
| 4849 | + ") to layer " + maxLayer); |
Dianne Hackborn | cb8f0e0 | 2010-12-16 11:15:18 -0800 | [diff] [blame] | 4850 | return null; |
| 4851 | } |
Jim Miller | e70d506 | 2011-03-08 21:38:39 -0800 | [diff] [blame] | 4852 | |
| 4853 | Bitmap bm = Bitmap.createBitmap(width, height, rawss.getConfig()); |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 4854 | Matrix matrix = new Matrix(); |
| 4855 | ScreenRotationAnimation.createRotationMatrix(rot, dw, dh, matrix); |
| 4856 | matrix.postTranslate(-(int)(frame.left*scale), -(int)(frame.top*scale)); |
| 4857 | Canvas canvas = new Canvas(bm); |
| 4858 | canvas.drawBitmap(rawss, matrix, null); |
| 4859 | |
| 4860 | rawss.recycle(); |
| 4861 | return bm; |
| 4862 | } |
| 4863 | |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 4864 | public void freezeRotation() { |
| 4865 | if (!checkCallingPermission(android.Manifest.permission.SET_ORIENTATION, |
Daniel Sandler | 2ed6ad6 | 2011-02-22 14:54:17 -0500 | [diff] [blame] | 4866 | "freezeRotation()")) { |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 4867 | throw new SecurityException("Requires SET_ORIENTATION permission"); |
| 4868 | } |
| 4869 | |
Daniel Sandler | 2ed6ad6 | 2011-02-22 14:54:17 -0500 | [diff] [blame] | 4870 | if (DEBUG_ORIENTATION) Slog.v(TAG, "freezeRotation: mRotation=" + mRotation); |
| 4871 | |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 4872 | mPolicy.setUserRotationMode(WindowManagerPolicy.USER_ROTATION_LOCKED, mRotation); |
| 4873 | setRotationUnchecked(WindowManagerPolicy.USE_LAST_ROTATION, false, 0); |
| 4874 | } |
| 4875 | |
| 4876 | public void thawRotation() { |
| 4877 | if (!checkCallingPermission(android.Manifest.permission.SET_ORIENTATION, |
Daniel Sandler | 2ed6ad6 | 2011-02-22 14:54:17 -0500 | [diff] [blame] | 4878 | "thawRotation()")) { |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 4879 | throw new SecurityException("Requires SET_ORIENTATION permission"); |
| 4880 | } |
| 4881 | |
Daniel Sandler | 2ed6ad6 | 2011-02-22 14:54:17 -0500 | [diff] [blame] | 4882 | if (DEBUG_ORIENTATION) Slog.v(TAG, "thawRotation: mRotation=" + mRotation); |
| 4883 | |
| 4884 | mPolicy.setUserRotationMode(WindowManagerPolicy.USER_ROTATION_FREE, 777); // rot not used |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 4885 | setRotationUnchecked(WindowManagerPolicy.USE_LAST_ROTATION, false, 0); |
| 4886 | } |
| 4887 | |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4888 | public void setRotation(int rotation, |
Dianne Hackborn | 1e880db | 2009-03-27 16:04:08 -0700 | [diff] [blame] | 4889 | boolean alwaysSendConfiguration, int animFlags) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4890 | if (!checkCallingPermission(android.Manifest.permission.SET_ORIENTATION, |
Dianne Hackborn | 1e880db | 2009-03-27 16:04:08 -0700 | [diff] [blame] | 4891 | "setRotation()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4892 | throw new SecurityException("Requires SET_ORIENTATION permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4893 | } |
| 4894 | |
Dianne Hackborn | 1e880db | 2009-03-27 16:04:08 -0700 | [diff] [blame] | 4895 | setRotationUnchecked(rotation, alwaysSendConfiguration, animFlags); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4896 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4897 | |
Dianne Hackborn | 1e880db | 2009-03-27 16:04:08 -0700 | [diff] [blame] | 4898 | public void setRotationUnchecked(int rotation, |
| 4899 | boolean alwaysSendConfiguration, int animFlags) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4900 | if(DEBUG_ORIENTATION) Slog.v(TAG, |
David 'Digit' Turner | 910a068 | 2011-02-05 00:34:46 +0100 | [diff] [blame] | 4901 | "setRotationUnchecked(rotation=" + rotation + |
| 4902 | " alwaysSendConfiguration=" + alwaysSendConfiguration + |
| 4903 | " animFlags=" + animFlags); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4904 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4905 | long origId = Binder.clearCallingIdentity(); |
| 4906 | boolean changed; |
| 4907 | synchronized(mWindowMap) { |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 4908 | changed = setRotationUncheckedLocked(rotation, animFlags, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4909 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4910 | |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 4911 | if (changed || alwaysSendConfiguration) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4912 | sendNewConfiguration(); |
| 4913 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4914 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4915 | Binder.restoreCallingIdentity(origId); |
| 4916 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4917 | |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 4918 | /** |
| 4919 | * Apply a new rotation to the screen, respecting the requests of |
| 4920 | * applications. Use WindowManagerPolicy.USE_LAST_ROTATION to simply |
| 4921 | * re-evaluate the desired rotation. |
| 4922 | * |
| 4923 | * Returns null if the rotation has been changed. In this case YOU |
| 4924 | * MUST CALL setNewConfiguration() TO UNFREEZE THE SCREEN. |
| 4925 | */ |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 4926 | public boolean setRotationUncheckedLocked(int rotation, int animFlags, boolean inTransaction) { |
Dianne Hackborn | 89ba675 | 2011-01-23 16:51:16 -0800 | [diff] [blame] | 4927 | if (mDragState != null || mScreenRotationAnimation != null) { |
Christopher Tate | ccd24de | 2011-01-12 15:02:55 -0800 | [diff] [blame] | 4928 | // Potential rotation during a drag. Don't do the rotation now, but make |
| 4929 | // a note to perform the rotation later. |
Dianne Hackborn | 89ba675 | 2011-01-23 16:51:16 -0800 | [diff] [blame] | 4930 | if (DEBUG_ORIENTATION) Slog.v(TAG, "Deferring rotation."); |
| 4931 | if (rotation != WindowManagerPolicy.USE_LAST_ROTATION) { |
| 4932 | mDeferredRotation = rotation; |
| 4933 | mDeferredRotationAnimFlags = animFlags; |
| 4934 | } |
Christopher Tate | ccd24de | 2011-01-12 15:02:55 -0800 | [diff] [blame] | 4935 | return false; |
| 4936 | } |
| 4937 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4938 | boolean changed; |
| 4939 | if (rotation == WindowManagerPolicy.USE_LAST_ROTATION) { |
Dianne Hackborn | 89ba675 | 2011-01-23 16:51:16 -0800 | [diff] [blame] | 4940 | if (mDeferredRotation != WindowManagerPolicy.USE_LAST_ROTATION) { |
| 4941 | rotation = mDeferredRotation; |
| 4942 | mRequestedRotation = rotation; |
| 4943 | mLastRotationFlags = mDeferredRotationAnimFlags; |
| 4944 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4945 | rotation = mRequestedRotation; |
| 4946 | } else { |
| 4947 | mRequestedRotation = rotation; |
Dianne Hackborn | 321ae68 | 2009-03-27 16:16:03 -0700 | [diff] [blame] | 4948 | mLastRotationFlags = animFlags; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4949 | } |
Dianne Hackborn | 89ba675 | 2011-01-23 16:51:16 -0800 | [diff] [blame] | 4950 | mDeferredRotation = WindowManagerPolicy.USE_LAST_ROTATION; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4951 | 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] | 4952 | rotation = mPolicy.rotationForOrientationLw(mForcedAppOrientation, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4953 | mRotation, mDisplayEnabled); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4954 | 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] | 4955 | changed = mDisplayEnabled && mRotation != rotation; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4956 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4957 | if (changed) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4958 | if (DEBUG_ORIENTATION) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4959 | "Rotation changed to " + rotation |
| 4960 | + " from " + mRotation |
| 4961 | + " (forceApp=" + mForcedAppOrientation |
| 4962 | + ", req=" + mRequestedRotation + ")"); |
| 4963 | mRotation = rotation; |
| 4964 | mWindowsFreezingScreen = true; |
| 4965 | mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT); |
| 4966 | mH.sendMessageDelayed(mH.obtainMessage(H.WINDOW_FREEZE_TIMEOUT), |
| 4967 | 2000); |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 4968 | mWaitingForConfig = true; |
| 4969 | mLayoutNeeded = true; |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 4970 | startFreezingDisplayLocked(inTransaction); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4971 | Slog.i(TAG, "Setting rotation to " + rotation + ", animFlags=" + animFlags); |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 4972 | mInputManager.setDisplayOrientation(0, rotation); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4973 | if (mDisplayEnabled) { |
David 'Digit' Turner | 910a068 | 2011-02-05 00:34:46 +0100 | [diff] [blame] | 4974 | // NOTE: We disable the rotation in the emulator because |
| 4975 | // it doesn't support hardware OpenGL emulation yet. |
Dianne Hackborn | de75cb4 | 2011-03-02 17:11:21 -0800 | [diff] [blame] | 4976 | if (CUSTOM_SCREEN_ROTATION && mScreenRotationAnimation != null |
| 4977 | && mScreenRotationAnimation.hasScreenshot()) { |
Dianne Hackborn | a111187 | 2010-11-23 20:55:11 -0800 | [diff] [blame] | 4978 | Surface.freezeDisplay(0); |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 4979 | if (!inTransaction) { |
| 4980 | if (SHOW_TRANSACTIONS) Slog.i(TAG, |
| 4981 | ">>> OPEN TRANSACTION setRotationUnchecked"); |
| 4982 | Surface.openTransaction(); |
Dianne Hackborn | a111187 | 2010-11-23 20:55:11 -0800 | [diff] [blame] | 4983 | } |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 4984 | try { |
| 4985 | if (mScreenRotationAnimation != null) { |
| 4986 | mScreenRotationAnimation.setRotation(rotation); |
| 4987 | } |
| 4988 | } finally { |
| 4989 | if (!inTransaction) { |
| 4990 | Surface.closeTransaction(); |
| 4991 | if (SHOW_TRANSACTIONS) Slog.i(TAG, |
| 4992 | "<<< CLOSE TRANSACTION setRotationUnchecked"); |
| 4993 | } |
| 4994 | } |
Dianne Hackborn | a111187 | 2010-11-23 20:55:11 -0800 | [diff] [blame] | 4995 | Surface.setOrientation(0, rotation, animFlags); |
| 4996 | Surface.unfreezeDisplay(0); |
| 4997 | } else { |
| 4998 | Surface.setOrientation(0, rotation, animFlags); |
| 4999 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5000 | } |
| 5001 | for (int i=mWindows.size()-1; i>=0; i--) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 5002 | WindowState w = mWindows.get(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5003 | if (w.mSurface != null) { |
| 5004 | w.mOrientationChanging = true; |
| 5005 | } |
| 5006 | } |
| 5007 | for (int i=mRotationWatchers.size()-1; i>=0; i--) { |
| 5008 | try { |
| 5009 | mRotationWatchers.get(i).onRotationChanged(rotation); |
| 5010 | } catch (RemoteException e) { |
| 5011 | } |
| 5012 | } |
| 5013 | } //end if changed |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5014 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5015 | return changed; |
| 5016 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5017 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5018 | public int getRotation() { |
| 5019 | return mRotation; |
| 5020 | } |
| 5021 | |
| 5022 | public int watchRotation(IRotationWatcher watcher) { |
| 5023 | final IBinder watcherBinder = watcher.asBinder(); |
| 5024 | IBinder.DeathRecipient dr = new IBinder.DeathRecipient() { |
| 5025 | public void binderDied() { |
| 5026 | synchronized (mWindowMap) { |
| 5027 | for (int i=0; i<mRotationWatchers.size(); i++) { |
| 5028 | if (watcherBinder == mRotationWatchers.get(i).asBinder()) { |
Suchi Amalapurapu | fff2fda | 2009-06-30 21:36:16 -0700 | [diff] [blame] | 5029 | IRotationWatcher removed = mRotationWatchers.remove(i); |
| 5030 | if (removed != null) { |
| 5031 | removed.asBinder().unlinkToDeath(this, 0); |
| 5032 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5033 | i--; |
| 5034 | } |
| 5035 | } |
| 5036 | } |
| 5037 | } |
| 5038 | }; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5039 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5040 | synchronized (mWindowMap) { |
| 5041 | try { |
| 5042 | watcher.asBinder().linkToDeath(dr, 0); |
| 5043 | mRotationWatchers.add(watcher); |
| 5044 | } catch (RemoteException e) { |
| 5045 | // Client died, no cleanup needed. |
| 5046 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5047 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5048 | return mRotation; |
| 5049 | } |
| 5050 | } |
| 5051 | |
| 5052 | /** |
| 5053 | * Starts the view server on the specified port. |
| 5054 | * |
| 5055 | * @param port The port to listener to. |
| 5056 | * |
| 5057 | * @return True if the server was successfully started, false otherwise. |
| 5058 | * |
Dianne Hackborn | a924dc0d | 2011-02-17 14:22:17 -0800 | [diff] [blame] | 5059 | * @see com.android.server.wm.ViewServer |
| 5060 | * @see com.android.server.wm.ViewServer#VIEW_SERVER_DEFAULT_PORT |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5061 | */ |
| 5062 | public boolean startViewServer(int port) { |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5063 | if (isSystemSecure()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5064 | return false; |
| 5065 | } |
| 5066 | |
| 5067 | if (!checkCallingPermission(Manifest.permission.DUMP, "startViewServer")) { |
| 5068 | return false; |
| 5069 | } |
| 5070 | |
| 5071 | if (port < 1024) { |
| 5072 | return false; |
| 5073 | } |
| 5074 | |
| 5075 | if (mViewServer != null) { |
| 5076 | if (!mViewServer.isRunning()) { |
| 5077 | try { |
| 5078 | return mViewServer.start(); |
| 5079 | } catch (IOException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5080 | Slog.w(TAG, "View server did not start"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5081 | } |
| 5082 | } |
| 5083 | return false; |
| 5084 | } |
| 5085 | |
| 5086 | try { |
| 5087 | mViewServer = new ViewServer(this, port); |
| 5088 | return mViewServer.start(); |
| 5089 | } catch (IOException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5090 | Slog.w(TAG, "View server did not start"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5091 | } |
| 5092 | return false; |
| 5093 | } |
| 5094 | |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5095 | private boolean isSystemSecure() { |
| 5096 | return "1".equals(SystemProperties.get(SYSTEM_SECURE, "1")) && |
| 5097 | "0".equals(SystemProperties.get(SYSTEM_DEBUGGABLE, "0")); |
| 5098 | } |
| 5099 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5100 | /** |
| 5101 | * Stops the view server if it exists. |
| 5102 | * |
| 5103 | * @return True if the server stopped, false if it wasn't started or |
| 5104 | * couldn't be stopped. |
| 5105 | * |
Dianne Hackborn | a924dc0d | 2011-02-17 14:22:17 -0800 | [diff] [blame] | 5106 | * @see com.android.server.wm.ViewServer |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5107 | */ |
| 5108 | public boolean stopViewServer() { |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5109 | if (isSystemSecure()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5110 | return false; |
| 5111 | } |
| 5112 | |
| 5113 | if (!checkCallingPermission(Manifest.permission.DUMP, "stopViewServer")) { |
| 5114 | return false; |
| 5115 | } |
| 5116 | |
| 5117 | if (mViewServer != null) { |
| 5118 | return mViewServer.stop(); |
| 5119 | } |
| 5120 | return false; |
| 5121 | } |
| 5122 | |
| 5123 | /** |
| 5124 | * Indicates whether the view server is running. |
| 5125 | * |
| 5126 | * @return True if the server is running, false otherwise. |
| 5127 | * |
Dianne Hackborn | a924dc0d | 2011-02-17 14:22:17 -0800 | [diff] [blame] | 5128 | * @see com.android.server.wm.ViewServer |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5129 | */ |
| 5130 | public boolean isViewServerRunning() { |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5131 | if (isSystemSecure()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5132 | return false; |
| 5133 | } |
| 5134 | |
| 5135 | if (!checkCallingPermission(Manifest.permission.DUMP, "isViewServerRunning")) { |
| 5136 | return false; |
| 5137 | } |
| 5138 | |
| 5139 | return mViewServer != null && mViewServer.isRunning(); |
| 5140 | } |
| 5141 | |
| 5142 | /** |
| 5143 | * Lists all availble windows in the system. The listing is written in the |
| 5144 | * specified Socket's output stream with the following syntax: |
| 5145 | * windowHashCodeInHexadecimal windowName |
| 5146 | * Each line of the ouput represents a different window. |
| 5147 | * |
| 5148 | * @param client The remote client to send the listing to. |
| 5149 | * @return False if an error occured, true otherwise. |
| 5150 | */ |
| 5151 | boolean viewServerListWindows(Socket client) { |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5152 | if (isSystemSecure()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5153 | return false; |
| 5154 | } |
| 5155 | |
| 5156 | boolean result = true; |
| 5157 | |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 5158 | WindowState[] windows; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5159 | synchronized (mWindowMap) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5160 | //noinspection unchecked |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 5161 | windows = mWindows.toArray(new WindowState[mWindows.size()]); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5162 | } |
| 5163 | |
| 5164 | BufferedWriter out = null; |
| 5165 | |
| 5166 | // Any uncaught exception will crash the system process |
| 5167 | try { |
| 5168 | OutputStream clientStream = client.getOutputStream(); |
| 5169 | out = new BufferedWriter(new OutputStreamWriter(clientStream), 8 * 1024); |
| 5170 | |
| 5171 | final int count = windows.length; |
| 5172 | for (int i = 0; i < count; i++) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 5173 | final WindowState w = windows[i]; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5174 | out.write(Integer.toHexString(System.identityHashCode(w))); |
| 5175 | out.write(' '); |
| 5176 | out.append(w.mAttrs.getTitle()); |
| 5177 | out.write('\n'); |
| 5178 | } |
| 5179 | |
| 5180 | out.write("DONE.\n"); |
| 5181 | out.flush(); |
| 5182 | } catch (Exception e) { |
| 5183 | result = false; |
| 5184 | } finally { |
| 5185 | if (out != null) { |
| 5186 | try { |
| 5187 | out.close(); |
| 5188 | } catch (IOException e) { |
| 5189 | result = false; |
| 5190 | } |
| 5191 | } |
| 5192 | } |
| 5193 | |
| 5194 | return result; |
| 5195 | } |
| 5196 | |
| 5197 | /** |
Konstantin Lopyrev | f962476 | 2010-07-14 17:02:37 -0700 | [diff] [blame] | 5198 | * Returns the focused window in the following format: |
| 5199 | * windowHashCodeInHexadecimal windowName |
| 5200 | * |
| 5201 | * @param client The remote client to send the listing to. |
| 5202 | * @return False if an error occurred, true otherwise. |
| 5203 | */ |
| 5204 | boolean viewServerGetFocusedWindow(Socket client) { |
| 5205 | if (isSystemSecure()) { |
| 5206 | return false; |
| 5207 | } |
| 5208 | |
| 5209 | boolean result = true; |
| 5210 | |
| 5211 | WindowState focusedWindow = getFocusedWindow(); |
| 5212 | |
| 5213 | BufferedWriter out = null; |
| 5214 | |
| 5215 | // Any uncaught exception will crash the system process |
| 5216 | try { |
| 5217 | OutputStream clientStream = client.getOutputStream(); |
| 5218 | out = new BufferedWriter(new OutputStreamWriter(clientStream), 8 * 1024); |
| 5219 | |
| 5220 | if(focusedWindow != null) { |
| 5221 | out.write(Integer.toHexString(System.identityHashCode(focusedWindow))); |
| 5222 | out.write(' '); |
| 5223 | out.append(focusedWindow.mAttrs.getTitle()); |
| 5224 | } |
| 5225 | out.write('\n'); |
| 5226 | out.flush(); |
| 5227 | } catch (Exception e) { |
| 5228 | result = false; |
| 5229 | } finally { |
| 5230 | if (out != null) { |
| 5231 | try { |
| 5232 | out.close(); |
| 5233 | } catch (IOException e) { |
| 5234 | result = false; |
| 5235 | } |
| 5236 | } |
| 5237 | } |
| 5238 | |
| 5239 | return result; |
| 5240 | } |
| 5241 | |
| 5242 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5243 | * Sends a command to a target window. The result of the command, if any, will be |
| 5244 | * written in the output stream of the specified socket. |
| 5245 | * |
| 5246 | * The parameters must follow this syntax: |
| 5247 | * windowHashcode extra |
| 5248 | * |
| 5249 | * Where XX is the length in characeters of the windowTitle. |
| 5250 | * |
| 5251 | * The first parameter is the target window. The window with the specified hashcode |
| 5252 | * will be the target. If no target can be found, nothing happens. The extra parameters |
| 5253 | * will be delivered to the target window and as parameters to the command itself. |
| 5254 | * |
| 5255 | * @param client The remote client to sent the result, if any, to. |
| 5256 | * @param command The command to execute. |
| 5257 | * @param parameters The command parameters. |
| 5258 | * |
| 5259 | * @return True if the command was successfully delivered, false otherwise. This does |
| 5260 | * not indicate whether the command itself was successful. |
| 5261 | */ |
| 5262 | boolean viewServerWindowCommand(Socket client, String command, String parameters) { |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5263 | if (isSystemSecure()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5264 | return false; |
| 5265 | } |
| 5266 | |
| 5267 | boolean success = true; |
| 5268 | Parcel data = null; |
| 5269 | Parcel reply = null; |
| 5270 | |
Konstantin Lopyrev | 43b9b48 | 2010-08-24 22:00:12 -0700 | [diff] [blame] | 5271 | BufferedWriter out = null; |
| 5272 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5273 | // Any uncaught exception will crash the system process |
| 5274 | try { |
| 5275 | // Find the hashcode of the window |
| 5276 | int index = parameters.indexOf(' '); |
| 5277 | if (index == -1) { |
| 5278 | index = parameters.length(); |
| 5279 | } |
| 5280 | final String code = parameters.substring(0, index); |
Romain Guy | 236092a | 2009-12-14 15:31:48 -0800 | [diff] [blame] | 5281 | int hashCode = (int) Long.parseLong(code, 16); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5282 | |
| 5283 | // Extract the command's parameter after the window description |
| 5284 | if (index < parameters.length()) { |
| 5285 | parameters = parameters.substring(index + 1); |
| 5286 | } else { |
| 5287 | parameters = ""; |
| 5288 | } |
| 5289 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 5290 | final WindowState window = findWindow(hashCode); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5291 | if (window == null) { |
| 5292 | return false; |
| 5293 | } |
| 5294 | |
| 5295 | data = Parcel.obtain(); |
| 5296 | data.writeInterfaceToken("android.view.IWindow"); |
| 5297 | data.writeString(command); |
| 5298 | data.writeString(parameters); |
| 5299 | data.writeInt(1); |
| 5300 | ParcelFileDescriptor.fromSocket(client).writeToParcel(data, 0); |
| 5301 | |
| 5302 | reply = Parcel.obtain(); |
| 5303 | |
| 5304 | final IBinder binder = window.mClient.asBinder(); |
| 5305 | // TODO: GET THE TRANSACTION CODE IN A SAFER MANNER |
| 5306 | binder.transact(IBinder.FIRST_CALL_TRANSACTION, data, reply, 0); |
| 5307 | |
| 5308 | reply.readException(); |
| 5309 | |
Konstantin Lopyrev | 43b9b48 | 2010-08-24 22:00:12 -0700 | [diff] [blame] | 5310 | if (!client.isOutputShutdown()) { |
| 5311 | out = new BufferedWriter(new OutputStreamWriter(client.getOutputStream())); |
| 5312 | out.write("DONE\n"); |
| 5313 | out.flush(); |
| 5314 | } |
| 5315 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5316 | } catch (Exception e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5317 | 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] | 5318 | success = false; |
| 5319 | } finally { |
| 5320 | if (data != null) { |
| 5321 | data.recycle(); |
| 5322 | } |
| 5323 | if (reply != null) { |
| 5324 | reply.recycle(); |
| 5325 | } |
Konstantin Lopyrev | 43b9b48 | 2010-08-24 22:00:12 -0700 | [diff] [blame] | 5326 | if (out != null) { |
| 5327 | try { |
| 5328 | out.close(); |
| 5329 | } catch (IOException e) { |
| 5330 | |
| 5331 | } |
| 5332 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5333 | } |
| 5334 | |
| 5335 | return success; |
| 5336 | } |
| 5337 | |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 5338 | public void addWindowChangeListener(WindowChangeListener listener) { |
| 5339 | synchronized(mWindowMap) { |
| 5340 | mWindowChangeListeners.add(listener); |
| 5341 | } |
| 5342 | } |
| 5343 | |
| 5344 | public void removeWindowChangeListener(WindowChangeListener listener) { |
| 5345 | synchronized(mWindowMap) { |
| 5346 | mWindowChangeListeners.remove(listener); |
| 5347 | } |
| 5348 | } |
| 5349 | |
| 5350 | private void notifyWindowsChanged() { |
| 5351 | WindowChangeListener[] windowChangeListeners; |
| 5352 | synchronized(mWindowMap) { |
| 5353 | if(mWindowChangeListeners.isEmpty()) { |
| 5354 | return; |
| 5355 | } |
| 5356 | windowChangeListeners = new WindowChangeListener[mWindowChangeListeners.size()]; |
| 5357 | windowChangeListeners = mWindowChangeListeners.toArray(windowChangeListeners); |
| 5358 | } |
| 5359 | int N = windowChangeListeners.length; |
| 5360 | for(int i = 0; i < N; i++) { |
| 5361 | windowChangeListeners[i].windowsChanged(); |
| 5362 | } |
| 5363 | } |
| 5364 | |
Konstantin Lopyrev | 6e0f65f | 2010-07-14 14:55:33 -0700 | [diff] [blame] | 5365 | private void notifyFocusChanged() { |
| 5366 | WindowChangeListener[] windowChangeListeners; |
| 5367 | synchronized(mWindowMap) { |
| 5368 | if(mWindowChangeListeners.isEmpty()) { |
| 5369 | return; |
| 5370 | } |
| 5371 | windowChangeListeners = new WindowChangeListener[mWindowChangeListeners.size()]; |
| 5372 | windowChangeListeners = mWindowChangeListeners.toArray(windowChangeListeners); |
| 5373 | } |
| 5374 | int N = windowChangeListeners.length; |
| 5375 | for(int i = 0; i < N; i++) { |
| 5376 | windowChangeListeners[i].focusChanged(); |
| 5377 | } |
| 5378 | } |
| 5379 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5380 | private WindowState findWindow(int hashCode) { |
| 5381 | if (hashCode == -1) { |
| 5382 | return getFocusedWindow(); |
| 5383 | } |
| 5384 | |
| 5385 | synchronized (mWindowMap) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 5386 | final ArrayList<WindowState> windows = mWindows; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5387 | final int count = windows.size(); |
| 5388 | |
| 5389 | for (int i = 0; i < count; i++) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 5390 | WindowState w = windows.get(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5391 | if (System.identityHashCode(w) == hashCode) { |
| 5392 | return w; |
| 5393 | } |
| 5394 | } |
| 5395 | } |
| 5396 | |
| 5397 | return null; |
| 5398 | } |
| 5399 | |
| 5400 | /* |
| 5401 | * Instruct the Activity Manager to fetch the current configuration and broadcast |
| 5402 | * that to config-changed listeners if appropriate. |
| 5403 | */ |
| 5404 | void sendNewConfiguration() { |
| 5405 | try { |
| 5406 | mActivityManager.updateConfiguration(null); |
| 5407 | } catch (RemoteException e) { |
| 5408 | } |
| 5409 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5410 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5411 | public Configuration computeNewConfiguration() { |
| 5412 | synchronized (mWindowMap) { |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 5413 | Configuration config = computeNewConfigurationLocked(); |
| 5414 | if (config == null && mWaitingForConfig) { |
| 5415 | // Nothing changed but we are waiting for something... stop that! |
| 5416 | mWaitingForConfig = false; |
| 5417 | performLayoutAndPlaceSurfacesLocked(); |
| 5418 | } |
| 5419 | return config; |
Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 5420 | } |
| 5421 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5422 | |
Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 5423 | Configuration computeNewConfigurationLocked() { |
| 5424 | Configuration config = new Configuration(); |
| 5425 | if (!computeNewConfigurationLocked(config)) { |
| 5426 | return null; |
| 5427 | } |
Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 5428 | return config; |
| 5429 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5430 | |
Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 5431 | boolean computeNewConfigurationLocked(Configuration config) { |
| 5432 | if (mDisplay == null) { |
| 5433 | return false; |
| 5434 | } |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 5435 | |
| 5436 | mInputManager.getInputConfiguration(config); |
Christopher Tate | b696aee | 2010-04-02 19:08:30 -0700 | [diff] [blame] | 5437 | |
| 5438 | // Use the effective "visual" dimensions based on current rotation |
| 5439 | final boolean rotated = (mRotation == Surface.ROTATION_90 |
| 5440 | || mRotation == Surface.ROTATION_270); |
| 5441 | final int dw = rotated ? mInitialDisplayHeight : mInitialDisplayWidth; |
| 5442 | final int dh = rotated ? mInitialDisplayWidth : mInitialDisplayHeight; |
| 5443 | |
Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 5444 | int orientation = Configuration.ORIENTATION_SQUARE; |
| 5445 | if (dw < dh) { |
| 5446 | orientation = Configuration.ORIENTATION_PORTRAIT; |
| 5447 | } else if (dw > dh) { |
| 5448 | orientation = Configuration.ORIENTATION_LANDSCAPE; |
| 5449 | } |
| 5450 | config.orientation = orientation; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 5451 | |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 5452 | DisplayMetrics dm = new DisplayMetrics(); |
| 5453 | mDisplay.getMetrics(dm); |
| 5454 | CompatibilityInfo.updateCompatibleScreenFrame(dm, orientation, mCompatibleScreenFrame); |
| 5455 | |
Dianne Hackborn | 3fc982f | 2011-03-30 16:20:26 -0700 | [diff] [blame^] | 5456 | config.screenWidthDp = (int)(dm.widthPixels / dm.density); |
| 5457 | config.screenHeightDp = (int)(dm.heightPixels / dm.density); |
| 5458 | |
Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 5459 | if (mScreenLayout == Configuration.SCREENLAYOUT_SIZE_UNDEFINED) { |
Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 5460 | // Note we only do this once because at this point we don't |
| 5461 | // expect the screen to change in this way at runtime, and want |
| 5462 | // to avoid all of this computation for every config change. |
Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 5463 | int longSize = dw; |
| 5464 | int shortSize = dh; |
| 5465 | if (longSize < shortSize) { |
| 5466 | int tmp = longSize; |
| 5467 | longSize = shortSize; |
| 5468 | shortSize = tmp; |
| 5469 | } |
| 5470 | longSize = (int)(longSize/dm.density); |
| 5471 | shortSize = (int)(shortSize/dm.density); |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 5472 | |
Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 5473 | // These semi-magic numbers define our compatibility modes for |
Dianne Hackborn | cc1d9f7 | 2011-03-08 10:33:55 -0800 | [diff] [blame] | 5474 | // applications with different screens. These are guarantees to |
| 5475 | // app developers about the space they can expect for a particular |
| 5476 | // configuration. DO NOT CHANGE! |
Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 5477 | if (longSize < 470) { |
| 5478 | // This is shorter than an HVGA normal density screen (which |
| 5479 | // is 480 pixels on its long side). |
Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 5480 | mScreenLayout = Configuration.SCREENLAYOUT_SIZE_SMALL |
| 5481 | | Configuration.SCREENLAYOUT_LONG_NO; |
Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 5482 | } else { |
Dianne Hackborn | 14cee9f | 2010-04-23 17:51:26 -0700 | [diff] [blame] | 5483 | // What size is this screen screen? |
Dianne Hackborn | cc1d9f7 | 2011-03-08 10:33:55 -0800 | [diff] [blame] | 5484 | if (longSize >= 960 && shortSize >= 720) { |
| 5485 | // 1.5xVGA or larger screens at medium density are the point |
Dianne Hackborn | 14cee9f | 2010-04-23 17:51:26 -0700 | [diff] [blame] | 5486 | // at which we consider it to be an extra large screen. |
| 5487 | mScreenLayout = Configuration.SCREENLAYOUT_SIZE_XLARGE; |
Dianne Hackborn | cc1d9f7 | 2011-03-08 10:33:55 -0800 | [diff] [blame] | 5488 | } else if (longSize >= 640 && shortSize >= 480) { |
| 5489 | // VGA or larger screens at medium density are the point |
Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 5490 | // at which we consider it to be a large screen. |
| 5491 | mScreenLayout = Configuration.SCREENLAYOUT_SIZE_LARGE; |
| 5492 | } else { |
| 5493 | mScreenLayout = Configuration.SCREENLAYOUT_SIZE_NORMAL; |
Dianne Hackborn | e97a12e | 2011-01-29 13:22:02 -0800 | [diff] [blame] | 5494 | } |
| 5495 | |
| 5496 | // If this screen is wider than normal HVGA, or taller |
| 5497 | // than FWVGA, then for old apps we want to run in size |
| 5498 | // compatibility mode. |
| 5499 | if (shortSize > 321 || longSize > 570) { |
| 5500 | mScreenLayout |= Configuration.SCREENLAYOUT_COMPAT_NEEDED; |
Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 5501 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 5502 | |
Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 5503 | // Is this a long screen? |
| 5504 | if (((longSize*3)/5) >= (shortSize-1)) { |
| 5505 | // Anything wider than WVGA (5:3) is considering to be long. |
| 5506 | mScreenLayout |= Configuration.SCREENLAYOUT_LONG_YES; |
| 5507 | } else { |
| 5508 | mScreenLayout |= Configuration.SCREENLAYOUT_LONG_NO; |
| 5509 | } |
Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 5510 | } |
| 5511 | } |
Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 5512 | config.screenLayout = mScreenLayout; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 5513 | |
Jeff Brown | 597eec8 | 2011-01-31 17:12:25 -0800 | [diff] [blame] | 5514 | // Determine whether a hard keyboard is available and enabled. |
Jeff Brown | 2992ea7 | 2011-01-28 22:04:14 -0800 | [diff] [blame] | 5515 | boolean hardKeyboardAvailable = config.keyboard != Configuration.KEYBOARD_NOKEYS; |
| 5516 | if (hardKeyboardAvailable != mHardKeyboardAvailable) { |
| 5517 | mHardKeyboardAvailable = hardKeyboardAvailable; |
| 5518 | mHardKeyboardEnabled = hardKeyboardAvailable; |
| 5519 | |
| 5520 | mH.removeMessages(H.REPORT_HARD_KEYBOARD_STATUS_CHANGE); |
| 5521 | mH.sendEmptyMessage(H.REPORT_HARD_KEYBOARD_STATUS_CHANGE); |
| 5522 | } |
| 5523 | if (!mHardKeyboardEnabled) { |
| 5524 | config.keyboard = Configuration.KEYBOARD_NOKEYS; |
Jeff Brown | 2992ea7 | 2011-01-28 22:04:14 -0800 | [diff] [blame] | 5525 | } |
Jeff Brown | 597eec8 | 2011-01-31 17:12:25 -0800 | [diff] [blame] | 5526 | |
| 5527 | // Update value of keyboardHidden, hardKeyboardHidden and navigationHidden |
| 5528 | // based on whether a hard or soft keyboard is present, whether navigation keys |
| 5529 | // are present and the lid switch state. |
| 5530 | config.keyboardHidden = Configuration.KEYBOARDHIDDEN_NO; |
| 5531 | config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_NO; |
| 5532 | config.navigationHidden = Configuration.NAVIGATIONHIDDEN_NO; |
| 5533 | mPolicy.adjustConfigurationLw(config); |
Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 5534 | return true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5535 | } |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5536 | |
Jeff Brown | 2992ea7 | 2011-01-28 22:04:14 -0800 | [diff] [blame] | 5537 | public boolean isHardKeyboardAvailable() { |
| 5538 | synchronized (mWindowMap) { |
| 5539 | return mHardKeyboardAvailable; |
| 5540 | } |
| 5541 | } |
| 5542 | |
| 5543 | public boolean isHardKeyboardEnabled() { |
| 5544 | synchronized (mWindowMap) { |
| 5545 | return mHardKeyboardEnabled; |
| 5546 | } |
| 5547 | } |
| 5548 | |
| 5549 | public void setHardKeyboardEnabled(boolean enabled) { |
| 5550 | synchronized (mWindowMap) { |
| 5551 | if (mHardKeyboardEnabled != enabled) { |
| 5552 | mHardKeyboardEnabled = enabled; |
| 5553 | mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION); |
| 5554 | } |
| 5555 | } |
| 5556 | } |
| 5557 | |
| 5558 | public void setOnHardKeyboardStatusChangeListener( |
| 5559 | OnHardKeyboardStatusChangeListener listener) { |
| 5560 | synchronized (mWindowMap) { |
| 5561 | mHardKeyboardStatusChangeListener = listener; |
| 5562 | } |
| 5563 | } |
| 5564 | |
| 5565 | void notifyHardKeyboardStatusChange() { |
| 5566 | final boolean available, enabled; |
| 5567 | final OnHardKeyboardStatusChangeListener listener; |
| 5568 | synchronized (mWindowMap) { |
| 5569 | listener = mHardKeyboardStatusChangeListener; |
| 5570 | available = mHardKeyboardAvailable; |
| 5571 | enabled = mHardKeyboardEnabled; |
| 5572 | } |
| 5573 | if (listener != null) { |
| 5574 | listener.onHardKeyboardStatusChange(available, enabled); |
| 5575 | } |
| 5576 | } |
| 5577 | |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5578 | // ------------------------------------------------------------- |
| 5579 | // Drag and drop |
| 5580 | // ------------------------------------------------------------- |
| 5581 | |
| 5582 | IBinder prepareDragSurface(IWindow window, SurfaceSession session, |
Christopher Tate | 02d2b3b | 2011-01-10 20:43:53 -0800 | [diff] [blame] | 5583 | int flags, int width, int height, Surface outSurface) { |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5584 | if (DEBUG_DRAG) { |
| 5585 | Slog.d(TAG, "prepare drag surface: w=" + width + " h=" + height |
Christopher Tate | 02d2b3b | 2011-01-10 20:43:53 -0800 | [diff] [blame] | 5586 | + " flags=" + Integer.toHexString(flags) + " win=" + window |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5587 | + " asbinder=" + window.asBinder()); |
| 5588 | } |
| 5589 | |
| 5590 | final int callerPid = Binder.getCallingPid(); |
| 5591 | final long origId = Binder.clearCallingIdentity(); |
| 5592 | IBinder token = null; |
| 5593 | |
| 5594 | try { |
| 5595 | synchronized (mWindowMap) { |
| 5596 | try { |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5597 | if (mDragState == null) { |
| 5598 | Surface surface = new Surface(session, callerPid, "drag surface", 0, |
| 5599 | width, height, PixelFormat.TRANSLUCENT, Surface.HIDDEN); |
Dianne Hackborn | ac1471a | 2011-02-03 13:46:06 -0800 | [diff] [blame] | 5600 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " DRAG " |
| 5601 | + surface + ": CREATE"); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5602 | outSurface.copyFrom(surface); |
Chris Tate | 7b362e4 | 2010-11-04 16:02:52 -0700 | [diff] [blame] | 5603 | final IBinder winBinder = window.asBinder(); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5604 | token = new Binder(); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 5605 | mDragState = new DragState(this, token, surface, /*flags*/ 0, winBinder); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5606 | mDragState.mSurface = surface; |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5607 | token = mDragState.mToken = new Binder(); |
| 5608 | |
| 5609 | // 5 second timeout for this window to actually begin the drag |
Chris Tate | 7b362e4 | 2010-11-04 16:02:52 -0700 | [diff] [blame] | 5610 | mH.removeMessages(H.DRAG_START_TIMEOUT, winBinder); |
| 5611 | Message msg = mH.obtainMessage(H.DRAG_START_TIMEOUT, winBinder); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5612 | mH.sendMessageDelayed(msg, 5000); |
| 5613 | } else { |
| 5614 | Slog.w(TAG, "Drag already in progress"); |
| 5615 | } |
| 5616 | } catch (Surface.OutOfResourcesException e) { |
| 5617 | Slog.e(TAG, "Can't allocate drag surface w=" + width + " h=" + height, e); |
| 5618 | if (mDragState != null) { |
| 5619 | mDragState.reset(); |
| 5620 | mDragState = null; |
| 5621 | } |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5622 | } |
| 5623 | } |
| 5624 | } finally { |
| 5625 | Binder.restoreCallingIdentity(origId); |
| 5626 | } |
| 5627 | |
| 5628 | return token; |
| 5629 | } |
| 5630 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5631 | // ------------------------------------------------------------- |
| 5632 | // Input Events and Focus Management |
| 5633 | // ------------------------------------------------------------- |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5634 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 5635 | final InputMonitor mInputMonitor = new InputMonitor(this); |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5636 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5637 | public void pauseKeyDispatching(IBinder _token) { |
| 5638 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 5639 | "pauseKeyDispatching()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5640 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5641 | } |
| 5642 | |
| 5643 | synchronized (mWindowMap) { |
| 5644 | WindowToken token = mTokenMap.get(_token); |
| 5645 | if (token != null) { |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 5646 | mInputMonitor.pauseDispatchingLw(token); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5647 | } |
| 5648 | } |
| 5649 | } |
| 5650 | |
| 5651 | public void resumeKeyDispatching(IBinder _token) { |
| 5652 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 5653 | "resumeKeyDispatching()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5654 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5655 | } |
| 5656 | |
| 5657 | synchronized (mWindowMap) { |
| 5658 | WindowToken token = mTokenMap.get(_token); |
| 5659 | if (token != null) { |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 5660 | mInputMonitor.resumeDispatchingLw(token); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5661 | } |
| 5662 | } |
| 5663 | } |
| 5664 | |
| 5665 | public void setEventDispatching(boolean enabled) { |
| 5666 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 5667 | "resumeKeyDispatching()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5668 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5669 | } |
| 5670 | |
| 5671 | synchronized (mWindowMap) { |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 5672 | mInputMonitor.setEventDispatchingLw(enabled); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5673 | } |
| 5674 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5675 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5676 | /** |
| 5677 | * Injects a keystroke event into the UI. |
Jeff Brown | bbda99d | 2010-07-28 15:48:59 -0700 | [diff] [blame] | 5678 | * Even when sync is false, this method may block while waiting for current |
| 5679 | * input events to be dispatched. |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5680 | * |
| 5681 | * @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] | 5682 | * {@link SystemClock#uptimeMillis()} as the timebase.) |
| 5683 | * @param sync If true, wait for the event to be completed before returning to the caller. |
| 5684 | * @return Returns true if event was dispatched, false if it was dropped for any reason |
| 5685 | */ |
| 5686 | public boolean injectKeyEvent(KeyEvent ev, boolean sync) { |
| 5687 | long downTime = ev.getDownTime(); |
| 5688 | long eventTime = ev.getEventTime(); |
| 5689 | |
| 5690 | int action = ev.getAction(); |
| 5691 | int code = ev.getKeyCode(); |
| 5692 | int repeatCount = ev.getRepeatCount(); |
| 5693 | int metaState = ev.getMetaState(); |
| 5694 | int deviceId = ev.getDeviceId(); |
| 5695 | int scancode = ev.getScanCode(); |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 5696 | int source = ev.getSource(); |
Mike Playle | c6ded10 | 2010-11-29 16:01:03 +0000 | [diff] [blame] | 5697 | int flags = ev.getFlags(); |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 5698 | |
| 5699 | if (source == InputDevice.SOURCE_UNKNOWN) { |
| 5700 | source = InputDevice.SOURCE_KEYBOARD; |
| 5701 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5702 | |
| 5703 | if (eventTime == 0) eventTime = SystemClock.uptimeMillis(); |
| 5704 | if (downTime == 0) downTime = eventTime; |
| 5705 | |
| 5706 | KeyEvent newEvent = new KeyEvent(downTime, eventTime, action, code, repeatCount, metaState, |
Jean-Baptiste Queru | 4a88013 | 2010-12-02 15:16:53 -0800 | [diff] [blame] | 5707 | deviceId, scancode, flags | KeyEvent.FLAG_FROM_SYSTEM, source); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5708 | |
Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5709 | final int pid = Binder.getCallingPid(); |
| 5710 | final int uid = Binder.getCallingUid(); |
| 5711 | final long ident = Binder.clearCallingIdentity(); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5712 | |
Jeff Brown | bbda99d | 2010-07-28 15:48:59 -0700 | [diff] [blame] | 5713 | final int result = mInputManager.injectInputEvent(newEvent, pid, uid, |
| 5714 | sync ? InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH |
| 5715 | : InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT, |
| 5716 | INJECTION_TIMEOUT_MILLIS); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5717 | |
Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5718 | Binder.restoreCallingIdentity(ident); |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 5719 | return reportInjectionResult(result); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5720 | } |
| 5721 | |
| 5722 | /** |
| 5723 | * Inject a pointer (touch) event into the UI. |
Jeff Brown | bbda99d | 2010-07-28 15:48:59 -0700 | [diff] [blame] | 5724 | * Even when sync is false, this method may block while waiting for current |
| 5725 | * input events to be dispatched. |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5726 | * |
| 5727 | * @param ev A motion event describing the pointer (touch) action. (As noted in |
| 5728 | * {@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] | 5729 | * {@link SystemClock#uptimeMillis()} as the timebase.) |
| 5730 | * @param sync If true, wait for the event to be completed before returning to the caller. |
| 5731 | * @return Returns true if event was dispatched, false if it was dropped for any reason |
| 5732 | */ |
| 5733 | public boolean injectPointerEvent(MotionEvent ev, boolean sync) { |
Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5734 | final int pid = Binder.getCallingPid(); |
| 5735 | final int uid = Binder.getCallingUid(); |
| 5736 | final long ident = Binder.clearCallingIdentity(); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5737 | |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 5738 | MotionEvent newEvent = MotionEvent.obtain(ev); |
| 5739 | if ((newEvent.getSource() & InputDevice.SOURCE_CLASS_POINTER) == 0) { |
| 5740 | newEvent.setSource(InputDevice.SOURCE_TOUCHSCREEN); |
| 5741 | } |
| 5742 | |
Jeff Brown | bbda99d | 2010-07-28 15:48:59 -0700 | [diff] [blame] | 5743 | final int result = mInputManager.injectInputEvent(newEvent, pid, uid, |
| 5744 | sync ? InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH |
| 5745 | : InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT, |
| 5746 | INJECTION_TIMEOUT_MILLIS); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5747 | |
Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5748 | Binder.restoreCallingIdentity(ident); |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 5749 | return reportInjectionResult(result); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5750 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5751 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5752 | /** |
| 5753 | * Inject a trackball (navigation device) event into the UI. |
Jeff Brown | bbda99d | 2010-07-28 15:48:59 -0700 | [diff] [blame] | 5754 | * Even when sync is false, this method may block while waiting for current |
| 5755 | * input events to be dispatched. |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5756 | * |
| 5757 | * @param ev A motion event describing the trackball action. (As noted in |
| 5758 | * {@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] | 5759 | * {@link SystemClock#uptimeMillis()} as the timebase.) |
| 5760 | * @param sync If true, wait for the event to be completed before returning to the caller. |
| 5761 | * @return Returns true if event was dispatched, false if it was dropped for any reason |
| 5762 | */ |
| 5763 | public boolean injectTrackballEvent(MotionEvent ev, boolean sync) { |
Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5764 | final int pid = Binder.getCallingPid(); |
| 5765 | final int uid = Binder.getCallingUid(); |
| 5766 | final long ident = Binder.clearCallingIdentity(); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5767 | |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 5768 | MotionEvent newEvent = MotionEvent.obtain(ev); |
| 5769 | if ((newEvent.getSource() & InputDevice.SOURCE_CLASS_TRACKBALL) == 0) { |
| 5770 | newEvent.setSource(InputDevice.SOURCE_TRACKBALL); |
| 5771 | } |
| 5772 | |
Jeff Brown | bbda99d | 2010-07-28 15:48:59 -0700 | [diff] [blame] | 5773 | final int result = mInputManager.injectInputEvent(newEvent, pid, uid, |
| 5774 | sync ? InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH |
| 5775 | : InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT, |
| 5776 | INJECTION_TIMEOUT_MILLIS); |
| 5777 | |
| 5778 | Binder.restoreCallingIdentity(ident); |
| 5779 | return reportInjectionResult(result); |
| 5780 | } |
| 5781 | |
| 5782 | /** |
| 5783 | * Inject an input event into the UI without waiting for dispatch to commence. |
| 5784 | * This variant is useful for fire-and-forget input event injection. It does not |
| 5785 | * block any longer than it takes to enqueue the input event. |
| 5786 | * |
| 5787 | * @param ev An input event. (Be sure to set the input source correctly.) |
| 5788 | * @return Returns true if event was dispatched, false if it was dropped for any reason |
| 5789 | */ |
| 5790 | public boolean injectInputEventNoWait(InputEvent ev) { |
| 5791 | final int pid = Binder.getCallingPid(); |
| 5792 | final int uid = Binder.getCallingUid(); |
| 5793 | final long ident = Binder.clearCallingIdentity(); |
| 5794 | |
| 5795 | final int result = mInputManager.injectInputEvent(ev, pid, uid, |
| 5796 | InputManager.INPUT_EVENT_INJECTION_SYNC_NONE, |
| 5797 | INJECTION_TIMEOUT_MILLIS); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5798 | |
Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 5799 | Binder.restoreCallingIdentity(ident); |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 5800 | return reportInjectionResult(result); |
| 5801 | } |
| 5802 | |
| 5803 | private boolean reportInjectionResult(int result) { |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 5804 | switch (result) { |
| 5805 | case InputManager.INPUT_EVENT_INJECTION_PERMISSION_DENIED: |
| 5806 | Slog.w(TAG, "Input event injection permission denied."); |
| 5807 | throw new SecurityException( |
| 5808 | "Injecting to another application requires INJECT_EVENTS permission"); |
| 5809 | case InputManager.INPUT_EVENT_INJECTION_SUCCEEDED: |
Christopher Tate | 09e85dc | 2010-08-02 11:54:41 -0700 | [diff] [blame] | 5810 | //Slog.v(TAG, "Input event injection succeeded."); |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 5811 | return true; |
| 5812 | case InputManager.INPUT_EVENT_INJECTION_TIMED_OUT: |
| 5813 | Slog.w(TAG, "Input event injection timed out."); |
| 5814 | return false; |
| 5815 | case InputManager.INPUT_EVENT_INJECTION_FAILED: |
| 5816 | default: |
| 5817 | Slog.w(TAG, "Input event injection failed."); |
| 5818 | return false; |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5819 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5820 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5821 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5822 | private WindowState getFocusedWindow() { |
| 5823 | synchronized (mWindowMap) { |
| 5824 | return getFocusedWindowLocked(); |
| 5825 | } |
| 5826 | } |
| 5827 | |
| 5828 | private WindowState getFocusedWindowLocked() { |
| 5829 | return mCurrentFocus; |
| 5830 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5831 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5832 | public boolean detectSafeMode() { |
Jeff Brown | b09abc1 | 2011-01-13 21:08:27 -0800 | [diff] [blame] | 5833 | if (!mInputMonitor.waitForInputDevicesReady( |
| 5834 | INPUT_DEVICES_READY_FOR_SAFE_MODE_DETECTION_TIMEOUT_MILLIS)) { |
| 5835 | Slog.w(TAG, "Devices still not ready after waiting " |
| 5836 | + INPUT_DEVICES_READY_FOR_SAFE_MODE_DETECTION_TIMEOUT_MILLIS |
| 5837 | + " milliseconds before attempting to detect safe mode."); |
| 5838 | } |
| 5839 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5840 | mSafeMode = mPolicy.detectSafeMode(); |
| 5841 | return mSafeMode; |
| 5842 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5843 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5844 | public void systemReady() { |
Dianne Hackborn | 5132b37 | 2010-07-29 12:51:35 -0700 | [diff] [blame] | 5845 | synchronized(mWindowMap) { |
| 5846 | if (mDisplay != null) { |
| 5847 | throw new IllegalStateException("Display already initialized"); |
| 5848 | } |
| 5849 | WindowManager wm = (WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE); |
| 5850 | mDisplay = wm.getDefaultDisplay(); |
| 5851 | mInitialDisplayWidth = mDisplay.getWidth(); |
| 5852 | mInitialDisplayHeight = mDisplay.getHeight(); |
Dianne Hackborn | 99aac7b | 2011-02-25 17:33:02 -0800 | [diff] [blame] | 5853 | mInputManager.setDisplaySize(0, mDisplay.getRealWidth(), mDisplay.getRealHeight()); |
Dianne Hackborn | 5132b37 | 2010-07-29 12:51:35 -0700 | [diff] [blame] | 5854 | } |
| 5855 | |
| 5856 | try { |
| 5857 | mActivityManager.updateConfiguration(null); |
| 5858 | } catch (RemoteException e) { |
| 5859 | } |
Dianne Hackborn | 154db5f | 2010-07-29 19:15:19 -0700 | [diff] [blame] | 5860 | |
| 5861 | mPolicy.systemReady(); |
Dianne Hackborn | 5132b37 | 2010-07-29 12:51:35 -0700 | [diff] [blame] | 5862 | } |
| 5863 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5864 | // This is an animation that does nothing: it just immediately finishes |
| 5865 | // itself every time it is called. It is used as a stub animation in cases |
| 5866 | // where we want to synchronize multiple things that may be animating. |
| 5867 | static final class DummyAnimation extends Animation { |
| 5868 | public boolean getTransformation(long currentTime, Transformation outTransformation) { |
| 5869 | return false; |
| 5870 | } |
| 5871 | } |
| 5872 | static final Animation sDummyAnimation = new DummyAnimation(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5873 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5874 | // ------------------------------------------------------------- |
| 5875 | // Async Handler |
| 5876 | // ------------------------------------------------------------- |
| 5877 | |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 5878 | final class H extends Handler { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5879 | public static final int REPORT_FOCUS_CHANGE = 2; |
| 5880 | public static final int REPORT_LOSING_FOCUS = 3; |
| 5881 | public static final int ANIMATE = 4; |
| 5882 | public static final int ADD_STARTING = 5; |
| 5883 | public static final int REMOVE_STARTING = 6; |
| 5884 | public static final int FINISHED_STARTING = 7; |
| 5885 | public static final int REPORT_APPLICATION_TOKEN_WINDOWS = 8; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5886 | public static final int WINDOW_FREEZE_TIMEOUT = 11; |
| 5887 | public static final int HOLD_SCREEN_CHANGED = 12; |
| 5888 | public static final int APP_TRANSITION_TIMEOUT = 13; |
| 5889 | public static final int PERSIST_ANIMATION_SCALE = 14; |
| 5890 | public static final int FORCE_GC = 15; |
| 5891 | public static final int ENABLE_SCREEN = 16; |
| 5892 | public static final int APP_FREEZE_TIMEOUT = 17; |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 5893 | public static final int SEND_NEW_CONFIGURATION = 18; |
Konstantin Lopyrev | 6e0f65f | 2010-07-14 14:55:33 -0700 | [diff] [blame] | 5894 | public static final int REPORT_WINDOWS_CHANGE = 19; |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5895 | public static final int DRAG_START_TIMEOUT = 20; |
Chris Tate | d4533f1 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 5896 | public static final int DRAG_END_TIMEOUT = 21; |
Jeff Brown | 2992ea7 | 2011-01-28 22:04:14 -0800 | [diff] [blame] | 5897 | public static final int REPORT_HARD_KEYBOARD_STATUS_CHANGE = 22; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5898 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5899 | private Session mLastReportedHold; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5900 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5901 | public H() { |
| 5902 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5903 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5904 | @Override |
| 5905 | public void handleMessage(Message msg) { |
| 5906 | switch (msg.what) { |
| 5907 | case REPORT_FOCUS_CHANGE: { |
| 5908 | WindowState lastFocus; |
| 5909 | WindowState newFocus; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5910 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5911 | synchronized(mWindowMap) { |
| 5912 | lastFocus = mLastFocus; |
| 5913 | newFocus = mCurrentFocus; |
| 5914 | if (lastFocus == newFocus) { |
| 5915 | // Focus is not changing, so nothing to do. |
| 5916 | return; |
| 5917 | } |
| 5918 | mLastFocus = newFocus; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5919 | //Slog.i(TAG, "Focus moving from " + lastFocus |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5920 | // + " to " + newFocus); |
| 5921 | if (newFocus != null && lastFocus != null |
| 5922 | && !newFocus.isDisplayedLw()) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5923 | //Slog.i(TAG, "Delaying loss of focus..."); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5924 | mLosingFocus.add(lastFocus); |
| 5925 | lastFocus = null; |
| 5926 | } |
| 5927 | } |
| 5928 | |
| 5929 | if (lastFocus != newFocus) { |
| 5930 | //System.out.println("Changing focus from " + lastFocus |
| 5931 | // + " to " + newFocus); |
| 5932 | if (newFocus != null) { |
| 5933 | try { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5934 | //Slog.i(TAG, "Gaining focus: " + newFocus); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5935 | newFocus.mClient.windowFocusChanged(true, mInTouchMode); |
| 5936 | } catch (RemoteException e) { |
| 5937 | // Ignore if process has died. |
| 5938 | } |
Konstantin Lopyrev | 5e7833a | 2010-08-09 17:01:11 -0700 | [diff] [blame] | 5939 | notifyFocusChanged(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5940 | } |
| 5941 | |
| 5942 | if (lastFocus != null) { |
| 5943 | try { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5944 | //Slog.i(TAG, "Losing focus: " + lastFocus); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5945 | lastFocus.mClient.windowFocusChanged(false, mInTouchMode); |
| 5946 | } catch (RemoteException e) { |
| 5947 | // Ignore if process has died. |
| 5948 | } |
| 5949 | } |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 5950 | |
| 5951 | mPolicy.focusChanged(lastFocus, newFocus); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5952 | } |
| 5953 | } break; |
| 5954 | |
| 5955 | case REPORT_LOSING_FOCUS: { |
| 5956 | ArrayList<WindowState> losers; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5957 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5958 | synchronized(mWindowMap) { |
| 5959 | losers = mLosingFocus; |
| 5960 | mLosingFocus = new ArrayList<WindowState>(); |
| 5961 | } |
| 5962 | |
| 5963 | final int N = losers.size(); |
| 5964 | for (int i=0; i<N; i++) { |
| 5965 | try { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5966 | //Slog.i(TAG, "Losing delayed focus: " + losers.get(i)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5967 | losers.get(i).mClient.windowFocusChanged(false, mInTouchMode); |
| 5968 | } catch (RemoteException e) { |
| 5969 | // Ignore if process has died. |
| 5970 | } |
| 5971 | } |
| 5972 | } break; |
| 5973 | |
| 5974 | case ANIMATE: { |
| 5975 | synchronized(mWindowMap) { |
| 5976 | mAnimationPending = false; |
| 5977 | performLayoutAndPlaceSurfacesLocked(); |
| 5978 | } |
| 5979 | } break; |
| 5980 | |
| 5981 | case ADD_STARTING: { |
| 5982 | final AppWindowToken wtoken = (AppWindowToken)msg.obj; |
| 5983 | final StartingData sd = wtoken.startingData; |
| 5984 | |
| 5985 | if (sd == null) { |
| 5986 | // Animation has been canceled... do nothing. |
| 5987 | return; |
| 5988 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5989 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5990 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Add starting " |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5991 | + wtoken + ": pkg=" + sd.pkg); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5992 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5993 | View view = null; |
| 5994 | try { |
| 5995 | view = mPolicy.addStartingWindow( |
| 5996 | wtoken.token, sd.pkg, |
| 5997 | sd.theme, sd.nonLocalizedLabel, sd.labelRes, |
Dianne Hackborn | 7eec10e | 2010-11-12 18:03:47 -0800 | [diff] [blame] | 5998 | sd.icon, sd.windowFlags); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5999 | } catch (Exception e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6000 | Slog.w(TAG, "Exception when adding starting window", e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6001 | } |
| 6002 | |
| 6003 | if (view != null) { |
| 6004 | boolean abort = false; |
| 6005 | |
| 6006 | synchronized(mWindowMap) { |
| 6007 | if (wtoken.removed || wtoken.startingData == null) { |
| 6008 | // If the window was successfully added, then |
| 6009 | // we need to remove it. |
| 6010 | if (wtoken.startingWindow != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6011 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6012 | "Aborted starting " + wtoken |
| 6013 | + ": removed=" + wtoken.removed |
| 6014 | + " startingData=" + wtoken.startingData); |
| 6015 | wtoken.startingWindow = null; |
| 6016 | wtoken.startingData = null; |
| 6017 | abort = true; |
| 6018 | } |
| 6019 | } else { |
| 6020 | wtoken.startingView = view; |
| 6021 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6022 | if (DEBUG_STARTING_WINDOW && !abort) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6023 | "Added starting " + wtoken |
| 6024 | + ": startingWindow=" |
| 6025 | + wtoken.startingWindow + " startingView=" |
| 6026 | + wtoken.startingView); |
| 6027 | } |
| 6028 | |
| 6029 | if (abort) { |
| 6030 | try { |
| 6031 | mPolicy.removeStartingWindow(wtoken.token, view); |
| 6032 | } catch (Exception e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6033 | Slog.w(TAG, "Exception when removing starting window", e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6034 | } |
| 6035 | } |
| 6036 | } |
| 6037 | } break; |
| 6038 | |
| 6039 | case REMOVE_STARTING: { |
| 6040 | final AppWindowToken wtoken = (AppWindowToken)msg.obj; |
| 6041 | IBinder token = null; |
| 6042 | View view = null; |
| 6043 | synchronized (mWindowMap) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6044 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Remove starting " |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6045 | + wtoken + ": startingWindow=" |
| 6046 | + wtoken.startingWindow + " startingView=" |
| 6047 | + wtoken.startingView); |
| 6048 | if (wtoken.startingWindow != null) { |
| 6049 | view = wtoken.startingView; |
| 6050 | token = wtoken.token; |
| 6051 | wtoken.startingData = null; |
| 6052 | wtoken.startingView = null; |
| 6053 | wtoken.startingWindow = null; |
| 6054 | } |
| 6055 | } |
| 6056 | if (view != null) { |
| 6057 | try { |
| 6058 | mPolicy.removeStartingWindow(token, view); |
| 6059 | } catch (Exception e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6060 | Slog.w(TAG, "Exception when removing starting window", e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6061 | } |
| 6062 | } |
| 6063 | } break; |
| 6064 | |
| 6065 | case FINISHED_STARTING: { |
| 6066 | IBinder token = null; |
| 6067 | View view = null; |
| 6068 | while (true) { |
| 6069 | synchronized (mWindowMap) { |
| 6070 | final int N = mFinishedStarting.size(); |
| 6071 | if (N <= 0) { |
| 6072 | break; |
| 6073 | } |
| 6074 | AppWindowToken wtoken = mFinishedStarting.remove(N-1); |
| 6075 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6076 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6077 | "Finished starting " + wtoken |
| 6078 | + ": startingWindow=" + wtoken.startingWindow |
| 6079 | + " startingView=" + wtoken.startingView); |
| 6080 | |
| 6081 | if (wtoken.startingWindow == null) { |
| 6082 | continue; |
| 6083 | } |
| 6084 | |
| 6085 | view = wtoken.startingView; |
| 6086 | token = wtoken.token; |
| 6087 | wtoken.startingData = null; |
| 6088 | wtoken.startingView = null; |
| 6089 | wtoken.startingWindow = null; |
| 6090 | } |
| 6091 | |
| 6092 | try { |
| 6093 | mPolicy.removeStartingWindow(token, view); |
| 6094 | } catch (Exception e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6095 | Slog.w(TAG, "Exception when removing starting window", e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6096 | } |
| 6097 | } |
| 6098 | } break; |
| 6099 | |
| 6100 | case REPORT_APPLICATION_TOKEN_WINDOWS: { |
| 6101 | final AppWindowToken wtoken = (AppWindowToken)msg.obj; |
| 6102 | |
| 6103 | boolean nowVisible = msg.arg1 != 0; |
| 6104 | boolean nowGone = msg.arg2 != 0; |
| 6105 | |
| 6106 | try { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6107 | if (DEBUG_VISIBILITY) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6108 | TAG, "Reporting visible in " + wtoken |
| 6109 | + " visible=" + nowVisible |
| 6110 | + " gone=" + nowGone); |
| 6111 | if (nowVisible) { |
| 6112 | wtoken.appToken.windowsVisible(); |
| 6113 | } else { |
| 6114 | wtoken.appToken.windowsGone(); |
| 6115 | } |
| 6116 | } catch (RemoteException ex) { |
| 6117 | } |
| 6118 | } break; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6119 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6120 | case WINDOW_FREEZE_TIMEOUT: { |
| 6121 | synchronized (mWindowMap) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6122 | Slog.w(TAG, "Window freeze timeout expired."); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6123 | int i = mWindows.size(); |
| 6124 | while (i > 0) { |
| 6125 | i--; |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 6126 | WindowState w = mWindows.get(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6127 | if (w.mOrientationChanging) { |
| 6128 | w.mOrientationChanging = false; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6129 | Slog.w(TAG, "Force clearing orientation change: " + w); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6130 | } |
| 6131 | } |
| 6132 | performLayoutAndPlaceSurfacesLocked(); |
| 6133 | } |
| 6134 | break; |
| 6135 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6136 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6137 | case HOLD_SCREEN_CHANGED: { |
| 6138 | Session oldHold; |
| 6139 | Session newHold; |
| 6140 | synchronized (mWindowMap) { |
| 6141 | oldHold = mLastReportedHold; |
| 6142 | newHold = (Session)msg.obj; |
| 6143 | mLastReportedHold = newHold; |
| 6144 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6145 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6146 | if (oldHold != newHold) { |
| 6147 | try { |
| 6148 | if (oldHold != null) { |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 6149 | mBatteryStats.noteStopWakelock(oldHold.mUid, -1, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6150 | "window", |
| 6151 | BatteryStats.WAKE_TYPE_WINDOW); |
| 6152 | } |
| 6153 | if (newHold != null) { |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 6154 | mBatteryStats.noteStartWakelock(newHold.mUid, -1, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6155 | "window", |
| 6156 | BatteryStats.WAKE_TYPE_WINDOW); |
| 6157 | } |
| 6158 | } catch (RemoteException e) { |
| 6159 | } |
| 6160 | } |
| 6161 | break; |
| 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 | case APP_TRANSITION_TIMEOUT: { |
| 6165 | synchronized (mWindowMap) { |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 6166 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6167 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6168 | "*** APP TRANSITION TIMEOUT"); |
| 6169 | mAppTransitionReady = true; |
| 6170 | mAppTransitionTimeout = true; |
| 6171 | performLayoutAndPlaceSurfacesLocked(); |
| 6172 | } |
| 6173 | } |
| 6174 | break; |
| 6175 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6176 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6177 | case PERSIST_ANIMATION_SCALE: { |
| 6178 | Settings.System.putFloat(mContext.getContentResolver(), |
| 6179 | Settings.System.WINDOW_ANIMATION_SCALE, mWindowAnimationScale); |
| 6180 | Settings.System.putFloat(mContext.getContentResolver(), |
| 6181 | Settings.System.TRANSITION_ANIMATION_SCALE, mTransitionAnimationScale); |
| 6182 | break; |
| 6183 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6184 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6185 | case FORCE_GC: { |
| 6186 | synchronized(mWindowMap) { |
| 6187 | if (mAnimationPending) { |
| 6188 | // If we are animating, don't do the gc now but |
| 6189 | // delay a bit so we don't interrupt the animation. |
| 6190 | mH.sendMessageDelayed(mH.obtainMessage(H.FORCE_GC), |
| 6191 | 2000); |
| 6192 | return; |
| 6193 | } |
| 6194 | // If we are currently rotating the display, it will |
| 6195 | // schedule a new message when done. |
| 6196 | if (mDisplayFrozen) { |
| 6197 | return; |
| 6198 | } |
| 6199 | mFreezeGcPending = 0; |
| 6200 | } |
| 6201 | Runtime.getRuntime().gc(); |
| 6202 | break; |
| 6203 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6204 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6205 | case ENABLE_SCREEN: { |
| 6206 | performEnableScreen(); |
| 6207 | break; |
| 6208 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6209 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6210 | case APP_FREEZE_TIMEOUT: { |
| 6211 | synchronized (mWindowMap) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6212 | Slog.w(TAG, "App freeze timeout expired."); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6213 | int i = mAppTokens.size(); |
| 6214 | while (i > 0) { |
| 6215 | i--; |
| 6216 | AppWindowToken tok = mAppTokens.get(i); |
| 6217 | if (tok.freezingScreen) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6218 | Slog.w(TAG, "Force clearing freeze: " + tok); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6219 | unsetAppFreezingScreenLocked(tok, true, true); |
| 6220 | } |
| 6221 | } |
| 6222 | } |
| 6223 | break; |
| 6224 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6225 | |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 6226 | case SEND_NEW_CONFIGURATION: { |
| 6227 | removeMessages(SEND_NEW_CONFIGURATION); |
| 6228 | sendNewConfiguration(); |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 6229 | break; |
| 6230 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6231 | |
Konstantin Lopyrev | 6e0f65f | 2010-07-14 14:55:33 -0700 | [diff] [blame] | 6232 | case REPORT_WINDOWS_CHANGE: { |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 6233 | if (mWindowsChanged) { |
| 6234 | synchronized (mWindowMap) { |
| 6235 | mWindowsChanged = false; |
| 6236 | } |
| 6237 | notifyWindowsChanged(); |
| 6238 | } |
| 6239 | break; |
| 6240 | } |
| 6241 | |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 6242 | case DRAG_START_TIMEOUT: { |
| 6243 | IBinder win = (IBinder)msg.obj; |
| 6244 | if (DEBUG_DRAG) { |
| 6245 | Slog.w(TAG, "Timeout starting drag by win " + win); |
| 6246 | } |
| 6247 | synchronized (mWindowMap) { |
| 6248 | // !!! TODO: ANR the app that has failed to start the drag in time |
| 6249 | if (mDragState != null) { |
Chris Tate | d4533f1 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 6250 | mDragState.unregister(); |
Jeff Brown | 2e44b07 | 2011-01-24 15:21:56 -0800 | [diff] [blame] | 6251 | mInputMonitor.updateInputWindowsLw(true /*force*/); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 6252 | mDragState.reset(); |
| 6253 | mDragState = null; |
| 6254 | } |
| 6255 | } |
Chris Tate | d4533f1 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 6256 | break; |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 6257 | } |
| 6258 | |
Chris Tate | d4533f1 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 6259 | case DRAG_END_TIMEOUT: { |
| 6260 | IBinder win = (IBinder)msg.obj; |
| 6261 | if (DEBUG_DRAG) { |
| 6262 | Slog.w(TAG, "Timeout ending drag to win " + win); |
| 6263 | } |
| 6264 | synchronized (mWindowMap) { |
| 6265 | // !!! TODO: ANR the drag-receiving app |
| 6266 | mDragState.mDragResult = false; |
| 6267 | mDragState.endDragLw(); |
| 6268 | } |
| 6269 | break; |
| 6270 | } |
Jeff Brown | 2992ea7 | 2011-01-28 22:04:14 -0800 | [diff] [blame] | 6271 | |
| 6272 | case REPORT_HARD_KEYBOARD_STATUS_CHANGE: { |
| 6273 | notifyHardKeyboardStatusChange(); |
| 6274 | break; |
| 6275 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6276 | } |
| 6277 | } |
| 6278 | } |
| 6279 | |
| 6280 | // ------------------------------------------------------------- |
| 6281 | // IWindowManager API |
| 6282 | // ------------------------------------------------------------- |
| 6283 | |
| 6284 | public IWindowSession openSession(IInputMethodClient client, |
| 6285 | IInputContext inputContext) { |
| 6286 | if (client == null) throw new IllegalArgumentException("null client"); |
| 6287 | if (inputContext == null) throw new IllegalArgumentException("null inputContext"); |
Dianne Hackborn | 6e1eb76 | 2011-02-17 16:07:28 -0800 | [diff] [blame] | 6288 | Session session = new Session(this, client, inputContext); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 6289 | return session; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6290 | } |
| 6291 | |
| 6292 | public boolean inputMethodClientHasFocus(IInputMethodClient client) { |
| 6293 | synchronized (mWindowMap) { |
| 6294 | // The focus for the client is the window immediately below |
| 6295 | // where we would place the input method window. |
| 6296 | int idx = findDesiredInputMethodWindowIndexLocked(false); |
| 6297 | WindowState imFocus; |
| 6298 | if (idx > 0) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 6299 | imFocus = mWindows.get(idx-1); |
Dianne Hackborn | e75d872 | 2011-01-27 19:37:40 -0800 | [diff] [blame] | 6300 | //Log.i(TAG, "Desired input method target: " + imFocus); |
| 6301 | //Log.i(TAG, "Current focus: " + this.mCurrentFocus); |
| 6302 | //Log.i(TAG, "Last focus: " + this.mLastFocus); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6303 | if (imFocus != null) { |
Dianne Hackborn | e75d872 | 2011-01-27 19:37:40 -0800 | [diff] [blame] | 6304 | // This may be a starting window, in which case we still want |
| 6305 | // to count it as okay. |
| 6306 | if (imFocus.mAttrs.type == LayoutParams.TYPE_APPLICATION_STARTING |
| 6307 | && imFocus.mAppToken != null) { |
| 6308 | // The client has definitely started, so it really should |
| 6309 | // have a window in this app token. Let's look for it. |
| 6310 | for (int i=0; i<imFocus.mAppToken.windows.size(); i++) { |
| 6311 | WindowState w = imFocus.mAppToken.windows.get(i); |
| 6312 | if (w != imFocus) { |
| 6313 | //Log.i(TAG, "Switching to real app window: " + w); |
| 6314 | imFocus = w; |
| 6315 | break; |
| 6316 | } |
| 6317 | } |
| 6318 | } |
| 6319 | //Log.i(TAG, "IM target client: " + imFocus.mSession.mClient); |
| 6320 | //if (imFocus.mSession.mClient != null) { |
| 6321 | // Log.i(TAG, "IM target client binder: " + imFocus.mSession.mClient.asBinder()); |
| 6322 | // Log.i(TAG, "Requesting client binder: " + client.asBinder()); |
| 6323 | //} |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6324 | if (imFocus.mSession.mClient != null && |
| 6325 | imFocus.mSession.mClient.asBinder() == client.asBinder()) { |
| 6326 | return true; |
| 6327 | } |
Dianne Hackborn | e75d872 | 2011-01-27 19:37:40 -0800 | [diff] [blame] | 6328 | |
| 6329 | // Okay, how about this... what is the current focus? |
| 6330 | // It seems in some cases we may not have moved the IM |
| 6331 | // target window, such as when it was in a pop-up window, |
| 6332 | // so let's also look at the current focus. (An example: |
| 6333 | // go to Gmail, start searching so the keyboard goes up, |
| 6334 | // press home. Sometimes the IME won't go down.) |
| 6335 | // Would be nice to fix this more correctly, but it's |
| 6336 | // way at the end of a release, and this should be good enough. |
| 6337 | if (mCurrentFocus != null && mCurrentFocus.mSession.mClient != null && |
| 6338 | mCurrentFocus.mSession.mClient.asBinder() == client.asBinder()) { |
| 6339 | return true; |
| 6340 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6341 | } |
| 6342 | } |
| 6343 | } |
| 6344 | return false; |
| 6345 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6346 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6347 | // ------------------------------------------------------------- |
| 6348 | // Internals |
| 6349 | // ------------------------------------------------------------- |
| 6350 | |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 6351 | final WindowState windowForClientLocked(Session session, IWindow client, |
| 6352 | boolean throwOnError) { |
| 6353 | return windowForClientLocked(session, client.asBinder(), throwOnError); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6354 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6355 | |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 6356 | final WindowState windowForClientLocked(Session session, IBinder client, |
| 6357 | boolean throwOnError) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6358 | WindowState win = mWindowMap.get(client); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6359 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6360 | TAG, "Looking up client " + client + ": " + win); |
| 6361 | if (win == null) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 6362 | RuntimeException ex = new IllegalArgumentException( |
| 6363 | "Requested window " + client + " does not exist"); |
| 6364 | if (throwOnError) { |
| 6365 | throw ex; |
| 6366 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6367 | Slog.w(TAG, "Failed looking up window", ex); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6368 | return null; |
| 6369 | } |
| 6370 | if (session != null && win.mSession != session) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 6371 | RuntimeException ex = new IllegalArgumentException( |
| 6372 | "Requested window " + client + " is in session " + |
| 6373 | win.mSession + ", not " + session); |
| 6374 | if (throwOnError) { |
| 6375 | throw ex; |
| 6376 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6377 | Slog.w(TAG, "Failed looking up window", ex); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6378 | return null; |
| 6379 | } |
| 6380 | |
| 6381 | return win; |
| 6382 | } |
| 6383 | |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 6384 | final void rebuildAppWindowListLocked() { |
| 6385 | int NW = mWindows.size(); |
| 6386 | int i; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 6387 | int lastWallpaper = -1; |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 6388 | int numRemoved = 0; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6389 | |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 6390 | if (mRebuildTmp.length < NW) { |
| 6391 | mRebuildTmp = new WindowState[NW+10]; |
| 6392 | } |
| 6393 | |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 6394 | // First remove all existing app windows. |
| 6395 | i=0; |
| 6396 | while (i < NW) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 6397 | WindowState w = mWindows.get(i); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 6398 | if (w.mAppToken != null) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 6399 | WindowState win = mWindows.remove(i); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 6400 | win.mRebuilding = true; |
| 6401 | mRebuildTmp[numRemoved] = win; |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 6402 | mWindowsChanged = true; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6403 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, |
Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 6404 | "Rebuild removing window: " + win); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 6405 | NW--; |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 6406 | numRemoved++; |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 6407 | continue; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 6408 | } else if (w.mAttrs.type == WindowManager.LayoutParams.TYPE_WALLPAPER |
| 6409 | && lastWallpaper == i-1) { |
| 6410 | lastWallpaper = i; |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 6411 | } |
| 6412 | i++; |
| 6413 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6414 | |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 6415 | // The wallpaper window(s) typically live at the bottom of the stack, |
| 6416 | // so skip them before adding app tokens. |
| 6417 | lastWallpaper++; |
| 6418 | i = lastWallpaper; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6419 | |
Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 6420 | // First add all of the exiting app tokens... these are no longer |
| 6421 | // in the main app list, but still have windows shown. We put them |
| 6422 | // in the back because now that the animation is over we no longer |
| 6423 | // will care about them. |
| 6424 | int NT = mExitingAppTokens.size(); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 6425 | for (int j=0; j<NT; j++) { |
Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 6426 | i = reAddAppWindowsLocked(i, mExitingAppTokens.get(j)); |
| 6427 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6428 | |
Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 6429 | // And add in the still active app tokens in Z order. |
| 6430 | NT = mAppTokens.size(); |
| 6431 | for (int j=0; j<NT; j++) { |
| 6432 | i = reAddAppWindowsLocked(i, mAppTokens.get(j)); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 6433 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6434 | |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 6435 | i -= lastWallpaper; |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 6436 | if (i != numRemoved) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6437 | Slog.w(TAG, "Rebuild removed " + numRemoved |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 6438 | + " windows but added " + i); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 6439 | for (i=0; i<numRemoved; i++) { |
| 6440 | WindowState ws = mRebuildTmp[i]; |
| 6441 | if (ws.mRebuilding) { |
| 6442 | StringWriter sw = new StringWriter(); |
| 6443 | PrintWriter pw = new PrintWriter(sw); |
| 6444 | ws.dump(pw, ""); |
| 6445 | pw.flush(); |
| 6446 | Slog.w(TAG, "This window was lost: " + ws); |
| 6447 | Slog.w(TAG, sw.toString()); |
| 6448 | } |
| 6449 | } |
| 6450 | Slog.w(TAG, "Current app token list:"); |
| 6451 | dumpAppTokensLocked(); |
| 6452 | Slog.w(TAG, "Final window list:"); |
| 6453 | dumpWindowsLocked(); |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 6454 | } |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 6455 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6456 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6457 | private final void assignLayersLocked() { |
| 6458 | int N = mWindows.size(); |
| 6459 | int curBaseLayer = 0; |
| 6460 | int curLayer = 0; |
| 6461 | int i; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6462 | |
Dianne Hackborn | 6c8e20f | 2010-11-09 18:59:09 -0800 | [diff] [blame] | 6463 | if (DEBUG_LAYERS) { |
| 6464 | RuntimeException here = new RuntimeException("here"); |
| 6465 | here.fillInStackTrace(); |
| 6466 | Log.v(TAG, "Assigning layers", here); |
| 6467 | } |
| 6468 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6469 | for (i=0; i<N; i++) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 6470 | WindowState w = mWindows.get(i); |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 6471 | if (w.mBaseLayer == curBaseLayer || w.mIsImWindow |
| 6472 | || (i > 0 && w.mIsWallpaper)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6473 | curLayer += WINDOW_LAYER_MULTIPLIER; |
| 6474 | w.mLayer = curLayer; |
| 6475 | } else { |
| 6476 | curBaseLayer = curLayer = w.mBaseLayer; |
| 6477 | w.mLayer = curLayer; |
| 6478 | } |
| 6479 | if (w.mTargetAppToken != null) { |
| 6480 | w.mAnimLayer = w.mLayer + w.mTargetAppToken.animLayerAdjustment; |
| 6481 | } else if (w.mAppToken != null) { |
| 6482 | w.mAnimLayer = w.mLayer + w.mAppToken.animLayerAdjustment; |
| 6483 | } else { |
| 6484 | w.mAnimLayer = w.mLayer; |
| 6485 | } |
| 6486 | if (w.mIsImWindow) { |
| 6487 | w.mAnimLayer += mInputMethodAnimLayerAdjustment; |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 6488 | } else if (w.mIsWallpaper) { |
| 6489 | w.mAnimLayer += mWallpaperAnimLayerAdjustment; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6490 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6491 | if (DEBUG_LAYERS) Slog.v(TAG, "Assign layer " + w + ": " |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6492 | + w.mAnimLayer); |
| 6493 | //System.out.println( |
| 6494 | // "Assigned layer " + curLayer + " to " + w.mClient.asBinder()); |
| 6495 | } |
| 6496 | } |
| 6497 | |
| 6498 | private boolean mInLayout = false; |
| 6499 | private final void performLayoutAndPlaceSurfacesLocked() { |
| 6500 | if (mInLayout) { |
Dave Bort | cfe6524 | 2009-04-09 14:51:04 -0700 | [diff] [blame] | 6501 | if (DEBUG) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6502 | throw new RuntimeException("Recursive call!"); |
| 6503 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6504 | Slog.w(TAG, "performLayoutAndPlaceSurfacesLocked called while in layout"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6505 | return; |
| 6506 | } |
| 6507 | |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 6508 | if (mWaitingForConfig) { |
| 6509 | // Our configuration has changed (most likely rotation), but we |
| 6510 | // don't yet have the complete configuration to report to |
| 6511 | // applications. Don't do any window layout until we have it. |
| 6512 | return; |
| 6513 | } |
| 6514 | |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 6515 | if (mDisplay == null) { |
| 6516 | // Not yet initialized, nothing to do. |
| 6517 | return; |
| 6518 | } |
| 6519 | |
Dianne Hackborn | 2e7ffa5 | 2011-01-12 13:21:28 -0800 | [diff] [blame] | 6520 | mInLayout = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6521 | boolean recoveringMemory = false; |
Dianne Hackborn | 2e7ffa5 | 2011-01-12 13:21:28 -0800 | [diff] [blame] | 6522 | |
| 6523 | try { |
| 6524 | if (mForceRemoves != null) { |
| 6525 | recoveringMemory = true; |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 6526 | // Wait a little bit for things to settle down, and off we go. |
Dianne Hackborn | 2e7ffa5 | 2011-01-12 13:21:28 -0800 | [diff] [blame] | 6527 | for (int i=0; i<mForceRemoves.size(); i++) { |
| 6528 | WindowState ws = mForceRemoves.get(i); |
| 6529 | Slog.i(TAG, "Force removing: " + ws); |
| 6530 | removeWindowInnerLocked(ws.mSession, ws); |
| 6531 | } |
| 6532 | mForceRemoves = null; |
| 6533 | Slog.w(TAG, "Due to memory failure, waiting a bit for next layout"); |
| 6534 | Object tmp = new Object(); |
| 6535 | synchronized (tmp) { |
| 6536 | try { |
| 6537 | tmp.wait(250); |
| 6538 | } catch (InterruptedException e) { |
| 6539 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6540 | } |
| 6541 | } |
Dianne Hackborn | 2e7ffa5 | 2011-01-12 13:21:28 -0800 | [diff] [blame] | 6542 | } catch (RuntimeException e) { |
| 6543 | Slog.e(TAG, "Unhandled exception while force removing for memory", e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6544 | } |
Dianne Hackborn | 2e7ffa5 | 2011-01-12 13:21:28 -0800 | [diff] [blame] | 6545 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6546 | try { |
| 6547 | performLayoutAndPlaceSurfacesLockedInner(recoveringMemory); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6548 | |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 6549 | int N = mPendingRemove.size(); |
| 6550 | if (N > 0) { |
| 6551 | if (mPendingRemoveTmp.length < N) { |
| 6552 | mPendingRemoveTmp = new WindowState[N+10]; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6553 | } |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 6554 | mPendingRemove.toArray(mPendingRemoveTmp); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6555 | mPendingRemove.clear(); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 6556 | for (int i=0; i<N; i++) { |
| 6557 | WindowState w = mPendingRemoveTmp[i]; |
| 6558 | removeWindowInnerLocked(w.mSession, w); |
| 6559 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6560 | |
| 6561 | mInLayout = false; |
| 6562 | assignLayersLocked(); |
| 6563 | mLayoutNeeded = true; |
| 6564 | performLayoutAndPlaceSurfacesLocked(); |
| 6565 | |
| 6566 | } else { |
| 6567 | mInLayout = false; |
| 6568 | if (mLayoutNeeded) { |
| 6569 | requestAnimationLocked(0); |
| 6570 | } |
| 6571 | } |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 6572 | if (mWindowsChanged && !mWindowChangeListeners.isEmpty()) { |
Konstantin Lopyrev | 6e0f65f | 2010-07-14 14:55:33 -0700 | [diff] [blame] | 6573 | mH.removeMessages(H.REPORT_WINDOWS_CHANGE); |
| 6574 | mH.sendMessage(mH.obtainMessage(H.REPORT_WINDOWS_CHANGE)); |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 6575 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6576 | } catch (RuntimeException e) { |
| 6577 | mInLayout = false; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6578 | 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] | 6579 | } |
| 6580 | } |
| 6581 | |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 6582 | private final int performLayoutLockedInner(boolean initial, boolean updateInputWindows) { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 6583 | if (!mLayoutNeeded) { |
| 6584 | return 0; |
| 6585 | } |
| 6586 | |
| 6587 | mLayoutNeeded = false; |
| 6588 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6589 | final int dw = mDisplay.getWidth(); |
| 6590 | final int dh = mDisplay.getHeight(); |
| 6591 | |
| 6592 | final int N = mWindows.size(); |
| 6593 | int i; |
| 6594 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6595 | if (DEBUG_LAYOUT) Slog.v(TAG, "performLayout: needed=" |
Dianne Hackborn | 9b52a21 | 2009-12-11 14:51:35 -0800 | [diff] [blame] | 6596 | + mLayoutNeeded + " dw=" + dw + " dh=" + dh); |
| 6597 | |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 6598 | mPolicy.beginLayoutLw(dw, dh); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6599 | |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 6600 | int seq = mLayoutSeq+1; |
| 6601 | if (seq < 0) seq = 0; |
| 6602 | mLayoutSeq = seq; |
| 6603 | |
| 6604 | // First perform layout of any root windows (not attached |
| 6605 | // to another window). |
| 6606 | int topAttached = -1; |
| 6607 | for (i = N-1; i >= 0; i--) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 6608 | WindowState win = mWindows.get(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6609 | |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 6610 | // Don't do layout of a window if it is not visible, or |
| 6611 | // soon won't be visible, to avoid wasting time and funky |
| 6612 | // changes while a window is animating away. |
| 6613 | final AppWindowToken atoken = win.mAppToken; |
| 6614 | final boolean gone = win.mViewVisibility == View.GONE |
| 6615 | || !win.mRelayoutCalled |
Dianne Hackborn | ff801ec | 2011-01-22 18:05:38 -0800 | [diff] [blame] | 6616 | || (atoken == null && win.mRootToken.hidden) |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 6617 | || (atoken != null && atoken.hiddenRequested) |
| 6618 | || win.mAttachedHidden |
| 6619 | || win.mExiting || win.mDestroying; |
| 6620 | |
Dianne Hackborn | 1c24e95 | 2010-11-23 00:34:30 -0800 | [diff] [blame] | 6621 | if (DEBUG_LAYOUT && !win.mLayoutAttached) { |
| 6622 | Slog.v(TAG, "First pass " + win |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 6623 | + ": gone=" + gone + " mHaveFrame=" + win.mHaveFrame |
| 6624 | + " mLayoutAttached=" + win.mLayoutAttached); |
Dianne Hackborn | 1c24e95 | 2010-11-23 00:34:30 -0800 | [diff] [blame] | 6625 | if (gone) Slog.v(TAG, " (mViewVisibility=" |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 6626 | + win.mViewVisibility + " mRelayoutCalled=" |
| 6627 | + win.mRelayoutCalled + " hidden=" |
| 6628 | + win.mRootToken.hidden + " hiddenRequested=" |
| 6629 | + (atoken != null && atoken.hiddenRequested) |
| 6630 | + " mAttachedHidden=" + win.mAttachedHidden); |
| 6631 | } |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 6632 | |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 6633 | // If this view is GONE, then skip it -- keep the current |
| 6634 | // frame, and let the caller know so they can ignore it |
| 6635 | // if they want. (We do the normal layout for INVISIBLE |
| 6636 | // windows, since that means "perform layout as normal, |
| 6637 | // just don't display"). |
| 6638 | if (!gone || !win.mHaveFrame) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 6639 | if (!win.mLayoutAttached) { |
Dianne Hackborn | 8e11ef0 | 2010-11-18 19:47:42 -0800 | [diff] [blame] | 6640 | if (initial) { |
Dianne Hackborn | 0f761d6 | 2010-11-30 22:06:10 -0800 | [diff] [blame] | 6641 | //Slog.i(TAG, "Window " + this + " clearing mContentChanged - initial"); |
Dianne Hackborn | 8e11ef0 | 2010-11-18 19:47:42 -0800 | [diff] [blame] | 6642 | win.mContentChanged = false; |
| 6643 | } |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 6644 | mPolicy.layoutWindowLw(win, win.mAttrs, null); |
| 6645 | win.mLayoutSeq = seq; |
| 6646 | if (DEBUG_LAYOUT) Slog.v(TAG, "-> mFrame=" |
| 6647 | + win.mFrame + " mContainingFrame=" |
| 6648 | + win.mContainingFrame + " mDisplayFrame=" |
| 6649 | + win.mDisplayFrame); |
| 6650 | } else { |
| 6651 | if (topAttached < 0) topAttached = i; |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 6652 | } |
Dianne Hackborn | 958b9ad | 2009-03-31 18:00:36 -0700 | [diff] [blame] | 6653 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6654 | } |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 6655 | |
| 6656 | // Now perform layout of attached windows, which usually |
| 6657 | // depend on the position of the window they are attached to. |
| 6658 | // XXX does not deal with windows that are attached to windows |
| 6659 | // that are themselves attached. |
| 6660 | for (i = topAttached; i >= 0; i--) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 6661 | WindowState win = mWindows.get(i); |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 6662 | |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 6663 | if (win.mLayoutAttached) { |
| 6664 | if (DEBUG_LAYOUT) Slog.v(TAG, "Second pass " + win |
| 6665 | + " mHaveFrame=" + win.mHaveFrame |
| 6666 | + " mViewVisibility=" + win.mViewVisibility |
| 6667 | + " mRelayoutCalled=" + win.mRelayoutCalled); |
Dianne Hackborn | 1c24e95 | 2010-11-23 00:34:30 -0800 | [diff] [blame] | 6668 | // If this view is GONE, then skip it -- keep the current |
| 6669 | // frame, and let the caller know so they can ignore it |
| 6670 | // if they want. (We do the normal layout for INVISIBLE |
| 6671 | // windows, since that means "perform layout as normal, |
| 6672 | // just don't display"). |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 6673 | if ((win.mViewVisibility != View.GONE && win.mRelayoutCalled) |
| 6674 | || !win.mHaveFrame) { |
Dianne Hackborn | 8e11ef0 | 2010-11-18 19:47:42 -0800 | [diff] [blame] | 6675 | if (initial) { |
Dianne Hackborn | 0f761d6 | 2010-11-30 22:06:10 -0800 | [diff] [blame] | 6676 | //Slog.i(TAG, "Window " + this + " clearing mContentChanged - initial"); |
Dianne Hackborn | 8e11ef0 | 2010-11-18 19:47:42 -0800 | [diff] [blame] | 6677 | win.mContentChanged = false; |
| 6678 | } |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 6679 | mPolicy.layoutWindowLw(win, win.mAttrs, win.mAttachedWindow); |
| 6680 | win.mLayoutSeq = seq; |
| 6681 | if (DEBUG_LAYOUT) Slog.v(TAG, "-> mFrame=" |
| 6682 | + win.mFrame + " mContainingFrame=" |
| 6683 | + win.mContainingFrame + " mDisplayFrame=" |
| 6684 | + win.mDisplayFrame); |
| 6685 | } |
| 6686 | } |
| 6687 | } |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 6688 | |
| 6689 | // Window frames may have changed. Tell the input dispatcher about it. |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 6690 | mInputMonitor.setUpdateInputWindowsNeededLw(); |
| 6691 | if (updateInputWindows) { |
Jeff Brown | 2e44b07 | 2011-01-24 15:21:56 -0800 | [diff] [blame] | 6692 | mInputMonitor.updateInputWindowsLw(false /*force*/); |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 6693 | } |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 6694 | |
| 6695 | return mPolicy.finishLayoutLw(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6696 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6697 | |
Brad Fitzpatrick | 6804433 | 2010-11-22 18:19:48 -0800 | [diff] [blame] | 6698 | // "Something has changed! Let's make it correct now." |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6699 | private final void performLayoutAndPlaceSurfacesLockedInner( |
| 6700 | boolean recoveringMemory) { |
Joe Onorato | 34bcebc | 2010-07-07 18:05:01 -0400 | [diff] [blame] | 6701 | if (mDisplay == null) { |
| 6702 | Slog.i(TAG, "skipping performLayoutAndPlaceSurfacesLockedInner with no mDisplay"); |
| 6703 | return; |
| 6704 | } |
| 6705 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6706 | final long currentTime = SystemClock.uptimeMillis(); |
| 6707 | final int dw = mDisplay.getWidth(); |
| 6708 | final int dh = mDisplay.getHeight(); |
| 6709 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6710 | int i; |
| 6711 | |
Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 6712 | if (mFocusMayChange) { |
| 6713 | mFocusMayChange = false; |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 6714 | updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES, |
| 6715 | false /*updateInputWindows*/); |
Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 6716 | } |
| 6717 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6718 | // Initialize state of exiting tokens. |
| 6719 | for (i=mExitingTokens.size()-1; i>=0; i--) { |
| 6720 | mExitingTokens.get(i).hasVisible = false; |
| 6721 | } |
| 6722 | |
| 6723 | // Initialize state of exiting applications. |
| 6724 | for (i=mExitingAppTokens.size()-1; i>=0; i--) { |
| 6725 | mExitingAppTokens.get(i).hasVisible = false; |
| 6726 | } |
| 6727 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6728 | boolean orientationChangeComplete = true; |
| 6729 | Session holdScreen = null; |
| 6730 | float screenBrightness = -1; |
Mike Lockwood | fb73f79 | 2009-11-20 11:31:18 -0500 | [diff] [blame] | 6731 | float buttonBrightness = -1; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6732 | boolean focusDisplayed = false; |
| 6733 | boolean animating = false; |
Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 6734 | boolean createWatermark = false; |
Dianne Hackborn | 89ba675 | 2011-01-23 16:51:16 -0800 | [diff] [blame] | 6735 | boolean updateRotation = false; |
Dianne Hackborn | 50660e2 | 2011-02-02 17:12:25 -0800 | [diff] [blame] | 6736 | boolean screenRotationFinished = false; |
Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 6737 | |
| 6738 | if (mFxSession == null) { |
| 6739 | mFxSession = new SurfaceSession(); |
| 6740 | createWatermark = true; |
| 6741 | } |
| 6742 | |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 6743 | if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION performLayoutAndPlaceSurfaces"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6744 | |
| 6745 | Surface.openTransaction(); |
Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 6746 | |
| 6747 | if (createWatermark) { |
| 6748 | createWatermark(); |
| 6749 | } |
| 6750 | if (mWatermark != null) { |
| 6751 | mWatermark.positionSurface(dw, dh); |
| 6752 | } |
Brad Fitzpatrick | 6804433 | 2010-11-22 18:19:48 -0800 | [diff] [blame] | 6753 | if (mStrictModeFlash != null) { |
| 6754 | mStrictModeFlash.positionSurface(dw, dh); |
| 6755 | } |
Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 6756 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6757 | try { |
Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 6758 | boolean wallpaperForceHidingChanged = false; |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 6759 | int repeats = 0; |
| 6760 | int changes = 0; |
| 6761 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6762 | do { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 6763 | repeats++; |
| 6764 | if (repeats > 6) { |
| 6765 | Slog.w(TAG, "Animation repeat aborted after too many iterations"); |
| 6766 | mLayoutNeeded = false; |
| 6767 | break; |
| 6768 | } |
| 6769 | |
| 6770 | if ((changes&(WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER |
| 6771 | | WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG |
| 6772 | | WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT)) != 0) { |
| 6773 | if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER) != 0) { |
| 6774 | if ((adjustWallpaperWindowsLocked()&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) { |
| 6775 | assignLayersLocked(); |
| 6776 | mLayoutNeeded = true; |
| 6777 | } |
| 6778 | } |
| 6779 | if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG) != 0) { |
| 6780 | if (DEBUG_LAYOUT) Slog.v(TAG, "Computing new config from layout"); |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 6781 | if (updateOrientationFromAppTokensLocked(true)) { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 6782 | mLayoutNeeded = true; |
| 6783 | mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION); |
| 6784 | } |
| 6785 | } |
| 6786 | if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT) != 0) { |
| 6787 | mLayoutNeeded = true; |
| 6788 | } |
| 6789 | } |
| 6790 | |
| 6791 | // FIRST LOOP: Perform a layout, if needed. |
| 6792 | if (repeats < 4) { |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 6793 | changes = performLayoutLockedInner(repeats == 0, false /*updateInputWindows*/); |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 6794 | if (changes != 0) { |
| 6795 | continue; |
| 6796 | } |
| 6797 | } else { |
| 6798 | Slog.w(TAG, "Layout repeat skipped after too many iterations"); |
| 6799 | changes = 0; |
| 6800 | } |
| 6801 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6802 | final int transactionSequence = ++mTransactionSequence; |
| 6803 | |
| 6804 | // Update animations of all applications, including those |
| 6805 | // associated with exiting/removed apps |
| 6806 | boolean tokensAnimating = false; |
| 6807 | final int NAT = mAppTokens.size(); |
| 6808 | for (i=0; i<NAT; i++) { |
| 6809 | if (mAppTokens.get(i).stepAnimationLocked(currentTime, dw, dh)) { |
| 6810 | tokensAnimating = true; |
| 6811 | } |
| 6812 | } |
| 6813 | final int NEAT = mExitingAppTokens.size(); |
| 6814 | for (i=0; i<NEAT; i++) { |
| 6815 | if (mExitingAppTokens.get(i).stepAnimationLocked(currentTime, dw, dh)) { |
| 6816 | tokensAnimating = true; |
| 6817 | } |
| 6818 | } |
| 6819 | |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 6820 | // SECOND LOOP: Execute animations and update visibility of windows. |
| 6821 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6822 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "*** ANIM STEP: seq=" |
Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 6823 | + transactionSequence + " tokensAnimating=" |
| 6824 | + tokensAnimating); |
| 6825 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6826 | animating = tokensAnimating; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6827 | |
Dianne Hackborn | f9d0be9 | 2010-11-24 12:35:25 -0800 | [diff] [blame] | 6828 | if (mScreenRotationAnimation != null) { |
| 6829 | if (mScreenRotationAnimation.isAnimating()) { |
| 6830 | if (mScreenRotationAnimation.stepAnimation(currentTime)) { |
| 6831 | animating = true; |
| 6832 | } else { |
Dianne Hackborn | 50660e2 | 2011-02-02 17:12:25 -0800 | [diff] [blame] | 6833 | screenRotationFinished = true; |
Dianne Hackborn | 89ba675 | 2011-01-23 16:51:16 -0800 | [diff] [blame] | 6834 | updateRotation = true; |
Dianne Hackborn | f9d0be9 | 2010-11-24 12:35:25 -0800 | [diff] [blame] | 6835 | } |
| 6836 | } |
| 6837 | } |
| 6838 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6839 | boolean tokenMayBeDrawn = false; |
Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 6840 | boolean wallpaperMayChange = false; |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 6841 | boolean forceHiding = false; |
Dianne Hackborn | 6c8e20f | 2010-11-09 18:59:09 -0800 | [diff] [blame] | 6842 | WindowState windowDetachedWallpaper = null; |
Dianne Hackborn | de75cb4 | 2011-03-02 17:11:21 -0800 | [diff] [blame] | 6843 | WindowState windowAnimationBackground = null; |
| 6844 | int windowAnimationBackgroundColor = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6845 | |
| 6846 | mPolicy.beginAnimationLw(dw, dh); |
| 6847 | |
Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 6848 | final int N = mWindows.size(); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6849 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6850 | for (i=N-1; i>=0; i--) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 6851 | WindowState w = mWindows.get(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6852 | |
| 6853 | final WindowManager.LayoutParams attrs = w.mAttrs; |
| 6854 | |
| 6855 | if (w.mSurface != null) { |
Dianne Hackborn | 8e11ef0 | 2010-11-18 19:47:42 -0800 | [diff] [blame] | 6856 | // Take care of the window being ready to display. |
Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 6857 | if (w.commitFinishDrawingLocked(currentTime)) { |
| 6858 | if ((w.mAttrs.flags |
| 6859 | & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER) != 0) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6860 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 6861 | "First draw done in potential wallpaper target " + w); |
Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 6862 | wallpaperMayChange = true; |
| 6863 | } |
| 6864 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6865 | |
Dianne Hackborn | 6c8e20f | 2010-11-09 18:59:09 -0800 | [diff] [blame] | 6866 | final boolean wasAnimating = w.mAnimating; |
Dianne Hackborn | 8e11ef0 | 2010-11-18 19:47:42 -0800 | [diff] [blame] | 6867 | |
| 6868 | int animDw = dw; |
| 6869 | int animDh = dh; |
| 6870 | |
| 6871 | // If the window has moved due to its containing |
| 6872 | // content frame changing, then we'd like to animate |
| 6873 | // it. The checks here are ordered by what is least |
Joe Onorato | 3fe7f2f | 2010-11-20 13:48:58 -0800 | [diff] [blame] | 6874 | // likely to be true first. |
Dianne Hackborn | 1c24e95 | 2010-11-23 00:34:30 -0800 | [diff] [blame] | 6875 | if (w.shouldAnimateMove()) { |
Dianne Hackborn | 8e11ef0 | 2010-11-18 19:47:42 -0800 | [diff] [blame] | 6876 | // Frame has moved, containing content frame |
| 6877 | // has also moved, and we're not currently animating... |
| 6878 | // let's do something. |
| 6879 | Animation a = AnimationUtils.loadAnimation(mContext, |
| 6880 | com.android.internal.R.anim.window_move_from_decor); |
| 6881 | w.setAnimation(a); |
| 6882 | animDw = w.mLastFrame.left - w.mFrame.left; |
| 6883 | animDh = w.mLastFrame.top - w.mFrame.top; |
| 6884 | } |
| 6885 | |
| 6886 | // Execute animation. |
| 6887 | final boolean nowAnimating = w.stepAnimationLocked(currentTime, |
| 6888 | animDw, animDh); |
Dianne Hackborn | 6c8e20f | 2010-11-09 18:59:09 -0800 | [diff] [blame] | 6889 | |
| 6890 | // If this window is animating, make a note that we have |
| 6891 | // an animating window and take care of a request to run |
| 6892 | // a detached wallpaper animation. |
| 6893 | if (nowAnimating) { |
Dianne Hackborn | de75cb4 | 2011-03-02 17:11:21 -0800 | [diff] [blame] | 6894 | if (w.mAnimation != null) { |
| 6895 | if (w.mAnimation.getDetachWallpaper()) { |
| 6896 | windowDetachedWallpaper = w; |
| 6897 | } |
| 6898 | if (w.mAnimation.getBackgroundColor() != 0) { |
| 6899 | windowAnimationBackground = w; |
| 6900 | windowAnimationBackgroundColor = |
| 6901 | w.mAnimation.getBackgroundColor(); |
| 6902 | } |
Dianne Hackborn | 6c8e20f | 2010-11-09 18:59:09 -0800 | [diff] [blame] | 6903 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6904 | animating = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6905 | } |
Dianne Hackborn | 6c8e20f | 2010-11-09 18:59:09 -0800 | [diff] [blame] | 6906 | |
| 6907 | // If this window's app token is running a detached wallpaper |
| 6908 | // animation, make a note so we can ensure the wallpaper is |
| 6909 | // displayed behind it. |
Dianne Hackborn | de75cb4 | 2011-03-02 17:11:21 -0800 | [diff] [blame] | 6910 | if (w.mAppToken != null && w.mAppToken.animation != null) { |
| 6911 | if (w.mAppToken.animation.getDetachWallpaper()) { |
| 6912 | windowDetachedWallpaper = w; |
| 6913 | } |
| 6914 | if (w.mAppToken.animation.getBackgroundColor() != 0) { |
| 6915 | windowAnimationBackground = w; |
| 6916 | windowAnimationBackgroundColor = |
| 6917 | w.mAppToken.animation.getBackgroundColor(); |
| 6918 | } |
Dianne Hackborn | 6c8e20f | 2010-11-09 18:59:09 -0800 | [diff] [blame] | 6919 | } |
| 6920 | |
Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 6921 | if (wasAnimating && !w.mAnimating && mWallpaperTarget == w) { |
| 6922 | wallpaperMayChange = true; |
| 6923 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6924 | |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 6925 | if (mPolicy.doesForceHide(w, attrs)) { |
Dianne Hackborn | 6c8e20f | 2010-11-09 18:59:09 -0800 | [diff] [blame] | 6926 | if (!wasAnimating && nowAnimating) { |
Dianne Hackborn | 20cb56e | 2010-03-04 00:58:29 -0800 | [diff] [blame] | 6927 | if (DEBUG_VISIBILITY) Slog.v(TAG, |
Dianne Hackborn | 6c8e20f | 2010-11-09 18:59:09 -0800 | [diff] [blame] | 6928 | "Animation started that could impact force hide: " |
Dianne Hackborn | 20cb56e | 2010-03-04 00:58:29 -0800 | [diff] [blame] | 6929 | + w); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 6930 | wallpaperForceHidingChanged = true; |
Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 6931 | mFocusMayChange = true; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 6932 | } else if (w.isReadyForDisplay() && w.mAnimation == null) { |
| 6933 | forceHiding = true; |
| 6934 | } |
| 6935 | } else if (mPolicy.canBeForceHidden(w, attrs)) { |
| 6936 | boolean changed; |
| 6937 | if (forceHiding) { |
| 6938 | changed = w.hideLw(false, false); |
Dianne Hackborn | 20cb56e | 2010-03-04 00:58:29 -0800 | [diff] [blame] | 6939 | if (DEBUG_VISIBILITY && changed) Slog.v(TAG, |
| 6940 | "Now policy hidden: " + w); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 6941 | } else { |
| 6942 | changed = w.showLw(false, false); |
Dianne Hackborn | 20cb56e | 2010-03-04 00:58:29 -0800 | [diff] [blame] | 6943 | if (DEBUG_VISIBILITY && changed) Slog.v(TAG, |
| 6944 | "Now policy shown: " + w); |
| 6945 | if (changed) { |
| 6946 | if (wallpaperForceHidingChanged |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 6947 | && w.isVisibleNow() /*w.isReadyForDisplay()*/) { |
Dianne Hackborn | 20cb56e | 2010-03-04 00:58:29 -0800 | [diff] [blame] | 6948 | // Assume we will need to animate. If |
| 6949 | // we don't (because the wallpaper will |
| 6950 | // stay with the lock screen), then we will |
| 6951 | // clean up later. |
| 6952 | Animation a = mPolicy.createForceHideEnterAnimation(); |
| 6953 | if (a != null) { |
| 6954 | w.setAnimation(a); |
| 6955 | } |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 6956 | } |
Dianne Hackborn | 20cb56e | 2010-03-04 00:58:29 -0800 | [diff] [blame] | 6957 | if (mCurrentFocus == null || |
| 6958 | mCurrentFocus.mLayer < w.mLayer) { |
| 6959 | // We are showing on to of the current |
| 6960 | // focus, so re-evaluate focus to make |
| 6961 | // sure it is correct. |
| 6962 | mFocusMayChange = true; |
| 6963 | } |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 6964 | } |
| 6965 | } |
| 6966 | if (changed && (attrs.flags |
| 6967 | & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER) != 0) { |
| 6968 | wallpaperMayChange = true; |
| 6969 | } |
| 6970 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6971 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6972 | mPolicy.animatingWindowLw(w, attrs); |
| 6973 | } |
| 6974 | |
| 6975 | final AppWindowToken atoken = w.mAppToken; |
| 6976 | if (atoken != null && (!atoken.allDrawn || atoken.freezingScreen)) { |
| 6977 | if (atoken.lastTransactionSequence != transactionSequence) { |
| 6978 | atoken.lastTransactionSequence = transactionSequence; |
| 6979 | atoken.numInterestingWindows = atoken.numDrawnWindows = 0; |
| 6980 | atoken.startingDisplayed = false; |
| 6981 | } |
| 6982 | if ((w.isOnScreen() || w.mAttrs.type |
| 6983 | == WindowManager.LayoutParams.TYPE_BASE_APPLICATION) |
| 6984 | && !w.mExiting && !w.mDestroying) { |
| 6985 | if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6986 | Slog.v(TAG, "Eval win " + w + ": isDrawn=" |
Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 6987 | + w.isDrawnLw() |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6988 | + ", isAnimating=" + w.isAnimating()); |
Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 6989 | if (!w.isDrawnLw()) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6990 | Slog.v(TAG, "Not displayed: s=" + w.mSurface |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6991 | + " pv=" + w.mPolicyVisibility |
| 6992 | + " dp=" + w.mDrawPending |
| 6993 | + " cdp=" + w.mCommitDrawPending |
| 6994 | + " ah=" + w.mAttachedHidden |
| 6995 | + " th=" + atoken.hiddenRequested |
| 6996 | + " a=" + w.mAnimating); |
| 6997 | } |
| 6998 | } |
| 6999 | if (w != atoken.startingWindow) { |
| 7000 | if (!atoken.freezingScreen || !w.mAppFreezing) { |
| 7001 | atoken.numInterestingWindows++; |
Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 7002 | if (w.isDrawnLw()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7003 | atoken.numDrawnWindows++; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7004 | if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7005 | "tokenMayBeDrawn: " + atoken |
| 7006 | + " freezingScreen=" + atoken.freezingScreen |
| 7007 | + " mAppFreezing=" + w.mAppFreezing); |
| 7008 | tokenMayBeDrawn = true; |
| 7009 | } |
| 7010 | } |
Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 7011 | } else if (w.isDrawnLw()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7012 | atoken.startingDisplayed = true; |
| 7013 | } |
| 7014 | } |
| 7015 | } else if (w.mReadyToShow) { |
| 7016 | w.performShowLocked(); |
| 7017 | } |
| 7018 | } |
| 7019 | |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 7020 | changes |= mPolicy.finishAnimationLw(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7021 | |
| 7022 | if (tokenMayBeDrawn) { |
| 7023 | // See if any windows have been drawn, so they (and others |
| 7024 | // associated with them) can now be shown. |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 7025 | final int NT = mAppTokens.size(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7026 | for (i=0; i<NT; i++) { |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 7027 | AppWindowToken wtoken = mAppTokens.get(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7028 | if (wtoken.freezingScreen) { |
| 7029 | int numInteresting = wtoken.numInterestingWindows; |
| 7030 | if (numInteresting > 0 && wtoken.numDrawnWindows >= numInteresting) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7031 | if (DEBUG_VISIBILITY) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7032 | "allDrawn: " + wtoken |
| 7033 | + " interesting=" + numInteresting |
| 7034 | + " drawn=" + wtoken.numDrawnWindows); |
| 7035 | wtoken.showAllWindowsLocked(); |
| 7036 | unsetAppFreezingScreenLocked(wtoken, false, true); |
| 7037 | orientationChangeComplete = true; |
| 7038 | } |
| 7039 | } else if (!wtoken.allDrawn) { |
| 7040 | int numInteresting = wtoken.numInterestingWindows; |
| 7041 | if (numInteresting > 0 && wtoken.numDrawnWindows >= numInteresting) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7042 | if (DEBUG_VISIBILITY) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7043 | "allDrawn: " + wtoken |
| 7044 | + " interesting=" + numInteresting |
| 7045 | + " drawn=" + wtoken.numDrawnWindows); |
| 7046 | wtoken.allDrawn = true; |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 7047 | changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7048 | |
| 7049 | // We can now show all of the drawn windows! |
| 7050 | if (!mOpeningApps.contains(wtoken)) { |
| 7051 | wtoken.showAllWindowsLocked(); |
| 7052 | } |
| 7053 | } |
| 7054 | } |
| 7055 | } |
| 7056 | } |
| 7057 | |
| 7058 | // If we are ready to perform an app transition, check through |
| 7059 | // all of the app tokens to be shown and see if they are ready |
| 7060 | // to go. |
| 7061 | if (mAppTransitionReady) { |
| 7062 | int NN = mOpeningApps.size(); |
| 7063 | boolean goodToGo = true; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7064 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7065 | "Checking " + NN + " opening apps (frozen=" |
| 7066 | + mDisplayFrozen + " timeout=" |
| 7067 | + mAppTransitionTimeout + ")..."); |
| 7068 | if (!mDisplayFrozen && !mAppTransitionTimeout) { |
| 7069 | // If the display isn't frozen, wait to do anything until |
| 7070 | // all of the apps are ready. Otherwise just go because |
| 7071 | // we'll unfreeze the display when everyone is ready. |
| 7072 | for (i=0; i<NN && goodToGo; i++) { |
| 7073 | AppWindowToken wtoken = mOpeningApps.get(i); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7074 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7075 | "Check opening app" + wtoken + ": allDrawn=" |
| 7076 | + wtoken.allDrawn + " startingDisplayed=" |
| 7077 | + wtoken.startingDisplayed); |
| 7078 | if (!wtoken.allDrawn && !wtoken.startingDisplayed |
| 7079 | && !wtoken.startingMoved) { |
| 7080 | goodToGo = false; |
| 7081 | } |
| 7082 | } |
| 7083 | } |
| 7084 | if (goodToGo) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7085 | 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] | 7086 | int transit = mNextAppTransition; |
| 7087 | if (mSkipAppTransitionAnimation) { |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 7088 | transit = WindowManagerPolicy.TRANSIT_UNSET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7089 | } |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 7090 | mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7091 | mAppTransitionReady = false; |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 7092 | mAppTransitionRunning = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7093 | mAppTransitionTimeout = false; |
| 7094 | mStartingIconInTransition = false; |
| 7095 | mSkipAppTransitionAnimation = false; |
| 7096 | |
| 7097 | mH.removeMessages(H.APP_TRANSITION_TIMEOUT); |
| 7098 | |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 7099 | // If there are applications waiting to come to the |
| 7100 | // top of the stack, now is the time to move their windows. |
| 7101 | // (Note that we don't do apps going to the bottom |
| 7102 | // here -- we want to keep their windows in the old |
| 7103 | // Z-order until the animation completes.) |
| 7104 | if (mToTopApps.size() > 0) { |
| 7105 | NN = mAppTokens.size(); |
| 7106 | for (i=0; i<NN; i++) { |
| 7107 | AppWindowToken wtoken = mAppTokens.get(i); |
| 7108 | if (wtoken.sendingToTop) { |
| 7109 | wtoken.sendingToTop = false; |
| 7110 | moveAppWindowsLocked(wtoken, NN, false); |
| 7111 | } |
| 7112 | } |
| 7113 | mToTopApps.clear(); |
| 7114 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7115 | |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 7116 | WindowState oldWallpaper = mWallpaperTarget; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7117 | |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 7118 | adjustWallpaperWindowsLocked(); |
Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 7119 | wallpaperMayChange = false; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7120 | |
Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 7121 | // The top-most window will supply the layout params, |
| 7122 | // and we will determine it below. |
| 7123 | LayoutParams animLp = null; |
| 7124 | int bestAnimLayer = -1; |
Dianne Hackborn | 08121bc | 2011-01-17 17:54:31 -0800 | [diff] [blame] | 7125 | boolean fullscreenAnim = false; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7126 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7127 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 7128 | "New wallpaper target=" + mWallpaperTarget |
| 7129 | + ", lower target=" + mLowerWallpaperTarget |
| 7130 | + ", upper target=" + mUpperWallpaperTarget); |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 7131 | int foundWallpapers = 0; |
Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 7132 | // Do a first pass through the tokens for two |
| 7133 | // things: |
| 7134 | // (1) Determine if both the closing and opening |
| 7135 | // app token sets are wallpaper targets, in which |
| 7136 | // case special animations are needed |
| 7137 | // (since the wallpaper needs to stay static |
| 7138 | // behind them). |
| 7139 | // (2) Find the layout params of the top-most |
| 7140 | // application window in the tokens, which is |
| 7141 | // what will control the animation theme. |
| 7142 | final int NC = mClosingApps.size(); |
| 7143 | NN = NC + mOpeningApps.size(); |
| 7144 | for (i=0; i<NN; i++) { |
| 7145 | AppWindowToken wtoken; |
| 7146 | int mode; |
| 7147 | if (i < NC) { |
| 7148 | wtoken = mClosingApps.get(i); |
| 7149 | mode = 1; |
| 7150 | } else { |
| 7151 | wtoken = mOpeningApps.get(i-NC); |
| 7152 | mode = 2; |
| 7153 | } |
| 7154 | if (mLowerWallpaperTarget != null) { |
| 7155 | if (mLowerWallpaperTarget.mAppToken == wtoken |
| 7156 | || mUpperWallpaperTarget.mAppToken == wtoken) { |
| 7157 | foundWallpapers |= mode; |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 7158 | } |
| 7159 | } |
Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 7160 | if (wtoken.appFullscreen) { |
| 7161 | WindowState ws = wtoken.findMainWindow(); |
| 7162 | if (ws != null) { |
| 7163 | // If this is a compatibility mode |
| 7164 | // window, we will always use its anim. |
| 7165 | if ((ws.mAttrs.flags&FLAG_COMPATIBLE_WINDOW) != 0) { |
| 7166 | animLp = ws.mAttrs; |
| 7167 | bestAnimLayer = Integer.MAX_VALUE; |
Dianne Hackborn | 08121bc | 2011-01-17 17:54:31 -0800 | [diff] [blame] | 7168 | } else if (!fullscreenAnim || ws.mLayer > bestAnimLayer) { |
Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 7169 | animLp = ws.mAttrs; |
Dianne Hackborn | 08121bc | 2011-01-17 17:54:31 -0800 | [diff] [blame] | 7170 | bestAnimLayer = ws.mLayer; |
| 7171 | } |
| 7172 | fullscreenAnim = true; |
| 7173 | } |
| 7174 | } else if (!fullscreenAnim) { |
| 7175 | WindowState ws = wtoken.findMainWindow(); |
| 7176 | if (ws != null) { |
| 7177 | if (ws.mLayer > bestAnimLayer) { |
| 7178 | animLp = ws.mAttrs; |
Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 7179 | bestAnimLayer = ws.mLayer; |
| 7180 | } |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 7181 | } |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 7182 | } |
| 7183 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7184 | |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 7185 | if (foundWallpapers == 3) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7186 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 7187 | "Wallpaper animation!"); |
| 7188 | switch (transit) { |
| 7189 | case WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN: |
| 7190 | case WindowManagerPolicy.TRANSIT_TASK_OPEN: |
| 7191 | case WindowManagerPolicy.TRANSIT_TASK_TO_FRONT: |
| 7192 | transit = WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_OPEN; |
| 7193 | break; |
| 7194 | case WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE: |
| 7195 | case WindowManagerPolicy.TRANSIT_TASK_CLOSE: |
| 7196 | case WindowManagerPolicy.TRANSIT_TASK_TO_BACK: |
| 7197 | transit = WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_CLOSE; |
| 7198 | break; |
| 7199 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7200 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 7201 | "New transit: " + transit); |
| 7202 | } else if (oldWallpaper != null) { |
| 7203 | // We are transitioning from an activity with |
| 7204 | // a wallpaper to one without. |
| 7205 | transit = WindowManagerPolicy.TRANSIT_WALLPAPER_CLOSE; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7206 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 7207 | "New transit away from wallpaper: " + transit); |
| 7208 | } else if (mWallpaperTarget != null) { |
| 7209 | // We are transitioning from an activity without |
| 7210 | // a wallpaper to now showing the wallpaper |
| 7211 | transit = WindowManagerPolicy.TRANSIT_WALLPAPER_OPEN; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7212 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 7213 | "New transit into wallpaper: " + transit); |
| 7214 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7215 | |
Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 7216 | // If all closing windows are obscured, then there is |
| 7217 | // no need to do an animation. This is the case, for |
| 7218 | // example, when this transition is being done behind |
| 7219 | // the lock screen. |
| 7220 | if (!mPolicy.allowAppAnimationsLw()) { |
| 7221 | animLp = null; |
| 7222 | } |
| 7223 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7224 | NN = mOpeningApps.size(); |
| 7225 | for (i=0; i<NN; i++) { |
| 7226 | AppWindowToken wtoken = mOpeningApps.get(i); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7227 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7228 | "Now opening app" + wtoken); |
| 7229 | wtoken.reportedVisible = false; |
| 7230 | wtoken.inPendingTransaction = false; |
Dianne Hackborn | 83360b3 | 2009-08-24 18:43:32 -0700 | [diff] [blame] | 7231 | wtoken.animation = null; |
Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 7232 | setTokenVisibilityLocked(wtoken, animLp, true, transit, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7233 | wtoken.updateReportedVisibilityLocked(); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 7234 | wtoken.waitingToShow = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7235 | wtoken.showAllWindowsLocked(); |
| 7236 | } |
| 7237 | NN = mClosingApps.size(); |
| 7238 | for (i=0; i<NN; i++) { |
| 7239 | AppWindowToken wtoken = mClosingApps.get(i); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7240 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7241 | "Now closing app" + wtoken); |
| 7242 | wtoken.inPendingTransaction = false; |
Dianne Hackborn | 83360b3 | 2009-08-24 18:43:32 -0700 | [diff] [blame] | 7243 | wtoken.animation = null; |
Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 7244 | setTokenVisibilityLocked(wtoken, animLp, false, transit, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7245 | wtoken.updateReportedVisibilityLocked(); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 7246 | wtoken.waitingToHide = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7247 | // Force the allDrawn flag, because we want to start |
| 7248 | // this guy's animations regardless of whether it's |
| 7249 | // gotten drawn. |
| 7250 | wtoken.allDrawn = true; |
| 7251 | } |
| 7252 | |
Dianne Hackborn | 8b571a8 | 2009-09-25 16:09:43 -0700 | [diff] [blame] | 7253 | mNextAppTransitionPackage = null; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7254 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7255 | mOpeningApps.clear(); |
| 7256 | mClosingApps.clear(); |
| 7257 | |
| 7258 | // This has changed the visibility of windows, so perform |
| 7259 | // a new layout to get them all up-to-date. |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 7260 | changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT |
| 7261 | | WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7262 | mLayoutNeeded = true; |
Dianne Hackborn | 20583ff | 2009-07-27 21:51:05 -0700 | [diff] [blame] | 7263 | if (!moveInputMethodWindowsIfNeededLocked(true)) { |
| 7264 | assignLayersLocked(); |
| 7265 | } |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 7266 | updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES, |
| 7267 | false /*updateInputWindows*/); |
Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 7268 | mFocusMayChange = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7269 | } |
| 7270 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7271 | |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 7272 | int adjResult = 0; |
| 7273 | |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 7274 | if (!animating && mAppTransitionRunning) { |
| 7275 | // We have finished the animation of an app transition. To do |
| 7276 | // this, we have delayed a lot of operations like showing and |
| 7277 | // hiding apps, moving apps in Z-order, etc. The app token list |
| 7278 | // reflects the correct Z-order, but the window list may now |
| 7279 | // be out of sync with it. So here we will just rebuild the |
| 7280 | // entire app window list. Fun! |
| 7281 | mAppTransitionRunning = false; |
| 7282 | // Clear information about apps that were moving. |
| 7283 | mToBottomApps.clear(); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7284 | |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 7285 | rebuildAppWindowListLocked(); |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 7286 | changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT; |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 7287 | adjResult |= ADJUST_WALLPAPER_LAYERS_CHANGED; |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 7288 | moveInputMethodWindowsIfNeededLocked(false); |
| 7289 | wallpaperMayChange = true; |
Suchi Amalapurapu | c9568e3 | 2009-11-05 18:51:16 -0800 | [diff] [blame] | 7290 | // Since the window list has been rebuilt, focus might |
| 7291 | // have to be recomputed since the actual order of windows |
| 7292 | // might have changed again. |
Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 7293 | mFocusMayChange = true; |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 7294 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7295 | |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 7296 | if (wallpaperForceHidingChanged && changes == 0 && !mAppTransitionReady) { |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 7297 | // At this point, there was a window with a wallpaper that |
| 7298 | // was force hiding other windows behind it, but now it |
| 7299 | // is going away. This may be simple -- just animate |
| 7300 | // away the wallpaper and its window -- or it may be |
| 7301 | // hard -- the wallpaper now needs to be shown behind |
| 7302 | // something that was hidden. |
| 7303 | WindowState oldWallpaper = mWallpaperTarget; |
Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 7304 | if (mLowerWallpaperTarget != null |
| 7305 | && mLowerWallpaperTarget.mAppToken != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7306 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 7307 | "wallpaperForceHiding changed with lower=" |
| 7308 | + mLowerWallpaperTarget); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7309 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 7310 | "hidden=" + mLowerWallpaperTarget.mAppToken.hidden + |
| 7311 | " hiddenRequested=" + mLowerWallpaperTarget.mAppToken.hiddenRequested); |
| 7312 | if (mLowerWallpaperTarget.mAppToken.hidden) { |
| 7313 | // The lower target has become hidden before we |
| 7314 | // actually started the animation... let's completely |
| 7315 | // re-evaluate everything. |
| 7316 | mLowerWallpaperTarget = mUpperWallpaperTarget = null; |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 7317 | changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM; |
Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 7318 | } |
| 7319 | } |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 7320 | adjResult |= adjustWallpaperWindowsLocked(); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 7321 | wallpaperMayChange = false; |
Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 7322 | wallpaperForceHidingChanged = false; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7323 | if (DEBUG_WALLPAPER) Slog.v(TAG, "****** OLD: " + oldWallpaper |
Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 7324 | + " NEW: " + mWallpaperTarget |
| 7325 | + " LOWER: " + mLowerWallpaperTarget); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 7326 | if (mLowerWallpaperTarget == null) { |
| 7327 | // Whoops, we don't need a special wallpaper animation. |
| 7328 | // Clear them out. |
| 7329 | forceHiding = false; |
| 7330 | for (i=N-1; i>=0; i--) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 7331 | WindowState w = mWindows.get(i); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 7332 | if (w.mSurface != null) { |
| 7333 | final WindowManager.LayoutParams attrs = w.mAttrs; |
Suchi Amalapurapu | c03d28b | 2009-10-28 14:32:05 -0700 | [diff] [blame] | 7334 | if (mPolicy.doesForceHide(w, attrs) && w.isVisibleLw()) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7335 | if (DEBUG_FOCUS) Slog.i(TAG, "win=" + w + " force hides other windows"); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 7336 | forceHiding = true; |
| 7337 | } else if (mPolicy.canBeForceHidden(w, attrs)) { |
| 7338 | if (!w.mAnimating) { |
| 7339 | // We set the animation above so it |
| 7340 | // is not yet running. |
| 7341 | w.clearAnimation(); |
| 7342 | } |
| 7343 | } |
| 7344 | } |
| 7345 | } |
| 7346 | } |
| 7347 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7348 | |
Dianne Hackborn | 6c8e20f | 2010-11-09 18:59:09 -0800 | [diff] [blame] | 7349 | if (mWindowDetachedWallpaper != windowDetachedWallpaper) { |
| 7350 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
| 7351 | "Detached wallpaper changed from " + mWindowDetachedWallpaper |
| 7352 | + windowDetachedWallpaper); |
| 7353 | mWindowDetachedWallpaper = windowDetachedWallpaper; |
| 7354 | wallpaperMayChange = true; |
| 7355 | } |
| 7356 | |
Dianne Hackborn | de75cb4 | 2011-03-02 17:11:21 -0800 | [diff] [blame] | 7357 | if (windowAnimationBackgroundColor != 0) { |
| 7358 | if (mWindowAnimationBackgroundSurface == null) { |
| 7359 | mWindowAnimationBackgroundSurface = new DimSurface(mFxSession); |
| 7360 | } |
| 7361 | mWindowAnimationBackgroundSurface.show(dw, dh, |
| 7362 | windowAnimationBackground.mAnimLayer - LAYER_OFFSET_DIM, |
| 7363 | windowAnimationBackgroundColor); |
| 7364 | } else if (mWindowAnimationBackgroundSurface != null) { |
| 7365 | mWindowAnimationBackgroundSurface.hide(); |
| 7366 | } |
| 7367 | |
Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 7368 | if (wallpaperMayChange) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7369 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 7370 | "Wallpaper may change! Adjusting"); |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 7371 | adjResult |= adjustWallpaperWindowsLocked(); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 7372 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7373 | |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 7374 | if ((adjResult&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7375 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 7376 | "Wallpaper layer changed: assigning layers + relayout"); |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 7377 | changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 7378 | assignLayersLocked(); |
| 7379 | } else if ((adjResult&ADJUST_WALLPAPER_VISIBILITY_CHANGED) != 0) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7380 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 7381 | "Wallpaper visibility changed: relayout"); |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 7382 | changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 7383 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7384 | |
Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 7385 | if (mFocusMayChange) { |
| 7386 | mFocusMayChange = false; |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 7387 | if (updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES, |
| 7388 | false /*updateInputWindows*/)) { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 7389 | changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 7390 | adjResult = 0; |
Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 7391 | } |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 7392 | } |
| 7393 | |
| 7394 | if (mLayoutNeeded) { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 7395 | changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT; |
Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 7396 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7397 | |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 7398 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "*** ANIM STEP: changes=0x" |
| 7399 | + Integer.toHexString(changes)); |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 7400 | } while (changes != 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7401 | |
| 7402 | // THIRD LOOP: Update the surfaces of all windows. |
| 7403 | |
| 7404 | final boolean someoneLosingFocus = mLosingFocus.size() != 0; |
| 7405 | |
| 7406 | boolean obscured = false; |
| 7407 | boolean blurring = false; |
| 7408 | boolean dimming = false; |
| 7409 | boolean covered = false; |
Dianne Hackborn | 9ed4a4b | 2009-03-25 17:10:37 -0700 | [diff] [blame] | 7410 | boolean syswin = false; |
Dianne Hackborn | ac1471a | 2011-02-03 13:46:06 -0800 | [diff] [blame] | 7411 | boolean backgroundFillerWasShown = mBackgroundFillerTarget != null; |
| 7412 | mBackgroundFillerTarget = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7413 | |
Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 7414 | final int N = mWindows.size(); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7415 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7416 | for (i=N-1; i>=0; i--) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 7417 | WindowState w = mWindows.get(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7418 | |
| 7419 | boolean displayed = false; |
| 7420 | final WindowManager.LayoutParams attrs = w.mAttrs; |
| 7421 | final int attrFlags = attrs.flags; |
| 7422 | |
| 7423 | if (w.mSurface != null) { |
Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 7424 | // XXX NOTE: The logic here could be improved. We have |
| 7425 | // the decision about whether to resize a window separated |
| 7426 | // from whether to hide the surface. This can cause us to |
| 7427 | // resize a surface even if we are going to hide it. You |
| 7428 | // can see this by (1) holding device in landscape mode on |
| 7429 | // home screen; (2) tapping browser icon (device will rotate |
| 7430 | // to landscape; (3) tap home. The wallpaper will be resized |
| 7431 | // in step 2 but then immediately hidden, causing us to |
| 7432 | // have to resize and then redraw it again in step 3. It |
| 7433 | // would be nice to figure out how to avoid this, but it is |
| 7434 | // difficult because we do need to resize surfaces in some |
| 7435 | // cases while they are hidden such as when first showing a |
| 7436 | // window. |
| 7437 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7438 | w.computeShownFrameLocked(); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7439 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7440 | TAG, "Placing surface #" + i + " " + w.mSurface |
| 7441 | + ": new=" + w.mShownFrame + ", old=" |
| 7442 | + w.mLastShownFrame); |
| 7443 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7444 | int width, height; |
| 7445 | if ((w.mAttrs.flags & w.mAttrs.FLAG_SCALED) != 0) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7446 | // for a scaled surface, we just want to use |
| 7447 | // the requested size. |
| 7448 | width = w.mRequestedWidth; |
| 7449 | height = w.mRequestedHeight; |
| 7450 | w.mLastRequestedWidth = width; |
| 7451 | w.mLastRequestedHeight = height; |
| 7452 | w.mLastShownFrame.set(w.mShownFrame); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7453 | } else { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7454 | width = w.mShownFrame.width(); |
| 7455 | height = w.mShownFrame.height(); |
| 7456 | w.mLastShownFrame.set(w.mShownFrame); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7457 | } |
| 7458 | |
Jeff Brown | fbae722 | 2011-01-23 13:07:25 -0800 | [diff] [blame] | 7459 | if (w.mSurface != null) { |
| 7460 | if (w.mSurfaceX != w.mShownFrame.left |
| 7461 | || w.mSurfaceY != w.mShownFrame.top) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7462 | try { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 7463 | if (SHOW_TRANSACTIONS) logSurface(w, |
Jeff Brown | fbae722 | 2011-01-23 13:07:25 -0800 | [diff] [blame] | 7464 | "POS " + w.mShownFrame.left |
| 7465 | + ", " + w.mShownFrame.top, null); |
| 7466 | w.mSurfaceX = w.mShownFrame.left; |
| 7467 | w.mSurfaceY = w.mShownFrame.top; |
| 7468 | w.mSurface.setPosition(w.mShownFrame.left, w.mShownFrame.top); |
| 7469 | } catch (RuntimeException e) { |
| 7470 | Slog.w(TAG, "Error positioning surface of " + w |
| 7471 | + " pos=(" + w.mShownFrame.left |
| 7472 | + "," + w.mShownFrame.top + ")", e); |
| 7473 | if (!recoveringMemory) { |
Dianne Hackborn | 6482517 | 2011-03-02 21:32:58 -0800 | [diff] [blame] | 7474 | reclaimSomeSurfaceMemoryLocked(w, "position", true); |
Jeff Brown | fbae722 | 2011-01-23 13:07:25 -0800 | [diff] [blame] | 7475 | } |
| 7476 | } |
| 7477 | } |
| 7478 | |
| 7479 | if (width < 1) { |
| 7480 | width = 1; |
| 7481 | } |
| 7482 | if (height < 1) { |
| 7483 | height = 1; |
| 7484 | } |
| 7485 | |
| 7486 | if (w.mSurfaceW != width || w.mSurfaceH != height) { |
| 7487 | try { |
| 7488 | if (SHOW_TRANSACTIONS) logSurface(w, |
| 7489 | "SIZE " + w.mShownFrame.width() + "x" |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 7490 | + w.mShownFrame.height(), null); |
Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 7491 | w.mSurfaceResized = true; |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 7492 | w.mSurfaceW = width; |
| 7493 | w.mSurfaceH = height; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7494 | w.mSurface.setSize(width, height); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7495 | } catch (RuntimeException e) { |
| 7496 | // If something goes wrong with the surface (such |
| 7497 | // as running out of memory), don't take down the |
| 7498 | // entire system. |
Jeff Brown | fbae722 | 2011-01-23 13:07:25 -0800 | [diff] [blame] | 7499 | Slog.e(TAG, "Error resizing surface of " + w |
| 7500 | + " size=(" + width + "x" + height + ")", e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7501 | if (!recoveringMemory) { |
Dianne Hackborn | 6482517 | 2011-03-02 21:32:58 -0800 | [diff] [blame] | 7502 | reclaimSomeSurfaceMemoryLocked(w, "size", true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7503 | } |
| 7504 | } |
| 7505 | } |
| 7506 | } |
Jeff Brown | fbae722 | 2011-01-23 13:07:25 -0800 | [diff] [blame] | 7507 | |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 7508 | if (!w.mAppFreezing && w.mLayoutSeq == mLayoutSeq) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7509 | w.mContentInsetsChanged = |
| 7510 | !w.mLastContentInsets.equals(w.mContentInsets); |
| 7511 | w.mVisibleInsetsChanged = |
| 7512 | !w.mLastVisibleInsets.equals(w.mVisibleInsets); |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 7513 | boolean configChanged = |
| 7514 | w.mConfiguration != mCurConfiguration |
| 7515 | && (w.mConfiguration == null |
| 7516 | || mCurConfiguration.diff(w.mConfiguration) != 0); |
Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 7517 | if (DEBUG_CONFIGURATION && configChanged) { |
| 7518 | Slog.v(TAG, "Win " + w + " config changed: " |
| 7519 | + mCurConfiguration); |
| 7520 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7521 | if (localLOGV) Slog.v(TAG, "Resizing " + w |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 7522 | + ": configChanged=" + configChanged |
| 7523 | + " last=" + w.mLastFrame + " frame=" + w.mFrame); |
Jeff Brown | fbae722 | 2011-01-23 13:07:25 -0800 | [diff] [blame] | 7524 | boolean frameChanged = !w.mLastFrame.equals(w.mFrame); |
| 7525 | if (frameChanged |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7526 | || w.mContentInsetsChanged |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 7527 | || w.mVisibleInsetsChanged |
Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 7528 | || w.mSurfaceResized |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 7529 | || configChanged) { |
Jeff Brown | fbae722 | 2011-01-23 13:07:25 -0800 | [diff] [blame] | 7530 | if (DEBUG_RESIZE || DEBUG_ORIENTATION) { |
| 7531 | Slog.v(TAG, "Resize reasons: " |
| 7532 | + "frameChanged=" + frameChanged |
| 7533 | + " contentInsetsChanged=" + w.mContentInsetsChanged |
| 7534 | + " visibleInsetsChanged=" + w.mVisibleInsetsChanged |
| 7535 | + " surfaceResized=" + w.mSurfaceResized |
| 7536 | + " configChanged=" + configChanged); |
| 7537 | } |
| 7538 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7539 | w.mLastFrame.set(w.mFrame); |
| 7540 | w.mLastContentInsets.set(w.mContentInsets); |
| 7541 | w.mLastVisibleInsets.set(w.mVisibleInsets); |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 7542 | // If the screen is currently frozen, then keep |
| 7543 | // it frozen until this window draws at its new |
| 7544 | // orientation. |
| 7545 | if (mDisplayFrozen) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7546 | if (DEBUG_ORIENTATION) Slog.v(TAG, |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 7547 | "Resizing while display frozen: " + w); |
| 7548 | w.mOrientationChanging = true; |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 7549 | if (!mWindowsFreezingScreen) { |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 7550 | mWindowsFreezingScreen = true; |
| 7551 | // XXX should probably keep timeout from |
| 7552 | // when we first froze the display. |
| 7553 | mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT); |
| 7554 | mH.sendMessageDelayed(mH.obtainMessage( |
| 7555 | H.WINDOW_FREEZE_TIMEOUT), 2000); |
| 7556 | } |
| 7557 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7558 | // If the orientation is changing, then we need to |
| 7559 | // hold off on unfreezing the display until this |
| 7560 | // window has been redrawn; to do that, we need |
| 7561 | // to go through the process of getting informed |
| 7562 | // by the application when it has finished drawing. |
| 7563 | if (w.mOrientationChanging) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7564 | if (DEBUG_ORIENTATION) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7565 | "Orientation start waiting for draw in " |
| 7566 | + w + ", surface " + w.mSurface); |
| 7567 | w.mDrawPending = true; |
| 7568 | w.mCommitDrawPending = false; |
| 7569 | w.mReadyToShow = false; |
| 7570 | if (w.mAppToken != null) { |
| 7571 | w.mAppToken.allDrawn = false; |
| 7572 | } |
| 7573 | } |
Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 7574 | if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7575 | "Resizing window " + w + " to " + w.mFrame); |
| 7576 | mResizingWindows.add(w); |
| 7577 | } else if (w.mOrientationChanging) { |
| 7578 | if (!w.mDrawPending && !w.mCommitDrawPending) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7579 | if (DEBUG_ORIENTATION) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7580 | "Orientation not waiting for draw in " |
| 7581 | + w + ", surface " + w.mSurface); |
| 7582 | w.mOrientationChanging = false; |
| 7583 | } |
| 7584 | } |
| 7585 | } |
| 7586 | |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 7587 | if (w.mAttachedHidden || !w.isReadyForDisplay()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7588 | if (!w.mLastHidden) { |
| 7589 | //dump(); |
| 7590 | w.mLastHidden = true; |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 7591 | if (SHOW_TRANSACTIONS) logSurface(w, |
| 7592 | "HIDE (performLayout)", null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7593 | if (w.mSurface != null) { |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 7594 | w.mSurfaceShown = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7595 | try { |
| 7596 | w.mSurface.hide(); |
| 7597 | } catch (RuntimeException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7598 | Slog.w(TAG, "Exception hiding surface in " + w); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7599 | } |
| 7600 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7601 | } |
| 7602 | // If we are waiting for this window to handle an |
| 7603 | // orientation change, well, it is hidden, so |
| 7604 | // doesn't really matter. Note that this does |
| 7605 | // introduce a potential glitch if the window |
| 7606 | // becomes unhidden before it has drawn for the |
| 7607 | // new orientation. |
| 7608 | if (w.mOrientationChanging) { |
| 7609 | w.mOrientationChanging = false; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7610 | if (DEBUG_ORIENTATION) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7611 | "Orientation change skips hidden " + w); |
| 7612 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7613 | } else if (w.mLastLayer != w.mAnimLayer |
| 7614 | || w.mLastAlpha != w.mShownAlpha |
| 7615 | || w.mLastDsDx != w.mDsDx |
| 7616 | || w.mLastDtDx != w.mDtDx |
| 7617 | || w.mLastDsDy != w.mDsDy |
| 7618 | || w.mLastDtDy != w.mDtDy |
| 7619 | || w.mLastHScale != w.mHScale |
| 7620 | || w.mLastVScale != w.mVScale |
| 7621 | || w.mLastHidden) { |
| 7622 | displayed = true; |
| 7623 | w.mLastAlpha = w.mShownAlpha; |
| 7624 | w.mLastLayer = w.mAnimLayer; |
| 7625 | w.mLastDsDx = w.mDsDx; |
| 7626 | w.mLastDtDx = w.mDtDx; |
| 7627 | w.mLastDsDy = w.mDsDy; |
| 7628 | w.mLastDtDy = w.mDtDy; |
| 7629 | w.mLastHScale = w.mHScale; |
| 7630 | w.mLastVScale = w.mVScale; |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 7631 | if (SHOW_TRANSACTIONS) logSurface(w, |
| 7632 | "alpha=" + w.mShownAlpha + " layer=" + w.mAnimLayer |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 7633 | + " matrix=[" + (w.mDsDx*w.mHScale) |
| 7634 | + "," + (w.mDtDx*w.mVScale) |
| 7635 | + "][" + (w.mDsDy*w.mHScale) |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 7636 | + "," + (w.mDtDy*w.mVScale) + "]", null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7637 | if (w.mSurface != null) { |
| 7638 | try { |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 7639 | w.mSurfaceAlpha = w.mShownAlpha; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7640 | w.mSurface.setAlpha(w.mShownAlpha); |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 7641 | w.mSurfaceLayer = w.mAnimLayer; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7642 | w.mSurface.setLayer(w.mAnimLayer); |
| 7643 | w.mSurface.setMatrix( |
| 7644 | w.mDsDx*w.mHScale, w.mDtDx*w.mVScale, |
| 7645 | w.mDsDy*w.mHScale, w.mDtDy*w.mVScale); |
| 7646 | } catch (RuntimeException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7647 | Slog.w(TAG, "Error updating surface in " + w, e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7648 | if (!recoveringMemory) { |
Dianne Hackborn | 6482517 | 2011-03-02 21:32:58 -0800 | [diff] [blame] | 7649 | reclaimSomeSurfaceMemoryLocked(w, "update", true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7650 | } |
| 7651 | } |
| 7652 | } |
| 7653 | |
| 7654 | if (w.mLastHidden && !w.mDrawPending |
| 7655 | && !w.mCommitDrawPending |
| 7656 | && !w.mReadyToShow) { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 7657 | if (SHOW_TRANSACTIONS) logSurface(w, |
| 7658 | "SHOW (performLayout)", null); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7659 | if (DEBUG_VISIBILITY) Slog.v(TAG, "Showing " + w |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7660 | + " during relayout"); |
| 7661 | if (showSurfaceRobustlyLocked(w)) { |
| 7662 | w.mHasDrawn = true; |
| 7663 | w.mLastHidden = false; |
| 7664 | } else { |
| 7665 | w.mOrientationChanging = false; |
| 7666 | } |
| 7667 | } |
| 7668 | if (w.mSurface != null) { |
| 7669 | w.mToken.hasVisible = true; |
| 7670 | } |
| 7671 | } else { |
| 7672 | displayed = true; |
| 7673 | } |
| 7674 | |
| 7675 | if (displayed) { |
| 7676 | if (!covered) { |
Romain Guy | 980a938 | 2010-01-08 15:06:28 -0800 | [diff] [blame] | 7677 | if (attrs.width == LayoutParams.MATCH_PARENT |
| 7678 | && attrs.height == LayoutParams.MATCH_PARENT) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7679 | covered = true; |
| 7680 | } |
| 7681 | } |
| 7682 | if (w.mOrientationChanging) { |
| 7683 | if (w.mDrawPending || w.mCommitDrawPending) { |
| 7684 | orientationChangeComplete = false; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7685 | if (DEBUG_ORIENTATION) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7686 | "Orientation continue waiting for draw in " + w); |
| 7687 | } else { |
| 7688 | w.mOrientationChanging = false; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7689 | if (DEBUG_ORIENTATION) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7690 | "Orientation change complete in " + w); |
| 7691 | } |
| 7692 | } |
| 7693 | w.mToken.hasVisible = true; |
| 7694 | } |
| 7695 | } else if (w.mOrientationChanging) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7696 | if (DEBUG_ORIENTATION) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7697 | "Orientation change skips hidden " + w); |
| 7698 | w.mOrientationChanging = false; |
| 7699 | } |
| 7700 | |
Dianne Hackborn | 0f761d6 | 2010-11-30 22:06:10 -0800 | [diff] [blame] | 7701 | if (w.mContentChanged) { |
| 7702 | //Slog.i(TAG, "Window " + this + " clearing mContentChanged - done placing"); |
| 7703 | w.mContentChanged = false; |
| 7704 | } |
| 7705 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7706 | final boolean canBeSeen = w.isDisplayedLw(); |
| 7707 | |
| 7708 | if (someoneLosingFocus && w == mCurrentFocus && canBeSeen) { |
| 7709 | focusDisplayed = true; |
| 7710 | } |
| 7711 | |
Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 7712 | final boolean obscuredChanged = w.mObscured != obscured; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7713 | |
Dianne Hackborn | ac1471a | 2011-02-03 13:46:06 -0800 | [diff] [blame] | 7714 | if (mBackgroundFillerTarget != null) { |
| 7715 | if (w.isAnimating()) { |
| 7716 | // Background filler is below all other windows that |
| 7717 | // are animating. |
| 7718 | mBackgroundFillerTarget = w; |
| 7719 | } else if (w.mIsWallpaper) { |
| 7720 | mBackgroundFillerTarget = w; |
| 7721 | } |
| 7722 | } |
| 7723 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7724 | // Update effect. |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 7725 | if (!(w.mObscured=obscured)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7726 | if (w.mSurface != null) { |
| 7727 | if ((attrFlags&FLAG_KEEP_SCREEN_ON) != 0) { |
| 7728 | holdScreen = w.mSession; |
| 7729 | } |
Dianne Hackborn | 9ed4a4b | 2009-03-25 17:10:37 -0700 | [diff] [blame] | 7730 | if (!syswin && w.mAttrs.screenBrightness >= 0 |
| 7731 | && screenBrightness < 0) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7732 | screenBrightness = w.mAttrs.screenBrightness; |
| 7733 | } |
Mike Lockwood | fb73f79 | 2009-11-20 11:31:18 -0500 | [diff] [blame] | 7734 | if (!syswin && w.mAttrs.buttonBrightness >= 0 |
| 7735 | && buttonBrightness < 0) { |
| 7736 | buttonBrightness = w.mAttrs.buttonBrightness; |
| 7737 | } |
Mike Lockwood | 46af6a8 | 2010-03-09 08:28:22 -0500 | [diff] [blame] | 7738 | if (canBeSeen |
| 7739 | && (attrs.type == WindowManager.LayoutParams.TYPE_SYSTEM_DIALOG |
| 7740 | || attrs.type == WindowManager.LayoutParams.TYPE_KEYGUARD |
| 7741 | || attrs.type == WindowManager.LayoutParams.TYPE_SYSTEM_ERROR)) { |
Dianne Hackborn | 9ed4a4b | 2009-03-25 17:10:37 -0700 | [diff] [blame] | 7742 | syswin = true; |
| 7743 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7744 | } |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 7745 | |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 7746 | boolean opaqueDrawn = canBeSeen && w.isOpaqueDrawn(); |
| 7747 | if (opaqueDrawn && w.isFullscreen(dw, dh)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7748 | // This window completely covers everything behind it, |
| 7749 | // so we want to leave all of them as unblurred (for |
| 7750 | // performance reasons). |
| 7751 | obscured = true; |
Dianne Hackborn | ac1471a | 2011-02-03 13:46:06 -0800 | [diff] [blame] | 7752 | } else if (w.needsBackgroundFiller(dw, dh) && (canBeSeen || w.isAnimating())) { |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 7753 | // This window is in compatibility mode, and needs background filler. |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 7754 | obscured = true; |
Dianne Hackborn | ac1471a | 2011-02-03 13:46:06 -0800 | [diff] [blame] | 7755 | mBackgroundFillerTarget = w; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 7756 | } else if (canBeSeen && !obscured && |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7757 | (attrFlags&FLAG_BLUR_BEHIND|FLAG_DIM_BEHIND) != 0) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7758 | if (localLOGV) Slog.v(TAG, "Win " + w |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7759 | + ": blurring=" + blurring |
| 7760 | + " obscured=" + obscured |
| 7761 | + " displayed=" + displayed); |
| 7762 | if ((attrFlags&FLAG_DIM_BEHIND) != 0) { |
| 7763 | if (!dimming) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7764 | //Slog.i(TAG, "DIM BEHIND: " + w); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7765 | dimming = true; |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 7766 | if (mDimAnimator == null) { |
| 7767 | mDimAnimator = new DimAnimator(mFxSession); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7768 | } |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 7769 | mDimAnimator.show(dw, dh); |
Dianne Hackborn | 1c24e95 | 2010-11-23 00:34:30 -0800 | [diff] [blame] | 7770 | mDimAnimator.updateParameters(mContext.getResources(), |
| 7771 | w, currentTime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7772 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7773 | } |
| 7774 | if ((attrFlags&FLAG_BLUR_BEHIND) != 0) { |
| 7775 | if (!blurring) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7776 | //Slog.i(TAG, "BLUR BEHIND: " + w); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7777 | blurring = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7778 | if (mBlurSurface == null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7779 | try { |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7780 | mBlurSurface = new Surface(mFxSession, 0, |
Mathias Agopian | 5d26c1e | 2010-03-01 16:09:43 -0800 | [diff] [blame] | 7781 | "BlurSurface", |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7782 | -1, 16, 16, |
| 7783 | PixelFormat.OPAQUE, |
| 7784 | Surface.FX_SURFACE_BLUR); |
| 7785 | } catch (Exception e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7786 | Slog.e(TAG, "Exception creating Blur surface", e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7787 | } |
Dianne Hackborn | ac1471a | 2011-02-03 13:46:06 -0800 | [diff] [blame] | 7788 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR " |
| 7789 | + mBlurSurface + ": CREATE"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7790 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7791 | if (mBlurSurface != null) { |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 7792 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR " |
| 7793 | + mBlurSurface + ": pos=(0,0) (" + |
| 7794 | dw + "x" + dh + "), layer=" + (w.mAnimLayer-1)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7795 | mBlurSurface.setPosition(0, 0); |
| 7796 | mBlurSurface.setSize(dw, dh); |
Dianne Hackborn | de75cb4 | 2011-03-02 17:11:21 -0800 | [diff] [blame] | 7797 | mBlurSurface.setLayer(w.mAnimLayer-LAYER_OFFSET_BLUR); |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 7798 | if (!mBlurShown) { |
| 7799 | try { |
| 7800 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR " |
| 7801 | + mBlurSurface + ": SHOW"); |
| 7802 | mBlurSurface.show(); |
| 7803 | } catch (RuntimeException e) { |
| 7804 | Slog.w(TAG, "Failure showing blur surface", e); |
| 7805 | } |
| 7806 | mBlurShown = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7807 | } |
| 7808 | } |
| 7809 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7810 | } |
| 7811 | } |
| 7812 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7813 | |
Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 7814 | if (obscuredChanged && mWallpaperTarget == w) { |
| 7815 | // This is the wallpaper target and its obscured state |
| 7816 | // changed... make sure the current wallaper's visibility |
| 7817 | // has been updated accordingly. |
| 7818 | updateWallpaperVisibilityLocked(); |
| 7819 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7820 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7821 | |
Dianne Hackborn | ac1471a | 2011-02-03 13:46:06 -0800 | [diff] [blame] | 7822 | if (mBackgroundFillerTarget != null) { |
| 7823 | if (mBackgroundFillerSurface == null) { |
| 7824 | try { |
| 7825 | mBackgroundFillerSurface = new Surface(mFxSession, 0, |
| 7826 | "BackGroundFiller", |
| 7827 | 0, dw, dh, |
| 7828 | PixelFormat.OPAQUE, |
| 7829 | Surface.FX_SURFACE_NORMAL); |
| 7830 | } catch (Exception e) { |
| 7831 | Slog.e(TAG, "Exception creating filler surface", e); |
| 7832 | } |
| 7833 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " BG FILLER " |
| 7834 | + mBackgroundFillerSurface + ": CREATE"); |
| 7835 | } |
| 7836 | try { |
| 7837 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " BG FILLER " |
| 7838 | + mBackgroundFillerSurface + " SHOW: pos=(0,0) (" |
| 7839 | + dw + "x" + dh + ") layer=" |
| 7840 | + (mBackgroundFillerTarget.mLayer - 1)); |
| 7841 | mBackgroundFillerSurface.setPosition(0, 0); |
| 7842 | mBackgroundFillerSurface.setSize(dw, dh); |
| 7843 | // Using the same layer as Dim because they will never be shown at the |
| 7844 | // same time. NOTE: we do NOT use mAnimLayer, because we don't |
| 7845 | // want this surface dragged up in front of stuff that is animating. |
Dianne Hackborn | de75cb4 | 2011-03-02 17:11:21 -0800 | [diff] [blame] | 7846 | mBackgroundFillerSurface.setLayer(mBackgroundFillerTarget.mLayer |
| 7847 | - LAYER_OFFSET_DIM); |
Dianne Hackborn | ac1471a | 2011-02-03 13:46:06 -0800 | [diff] [blame] | 7848 | mBackgroundFillerSurface.show(); |
| 7849 | } catch (RuntimeException e) { |
| 7850 | Slog.e(TAG, "Exception showing filler surface"); |
| 7851 | } |
| 7852 | } else if (backgroundFillerWasShown) { |
| 7853 | mBackgroundFillerTarget = null; |
| 7854 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " BG FILLER " |
| 7855 | + mBackgroundFillerSurface + " HIDE"); |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 7856 | try { |
| 7857 | mBackgroundFillerSurface.hide(); |
| 7858 | } catch (RuntimeException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7859 | Slog.e(TAG, "Exception hiding filler surface", e); |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 7860 | } |
| 7861 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7862 | |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 7863 | if (mDimAnimator != null && mDimAnimator.mDimShown) { |
Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 7864 | animating |= mDimAnimator.updateSurface(dimming, currentTime, |
| 7865 | mDisplayFrozen || !mPolicy.isScreenOn()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7866 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7867 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7868 | if (!blurring && mBlurShown) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7869 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR " + mBlurSurface |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7870 | + ": HIDE"); |
| 7871 | try { |
| 7872 | mBlurSurface.hide(); |
| 7873 | } catch (IllegalArgumentException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7874 | Slog.w(TAG, "Illegal argument exception hiding blur surface"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7875 | } |
| 7876 | mBlurShown = false; |
| 7877 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7878 | } catch (RuntimeException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7879 | Slog.e(TAG, "Unhandled exception in Window Manager", e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7880 | } |
| 7881 | |
| 7882 | Surface.closeTransaction(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7883 | |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 7884 | if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION performLayoutAndPlaceSurfaces"); |
| 7885 | |
Dianne Hackborn | b9fb170 | 2010-08-23 16:49:02 -0700 | [diff] [blame] | 7886 | if (mWatermark != null) { |
| 7887 | mWatermark.drawIfNeeded(); |
| 7888 | } |
| 7889 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7890 | if (DEBUG_ORIENTATION && mDisplayFrozen) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7891 | "With display frozen, orientationChangeComplete=" |
| 7892 | + orientationChangeComplete); |
| 7893 | if (orientationChangeComplete) { |
| 7894 | if (mWindowsFreezingScreen) { |
| 7895 | mWindowsFreezingScreen = false; |
| 7896 | mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT); |
| 7897 | } |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 7898 | stopFreezingDisplayLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7899 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7900 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7901 | i = mResizingWindows.size(); |
| 7902 | if (i > 0) { |
| 7903 | do { |
| 7904 | i--; |
| 7905 | WindowState win = mResizingWindows.get(i); |
| 7906 | try { |
Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 7907 | if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG, |
| 7908 | "Reporting new frame to " + win + ": " + win.mFrame); |
Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 7909 | int diff = 0; |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 7910 | boolean configChanged = |
| 7911 | win.mConfiguration != mCurConfiguration |
| 7912 | && (win.mConfiguration == null |
Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 7913 | || (diff=mCurConfiguration.diff(win.mConfiguration)) != 0); |
| 7914 | if ((DEBUG_RESIZE || DEBUG_ORIENTATION || DEBUG_CONFIGURATION) |
| 7915 | && configChanged) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7916 | Slog.i(TAG, "Sending new config to window " + win + ": " |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 7917 | + win.mFrame.width() + "x" + win.mFrame.height() |
Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 7918 | + " / " + mCurConfiguration + " / 0x" |
| 7919 | + Integer.toHexString(diff)); |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 7920 | } |
Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 7921 | win.mConfiguration = mCurConfiguration; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7922 | win.mClient.resized(win.mFrame.width(), |
| 7923 | win.mFrame.height(), win.mLastContentInsets, |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 7924 | win.mLastVisibleInsets, win.mDrawPending, |
| 7925 | configChanged ? win.mConfiguration : null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7926 | win.mContentInsetsChanged = false; |
| 7927 | win.mVisibleInsetsChanged = false; |
Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 7928 | win.mSurfaceResized = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7929 | } catch (RemoteException e) { |
| 7930 | win.mOrientationChanging = false; |
| 7931 | } |
| 7932 | } while (i > 0); |
| 7933 | mResizingWindows.clear(); |
| 7934 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7935 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7936 | // Destroy the surface of any windows that are no longer visible. |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 7937 | boolean wallpaperDestroyed = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7938 | i = mDestroySurface.size(); |
| 7939 | if (i > 0) { |
| 7940 | do { |
| 7941 | i--; |
| 7942 | WindowState win = mDestroySurface.get(i); |
| 7943 | win.mDestroying = false; |
| 7944 | if (mInputMethodWindow == win) { |
| 7945 | mInputMethodWindow = null; |
| 7946 | } |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 7947 | if (win == mWallpaperTarget) { |
| 7948 | wallpaperDestroyed = true; |
| 7949 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7950 | win.destroySurfaceLocked(); |
| 7951 | } while (i > 0); |
| 7952 | mDestroySurface.clear(); |
| 7953 | } |
| 7954 | |
| 7955 | // Time to remove any exiting tokens? |
| 7956 | for (i=mExitingTokens.size()-1; i>=0; i--) { |
| 7957 | WindowToken token = mExitingTokens.get(i); |
| 7958 | if (!token.hasVisible) { |
| 7959 | mExitingTokens.remove(i); |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 7960 | if (token.windowType == TYPE_WALLPAPER) { |
| 7961 | mWallpaperTokens.remove(token); |
| 7962 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7963 | } |
| 7964 | } |
| 7965 | |
| 7966 | // Time to remove any exiting applications? |
| 7967 | for (i=mExitingAppTokens.size()-1; i>=0; i--) { |
| 7968 | AppWindowToken token = mExitingAppTokens.get(i); |
| 7969 | if (!token.hasVisible && !mClosingApps.contains(token)) { |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 7970 | // Make sure there is no animation running on this token, |
| 7971 | // so any windows associated with it will be removed as |
| 7972 | // soon as their animations are complete |
| 7973 | token.animation = null; |
| 7974 | token.animating = false; |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 7975 | if (DEBUG_ADD_REMOVE || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG, |
| 7976 | "performLayout: App token exiting now removed" + token); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7977 | mAppTokens.remove(token); |
| 7978 | mExitingAppTokens.remove(i); |
| 7979 | } |
| 7980 | } |
| 7981 | |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 7982 | boolean needRelayout = false; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7983 | |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 7984 | if (!animating && mAppTransitionRunning) { |
| 7985 | // We have finished the animation of an app transition. To do |
| 7986 | // this, we have delayed a lot of operations like showing and |
| 7987 | // hiding apps, moving apps in Z-order, etc. The app token list |
| 7988 | // reflects the correct Z-order, but the window list may now |
| 7989 | // be out of sync with it. So here we will just rebuild the |
| 7990 | // entire app window list. Fun! |
| 7991 | mAppTransitionRunning = false; |
| 7992 | needRelayout = true; |
| 7993 | rebuildAppWindowListLocked(); |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 7994 | assignLayersLocked(); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 7995 | // Clear information about apps that were moving. |
| 7996 | mToBottomApps.clear(); |
| 7997 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7998 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7999 | if (focusDisplayed) { |
| 8000 | mH.sendEmptyMessage(H.REPORT_LOSING_FOCUS); |
| 8001 | } |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 8002 | if (wallpaperDestroyed) { |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 8003 | needRelayout = adjustWallpaperWindowsLocked() != 0; |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 8004 | } |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8005 | if (needRelayout) { |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 8006 | requestAnimationLocked(0); |
| 8007 | } else if (animating) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8008 | requestAnimationLocked(currentTime+(1000/60)-SystemClock.uptimeMillis()); |
| 8009 | } |
Jeff Brown | eb857f1 | 2010-07-16 10:06:33 -0700 | [diff] [blame] | 8010 | |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 8011 | // Finally update all input windows now that the window changes have stabilized. |
Jeff Brown | 2e44b07 | 2011-01-24 15:21:56 -0800 | [diff] [blame] | 8012 | mInputMonitor.updateInputWindowsLw(true /*force*/); |
Jeff Brown | eb857f1 | 2010-07-16 10:06:33 -0700 | [diff] [blame] | 8013 | |
Jeff Brown | 8e03b75 | 2010-06-13 19:16:55 -0700 | [diff] [blame] | 8014 | setHoldScreenLocked(holdScreen != null); |
Dianne Hackborn | 428ecb6 | 2011-01-26 14:53:23 -0800 | [diff] [blame] | 8015 | if (!mDisplayFrozen) { |
| 8016 | if (screenBrightness < 0 || screenBrightness > 1.0f) { |
| 8017 | mPowerManager.setScreenBrightnessOverride(-1); |
| 8018 | } else { |
| 8019 | mPowerManager.setScreenBrightnessOverride((int) |
| 8020 | (screenBrightness * Power.BRIGHTNESS_ON)); |
| 8021 | } |
| 8022 | if (buttonBrightness < 0 || buttonBrightness > 1.0f) { |
| 8023 | mPowerManager.setButtonBrightnessOverride(-1); |
| 8024 | } else { |
| 8025 | mPowerManager.setButtonBrightnessOverride((int) |
| 8026 | (buttonBrightness * Power.BRIGHTNESS_ON)); |
| 8027 | } |
Mike Lockwood | fb73f79 | 2009-11-20 11:31:18 -0500 | [diff] [blame] | 8028 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8029 | if (holdScreen != mHoldingScreenOn) { |
| 8030 | mHoldingScreenOn = holdScreen; |
| 8031 | Message m = mH.obtainMessage(H.HOLD_SCREEN_CHANGED, holdScreen); |
| 8032 | mH.sendMessage(m); |
| 8033 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8034 | |
Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 8035 | if (mTurnOnScreen) { |
Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 8036 | if (DEBUG_VISIBILITY) Slog.v(TAG, "Turning screen on after layout!"); |
Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 8037 | mPowerManager.userActivity(SystemClock.uptimeMillis(), false, |
| 8038 | LocalPowerManager.BUTTON_EVENT, true); |
| 8039 | mTurnOnScreen = false; |
| 8040 | } |
Dianne Hackborn | f3bea9c | 2009-12-09 18:26:21 -0800 | [diff] [blame] | 8041 | |
Dianne Hackborn | 50660e2 | 2011-02-02 17:12:25 -0800 | [diff] [blame] | 8042 | if (screenRotationFinished && mScreenRotationAnimation != null) { |
| 8043 | mScreenRotationAnimation.kill(); |
| 8044 | mScreenRotationAnimation = null; |
| 8045 | } |
| 8046 | |
Dianne Hackborn | 89ba675 | 2011-01-23 16:51:16 -0800 | [diff] [blame] | 8047 | if (updateRotation) { |
| 8048 | if (DEBUG_ORIENTATION) Slog.d(TAG, "Performing post-rotate rotation"); |
| 8049 | boolean changed = setRotationUncheckedLocked( |
| 8050 | WindowManagerPolicy.USE_LAST_ROTATION, 0, false); |
| 8051 | if (changed) { |
Dianne Hackborn | 3e4f9d0 | 2011-02-04 14:05:55 -0800 | [diff] [blame] | 8052 | mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION); |
Dianne Hackborn | 89ba675 | 2011-01-23 16:51:16 -0800 | [diff] [blame] | 8053 | } |
| 8054 | } |
| 8055 | |
Dianne Hackborn | f3bea9c | 2009-12-09 18:26:21 -0800 | [diff] [blame] | 8056 | // Check to see if we are now in a state where the screen should |
| 8057 | // be enabled, because the window obscured flags have changed. |
| 8058 | enableScreenIfNeededLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8059 | } |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 8060 | |
| 8061 | /** |
| 8062 | * Must be called with the main window manager lock held. |
| 8063 | */ |
| 8064 | void setHoldScreenLocked(boolean holding) { |
| 8065 | boolean state = mHoldingScreenWakeLock.isHeld(); |
| 8066 | if (holding != state) { |
| 8067 | if (holding) { |
| 8068 | mHoldingScreenWakeLock.acquire(); |
| 8069 | } else { |
| 8070 | mPolicy.screenOnStoppedLw(); |
| 8071 | mHoldingScreenWakeLock.release(); |
| 8072 | } |
| 8073 | } |
| 8074 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8075 | |
| 8076 | void requestAnimationLocked(long delay) { |
| 8077 | if (!mAnimationPending) { |
| 8078 | mAnimationPending = true; |
| 8079 | mH.sendMessageDelayed(mH.obtainMessage(H.ANIMATE), delay); |
| 8080 | } |
| 8081 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8082 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8083 | /** |
| 8084 | * Have the surface flinger show a surface, robustly dealing with |
| 8085 | * error conditions. In particular, if there is not enough memory |
| 8086 | * to show the surface, then we will try to get rid of other surfaces |
| 8087 | * in order to succeed. |
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 | * @return Returns true if the surface was successfully shown. |
| 8090 | */ |
| 8091 | boolean showSurfaceRobustlyLocked(WindowState win) { |
| 8092 | try { |
| 8093 | if (win.mSurface != null) { |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 8094 | win.mSurfaceShown = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8095 | win.mSurface.show(); |
Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 8096 | if (win.mTurnOnScreen) { |
Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 8097 | if (DEBUG_VISIBILITY) Slog.v(TAG, |
| 8098 | "Show surface turning screen on: " + win); |
Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 8099 | win.mTurnOnScreen = false; |
| 8100 | mTurnOnScreen = true; |
| 8101 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8102 | } |
| 8103 | return true; |
| 8104 | } catch (RuntimeException e) { |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 8105 | Slog.w(TAG, "Failure showing surface " + win.mSurface + " in " + win, e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8106 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8107 | |
Dianne Hackborn | 6482517 | 2011-03-02 21:32:58 -0800 | [diff] [blame] | 8108 | reclaimSomeSurfaceMemoryLocked(win, "show", true); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8109 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8110 | return false; |
| 8111 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8112 | |
Dianne Hackborn | 6482517 | 2011-03-02 21:32:58 -0800 | [diff] [blame] | 8113 | boolean reclaimSomeSurfaceMemoryLocked(WindowState win, String operation, boolean secure) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8114 | final Surface surface = win.mSurface; |
Dianne Hackborn | 6482517 | 2011-03-02 21:32:58 -0800 | [diff] [blame] | 8115 | boolean leakedSurface = false; |
| 8116 | boolean killedApps = false; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8117 | |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8118 | EventLog.writeEvent(EventLogTags.WM_NO_SURFACE_MEMORY, win.toString(), |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8119 | win.mSession.mPid, operation); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8120 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8121 | if (mForceRemoves == null) { |
| 8122 | mForceRemoves = new ArrayList<WindowState>(); |
| 8123 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8124 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8125 | long callingIdentity = Binder.clearCallingIdentity(); |
| 8126 | try { |
| 8127 | // There was some problem... first, do a sanity check of the |
| 8128 | // window list to make sure we haven't left any dangling surfaces |
| 8129 | // around. |
| 8130 | int N = mWindows.size(); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8131 | 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] | 8132 | for (int i=0; i<N; i++) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 8133 | WindowState ws = mWindows.get(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8134 | if (ws.mSurface != null) { |
| 8135 | if (!mSessions.contains(ws.mSession)) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8136 | Slog.w(TAG, "LEAKED SURFACE (session doesn't exist): " |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8137 | + ws + " surface=" + ws.mSurface |
| 8138 | + " token=" + win.mToken |
| 8139 | + " pid=" + ws.mSession.mPid |
| 8140 | + " uid=" + ws.mSession.mUid); |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 8141 | if (SHOW_TRANSACTIONS) logSurface(ws, "LEAK DESTROY", null); |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 8142 | ws.mSurface.destroy(); |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 8143 | ws.mSurfaceShown = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8144 | ws.mSurface = null; |
| 8145 | mForceRemoves.add(ws); |
| 8146 | i--; |
| 8147 | N--; |
| 8148 | leakedSurface = true; |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 8149 | } else if (ws.mAppToken != null && ws.mAppToken.clientHidden) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8150 | Slog.w(TAG, "LEAKED SURFACE (app token hidden): " |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8151 | + ws + " surface=" + ws.mSurface |
| 8152 | + " token=" + win.mAppToken); |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 8153 | if (SHOW_TRANSACTIONS) logSurface(ws, "LEAK DESTROY", null); |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 8154 | ws.mSurface.destroy(); |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 8155 | ws.mSurfaceShown = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8156 | ws.mSurface = null; |
| 8157 | leakedSurface = true; |
| 8158 | } |
| 8159 | } |
| 8160 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8161 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8162 | if (!leakedSurface) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8163 | Slog.w(TAG, "No leaked surfaces; killing applicatons!"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8164 | SparseIntArray pidCandidates = new SparseIntArray(); |
| 8165 | for (int i=0; i<N; i++) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 8166 | WindowState ws = mWindows.get(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8167 | if (ws.mSurface != null) { |
| 8168 | pidCandidates.append(ws.mSession.mPid, ws.mSession.mPid); |
| 8169 | } |
| 8170 | } |
| 8171 | if (pidCandidates.size() > 0) { |
| 8172 | int[] pids = new int[pidCandidates.size()]; |
| 8173 | for (int i=0; i<pids.length; i++) { |
| 8174 | pids[i] = pidCandidates.keyAt(i); |
| 8175 | } |
| 8176 | try { |
Dianne Hackborn | 6482517 | 2011-03-02 21:32:58 -0800 | [diff] [blame] | 8177 | if (mActivityManager.killPids(pids, "Free memory", secure)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8178 | killedApps = true; |
| 8179 | } |
| 8180 | } catch (RemoteException e) { |
| 8181 | } |
| 8182 | } |
| 8183 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8184 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8185 | if (leakedSurface || killedApps) { |
| 8186 | // We managed to reclaim some memory, so get rid of the trouble |
| 8187 | // surface and ask the app to request another one. |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8188 | 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] | 8189 | if (surface != null) { |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 8190 | if (SHOW_TRANSACTIONS) logSurface(win, "RECOVER DESTROY", null); |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 8191 | surface.destroy(); |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 8192 | win.mSurfaceShown = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8193 | win.mSurface = null; |
| 8194 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8195 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8196 | try { |
| 8197 | win.mClient.dispatchGetNewSurface(); |
| 8198 | } catch (RemoteException e) { |
| 8199 | } |
| 8200 | } |
| 8201 | } finally { |
| 8202 | Binder.restoreCallingIdentity(callingIdentity); |
| 8203 | } |
Dianne Hackborn | 6482517 | 2011-03-02 21:32:58 -0800 | [diff] [blame] | 8204 | |
| 8205 | return leakedSurface || killedApps; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8206 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8207 | |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 8208 | private boolean updateFocusedWindowLocked(int mode, boolean updateInputWindows) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8209 | WindowState newFocus = computeFocusedWindowLocked(); |
| 8210 | if (mCurrentFocus != newFocus) { |
| 8211 | // This check makes sure that we don't already have the focus |
| 8212 | // change message pending. |
| 8213 | mH.removeMessages(H.REPORT_FOCUS_CHANGE); |
| 8214 | mH.sendEmptyMessage(H.REPORT_FOCUS_CHANGE); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8215 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8216 | TAG, "Changing focus from " + mCurrentFocus + " to " + newFocus); |
| 8217 | final WindowState oldFocus = mCurrentFocus; |
| 8218 | mCurrentFocus = newFocus; |
| 8219 | mLosingFocus.remove(newFocus); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8220 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8221 | final WindowState imWindow = mInputMethodWindow; |
| 8222 | if (newFocus != imWindow && oldFocus != imWindow) { |
The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 8223 | if (moveInputMethodWindowsIfNeededLocked( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8224 | mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS && |
The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 8225 | mode != UPDATE_FOCUS_WILL_PLACE_SURFACES)) { |
| 8226 | mLayoutNeeded = true; |
| 8227 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8228 | if (mode == UPDATE_FOCUS_PLACING_SURFACES) { |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 8229 | performLayoutLockedInner(true /*initial*/, updateInputWindows); |
The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 8230 | } else if (mode == UPDATE_FOCUS_WILL_PLACE_SURFACES) { |
| 8231 | // Client will do the layout, but we need to assign layers |
| 8232 | // for handleNewWindowLocked() below. |
| 8233 | assignLayersLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8234 | } |
| 8235 | } |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 8236 | |
| 8237 | if (mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS) { |
| 8238 | // If we defer assigning layers, then the caller is responsible for |
| 8239 | // doing this part. |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 8240 | finishUpdateFocusedWindowAfterAssignLayersLocked(updateInputWindows); |
The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 8241 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8242 | return true; |
| 8243 | } |
| 8244 | return false; |
| 8245 | } |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 8246 | |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 8247 | private void finishUpdateFocusedWindowAfterAssignLayersLocked(boolean updateInputWindows) { |
| 8248 | mInputMonitor.setInputFocusLw(mCurrentFocus, updateInputWindows); |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 8249 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8250 | |
| 8251 | private WindowState computeFocusedWindowLocked() { |
| 8252 | WindowState result = null; |
| 8253 | WindowState win; |
| 8254 | |
| 8255 | int i = mWindows.size() - 1; |
| 8256 | int nextAppIndex = mAppTokens.size()-1; |
| 8257 | WindowToken nextApp = nextAppIndex >= 0 |
| 8258 | ? mAppTokens.get(nextAppIndex) : null; |
| 8259 | |
| 8260 | while (i >= 0) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 8261 | win = mWindows.get(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8262 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8263 | if (localLOGV || DEBUG_FOCUS) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8264 | TAG, "Looking for focus: " + i |
| 8265 | + " = " + win |
| 8266 | + ", flags=" + win.mAttrs.flags |
| 8267 | + ", canReceive=" + win.canReceiveKeys()); |
| 8268 | |
| 8269 | AppWindowToken thisApp = win.mAppToken; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8270 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8271 | // If this window's application has been removed, just skip it. |
| 8272 | if (thisApp != null && thisApp.removed) { |
| 8273 | i--; |
| 8274 | continue; |
| 8275 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8276 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8277 | // If there is a focused app, don't allow focus to go to any |
| 8278 | // windows below it. If this is an application window, step |
| 8279 | // through the app tokens until we find its app. |
| 8280 | if (thisApp != null && nextApp != null && thisApp != nextApp |
| 8281 | && win.mAttrs.type != TYPE_APPLICATION_STARTING) { |
| 8282 | int origAppIndex = nextAppIndex; |
| 8283 | while (nextAppIndex > 0) { |
| 8284 | if (nextApp == mFocusedApp) { |
| 8285 | // Whoops, we are below the focused app... no focus |
| 8286 | // for you! |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8287 | if (localLOGV || DEBUG_FOCUS) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8288 | TAG, "Reached focused app: " + mFocusedApp); |
| 8289 | return null; |
| 8290 | } |
| 8291 | nextAppIndex--; |
| 8292 | nextApp = mAppTokens.get(nextAppIndex); |
| 8293 | if (nextApp == thisApp) { |
| 8294 | break; |
| 8295 | } |
| 8296 | } |
| 8297 | if (thisApp != nextApp) { |
| 8298 | // Uh oh, the app token doesn't exist! This shouldn't |
| 8299 | // happen, but if it does we can get totally hosed... |
| 8300 | // so restart at the original app. |
| 8301 | nextAppIndex = origAppIndex; |
| 8302 | nextApp = mAppTokens.get(nextAppIndex); |
| 8303 | } |
| 8304 | } |
| 8305 | |
| 8306 | // Dispatch to this window if it is wants key events. |
| 8307 | if (win.canReceiveKeys()) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8308 | if (DEBUG_FOCUS) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8309 | TAG, "Found focus @ " + i + " = " + win); |
| 8310 | result = win; |
| 8311 | break; |
| 8312 | } |
| 8313 | |
| 8314 | i--; |
| 8315 | } |
| 8316 | |
| 8317 | return result; |
| 8318 | } |
| 8319 | |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 8320 | private void startFreezingDisplayLocked(boolean inTransaction) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8321 | if (mDisplayFrozen) { |
| 8322 | return; |
| 8323 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8324 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8325 | mScreenFrozenLock.acquire(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8326 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8327 | long now = SystemClock.uptimeMillis(); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8328 | //Slog.i(TAG, "Freezing, gc pending: " + mFreezeGcPending + ", now " + now); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8329 | if (mFreezeGcPending != 0) { |
| 8330 | if (now > (mFreezeGcPending+1000)) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8331 | //Slog.i(TAG, "Gc! " + now + " > " + (mFreezeGcPending+1000)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8332 | mH.removeMessages(H.FORCE_GC); |
| 8333 | Runtime.getRuntime().gc(); |
| 8334 | mFreezeGcPending = now; |
| 8335 | } |
| 8336 | } else { |
| 8337 | mFreezeGcPending = now; |
| 8338 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8339 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8340 | mDisplayFrozen = true; |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 8341 | |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 8342 | mInputMonitor.freezeInputDispatchingLw(); |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 8343 | |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 8344 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
| 8345 | mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8346 | mNextAppTransitionPackage = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8347 | mAppTransitionReady = true; |
| 8348 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8349 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8350 | if (PROFILE_ORIENTATION) { |
| 8351 | File file = new File("/data/system/frozen"); |
| 8352 | Debug.startMethodTracing(file.toString(), 8 * 1024 * 1024); |
| 8353 | } |
Dianne Hackborn | a111187 | 2010-11-23 20:55:11 -0800 | [diff] [blame] | 8354 | |
| 8355 | if (CUSTOM_SCREEN_ROTATION) { |
Dianne Hackborn | f9d0be9 | 2010-11-24 12:35:25 -0800 | [diff] [blame] | 8356 | if (mScreenRotationAnimation != null && mScreenRotationAnimation.isAnimating()) { |
| 8357 | mScreenRotationAnimation.kill(); |
| 8358 | mScreenRotationAnimation = null; |
| 8359 | } |
Dianne Hackborn | a111187 | 2010-11-23 20:55:11 -0800 | [diff] [blame] | 8360 | if (mScreenRotationAnimation == null) { |
Dianne Hackborn | f9d0be9 | 2010-11-24 12:35:25 -0800 | [diff] [blame] | 8361 | mScreenRotationAnimation = new ScreenRotationAnimation(mContext, |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 8362 | mDisplay, mFxSession, inTransaction); |
Dianne Hackborn | a111187 | 2010-11-23 20:55:11 -0800 | [diff] [blame] | 8363 | } |
Dianne Hackborn | de75cb4 | 2011-03-02 17:11:21 -0800 | [diff] [blame] | 8364 | if (!mScreenRotationAnimation.hasScreenshot()) { |
| 8365 | Surface.freezeDisplay(0); |
| 8366 | } |
Dianne Hackborn | a111187 | 2010-11-23 20:55:11 -0800 | [diff] [blame] | 8367 | } else { |
| 8368 | Surface.freezeDisplay(0); |
| 8369 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8370 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8371 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8372 | private void stopFreezingDisplayLocked() { |
| 8373 | if (!mDisplayFrozen) { |
| 8374 | return; |
| 8375 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8376 | |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 8377 | if (mWaitingForConfig || mAppsFreezingScreen > 0 || mWindowsFreezingScreen) { |
| 8378 | return; |
| 8379 | } |
| 8380 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8381 | mDisplayFrozen = false; |
| 8382 | mH.removeMessages(H.APP_FREEZE_TIMEOUT); |
| 8383 | if (PROFILE_ORIENTATION) { |
| 8384 | Debug.stopMethodTracing(); |
| 8385 | } |
Dianne Hackborn | a111187 | 2010-11-23 20:55:11 -0800 | [diff] [blame] | 8386 | |
Dianne Hackborn | 89ba675 | 2011-01-23 16:51:16 -0800 | [diff] [blame] | 8387 | boolean updateRotation = false; |
| 8388 | |
Dianne Hackborn | de75cb4 | 2011-03-02 17:11:21 -0800 | [diff] [blame] | 8389 | if (CUSTOM_SCREEN_ROTATION && mScreenRotationAnimation != null |
| 8390 | && mScreenRotationAnimation.hasScreenshot()) { |
| 8391 | if (mScreenRotationAnimation.dismiss(mFxSession, MAX_ANIMATION_DURATION, |
| 8392 | mTransitionAnimationScale)) { |
| 8393 | requestAnimationLocked(0); |
| 8394 | } else { |
| 8395 | mScreenRotationAnimation = null; |
| 8396 | updateRotation = true; |
Dianne Hackborn | a111187 | 2010-11-23 20:55:11 -0800 | [diff] [blame] | 8397 | } |
| 8398 | } else { |
Dianne Hackborn | de75cb4 | 2011-03-02 17:11:21 -0800 | [diff] [blame] | 8399 | if (mScreenRotationAnimation != null) { |
| 8400 | mScreenRotationAnimation.kill(); |
| 8401 | mScreenRotationAnimation = null; |
| 8402 | } |
| 8403 | updateRotation = true; |
Dianne Hackborn | a111187 | 2010-11-23 20:55:11 -0800 | [diff] [blame] | 8404 | Surface.unfreezeDisplay(0); |
| 8405 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8406 | |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 8407 | mInputMonitor.thawInputDispatchingLw(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8408 | |
Dianne Hackborn | 420829e | 2011-01-28 11:30:35 -0800 | [diff] [blame] | 8409 | boolean configChanged; |
| 8410 | |
Christopher Tate | b696aee | 2010-04-02 19:08:30 -0700 | [diff] [blame] | 8411 | // While the display is frozen we don't re-compute the orientation |
| 8412 | // to avoid inconsistent states. However, something interesting |
| 8413 | // could have actually changed during that time so re-evaluate it |
| 8414 | // now to catch that. |
Dianne Hackborn | 420829e | 2011-01-28 11:30:35 -0800 | [diff] [blame] | 8415 | configChanged = updateOrientationFromAppTokensLocked(false); |
Christopher Tate | b696aee | 2010-04-02 19:08:30 -0700 | [diff] [blame] | 8416 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8417 | // A little kludge: a lot could have happened while the |
| 8418 | // display was frozen, so now that we are coming back we |
| 8419 | // do a gc so that any remote references the system |
| 8420 | // processes holds on others can be released if they are |
| 8421 | // no longer needed. |
| 8422 | mH.removeMessages(H.FORCE_GC); |
| 8423 | mH.sendMessageDelayed(mH.obtainMessage(H.FORCE_GC), |
| 8424 | 2000); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8425 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8426 | mScreenFrozenLock.release(); |
Dianne Hackborn | 89ba675 | 2011-01-23 16:51:16 -0800 | [diff] [blame] | 8427 | |
| 8428 | if (updateRotation) { |
| 8429 | if (DEBUG_ORIENTATION) Slog.d(TAG, "Performing post-rotate rotation"); |
Dianne Hackborn | 420829e | 2011-01-28 11:30:35 -0800 | [diff] [blame] | 8430 | configChanged |= setRotationUncheckedLocked( |
Dianne Hackborn | 89ba675 | 2011-01-23 16:51:16 -0800 | [diff] [blame] | 8431 | WindowManagerPolicy.USE_LAST_ROTATION, 0, false); |
Dianne Hackborn | 420829e | 2011-01-28 11:30:35 -0800 | [diff] [blame] | 8432 | } |
| 8433 | |
| 8434 | if (configChanged) { |
| 8435 | mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION); |
Dianne Hackborn | 89ba675 | 2011-01-23 16:51:16 -0800 | [diff] [blame] | 8436 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8437 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8438 | |
Dianne Hackborn | b9fb170 | 2010-08-23 16:49:02 -0700 | [diff] [blame] | 8439 | static int getPropertyInt(String[] tokens, int index, int defUnits, int defDps, |
| 8440 | DisplayMetrics dm) { |
| 8441 | if (index < tokens.length) { |
| 8442 | String str = tokens[index]; |
| 8443 | if (str != null && str.length() > 0) { |
| 8444 | try { |
| 8445 | int val = Integer.parseInt(str); |
| 8446 | return val; |
| 8447 | } catch (Exception e) { |
| 8448 | } |
| 8449 | } |
Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 8450 | } |
| 8451 | if (defUnits == TypedValue.COMPLEX_UNIT_PX) { |
| 8452 | return defDps; |
| 8453 | } |
| 8454 | int val = (int)TypedValue.applyDimension(defUnits, defDps, dm); |
| 8455 | return val; |
| 8456 | } |
| 8457 | |
Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 8458 | void createWatermark() { |
| 8459 | if (mWatermark != null) { |
| 8460 | return; |
| 8461 | } |
| 8462 | |
Dianne Hackborn | b9fb170 | 2010-08-23 16:49:02 -0700 | [diff] [blame] | 8463 | File file = new File("/system/etc/setup.conf"); |
| 8464 | FileInputStream in = null; |
| 8465 | try { |
| 8466 | in = new FileInputStream(file); |
| 8467 | DataInputStream ind = new DataInputStream(in); |
| 8468 | String line = ind.readLine(); |
| 8469 | if (line != null) { |
| 8470 | String[] toks = line.split("%"); |
| 8471 | if (toks != null && toks.length > 0) { |
Dianne Hackborn | ed7bfbf | 2010-11-05 13:08:35 -0700 | [diff] [blame] | 8472 | mWatermark = new Watermark(mDisplay, mFxSession, toks); |
Dianne Hackborn | b9fb170 | 2010-08-23 16:49:02 -0700 | [diff] [blame] | 8473 | } |
| 8474 | } |
| 8475 | } catch (FileNotFoundException e) { |
| 8476 | } catch (IOException e) { |
| 8477 | } finally { |
| 8478 | if (in != null) { |
| 8479 | try { |
| 8480 | in.close(); |
| 8481 | } catch (IOException e) { |
| 8482 | } |
| 8483 | } |
Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 8484 | } |
Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 8485 | } |
| 8486 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8487 | @Override |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 8488 | public void statusBarVisibilityChanged(int visibility) { |
Jeff Brown | 05dc66a | 2011-03-02 14:41:58 -0800 | [diff] [blame] | 8489 | mInputManager.setSystemUiVisibility(visibility); |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 8490 | synchronized (mWindowMap) { |
| 8491 | final int N = mWindows.size(); |
| 8492 | for (int i = 0; i < N; i++) { |
| 8493 | WindowState ws = mWindows.get(i); |
| 8494 | try { |
| 8495 | if (ws.getAttrs().hasSystemUiListeners) { |
| 8496 | ws.mClient.dispatchSystemUiVisibilityChanged(visibility); |
| 8497 | } |
| 8498 | } catch (RemoteException e) { |
| 8499 | // so sorry |
| 8500 | } |
| 8501 | } |
| 8502 | } |
| 8503 | } |
| 8504 | |
| 8505 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8506 | public void dump(FileDescriptor fd, PrintWriter pw, String[] args) { |
| 8507 | if (mContext.checkCallingOrSelfPermission("android.permission.DUMP") |
| 8508 | != PackageManager.PERMISSION_GRANTED) { |
| 8509 | pw.println("Permission Denial: can't dump WindowManager from from pid=" |
| 8510 | + Binder.getCallingPid() |
| 8511 | + ", uid=" + Binder.getCallingUid()); |
| 8512 | return; |
| 8513 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8514 | |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 8515 | mInputManager.dump(pw); |
Dianne Hackborn | a2e9226 | 2010-03-02 17:19:29 -0800 | [diff] [blame] | 8516 | pw.println(" "); |
| 8517 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8518 | synchronized(mWindowMap) { |
| 8519 | pw.println("Current Window Manager state:"); |
| 8520 | for (int i=mWindows.size()-1; i>=0; i--) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 8521 | WindowState w = mWindows.get(i); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8522 | pw.print(" Window #"); pw.print(i); pw.print(' '); |
| 8523 | pw.print(w); pw.println(":"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8524 | w.dump(pw, " "); |
| 8525 | } |
| 8526 | if (mInputMethodDialogs.size() > 0) { |
| 8527 | pw.println(" "); |
| 8528 | pw.println(" Input method dialogs:"); |
| 8529 | for (int i=mInputMethodDialogs.size()-1; i>=0; i--) { |
| 8530 | WindowState w = mInputMethodDialogs.get(i); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8531 | 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] | 8532 | } |
| 8533 | } |
| 8534 | if (mPendingRemove.size() > 0) { |
| 8535 | pw.println(" "); |
| 8536 | pw.println(" Remove pending for:"); |
| 8537 | for (int i=mPendingRemove.size()-1; i>=0; i--) { |
| 8538 | WindowState w = mPendingRemove.get(i); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8539 | pw.print(" Remove #"); pw.print(i); pw.print(' '); |
| 8540 | pw.print(w); pw.println(":"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8541 | w.dump(pw, " "); |
| 8542 | } |
| 8543 | } |
| 8544 | if (mForceRemoves != null && mForceRemoves.size() > 0) { |
| 8545 | pw.println(" "); |
| 8546 | pw.println(" Windows force removing:"); |
| 8547 | for (int i=mForceRemoves.size()-1; i>=0; i--) { |
| 8548 | WindowState w = mForceRemoves.get(i); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8549 | pw.print(" Removing #"); pw.print(i); pw.print(' '); |
| 8550 | pw.print(w); pw.println(":"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8551 | w.dump(pw, " "); |
| 8552 | } |
| 8553 | } |
| 8554 | if (mDestroySurface.size() > 0) { |
| 8555 | pw.println(" "); |
| 8556 | pw.println(" Windows waiting to destroy their surface:"); |
| 8557 | for (int i=mDestroySurface.size()-1; i>=0; i--) { |
| 8558 | WindowState w = mDestroySurface.get(i); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8559 | pw.print(" Destroy #"); pw.print(i); pw.print(' '); |
| 8560 | pw.print(w); pw.println(":"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8561 | w.dump(pw, " "); |
| 8562 | } |
| 8563 | } |
| 8564 | if (mLosingFocus.size() > 0) { |
| 8565 | pw.println(" "); |
| 8566 | pw.println(" Windows losing focus:"); |
| 8567 | for (int i=mLosingFocus.size()-1; i>=0; i--) { |
| 8568 | WindowState w = mLosingFocus.get(i); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8569 | pw.print(" Losing #"); pw.print(i); pw.print(' '); |
| 8570 | pw.print(w); pw.println(":"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8571 | w.dump(pw, " "); |
| 8572 | } |
| 8573 | } |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 8574 | if (mResizingWindows.size() > 0) { |
| 8575 | pw.println(" "); |
| 8576 | pw.println(" Windows waiting to resize:"); |
| 8577 | for (int i=mResizingWindows.size()-1; i>=0; i--) { |
| 8578 | WindowState w = mResizingWindows.get(i); |
| 8579 | pw.print(" Resizing #"); pw.print(i); pw.print(' '); |
| 8580 | pw.print(w); pw.println(":"); |
| 8581 | w.dump(pw, " "); |
| 8582 | } |
| 8583 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8584 | if (mSessions.size() > 0) { |
| 8585 | pw.println(" "); |
| 8586 | pw.println(" All active sessions:"); |
| 8587 | Iterator<Session> it = mSessions.iterator(); |
| 8588 | while (it.hasNext()) { |
| 8589 | Session s = it.next(); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8590 | pw.print(" Session "); pw.print(s); pw.println(':'); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8591 | s.dump(pw, " "); |
| 8592 | } |
| 8593 | } |
| 8594 | if (mTokenMap.size() > 0) { |
| 8595 | pw.println(" "); |
| 8596 | pw.println(" All tokens:"); |
| 8597 | Iterator<WindowToken> it = mTokenMap.values().iterator(); |
| 8598 | while (it.hasNext()) { |
| 8599 | WindowToken token = it.next(); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8600 | pw.print(" Token "); pw.print(token.token); pw.println(':'); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8601 | token.dump(pw, " "); |
| 8602 | } |
| 8603 | } |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 8604 | if (mWallpaperTokens.size() > 0) { |
| 8605 | pw.println(" "); |
| 8606 | pw.println(" Wallpaper tokens:"); |
| 8607 | for (int i=mWallpaperTokens.size()-1; i>=0; i--) { |
| 8608 | WindowToken token = mWallpaperTokens.get(i); |
| 8609 | pw.print(" Wallpaper #"); pw.print(i); |
| 8610 | pw.print(' '); pw.print(token); pw.println(':'); |
| 8611 | token.dump(pw, " "); |
| 8612 | } |
| 8613 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8614 | if (mAppTokens.size() > 0) { |
| 8615 | pw.println(" "); |
| 8616 | pw.println(" Application tokens in Z order:"); |
| 8617 | for (int i=mAppTokens.size()-1; i>=0; i--) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8618 | pw.print(" App #"); pw.print(i); pw.print(": "); |
| 8619 | pw.println(mAppTokens.get(i)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8620 | } |
| 8621 | } |
| 8622 | if (mFinishedStarting.size() > 0) { |
| 8623 | pw.println(" "); |
| 8624 | pw.println(" Finishing start of application tokens:"); |
| 8625 | for (int i=mFinishedStarting.size()-1; i>=0; i--) { |
| 8626 | WindowToken token = mFinishedStarting.get(i); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8627 | pw.print(" Finished Starting #"); pw.print(i); |
| 8628 | pw.print(' '); pw.print(token); pw.println(':'); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8629 | token.dump(pw, " "); |
| 8630 | } |
| 8631 | } |
| 8632 | if (mExitingTokens.size() > 0) { |
| 8633 | pw.println(" "); |
| 8634 | pw.println(" Exiting tokens:"); |
| 8635 | for (int i=mExitingTokens.size()-1; i>=0; i--) { |
| 8636 | WindowToken token = mExitingTokens.get(i); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8637 | pw.print(" Exiting #"); pw.print(i); |
| 8638 | pw.print(' '); pw.print(token); pw.println(':'); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8639 | token.dump(pw, " "); |
| 8640 | } |
| 8641 | } |
| 8642 | if (mExitingAppTokens.size() > 0) { |
| 8643 | pw.println(" "); |
| 8644 | pw.println(" Exiting application tokens:"); |
| 8645 | for (int i=mExitingAppTokens.size()-1; i>=0; i--) { |
| 8646 | WindowToken token = mExitingAppTokens.get(i); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8647 | pw.print(" Exiting App #"); pw.print(i); |
| 8648 | pw.print(' '); pw.print(token); pw.println(':'); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8649 | token.dump(pw, " "); |
| 8650 | } |
| 8651 | } |
| 8652 | pw.println(" "); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8653 | pw.print(" mCurrentFocus="); pw.println(mCurrentFocus); |
| 8654 | pw.print(" mLastFocus="); pw.println(mLastFocus); |
| 8655 | pw.print(" mFocusedApp="); pw.println(mFocusedApp); |
| 8656 | pw.print(" mInputMethodTarget="); pw.println(mInputMethodTarget); |
| 8657 | pw.print(" mInputMethodWindow="); pw.println(mInputMethodWindow); |
Dianne Hackborn | f21adf6 | 2009-08-13 10:20:21 -0700 | [diff] [blame] | 8658 | pw.print(" mWallpaperTarget="); pw.println(mWallpaperTarget); |
Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 8659 | if (mLowerWallpaperTarget != null && mUpperWallpaperTarget != null) { |
| 8660 | pw.print(" mLowerWallpaperTarget="); pw.println(mLowerWallpaperTarget); |
| 8661 | pw.print(" mUpperWallpaperTarget="); pw.println(mUpperWallpaperTarget); |
| 8662 | } |
Dianne Hackborn | 6c8e20f | 2010-11-09 18:59:09 -0800 | [diff] [blame] | 8663 | if (mWindowDetachedWallpaper != null) { |
| 8664 | pw.print(" mWindowDetachedWallpaper="); pw.println(mWindowDetachedWallpaper); |
| 8665 | } |
Dianne Hackborn | de75cb4 | 2011-03-02 17:11:21 -0800 | [diff] [blame] | 8666 | if (mWindowAnimationBackgroundSurface != null) { |
| 8667 | pw.println(" mWindowAnimationBackgroundSurface:"); |
| 8668 | mWindowAnimationBackgroundSurface.printTo(" ", pw); |
| 8669 | } |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 8670 | pw.print(" mCurConfiguration="); pw.println(this.mCurConfiguration); |
| 8671 | pw.print(" mInTouchMode="); pw.print(mInTouchMode); |
| 8672 | pw.print(" mLayoutSeq="); pw.println(mLayoutSeq); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8673 | pw.print(" mSystemBooted="); pw.print(mSystemBooted); |
| 8674 | pw.print(" mDisplayEnabled="); pw.println(mDisplayEnabled); |
| 8675 | pw.print(" mLayoutNeeded="); pw.print(mLayoutNeeded); |
| 8676 | pw.print(" mBlurShown="); pw.println(mBlurShown); |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 8677 | if (mDimAnimator != null) { |
Dianne Hackborn | de75cb4 | 2011-03-02 17:11:21 -0800 | [diff] [blame] | 8678 | pw.println(" mDimAnimator:"); |
| 8679 | mDimAnimator.printTo(" ", pw); |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 8680 | } else { |
Dianne Hackborn | a2e9226 | 2010-03-02 17:19:29 -0800 | [diff] [blame] | 8681 | pw.println( " no DimAnimator "); |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 8682 | } |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8683 | pw.print(" mInputMethodAnimLayerAdjustment="); |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 8684 | pw.print(mInputMethodAnimLayerAdjustment); |
| 8685 | pw.print(" mWallpaperAnimLayerAdjustment="); |
| 8686 | pw.println(mWallpaperAnimLayerAdjustment); |
Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 8687 | pw.print(" mLastWallpaperX="); pw.print(mLastWallpaperX); |
| 8688 | pw.print(" mLastWallpaperY="); pw.println(mLastWallpaperY); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8689 | pw.print(" mDisplayFrozen="); pw.print(mDisplayFrozen); |
| 8690 | pw.print(" mWindowsFreezingScreen="); pw.print(mWindowsFreezingScreen); |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 8691 | pw.print(" mAppsFreezingScreen="); pw.print(mAppsFreezingScreen); |
| 8692 | pw.print(" mWaitingForConfig="); pw.println(mWaitingForConfig); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8693 | pw.print(" mRotation="); pw.print(mRotation); |
| 8694 | pw.print(", mForcedAppOrientation="); pw.print(mForcedAppOrientation); |
| 8695 | pw.print(", mRequestedRotation="); pw.println(mRequestedRotation); |
Dianne Hackborn | 89ba675 | 2011-01-23 16:51:16 -0800 | [diff] [blame] | 8696 | pw.print(" mDeferredRotation="); pw.print(mDeferredRotation); |
| 8697 | pw.print(", mDeferredRotationAnimFlags="); pw.print(mDeferredRotationAnimFlags); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8698 | pw.print(" mAnimationPending="); pw.print(mAnimationPending); |
| 8699 | pw.print(" mWindowAnimationScale="); pw.print(mWindowAnimationScale); |
| 8700 | pw.print(" mTransitionWindowAnimationScale="); pw.println(mTransitionAnimationScale); |
| 8701 | pw.print(" mNextAppTransition=0x"); |
| 8702 | pw.print(Integer.toHexString(mNextAppTransition)); |
| 8703 | pw.print(", mAppTransitionReady="); pw.print(mAppTransitionReady); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8704 | pw.print(", mAppTransitionRunning="); pw.print(mAppTransitionRunning); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8705 | pw.print(", mAppTransitionTimeout="); pw.println( mAppTransitionTimeout); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8706 | if (mNextAppTransitionPackage != null) { |
| 8707 | pw.print(" mNextAppTransitionPackage="); |
| 8708 | pw.print(mNextAppTransitionPackage); |
| 8709 | pw.print(", mNextAppTransitionEnter=0x"); |
| 8710 | pw.print(Integer.toHexString(mNextAppTransitionEnter)); |
| 8711 | pw.print(", mNextAppTransitionExit=0x"); |
| 8712 | pw.print(Integer.toHexString(mNextAppTransitionExit)); |
| 8713 | } |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8714 | pw.print(" mStartingIconInTransition="); pw.print(mStartingIconInTransition); |
| 8715 | pw.print(", mSkipAppTransitionAnimation="); pw.println(mSkipAppTransitionAnimation); |
| 8716 | if (mOpeningApps.size() > 0) { |
| 8717 | pw.print(" mOpeningApps="); pw.println(mOpeningApps); |
| 8718 | } |
| 8719 | if (mClosingApps.size() > 0) { |
| 8720 | pw.print(" mClosingApps="); pw.println(mClosingApps); |
| 8721 | } |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8722 | if (mToTopApps.size() > 0) { |
| 8723 | pw.print(" mToTopApps="); pw.println(mToTopApps); |
| 8724 | } |
| 8725 | if (mToBottomApps.size() > 0) { |
| 8726 | pw.print(" mToBottomApps="); pw.println(mToBottomApps); |
| 8727 | } |
Dianne Hackborn | 87fc308 | 2010-12-03 13:09:12 -0800 | [diff] [blame] | 8728 | if (mDisplay != null) { |
| 8729 | pw.print(" DisplayWidth="); pw.print(mDisplay.getWidth()); |
| 8730 | pw.print(" DisplayHeight="); pw.println(mDisplay.getHeight()); |
| 8731 | } else { |
| 8732 | pw.println(" NO DISPLAY"); |
| 8733 | } |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 8734 | pw.println(" Policy:"); |
| 8735 | mPolicy.dump(" ", fd, pw, args); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8736 | } |
| 8737 | } |
| 8738 | |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 8739 | // 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] | 8740 | public void monitor() { |
| 8741 | synchronized (mWindowMap) { } |
Mike Lockwood | 983ee09 | 2009-11-22 01:42:24 -0500 | [diff] [blame] | 8742 | synchronized (mKeyguardTokenWatcher) { } |
Dianne Hackborn | ddca3ee | 2009-07-23 19:01:31 -0700 | [diff] [blame] | 8743 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8744 | |
Jeff Brown | 2992ea7 | 2011-01-28 22:04:14 -0800 | [diff] [blame] | 8745 | public interface OnHardKeyboardStatusChangeListener { |
| 8746 | public void onHardKeyboardStatusChange(boolean available, boolean enabled); |
| 8747 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8748 | } |