The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2007 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package com.android.server; |
| 18 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 19 | import static android.view.WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW; |
| 20 | import static android.view.WindowManager.LayoutParams.FIRST_SUB_WINDOW; |
| 21 | import static android.view.WindowManager.LayoutParams.FLAG_BLUR_BEHIND; |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 22 | import static android.view.WindowManager.LayoutParams.FLAG_COMPATIBLE_WINDOW; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 23 | import static android.view.WindowManager.LayoutParams.FLAG_DIM_BEHIND; |
| 24 | import static android.view.WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON; |
Mitsuru Oshima | d2967e2 | 2009-07-20 14:01:43 -0700 | [diff] [blame] | 25 | import static android.view.WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 26 | import static android.view.WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE; |
| 27 | import static android.view.WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 28 | import static android.view.WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 29 | import static android.view.WindowManager.LayoutParams.LAST_APPLICATION_WINDOW; |
| 30 | import static android.view.WindowManager.LayoutParams.LAST_SUB_WINDOW; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 31 | import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_STARTING; |
| 32 | import static android.view.WindowManager.LayoutParams.TYPE_BASE_APPLICATION; |
| 33 | import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD; |
| 34 | import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 35 | import static android.view.WindowManager.LayoutParams.TYPE_WALLPAPER; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 36 | |
| 37 | import com.android.internal.app.IBatteryStats; |
| 38 | import com.android.internal.policy.PolicyManager; |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 39 | import com.android.internal.policy.impl.PhoneWindowManager; |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 40 | import com.android.internal.view.BaseInputHandler; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 41 | import com.android.internal.view.IInputContext; |
| 42 | import com.android.internal.view.IInputMethodClient; |
| 43 | import com.android.internal.view.IInputMethodManager; |
Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 44 | import com.android.internal.view.WindowManagerPolicyThread; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 45 | import com.android.server.am.BatteryStatsService; |
| 46 | |
| 47 | import android.Manifest; |
| 48 | import android.app.ActivityManagerNative; |
| 49 | import android.app.IActivityManager; |
Jim Miller | d6b5705 | 2010-06-07 17:52:42 -0700 | [diff] [blame] | 50 | import android.app.admin.DevicePolicyManager; |
Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 51 | import android.content.BroadcastReceiver; |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 52 | import android.content.ClipData; |
| 53 | import android.content.ClipDescription; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 54 | import android.content.Context; |
Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 55 | import android.content.Intent; |
| 56 | import android.content.IntentFilter; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 57 | import android.content.pm.ActivityInfo; |
| 58 | import android.content.pm.PackageManager; |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 59 | import android.content.res.CompatibilityInfo; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 60 | import android.content.res.Configuration; |
Dianne Hackborn | 1c24e95 | 2010-11-23 00:34:30 -0800 | [diff] [blame] | 61 | import android.content.res.Resources; |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 62 | import android.graphics.Bitmap; |
Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 63 | import android.graphics.Canvas; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 64 | import android.graphics.Matrix; |
Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 65 | import android.graphics.Paint; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 66 | import android.graphics.PixelFormat; |
Dianne Hackborn | ed7bfbf | 2010-11-05 13:08:35 -0700 | [diff] [blame] | 67 | import android.graphics.PorterDuff; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 68 | import android.graphics.Rect; |
| 69 | import android.graphics.Region; |
Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 70 | import android.graphics.Typeface; |
| 71 | import android.graphics.Paint.FontMetricsInt; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 72 | import android.os.BatteryStats; |
| 73 | import android.os.Binder; |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 74 | import android.os.Bundle; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 75 | import android.os.Debug; |
| 76 | import android.os.Handler; |
| 77 | import android.os.IBinder; |
| 78 | import android.os.LocalPowerManager; |
| 79 | import android.os.Looper; |
| 80 | import android.os.Message; |
| 81 | import android.os.Parcel; |
| 82 | import android.os.ParcelFileDescriptor; |
| 83 | import android.os.Power; |
| 84 | import android.os.PowerManager; |
| 85 | import android.os.Process; |
| 86 | import android.os.RemoteException; |
| 87 | import android.os.ServiceManager; |
Brad Fitzpatrick | ec062f6 | 2010-11-03 09:56:54 -0700 | [diff] [blame] | 88 | import android.os.StrictMode; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 89 | import android.os.SystemClock; |
| 90 | import android.os.SystemProperties; |
| 91 | import android.os.TokenWatcher; |
| 92 | import android.provider.Settings; |
Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 93 | import android.util.DisplayMetrics; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 94 | import android.util.EventLog; |
Jim Miller | d6b5705 | 2010-06-07 17:52:42 -0700 | [diff] [blame] | 95 | import android.util.Log; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 96 | import android.util.Slog; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 97 | import android.util.SparseIntArray; |
Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 98 | import android.util.TypedValue; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 99 | import android.view.Display; |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 100 | import android.view.DragEvent; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 101 | import android.view.Gravity; |
| 102 | import android.view.IApplicationToken; |
| 103 | import android.view.IOnKeyguardExitResult; |
| 104 | import android.view.IRotationWatcher; |
| 105 | import android.view.IWindow; |
| 106 | import android.view.IWindowManager; |
| 107 | import android.view.IWindowSession; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 108 | import android.view.InputChannel; |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 109 | import android.view.InputDevice; |
Jeff Brown | bbda99d | 2010-07-28 15:48:59 -0700 | [diff] [blame] | 110 | import android.view.InputEvent; |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 111 | import android.view.InputHandler; |
| 112 | import android.view.InputQueue; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 113 | import android.view.KeyEvent; |
| 114 | import android.view.MotionEvent; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 115 | import android.view.Surface; |
| 116 | import android.view.SurfaceSession; |
| 117 | import android.view.View; |
| 118 | import android.view.ViewTreeObserver; |
| 119 | import android.view.WindowManager; |
| 120 | import android.view.WindowManagerImpl; |
| 121 | import android.view.WindowManagerPolicy; |
Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 122 | import android.view.Surface.OutOfResourcesException; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 123 | import android.view.WindowManager.LayoutParams; |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 124 | import android.view.animation.AccelerateInterpolator; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 125 | import android.view.animation.Animation; |
| 126 | import android.view.animation.AnimationUtils; |
| 127 | import android.view.animation.Transformation; |
| 128 | |
| 129 | import java.io.BufferedWriter; |
Dianne Hackborn | b9fb170 | 2010-08-23 16:49:02 -0700 | [diff] [blame] | 130 | import java.io.DataInputStream; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 131 | import java.io.File; |
| 132 | import java.io.FileDescriptor; |
Dianne Hackborn | b9fb170 | 2010-08-23 16:49:02 -0700 | [diff] [blame] | 133 | import java.io.FileInputStream; |
| 134 | import java.io.FileNotFoundException; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 135 | import java.io.IOException; |
| 136 | import java.io.OutputStream; |
| 137 | import java.io.OutputStreamWriter; |
| 138 | import java.io.PrintWriter; |
| 139 | import java.io.StringWriter; |
| 140 | import java.net.Socket; |
| 141 | import java.util.ArrayList; |
| 142 | import java.util.HashMap; |
| 143 | import java.util.HashSet; |
| 144 | import java.util.Iterator; |
| 145 | import java.util.List; |
| 146 | |
| 147 | /** {@hide} */ |
Dianne Hackborn | ddca3ee | 2009-07-23 19:01:31 -0700 | [diff] [blame] | 148 | public class WindowManagerService extends IWindowManager.Stub |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 149 | implements Watchdog.Monitor { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 150 | static final String TAG = "WindowManager"; |
| 151 | static final boolean DEBUG = false; |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 152 | static final boolean DEBUG_ADD_REMOVE = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 153 | static final boolean DEBUG_FOCUS = false; |
| 154 | static final boolean DEBUG_ANIM = false; |
Dianne Hackborn | 9b52a21 | 2009-12-11 14:51:35 -0800 | [diff] [blame] | 155 | static final boolean DEBUG_LAYOUT = false; |
Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 156 | static final boolean DEBUG_RESIZE = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 157 | static final boolean DEBUG_LAYERS = false; |
| 158 | static final boolean DEBUG_INPUT = false; |
| 159 | static final boolean DEBUG_INPUT_METHOD = false; |
| 160 | static final boolean DEBUG_VISIBILITY = false; |
Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 161 | static final boolean DEBUG_WINDOW_MOVEMENT = false; |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 162 | static final boolean DEBUG_TOKEN_MOVEMENT = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 163 | static final boolean DEBUG_ORIENTATION = false; |
Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 164 | static final boolean DEBUG_CONFIGURATION = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 165 | static final boolean DEBUG_APP_TRANSITIONS = false; |
| 166 | static final boolean DEBUG_STARTING_WINDOW = false; |
| 167 | static final boolean DEBUG_REORDER = false; |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 168 | static final boolean DEBUG_WALLPAPER = false; |
Christopher Tate | 994ef92 | 2011-01-12 20:06:07 -0800 | [diff] [blame] | 169 | static final boolean DEBUG_DRAG = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 170 | static final boolean SHOW_TRANSACTIONS = false; |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 171 | static final boolean HIDE_STACK_CRAWLS = true; |
Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 172 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 173 | static final boolean PROFILE_ORIENTATION = false; |
| 174 | static final boolean BLUR = true; |
Dave Bort | cfe6524 | 2009-04-09 14:51:04 -0700 | [diff] [blame] | 175 | static final boolean localLOGV = DEBUG; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 176 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 177 | /** How much to multiply the policy's type layer, to reserve room |
| 178 | * for multiple windows of the same type and Z-ordering adjustment |
| 179 | * with TYPE_LAYER_OFFSET. */ |
| 180 | static final int TYPE_LAYER_MULTIPLIER = 10000; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 181 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 182 | /** Offset from TYPE_LAYER_MULTIPLIER for moving a group of windows above |
| 183 | * or below others in the same layer. */ |
| 184 | static final int TYPE_LAYER_OFFSET = 1000; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 185 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 186 | /** How much to increment the layer for each window, to reserve room |
| 187 | * for effect surfaces between them. |
| 188 | */ |
| 189 | static final int WINDOW_LAYER_MULTIPLIER = 5; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 190 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 191 | /** The maximum length we will accept for a loaded animation duration: |
| 192 | * this is 10 seconds. |
| 193 | */ |
| 194 | static final int MAX_ANIMATION_DURATION = 10*1000; |
| 195 | |
| 196 | /** Amount of time (in milliseconds) to animate the dim surface from one |
| 197 | * value to another, when no window animation is driving it. |
| 198 | */ |
| 199 | static final int DEFAULT_DIM_DURATION = 200; |
| 200 | |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 201 | /** Amount of time (in milliseconds) to animate the fade-in-out transition for |
| 202 | * compatible windows. |
| 203 | */ |
| 204 | static final int DEFAULT_FADE_IN_OUT_DURATION = 400; |
| 205 | |
Dianne Hackborn | a111187 | 2010-11-23 20:55:11 -0800 | [diff] [blame] | 206 | /** |
| 207 | * If true, the window manager will do its own custom freezing and general |
| 208 | * management of the screen during rotation. |
| 209 | */ |
| 210 | static final boolean CUSTOM_SCREEN_ROTATION = true; |
| 211 | |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 212 | // Maximum number of milliseconds to wait for input event injection. |
| 213 | // FIXME is this value reasonable? |
| 214 | private static final int INJECTION_TIMEOUT_MILLIS = 30 * 1000; |
Jeff Brown | b09abc1 | 2011-01-13 21:08:27 -0800 | [diff] [blame] | 215 | |
| 216 | // Maximum number of milliseconds to wait for input devices to be enumerated before |
| 217 | // proceding with safe mode detection. |
| 218 | 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] | 219 | |
| 220 | // Default input dispatching timeout in nanoseconds. |
| 221 | private static final long DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS = 5000 * 1000000L; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 222 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 223 | static final int UPDATE_FOCUS_NORMAL = 0; |
| 224 | static final int UPDATE_FOCUS_WILL_ASSIGN_LAYERS = 1; |
| 225 | static final int UPDATE_FOCUS_PLACING_SURFACES = 2; |
| 226 | static final int UPDATE_FOCUS_WILL_PLACE_SURFACES = 3; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 227 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 228 | private static final String SYSTEM_SECURE = "ro.secure"; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 229 | private static final String SYSTEM_DEBUGGABLE = "ro.debuggable"; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 230 | |
| 231 | /** |
| 232 | * Condition waited on by {@link #reenableKeyguard} to know the call to |
| 233 | * the window policy has finished. |
Mike Lockwood | 983ee09 | 2009-11-22 01:42:24 -0500 | [diff] [blame] | 234 | * This is set to true only if mKeyguardTokenWatcher.acquired() has |
| 235 | * actually disabled the keyguard. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 236 | */ |
Mike Lockwood | 983ee09 | 2009-11-22 01:42:24 -0500 | [diff] [blame] | 237 | private boolean mKeyguardDisabled = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 238 | |
Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 239 | private static final int ALLOW_DISABLE_YES = 1; |
| 240 | private static final int ALLOW_DISABLE_NO = 0; |
| 241 | private static final int ALLOW_DISABLE_UNKNOWN = -1; // check with DevicePolicyManager |
| 242 | private int mAllowDisableKeyguard = ALLOW_DISABLE_UNKNOWN; // sync'd by mKeyguardTokenWatcher |
| 243 | |
Mike Lockwood | 983ee09 | 2009-11-22 01:42:24 -0500 | [diff] [blame] | 244 | final TokenWatcher mKeyguardTokenWatcher = new TokenWatcher( |
| 245 | new Handler(), "WindowManagerService.mKeyguardTokenWatcher") { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 246 | public void acquired() { |
Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 247 | if (shouldAllowDisableKeyguard()) { |
| 248 | mPolicy.enableKeyguard(false); |
| 249 | mKeyguardDisabled = true; |
| 250 | } else { |
| 251 | Log.v(TAG, "Not disabling keyguard since device policy is enforced"); |
| 252 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 253 | } |
| 254 | public void released() { |
Dianne Hackborn | a33e3f7 | 2009-09-29 17:28:24 -0700 | [diff] [blame] | 255 | mPolicy.enableKeyguard(true); |
Mike Lockwood | 983ee09 | 2009-11-22 01:42:24 -0500 | [diff] [blame] | 256 | synchronized (mKeyguardTokenWatcher) { |
| 257 | mKeyguardDisabled = false; |
| 258 | mKeyguardTokenWatcher.notifyAll(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 259 | } |
| 260 | } |
| 261 | }; |
| 262 | |
Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 263 | final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() { |
| 264 | @Override |
| 265 | public void onReceive(Context context, Intent intent) { |
| 266 | mPolicy.enableKeyguard(true); |
| 267 | synchronized(mKeyguardTokenWatcher) { |
| 268 | // lazily evaluate this next time we're asked to disable keyguard |
| 269 | mAllowDisableKeyguard = ALLOW_DISABLE_UNKNOWN; |
| 270 | mKeyguardDisabled = false; |
| 271 | } |
| 272 | } |
| 273 | }; |
| 274 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 275 | final Context mContext; |
| 276 | |
| 277 | final boolean mHaveInputMethods; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 278 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 279 | final boolean mLimitedAlphaCompositing; |
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 WindowManagerPolicy mPolicy = PolicyManager.makeNewWindowManager(); |
| 282 | |
| 283 | final IActivityManager mActivityManager; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 284 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 285 | final IBatteryStats mBatteryStats; |
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 | /** |
| 288 | * All currently active sessions with clients. |
| 289 | */ |
| 290 | final HashSet<Session> mSessions = new HashSet<Session>(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 291 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 292 | /** |
| 293 | * Mapping from an IWindow IBinder to the server's Window object. |
| 294 | * This is also used as the lock for all of our state. |
| 295 | */ |
| 296 | final HashMap<IBinder, WindowState> mWindowMap = new HashMap<IBinder, WindowState>(); |
| 297 | |
| 298 | /** |
| 299 | * Mapping from a token IBinder to a WindowToken object. |
| 300 | */ |
| 301 | final HashMap<IBinder, WindowToken> mTokenMap = |
| 302 | new HashMap<IBinder, WindowToken>(); |
| 303 | |
| 304 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 305 | * Window tokens that are in the process of exiting, but still |
| 306 | * on screen for animations. |
| 307 | */ |
| 308 | final ArrayList<WindowToken> mExitingTokens = new ArrayList<WindowToken>(); |
| 309 | |
| 310 | /** |
| 311 | * Z-ordered (bottom-most first) list of all application tokens, for |
| 312 | * controlling the ordering of windows in different applications. This |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 313 | * contains AppWindowToken objects. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 314 | */ |
| 315 | final ArrayList<AppWindowToken> mAppTokens = new ArrayList<AppWindowToken>(); |
| 316 | |
| 317 | /** |
| 318 | * Application tokens that are in the process of exiting, but still |
| 319 | * on screen for animations. |
| 320 | */ |
| 321 | final ArrayList<AppWindowToken> mExitingAppTokens = new ArrayList<AppWindowToken>(); |
| 322 | |
| 323 | /** |
| 324 | * List of window tokens that have finished starting their application, |
| 325 | * and now need to have the policy remove their windows. |
| 326 | */ |
| 327 | final ArrayList<AppWindowToken> mFinishedStarting = new ArrayList<AppWindowToken>(); |
| 328 | |
| 329 | /** |
| 330 | * Z-ordered (bottom-most first) list of all Window objects. |
| 331 | */ |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 332 | final ArrayList<WindowState> mWindows = new ArrayList<WindowState>(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 333 | |
| 334 | /** |
| 335 | * Windows that are being resized. Used so we can tell the client about |
| 336 | * the resize after closing the transaction in which we resized the |
| 337 | * underlying surface. |
| 338 | */ |
| 339 | final ArrayList<WindowState> mResizingWindows = new ArrayList<WindowState>(); |
| 340 | |
| 341 | /** |
| 342 | * Windows whose animations have ended and now must be removed. |
| 343 | */ |
| 344 | final ArrayList<WindowState> mPendingRemove = new ArrayList<WindowState>(); |
| 345 | |
| 346 | /** |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 347 | * Used when processing mPendingRemove to avoid working on the original array. |
| 348 | */ |
| 349 | WindowState[] mPendingRemoveTmp = new WindowState[20]; |
| 350 | |
| 351 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 352 | * Windows whose surface should be destroyed. |
| 353 | */ |
| 354 | final ArrayList<WindowState> mDestroySurface = new ArrayList<WindowState>(); |
| 355 | |
| 356 | /** |
| 357 | * Windows that have lost input focus and are waiting for the new |
| 358 | * focus window to be displayed before they are told about this. |
| 359 | */ |
| 360 | ArrayList<WindowState> mLosingFocus = new ArrayList<WindowState>(); |
| 361 | |
| 362 | /** |
| 363 | * This is set when we have run out of memory, and will either be an empty |
| 364 | * list or contain windows that need to be force removed. |
| 365 | */ |
| 366 | ArrayList<WindowState> mForceRemoves; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 367 | |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 368 | /** |
| 369 | * Used when rebuilding window list to keep track of windows that have |
| 370 | * been removed. |
| 371 | */ |
| 372 | WindowState[] mRebuildTmp = new WindowState[20]; |
| 373 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 374 | IInputMethodManager mInputMethodManager; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 375 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 376 | SurfaceSession mFxSession; |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 377 | private DimAnimator mDimAnimator = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 378 | Surface mBlurSurface; |
| 379 | boolean mBlurShown; |
Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 380 | Watermark mWatermark; |
Brad Fitzpatrick | 6804433 | 2010-11-22 18:19:48 -0800 | [diff] [blame] | 381 | StrictModeFlash mStrictModeFlash; |
Dianne Hackborn | a111187 | 2010-11-23 20:55:11 -0800 | [diff] [blame] | 382 | ScreenRotationAnimation mScreenRotationAnimation; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 383 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 384 | int mTransactionSequence = 0; |
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 | final float[] mTmpFloats = new float[9]; |
| 387 | |
| 388 | boolean mSafeMode; |
| 389 | boolean mDisplayEnabled = false; |
| 390 | boolean mSystemBooted = false; |
Christopher Tate | b696aee | 2010-04-02 19:08:30 -0700 | [diff] [blame] | 391 | int mInitialDisplayWidth = 0; |
| 392 | int mInitialDisplayHeight = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 393 | int mRotation = 0; |
| 394 | int mRequestedRotation = 0; |
| 395 | int mForcedAppOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
Dianne Hackborn | 321ae68 | 2009-03-27 16:16:03 -0700 | [diff] [blame] | 396 | int mLastRotationFlags; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 397 | ArrayList<IRotationWatcher> mRotationWatchers |
| 398 | = new ArrayList<IRotationWatcher>(); |
Dianne Hackborn | 89ba675 | 2011-01-23 16:51:16 -0800 | [diff] [blame] | 399 | int mDeferredRotation; |
| 400 | int mDeferredRotationAnimFlags; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 401 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 402 | boolean mLayoutNeeded = true; |
| 403 | boolean mAnimationPending = false; |
| 404 | boolean mDisplayFrozen = false; |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 405 | boolean mWaitingForConfig = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 406 | boolean mWindowsFreezingScreen = false; |
| 407 | long mFreezeGcPending = 0; |
| 408 | int mAppsFreezingScreen = 0; |
| 409 | |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 410 | int mLayoutSeq = 0; |
| 411 | |
Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 412 | // State while inside of layoutAndPlaceSurfacesLocked(). |
| 413 | boolean mFocusMayChange; |
| 414 | |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 415 | Configuration mCurConfiguration = new Configuration(); |
| 416 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 417 | // This is held as long as we have the screen frozen, to give us time to |
| 418 | // perform a rotation animation when turning off shows the lock screen which |
| 419 | // changes the orientation. |
| 420 | PowerManager.WakeLock mScreenFrozenLock; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 421 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 422 | // State management of app transitions. When we are preparing for a |
| 423 | // transition, mNextAppTransition will be the kind of transition to |
| 424 | // perform or TRANSIT_NONE if we are not waiting. If we are waiting, |
| 425 | // mOpeningApps and mClosingApps are the lists of tokens that will be |
| 426 | // made visible or hidden at the next transition. |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 427 | int mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 428 | String mNextAppTransitionPackage; |
| 429 | int mNextAppTransitionEnter; |
| 430 | int mNextAppTransitionExit; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 431 | boolean mAppTransitionReady = false; |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 432 | boolean mAppTransitionRunning = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 433 | boolean mAppTransitionTimeout = false; |
| 434 | boolean mStartingIconInTransition = false; |
| 435 | boolean mSkipAppTransitionAnimation = false; |
| 436 | final ArrayList<AppWindowToken> mOpeningApps = new ArrayList<AppWindowToken>(); |
| 437 | final ArrayList<AppWindowToken> mClosingApps = new ArrayList<AppWindowToken>(); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 438 | final ArrayList<AppWindowToken> mToTopApps = new ArrayList<AppWindowToken>(); |
| 439 | final ArrayList<AppWindowToken> mToBottomApps = new ArrayList<AppWindowToken>(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 440 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 441 | Display mDisplay; |
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 | H mH = new H(); |
| 444 | |
| 445 | WindowState mCurrentFocus = null; |
| 446 | WindowState mLastFocus = null; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 447 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 448 | // This just indicates the window the input method is on top of, not |
| 449 | // necessarily the window its input is going to. |
| 450 | WindowState mInputMethodTarget = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 451 | boolean mInputMethodTargetWaitingAnim; |
| 452 | int mInputMethodAnimLayerAdjustment; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 453 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 454 | WindowState mInputMethodWindow = null; |
| 455 | final ArrayList<WindowState> mInputMethodDialogs = new ArrayList<WindowState>(); |
| 456 | |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 457 | final ArrayList<WindowToken> mWallpaperTokens = new ArrayList<WindowToken>(); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 458 | |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 459 | // If non-null, this is the currently visible window that is associated |
| 460 | // with the wallpaper. |
| 461 | WindowState mWallpaperTarget = null; |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 462 | // If non-null, we are in the middle of animating from one wallpaper target |
| 463 | // to another, and this is the lower one in Z-order. |
| 464 | WindowState mLowerWallpaperTarget = null; |
| 465 | // If non-null, we are in the middle of animating from one wallpaper target |
| 466 | // to another, and this is the higher one in Z-order. |
| 467 | WindowState mUpperWallpaperTarget = null; |
Dianne Hackborn | 6c8e20f | 2010-11-09 18:59:09 -0800 | [diff] [blame] | 468 | // Window currently running an animation that has requested it be detached |
| 469 | // from the wallpaper. This means we need to ensure the wallpaper is |
| 470 | // visible behind it in case it animates in a way that would allow it to be |
| 471 | // seen. |
| 472 | WindowState mWindowDetachedWallpaper = null; |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 473 | int mWallpaperAnimLayerAdjustment; |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 474 | float mLastWallpaperX = -1; |
| 475 | float mLastWallpaperY = -1; |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 476 | float mLastWallpaperXStep = -1; |
| 477 | float mLastWallpaperYStep = -1; |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 478 | // This is set when we are waiting for a wallpaper to tell us it is done |
| 479 | // changing its scroll position. |
| 480 | WindowState mWaitingOnWallpaper; |
| 481 | // The last time we had a timeout when waiting for a wallpaper. |
| 482 | long mLastWallpaperTimeoutTime; |
| 483 | // We give a wallpaper up to 150ms to finish scrolling. |
| 484 | static final long WALLPAPER_TIMEOUT = 150; |
| 485 | // Time we wait after a timeout before trying to wait again. |
| 486 | static final long WALLPAPER_TIMEOUT_RECOVERY = 10000; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 487 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 488 | AppWindowToken mFocusedApp = null; |
| 489 | |
| 490 | PowerManagerService mPowerManager; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 491 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 492 | float mWindowAnimationScale = 1.0f; |
| 493 | float mTransitionAnimationScale = 1.0f; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 494 | |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 495 | final InputManager mInputManager; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 496 | |
| 497 | // Who is holding the screen on. |
| 498 | Session mHoldingScreenOn; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 499 | PowerManager.WakeLock mHoldingScreenWakeLock; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 500 | |
Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 501 | boolean mTurnOnScreen; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 502 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 503 | /** |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 504 | * Drag/drop state |
| 505 | */ |
| 506 | class DragState { |
| 507 | IBinder mToken; |
| 508 | Surface mSurface; |
Christopher Tate | 02d2b3b | 2011-01-10 20:43:53 -0800 | [diff] [blame] | 509 | int mFlags; |
Chris Tate | 7b362e4 | 2010-11-04 16:02:52 -0700 | [diff] [blame] | 510 | IBinder mLocalWin; |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 511 | ClipData mData; |
| 512 | ClipDescription mDataDescription; |
Chris Tate | d4533f14 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 513 | boolean mDragResult; |
Chris Tate | b478f46 | 2010-10-15 16:02:26 -0700 | [diff] [blame] | 514 | float mCurrentX, mCurrentY; |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 515 | float mThumbOffsetX, mThumbOffsetY; |
| 516 | InputChannel mServerChannel, mClientChannel; |
| 517 | WindowState mTargetWindow; |
| 518 | ArrayList<WindowState> mNotifiedWindows; |
Christopher Tate | 5ada6cb | 2010-10-05 14:15:29 -0700 | [diff] [blame] | 519 | boolean mDragInProgress; |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 520 | |
Jeff Brown | fbf0977 | 2011-01-16 14:06:57 -0800 | [diff] [blame] | 521 | private final Region mTmpRegion = new Region(); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 522 | |
Christopher Tate | 02d2b3b | 2011-01-10 20:43:53 -0800 | [diff] [blame] | 523 | DragState(IBinder token, Surface surface, int flags, IBinder localWin) { |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 524 | mToken = token; |
| 525 | mSurface = surface; |
Christopher Tate | 02d2b3b | 2011-01-10 20:43:53 -0800 | [diff] [blame] | 526 | mFlags = flags; |
Chris Tate | 7b362e4 | 2010-11-04 16:02:52 -0700 | [diff] [blame] | 527 | mLocalWin = localWin; |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 528 | mNotifiedWindows = new ArrayList<WindowState>(); |
| 529 | } |
| 530 | |
| 531 | void reset() { |
| 532 | if (mSurface != null) { |
| 533 | mSurface.destroy(); |
| 534 | } |
| 535 | mSurface = null; |
Christopher Tate | 02d2b3b | 2011-01-10 20:43:53 -0800 | [diff] [blame] | 536 | mFlags = 0; |
Chris Tate | 7b362e4 | 2010-11-04 16:02:52 -0700 | [diff] [blame] | 537 | mLocalWin = null; |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 538 | mToken = null; |
| 539 | mData = null; |
| 540 | mThumbOffsetX = mThumbOffsetY = 0; |
| 541 | mNotifiedWindows = null; |
| 542 | } |
| 543 | |
| 544 | void register() { |
| 545 | if (DEBUG_DRAG) Slog.d(TAG, "registering drag input channel"); |
| 546 | if (mClientChannel != null) { |
| 547 | Slog.e(TAG, "Duplicate register of drag input channel"); |
| 548 | } else { |
| 549 | InputChannel[] channels = InputChannel.openInputChannelPair("drag"); |
| 550 | mServerChannel = channels[0]; |
| 551 | mClientChannel = channels[1]; |
Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame] | 552 | mInputManager.registerInputChannel(mServerChannel, null); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 553 | InputQueue.registerInputChannel(mClientChannel, mDragInputHandler, |
| 554 | mH.getLooper().getQueue()); |
| 555 | } |
| 556 | } |
| 557 | |
| 558 | void unregister() { |
| 559 | if (DEBUG_DRAG) Slog.d(TAG, "unregistering drag input channel"); |
| 560 | if (mClientChannel == null) { |
| 561 | Slog.e(TAG, "Unregister of nonexistent drag input channel"); |
| 562 | } else { |
| 563 | mInputManager.unregisterInputChannel(mServerChannel); |
| 564 | InputQueue.unregisterInputChannel(mClientChannel); |
| 565 | mClientChannel.dispose(); |
Chris Tate | ef70a07 | 2010-10-22 19:10:34 -0700 | [diff] [blame] | 566 | mServerChannel.dispose(); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 567 | mClientChannel = null; |
| 568 | mServerChannel = null; |
| 569 | } |
| 570 | } |
| 571 | |
Chris Tate | a32dcf7 | 2010-10-14 12:13:50 -0700 | [diff] [blame] | 572 | int getDragLayerLw() { |
| 573 | return mPolicy.windowTypeToLayerLw(WindowManager.LayoutParams.TYPE_DRAG) |
| 574 | * TYPE_LAYER_MULTIPLIER |
| 575 | + TYPE_LAYER_OFFSET; |
| 576 | } |
| 577 | |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 578 | /* call out to each visible window/session informing it about the drag |
| 579 | */ |
Chris Tate | b8203e9 | 2010-10-12 14:23:21 -0700 | [diff] [blame] | 580 | void broadcastDragStartedLw(final float touchX, final float touchY) { |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 581 | // Cache a base-class instance of the clip metadata so that parceling |
| 582 | // works correctly in calling out to the apps. |
Christopher Tate | 1fc014f | 2011-01-19 12:56:26 -0800 | [diff] [blame] | 583 | mDataDescription = (mData != null) ? mData.getDescription() : null; |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 584 | mNotifiedWindows.clear(); |
Christopher Tate | 5ada6cb | 2010-10-05 14:15:29 -0700 | [diff] [blame] | 585 | mDragInProgress = true; |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 586 | |
| 587 | if (DEBUG_DRAG) { |
Chris Tate | b478f46 | 2010-10-15 16:02:26 -0700 | [diff] [blame] | 588 | Slog.d(TAG, "broadcasting DRAG_STARTED at (" + touchX + ", " + touchY + ")"); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 589 | } |
| 590 | |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 591 | final int N = mWindows.size(); |
| 592 | for (int i = 0; i < N; i++) { |
Chris Tate | b478f46 | 2010-10-15 16:02:26 -0700 | [diff] [blame] | 593 | sendDragStartedLw(mWindows.get(i), touchX, touchY, mDataDescription); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 594 | } |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 595 | } |
| 596 | |
| 597 | /* helper - send a caller-provided event, presumed to be DRAG_STARTED, if the |
| 598 | * designated window is potentially a drop recipient. There are race situations |
| 599 | * around DRAG_ENDED broadcast, so we make sure that once we've declared that |
| 600 | * the drag has ended, we never send out another DRAG_STARTED for this drag action. |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 601 | * |
| 602 | * This method clones the 'event' parameter if it's being delivered to the same |
| 603 | * process, so it's safe for the caller to call recycle() on the event afterwards. |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 604 | */ |
Chris Tate | b478f46 | 2010-10-15 16:02:26 -0700 | [diff] [blame] | 605 | private void sendDragStartedLw(WindowState newWin, float touchX, float touchY, |
| 606 | ClipDescription desc) { |
Chris Tate | 7b362e4 | 2010-11-04 16:02:52 -0700 | [diff] [blame] | 607 | // Don't actually send the event if the drag is supposed to be pinned |
| 608 | // to the originating window but 'newWin' is not that window. |
Christopher Tate | 02d2b3b | 2011-01-10 20:43:53 -0800 | [diff] [blame] | 609 | if ((mFlags & View.DRAG_FLAG_GLOBAL) == 0) { |
Chris Tate | 7b362e4 | 2010-11-04 16:02:52 -0700 | [diff] [blame] | 610 | final IBinder winBinder = newWin.mClient.asBinder(); |
| 611 | if (winBinder != mLocalWin) { |
| 612 | if (DEBUG_DRAG) { |
| 613 | Slog.d(TAG, "Not dispatching local DRAG_STARTED to " + newWin); |
| 614 | } |
| 615 | return; |
| 616 | } |
| 617 | } |
| 618 | |
Christopher Tate | 5ada6cb | 2010-10-05 14:15:29 -0700 | [diff] [blame] | 619 | if (mDragInProgress && newWin.isPotentialDragTarget()) { |
Chris Tate | b478f46 | 2010-10-15 16:02:26 -0700 | [diff] [blame] | 620 | DragEvent event = DragEvent.obtain(DragEvent.ACTION_DRAG_STARTED, |
| 621 | touchX - newWin.mFrame.left, touchY - newWin.mFrame.top, |
Christopher Tate | 407b4e9 | 2010-11-30 17:14:08 -0800 | [diff] [blame] | 622 | null, desc, null, false); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 623 | try { |
| 624 | newWin.mClient.dispatchDragEvent(event); |
| 625 | // track each window that we've notified that the drag is starting |
| 626 | mNotifiedWindows.add(newWin); |
| 627 | } catch (RemoteException e) { |
| 628 | Slog.w(TAG, "Unable to drag-start window " + newWin); |
Chris Tate | b478f46 | 2010-10-15 16:02:26 -0700 | [diff] [blame] | 629 | } finally { |
| 630 | // if the callee was local, the dispatch has already recycled the event |
| 631 | if (Process.myPid() != newWin.mSession.mPid) { |
| 632 | event.recycle(); |
| 633 | } |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 634 | } |
| 635 | } |
| 636 | } |
| 637 | |
| 638 | /* helper - construct and send a DRAG_STARTED event only if the window has not |
| 639 | * previously been notified, i.e. it became visible after the drag operation |
| 640 | * was begun. This is a rare case. |
| 641 | */ |
| 642 | private void sendDragStartedIfNeededLw(WindowState newWin) { |
Christopher Tate | 5ada6cb | 2010-10-05 14:15:29 -0700 | [diff] [blame] | 643 | if (mDragInProgress) { |
| 644 | // If we have sent the drag-started, we needn't do so again |
| 645 | for (WindowState ws : mNotifiedWindows) { |
| 646 | if (ws == newWin) { |
| 647 | return; |
| 648 | } |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 649 | } |
Christopher Tate | 5ada6cb | 2010-10-05 14:15:29 -0700 | [diff] [blame] | 650 | if (DEBUG_DRAG) { |
Chris Tate | ef70a07 | 2010-10-22 19:10:34 -0700 | [diff] [blame] | 651 | Slog.d(TAG, "need to send DRAG_STARTED to new window " + newWin); |
Christopher Tate | 5ada6cb | 2010-10-05 14:15:29 -0700 | [diff] [blame] | 652 | } |
Chris Tate | b478f46 | 2010-10-15 16:02:26 -0700 | [diff] [blame] | 653 | sendDragStartedLw(newWin, mCurrentX, mCurrentY, mDataDescription); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 654 | } |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 655 | } |
| 656 | |
Chris Tate | d4533f14 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 657 | void broadcastDragEndedLw() { |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 658 | if (DEBUG_DRAG) { |
| 659 | Slog.d(TAG, "broadcasting DRAG_ENDED"); |
| 660 | } |
Chris Tate | d4533f14 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 661 | DragEvent evt = DragEvent.obtain(DragEvent.ACTION_DRAG_ENDED, |
Christopher Tate | 407b4e9 | 2010-11-30 17:14:08 -0800 | [diff] [blame] | 662 | 0, 0, null, null, null, mDragResult); |
Chris Tate | d4533f14 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 663 | for (WindowState ws: mNotifiedWindows) { |
| 664 | try { |
| 665 | ws.mClient.dispatchDragEvent(evt); |
| 666 | } catch (RemoteException e) { |
| 667 | Slog.w(TAG, "Unable to drag-end window " + ws); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 668 | } |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 669 | } |
Chris Tate | d4533f14 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 670 | mNotifiedWindows.clear(); |
| 671 | mDragInProgress = false; |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 672 | evt.recycle(); |
| 673 | } |
| 674 | |
Chris Tate | d4533f14 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 675 | void endDragLw() { |
| 676 | mDragState.broadcastDragEndedLw(); |
| 677 | |
| 678 | // stop intercepting input |
| 679 | mDragState.unregister(); |
Jeff Brown | 2e44b07 | 2011-01-24 15:21:56 -0800 | [diff] [blame^] | 680 | mInputMonitor.updateInputWindowsLw(true /*force*/); |
Chris Tate | d4533f14 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 681 | |
| 682 | // free our resources and drop all the object references |
| 683 | mDragState.reset(); |
| 684 | mDragState = null; |
Christopher Tate | ccd24de | 2011-01-12 15:02:55 -0800 | [diff] [blame] | 685 | |
Dianne Hackborn | 89ba675 | 2011-01-23 16:51:16 -0800 | [diff] [blame] | 686 | if (DEBUG_ORIENTATION) Slog.d(TAG, "Performing post-drag rotation"); |
| 687 | boolean changed = setRotationUncheckedLocked( |
| 688 | WindowManagerPolicy.USE_LAST_ROTATION, 0, false); |
| 689 | if (changed) { |
| 690 | sendNewConfiguration(); |
Christopher Tate | ccd24de | 2011-01-12 15:02:55 -0800 | [diff] [blame] | 691 | } |
Chris Tate | d4533f14 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 692 | } |
| 693 | |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 694 | void notifyMoveLw(float x, float y) { |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 695 | final int myPid = Process.myPid(); |
| 696 | |
| 697 | // Move the surface to the given touch |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 698 | if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION notifyMoveLw"); |
Christopher Tate | f01af75 | 2011-01-19 16:22:07 -0800 | [diff] [blame] | 699 | Surface.openTransaction(); |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 700 | try { |
| 701 | mSurface.setPosition((int)(x - mThumbOffsetX), (int)(y - mThumbOffsetY)); |
| 702 | } finally { |
Christopher Tate | f01af75 | 2011-01-19 16:22:07 -0800 | [diff] [blame] | 703 | Surface.closeTransaction(); |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 704 | if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION notifyMoveLw"); |
| 705 | } |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 706 | |
| 707 | // Tell the affected window |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 708 | WindowState touchedWin = getTouchedWinAtPointLw(x, y); |
Christopher Tate | f01af75 | 2011-01-19 16:22:07 -0800 | [diff] [blame] | 709 | if (touchedWin == null) { |
| 710 | if (DEBUG_DRAG) Slog.d(TAG, "No touched win at x=" + x + " y=" + y); |
| 711 | return; |
| 712 | } |
Christopher Tate | 02d2b3b | 2011-01-10 20:43:53 -0800 | [diff] [blame] | 713 | if ((mFlags & View.DRAG_FLAG_GLOBAL) == 0) { |
Chris Tate | 7b362e4 | 2010-11-04 16:02:52 -0700 | [diff] [blame] | 714 | final IBinder touchedBinder = touchedWin.mClient.asBinder(); |
| 715 | if (touchedBinder != mLocalWin) { |
| 716 | // This drag is pinned only to the originating window, but the drag |
| 717 | // point is outside that window. Pretend it's over empty space. |
| 718 | touchedWin = null; |
| 719 | } |
| 720 | } |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 721 | try { |
| 722 | // have we dragged over a new window? |
| 723 | if ((touchedWin != mTargetWindow) && (mTargetWindow != null)) { |
| 724 | if (DEBUG_DRAG) { |
| 725 | Slog.d(TAG, "sending DRAG_EXITED to " + mTargetWindow); |
| 726 | } |
| 727 | // force DRAG_EXITED_EVENT if appropriate |
| 728 | DragEvent evt = DragEvent.obtain(DragEvent.ACTION_DRAG_EXITED, |
Chris Tate | b478f46 | 2010-10-15 16:02:26 -0700 | [diff] [blame] | 729 | x - mTargetWindow.mFrame.left, y - mTargetWindow.mFrame.top, |
Christopher Tate | 407b4e9 | 2010-11-30 17:14:08 -0800 | [diff] [blame] | 730 | null, null, null, false); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 731 | mTargetWindow.mClient.dispatchDragEvent(evt); |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 732 | if (myPid != mTargetWindow.mSession.mPid) { |
| 733 | evt.recycle(); |
| 734 | } |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 735 | } |
| 736 | if (touchedWin != null) { |
Chris Tate | 9d1ab88 | 2010-11-02 15:55:39 -0700 | [diff] [blame] | 737 | if (false && DEBUG_DRAG) { |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 738 | Slog.d(TAG, "sending DRAG_LOCATION to " + touchedWin); |
| 739 | } |
| 740 | DragEvent evt = DragEvent.obtain(DragEvent.ACTION_DRAG_LOCATION, |
Chris Tate | b478f46 | 2010-10-15 16:02:26 -0700 | [diff] [blame] | 741 | x - touchedWin.mFrame.left, y - touchedWin.mFrame.top, |
Christopher Tate | 407b4e9 | 2010-11-30 17:14:08 -0800 | [diff] [blame] | 742 | null, null, null, false); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 743 | touchedWin.mClient.dispatchDragEvent(evt); |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 744 | if (myPid != touchedWin.mSession.mPid) { |
| 745 | evt.recycle(); |
| 746 | } |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 747 | } |
| 748 | } catch (RemoteException e) { |
| 749 | Slog.w(TAG, "can't send drag notification to windows"); |
| 750 | } |
| 751 | mTargetWindow = touchedWin; |
| 752 | } |
| 753 | |
Chris Tate | d4533f14 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 754 | // Tell the drop target about the data. Returns 'true' if we can immediately |
| 755 | // dispatch the global drag-ended message, 'false' if we need to wait for a |
| 756 | // result from the recipient. |
| 757 | boolean notifyDropLw(float x, float y) { |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 758 | WindowState touchedWin = getTouchedWinAtPointLw(x, y); |
Chris Tate | d4533f14 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 759 | if (touchedWin == null) { |
| 760 | // "drop" outside a valid window -- no recipient to apply a |
| 761 | // timeout to, and we can send the drag-ended message immediately. |
| 762 | mDragResult = false; |
| 763 | return true; |
| 764 | } |
| 765 | |
| 766 | if (DEBUG_DRAG) { |
| 767 | Slog.d(TAG, "sending DROP to " + touchedWin); |
| 768 | } |
| 769 | final int myPid = Process.myPid(); |
| 770 | final IBinder token = touchedWin.mClient.asBinder(); |
| 771 | DragEvent evt = DragEvent.obtain(DragEvent.ACTION_DROP, |
| 772 | x - touchedWin.mFrame.left, y - touchedWin.mFrame.top, |
Christopher Tate | 407b4e9 | 2010-11-30 17:14:08 -0800 | [diff] [blame] | 773 | null, null, mData, false); |
Chris Tate | d4533f14 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 774 | try { |
| 775 | touchedWin.mClient.dispatchDragEvent(evt); |
| 776 | |
| 777 | // 5 second timeout for this window to respond to the drop |
| 778 | mH.removeMessages(H.DRAG_END_TIMEOUT, token); |
| 779 | Message msg = mH.obtainMessage(H.DRAG_END_TIMEOUT, token); |
| 780 | mH.sendMessageDelayed(msg, 5000); |
| 781 | } catch (RemoteException e) { |
| 782 | Slog.w(TAG, "can't send drop notification to win " + touchedWin); |
| 783 | return true; |
| 784 | } finally { |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 785 | if (myPid != touchedWin.mSession.mPid) { |
| 786 | evt.recycle(); |
| 787 | } |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 788 | } |
Chris Tate | d4533f14 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 789 | mToken = token; |
| 790 | return false; |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 791 | } |
| 792 | |
| 793 | // Find the visible, touch-deliverable window under the given point |
| 794 | private WindowState getTouchedWinAtPointLw(float xf, float yf) { |
| 795 | WindowState touchedWin = null; |
| 796 | final int x = (int) xf; |
| 797 | final int y = (int) yf; |
| 798 | final ArrayList<WindowState> windows = mWindows; |
| 799 | final int N = windows.size(); |
| 800 | for (int i = N - 1; i >= 0; i--) { |
| 801 | WindowState child = windows.get(i); |
| 802 | final int flags = child.mAttrs.flags; |
| 803 | if (!child.isVisibleLw()) { |
| 804 | // not visible == don't tell about drags |
| 805 | continue; |
| 806 | } |
| 807 | if ((flags & WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE) != 0) { |
| 808 | // not touchable == don't tell about drags |
| 809 | continue; |
| 810 | } |
Jeff Brown | fbf0977 | 2011-01-16 14:06:57 -0800 | [diff] [blame] | 811 | |
| 812 | child.getTouchableRegion(mTmpRegion); |
| 813 | |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 814 | final int touchFlags = flags & |
Jeff Brown | fbf0977 | 2011-01-16 14:06:57 -0800 | [diff] [blame] | 815 | (WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE |
| 816 | | WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL); |
| 817 | if (mTmpRegion.contains(x, y) || touchFlags == 0) { |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 818 | // Found it |
| 819 | touchedWin = child; |
| 820 | break; |
| 821 | } |
| 822 | } |
| 823 | |
| 824 | return touchedWin; |
| 825 | } |
| 826 | } |
| 827 | |
| 828 | DragState mDragState = null; |
| 829 | private final InputHandler mDragInputHandler = new BaseInputHandler() { |
| 830 | @Override |
Jeff Brown | 3915bb8 | 2010-11-05 15:02:16 -0700 | [diff] [blame] | 831 | public void handleMotion(MotionEvent event, InputQueue.FinishedCallback finishedCallback) { |
| 832 | boolean handled = false; |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 833 | try { |
Jeff Brown | 3915bb8 | 2010-11-05 15:02:16 -0700 | [diff] [blame] | 834 | if ((event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0 |
| 835 | && mDragState != null) { |
| 836 | boolean endDrag = false; |
| 837 | final float newX = event.getRawX(); |
| 838 | final float newY = event.getRawY(); |
| 839 | |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 840 | switch (event.getAction()) { |
| 841 | case MotionEvent.ACTION_DOWN: { |
| 842 | if (DEBUG_DRAG) { |
| 843 | Slog.w(TAG, "Unexpected ACTION_DOWN in drag layer"); |
| 844 | } |
| 845 | } break; |
| 846 | |
| 847 | case MotionEvent.ACTION_MOVE: { |
| 848 | synchronized (mWindowMap) { |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 849 | // move the surface and tell the involved window(s) where we are |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 850 | mDragState.notifyMoveLw(newX, newY); |
| 851 | } |
| 852 | } break; |
| 853 | |
| 854 | case MotionEvent.ACTION_UP: { |
| 855 | if (DEBUG_DRAG) Slog.d(TAG, "Got UP on move channel; dropping at " |
| 856 | + newX + "," + newY); |
| 857 | synchronized (mWindowMap) { |
Chris Tate | d4533f14 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 858 | endDrag = mDragState.notifyDropLw(newX, newY); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 859 | } |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 860 | } break; |
| 861 | |
| 862 | case MotionEvent.ACTION_CANCEL: { |
| 863 | if (DEBUG_DRAG) Slog.d(TAG, "Drag cancelled!"); |
| 864 | endDrag = true; |
| 865 | } break; |
| 866 | } |
| 867 | |
| 868 | if (endDrag) { |
| 869 | if (DEBUG_DRAG) Slog.d(TAG, "Drag ended; tearing down state"); |
| 870 | // tell all the windows that the drag has ended |
Chris Tate | 5994359 | 2010-10-11 20:33:44 -0700 | [diff] [blame] | 871 | synchronized (mWindowMap) { |
Chris Tate | d4533f14 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 872 | mDragState.endDragLw(); |
Chris Tate | 5994359 | 2010-10-11 20:33:44 -0700 | [diff] [blame] | 873 | } |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 874 | } |
Jeff Brown | 3915bb8 | 2010-11-05 15:02:16 -0700 | [diff] [blame] | 875 | |
| 876 | handled = true; |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 877 | } |
| 878 | } catch (Exception e) { |
| 879 | Slog.e(TAG, "Exception caught by drag handleMotion", e); |
| 880 | } finally { |
Jeff Brown | 3915bb8 | 2010-11-05 15:02:16 -0700 | [diff] [blame] | 881 | finishedCallback.finished(handled); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 882 | } |
| 883 | } |
| 884 | }; |
| 885 | |
| 886 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 887 | * Whether the UI is currently running in touch mode (not showing |
| 888 | * navigational focus because the user is directly pressing the screen). |
| 889 | */ |
| 890 | boolean mInTouchMode = false; |
| 891 | |
| 892 | private ViewServer mViewServer; |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 893 | private ArrayList<WindowChangeListener> mWindowChangeListeners = |
| 894 | new ArrayList<WindowChangeListener>(); |
| 895 | private boolean mWindowsChanged = false; |
| 896 | |
| 897 | public interface WindowChangeListener { |
| 898 | public void windowsChanged(); |
Konstantin Lopyrev | 6e0f65f | 2010-07-14 14:55:33 -0700 | [diff] [blame] | 899 | public void focusChanged(); |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 900 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 901 | |
Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 902 | final Configuration mTempConfiguration = new Configuration(); |
Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 903 | int mScreenLayout = Configuration.SCREENLAYOUT_SIZE_UNDEFINED; |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 904 | |
| 905 | // The frame use to limit the size of the app running in compatibility mode. |
| 906 | Rect mCompatibleScreenFrame = new Rect(); |
| 907 | // The surface used to fill the outer rim of the app running in compatibility mode. |
| 908 | Surface mBackgroundFillerSurface = null; |
| 909 | boolean mBackgroundFillerShown = false; |
| 910 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 911 | public static WindowManagerService main(Context context, |
| 912 | PowerManagerService pm, boolean haveInputMethods) { |
| 913 | WMThread thr = new WMThread(context, pm, haveInputMethods); |
| 914 | thr.start(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 915 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 916 | synchronized (thr) { |
| 917 | while (thr.mService == null) { |
| 918 | try { |
| 919 | thr.wait(); |
| 920 | } catch (InterruptedException e) { |
| 921 | } |
| 922 | } |
| 923 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 924 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 925 | return thr.mService; |
| 926 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 927 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 928 | static class WMThread extends Thread { |
| 929 | WindowManagerService mService; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 930 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 931 | private final Context mContext; |
| 932 | private final PowerManagerService mPM; |
| 933 | private final boolean mHaveInputMethods; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 934 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 935 | public WMThread(Context context, PowerManagerService pm, |
| 936 | boolean haveInputMethods) { |
| 937 | super("WindowManager"); |
| 938 | mContext = context; |
| 939 | mPM = pm; |
| 940 | mHaveInputMethods = haveInputMethods; |
| 941 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 942 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 943 | public void run() { |
| 944 | Looper.prepare(); |
| 945 | WindowManagerService s = new WindowManagerService(mContext, mPM, |
| 946 | mHaveInputMethods); |
| 947 | android.os.Process.setThreadPriority( |
| 948 | android.os.Process.THREAD_PRIORITY_DISPLAY); |
Christopher Tate | 160edb3 | 2010-06-30 17:46:30 -0700 | [diff] [blame] | 949 | android.os.Process.setCanSelfBackground(false); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 950 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 951 | synchronized (this) { |
| 952 | mService = s; |
| 953 | notifyAll(); |
| 954 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 955 | |
Brad Fitzpatrick | ec062f6 | 2010-11-03 09:56:54 -0700 | [diff] [blame] | 956 | // For debug builds, log event loop stalls to dropbox for analysis. |
| 957 | if (StrictMode.conditionallyEnableDebugLogging()) { |
| 958 | Slog.i(TAG, "Enabled StrictMode logging for WMThread's Looper"); |
| 959 | } |
| 960 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 961 | Looper.loop(); |
| 962 | } |
| 963 | } |
| 964 | |
| 965 | static class PolicyThread extends Thread { |
| 966 | private final WindowManagerPolicy mPolicy; |
| 967 | private final WindowManagerService mService; |
| 968 | private final Context mContext; |
| 969 | private final PowerManagerService mPM; |
| 970 | boolean mRunning = false; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 971 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 972 | public PolicyThread(WindowManagerPolicy policy, |
| 973 | WindowManagerService service, Context context, |
| 974 | PowerManagerService pm) { |
| 975 | super("WindowManagerPolicy"); |
| 976 | mPolicy = policy; |
| 977 | mService = service; |
| 978 | mContext = context; |
| 979 | mPM = pm; |
| 980 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 981 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 982 | public void run() { |
| 983 | Looper.prepare(); |
Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 984 | WindowManagerPolicyThread.set(this, Looper.myLooper()); |
| 985 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 986 | //Looper.myLooper().setMessageLogging(new LogPrinter( |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 987 | // Log.VERBOSE, "WindowManagerPolicy", Log.LOG_ID_SYSTEM)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 988 | android.os.Process.setThreadPriority( |
| 989 | android.os.Process.THREAD_PRIORITY_FOREGROUND); |
Christopher Tate | 160edb3 | 2010-06-30 17:46:30 -0700 | [diff] [blame] | 990 | android.os.Process.setCanSelfBackground(false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 991 | mPolicy.init(mContext, mService, mPM); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 992 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 993 | synchronized (this) { |
| 994 | mRunning = true; |
| 995 | notifyAll(); |
| 996 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 997 | |
Brad Fitzpatrick | ec062f6 | 2010-11-03 09:56:54 -0700 | [diff] [blame] | 998 | // For debug builds, log event loop stalls to dropbox for analysis. |
| 999 | if (StrictMode.conditionallyEnableDebugLogging()) { |
| 1000 | Slog.i(TAG, "Enabled StrictMode for PolicyThread's Looper"); |
| 1001 | } |
| 1002 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1003 | Looper.loop(); |
| 1004 | } |
| 1005 | } |
| 1006 | |
| 1007 | private WindowManagerService(Context context, PowerManagerService pm, |
| 1008 | boolean haveInputMethods) { |
| 1009 | mContext = context; |
| 1010 | mHaveInputMethods = haveInputMethods; |
| 1011 | mLimitedAlphaCompositing = context.getResources().getBoolean( |
| 1012 | com.android.internal.R.bool.config_sf_limitedAlpha); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1013 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1014 | mPowerManager = pm; |
| 1015 | mPowerManager.setPolicy(mPolicy); |
| 1016 | PowerManager pmc = (PowerManager)context.getSystemService(Context.POWER_SERVICE); |
| 1017 | mScreenFrozenLock = pmc.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, |
| 1018 | "SCREEN_FROZEN"); |
| 1019 | mScreenFrozenLock.setReferenceCounted(false); |
| 1020 | |
| 1021 | mActivityManager = ActivityManagerNative.getDefault(); |
| 1022 | mBatteryStats = BatteryStatsService.getService(); |
| 1023 | |
| 1024 | // Get persisted window scale setting |
| 1025 | mWindowAnimationScale = Settings.System.getFloat(context.getContentResolver(), |
| 1026 | Settings.System.WINDOW_ANIMATION_SCALE, mWindowAnimationScale); |
| 1027 | mTransitionAnimationScale = Settings.System.getFloat(context.getContentResolver(), |
| 1028 | Settings.System.TRANSITION_ANIMATION_SCALE, mTransitionAnimationScale); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1029 | |
Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 1030 | // Track changes to DevicePolicyManager state so we can enable/disable keyguard. |
| 1031 | IntentFilter filter = new IntentFilter(); |
| 1032 | filter.addAction(DevicePolicyManager.ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED); |
| 1033 | mContext.registerReceiver(mBroadcastReceiver, filter); |
| 1034 | |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1035 | mHoldingScreenWakeLock = pmc.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK, |
| 1036 | "KEEP_SCREEN_ON_FLAG"); |
| 1037 | mHoldingScreenWakeLock.setReferenceCounted(false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1038 | |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1039 | mInputManager = new InputManager(context, this); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1040 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1041 | PolicyThread thr = new PolicyThread(mPolicy, this, context, pm); |
| 1042 | thr.start(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1043 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1044 | synchronized (thr) { |
| 1045 | while (!thr.mRunning) { |
| 1046 | try { |
| 1047 | thr.wait(); |
| 1048 | } catch (InterruptedException e) { |
| 1049 | } |
| 1050 | } |
| 1051 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1052 | |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 1053 | mInputManager.start(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1054 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1055 | // Add ourself to the Watchdog monitors. |
| 1056 | Watchdog.getInstance().addMonitor(this); |
| 1057 | } |
| 1058 | |
| 1059 | @Override |
| 1060 | public boolean onTransact(int code, Parcel data, Parcel reply, int flags) |
| 1061 | throws RemoteException { |
| 1062 | try { |
| 1063 | return super.onTransact(code, data, reply, flags); |
| 1064 | } catch (RuntimeException e) { |
| 1065 | // The window manager only throws security exceptions, so let's |
| 1066 | // log all others. |
| 1067 | if (!(e instanceof SecurityException)) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1068 | Slog.e(TAG, "Window Manager Crash", e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1069 | } |
| 1070 | throw e; |
| 1071 | } |
| 1072 | } |
| 1073 | |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1074 | private void placeWindowAfter(WindowState pos, WindowState window) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1075 | final int i = mWindows.indexOf(pos); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 1076 | 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] | 1077 | TAG, "Adding window " + window + " at " |
| 1078 | + (i+1) + " of " + mWindows.size() + " (after " + pos + ")"); |
| 1079 | mWindows.add(i+1, window); |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 1080 | mWindowsChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1081 | } |
| 1082 | |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1083 | private void placeWindowBefore(WindowState pos, WindowState window) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1084 | final int i = mWindows.indexOf(pos); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 1085 | 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] | 1086 | TAG, "Adding window " + window + " at " |
| 1087 | + i + " of " + mWindows.size() + " (before " + pos + ")"); |
| 1088 | mWindows.add(i, window); |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 1089 | mWindowsChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1090 | } |
| 1091 | |
| 1092 | //This method finds out the index of a window that has the same app token as |
| 1093 | //win. used for z ordering the windows in mWindows |
| 1094 | private int findIdxBasedOnAppTokens(WindowState win) { |
| 1095 | //use a local variable to cache mWindows |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1096 | ArrayList<WindowState> localmWindows = mWindows; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1097 | int jmax = localmWindows.size(); |
| 1098 | if(jmax == 0) { |
| 1099 | return -1; |
| 1100 | } |
| 1101 | for(int j = (jmax-1); j >= 0; j--) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1102 | WindowState wentry = localmWindows.get(j); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1103 | if(wentry.mAppToken == win.mAppToken) { |
| 1104 | return j; |
| 1105 | } |
| 1106 | } |
| 1107 | return -1; |
| 1108 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1109 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1110 | private void addWindowToListInOrderLocked(WindowState win, boolean addToToken) { |
| 1111 | final IWindow client = win.mClient; |
| 1112 | final WindowToken token = win.mToken; |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1113 | final ArrayList<WindowState> localmWindows = mWindows; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1114 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1115 | final int N = localmWindows.size(); |
| 1116 | final WindowState attached = win.mAttachedWindow; |
| 1117 | int i; |
| 1118 | if (attached == null) { |
| 1119 | int tokenWindowsPos = token.windows.size(); |
| 1120 | if (token.appWindowToken != null) { |
| 1121 | int index = tokenWindowsPos-1; |
| 1122 | if (index >= 0) { |
| 1123 | // If this application has existing windows, we |
| 1124 | // simply place the new window on top of them... but |
| 1125 | // keep the starting window on top. |
| 1126 | if (win.mAttrs.type == TYPE_BASE_APPLICATION) { |
| 1127 | // Base windows go behind everything else. |
| 1128 | placeWindowBefore(token.windows.get(0), win); |
| 1129 | tokenWindowsPos = 0; |
| 1130 | } else { |
| 1131 | AppWindowToken atoken = win.mAppToken; |
| 1132 | if (atoken != null && |
| 1133 | token.windows.get(index) == atoken.startingWindow) { |
| 1134 | placeWindowBefore(token.windows.get(index), win); |
| 1135 | tokenWindowsPos--; |
| 1136 | } else { |
| 1137 | int newIdx = findIdxBasedOnAppTokens(win); |
| 1138 | if(newIdx != -1) { |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1139 | //there is a window above this one associated with the same |
| 1140 | //apptoken note that the window could be a floating window |
| 1141 | //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] | 1142 | //windows associated with this token. |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 1143 | if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) { |
| 1144 | Slog.v(TAG, "Adding window " + win + " at " |
| 1145 | + (newIdx+1) + " of " + N); |
| 1146 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1147 | localmWindows.add(newIdx+1, win); |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 1148 | mWindowsChanged = true; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1149 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1150 | } |
| 1151 | } |
| 1152 | } else { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1153 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1154 | TAG, "Figuring out where to add app window " |
| 1155 | + client.asBinder() + " (token=" + token + ")"); |
| 1156 | // Figure out where the window should go, based on the |
| 1157 | // order of applications. |
| 1158 | final int NA = mAppTokens.size(); |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1159 | WindowState pos = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1160 | for (i=NA-1; i>=0; i--) { |
| 1161 | AppWindowToken t = mAppTokens.get(i); |
| 1162 | if (t == token) { |
| 1163 | i--; |
| 1164 | break; |
| 1165 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1166 | |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 1167 | // We haven't reached the token yet; if this token |
| 1168 | // is not going to the bottom and has windows, we can |
| 1169 | // use it as an anchor for when we do reach the token. |
| 1170 | if (!t.sendingToBottom && t.windows.size() > 0) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1171 | pos = t.windows.get(0); |
| 1172 | } |
| 1173 | } |
| 1174 | // We now know the index into the apps. If we found |
| 1175 | // an app window above, that gives us the position; else |
| 1176 | // we need to look some more. |
| 1177 | if (pos != null) { |
| 1178 | // Move behind any windows attached to this one. |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1179 | WindowToken atoken = mTokenMap.get(pos.mClient.asBinder()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1180 | if (atoken != null) { |
| 1181 | final int NC = atoken.windows.size(); |
| 1182 | if (NC > 0) { |
| 1183 | WindowState bottom = atoken.windows.get(0); |
| 1184 | if (bottom.mSubLayer < 0) { |
| 1185 | pos = bottom; |
| 1186 | } |
| 1187 | } |
| 1188 | } |
| 1189 | placeWindowBefore(pos, win); |
| 1190 | } else { |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 1191 | // Continue looking down until we find the first |
| 1192 | // token that has windows. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1193 | while (i >= 0) { |
| 1194 | AppWindowToken t = mAppTokens.get(i); |
| 1195 | final int NW = t.windows.size(); |
| 1196 | if (NW > 0) { |
| 1197 | pos = t.windows.get(NW-1); |
| 1198 | break; |
| 1199 | } |
| 1200 | i--; |
| 1201 | } |
| 1202 | if (pos != null) { |
| 1203 | // Move in front of any windows attached to this |
| 1204 | // one. |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1205 | WindowToken atoken = mTokenMap.get(pos.mClient.asBinder()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1206 | if (atoken != null) { |
| 1207 | final int NC = atoken.windows.size(); |
| 1208 | if (NC > 0) { |
| 1209 | WindowState top = atoken.windows.get(NC-1); |
| 1210 | if (top.mSubLayer >= 0) { |
| 1211 | pos = top; |
| 1212 | } |
| 1213 | } |
| 1214 | } |
| 1215 | placeWindowAfter(pos, win); |
| 1216 | } else { |
| 1217 | // Just search for the start of this layer. |
| 1218 | final int myLayer = win.mBaseLayer; |
| 1219 | for (i=0; i<N; i++) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1220 | WindowState w = localmWindows.get(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1221 | if (w.mBaseLayer > myLayer) { |
| 1222 | break; |
| 1223 | } |
| 1224 | } |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 1225 | if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) { |
| 1226 | Slog.v(TAG, "Adding window " + win + " at " |
| 1227 | + i + " of " + N); |
| 1228 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1229 | localmWindows.add(i, win); |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 1230 | mWindowsChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1231 | } |
| 1232 | } |
| 1233 | } |
| 1234 | } else { |
| 1235 | // Figure out where window should go, based on layer. |
| 1236 | final int myLayer = win.mBaseLayer; |
| 1237 | for (i=N-1; i>=0; i--) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1238 | if (localmWindows.get(i).mBaseLayer <= myLayer) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1239 | i++; |
| 1240 | break; |
| 1241 | } |
| 1242 | } |
| 1243 | if (i < 0) i = 0; |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 1244 | if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) Slog.v( |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 1245 | TAG, "Adding window " + win + " at " |
| 1246 | + i + " of " + N); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1247 | localmWindows.add(i, win); |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 1248 | mWindowsChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1249 | } |
| 1250 | if (addToToken) { |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 1251 | 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] | 1252 | token.windows.add(tokenWindowsPos, win); |
| 1253 | } |
| 1254 | |
| 1255 | } else { |
| 1256 | // Figure out this window's ordering relative to the window |
| 1257 | // it is attached to. |
| 1258 | final int NA = token.windows.size(); |
| 1259 | final int sublayer = win.mSubLayer; |
| 1260 | int largestSublayer = Integer.MIN_VALUE; |
| 1261 | WindowState windowWithLargestSublayer = null; |
| 1262 | for (i=0; i<NA; i++) { |
| 1263 | WindowState w = token.windows.get(i); |
| 1264 | final int wSublayer = w.mSubLayer; |
| 1265 | if (wSublayer >= largestSublayer) { |
| 1266 | largestSublayer = wSublayer; |
| 1267 | windowWithLargestSublayer = w; |
| 1268 | } |
| 1269 | if (sublayer < 0) { |
| 1270 | // For negative sublayers, we go below all windows |
| 1271 | // in the same sublayer. |
| 1272 | if (wSublayer >= sublayer) { |
| 1273 | if (addToToken) { |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 1274 | 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] | 1275 | token.windows.add(i, win); |
| 1276 | } |
| 1277 | placeWindowBefore( |
| 1278 | wSublayer >= 0 ? attached : w, win); |
| 1279 | break; |
| 1280 | } |
| 1281 | } else { |
| 1282 | // For positive sublayers, we go above all windows |
| 1283 | // in the same sublayer. |
| 1284 | if (wSublayer > sublayer) { |
| 1285 | if (addToToken) { |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 1286 | 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] | 1287 | token.windows.add(i, win); |
| 1288 | } |
| 1289 | placeWindowBefore(w, win); |
| 1290 | break; |
| 1291 | } |
| 1292 | } |
| 1293 | } |
| 1294 | if (i >= NA) { |
| 1295 | if (addToToken) { |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 1296 | 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] | 1297 | token.windows.add(win); |
| 1298 | } |
| 1299 | if (sublayer < 0) { |
| 1300 | placeWindowBefore(attached, win); |
| 1301 | } else { |
| 1302 | placeWindowAfter(largestSublayer >= 0 |
| 1303 | ? windowWithLargestSublayer |
| 1304 | : attached, |
| 1305 | win); |
| 1306 | } |
| 1307 | } |
| 1308 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1309 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1310 | if (win.mAppToken != null && addToToken) { |
| 1311 | win.mAppToken.allAppWindows.add(win); |
| 1312 | } |
| 1313 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1314 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1315 | static boolean canBeImeTarget(WindowState w) { |
| 1316 | final int fl = w.mAttrs.flags |
| 1317 | & (FLAG_NOT_FOCUSABLE|FLAG_ALT_FOCUSABLE_IM); |
| 1318 | if (fl == 0 || fl == (FLAG_NOT_FOCUSABLE|FLAG_ALT_FOCUSABLE_IM)) { |
| 1319 | return w.isVisibleOrAdding(); |
| 1320 | } |
| 1321 | return false; |
| 1322 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1323 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1324 | int findDesiredInputMethodWindowIndexLocked(boolean willMove) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1325 | final ArrayList<WindowState> localmWindows = mWindows; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1326 | final int N = localmWindows.size(); |
| 1327 | WindowState w = null; |
| 1328 | int i = N; |
| 1329 | while (i > 0) { |
| 1330 | i--; |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1331 | w = localmWindows.get(i); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1332 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1333 | //Slog.i(TAG, "Checking window @" + i + " " + w + " fl=0x" |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1334 | // + Integer.toHexString(w.mAttrs.flags)); |
| 1335 | if (canBeImeTarget(w)) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1336 | //Slog.i(TAG, "Putting input method here!"); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1337 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1338 | // Yet more tricksyness! If this window is a "starting" |
| 1339 | // window, we do actually want to be on top of it, but |
| 1340 | // it is not -really- where input will go. So if the caller |
| 1341 | // is not actually looking to move the IME, look down below |
| 1342 | // for a real window to target... |
| 1343 | if (!willMove |
| 1344 | && w.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING |
| 1345 | && i > 0) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1346 | WindowState wb = localmWindows.get(i-1); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1347 | if (wb.mAppToken == w.mAppToken && canBeImeTarget(wb)) { |
| 1348 | i--; |
| 1349 | w = wb; |
| 1350 | } |
| 1351 | } |
| 1352 | break; |
| 1353 | } |
| 1354 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1355 | |
Dianne Hackborn | 7eab094 | 2011-01-01 13:21:50 -0800 | [diff] [blame] | 1356 | // Now, a special case -- if the last target's window is in the |
| 1357 | // process of exiting, and is above the new target, keep on the |
| 1358 | // last target to avoid flicker. Consider for example a Dialog with |
| 1359 | // the IME shown: when the Dialog is dismissed, we want to keep |
| 1360 | // the IME above it until it is completely gone so it doesn't drop |
| 1361 | // behind the dialog or its full-screen scrim. |
| 1362 | if (mInputMethodTarget != null && w != null |
| 1363 | && mInputMethodTarget.isDisplayedLw() |
| 1364 | && mInputMethodTarget.mExiting) { |
| 1365 | if (mInputMethodTarget.mAnimLayer > w.mAnimLayer) { |
| 1366 | w = mInputMethodTarget; |
| 1367 | i = localmWindows.indexOf(w); |
| 1368 | } |
| 1369 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1370 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1371 | 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] | 1372 | + w + " willMove=" + willMove); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1373 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1374 | if (willMove && w != null) { |
| 1375 | final WindowState curTarget = mInputMethodTarget; |
| 1376 | if (curTarget != null && curTarget.mAppToken != null) { |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1377 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1378 | // Now some fun for dealing with window animations that |
| 1379 | // modify the Z order. We need to look at all windows below |
| 1380 | // the current target that are in this app, finding the highest |
| 1381 | // visible one in layering. |
| 1382 | AppWindowToken token = curTarget.mAppToken; |
| 1383 | WindowState highestTarget = null; |
| 1384 | int highestPos = 0; |
| 1385 | if (token.animating || token.animation != null) { |
| 1386 | int pos = 0; |
| 1387 | pos = localmWindows.indexOf(curTarget); |
| 1388 | while (pos >= 0) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1389 | WindowState win = localmWindows.get(pos); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1390 | if (win.mAppToken != token) { |
| 1391 | break; |
| 1392 | } |
| 1393 | if (!win.mRemoved) { |
| 1394 | if (highestTarget == null || win.mAnimLayer > |
| 1395 | highestTarget.mAnimLayer) { |
| 1396 | highestTarget = win; |
| 1397 | highestPos = pos; |
| 1398 | } |
| 1399 | } |
| 1400 | pos--; |
| 1401 | } |
| 1402 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1403 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1404 | if (highestTarget != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1405 | if (DEBUG_INPUT_METHOD) Slog.v(TAG, "mNextAppTransition=" |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1406 | + mNextAppTransition + " " + highestTarget |
| 1407 | + " animating=" + highestTarget.isAnimating() |
| 1408 | + " layer=" + highestTarget.mAnimLayer |
| 1409 | + " new layer=" + w.mAnimLayer); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1410 | |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 1411 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1412 | // If we are currently setting up for an animation, |
| 1413 | // hold everything until we can find out what will happen. |
| 1414 | mInputMethodTargetWaitingAnim = true; |
| 1415 | mInputMethodTarget = highestTarget; |
| 1416 | return highestPos + 1; |
| 1417 | } else if (highestTarget.isAnimating() && |
| 1418 | highestTarget.mAnimLayer > w.mAnimLayer) { |
| 1419 | // If the window we are currently targeting is involved |
| 1420 | // with an animation, and it is on top of the next target |
| 1421 | // we will be over, then hold off on moving until |
| 1422 | // that is done. |
| 1423 | mInputMethodTarget = highestTarget; |
| 1424 | return highestPos + 1; |
| 1425 | } |
| 1426 | } |
| 1427 | } |
| 1428 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1429 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1430 | //Slog.i(TAG, "Placing input method @" + (i+1)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1431 | if (w != null) { |
| 1432 | if (willMove) { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 1433 | if (DEBUG_INPUT_METHOD) { |
| 1434 | RuntimeException e = null; |
| 1435 | if (!HIDE_STACK_CRAWLS) { |
| 1436 | e = new RuntimeException(); |
| 1437 | e.fillInStackTrace(); |
| 1438 | } |
| 1439 | Slog.w(TAG, "Moving IM target from " |
| 1440 | + mInputMethodTarget + " to " + w, e); |
| 1441 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1442 | mInputMethodTarget = w; |
| 1443 | if (w.mAppToken != null) { |
| 1444 | setInputMethodAnimLayerAdjustment(w.mAppToken.animLayerAdjustment); |
| 1445 | } else { |
| 1446 | setInputMethodAnimLayerAdjustment(0); |
| 1447 | } |
| 1448 | } |
| 1449 | return i+1; |
| 1450 | } |
| 1451 | if (willMove) { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 1452 | if (DEBUG_INPUT_METHOD) { |
| 1453 | RuntimeException e = null; |
| 1454 | if (!HIDE_STACK_CRAWLS) { |
| 1455 | e = new RuntimeException(); |
| 1456 | e.fillInStackTrace(); |
| 1457 | } |
| 1458 | Slog.w(TAG, "Moving IM target from " |
| 1459 | + mInputMethodTarget + " to null", e); |
| 1460 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1461 | mInputMethodTarget = null; |
| 1462 | setInputMethodAnimLayerAdjustment(0); |
| 1463 | } |
| 1464 | return -1; |
| 1465 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1466 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1467 | void addInputMethodWindowToListLocked(WindowState win) { |
| 1468 | int pos = findDesiredInputMethodWindowIndexLocked(true); |
| 1469 | if (pos >= 0) { |
| 1470 | win.mTargetAppToken = mInputMethodTarget.mAppToken; |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 1471 | if (DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) Slog.v( |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 1472 | TAG, "Adding input method window " + win + " at " + pos); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1473 | mWindows.add(pos, win); |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 1474 | mWindowsChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1475 | moveInputMethodDialogsLocked(pos+1); |
| 1476 | return; |
| 1477 | } |
| 1478 | win.mTargetAppToken = null; |
| 1479 | addWindowToListInOrderLocked(win, true); |
| 1480 | moveInputMethodDialogsLocked(pos); |
| 1481 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1482 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1483 | void setInputMethodAnimLayerAdjustment(int adj) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1484 | 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] | 1485 | mInputMethodAnimLayerAdjustment = adj; |
| 1486 | WindowState imw = mInputMethodWindow; |
| 1487 | if (imw != null) { |
| 1488 | imw.mAnimLayer = imw.mLayer + adj; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1489 | if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + imw |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1490 | + " anim layer: " + imw.mAnimLayer); |
| 1491 | int wi = imw.mChildWindows.size(); |
| 1492 | while (wi > 0) { |
| 1493 | wi--; |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1494 | WindowState cw = imw.mChildWindows.get(wi); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1495 | cw.mAnimLayer = cw.mLayer + adj; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1496 | if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + cw |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1497 | + " anim layer: " + cw.mAnimLayer); |
| 1498 | } |
| 1499 | } |
| 1500 | int di = mInputMethodDialogs.size(); |
| 1501 | while (di > 0) { |
| 1502 | di --; |
| 1503 | imw = mInputMethodDialogs.get(di); |
| 1504 | imw.mAnimLayer = imw.mLayer + adj; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1505 | if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + imw |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1506 | + " anim layer: " + imw.mAnimLayer); |
| 1507 | } |
| 1508 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1509 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1510 | private int tmpRemoveWindowLocked(int interestingPos, WindowState win) { |
| 1511 | int wpos = mWindows.indexOf(win); |
| 1512 | if (wpos >= 0) { |
| 1513 | if (wpos < interestingPos) interestingPos--; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1514 | 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] | 1515 | mWindows.remove(wpos); |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 1516 | mWindowsChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1517 | int NC = win.mChildWindows.size(); |
| 1518 | while (NC > 0) { |
| 1519 | NC--; |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1520 | WindowState cw = win.mChildWindows.get(NC); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1521 | int cpos = mWindows.indexOf(cw); |
| 1522 | if (cpos >= 0) { |
| 1523 | if (cpos < interestingPos) interestingPos--; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1524 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Temp removing child at " |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 1525 | + cpos + ": " + cw); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1526 | mWindows.remove(cpos); |
| 1527 | } |
| 1528 | } |
| 1529 | } |
| 1530 | return interestingPos; |
| 1531 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1532 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1533 | private void reAddWindowToListInOrderLocked(WindowState win) { |
| 1534 | addWindowToListInOrderLocked(win, false); |
| 1535 | // This is a hack to get all of the child windows added as well |
| 1536 | // at the right position. Child windows should be rare and |
| 1537 | // this case should be rare, so it shouldn't be that big a deal. |
| 1538 | int wpos = mWindows.indexOf(win); |
| 1539 | if (wpos >= 0) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1540 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "ReAdd removing from " + wpos |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 1541 | + ": " + win); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1542 | mWindows.remove(wpos); |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 1543 | mWindowsChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1544 | reAddWindowLocked(wpos, win); |
| 1545 | } |
| 1546 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1547 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1548 | void logWindowList(String prefix) { |
| 1549 | int N = mWindows.size(); |
| 1550 | while (N > 0) { |
| 1551 | N--; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1552 | Slog.v(TAG, prefix + "#" + N + ": " + mWindows.get(N)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1553 | } |
| 1554 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1555 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1556 | void moveInputMethodDialogsLocked(int pos) { |
| 1557 | ArrayList<WindowState> dialogs = mInputMethodDialogs; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1558 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1559 | final int N = dialogs.size(); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1560 | 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] | 1561 | for (int i=0; i<N; i++) { |
| 1562 | pos = tmpRemoveWindowLocked(pos, dialogs.get(i)); |
| 1563 | } |
| 1564 | if (DEBUG_INPUT_METHOD) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1565 | Slog.v(TAG, "Window list w/pos=" + pos); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1566 | logWindowList(" "); |
| 1567 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1568 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1569 | if (pos >= 0) { |
| 1570 | final AppWindowToken targetAppToken = mInputMethodTarget.mAppToken; |
| 1571 | if (pos < mWindows.size()) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1572 | WindowState wp = mWindows.get(pos); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1573 | if (wp == mInputMethodWindow) { |
| 1574 | pos++; |
| 1575 | } |
| 1576 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1577 | 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] | 1578 | for (int i=0; i<N; i++) { |
| 1579 | WindowState win = dialogs.get(i); |
| 1580 | win.mTargetAppToken = targetAppToken; |
| 1581 | pos = reAddWindowLocked(pos, win); |
| 1582 | } |
| 1583 | if (DEBUG_INPUT_METHOD) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1584 | Slog.v(TAG, "Final window list:"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1585 | logWindowList(" "); |
| 1586 | } |
| 1587 | return; |
| 1588 | } |
| 1589 | for (int i=0; i<N; i++) { |
| 1590 | WindowState win = dialogs.get(i); |
| 1591 | win.mTargetAppToken = null; |
| 1592 | reAddWindowToListInOrderLocked(win); |
| 1593 | if (DEBUG_INPUT_METHOD) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1594 | Slog.v(TAG, "No IM target, final list:"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1595 | logWindowList(" "); |
| 1596 | } |
| 1597 | } |
| 1598 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1599 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1600 | boolean moveInputMethodWindowsIfNeededLocked(boolean needAssignLayers) { |
| 1601 | final WindowState imWin = mInputMethodWindow; |
| 1602 | final int DN = mInputMethodDialogs.size(); |
| 1603 | if (imWin == null && DN == 0) { |
| 1604 | return false; |
| 1605 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1606 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1607 | int imPos = findDesiredInputMethodWindowIndexLocked(true); |
| 1608 | if (imPos >= 0) { |
| 1609 | // In this case, the input method windows are to be placed |
| 1610 | // immediately above the window they are targeting. |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1611 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1612 | // First check to see if the input method windows are already |
| 1613 | // located here, and contiguous. |
| 1614 | final int N = mWindows.size(); |
| 1615 | WindowState firstImWin = imPos < N |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1616 | ? mWindows.get(imPos) : null; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1617 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1618 | // Figure out the actual input method window that should be |
| 1619 | // at the bottom of their stack. |
| 1620 | WindowState baseImWin = imWin != null |
| 1621 | ? imWin : mInputMethodDialogs.get(0); |
| 1622 | if (baseImWin.mChildWindows.size() > 0) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1623 | WindowState cw = baseImWin.mChildWindows.get(0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1624 | if (cw.mSubLayer < 0) baseImWin = cw; |
| 1625 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1626 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1627 | if (firstImWin == baseImWin) { |
| 1628 | // The windows haven't moved... but are they still contiguous? |
| 1629 | // First find the top IM window. |
| 1630 | int pos = imPos+1; |
| 1631 | while (pos < N) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1632 | if (!(mWindows.get(pos)).mIsImWindow) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1633 | break; |
| 1634 | } |
| 1635 | pos++; |
| 1636 | } |
| 1637 | pos++; |
| 1638 | // Now there should be no more input method windows above. |
| 1639 | while (pos < N) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1640 | if ((mWindows.get(pos)).mIsImWindow) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1641 | break; |
| 1642 | } |
| 1643 | pos++; |
| 1644 | } |
| 1645 | if (pos >= N) { |
| 1646 | // All is good! |
| 1647 | return false; |
| 1648 | } |
| 1649 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1650 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1651 | if (imWin != null) { |
| 1652 | if (DEBUG_INPUT_METHOD) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1653 | Slog.v(TAG, "Moving IM from " + imPos); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1654 | logWindowList(" "); |
| 1655 | } |
| 1656 | imPos = tmpRemoveWindowLocked(imPos, imWin); |
| 1657 | if (DEBUG_INPUT_METHOD) { |
Dianne Hackborn | 7eab094 | 2011-01-01 13:21:50 -0800 | [diff] [blame] | 1658 | 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] | 1659 | logWindowList(" "); |
| 1660 | } |
| 1661 | imWin.mTargetAppToken = mInputMethodTarget.mAppToken; |
| 1662 | reAddWindowLocked(imPos, imWin); |
| 1663 | if (DEBUG_INPUT_METHOD) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1664 | Slog.v(TAG, "List after moving IM to " + imPos + ":"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1665 | logWindowList(" "); |
| 1666 | } |
| 1667 | if (DN > 0) moveInputMethodDialogsLocked(imPos+1); |
| 1668 | } else { |
| 1669 | moveInputMethodDialogsLocked(imPos); |
| 1670 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1671 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1672 | } else { |
| 1673 | // In this case, the input method windows go in a fixed layer, |
| 1674 | // because they aren't currently associated with a focus window. |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1675 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1676 | if (imWin != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1677 | 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] | 1678 | tmpRemoveWindowLocked(0, imWin); |
| 1679 | imWin.mTargetAppToken = null; |
| 1680 | reAddWindowToListInOrderLocked(imWin); |
| 1681 | if (DEBUG_INPUT_METHOD) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1682 | Slog.v(TAG, "List with no IM target:"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1683 | logWindowList(" "); |
| 1684 | } |
| 1685 | if (DN > 0) moveInputMethodDialogsLocked(-1);; |
| 1686 | } else { |
| 1687 | moveInputMethodDialogsLocked(-1);; |
| 1688 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1689 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1690 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1691 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1692 | if (needAssignLayers) { |
| 1693 | assignLayersLocked(); |
| 1694 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1695 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1696 | return true; |
| 1697 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1698 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1699 | void adjustInputMethodDialogsLocked() { |
| 1700 | moveInputMethodDialogsLocked(findDesiredInputMethodWindowIndexLocked(true)); |
| 1701 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1702 | |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 1703 | final boolean isWallpaperVisible(WindowState wallpaperTarget) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1704 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper vis: target obscured=" |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 1705 | + (wallpaperTarget != null ? Boolean.toString(wallpaperTarget.mObscured) : "??") |
| 1706 | + " anim=" + ((wallpaperTarget != null && wallpaperTarget.mAppToken != null) |
| 1707 | ? wallpaperTarget.mAppToken.animation : null) |
| 1708 | + " upper=" + mUpperWallpaperTarget |
| 1709 | + " lower=" + mLowerWallpaperTarget); |
| 1710 | return (wallpaperTarget != null |
| 1711 | && (!wallpaperTarget.mObscured || (wallpaperTarget.mAppToken != null |
| 1712 | && wallpaperTarget.mAppToken.animation != null))) |
| 1713 | || mUpperWallpaperTarget != null |
| 1714 | || mLowerWallpaperTarget != null; |
| 1715 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1716 | |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 1717 | static final int ADJUST_WALLPAPER_LAYERS_CHANGED = 1<<1; |
| 1718 | static final int ADJUST_WALLPAPER_VISIBILITY_CHANGED = 1<<2; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1719 | |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 1720 | int adjustWallpaperWindowsLocked() { |
| 1721 | int changed = 0; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1722 | |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1723 | final int dw = mDisplay.getWidth(); |
| 1724 | final int dh = mDisplay.getHeight(); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1725 | |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1726 | // First find top-most window that has asked to be on top of the |
| 1727 | // wallpaper; all wallpapers go behind it. |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1728 | final ArrayList<WindowState> localmWindows = mWindows; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1729 | int N = localmWindows.size(); |
| 1730 | WindowState w = null; |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1731 | WindowState foundW = null; |
| 1732 | int foundI = 0; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1733 | WindowState topCurW = null; |
| 1734 | int topCurI = 0; |
Dianne Hackborn | 6c8e20f | 2010-11-09 18:59:09 -0800 | [diff] [blame] | 1735 | int windowDetachedI = -1; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1736 | int i = N; |
| 1737 | while (i > 0) { |
| 1738 | i--; |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1739 | w = localmWindows.get(i); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1740 | if ((w.mAttrs.type == WindowManager.LayoutParams.TYPE_WALLPAPER)) { |
| 1741 | if (topCurW == null) { |
| 1742 | topCurW = w; |
| 1743 | topCurI = i; |
| 1744 | } |
| 1745 | continue; |
| 1746 | } |
| 1747 | topCurW = null; |
Dianne Hackborn | 6c8e20f | 2010-11-09 18:59:09 -0800 | [diff] [blame] | 1748 | if (w != mWindowDetachedWallpaper && w.mAppToken != null) { |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1749 | // If this window's app token is hidden and not animating, |
| 1750 | // it is of no interest to us. |
| 1751 | if (w.mAppToken.hidden && w.mAppToken.animation == null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1752 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
Dianne Hackborn | 6c8e20f | 2010-11-09 18:59:09 -0800 | [diff] [blame] | 1753 | "Skipping not hidden or animating token: " + w); |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1754 | continue; |
| 1755 | } |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1756 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1757 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Win " + w + ": readyfordisplay=" |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1758 | + w.isReadyForDisplay() + " drawpending=" + w.mDrawPending |
| 1759 | + " commitdrawpending=" + w.mCommitDrawPending); |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1760 | if ((w.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0 && w.isReadyForDisplay() |
Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 1761 | && (mWallpaperTarget == w |
| 1762 | || (!w.mDrawPending && !w.mCommitDrawPending))) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1763 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1764 | "Found wallpaper activity: #" + i + "=" + w); |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1765 | foundW = w; |
| 1766 | foundI = i; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1767 | if (w == mWallpaperTarget && ((w.mAppToken != null |
| 1768 | && w.mAppToken.animation != null) |
| 1769 | || w.mAnimation != null)) { |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1770 | // The current wallpaper target is animating, so we'll |
| 1771 | // look behind it for another possible target and figure |
| 1772 | // out what is going on below. |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1773 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Win " + w |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1774 | + ": token animating, looking behind."); |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1775 | continue; |
| 1776 | } |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1777 | break; |
Dianne Hackborn | 6c8e20f | 2010-11-09 18:59:09 -0800 | [diff] [blame] | 1778 | } else if (w == mWindowDetachedWallpaper) { |
| 1779 | windowDetachedI = i; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1780 | } |
| 1781 | } |
| 1782 | |
Dianne Hackborn | 6c8e20f | 2010-11-09 18:59:09 -0800 | [diff] [blame] | 1783 | if (foundW == null && windowDetachedI >= 0) { |
| 1784 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
| 1785 | "Found animating detached wallpaper activity: #" + i + "=" + w); |
| 1786 | foundW = w; |
| 1787 | foundI = windowDetachedI; |
| 1788 | } |
| 1789 | |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 1790 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1791 | // If we are currently waiting for an app transition, and either |
| 1792 | // the current target or the next target are involved with it, |
| 1793 | // then hold off on doing anything with the wallpaper. |
| 1794 | // Note that we are checking here for just whether the target |
| 1795 | // is part of an app token... which is potentially overly aggressive |
| 1796 | // (the app token may not be involved in the transition), but good |
| 1797 | // enough (we'll just wait until whatever transition is pending |
| 1798 | // executes). |
| 1799 | if (mWallpaperTarget != null && mWallpaperTarget.mAppToken != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1800 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1801 | "Wallpaper not changing: waiting for app anim in current target"); |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 1802 | return 0; |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1803 | } |
| 1804 | if (foundW != null && foundW.mAppToken != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1805 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1806 | "Wallpaper not changing: waiting for app anim in found target"); |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 1807 | return 0; |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1808 | } |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1809 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1810 | |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1811 | if (mWallpaperTarget != foundW) { |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1812 | if (DEBUG_WALLPAPER) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1813 | Slog.v(TAG, "New wallpaper target: " + foundW |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1814 | + " oldTarget: " + mWallpaperTarget); |
| 1815 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1816 | |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1817 | mLowerWallpaperTarget = null; |
| 1818 | mUpperWallpaperTarget = null; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1819 | |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1820 | WindowState oldW = mWallpaperTarget; |
| 1821 | mWallpaperTarget = foundW; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1822 | |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1823 | // Now what is happening... if the current and new targets are |
| 1824 | // animating, then we are in our super special mode! |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1825 | if (foundW != null && oldW != null) { |
| 1826 | boolean oldAnim = oldW.mAnimation != null |
| 1827 | || (oldW.mAppToken != null && oldW.mAppToken.animation != null); |
| 1828 | boolean foundAnim = foundW.mAnimation != null |
| 1829 | || (foundW.mAppToken != null && foundW.mAppToken.animation != null); |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1830 | if (DEBUG_WALLPAPER) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1831 | Slog.v(TAG, "New animation: " + foundAnim |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1832 | + " old animation: " + oldAnim); |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1833 | } |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1834 | if (foundAnim && oldAnim) { |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1835 | int oldI = localmWindows.indexOf(oldW); |
| 1836 | if (DEBUG_WALLPAPER) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1837 | Slog.v(TAG, "New i: " + foundI + " old i: " + oldI); |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1838 | } |
| 1839 | if (oldI >= 0) { |
| 1840 | if (DEBUG_WALLPAPER) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1841 | Slog.v(TAG, "Animating wallpapers: old#" + oldI |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1842 | + "=" + oldW + "; new#" + foundI |
| 1843 | + "=" + foundW); |
| 1844 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1845 | |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1846 | // Set the new target correctly. |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1847 | if (foundW.mAppToken != null && foundW.mAppToken.hiddenRequested) { |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1848 | if (DEBUG_WALLPAPER) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1849 | Slog.v(TAG, "Old wallpaper still the target."); |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1850 | } |
| 1851 | mWallpaperTarget = oldW; |
| 1852 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1853 | |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1854 | // Now set the upper and lower wallpaper targets |
| 1855 | // correctly, and make sure that we are positioning |
| 1856 | // the wallpaper below the lower. |
| 1857 | if (foundI > oldI) { |
| 1858 | // The new target is on top of the old one. |
| 1859 | if (DEBUG_WALLPAPER) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1860 | Slog.v(TAG, "Found target above old target."); |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1861 | } |
| 1862 | mUpperWallpaperTarget = foundW; |
| 1863 | mLowerWallpaperTarget = oldW; |
| 1864 | foundW = oldW; |
| 1865 | foundI = oldI; |
| 1866 | } else { |
| 1867 | // The new target is below the old one. |
| 1868 | if (DEBUG_WALLPAPER) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1869 | Slog.v(TAG, "Found target below old target."); |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1870 | } |
| 1871 | mUpperWallpaperTarget = oldW; |
| 1872 | mLowerWallpaperTarget = foundW; |
| 1873 | } |
| 1874 | } |
| 1875 | } |
| 1876 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1877 | |
Dianne Hackborn | 6b1cb35 | 2009-09-28 18:27:26 -0700 | [diff] [blame] | 1878 | } else if (mLowerWallpaperTarget != null) { |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1879 | // Is it time to stop animating? |
Dianne Hackborn | 6b1cb35 | 2009-09-28 18:27:26 -0700 | [diff] [blame] | 1880 | boolean lowerAnimating = mLowerWallpaperTarget.mAnimation != null |
| 1881 | || (mLowerWallpaperTarget.mAppToken != null |
| 1882 | && mLowerWallpaperTarget.mAppToken.animation != null); |
| 1883 | boolean upperAnimating = mUpperWallpaperTarget.mAnimation != null |
| 1884 | || (mUpperWallpaperTarget.mAppToken != null |
| 1885 | && mUpperWallpaperTarget.mAppToken.animation != null); |
| 1886 | if (!lowerAnimating || !upperAnimating) { |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1887 | if (DEBUG_WALLPAPER) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1888 | Slog.v(TAG, "No longer animating wallpaper targets!"); |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1889 | } |
| 1890 | mLowerWallpaperTarget = null; |
| 1891 | mUpperWallpaperTarget = null; |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1892 | } |
| 1893 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1894 | |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1895 | boolean visible = foundW != null; |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 1896 | if (visible) { |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1897 | // The window is visible to the compositor... but is it visible |
| 1898 | // to the user? That is what the wallpaper cares about. |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 1899 | visible = isWallpaperVisible(foundW); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1900 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper visibility: " + visible); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1901 | |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1902 | // If the wallpaper target is animating, we may need to copy |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1903 | // its layer adjustment. Only do this if we are not transfering |
| 1904 | // between two wallpaper targets. |
| 1905 | mWallpaperAnimLayerAdjustment = |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1906 | (mLowerWallpaperTarget == null && foundW.mAppToken != null) |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1907 | ? foundW.mAppToken.animLayerAdjustment : 0; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1908 | |
Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 1909 | final int maxLayer = mPolicy.getMaxWallpaperLayer() |
| 1910 | * TYPE_LAYER_MULTIPLIER |
| 1911 | + TYPE_LAYER_OFFSET; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1912 | |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1913 | // Now w is the window we are supposed to be behind... but we |
| 1914 | // 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] | 1915 | // AND any starting window associated with it, AND below the |
| 1916 | // maximum layer the policy allows for wallpapers. |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1917 | while (foundI > 0) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1918 | WindowState wb = localmWindows.get(foundI-1); |
Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 1919 | if (wb.mBaseLayer < maxLayer && |
| 1920 | wb.mAttachedWindow != foundW && |
Pal Szasz | 73dc259 | 2010-09-03 11:46:26 +0200 | [diff] [blame] | 1921 | wb.mAttachedWindow != foundW.mAttachedWindow && |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1922 | (wb.mAttrs.type != TYPE_APPLICATION_STARTING || |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1923 | wb.mToken != foundW.mToken)) { |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1924 | // This window is not related to the previous one in any |
| 1925 | // interesting way, so stop here. |
| 1926 | break; |
| 1927 | } |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1928 | foundW = wb; |
| 1929 | foundI--; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1930 | } |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 1931 | } else { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1932 | if (DEBUG_WALLPAPER) Slog.v(TAG, "No wallpaper target"); |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1933 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1934 | |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1935 | if (foundW == null && topCurW != null) { |
| 1936 | // There is no wallpaper target, so it goes at the bottom. |
| 1937 | // We will assume it is the same place as last time, if known. |
| 1938 | foundW = topCurW; |
| 1939 | foundI = topCurI+1; |
| 1940 | } else { |
| 1941 | // Okay i is the position immediately above the wallpaper. Look at |
| 1942 | // what is below it for later. |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1943 | foundW = foundI > 0 ? localmWindows.get(foundI-1) : null; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1944 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1945 | |
Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 1946 | if (visible) { |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1947 | if (mWallpaperTarget.mWallpaperX >= 0) { |
| 1948 | mLastWallpaperX = mWallpaperTarget.mWallpaperX; |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 1949 | mLastWallpaperXStep = mWallpaperTarget.mWallpaperXStep; |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1950 | } |
| 1951 | if (mWallpaperTarget.mWallpaperY >= 0) { |
| 1952 | mLastWallpaperY = mWallpaperTarget.mWallpaperY; |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 1953 | mLastWallpaperYStep = mWallpaperTarget.mWallpaperYStep; |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1954 | } |
Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 1955 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1956 | |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1957 | // Start stepping backwards from here, ensuring that our wallpaper windows |
| 1958 | // are correctly placed. |
| 1959 | int curTokenIndex = mWallpaperTokens.size(); |
| 1960 | while (curTokenIndex > 0) { |
| 1961 | curTokenIndex--; |
| 1962 | WindowToken token = mWallpaperTokens.get(curTokenIndex); |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 1963 | if (token.hidden == visible) { |
| 1964 | changed |= ADJUST_WALLPAPER_VISIBILITY_CHANGED; |
| 1965 | token.hidden = !visible; |
| 1966 | // Need to do a layout to ensure the wallpaper now has the |
| 1967 | // correct size. |
| 1968 | mLayoutNeeded = true; |
| 1969 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1970 | |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1971 | int curWallpaperIndex = token.windows.size(); |
| 1972 | while (curWallpaperIndex > 0) { |
| 1973 | curWallpaperIndex--; |
| 1974 | WindowState wallpaper = token.windows.get(curWallpaperIndex); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1975 | |
Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 1976 | if (visible) { |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1977 | updateWallpaperOffsetLocked(wallpaper, dw, dh, false); |
Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 1978 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1979 | |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 1980 | // First, make sure the client has the current visibility |
| 1981 | // state. |
| 1982 | if (wallpaper.mWallpaperVisible != visible) { |
| 1983 | wallpaper.mWallpaperVisible = visible; |
| 1984 | try { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1985 | if (DEBUG_VISIBILITY || DEBUG_WALLPAPER) Slog.v(TAG, |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 1986 | "Setting visibility of wallpaper " + wallpaper |
| 1987 | + ": " + visible); |
| 1988 | wallpaper.mClient.dispatchAppVisibility(visible); |
| 1989 | } catch (RemoteException e) { |
| 1990 | } |
| 1991 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1992 | |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 1993 | wallpaper.mAnimLayer = wallpaper.mLayer + mWallpaperAnimLayerAdjustment; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1994 | if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper win " |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1995 | + wallpaper + " anim layer: " + wallpaper.mAnimLayer); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1996 | |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1997 | // First, if this window is at the current index, then all |
| 1998 | // is well. |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1999 | if (wallpaper == foundW) { |
| 2000 | foundI--; |
| 2001 | foundW = foundI > 0 |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 2002 | ? localmWindows.get(foundI-1) : null; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2003 | continue; |
| 2004 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2005 | |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2006 | // The window didn't match... the current wallpaper window, |
| 2007 | // wherever it is, is in the wrong place, so make sure it is |
| 2008 | // not in the list. |
| 2009 | int oldIndex = localmWindows.indexOf(wallpaper); |
| 2010 | if (oldIndex >= 0) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2011 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Wallpaper removing at " |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 2012 | + oldIndex + ": " + wallpaper); |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2013 | localmWindows.remove(oldIndex); |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 2014 | mWindowsChanged = true; |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 2015 | if (oldIndex < foundI) { |
| 2016 | foundI--; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2017 | } |
| 2018 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2019 | |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2020 | // Now stick it in. |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 2021 | if (DEBUG_WALLPAPER || DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) { |
| 2022 | Slog.v(TAG, "Moving wallpaper " + wallpaper |
| 2023 | + " from " + oldIndex + " to " + foundI); |
| 2024 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2025 | |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 2026 | localmWindows.add(foundI, wallpaper); |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 2027 | mWindowsChanged = true; |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 2028 | changed |= ADJUST_WALLPAPER_LAYERS_CHANGED; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2029 | } |
| 2030 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2031 | |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2032 | return changed; |
| 2033 | } |
| 2034 | |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 2035 | void setWallpaperAnimLayerAdjustmentLocked(int adj) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2036 | if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG, |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 2037 | "Setting wallpaper layer adj to " + adj); |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 2038 | mWallpaperAnimLayerAdjustment = adj; |
| 2039 | int curTokenIndex = mWallpaperTokens.size(); |
| 2040 | while (curTokenIndex > 0) { |
| 2041 | curTokenIndex--; |
| 2042 | WindowToken token = mWallpaperTokens.get(curTokenIndex); |
| 2043 | int curWallpaperIndex = token.windows.size(); |
| 2044 | while (curWallpaperIndex > 0) { |
| 2045 | curWallpaperIndex--; |
| 2046 | WindowState wallpaper = token.windows.get(curWallpaperIndex); |
| 2047 | wallpaper.mAnimLayer = wallpaper.mLayer + adj; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2048 | if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper win " |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 2049 | + wallpaper + " anim layer: " + wallpaper.mAnimLayer); |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 2050 | } |
| 2051 | } |
| 2052 | } |
| 2053 | |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 2054 | boolean updateWallpaperOffsetLocked(WindowState wallpaperWin, int dw, int dh, |
| 2055 | boolean sync) { |
Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 2056 | boolean changed = false; |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 2057 | boolean rawChanged = false; |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 2058 | float wpx = mLastWallpaperX >= 0 ? mLastWallpaperX : 0.5f; |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 2059 | float wpxs = mLastWallpaperXStep >= 0 ? mLastWallpaperXStep : -1.0f; |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 2060 | int availw = wallpaperWin.mFrame.right-wallpaperWin.mFrame.left-dw; |
| 2061 | int offset = availw > 0 ? -(int)(availw*wpx+.5f) : 0; |
| 2062 | changed = wallpaperWin.mXOffset != offset; |
| 2063 | if (changed) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2064 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Update wallpaper " |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 2065 | + wallpaperWin + " x: " + offset); |
| 2066 | wallpaperWin.mXOffset = offset; |
| 2067 | } |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 2068 | if (wallpaperWin.mWallpaperX != wpx || wallpaperWin.mWallpaperXStep != wpxs) { |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 2069 | wallpaperWin.mWallpaperX = wpx; |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 2070 | wallpaperWin.mWallpaperXStep = wpxs; |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 2071 | rawChanged = true; |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 2072 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2073 | |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 2074 | float wpy = mLastWallpaperY >= 0 ? mLastWallpaperY : 0.5f; |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 2075 | float wpys = mLastWallpaperYStep >= 0 ? mLastWallpaperYStep : -1.0f; |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 2076 | int availh = wallpaperWin.mFrame.bottom-wallpaperWin.mFrame.top-dh; |
| 2077 | offset = availh > 0 ? -(int)(availh*wpy+.5f) : 0; |
| 2078 | if (wallpaperWin.mYOffset != offset) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2079 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Update wallpaper " |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 2080 | + wallpaperWin + " y: " + offset); |
| 2081 | changed = true; |
| 2082 | wallpaperWin.mYOffset = offset; |
| 2083 | } |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 2084 | if (wallpaperWin.mWallpaperY != wpy || wallpaperWin.mWallpaperYStep != wpys) { |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 2085 | wallpaperWin.mWallpaperY = wpy; |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 2086 | wallpaperWin.mWallpaperYStep = wpys; |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 2087 | rawChanged = true; |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 2088 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2089 | |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 2090 | if (rawChanged) { |
Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 2091 | try { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2092 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Report new wp offset " |
Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 2093 | + wallpaperWin + " x=" + wallpaperWin.mWallpaperX |
| 2094 | + " y=" + wallpaperWin.mWallpaperY); |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 2095 | if (sync) { |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 2096 | mWaitingOnWallpaper = wallpaperWin; |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 2097 | } |
Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 2098 | wallpaperWin.mClient.dispatchWallpaperOffsets( |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 2099 | wallpaperWin.mWallpaperX, wallpaperWin.mWallpaperY, |
| 2100 | wallpaperWin.mWallpaperXStep, wallpaperWin.mWallpaperYStep, sync); |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 2101 | if (sync) { |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 2102 | if (mWaitingOnWallpaper != null) { |
| 2103 | long start = SystemClock.uptimeMillis(); |
| 2104 | if ((mLastWallpaperTimeoutTime+WALLPAPER_TIMEOUT_RECOVERY) |
| 2105 | < start) { |
| 2106 | try { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2107 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 2108 | "Waiting for offset complete..."); |
| 2109 | mWindowMap.wait(WALLPAPER_TIMEOUT); |
| 2110 | } catch (InterruptedException e) { |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 2111 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2112 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Offset complete!"); |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 2113 | if ((start+WALLPAPER_TIMEOUT) |
| 2114 | < SystemClock.uptimeMillis()) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2115 | Slog.i(TAG, "Timeout waiting for wallpaper to offset: " |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 2116 | + wallpaperWin); |
| 2117 | mLastWallpaperTimeoutTime = start; |
| 2118 | } |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 2119 | } |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 2120 | mWaitingOnWallpaper = null; |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 2121 | } |
| 2122 | } |
Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 2123 | } catch (RemoteException e) { |
| 2124 | } |
| 2125 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2126 | |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 2127 | return changed; |
| 2128 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2129 | |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 2130 | void wallpaperOffsetsComplete(IBinder window) { |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 2131 | synchronized (mWindowMap) { |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 2132 | if (mWaitingOnWallpaper != null && |
| 2133 | mWaitingOnWallpaper.mClient.asBinder() == window) { |
| 2134 | mWaitingOnWallpaper = null; |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 2135 | mWindowMap.notifyAll(); |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 2136 | } |
| 2137 | } |
| 2138 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2139 | |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 2140 | boolean updateWallpaperOffsetLocked(WindowState changingTarget, boolean sync) { |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 2141 | final int dw = mDisplay.getWidth(); |
| 2142 | final int dh = mDisplay.getHeight(); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2143 | |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 2144 | boolean changed = false; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2145 | |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 2146 | WindowState target = mWallpaperTarget; |
| 2147 | if (target != null) { |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 2148 | if (target.mWallpaperX >= 0) { |
| 2149 | mLastWallpaperX = target.mWallpaperX; |
| 2150 | } else if (changingTarget.mWallpaperX >= 0) { |
| 2151 | mLastWallpaperX = changingTarget.mWallpaperX; |
| 2152 | } |
| 2153 | if (target.mWallpaperY >= 0) { |
| 2154 | mLastWallpaperY = target.mWallpaperY; |
| 2155 | } else if (changingTarget.mWallpaperY >= 0) { |
| 2156 | mLastWallpaperY = changingTarget.mWallpaperY; |
| 2157 | } |
| 2158 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2159 | |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 2160 | int curTokenIndex = mWallpaperTokens.size(); |
| 2161 | while (curTokenIndex > 0) { |
| 2162 | curTokenIndex--; |
| 2163 | WindowToken token = mWallpaperTokens.get(curTokenIndex); |
| 2164 | int curWallpaperIndex = token.windows.size(); |
| 2165 | while (curWallpaperIndex > 0) { |
| 2166 | curWallpaperIndex--; |
| 2167 | WindowState wallpaper = token.windows.get(curWallpaperIndex); |
| 2168 | if (updateWallpaperOffsetLocked(wallpaper, dw, dh, sync)) { |
| 2169 | wallpaper.computeShownFrameLocked(); |
| 2170 | changed = true; |
| 2171 | // We only want to be synchronous with one wallpaper. |
| 2172 | sync = false; |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 2173 | } |
| 2174 | } |
| 2175 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2176 | |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 2177 | return changed; |
| 2178 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2179 | |
Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 2180 | void updateWallpaperVisibilityLocked() { |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 2181 | final boolean visible = isWallpaperVisible(mWallpaperTarget); |
Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 2182 | final int dw = mDisplay.getWidth(); |
| 2183 | final int dh = mDisplay.getHeight(); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2184 | |
Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 2185 | int curTokenIndex = mWallpaperTokens.size(); |
| 2186 | while (curTokenIndex > 0) { |
| 2187 | curTokenIndex--; |
| 2188 | WindowToken token = mWallpaperTokens.get(curTokenIndex); |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 2189 | if (token.hidden == visible) { |
| 2190 | token.hidden = !visible; |
| 2191 | // Need to do a layout to ensure the wallpaper now has the |
| 2192 | // correct size. |
| 2193 | mLayoutNeeded = true; |
| 2194 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2195 | |
Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 2196 | int curWallpaperIndex = token.windows.size(); |
| 2197 | while (curWallpaperIndex > 0) { |
| 2198 | curWallpaperIndex--; |
| 2199 | WindowState wallpaper = token.windows.get(curWallpaperIndex); |
| 2200 | if (visible) { |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 2201 | updateWallpaperOffsetLocked(wallpaper, dw, dh, false); |
Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 2202 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2203 | |
Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 2204 | if (wallpaper.mWallpaperVisible != visible) { |
| 2205 | wallpaper.mWallpaperVisible = visible; |
| 2206 | try { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2207 | if (DEBUG_VISIBILITY || DEBUG_WALLPAPER) Slog.v(TAG, |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 2208 | "Updating visibility of wallpaper " + wallpaper |
Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 2209 | + ": " + visible); |
| 2210 | wallpaper.mClient.dispatchAppVisibility(visible); |
| 2211 | } catch (RemoteException e) { |
| 2212 | } |
| 2213 | } |
| 2214 | } |
| 2215 | } |
| 2216 | } |
Dianne Hackborn | 90d2db3 | 2010-02-11 22:19:06 -0800 | [diff] [blame] | 2217 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2218 | public int addWindow(Session session, IWindow client, |
| 2219 | WindowManager.LayoutParams attrs, int viewVisibility, |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 2220 | Rect outContentInsets, InputChannel outInputChannel) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2221 | int res = mPolicy.checkAddPermission(attrs); |
| 2222 | if (res != WindowManagerImpl.ADD_OKAY) { |
| 2223 | return res; |
| 2224 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2225 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2226 | boolean reportNewConfig = false; |
| 2227 | WindowState attachedWindow = null; |
| 2228 | WindowState win = null; |
Dianne Hackborn | 5132b37 | 2010-07-29 12:51:35 -0700 | [diff] [blame] | 2229 | long origId; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2230 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2231 | synchronized(mWindowMap) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2232 | if (mDisplay == null) { |
Dianne Hackborn | 5132b37 | 2010-07-29 12:51:35 -0700 | [diff] [blame] | 2233 | throw new IllegalStateException("Display has not been initialialized"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2234 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2235 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2236 | if (mWindowMap.containsKey(client.asBinder())) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2237 | Slog.w(TAG, "Window " + client + " is already added"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2238 | return WindowManagerImpl.ADD_DUPLICATE_ADD; |
| 2239 | } |
| 2240 | |
| 2241 | if (attrs.type >= FIRST_SUB_WINDOW && attrs.type <= LAST_SUB_WINDOW) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2242 | attachedWindow = windowForClientLocked(null, attrs.token, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2243 | if (attachedWindow == null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2244 | 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] | 2245 | + attrs.token + ". Aborting."); |
| 2246 | return WindowManagerImpl.ADD_BAD_SUBWINDOW_TOKEN; |
| 2247 | } |
| 2248 | if (attachedWindow.mAttrs.type >= FIRST_SUB_WINDOW |
| 2249 | && attachedWindow.mAttrs.type <= LAST_SUB_WINDOW) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2250 | 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] | 2251 | + attrs.token + ". Aborting."); |
| 2252 | return WindowManagerImpl.ADD_BAD_SUBWINDOW_TOKEN; |
| 2253 | } |
| 2254 | } |
| 2255 | |
| 2256 | boolean addToken = false; |
| 2257 | WindowToken token = mTokenMap.get(attrs.token); |
| 2258 | if (token == null) { |
| 2259 | if (attrs.type >= FIRST_APPLICATION_WINDOW |
| 2260 | && attrs.type <= LAST_APPLICATION_WINDOW) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2261 | 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] | 2262 | + attrs.token + ". Aborting."); |
| 2263 | return WindowManagerImpl.ADD_BAD_APP_TOKEN; |
| 2264 | } |
| 2265 | if (attrs.type == TYPE_INPUT_METHOD) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2266 | 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] | 2267 | + attrs.token + ". Aborting."); |
| 2268 | return WindowManagerImpl.ADD_BAD_APP_TOKEN; |
| 2269 | } |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2270 | if (attrs.type == TYPE_WALLPAPER) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2271 | Slog.w(TAG, "Attempted to add wallpaper window with unknown token " |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2272 | + attrs.token + ". Aborting."); |
| 2273 | return WindowManagerImpl.ADD_BAD_APP_TOKEN; |
| 2274 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2275 | token = new WindowToken(attrs.token, -1, false); |
| 2276 | addToken = true; |
| 2277 | } else if (attrs.type >= FIRST_APPLICATION_WINDOW |
| 2278 | && attrs.type <= LAST_APPLICATION_WINDOW) { |
| 2279 | AppWindowToken atoken = token.appWindowToken; |
| 2280 | if (atoken == null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2281 | 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] | 2282 | + token + ". Aborting."); |
| 2283 | return WindowManagerImpl.ADD_NOT_APP_TOKEN; |
| 2284 | } else if (atoken.removed) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2285 | 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] | 2286 | + token + ". Aborting."); |
| 2287 | return WindowManagerImpl.ADD_APP_EXITING; |
| 2288 | } |
| 2289 | if (attrs.type == TYPE_APPLICATION_STARTING && atoken.firstWindowDrawn) { |
| 2290 | // No need for this guy! |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2291 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2292 | TAG, "**** NO NEED TO START: " + attrs.getTitle()); |
| 2293 | return WindowManagerImpl.ADD_STARTING_NOT_NEEDED; |
| 2294 | } |
| 2295 | } else if (attrs.type == TYPE_INPUT_METHOD) { |
| 2296 | if (token.windowType != TYPE_INPUT_METHOD) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2297 | 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] | 2298 | + attrs.token + ". Aborting."); |
| 2299 | return WindowManagerImpl.ADD_BAD_APP_TOKEN; |
| 2300 | } |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2301 | } else if (attrs.type == TYPE_WALLPAPER) { |
| 2302 | if (token.windowType != TYPE_WALLPAPER) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2303 | Slog.w(TAG, "Attempted to add wallpaper window with bad token " |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2304 | + attrs.token + ". Aborting."); |
| 2305 | return WindowManagerImpl.ADD_BAD_APP_TOKEN; |
| 2306 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2307 | } |
| 2308 | |
| 2309 | win = new WindowState(session, client, token, |
| 2310 | attachedWindow, attrs, viewVisibility); |
| 2311 | if (win.mDeathRecipient == null) { |
| 2312 | // Client has apparently died, so there is no reason to |
| 2313 | // continue. |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2314 | Slog.w(TAG, "Adding window client " + client.asBinder() |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2315 | + " that is dead, aborting."); |
| 2316 | return WindowManagerImpl.ADD_APP_EXITING; |
| 2317 | } |
| 2318 | |
| 2319 | mPolicy.adjustWindowParamsLw(win.mAttrs); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2320 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2321 | res = mPolicy.prepareAddWindowLw(win, attrs); |
| 2322 | if (res != WindowManagerImpl.ADD_OKAY) { |
| 2323 | return res; |
| 2324 | } |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 2325 | |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 2326 | if (outInputChannel != null) { |
| 2327 | String name = win.makeInputChannelName(); |
| 2328 | InputChannel[] inputChannels = InputChannel.openInputChannelPair(name); |
| 2329 | win.mInputChannel = inputChannels[0]; |
| 2330 | inputChannels[1].transferToBinderOutParameter(outInputChannel); |
| 2331 | |
Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame] | 2332 | mInputManager.registerInputChannel(win.mInputChannel, win.mInputWindowHandle); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 2333 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2334 | |
| 2335 | // From now on, no exceptions or errors allowed! |
| 2336 | |
| 2337 | res = WindowManagerImpl.ADD_OKAY; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2338 | |
Dianne Hackborn | 5132b37 | 2010-07-29 12:51:35 -0700 | [diff] [blame] | 2339 | origId = Binder.clearCallingIdentity(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2340 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2341 | if (addToken) { |
| 2342 | mTokenMap.put(attrs.token, token); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2343 | } |
| 2344 | win.attach(); |
| 2345 | mWindowMap.put(client.asBinder(), win); |
| 2346 | |
| 2347 | if (attrs.type == TYPE_APPLICATION_STARTING && |
| 2348 | token.appWindowToken != null) { |
| 2349 | token.appWindowToken.startingWindow = win; |
| 2350 | } |
| 2351 | |
| 2352 | boolean imMayMove = true; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2353 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2354 | if (attrs.type == TYPE_INPUT_METHOD) { |
| 2355 | mInputMethodWindow = win; |
| 2356 | addInputMethodWindowToListLocked(win); |
| 2357 | imMayMove = false; |
| 2358 | } else if (attrs.type == TYPE_INPUT_METHOD_DIALOG) { |
| 2359 | mInputMethodDialogs.add(win); |
| 2360 | addWindowToListInOrderLocked(win, true); |
| 2361 | adjustInputMethodDialogsLocked(); |
| 2362 | imMayMove = false; |
| 2363 | } else { |
| 2364 | addWindowToListInOrderLocked(win, true); |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 2365 | if (attrs.type == TYPE_WALLPAPER) { |
| 2366 | mLastWallpaperTimeoutTime = 0; |
| 2367 | adjustWallpaperWindowsLocked(); |
| 2368 | } else if ((attrs.flags&FLAG_SHOW_WALLPAPER) != 0) { |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2369 | adjustWallpaperWindowsLocked(); |
| 2370 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2371 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2372 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2373 | win.mEnterAnimationPending = true; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2374 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2375 | mPolicy.getContentInsetHintLw(attrs, outContentInsets); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2376 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2377 | if (mInTouchMode) { |
| 2378 | res |= WindowManagerImpl.ADD_FLAG_IN_TOUCH_MODE; |
| 2379 | } |
| 2380 | if (win == null || win.mAppToken == null || !win.mAppToken.clientHidden) { |
| 2381 | res |= WindowManagerImpl.ADD_FLAG_APP_VISIBLE; |
| 2382 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2383 | |
Jeff Brown | 2e44b07 | 2011-01-24 15:21:56 -0800 | [diff] [blame^] | 2384 | mInputMonitor.setUpdateInputWindowsNeededLw(); |
| 2385 | |
The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 2386 | boolean focusChanged = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2387 | if (win.canReceiveKeys()) { |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 2388 | focusChanged = updateFocusedWindowLocked(UPDATE_FOCUS_WILL_ASSIGN_LAYERS, |
| 2389 | false /*updateInputWindows*/); |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 2390 | if (focusChanged) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2391 | imMayMove = false; |
| 2392 | } |
| 2393 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2394 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2395 | if (imMayMove) { |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2396 | moveInputMethodWindowsIfNeededLocked(false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2397 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2398 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2399 | assignLayersLocked(); |
| 2400 | // Don't do layout here, the window must call |
| 2401 | // relayout to be displayed, so we'll do it there. |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2402 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2403 | //dump(); |
| 2404 | |
The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 2405 | if (focusChanged) { |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 2406 | finishUpdateFocusedWindowAfterAssignLayersLocked(false /*updateInputWindows*/); |
The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 2407 | } |
Jeff Brown | 2e44b07 | 2011-01-24 15:21:56 -0800 | [diff] [blame^] | 2408 | mInputMonitor.updateInputWindowsLw(false /*force*/); |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 2409 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2410 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2411 | TAG, "New client " + client.asBinder() |
| 2412 | + ": window=" + win); |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2413 | |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 2414 | if (win.isVisibleOrAdding() && updateOrientationFromAppTokensLocked(false)) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2415 | reportNewConfig = true; |
| 2416 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2417 | } |
| 2418 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2419 | if (reportNewConfig) { |
| 2420 | sendNewConfiguration(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2421 | } |
Dianne Hackborn | 5132b37 | 2010-07-29 12:51:35 -0700 | [diff] [blame] | 2422 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2423 | Binder.restoreCallingIdentity(origId); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2424 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2425 | return res; |
| 2426 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2427 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2428 | public void removeWindow(Session session, IWindow client) { |
| 2429 | synchronized(mWindowMap) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2430 | WindowState win = windowForClientLocked(session, client, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2431 | if (win == null) { |
| 2432 | return; |
| 2433 | } |
| 2434 | removeWindowLocked(session, win); |
| 2435 | } |
| 2436 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2437 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2438 | public void removeWindowLocked(Session session, WindowState win) { |
| 2439 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2440 | if (localLOGV || DEBUG_FOCUS) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2441 | TAG, "Remove " + win + " client=" |
| 2442 | + Integer.toHexString(System.identityHashCode( |
| 2443 | win.mClient.asBinder())) |
| 2444 | + ", surface=" + win.mSurface); |
| 2445 | |
| 2446 | final long origId = Binder.clearCallingIdentity(); |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 2447 | |
| 2448 | win.disposeInputChannel(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2449 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2450 | if (DEBUG_APP_TRANSITIONS) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2451 | TAG, "Remove " + win + ": mSurface=" + win.mSurface |
| 2452 | + " mExiting=" + win.mExiting |
| 2453 | + " isAnimating=" + win.isAnimating() |
| 2454 | + " app-animation=" |
| 2455 | + (win.mAppToken != null ? win.mAppToken.animation : null) |
| 2456 | + " inPendingTransaction=" |
| 2457 | + (win.mAppToken != null ? win.mAppToken.inPendingTransaction : false) |
| 2458 | + " mDisplayFrozen=" + mDisplayFrozen); |
| 2459 | // Visibility of the removed window. Will be used later to update orientation later on. |
| 2460 | boolean wasVisible = false; |
| 2461 | // First, see if we need to run an animation. If we do, we have |
| 2462 | // to hold off on removing the window until the animation is done. |
| 2463 | // If the display is frozen, just remove immediately, since the |
| 2464 | // animation wouldn't be seen. |
Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 2465 | if (win.mSurface != null && !mDisplayFrozen && mPolicy.isScreenOn()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2466 | // If we are not currently running the exit animation, we |
| 2467 | // need to see about starting one. |
| 2468 | if (wasVisible=win.isWinVisibleLw()) { |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2469 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2470 | int transit = WindowManagerPolicy.TRANSIT_EXIT; |
| 2471 | if (win.getAttrs().type == TYPE_APPLICATION_STARTING) { |
| 2472 | transit = WindowManagerPolicy.TRANSIT_PREVIEW_DONE; |
| 2473 | } |
| 2474 | // Try starting an animation. |
| 2475 | if (applyAnimationLocked(win, transit, false)) { |
| 2476 | win.mExiting = true; |
| 2477 | } |
| 2478 | } |
| 2479 | if (win.mExiting || win.isAnimating()) { |
| 2480 | // The exit animation is running... wait for it! |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2481 | //Slog.i(TAG, "*** Running exit animation..."); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2482 | win.mExiting = true; |
| 2483 | win.mRemoveOnExit = true; |
| 2484 | mLayoutNeeded = true; |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 2485 | updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES, |
| 2486 | false /*updateInputWindows*/); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2487 | performLayoutAndPlaceSurfacesLocked(); |
Jeff Brown | 2e44b07 | 2011-01-24 15:21:56 -0800 | [diff] [blame^] | 2488 | mInputMonitor.updateInputWindowsLw(false /*force*/); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2489 | if (win.mAppToken != null) { |
| 2490 | win.mAppToken.updateReportedVisibilityLocked(); |
| 2491 | } |
| 2492 | //dump(); |
| 2493 | Binder.restoreCallingIdentity(origId); |
| 2494 | return; |
| 2495 | } |
| 2496 | } |
| 2497 | |
| 2498 | removeWindowInnerLocked(session, win); |
| 2499 | // Removing a visible window will effect the computed orientation |
| 2500 | // So just update orientation if needed. |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 2501 | if (wasVisible && computeForcedAppOrientationLocked() |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2502 | != mForcedAppOrientation |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 2503 | && updateOrientationFromAppTokensLocked(false)) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2504 | mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2505 | } |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 2506 | updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL, true /*updateInputWindows*/); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2507 | Binder.restoreCallingIdentity(origId); |
| 2508 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2509 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2510 | private void removeWindowInnerLocked(Session session, WindowState win) { |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 2511 | if (win.mRemoved) { |
| 2512 | // Nothing to do. |
| 2513 | return; |
| 2514 | } |
| 2515 | |
| 2516 | for (int i=win.mChildWindows.size()-1; i>=0; i--) { |
| 2517 | WindowState cwin = win.mChildWindows.get(i); |
| 2518 | Slog.w(TAG, "Force-removing child win " + cwin + " from container " |
| 2519 | + win); |
| 2520 | removeWindowInnerLocked(cwin.mSession, cwin); |
| 2521 | } |
| 2522 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2523 | win.mRemoved = true; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2524 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2525 | if (mInputMethodTarget == win) { |
| 2526 | moveInputMethodWindowsIfNeededLocked(false); |
| 2527 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2528 | |
Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 2529 | if (false) { |
| 2530 | RuntimeException e = new RuntimeException("here"); |
| 2531 | e.fillInStackTrace(); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2532 | Slog.w(TAG, "Removing window " + win, e); |
Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 2533 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2534 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2535 | mPolicy.removeWindowLw(win); |
| 2536 | win.removeLocked(); |
| 2537 | |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 2538 | if (DEBUG_ADD_REMOVE) Slog.v(TAG, "removeWindowInnerLocked: " + win); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2539 | mWindowMap.remove(win.mClient.asBinder()); |
| 2540 | mWindows.remove(win); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 2541 | mPendingRemove.remove(win); |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 2542 | mWindowsChanged = true; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2543 | 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] | 2544 | |
| 2545 | if (mInputMethodWindow == win) { |
| 2546 | mInputMethodWindow = null; |
| 2547 | } else if (win.mAttrs.type == TYPE_INPUT_METHOD_DIALOG) { |
| 2548 | mInputMethodDialogs.remove(win); |
| 2549 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2550 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2551 | final WindowToken token = win.mToken; |
| 2552 | final AppWindowToken atoken = win.mAppToken; |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 2553 | 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] | 2554 | token.windows.remove(win); |
| 2555 | if (atoken != null) { |
| 2556 | atoken.allAppWindows.remove(win); |
| 2557 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2558 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2559 | TAG, "**** Removing window " + win + ": count=" |
| 2560 | + token.windows.size()); |
| 2561 | if (token.windows.size() == 0) { |
| 2562 | if (!token.explicit) { |
| 2563 | mTokenMap.remove(token.token); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2564 | } else if (atoken != null) { |
| 2565 | atoken.firstWindowDrawn = false; |
| 2566 | } |
| 2567 | } |
| 2568 | |
| 2569 | if (atoken != null) { |
| 2570 | if (atoken.startingWindow == win) { |
| 2571 | atoken.startingWindow = null; |
| 2572 | } else if (atoken.allAppWindows.size() == 0 && atoken.startingData != null) { |
| 2573 | // If this is the last window and we had requested a starting |
| 2574 | // transition window, well there is no point now. |
| 2575 | atoken.startingData = null; |
| 2576 | } else if (atoken.allAppWindows.size() == 1 && atoken.startingView != null) { |
| 2577 | // If this is the last window except for a starting transition |
| 2578 | // window, we need to get rid of the starting transition. |
| 2579 | if (DEBUG_STARTING_WINDOW) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2580 | Slog.v(TAG, "Schedule remove starting " + token |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2581 | + ": no more real windows"); |
| 2582 | } |
| 2583 | Message m = mH.obtainMessage(H.REMOVE_STARTING, atoken); |
| 2584 | mH.sendMessage(m); |
| 2585 | } |
| 2586 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2587 | |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 2588 | if (win.mAttrs.type == TYPE_WALLPAPER) { |
| 2589 | mLastWallpaperTimeoutTime = 0; |
| 2590 | adjustWallpaperWindowsLocked(); |
| 2591 | } else if ((win.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0) { |
Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 2592 | adjustWallpaperWindowsLocked(); |
| 2593 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2594 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2595 | if (!mInLayout) { |
| 2596 | assignLayersLocked(); |
| 2597 | mLayoutNeeded = true; |
| 2598 | performLayoutAndPlaceSurfacesLocked(); |
| 2599 | if (win.mAppToken != null) { |
| 2600 | win.mAppToken.updateReportedVisibilityLocked(); |
| 2601 | } |
| 2602 | } |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 2603 | |
Jeff Brown | 2e44b07 | 2011-01-24 15:21:56 -0800 | [diff] [blame^] | 2604 | mInputMonitor.updateInputWindowsLw(true /*force*/); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2605 | } |
| 2606 | |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 2607 | private static void logSurface(WindowState w, String msg, RuntimeException where) { |
| 2608 | String str = " SURFACE " + Integer.toHexString(w.hashCode()) |
| 2609 | + ": " + msg + " / " + w.mAttrs.getTitle(); |
| 2610 | if (where != null) { |
| 2611 | Slog.i(TAG, str, where); |
| 2612 | } else { |
| 2613 | Slog.i(TAG, str); |
| 2614 | } |
| 2615 | } |
| 2616 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2617 | private void setTransparentRegionWindow(Session session, IWindow client, Region region) { |
| 2618 | long origId = Binder.clearCallingIdentity(); |
| 2619 | try { |
| 2620 | synchronized (mWindowMap) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2621 | WindowState w = windowForClientLocked(session, client, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2622 | if ((w != null) && (w.mSurface != null)) { |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 2623 | if (SHOW_TRANSACTIONS) Slog.i(TAG, |
| 2624 | ">>> OPEN TRANSACTION setTransparentRegion"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2625 | Surface.openTransaction(); |
| 2626 | try { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 2627 | if (SHOW_TRANSACTIONS) logSurface(w, |
| 2628 | "transparentRegionHint=" + region, null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2629 | w.mSurface.setTransparentRegionHint(region); |
| 2630 | } finally { |
| 2631 | Surface.closeTransaction(); |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 2632 | if (SHOW_TRANSACTIONS) Slog.i(TAG, |
| 2633 | "<<< CLOSE TRANSACTION setTransparentRegion"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2634 | } |
| 2635 | } |
| 2636 | } |
| 2637 | } finally { |
| 2638 | Binder.restoreCallingIdentity(origId); |
| 2639 | } |
| 2640 | } |
| 2641 | |
| 2642 | void setInsetsWindow(Session session, IWindow client, |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2643 | int touchableInsets, Rect contentInsets, |
Jeff Brown | fbf0977 | 2011-01-16 14:06:57 -0800 | [diff] [blame] | 2644 | Rect visibleInsets, Region touchableRegion) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2645 | long origId = Binder.clearCallingIdentity(); |
| 2646 | try { |
| 2647 | synchronized (mWindowMap) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2648 | WindowState w = windowForClientLocked(session, client, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2649 | if (w != null) { |
| 2650 | w.mGivenInsetsPending = false; |
| 2651 | w.mGivenContentInsets.set(contentInsets); |
| 2652 | w.mGivenVisibleInsets.set(visibleInsets); |
Jeff Brown | fbf0977 | 2011-01-16 14:06:57 -0800 | [diff] [blame] | 2653 | w.mGivenTouchableRegion.set(touchableRegion); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2654 | w.mTouchableInsets = touchableInsets; |
| 2655 | mLayoutNeeded = true; |
| 2656 | performLayoutAndPlaceSurfacesLocked(); |
| 2657 | } |
| 2658 | } |
| 2659 | } finally { |
| 2660 | Binder.restoreCallingIdentity(origId); |
| 2661 | } |
| 2662 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2663 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2664 | public void getWindowDisplayFrame(Session session, IWindow client, |
| 2665 | Rect outDisplayFrame) { |
| 2666 | synchronized(mWindowMap) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2667 | WindowState win = windowForClientLocked(session, client, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2668 | if (win == null) { |
| 2669 | outDisplayFrame.setEmpty(); |
| 2670 | return; |
| 2671 | } |
| 2672 | outDisplayFrame.set(win.mDisplayFrame); |
| 2673 | } |
| 2674 | } |
| 2675 | |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 2676 | public void setWindowWallpaperPositionLocked(WindowState window, float x, float y, |
| 2677 | float xStep, float yStep) { |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 2678 | if (window.mWallpaperX != x || window.mWallpaperY != y) { |
| 2679 | window.mWallpaperX = x; |
| 2680 | window.mWallpaperY = y; |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 2681 | window.mWallpaperXStep = xStep; |
| 2682 | window.mWallpaperYStep = yStep; |
Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 2683 | if (updateWallpaperOffsetLocked(window, true)) { |
| 2684 | performLayoutAndPlaceSurfacesLocked(); |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 2685 | } |
| 2686 | } |
| 2687 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2688 | |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 2689 | void wallpaperCommandComplete(IBinder window, Bundle result) { |
| 2690 | synchronized (mWindowMap) { |
| 2691 | if (mWaitingOnWallpaper != null && |
| 2692 | mWaitingOnWallpaper.mClient.asBinder() == window) { |
| 2693 | mWaitingOnWallpaper = null; |
| 2694 | mWindowMap.notifyAll(); |
| 2695 | } |
| 2696 | } |
| 2697 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2698 | |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 2699 | public Bundle sendWindowWallpaperCommandLocked(WindowState window, |
| 2700 | String action, int x, int y, int z, Bundle extras, boolean sync) { |
| 2701 | if (window == mWallpaperTarget || window == mLowerWallpaperTarget |
| 2702 | || window == mUpperWallpaperTarget) { |
| 2703 | boolean doWait = sync; |
| 2704 | int curTokenIndex = mWallpaperTokens.size(); |
| 2705 | while (curTokenIndex > 0) { |
| 2706 | curTokenIndex--; |
| 2707 | WindowToken token = mWallpaperTokens.get(curTokenIndex); |
| 2708 | int curWallpaperIndex = token.windows.size(); |
| 2709 | while (curWallpaperIndex > 0) { |
| 2710 | curWallpaperIndex--; |
| 2711 | WindowState wallpaper = token.windows.get(curWallpaperIndex); |
| 2712 | try { |
| 2713 | wallpaper.mClient.dispatchWallpaperCommand(action, |
| 2714 | x, y, z, extras, sync); |
| 2715 | // We only want to be synchronous with one wallpaper. |
| 2716 | sync = false; |
| 2717 | } catch (RemoteException e) { |
| 2718 | } |
| 2719 | } |
| 2720 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2721 | |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 2722 | if (doWait) { |
| 2723 | // XXX Need to wait for result. |
| 2724 | } |
| 2725 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2726 | |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 2727 | return null; |
| 2728 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2729 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2730 | public int relayoutWindow(Session session, IWindow client, |
| 2731 | WindowManager.LayoutParams attrs, int requestedWidth, |
| 2732 | int requestedHeight, int viewVisibility, boolean insetsPending, |
| 2733 | Rect outFrame, Rect outContentInsets, Rect outVisibleInsets, |
Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 2734 | Configuration outConfig, Surface outSurface) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2735 | boolean displayed = false; |
| 2736 | boolean inTouchMode; |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2737 | boolean configChanged; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2738 | long origId = Binder.clearCallingIdentity(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2739 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2740 | synchronized(mWindowMap) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2741 | WindowState win = windowForClientLocked(session, client, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2742 | if (win == null) { |
| 2743 | return 0; |
| 2744 | } |
| 2745 | win.mRequestedWidth = requestedWidth; |
| 2746 | win.mRequestedHeight = requestedHeight; |
| 2747 | |
| 2748 | if (attrs != null) { |
| 2749 | mPolicy.adjustWindowParamsLw(attrs); |
| 2750 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2751 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2752 | int attrChanges = 0; |
| 2753 | int flagChanges = 0; |
| 2754 | if (attrs != null) { |
| 2755 | flagChanges = win.mAttrs.flags ^= attrs.flags; |
| 2756 | attrChanges = win.mAttrs.copyFrom(attrs); |
| 2757 | } |
| 2758 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2759 | 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] | 2760 | |
| 2761 | if ((attrChanges & WindowManager.LayoutParams.ALPHA_CHANGED) != 0) { |
| 2762 | win.mAlpha = attrs.alpha; |
| 2763 | } |
| 2764 | |
| 2765 | final boolean scaledWindow = |
| 2766 | ((win.mAttrs.flags & WindowManager.LayoutParams.FLAG_SCALED) != 0); |
| 2767 | |
| 2768 | if (scaledWindow) { |
| 2769 | // requested{Width|Height} Surface's physical size |
| 2770 | // attrs.{width|height} Size on screen |
| 2771 | win.mHScale = (attrs.width != requestedWidth) ? |
| 2772 | (attrs.width / (float)requestedWidth) : 1.0f; |
| 2773 | win.mVScale = (attrs.height != requestedHeight) ? |
| 2774 | (attrs.height / (float)requestedHeight) : 1.0f; |
Dianne Hackborn | 9b52a21 | 2009-12-11 14:51:35 -0800 | [diff] [blame] | 2775 | } else { |
| 2776 | win.mHScale = win.mVScale = 1; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2777 | } |
| 2778 | |
| 2779 | boolean imMayMove = (flagChanges&( |
| 2780 | WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM | |
| 2781 | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE)) != 0; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2782 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2783 | boolean focusMayChange = win.mViewVisibility != viewVisibility |
| 2784 | || ((flagChanges&WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) != 0) |
| 2785 | || (!win.mRelayoutCalled); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2786 | |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2787 | boolean wallpaperMayMove = win.mViewVisibility != viewVisibility |
| 2788 | && (win.mAttrs.flags & FLAG_SHOW_WALLPAPER) != 0; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2789 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2790 | win.mRelayoutCalled = true; |
| 2791 | final int oldVisibility = win.mViewVisibility; |
| 2792 | win.mViewVisibility = viewVisibility; |
| 2793 | if (viewVisibility == View.VISIBLE && |
| 2794 | (win.mAppToken == null || !win.mAppToken.clientHidden)) { |
| 2795 | displayed = !win.isVisibleLw(); |
| 2796 | if (win.mExiting) { |
| 2797 | win.mExiting = false; |
Brad Fitzpatrick | 3fe3851 | 2010-11-03 11:46:54 -0700 | [diff] [blame] | 2798 | if (win.mAnimation != null) { |
| 2799 | win.mAnimation.cancel(); |
| 2800 | win.mAnimation = null; |
| 2801 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2802 | } |
| 2803 | if (win.mDestroying) { |
| 2804 | win.mDestroying = false; |
| 2805 | mDestroySurface.remove(win); |
| 2806 | } |
| 2807 | if (oldVisibility == View.GONE) { |
| 2808 | win.mEnterAnimationPending = true; |
| 2809 | } |
Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 2810 | if (displayed) { |
| 2811 | if (win.mSurface != null && !win.mDrawPending |
| 2812 | && !win.mCommitDrawPending && !mDisplayFrozen |
| 2813 | && mPolicy.isScreenOn()) { |
| 2814 | applyEnterAnimationLocked(win); |
| 2815 | } |
| 2816 | if ((win.mAttrs.flags |
| 2817 | & WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON) != 0) { |
| 2818 | if (DEBUG_VISIBILITY) Slog.v(TAG, |
| 2819 | "Relayout window turning screen on: " + win); |
| 2820 | win.mTurnOnScreen = true; |
| 2821 | } |
| 2822 | int diff = 0; |
| 2823 | if (win.mConfiguration != mCurConfiguration |
| 2824 | && (win.mConfiguration == null |
| 2825 | || (diff=mCurConfiguration.diff(win.mConfiguration)) != 0)) { |
| 2826 | win.mConfiguration = mCurConfiguration; |
| 2827 | if (DEBUG_CONFIGURATION) { |
| 2828 | Slog.i(TAG, "Window " + win + " visible with new config: " |
| 2829 | + win.mConfiguration + " / 0x" |
| 2830 | + Integer.toHexString(diff)); |
| 2831 | } |
| 2832 | outConfig.setTo(mCurConfiguration); |
| 2833 | } |
Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 2834 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2835 | if ((attrChanges&WindowManager.LayoutParams.FORMAT_CHANGED) != 0) { |
| 2836 | // To change the format, we need to re-build the surface. |
| 2837 | win.destroySurfaceLocked(); |
| 2838 | displayed = true; |
| 2839 | } |
| 2840 | try { |
| 2841 | Surface surface = win.createSurfaceLocked(); |
| 2842 | if (surface != null) { |
| 2843 | outSurface.copyFrom(surface); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2844 | win.mReportDestroySurface = false; |
| 2845 | win.mSurfacePendingDestroy = false; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2846 | if (SHOW_TRANSACTIONS) Slog.i(TAG, |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 2847 | " OUT SURFACE " + outSurface + ": copied"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2848 | } else { |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 2849 | // For some reason there isn't a surface. Clear the |
| 2850 | // caller's object so they see the same state. |
| 2851 | outSurface.release(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2852 | } |
| 2853 | } catch (Exception e) { |
Jeff Brown | 2e44b07 | 2011-01-24 15:21:56 -0800 | [diff] [blame^] | 2854 | mInputMonitor.updateInputWindowsLw(true /*force*/); |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 2855 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2856 | Slog.w(TAG, "Exception thrown when creating surface for client " |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 2857 | + client + " (" + win.mAttrs.getTitle() + ")", |
| 2858 | e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2859 | Binder.restoreCallingIdentity(origId); |
| 2860 | return 0; |
| 2861 | } |
| 2862 | if (displayed) { |
| 2863 | focusMayChange = true; |
| 2864 | } |
| 2865 | if (win.mAttrs.type == TYPE_INPUT_METHOD |
| 2866 | && mInputMethodWindow == null) { |
| 2867 | mInputMethodWindow = win; |
| 2868 | imMayMove = true; |
| 2869 | } |
Dianne Hackborn | 558947c | 2009-12-18 16:02:50 -0800 | [diff] [blame] | 2870 | if (win.mAttrs.type == TYPE_BASE_APPLICATION |
| 2871 | && win.mAppToken != null |
| 2872 | && win.mAppToken.startingWindow != null) { |
| 2873 | // Special handling of starting window over the base |
| 2874 | // window of the app: propagate lock screen flags to it, |
| 2875 | // to provide the correct semantics while starting. |
| 2876 | final int mask = |
| 2877 | WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED |
Mike Lockwood | ef73162 | 2010-01-27 17:51:34 -0500 | [diff] [blame] | 2878 | | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD |
| 2879 | | WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON; |
Dianne Hackborn | 558947c | 2009-12-18 16:02:50 -0800 | [diff] [blame] | 2880 | WindowManager.LayoutParams sa = win.mAppToken.startingWindow.mAttrs; |
| 2881 | sa.flags = (sa.flags&~mask) | (win.mAttrs.flags&mask); |
| 2882 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2883 | } else { |
| 2884 | win.mEnterAnimationPending = false; |
| 2885 | if (win.mSurface != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2886 | if (DEBUG_VISIBILITY) Slog.i(TAG, "Relayout invis " + win |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2887 | + ": mExiting=" + win.mExiting |
| 2888 | + " mSurfacePendingDestroy=" + win.mSurfacePendingDestroy); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2889 | // If we are not currently running the exit animation, we |
| 2890 | // need to see about starting one. |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2891 | if (!win.mExiting || win.mSurfacePendingDestroy) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2892 | // Try starting an animation; if there isn't one, we |
| 2893 | // can destroy the surface right away. |
| 2894 | int transit = WindowManagerPolicy.TRANSIT_EXIT; |
| 2895 | if (win.getAttrs().type == TYPE_APPLICATION_STARTING) { |
| 2896 | transit = WindowManagerPolicy.TRANSIT_PREVIEW_DONE; |
| 2897 | } |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2898 | if (!win.mSurfacePendingDestroy && win.isWinVisibleLw() && |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2899 | applyAnimationLocked(win, transit, false)) { |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2900 | focusMayChange = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2901 | win.mExiting = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2902 | } else if (win.isAnimating()) { |
| 2903 | // Currently in a hide animation... turn this into |
| 2904 | // an exit. |
| 2905 | win.mExiting = true; |
Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 2906 | } else if (win == mWallpaperTarget) { |
| 2907 | // If the wallpaper is currently behind this |
| 2908 | // window, we need to change both of them inside |
| 2909 | // of a transaction to avoid artifacts. |
| 2910 | win.mExiting = true; |
| 2911 | win.mAnimating = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2912 | } else { |
| 2913 | if (mInputMethodWindow == win) { |
| 2914 | mInputMethodWindow = null; |
| 2915 | } |
| 2916 | win.destroySurfaceLocked(); |
| 2917 | } |
| 2918 | } |
| 2919 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2920 | |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2921 | if (win.mSurface == null || (win.getAttrs().flags |
| 2922 | & WindowManager.LayoutParams.FLAG_KEEP_SURFACE_WHILE_ANIMATING) == 0 |
| 2923 | || win.mSurfacePendingDestroy) { |
| 2924 | // We are being called from a local process, which |
| 2925 | // means outSurface holds its current surface. Ensure the |
| 2926 | // surface object is cleared, but we don't want it actually |
| 2927 | // destroyed at this point. |
| 2928 | win.mSurfacePendingDestroy = false; |
| 2929 | outSurface.release(); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2930 | if (DEBUG_VISIBILITY) Slog.i(TAG, "Releasing surface in: " + win); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2931 | } else if (win.mSurface != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2932 | if (DEBUG_VISIBILITY) Slog.i(TAG, |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2933 | "Keeping surface, will report destroy: " + win); |
| 2934 | win.mReportDestroySurface = true; |
| 2935 | outSurface.copyFrom(win.mSurface); |
| 2936 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2937 | } |
| 2938 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2939 | if (focusMayChange) { |
| 2940 | //System.out.println("Focus may change: " + win.mAttrs.getTitle()); |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 2941 | if (updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES, |
| 2942 | false /*updateInputWindows*/)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2943 | imMayMove = false; |
| 2944 | } |
| 2945 | //System.out.println("Relayout " + win + ": focus=" + mCurrentFocus); |
| 2946 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2947 | |
The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 2948 | // updateFocusedWindowLocked() already assigned layers so we only need to |
| 2949 | // reassign them at this point if the IM window state gets shuffled |
| 2950 | boolean assignLayers = false; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2951 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2952 | if (imMayMove) { |
Dianne Hackborn | 8abd5f0 | 2009-11-20 18:09:03 -0800 | [diff] [blame] | 2953 | if (moveInputMethodWindowsIfNeededLocked(false) || displayed) { |
| 2954 | // Little hack here -- we -should- be able to rely on the |
| 2955 | // function to return true if the IME has moved and needs |
| 2956 | // its layer recomputed. However, if the IME was hidden |
| 2957 | // and isn't actually moved in the list, its layer may be |
| 2958 | // 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] | 2959 | assignLayers = true; |
| 2960 | } |
| 2961 | } |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2962 | if (wallpaperMayMove) { |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 2963 | if ((adjustWallpaperWindowsLocked()&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) { |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2964 | assignLayers = true; |
| 2965 | } |
| 2966 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2967 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2968 | mLayoutNeeded = true; |
| 2969 | win.mGivenInsetsPending = insetsPending; |
| 2970 | if (assignLayers) { |
| 2971 | assignLayersLocked(); |
| 2972 | } |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 2973 | configChanged = updateOrientationFromAppTokensLocked(false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2974 | performLayoutAndPlaceSurfacesLocked(); |
Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 2975 | if (displayed && win.mIsWallpaper) { |
| 2976 | updateWallpaperOffsetLocked(win, mDisplay.getWidth(), |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 2977 | mDisplay.getHeight(), false); |
Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 2978 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2979 | if (win.mAppToken != null) { |
| 2980 | win.mAppToken.updateReportedVisibilityLocked(); |
| 2981 | } |
| 2982 | outFrame.set(win.mFrame); |
| 2983 | outContentInsets.set(win.mContentInsets); |
| 2984 | outVisibleInsets.set(win.mVisibleInsets); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2985 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2986 | TAG, "Relayout given client " + client.asBinder() |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2987 | + ", requestedWidth=" + requestedWidth |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2988 | + ", requestedHeight=" + requestedHeight |
| 2989 | + ", viewVisibility=" + viewVisibility |
| 2990 | + "\nRelayout returning frame=" + outFrame |
| 2991 | + ", surface=" + outSurface); |
| 2992 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2993 | if (localLOGV || DEBUG_FOCUS) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2994 | TAG, "Relayout of " + win + ": focusMayChange=" + focusMayChange); |
| 2995 | |
| 2996 | inTouchMode = mInTouchMode; |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 2997 | |
Jeff Brown | 2e44b07 | 2011-01-24 15:21:56 -0800 | [diff] [blame^] | 2998 | mInputMonitor.updateInputWindowsLw(true /*force*/); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2999 | } |
| 3000 | |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3001 | if (configChanged) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3002 | sendNewConfiguration(); |
| 3003 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3004 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3005 | Binder.restoreCallingIdentity(origId); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3006 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3007 | return (inTouchMode ? WindowManagerImpl.RELAYOUT_IN_TOUCH_MODE : 0) |
| 3008 | | (displayed ? WindowManagerImpl.RELAYOUT_FIRST_TIME : 0); |
| 3009 | } |
| 3010 | |
| 3011 | public void finishDrawingWindow(Session session, IWindow client) { |
| 3012 | final long origId = Binder.clearCallingIdentity(); |
| 3013 | synchronized(mWindowMap) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3014 | WindowState win = windowForClientLocked(session, client, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3015 | if (win != null && win.finishDrawingLocked()) { |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 3016 | if ((win.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0) { |
| 3017 | adjustWallpaperWindowsLocked(); |
| 3018 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3019 | mLayoutNeeded = true; |
| 3020 | performLayoutAndPlaceSurfacesLocked(); |
| 3021 | } |
| 3022 | } |
| 3023 | Binder.restoreCallingIdentity(origId); |
| 3024 | } |
| 3025 | |
| 3026 | private AttributeCache.Entry getCachedAnimations(WindowManager.LayoutParams lp) { |
Dianne Hackborn | 08121bc | 2011-01-17 17:54:31 -0800 | [diff] [blame] | 3027 | 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] | 3028 | + (lp != null ? lp.packageName : null) |
| 3029 | + " resId=0x" + (lp != null ? Integer.toHexString(lp.windowAnimations) : null)); |
| 3030 | if (lp != null && lp.windowAnimations != 0) { |
| 3031 | // If this is a system resource, don't try to load it from the |
| 3032 | // application resources. It is nice to avoid loading application |
| 3033 | // resources if we can. |
| 3034 | String packageName = lp.packageName != null ? lp.packageName : "android"; |
| 3035 | int resId = lp.windowAnimations; |
| 3036 | if ((resId&0xFF000000) == 0x01000000) { |
| 3037 | packageName = "android"; |
| 3038 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3039 | 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] | 3040 | + packageName); |
| 3041 | return AttributeCache.instance().get(packageName, resId, |
| 3042 | com.android.internal.R.styleable.WindowAnimation); |
| 3043 | } |
| 3044 | return null; |
| 3045 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3046 | |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 3047 | private AttributeCache.Entry getCachedAnimations(String packageName, int resId) { |
Dianne Hackborn | 08121bc | 2011-01-17 17:54:31 -0800 | [diff] [blame] | 3048 | if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: package=" |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 3049 | + packageName + " resId=0x" + Integer.toHexString(resId)); |
| 3050 | if (packageName != null) { |
| 3051 | if ((resId&0xFF000000) == 0x01000000) { |
| 3052 | packageName = "android"; |
| 3053 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3054 | if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: picked package=" |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 3055 | + packageName); |
| 3056 | return AttributeCache.instance().get(packageName, resId, |
| 3057 | com.android.internal.R.styleable.WindowAnimation); |
| 3058 | } |
| 3059 | return null; |
| 3060 | } |
| 3061 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3062 | private void applyEnterAnimationLocked(WindowState win) { |
| 3063 | int transit = WindowManagerPolicy.TRANSIT_SHOW; |
| 3064 | if (win.mEnterAnimationPending) { |
| 3065 | win.mEnterAnimationPending = false; |
| 3066 | transit = WindowManagerPolicy.TRANSIT_ENTER; |
| 3067 | } |
| 3068 | |
| 3069 | applyAnimationLocked(win, transit, true); |
| 3070 | } |
| 3071 | |
| 3072 | private boolean applyAnimationLocked(WindowState win, |
| 3073 | int transit, boolean isEntrance) { |
| 3074 | if (win.mLocalAnimating && win.mAnimationIsEntrance == isEntrance) { |
| 3075 | // If we are trying to apply an animation, but already running |
| 3076 | // an animation of the same type, then just leave that one alone. |
| 3077 | return true; |
| 3078 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3079 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3080 | // Only apply an animation if the display isn't frozen. If it is |
| 3081 | // frozen, there is no reason to animate and it can cause strange |
| 3082 | // artifacts when we unfreeze the display if some different animation |
| 3083 | // is running. |
Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 3084 | if (!mDisplayFrozen && mPolicy.isScreenOn()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3085 | int anim = mPolicy.selectAnimationLw(win, transit); |
| 3086 | int attr = -1; |
| 3087 | Animation a = null; |
| 3088 | if (anim != 0) { |
| 3089 | a = AnimationUtils.loadAnimation(mContext, anim); |
| 3090 | } else { |
| 3091 | switch (transit) { |
| 3092 | case WindowManagerPolicy.TRANSIT_ENTER: |
| 3093 | attr = com.android.internal.R.styleable.WindowAnimation_windowEnterAnimation; |
| 3094 | break; |
| 3095 | case WindowManagerPolicy.TRANSIT_EXIT: |
| 3096 | attr = com.android.internal.R.styleable.WindowAnimation_windowExitAnimation; |
| 3097 | break; |
| 3098 | case WindowManagerPolicy.TRANSIT_SHOW: |
| 3099 | attr = com.android.internal.R.styleable.WindowAnimation_windowShowAnimation; |
| 3100 | break; |
| 3101 | case WindowManagerPolicy.TRANSIT_HIDE: |
| 3102 | attr = com.android.internal.R.styleable.WindowAnimation_windowHideAnimation; |
| 3103 | break; |
| 3104 | } |
| 3105 | if (attr >= 0) { |
| 3106 | a = loadAnimation(win.mAttrs, attr); |
| 3107 | } |
| 3108 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3109 | if (DEBUG_ANIM) Slog.v(TAG, "applyAnimation: win=" + win |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3110 | + " anim=" + anim + " attr=0x" + Integer.toHexString(attr) |
| 3111 | + " mAnimation=" + win.mAnimation |
| 3112 | + " isEntrance=" + isEntrance); |
| 3113 | if (a != null) { |
| 3114 | if (DEBUG_ANIM) { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 3115 | RuntimeException e = null; |
| 3116 | if (!HIDE_STACK_CRAWLS) { |
| 3117 | e = new RuntimeException(); |
| 3118 | e.fillInStackTrace(); |
| 3119 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3120 | Slog.v(TAG, "Loaded animation " + a + " for " + win, e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3121 | } |
| 3122 | win.setAnimation(a); |
| 3123 | win.mAnimationIsEntrance = isEntrance; |
| 3124 | } |
| 3125 | } else { |
| 3126 | win.clearAnimation(); |
| 3127 | } |
| 3128 | |
| 3129 | return win.mAnimation != null; |
| 3130 | } |
| 3131 | |
| 3132 | private Animation loadAnimation(WindowManager.LayoutParams lp, int animAttr) { |
| 3133 | int anim = 0; |
| 3134 | Context context = mContext; |
| 3135 | if (animAttr >= 0) { |
| 3136 | AttributeCache.Entry ent = getCachedAnimations(lp); |
| 3137 | if (ent != null) { |
| 3138 | context = ent.context; |
| 3139 | anim = ent.array.getResourceId(animAttr, 0); |
| 3140 | } |
| 3141 | } |
| 3142 | if (anim != 0) { |
| 3143 | return AnimationUtils.loadAnimation(context, anim); |
| 3144 | } |
| 3145 | return null; |
| 3146 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3147 | |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 3148 | private Animation loadAnimation(String packageName, int resId) { |
| 3149 | int anim = 0; |
| 3150 | Context context = mContext; |
| 3151 | if (resId >= 0) { |
| 3152 | AttributeCache.Entry ent = getCachedAnimations(packageName, resId); |
| 3153 | if (ent != null) { |
| 3154 | context = ent.context; |
| 3155 | anim = resId; |
| 3156 | } |
| 3157 | } |
| 3158 | if (anim != 0) { |
| 3159 | return AnimationUtils.loadAnimation(context, anim); |
| 3160 | } |
| 3161 | return null; |
| 3162 | } |
| 3163 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3164 | private boolean applyAnimationLocked(AppWindowToken wtoken, |
| 3165 | WindowManager.LayoutParams lp, int transit, boolean enter) { |
| 3166 | // Only apply an animation if the display isn't frozen. If it is |
| 3167 | // frozen, there is no reason to animate and it can cause strange |
| 3168 | // artifacts when we unfreeze the display if some different animation |
| 3169 | // is running. |
Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 3170 | if (!mDisplayFrozen && mPolicy.isScreenOn()) { |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 3171 | Animation a; |
Mitsuru Oshima | d2967e2 | 2009-07-20 14:01:43 -0700 | [diff] [blame] | 3172 | if (lp != null && (lp.flags & FLAG_COMPATIBLE_WINDOW) != 0) { |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 3173 | a = new FadeInOutAnimation(enter); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3174 | if (DEBUG_ANIM) Slog.v(TAG, |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 3175 | "applying FadeInOutAnimation for a window in compatibility mode"); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 3176 | } else if (mNextAppTransitionPackage != null) { |
| 3177 | a = loadAnimation(mNextAppTransitionPackage, enter ? |
| 3178 | mNextAppTransitionEnter : mNextAppTransitionExit); |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 3179 | } else { |
| 3180 | int animAttr = 0; |
| 3181 | switch (transit) { |
| 3182 | case WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN: |
| 3183 | animAttr = enter |
| 3184 | ? com.android.internal.R.styleable.WindowAnimation_activityOpenEnterAnimation |
| 3185 | : com.android.internal.R.styleable.WindowAnimation_activityOpenExitAnimation; |
| 3186 | break; |
| 3187 | case WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE: |
| 3188 | animAttr = enter |
| 3189 | ? com.android.internal.R.styleable.WindowAnimation_activityCloseEnterAnimation |
| 3190 | : com.android.internal.R.styleable.WindowAnimation_activityCloseExitAnimation; |
| 3191 | break; |
| 3192 | case WindowManagerPolicy.TRANSIT_TASK_OPEN: |
| 3193 | animAttr = enter |
| 3194 | ? com.android.internal.R.styleable.WindowAnimation_taskOpenEnterAnimation |
| 3195 | : com.android.internal.R.styleable.WindowAnimation_taskOpenExitAnimation; |
| 3196 | break; |
| 3197 | case WindowManagerPolicy.TRANSIT_TASK_CLOSE: |
| 3198 | animAttr = enter |
| 3199 | ? com.android.internal.R.styleable.WindowAnimation_taskCloseEnterAnimation |
| 3200 | : com.android.internal.R.styleable.WindowAnimation_taskCloseExitAnimation; |
| 3201 | break; |
| 3202 | case WindowManagerPolicy.TRANSIT_TASK_TO_FRONT: |
| 3203 | animAttr = enter |
| 3204 | ? com.android.internal.R.styleable.WindowAnimation_taskToFrontEnterAnimation |
| 3205 | : com.android.internal.R.styleable.WindowAnimation_taskToFrontExitAnimation; |
| 3206 | break; |
| 3207 | case WindowManagerPolicy.TRANSIT_TASK_TO_BACK: |
| 3208 | animAttr = enter |
Mitsuru Oshima | 5a2b91d | 2009-07-16 16:30:02 -0700 | [diff] [blame] | 3209 | ? com.android.internal.R.styleable.WindowAnimation_taskToBackEnterAnimation |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 3210 | : com.android.internal.R.styleable.WindowAnimation_taskToBackExitAnimation; |
| 3211 | break; |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 3212 | case WindowManagerPolicy.TRANSIT_WALLPAPER_OPEN: |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 3213 | animAttr = enter |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 3214 | ? com.android.internal.R.styleable.WindowAnimation_wallpaperOpenEnterAnimation |
| 3215 | : com.android.internal.R.styleable.WindowAnimation_wallpaperOpenExitAnimation; |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 3216 | break; |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 3217 | case WindowManagerPolicy.TRANSIT_WALLPAPER_CLOSE: |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 3218 | animAttr = enter |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 3219 | ? com.android.internal.R.styleable.WindowAnimation_wallpaperCloseEnterAnimation |
| 3220 | : com.android.internal.R.styleable.WindowAnimation_wallpaperCloseExitAnimation; |
| 3221 | break; |
| 3222 | case WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_OPEN: |
| 3223 | animAttr = enter |
| 3224 | ? com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenEnterAnimation |
| 3225 | : com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenExitAnimation; |
| 3226 | break; |
| 3227 | case WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_CLOSE: |
| 3228 | animAttr = enter |
| 3229 | ? com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseEnterAnimation |
| 3230 | : com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseExitAnimation; |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 3231 | break; |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 3232 | } |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 3233 | a = animAttr != 0 ? loadAnimation(lp, animAttr) : null; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3234 | if (DEBUG_ANIM) Slog.v(TAG, "applyAnimation: wtoken=" + wtoken |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 3235 | + " anim=" + a |
| 3236 | + " animAttr=0x" + Integer.toHexString(animAttr) |
| 3237 | + " transit=" + transit); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3238 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3239 | if (a != null) { |
| 3240 | if (DEBUG_ANIM) { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 3241 | RuntimeException e = null; |
| 3242 | if (!HIDE_STACK_CRAWLS) { |
| 3243 | e = new RuntimeException(); |
| 3244 | e.fillInStackTrace(); |
| 3245 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3246 | Slog.v(TAG, "Loaded animation " + a + " for " + wtoken, e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3247 | } |
| 3248 | wtoken.setAnimation(a); |
| 3249 | } |
| 3250 | } else { |
| 3251 | wtoken.clearAnimation(); |
| 3252 | } |
| 3253 | |
| 3254 | return wtoken.animation != null; |
| 3255 | } |
| 3256 | |
| 3257 | // ------------------------------------------------------------- |
| 3258 | // Application Window Tokens |
| 3259 | // ------------------------------------------------------------- |
| 3260 | |
| 3261 | public void validateAppTokens(List tokens) { |
| 3262 | int v = tokens.size()-1; |
| 3263 | int m = mAppTokens.size()-1; |
| 3264 | while (v >= 0 && m >= 0) { |
| 3265 | AppWindowToken wtoken = mAppTokens.get(m); |
| 3266 | if (wtoken.removed) { |
| 3267 | m--; |
| 3268 | continue; |
| 3269 | } |
| 3270 | if (tokens.get(v) != wtoken.token) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3271 | 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] | 3272 | + " @ " + v + ", internal is " + wtoken.token + " @ " + m); |
| 3273 | } |
| 3274 | v--; |
| 3275 | m--; |
| 3276 | } |
| 3277 | while (v >= 0) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3278 | 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] | 3279 | v--; |
| 3280 | } |
| 3281 | while (m >= 0) { |
| 3282 | AppWindowToken wtoken = mAppTokens.get(m); |
| 3283 | if (!wtoken.removed) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3284 | Slog.w(TAG, "Invalid internal token: " + wtoken.token + " @ " + m); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3285 | } |
| 3286 | m--; |
| 3287 | } |
| 3288 | } |
| 3289 | |
| 3290 | boolean checkCallingPermission(String permission, String func) { |
| 3291 | // Quick check: if the calling permission is me, it's all okay. |
| 3292 | if (Binder.getCallingPid() == Process.myPid()) { |
| 3293 | return true; |
| 3294 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3295 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3296 | if (mContext.checkCallingPermission(permission) |
| 3297 | == PackageManager.PERMISSION_GRANTED) { |
| 3298 | return true; |
| 3299 | } |
| 3300 | String msg = "Permission Denial: " + func + " from pid=" |
| 3301 | + Binder.getCallingPid() |
| 3302 | + ", uid=" + Binder.getCallingUid() |
| 3303 | + " requires " + permission; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3304 | Slog.w(TAG, msg); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3305 | return false; |
| 3306 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3307 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3308 | AppWindowToken findAppWindowToken(IBinder token) { |
| 3309 | WindowToken wtoken = mTokenMap.get(token); |
| 3310 | if (wtoken == null) { |
| 3311 | return null; |
| 3312 | } |
| 3313 | return wtoken.appWindowToken; |
| 3314 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3315 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3316 | public void addWindowToken(IBinder token, int type) { |
| 3317 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3318 | "addWindowToken()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3319 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3320 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3321 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3322 | synchronized(mWindowMap) { |
| 3323 | WindowToken wtoken = mTokenMap.get(token); |
| 3324 | if (wtoken != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3325 | 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] | 3326 | return; |
| 3327 | } |
| 3328 | wtoken = new WindowToken(token, type, true); |
| 3329 | mTokenMap.put(token, wtoken); |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 3330 | if (type == TYPE_WALLPAPER) { |
| 3331 | mWallpaperTokens.add(wtoken); |
| 3332 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3333 | } |
| 3334 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3335 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3336 | public void removeWindowToken(IBinder token) { |
| 3337 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3338 | "removeWindowToken()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3339 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3340 | } |
| 3341 | |
| 3342 | final long origId = Binder.clearCallingIdentity(); |
| 3343 | synchronized(mWindowMap) { |
| 3344 | WindowToken wtoken = mTokenMap.remove(token); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3345 | if (wtoken != null) { |
| 3346 | boolean delayed = false; |
| 3347 | if (!wtoken.hidden) { |
| 3348 | wtoken.hidden = true; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3349 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3350 | final int N = wtoken.windows.size(); |
| 3351 | boolean changed = false; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3352 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3353 | for (int i=0; i<N; i++) { |
| 3354 | WindowState win = wtoken.windows.get(i); |
| 3355 | |
| 3356 | if (win.isAnimating()) { |
| 3357 | delayed = true; |
| 3358 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3359 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3360 | if (win.isVisibleNow()) { |
| 3361 | applyAnimationLocked(win, |
| 3362 | WindowManagerPolicy.TRANSIT_EXIT, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3363 | changed = true; |
| 3364 | } |
| 3365 | } |
| 3366 | |
| 3367 | if (changed) { |
| 3368 | mLayoutNeeded = true; |
| 3369 | performLayoutAndPlaceSurfacesLocked(); |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 3370 | updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL, |
| 3371 | false /*updateInputWindows*/); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3372 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3373 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3374 | if (delayed) { |
| 3375 | mExitingTokens.add(wtoken); |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 3376 | } else if (wtoken.windowType == TYPE_WALLPAPER) { |
| 3377 | mWallpaperTokens.remove(wtoken); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3378 | } |
| 3379 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3380 | |
Jeff Brown | 2e44b07 | 2011-01-24 15:21:56 -0800 | [diff] [blame^] | 3381 | mInputMonitor.updateInputWindowsLw(true /*force*/); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3382 | } else { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3383 | 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] | 3384 | } |
| 3385 | } |
| 3386 | Binder.restoreCallingIdentity(origId); |
| 3387 | } |
| 3388 | |
| 3389 | public void addAppToken(int addPos, IApplicationToken token, |
| 3390 | int groupId, int requestedOrientation, boolean fullscreen) { |
| 3391 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3392 | "addAppToken()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3393 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3394 | } |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 3395 | |
| 3396 | // Get the dispatching timeout here while we are not holding any locks so that it |
| 3397 | // can be cached by the AppWindowToken. The timeout value is used later by the |
| 3398 | // input dispatcher in code that does hold locks. If we did not cache the value |
| 3399 | // here we would run the chance of introducing a deadlock between the window manager |
| 3400 | // (which holds locks while updating the input dispatcher state) and the activity manager |
| 3401 | // (which holds locks while querying the application token). |
| 3402 | long inputDispatchingTimeoutNanos; |
| 3403 | try { |
| 3404 | inputDispatchingTimeoutNanos = token.getKeyDispatchingTimeout() * 1000000L; |
| 3405 | } catch (RemoteException ex) { |
| 3406 | Slog.w(TAG, "Could not get dispatching timeout.", ex); |
| 3407 | inputDispatchingTimeoutNanos = DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS; |
| 3408 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3409 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3410 | synchronized(mWindowMap) { |
| 3411 | AppWindowToken wtoken = findAppWindowToken(token.asBinder()); |
| 3412 | if (wtoken != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3413 | 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] | 3414 | return; |
| 3415 | } |
| 3416 | wtoken = new AppWindowToken(token); |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 3417 | wtoken.inputDispatchingTimeoutNanos = inputDispatchingTimeoutNanos; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3418 | wtoken.groupId = groupId; |
| 3419 | wtoken.appFullscreen = fullscreen; |
| 3420 | wtoken.requestedOrientation = requestedOrientation; |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 3421 | 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] | 3422 | mAppTokens.add(addPos, wtoken); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3423 | mTokenMap.put(token.asBinder(), wtoken); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3424 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3425 | // Application tokens start out hidden. |
| 3426 | wtoken.hidden = true; |
| 3427 | wtoken.hiddenRequested = true; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3428 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3429 | //dump(); |
| 3430 | } |
| 3431 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3432 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3433 | public void setAppGroupId(IBinder token, int groupId) { |
| 3434 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3435 | "setAppStartingIcon()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3436 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3437 | } |
| 3438 | |
| 3439 | synchronized(mWindowMap) { |
| 3440 | AppWindowToken wtoken = findAppWindowToken(token); |
| 3441 | if (wtoken == null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3442 | 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] | 3443 | return; |
| 3444 | } |
| 3445 | wtoken.groupId = groupId; |
| 3446 | } |
| 3447 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3448 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3449 | public int getOrientationFromWindowsLocked() { |
| 3450 | int pos = mWindows.size() - 1; |
| 3451 | while (pos >= 0) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 3452 | WindowState wtoken = mWindows.get(pos); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3453 | pos--; |
| 3454 | if (wtoken.mAppToken != null) { |
| 3455 | // We hit an application window. so the orientation will be determined by the |
| 3456 | // app window. No point in continuing further. |
| 3457 | return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
| 3458 | } |
Christopher Tate | b696aee | 2010-04-02 19:08:30 -0700 | [diff] [blame] | 3459 | if (!wtoken.isVisibleLw() || !wtoken.mPolicyVisibilityAfterAnim) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3460 | continue; |
| 3461 | } |
| 3462 | int req = wtoken.mAttrs.screenOrientation; |
| 3463 | if((req == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) || |
| 3464 | (req == ActivityInfo.SCREEN_ORIENTATION_BEHIND)){ |
| 3465 | continue; |
| 3466 | } else { |
| 3467 | return req; |
| 3468 | } |
| 3469 | } |
| 3470 | return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
| 3471 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3472 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3473 | public int getOrientationFromAppTokensLocked() { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3474 | int pos = mAppTokens.size() - 1; |
| 3475 | int curGroup = 0; |
| 3476 | int lastOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
| 3477 | boolean findingBehind = false; |
| 3478 | boolean haveGroup = false; |
| 3479 | boolean lastFullscreen = false; |
| 3480 | while (pos >= 0) { |
| 3481 | AppWindowToken wtoken = mAppTokens.get(pos); |
| 3482 | pos--; |
| 3483 | // if we're about to tear down this window and not seek for |
| 3484 | // the behind activity, don't use it for orientation |
| 3485 | if (!findingBehind |
| 3486 | && (!wtoken.hidden && wtoken.hiddenRequested)) { |
| 3487 | continue; |
| 3488 | } |
| 3489 | |
| 3490 | if (!haveGroup) { |
| 3491 | // We ignore any hidden applications on the top. |
| 3492 | if (wtoken.hiddenRequested || wtoken.willBeHidden) { |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3493 | continue; |
| 3494 | } |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3495 | haveGroup = true; |
| 3496 | curGroup = wtoken.groupId; |
| 3497 | lastOrientation = wtoken.requestedOrientation; |
| 3498 | } else if (curGroup != wtoken.groupId) { |
| 3499 | // If we have hit a new application group, and the bottom |
| 3500 | // of the previous group didn't explicitly say to use |
| 3501 | // the orientation behind it, and the last app was |
| 3502 | // full screen, then we'll stick with the |
| 3503 | // user's orientation. |
| 3504 | if (lastOrientation != ActivityInfo.SCREEN_ORIENTATION_BEHIND |
| 3505 | && lastFullscreen) { |
| 3506 | return lastOrientation; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3507 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3508 | } |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3509 | int or = wtoken.requestedOrientation; |
| 3510 | // If this application is fullscreen, and didn't explicitly say |
| 3511 | // to use the orientation behind it, then just take whatever |
| 3512 | // orientation it has and ignores whatever is under it. |
| 3513 | lastFullscreen = wtoken.appFullscreen; |
| 3514 | if (lastFullscreen |
| 3515 | && or != ActivityInfo.SCREEN_ORIENTATION_BEHIND) { |
| 3516 | return or; |
| 3517 | } |
| 3518 | // If this application has requested an explicit orientation, |
| 3519 | // then use it. |
Dianne Hackborn | e5439f2 | 2010-10-02 16:53:50 -0700 | [diff] [blame] | 3520 | if (or != ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED |
| 3521 | && or != ActivityInfo.SCREEN_ORIENTATION_BEHIND) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3522 | return or; |
| 3523 | } |
| 3524 | findingBehind |= (or == ActivityInfo.SCREEN_ORIENTATION_BEHIND); |
| 3525 | } |
| 3526 | return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3527 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3528 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3529 | public Configuration updateOrientationFromAppTokens( |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3530 | Configuration currentConfig, IBinder freezeThisOneIfNeeded) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3531 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3532 | "updateOrientationFromAppTokens()")) { |
| 3533 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| 3534 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3535 | |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3536 | Configuration config = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3537 | long ident = Binder.clearCallingIdentity(); |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3538 | |
| 3539 | synchronized(mWindowMap) { |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 3540 | if (updateOrientationFromAppTokensLocked(false)) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3541 | if (freezeThisOneIfNeeded != null) { |
| 3542 | AppWindowToken wtoken = findAppWindowToken( |
| 3543 | freezeThisOneIfNeeded); |
| 3544 | if (wtoken != null) { |
| 3545 | startAppFreezingScreenLocked(wtoken, |
| 3546 | ActivityInfo.CONFIG_ORIENTATION); |
| 3547 | } |
| 3548 | } |
| 3549 | config = computeNewConfigurationLocked(); |
| 3550 | |
| 3551 | } else if (currentConfig != null) { |
| 3552 | // No obvious action we need to take, but if our current |
Casey Burkhardt | 0920ba5 | 2010-08-03 12:04:19 -0700 | [diff] [blame] | 3553 | // state mismatches the activity manager's, update it, |
| 3554 | // disregarding font scale, which should remain set to |
| 3555 | // the value of the previous configuration. |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3556 | mTempConfiguration.setToDefaults(); |
Casey Burkhardt | 0920ba5 | 2010-08-03 12:04:19 -0700 | [diff] [blame] | 3557 | mTempConfiguration.fontScale = currentConfig.fontScale; |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3558 | if (computeNewConfigurationLocked(mTempConfiguration)) { |
| 3559 | if (currentConfig.diff(mTempConfiguration) != 0) { |
| 3560 | mWaitingForConfig = true; |
| 3561 | mLayoutNeeded = true; |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 3562 | startFreezingDisplayLocked(false); |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3563 | config = new Configuration(mTempConfiguration); |
| 3564 | } |
| 3565 | } |
| 3566 | } |
| 3567 | } |
| 3568 | |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3569 | Binder.restoreCallingIdentity(ident); |
| 3570 | return config; |
| 3571 | } |
| 3572 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3573 | /* |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3574 | * Determine the new desired orientation of the display, returning |
| 3575 | * a non-null new Configuration if it has changed from the current |
| 3576 | * orientation. IF TRUE IS RETURNED SOMEONE MUST CALL |
| 3577 | * setNewConfiguration() TO TELL THE WINDOW MANAGER IT CAN UNFREEZE THE |
| 3578 | * SCREEN. This will typically be done for you if you call |
| 3579 | * sendNewConfiguration(). |
| 3580 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3581 | * The orientation is computed from non-application windows first. If none of |
| 3582 | * the non-application windows specify orientation, the orientation is computed from |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3583 | * application tokens. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3584 | * @see android.view.IWindowManager#updateOrientationFromAppTokens( |
| 3585 | * android.os.IBinder) |
| 3586 | */ |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 3587 | boolean updateOrientationFromAppTokensLocked(boolean inTransaction) { |
| 3588 | if (mDisplayFrozen || mOpeningApps.size() > 0 || mClosingApps.size() > 0) { |
Christopher Tate | b696aee | 2010-04-02 19:08:30 -0700 | [diff] [blame] | 3589 | // If the display is frozen, some activities may be in the middle |
| 3590 | // of restarting, and thus have removed their old window. If the |
| 3591 | // window has the flag to hide the lock screen, then the lock screen |
| 3592 | // can re-appear and inflict its own orientation on us. Keep the |
| 3593 | // orientation stable until this all settles down. |
| 3594 | return false; |
| 3595 | } |
| 3596 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3597 | boolean changed = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3598 | long ident = Binder.clearCallingIdentity(); |
| 3599 | try { |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 3600 | int req = computeForcedAppOrientationLocked(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3601 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3602 | if (req != mForcedAppOrientation) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3603 | mForcedAppOrientation = req; |
| 3604 | //send a message to Policy indicating orientation change to take |
| 3605 | //action like disabling/enabling sensors etc., |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 3606 | mPolicy.setCurrentOrientationLw(req); |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3607 | if (setRotationUncheckedLocked(WindowManagerPolicy.USE_LAST_ROTATION, |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 3608 | mLastRotationFlags | Surface.FLAGS_ORIENTATION_ANIMATION_DISABLE, |
| 3609 | inTransaction)) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3610 | changed = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3611 | } |
| 3612 | } |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3613 | |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3614 | return changed; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3615 | } finally { |
| 3616 | Binder.restoreCallingIdentity(ident); |
| 3617 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3618 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3619 | |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 3620 | int computeForcedAppOrientationLocked() { |
| 3621 | int req = getOrientationFromWindowsLocked(); |
| 3622 | if (req == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) { |
| 3623 | req = getOrientationFromAppTokensLocked(); |
| 3624 | } |
| 3625 | return req; |
| 3626 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3627 | |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3628 | public void setNewConfiguration(Configuration config) { |
| 3629 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3630 | "setNewConfiguration()")) { |
| 3631 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| 3632 | } |
| 3633 | |
| 3634 | synchronized(mWindowMap) { |
| 3635 | mCurConfiguration = new Configuration(config); |
| 3636 | mWaitingForConfig = false; |
| 3637 | performLayoutAndPlaceSurfacesLocked(); |
| 3638 | } |
| 3639 | } |
| 3640 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3641 | public void setAppOrientation(IApplicationToken token, int requestedOrientation) { |
| 3642 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3643 | "setAppOrientation()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3644 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3645 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3646 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3647 | synchronized(mWindowMap) { |
| 3648 | AppWindowToken wtoken = findAppWindowToken(token.asBinder()); |
| 3649 | if (wtoken == null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3650 | 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] | 3651 | return; |
| 3652 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3653 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3654 | wtoken.requestedOrientation = requestedOrientation; |
| 3655 | } |
| 3656 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3657 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3658 | public int getAppOrientation(IApplicationToken token) { |
| 3659 | synchronized(mWindowMap) { |
| 3660 | AppWindowToken wtoken = findAppWindowToken(token.asBinder()); |
| 3661 | if (wtoken == null) { |
| 3662 | return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
| 3663 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3664 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3665 | return wtoken.requestedOrientation; |
| 3666 | } |
| 3667 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3668 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3669 | public void setFocusedApp(IBinder token, boolean moveFocusNow) { |
| 3670 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3671 | "setFocusedApp()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3672 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3673 | } |
| 3674 | |
| 3675 | synchronized(mWindowMap) { |
| 3676 | boolean changed = false; |
| 3677 | if (token == null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3678 | 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] | 3679 | changed = mFocusedApp != null; |
| 3680 | mFocusedApp = null; |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 3681 | if (changed) { |
| 3682 | mInputMonitor.setFocusedAppLw(null); |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 3683 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3684 | } else { |
| 3685 | AppWindowToken newFocus = findAppWindowToken(token); |
| 3686 | if (newFocus == null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3687 | 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] | 3688 | return; |
| 3689 | } |
| 3690 | changed = mFocusedApp != newFocus; |
| 3691 | mFocusedApp = newFocus; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3692 | if (DEBUG_FOCUS) Slog.v(TAG, "Set focused app to: " + mFocusedApp); |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 3693 | if (changed) { |
| 3694 | mInputMonitor.setFocusedAppLw(newFocus); |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 3695 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3696 | } |
| 3697 | |
| 3698 | if (moveFocusNow && changed) { |
| 3699 | final long origId = Binder.clearCallingIdentity(); |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 3700 | updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL, true /*updateInputWindows*/); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3701 | Binder.restoreCallingIdentity(origId); |
| 3702 | } |
| 3703 | } |
| 3704 | } |
| 3705 | |
Dianne Hackborn | 7da6ac3 | 2010-12-09 19:22:04 -0800 | [diff] [blame] | 3706 | public void prepareAppTransition(int transit, boolean alwaysKeepCurrent) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3707 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3708 | "prepareAppTransition()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3709 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 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 | synchronized(mWindowMap) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3713 | if (DEBUG_APP_TRANSITIONS) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3714 | TAG, "Prepare app transition: transit=" + transit |
| 3715 | + " mNextAppTransition=" + mNextAppTransition); |
Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 3716 | if (!mDisplayFrozen && mPolicy.isScreenOn()) { |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 3717 | if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET |
| 3718 | || mNextAppTransition == WindowManagerPolicy.TRANSIT_NONE) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3719 | mNextAppTransition = transit; |
Dianne Hackborn | 7da6ac3 | 2010-12-09 19:22:04 -0800 | [diff] [blame] | 3720 | } else if (!alwaysKeepCurrent) { |
| 3721 | if (transit == WindowManagerPolicy.TRANSIT_TASK_OPEN |
| 3722 | && mNextAppTransition == WindowManagerPolicy.TRANSIT_TASK_CLOSE) { |
| 3723 | // Opening a new task always supersedes a close for the anim. |
| 3724 | mNextAppTransition = transit; |
| 3725 | } else if (transit == WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN |
| 3726 | && mNextAppTransition == WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE) { |
| 3727 | // Opening a new activity always supersedes a close for the anim. |
| 3728 | mNextAppTransition = transit; |
| 3729 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3730 | } |
| 3731 | mAppTransitionReady = false; |
| 3732 | mAppTransitionTimeout = false; |
| 3733 | mStartingIconInTransition = false; |
| 3734 | mSkipAppTransitionAnimation = false; |
| 3735 | mH.removeMessages(H.APP_TRANSITION_TIMEOUT); |
| 3736 | mH.sendMessageDelayed(mH.obtainMessage(H.APP_TRANSITION_TIMEOUT), |
| 3737 | 5000); |
| 3738 | } |
| 3739 | } |
| 3740 | } |
| 3741 | |
| 3742 | public int getPendingAppTransition() { |
| 3743 | return mNextAppTransition; |
| 3744 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3745 | |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 3746 | public void overridePendingAppTransition(String packageName, |
| 3747 | int enterAnim, int exitAnim) { |
Dianne Hackborn | 8b571a8 | 2009-09-25 16:09:43 -0700 | [diff] [blame] | 3748 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 3749 | mNextAppTransitionPackage = packageName; |
| 3750 | mNextAppTransitionEnter = enterAnim; |
| 3751 | mNextAppTransitionExit = exitAnim; |
| 3752 | } |
| 3753 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3754 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3755 | public void executeAppTransition() { |
| 3756 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3757 | "executeAppTransition()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3758 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3759 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3760 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3761 | synchronized(mWindowMap) { |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 3762 | if (DEBUG_APP_TRANSITIONS) { |
| 3763 | RuntimeException e = new RuntimeException("here"); |
| 3764 | e.fillInStackTrace(); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3765 | Slog.w(TAG, "Execute app transition: mNextAppTransition=" |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 3766 | + mNextAppTransition, e); |
| 3767 | } |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 3768 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3769 | mAppTransitionReady = true; |
| 3770 | final long origId = Binder.clearCallingIdentity(); |
| 3771 | performLayoutAndPlaceSurfacesLocked(); |
| 3772 | Binder.restoreCallingIdentity(origId); |
| 3773 | } |
| 3774 | } |
| 3775 | } |
| 3776 | |
| 3777 | public void setAppStartingWindow(IBinder token, String pkg, |
| 3778 | int theme, CharSequence nonLocalizedLabel, int labelRes, int icon, |
Dianne Hackborn | 7eec10e | 2010-11-12 18:03:47 -0800 | [diff] [blame] | 3779 | int windowFlags, IBinder transferFrom, boolean createIfNeeded) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3780 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3781 | "setAppStartingIcon()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3782 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3783 | } |
| 3784 | |
| 3785 | synchronized(mWindowMap) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3786 | if (DEBUG_STARTING_WINDOW) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3787 | TAG, "setAppStartingIcon: token=" + token + " pkg=" + pkg |
| 3788 | + " transferFrom=" + transferFrom); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3789 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3790 | AppWindowToken wtoken = findAppWindowToken(token); |
| 3791 | if (wtoken == null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3792 | 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] | 3793 | return; |
| 3794 | } |
| 3795 | |
| 3796 | // If the display is frozen, we won't do anything until the |
| 3797 | // actual window is displayed so there is no reason to put in |
| 3798 | // the starting window. |
Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 3799 | if (mDisplayFrozen || !mPolicy.isScreenOn()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3800 | return; |
| 3801 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3802 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3803 | if (wtoken.startingData != null) { |
| 3804 | return; |
| 3805 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3806 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3807 | if (transferFrom != null) { |
| 3808 | AppWindowToken ttoken = findAppWindowToken(transferFrom); |
| 3809 | if (ttoken != null) { |
| 3810 | WindowState startingWindow = ttoken.startingWindow; |
| 3811 | if (startingWindow != null) { |
| 3812 | if (mStartingIconInTransition) { |
| 3813 | // In this case, the starting icon has already |
| 3814 | // been displayed, so start letting windows get |
| 3815 | // shown immediately without any more transitions. |
| 3816 | mSkipAppTransitionAnimation = true; |
| 3817 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3818 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3819 | "Moving existing starting from " + ttoken |
| 3820 | + " to " + wtoken); |
| 3821 | final long origId = Binder.clearCallingIdentity(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3822 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3823 | // Transfer the starting window over to the new |
| 3824 | // token. |
| 3825 | wtoken.startingData = ttoken.startingData; |
| 3826 | wtoken.startingView = ttoken.startingView; |
| 3827 | wtoken.startingWindow = startingWindow; |
| 3828 | ttoken.startingData = null; |
| 3829 | ttoken.startingView = null; |
| 3830 | ttoken.startingWindow = null; |
| 3831 | ttoken.startingMoved = true; |
| 3832 | startingWindow.mToken = wtoken; |
Dianne Hackborn | ef49c57 | 2009-03-24 19:27:32 -0700 | [diff] [blame] | 3833 | startingWindow.mRootToken = wtoken; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3834 | startingWindow.mAppToken = wtoken; |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 3835 | if (DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) Slog.v(TAG, |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 3836 | "Removing starting window: " + startingWindow); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3837 | mWindows.remove(startingWindow); |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 3838 | mWindowsChanged = true; |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 3839 | if (DEBUG_ADD_REMOVE) Slog.v(TAG, "Removing starting " + startingWindow |
| 3840 | + " from " + ttoken); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3841 | ttoken.windows.remove(startingWindow); |
| 3842 | ttoken.allAppWindows.remove(startingWindow); |
| 3843 | addWindowToListInOrderLocked(startingWindow, true); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3844 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3845 | // Propagate other interesting state between the |
| 3846 | // tokens. If the old token is displayed, we should |
| 3847 | // immediately force the new one to be displayed. If |
| 3848 | // it is animating, we need to move that animation to |
| 3849 | // the new one. |
| 3850 | if (ttoken.allDrawn) { |
| 3851 | wtoken.allDrawn = true; |
| 3852 | } |
| 3853 | if (ttoken.firstWindowDrawn) { |
| 3854 | wtoken.firstWindowDrawn = true; |
| 3855 | } |
| 3856 | if (!ttoken.hidden) { |
| 3857 | wtoken.hidden = false; |
| 3858 | wtoken.hiddenRequested = false; |
| 3859 | wtoken.willBeHidden = false; |
| 3860 | } |
| 3861 | if (wtoken.clientHidden != ttoken.clientHidden) { |
| 3862 | wtoken.clientHidden = ttoken.clientHidden; |
| 3863 | wtoken.sendAppVisibilityToClients(); |
| 3864 | } |
| 3865 | if (ttoken.animation != null) { |
| 3866 | wtoken.animation = ttoken.animation; |
| 3867 | wtoken.animating = ttoken.animating; |
| 3868 | wtoken.animLayerAdjustment = ttoken.animLayerAdjustment; |
| 3869 | ttoken.animation = null; |
| 3870 | ttoken.animLayerAdjustment = 0; |
| 3871 | wtoken.updateLayers(); |
| 3872 | ttoken.updateLayers(); |
| 3873 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3874 | |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 3875 | updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES, |
| 3876 | true /*updateInputWindows*/); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3877 | mLayoutNeeded = true; |
| 3878 | performLayoutAndPlaceSurfacesLocked(); |
| 3879 | Binder.restoreCallingIdentity(origId); |
| 3880 | return; |
| 3881 | } else if (ttoken.startingData != null) { |
| 3882 | // The previous app was getting ready to show a |
| 3883 | // starting window, but hasn't yet done so. Steal it! |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3884 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3885 | "Moving pending starting from " + ttoken |
| 3886 | + " to " + wtoken); |
| 3887 | wtoken.startingData = ttoken.startingData; |
| 3888 | ttoken.startingData = null; |
| 3889 | ttoken.startingMoved = true; |
| 3890 | Message m = mH.obtainMessage(H.ADD_STARTING, wtoken); |
| 3891 | // Note: we really want to do sendMessageAtFrontOfQueue() because we |
| 3892 | // want to process the message ASAP, before any other queued |
| 3893 | // messages. |
| 3894 | mH.sendMessageAtFrontOfQueue(m); |
| 3895 | return; |
| 3896 | } |
| 3897 | } |
| 3898 | } |
| 3899 | |
| 3900 | // There is no existing starting window, and the caller doesn't |
| 3901 | // want us to create one, so that's it! |
| 3902 | if (!createIfNeeded) { |
| 3903 | return; |
| 3904 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3905 | |
Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 3906 | // If this is a translucent or wallpaper window, then don't |
| 3907 | // show a starting window -- the current effect (a full-screen |
| 3908 | // opaque starting window that fades away to the real contents |
| 3909 | // when it is ready) does not work for this. |
| 3910 | if (theme != 0) { |
| 3911 | AttributeCache.Entry ent = AttributeCache.instance().get(pkg, theme, |
| 3912 | com.android.internal.R.styleable.Window); |
| 3913 | if (ent.array.getBoolean( |
| 3914 | com.android.internal.R.styleable.Window_windowIsTranslucent, false)) { |
| 3915 | return; |
| 3916 | } |
| 3917 | if (ent.array.getBoolean( |
Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 3918 | com.android.internal.R.styleable.Window_windowIsFloating, false)) { |
| 3919 | return; |
| 3920 | } |
| 3921 | if (ent.array.getBoolean( |
Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 3922 | com.android.internal.R.styleable.Window_windowShowWallpaper, false)) { |
| 3923 | return; |
| 3924 | } |
| 3925 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3926 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3927 | mStartingIconInTransition = true; |
| 3928 | wtoken.startingData = new StartingData( |
| 3929 | pkg, theme, nonLocalizedLabel, |
Dianne Hackborn | 7eec10e | 2010-11-12 18:03:47 -0800 | [diff] [blame] | 3930 | labelRes, icon, windowFlags); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3931 | Message m = mH.obtainMessage(H.ADD_STARTING, wtoken); |
| 3932 | // Note: we really want to do sendMessageAtFrontOfQueue() because we |
| 3933 | // want to process the message ASAP, before any other queued |
| 3934 | // messages. |
| 3935 | mH.sendMessageAtFrontOfQueue(m); |
| 3936 | } |
| 3937 | } |
| 3938 | |
| 3939 | public void setAppWillBeHidden(IBinder token) { |
| 3940 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3941 | "setAppWillBeHidden()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3942 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3943 | } |
| 3944 | |
| 3945 | AppWindowToken wtoken; |
| 3946 | |
| 3947 | synchronized(mWindowMap) { |
| 3948 | wtoken = findAppWindowToken(token); |
| 3949 | if (wtoken == null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3950 | 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] | 3951 | return; |
| 3952 | } |
| 3953 | wtoken.willBeHidden = true; |
| 3954 | } |
| 3955 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3956 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3957 | boolean setTokenVisibilityLocked(AppWindowToken wtoken, WindowManager.LayoutParams lp, |
| 3958 | boolean visible, int transit, boolean performLayout) { |
| 3959 | boolean delayed = false; |
| 3960 | |
| 3961 | if (wtoken.clientHidden == visible) { |
| 3962 | wtoken.clientHidden = !visible; |
| 3963 | wtoken.sendAppVisibilityToClients(); |
| 3964 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3965 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3966 | wtoken.willBeHidden = false; |
| 3967 | if (wtoken.hidden == visible) { |
| 3968 | final int N = wtoken.allAppWindows.size(); |
| 3969 | boolean changed = false; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3970 | if (DEBUG_APP_TRANSITIONS) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3971 | TAG, "Changing app " + wtoken + " hidden=" + wtoken.hidden |
| 3972 | + " performLayout=" + performLayout); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3973 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3974 | boolean runningAppAnimation = false; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3975 | |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 3976 | if (transit != WindowManagerPolicy.TRANSIT_UNSET) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3977 | if (wtoken.animation == sDummyAnimation) { |
| 3978 | wtoken.animation = null; |
| 3979 | } |
| 3980 | applyAnimationLocked(wtoken, lp, transit, visible); |
| 3981 | changed = true; |
| 3982 | if (wtoken.animation != null) { |
| 3983 | delayed = runningAppAnimation = true; |
| 3984 | } |
| 3985 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3986 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3987 | for (int i=0; i<N; i++) { |
| 3988 | WindowState win = wtoken.allAppWindows.get(i); |
| 3989 | if (win == wtoken.startingWindow) { |
| 3990 | continue; |
| 3991 | } |
| 3992 | |
| 3993 | if (win.isAnimating()) { |
| 3994 | delayed = true; |
| 3995 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3996 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3997 | //Slog.i(TAG, "Window " + win + ": vis=" + win.isVisible()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3998 | //win.dump(" "); |
| 3999 | if (visible) { |
| 4000 | if (!win.isVisibleNow()) { |
| 4001 | if (!runningAppAnimation) { |
| 4002 | applyAnimationLocked(win, |
| 4003 | WindowManagerPolicy.TRANSIT_ENTER, true); |
| 4004 | } |
| 4005 | changed = true; |
| 4006 | } |
| 4007 | } else if (win.isVisibleNow()) { |
| 4008 | if (!runningAppAnimation) { |
| 4009 | applyAnimationLocked(win, |
| 4010 | WindowManagerPolicy.TRANSIT_EXIT, false); |
| 4011 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4012 | changed = true; |
| 4013 | } |
| 4014 | } |
| 4015 | |
| 4016 | wtoken.hidden = wtoken.hiddenRequested = !visible; |
| 4017 | if (!visible) { |
| 4018 | unsetAppFreezingScreenLocked(wtoken, true, true); |
| 4019 | } else { |
| 4020 | // If we are being set visible, and the starting window is |
| 4021 | // not yet displayed, then make sure it doesn't get displayed. |
| 4022 | WindowState swin = wtoken.startingWindow; |
| 4023 | if (swin != null && (swin.mDrawPending |
| 4024 | || swin.mCommitDrawPending)) { |
| 4025 | swin.mPolicyVisibility = false; |
| 4026 | swin.mPolicyVisibilityAfterAnim = false; |
| 4027 | } |
| 4028 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4029 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4030 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "setTokenVisibilityLocked: " + wtoken |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4031 | + ": hidden=" + wtoken.hidden + " hiddenRequested=" |
| 4032 | + wtoken.hiddenRequested); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4033 | |
Dianne Hackborn | 9b52a21 | 2009-12-11 14:51:35 -0800 | [diff] [blame] | 4034 | if (changed) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4035 | mLayoutNeeded = true; |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 4036 | mInputMonitor.setUpdateInputWindowsNeededLw(); |
Dianne Hackborn | 9b52a21 | 2009-12-11 14:51:35 -0800 | [diff] [blame] | 4037 | if (performLayout) { |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 4038 | updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES, |
| 4039 | false /*updateInputWindows*/); |
Dianne Hackborn | 9b52a21 | 2009-12-11 14:51:35 -0800 | [diff] [blame] | 4040 | performLayoutAndPlaceSurfacesLocked(); |
| 4041 | } |
Jeff Brown | 2e44b07 | 2011-01-24 15:21:56 -0800 | [diff] [blame^] | 4042 | mInputMonitor.updateInputWindowsLw(false /*force*/); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4043 | } |
| 4044 | } |
| 4045 | |
| 4046 | if (wtoken.animation != null) { |
| 4047 | delayed = true; |
| 4048 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4049 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4050 | return delayed; |
| 4051 | } |
| 4052 | |
| 4053 | public void setAppVisibility(IBinder token, boolean visible) { |
| 4054 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 4055 | "setAppVisibility()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4056 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4057 | } |
| 4058 | |
| 4059 | AppWindowToken wtoken; |
| 4060 | |
| 4061 | synchronized(mWindowMap) { |
| 4062 | wtoken = findAppWindowToken(token); |
| 4063 | if (wtoken == null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4064 | 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] | 4065 | return; |
| 4066 | } |
| 4067 | |
| 4068 | if (DEBUG_APP_TRANSITIONS || DEBUG_ORIENTATION) { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 4069 | RuntimeException e = null; |
| 4070 | if (!HIDE_STACK_CRAWLS) { |
| 4071 | e = new RuntimeException(); |
| 4072 | e.fillInStackTrace(); |
| 4073 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4074 | Slog.v(TAG, "setAppVisibility(" + token + ", " + visible |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4075 | + "): mNextAppTransition=" + mNextAppTransition |
| 4076 | + " hidden=" + wtoken.hidden |
| 4077 | + " hiddenRequested=" + wtoken.hiddenRequested, e); |
| 4078 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4079 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4080 | // If we are preparing an app transition, then delay changing |
| 4081 | // the visibility of this token until we execute that transition. |
Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 4082 | if (!mDisplayFrozen && mPolicy.isScreenOn() |
| 4083 | && mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4084 | // Already in requested state, don't do anything more. |
| 4085 | if (wtoken.hiddenRequested != visible) { |
| 4086 | return; |
| 4087 | } |
| 4088 | wtoken.hiddenRequested = !visible; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4089 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4090 | if (DEBUG_APP_TRANSITIONS) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4091 | TAG, "Setting dummy animation on: " + wtoken); |
| 4092 | wtoken.setDummyAnimation(); |
| 4093 | mOpeningApps.remove(wtoken); |
| 4094 | mClosingApps.remove(wtoken); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4095 | wtoken.waitingToShow = wtoken.waitingToHide = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4096 | wtoken.inPendingTransaction = true; |
| 4097 | if (visible) { |
| 4098 | mOpeningApps.add(wtoken); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4099 | wtoken.startingDisplayed = false; |
| 4100 | wtoken.startingMoved = false; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 4101 | |
Dianne Hackborn | 195f6a0 | 2009-11-24 11:26:00 -0800 | [diff] [blame] | 4102 | // If the token is currently hidden (should be the |
| 4103 | // common case), then we need to set up to wait for |
| 4104 | // its windows to be ready. |
| 4105 | if (wtoken.hidden) { |
| 4106 | wtoken.allDrawn = false; |
| 4107 | wtoken.waitingToShow = true; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 4108 | |
Dianne Hackborn | 195f6a0 | 2009-11-24 11:26:00 -0800 | [diff] [blame] | 4109 | if (wtoken.clientHidden) { |
| 4110 | // In the case where we are making an app visible |
| 4111 | // but holding off for a transition, we still need |
| 4112 | // to tell the client to make its windows visible so |
| 4113 | // they get drawn. Otherwise, we will wait on |
| 4114 | // performing the transition until all windows have |
| 4115 | // been drawn, they never will be, and we are sad. |
| 4116 | wtoken.clientHidden = false; |
| 4117 | wtoken.sendAppVisibilityToClients(); |
| 4118 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4119 | } |
| 4120 | } else { |
| 4121 | mClosingApps.add(wtoken); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 4122 | |
Dianne Hackborn | 195f6a0 | 2009-11-24 11:26:00 -0800 | [diff] [blame] | 4123 | // If the token is currently visible (should be the |
| 4124 | // common case), then set up to wait for it to be hidden. |
| 4125 | if (!wtoken.hidden) { |
| 4126 | wtoken.waitingToHide = true; |
| 4127 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4128 | } |
| 4129 | return; |
| 4130 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4131 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4132 | final long origId = Binder.clearCallingIdentity(); |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 4133 | setTokenVisibilityLocked(wtoken, null, visible, WindowManagerPolicy.TRANSIT_UNSET, true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4134 | wtoken.updateReportedVisibilityLocked(); |
| 4135 | Binder.restoreCallingIdentity(origId); |
| 4136 | } |
| 4137 | } |
| 4138 | |
| 4139 | void unsetAppFreezingScreenLocked(AppWindowToken wtoken, |
| 4140 | boolean unfreezeSurfaceNow, boolean force) { |
| 4141 | if (wtoken.freezingScreen) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4142 | 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] | 4143 | + " force=" + force); |
| 4144 | final int N = wtoken.allAppWindows.size(); |
| 4145 | boolean unfrozeWindows = false; |
| 4146 | for (int i=0; i<N; i++) { |
| 4147 | WindowState w = wtoken.allAppWindows.get(i); |
| 4148 | if (w.mAppFreezing) { |
| 4149 | w.mAppFreezing = false; |
| 4150 | if (w.mSurface != null && !w.mOrientationChanging) { |
| 4151 | w.mOrientationChanging = true; |
| 4152 | } |
| 4153 | unfrozeWindows = true; |
| 4154 | } |
| 4155 | } |
| 4156 | if (force || unfrozeWindows) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4157 | 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] | 4158 | wtoken.freezingScreen = false; |
| 4159 | mAppsFreezingScreen--; |
| 4160 | } |
| 4161 | if (unfreezeSurfaceNow) { |
| 4162 | if (unfrozeWindows) { |
| 4163 | mLayoutNeeded = true; |
| 4164 | performLayoutAndPlaceSurfacesLocked(); |
| 4165 | } |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 4166 | stopFreezingDisplayLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4167 | } |
| 4168 | } |
| 4169 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4170 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4171 | public void startAppFreezingScreenLocked(AppWindowToken wtoken, |
| 4172 | int configChanges) { |
| 4173 | if (DEBUG_ORIENTATION) { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 4174 | RuntimeException e = null; |
| 4175 | if (!HIDE_STACK_CRAWLS) { |
| 4176 | e = new RuntimeException(); |
| 4177 | e.fillInStackTrace(); |
| 4178 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4179 | Slog.i(TAG, "Set freezing of " + wtoken.appToken |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4180 | + ": hidden=" + wtoken.hidden + " freezing=" |
| 4181 | + wtoken.freezingScreen, e); |
| 4182 | } |
| 4183 | if (!wtoken.hiddenRequested) { |
| 4184 | if (!wtoken.freezingScreen) { |
| 4185 | wtoken.freezingScreen = true; |
| 4186 | mAppsFreezingScreen++; |
| 4187 | if (mAppsFreezingScreen == 1) { |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 4188 | startFreezingDisplayLocked(false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4189 | mH.removeMessages(H.APP_FREEZE_TIMEOUT); |
| 4190 | mH.sendMessageDelayed(mH.obtainMessage(H.APP_FREEZE_TIMEOUT), |
| 4191 | 5000); |
| 4192 | } |
| 4193 | } |
| 4194 | final int N = wtoken.allAppWindows.size(); |
| 4195 | for (int i=0; i<N; i++) { |
| 4196 | WindowState w = wtoken.allAppWindows.get(i); |
| 4197 | w.mAppFreezing = true; |
| 4198 | } |
| 4199 | } |
| 4200 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4201 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4202 | public void startAppFreezingScreen(IBinder token, int configChanges) { |
| 4203 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 4204 | "setAppFreezingScreen()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4205 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4206 | } |
| 4207 | |
| 4208 | synchronized(mWindowMap) { |
Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 4209 | if (configChanges == 0 && !mDisplayFrozen && mPolicy.isScreenOn()) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4210 | 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] | 4211 | return; |
| 4212 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4213 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4214 | AppWindowToken wtoken = findAppWindowToken(token); |
| 4215 | if (wtoken == null || wtoken.appToken == null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4216 | 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] | 4217 | return; |
| 4218 | } |
| 4219 | final long origId = Binder.clearCallingIdentity(); |
| 4220 | startAppFreezingScreenLocked(wtoken, configChanges); |
| 4221 | Binder.restoreCallingIdentity(origId); |
| 4222 | } |
| 4223 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4224 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4225 | public void stopAppFreezingScreen(IBinder token, boolean force) { |
| 4226 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 4227 | "setAppFreezingScreen()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4228 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4229 | } |
| 4230 | |
| 4231 | synchronized(mWindowMap) { |
| 4232 | AppWindowToken wtoken = findAppWindowToken(token); |
| 4233 | if (wtoken == null || wtoken.appToken == null) { |
| 4234 | return; |
| 4235 | } |
| 4236 | final long origId = Binder.clearCallingIdentity(); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4237 | 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] | 4238 | + ": hidden=" + wtoken.hidden + " freezing=" + wtoken.freezingScreen); |
| 4239 | unsetAppFreezingScreenLocked(wtoken, true, force); |
| 4240 | Binder.restoreCallingIdentity(origId); |
| 4241 | } |
| 4242 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4243 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4244 | public void removeAppToken(IBinder token) { |
| 4245 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 4246 | "removeAppToken()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4247 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4248 | } |
| 4249 | |
| 4250 | AppWindowToken wtoken = null; |
| 4251 | AppWindowToken startingToken = null; |
| 4252 | boolean delayed = false; |
| 4253 | |
| 4254 | final long origId = Binder.clearCallingIdentity(); |
| 4255 | synchronized(mWindowMap) { |
| 4256 | WindowToken basewtoken = mTokenMap.remove(token); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4257 | if (basewtoken != null && (wtoken=basewtoken.appWindowToken) != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4258 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "Removing app token: " + wtoken); |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 4259 | delayed = setTokenVisibilityLocked(wtoken, null, false, WindowManagerPolicy.TRANSIT_UNSET, true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4260 | wtoken.inPendingTransaction = false; |
| 4261 | mOpeningApps.remove(wtoken); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4262 | wtoken.waitingToShow = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4263 | if (mClosingApps.contains(wtoken)) { |
| 4264 | delayed = true; |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 4265 | } else if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4266 | mClosingApps.add(wtoken); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4267 | wtoken.waitingToHide = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4268 | delayed = true; |
| 4269 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4270 | if (DEBUG_APP_TRANSITIONS) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4271 | TAG, "Removing app " + wtoken + " delayed=" + delayed |
| 4272 | + " animation=" + wtoken.animation |
| 4273 | + " animating=" + wtoken.animating); |
| 4274 | if (delayed) { |
| 4275 | // 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] | 4276 | if (DEBUG_ADD_REMOVE || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG, |
| 4277 | "removeAppToken make exiting: " + wtoken); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4278 | mExitingAppTokens.add(wtoken); |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 4279 | } else { |
| 4280 | // Make sure there is no animation running on this token, |
| 4281 | // so any windows associated with it will be removed as |
| 4282 | // soon as their animations are complete |
| 4283 | wtoken.animation = null; |
| 4284 | wtoken.animating = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4285 | } |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 4286 | if (DEBUG_ADD_REMOVE || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG, |
| 4287 | "removeAppToken: " + wtoken); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4288 | mAppTokens.remove(wtoken); |
| 4289 | wtoken.removed = true; |
| 4290 | if (wtoken.startingData != null) { |
| 4291 | startingToken = wtoken; |
| 4292 | } |
| 4293 | unsetAppFreezingScreenLocked(wtoken, true, true); |
| 4294 | if (mFocusedApp == wtoken) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4295 | 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] | 4296 | mFocusedApp = null; |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 4297 | updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL, true /*updateInputWindows*/); |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 4298 | mInputMonitor.setFocusedAppLw(null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4299 | } |
| 4300 | } else { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4301 | 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] | 4302 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4303 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4304 | if (!delayed && wtoken != null) { |
| 4305 | wtoken.updateReportedVisibilityLocked(); |
| 4306 | } |
| 4307 | } |
| 4308 | Binder.restoreCallingIdentity(origId); |
| 4309 | |
| 4310 | if (startingToken != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4311 | 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] | 4312 | + startingToken + ": app token removed"); |
| 4313 | Message m = mH.obtainMessage(H.REMOVE_STARTING, startingToken); |
| 4314 | mH.sendMessage(m); |
| 4315 | } |
| 4316 | } |
| 4317 | |
| 4318 | private boolean tmpRemoveAppWindowsLocked(WindowToken token) { |
| 4319 | final int NW = token.windows.size(); |
| 4320 | for (int i=0; i<NW; i++) { |
| 4321 | WindowState win = token.windows.get(i); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4322 | 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] | 4323 | mWindows.remove(win); |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 4324 | mWindowsChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4325 | int j = win.mChildWindows.size(); |
| 4326 | while (j > 0) { |
| 4327 | j--; |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 4328 | WindowState cwin = win.mChildWindows.get(j); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4329 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, |
Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 4330 | "Tmp removing child window " + cwin); |
| 4331 | mWindows.remove(cwin); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4332 | } |
| 4333 | } |
| 4334 | return NW > 0; |
| 4335 | } |
| 4336 | |
| 4337 | void dumpAppTokensLocked() { |
| 4338 | for (int i=mAppTokens.size()-1; i>=0; i--) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4339 | Slog.v(TAG, " #" + i + ": " + mAppTokens.get(i).token); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4340 | } |
| 4341 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4342 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4343 | void dumpWindowsLocked() { |
| 4344 | for (int i=mWindows.size()-1; i>=0; i--) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4345 | Slog.v(TAG, " #" + i + ": " + mWindows.get(i)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4346 | } |
| 4347 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4348 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4349 | private int findWindowOffsetLocked(int tokenPos) { |
| 4350 | final int NW = mWindows.size(); |
| 4351 | |
| 4352 | if (tokenPos >= mAppTokens.size()) { |
| 4353 | int i = NW; |
| 4354 | while (i > 0) { |
| 4355 | i--; |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 4356 | WindowState win = mWindows.get(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4357 | if (win.getAppToken() != null) { |
| 4358 | return i+1; |
| 4359 | } |
| 4360 | } |
| 4361 | } |
| 4362 | |
| 4363 | while (tokenPos > 0) { |
| 4364 | // Find the first app token below the new position that has |
| 4365 | // a window displayed. |
| 4366 | final AppWindowToken wtoken = mAppTokens.get(tokenPos-1); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4367 | 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] | 4368 | + tokenPos + " -- " + wtoken.token); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4369 | if (wtoken.sendingToBottom) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4370 | if (DEBUG_REORDER) Slog.v(TAG, |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4371 | "Skipping token -- currently sending to bottom"); |
| 4372 | tokenPos--; |
| 4373 | continue; |
| 4374 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4375 | int i = wtoken.windows.size(); |
| 4376 | while (i > 0) { |
| 4377 | i--; |
| 4378 | WindowState win = wtoken.windows.get(i); |
| 4379 | int j = win.mChildWindows.size(); |
| 4380 | while (j > 0) { |
| 4381 | j--; |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 4382 | WindowState cwin = win.mChildWindows.get(j); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4383 | if (cwin.mSubLayer >= 0) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4384 | for (int pos=NW-1; pos>=0; pos--) { |
| 4385 | if (mWindows.get(pos) == cwin) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4386 | if (DEBUG_REORDER) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4387 | "Found child win @" + (pos+1)); |
| 4388 | return pos+1; |
| 4389 | } |
| 4390 | } |
| 4391 | } |
| 4392 | } |
| 4393 | for (int pos=NW-1; pos>=0; pos--) { |
| 4394 | if (mWindows.get(pos) == win) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4395 | 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] | 4396 | return pos+1; |
| 4397 | } |
| 4398 | } |
| 4399 | } |
| 4400 | tokenPos--; |
| 4401 | } |
| 4402 | |
| 4403 | return 0; |
| 4404 | } |
| 4405 | |
| 4406 | private final int reAddWindowLocked(int index, WindowState win) { |
| 4407 | final int NCW = win.mChildWindows.size(); |
| 4408 | boolean added = false; |
| 4409 | for (int j=0; j<NCW; j++) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 4410 | WindowState cwin = win.mChildWindows.get(j); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4411 | if (!added && cwin.mSubLayer >= 0) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4412 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding child window at " |
Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 4413 | + index + ": " + cwin); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 4414 | win.mRebuilding = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4415 | mWindows.add(index, win); |
| 4416 | index++; |
| 4417 | added = true; |
| 4418 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4419 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding window at " |
Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 4420 | + index + ": " + cwin); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 4421 | cwin.mRebuilding = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4422 | mWindows.add(index, cwin); |
| 4423 | index++; |
| 4424 | } |
| 4425 | if (!added) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4426 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding window at " |
Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 4427 | + index + ": " + win); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 4428 | win.mRebuilding = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4429 | mWindows.add(index, win); |
| 4430 | index++; |
| 4431 | } |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 4432 | mWindowsChanged = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4433 | return index; |
| 4434 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4435 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4436 | private final int reAddAppWindowsLocked(int index, WindowToken token) { |
| 4437 | final int NW = token.windows.size(); |
| 4438 | for (int i=0; i<NW; i++) { |
| 4439 | index = reAddWindowLocked(index, token.windows.get(i)); |
| 4440 | } |
| 4441 | return index; |
| 4442 | } |
| 4443 | |
| 4444 | public void moveAppToken(int index, IBinder token) { |
| 4445 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 4446 | "moveAppToken()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4447 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4448 | } |
| 4449 | |
| 4450 | synchronized(mWindowMap) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4451 | if (DEBUG_REORDER) Slog.v(TAG, "Initial app tokens:"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4452 | if (DEBUG_REORDER) dumpAppTokensLocked(); |
| 4453 | final AppWindowToken wtoken = findAppWindowToken(token); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 4454 | if (DEBUG_TOKEN_MOVEMENT || DEBUG_REORDER) Slog.v(TAG, |
| 4455 | "Start moving token " + wtoken + " initially at " |
| 4456 | + mAppTokens.indexOf(wtoken)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4457 | if (wtoken == null || !mAppTokens.remove(wtoken)) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4458 | 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] | 4459 | + token + " (" + wtoken + ")"); |
| 4460 | return; |
| 4461 | } |
| 4462 | mAppTokens.add(index, wtoken); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4463 | if (DEBUG_REORDER) Slog.v(TAG, "Moved " + token + " to " + index + ":"); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 4464 | 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] | 4465 | if (DEBUG_REORDER) dumpAppTokensLocked(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4466 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4467 | final long origId = Binder.clearCallingIdentity(); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4468 | 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] | 4469 | if (DEBUG_REORDER) dumpWindowsLocked(); |
| 4470 | if (tmpRemoveAppWindowsLocked(wtoken)) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4471 | 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] | 4472 | if (DEBUG_REORDER) dumpWindowsLocked(); |
| 4473 | reAddAppWindowsLocked(findWindowOffsetLocked(index), wtoken); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4474 | if (DEBUG_REORDER) Slog.v(TAG, "Final window list:"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4475 | if (DEBUG_REORDER) dumpWindowsLocked(); |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 4476 | updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES, |
| 4477 | false /*updateInputWindows*/); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4478 | mLayoutNeeded = true; |
Jeff Brown | 2e44b07 | 2011-01-24 15:21:56 -0800 | [diff] [blame^] | 4479 | mInputMonitor.setUpdateInputWindowsNeededLw(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4480 | performLayoutAndPlaceSurfacesLocked(); |
Jeff Brown | 2e44b07 | 2011-01-24 15:21:56 -0800 | [diff] [blame^] | 4481 | mInputMonitor.updateInputWindowsLw(false /*force*/); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4482 | } |
| 4483 | Binder.restoreCallingIdentity(origId); |
| 4484 | } |
| 4485 | } |
| 4486 | |
| 4487 | private void removeAppTokensLocked(List<IBinder> tokens) { |
| 4488 | // XXX This should be done more efficiently! |
| 4489 | // (take advantage of the fact that both lists should be |
| 4490 | // ordered in the same way.) |
| 4491 | int N = tokens.size(); |
| 4492 | for (int i=0; i<N; i++) { |
| 4493 | IBinder token = tokens.get(i); |
| 4494 | final AppWindowToken wtoken = findAppWindowToken(token); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 4495 | if (DEBUG_REORDER || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG, |
| 4496 | "Temporarily removing " + wtoken + " from " + mAppTokens.indexOf(wtoken)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4497 | if (!mAppTokens.remove(wtoken)) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4498 | 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] | 4499 | + token + " (" + wtoken + ")"); |
| 4500 | i--; |
| 4501 | N--; |
| 4502 | } |
| 4503 | } |
| 4504 | } |
| 4505 | |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4506 | private void moveAppWindowsLocked(AppWindowToken wtoken, int tokenPos, |
| 4507 | boolean updateFocusAndLayout) { |
| 4508 | // First remove all of the windows from the list. |
| 4509 | tmpRemoveAppWindowsLocked(wtoken); |
| 4510 | |
| 4511 | // Where to start adding? |
| 4512 | int pos = findWindowOffsetLocked(tokenPos); |
| 4513 | |
| 4514 | // And now add them back at the correct place. |
| 4515 | pos = reAddAppWindowsLocked(pos, wtoken); |
| 4516 | |
| 4517 | if (updateFocusAndLayout) { |
Jeff Brown | 2e44b07 | 2011-01-24 15:21:56 -0800 | [diff] [blame^] | 4518 | mInputMonitor.setUpdateInputWindowsNeededLw(); |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 4519 | if (!updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES, |
| 4520 | false /*updateInputWindows*/)) { |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4521 | assignLayersLocked(); |
| 4522 | } |
| 4523 | mLayoutNeeded = true; |
| 4524 | performLayoutAndPlaceSurfacesLocked(); |
Jeff Brown | 2e44b07 | 2011-01-24 15:21:56 -0800 | [diff] [blame^] | 4525 | mInputMonitor.updateInputWindowsLw(false /*force*/); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4526 | } |
| 4527 | } |
| 4528 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4529 | private void moveAppWindowsLocked(List<IBinder> tokens, int tokenPos) { |
| 4530 | // First remove all of the windows from the list. |
| 4531 | final int N = tokens.size(); |
| 4532 | int i; |
| 4533 | for (i=0; i<N; i++) { |
| 4534 | WindowToken token = mTokenMap.get(tokens.get(i)); |
| 4535 | if (token != null) { |
| 4536 | tmpRemoveAppWindowsLocked(token); |
| 4537 | } |
| 4538 | } |
| 4539 | |
| 4540 | // Where to start adding? |
| 4541 | int pos = findWindowOffsetLocked(tokenPos); |
| 4542 | |
| 4543 | // And now add them back at the correct place. |
| 4544 | for (i=0; i<N; i++) { |
| 4545 | WindowToken token = mTokenMap.get(tokens.get(i)); |
| 4546 | if (token != null) { |
| 4547 | pos = reAddAppWindowsLocked(pos, token); |
| 4548 | } |
| 4549 | } |
| 4550 | |
Jeff Brown | 2e44b07 | 2011-01-24 15:21:56 -0800 | [diff] [blame^] | 4551 | mInputMonitor.setUpdateInputWindowsNeededLw(); |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 4552 | if (!updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES, |
| 4553 | false /*updateInputWindows*/)) { |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4554 | assignLayersLocked(); |
| 4555 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4556 | mLayoutNeeded = true; |
| 4557 | performLayoutAndPlaceSurfacesLocked(); |
Jeff Brown | 2e44b07 | 2011-01-24 15:21:56 -0800 | [diff] [blame^] | 4558 | mInputMonitor.updateInputWindowsLw(false /*force*/); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4559 | |
| 4560 | //dump(); |
| 4561 | } |
| 4562 | |
| 4563 | public void moveAppTokensToTop(List<IBinder> tokens) { |
| 4564 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 4565 | "moveAppTokensToTop()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4566 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4567 | } |
| 4568 | |
| 4569 | final long origId = Binder.clearCallingIdentity(); |
| 4570 | synchronized(mWindowMap) { |
| 4571 | removeAppTokensLocked(tokens); |
| 4572 | final int N = tokens.size(); |
| 4573 | for (int i=0; i<N; i++) { |
| 4574 | AppWindowToken wt = findAppWindowToken(tokens.get(i)); |
| 4575 | if (wt != null) { |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 4576 | if (DEBUG_TOKEN_MOVEMENT || DEBUG_REORDER) Slog.v(TAG, |
| 4577 | "Adding next to top: " + wt); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4578 | mAppTokens.add(wt); |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 4579 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4580 | mToTopApps.remove(wt); |
| 4581 | mToBottomApps.remove(wt); |
| 4582 | mToTopApps.add(wt); |
| 4583 | wt.sendingToBottom = false; |
| 4584 | wt.sendingToTop = true; |
| 4585 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4586 | } |
| 4587 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 4588 | |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 4589 | if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET) { |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4590 | moveAppWindowsLocked(tokens, mAppTokens.size()); |
| 4591 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4592 | } |
| 4593 | Binder.restoreCallingIdentity(origId); |
| 4594 | } |
| 4595 | |
| 4596 | public void moveAppTokensToBottom(List<IBinder> tokens) { |
| 4597 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 4598 | "moveAppTokensToBottom()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4599 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4600 | } |
| 4601 | |
| 4602 | final long origId = Binder.clearCallingIdentity(); |
| 4603 | synchronized(mWindowMap) { |
| 4604 | removeAppTokensLocked(tokens); |
| 4605 | final int N = tokens.size(); |
| 4606 | int pos = 0; |
| 4607 | for (int i=0; i<N; i++) { |
| 4608 | AppWindowToken wt = findAppWindowToken(tokens.get(i)); |
| 4609 | if (wt != null) { |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 4610 | if (DEBUG_TOKEN_MOVEMENT) Slog.v(TAG, |
| 4611 | "Adding next to bottom: " + wt + " at " + pos); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4612 | mAppTokens.add(pos, wt); |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 4613 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4614 | mToTopApps.remove(wt); |
| 4615 | mToBottomApps.remove(wt); |
| 4616 | mToBottomApps.add(i, wt); |
| 4617 | wt.sendingToTop = false; |
| 4618 | wt.sendingToBottom = true; |
| 4619 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4620 | pos++; |
| 4621 | } |
| 4622 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 4623 | |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 4624 | if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET) { |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4625 | moveAppWindowsLocked(tokens, 0); |
| 4626 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4627 | } |
| 4628 | Binder.restoreCallingIdentity(origId); |
| 4629 | } |
| 4630 | |
| 4631 | // ------------------------------------------------------------- |
| 4632 | // Misc IWindowSession methods |
| 4633 | // ------------------------------------------------------------- |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4634 | |
Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 4635 | private boolean shouldAllowDisableKeyguard() |
Jim Miller | d6b5705 | 2010-06-07 17:52:42 -0700 | [diff] [blame] | 4636 | { |
Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 4637 | // We fail safe and prevent disabling keyguard in the unlikely event this gets |
| 4638 | // called before DevicePolicyManagerService has started. |
| 4639 | if (mAllowDisableKeyguard == ALLOW_DISABLE_UNKNOWN) { |
| 4640 | DevicePolicyManager dpm = (DevicePolicyManager) mContext.getSystemService( |
| 4641 | Context.DEVICE_POLICY_SERVICE); |
| 4642 | if (dpm != null) { |
| 4643 | mAllowDisableKeyguard = dpm.getPasswordQuality(null) |
| 4644 | == DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED ? |
| 4645 | ALLOW_DISABLE_YES : ALLOW_DISABLE_NO; |
| 4646 | } |
Jim Miller | d6b5705 | 2010-06-07 17:52:42 -0700 | [diff] [blame] | 4647 | } |
Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 4648 | return mAllowDisableKeyguard == ALLOW_DISABLE_YES; |
Jim Miller | d6b5705 | 2010-06-07 17:52:42 -0700 | [diff] [blame] | 4649 | } |
| 4650 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4651 | public void disableKeyguard(IBinder token, String tag) { |
Mike Lockwood | 733fdf3 | 2009-09-28 19:08:53 -0400 | [diff] [blame] | 4652 | if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4653 | != PackageManager.PERMISSION_GRANTED) { |
| 4654 | throw new SecurityException("Requires DISABLE_KEYGUARD permission"); |
| 4655 | } |
Jim Miller | d6b5705 | 2010-06-07 17:52:42 -0700 | [diff] [blame] | 4656 | |
Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 4657 | synchronized (mKeyguardTokenWatcher) { |
| 4658 | mKeyguardTokenWatcher.acquire(token, tag); |
Mike Lockwood | dd88468 | 2009-10-11 16:57:08 -0400 | [diff] [blame] | 4659 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4660 | } |
| 4661 | |
| 4662 | public void reenableKeyguard(IBinder token) { |
Mike Lockwood | 733fdf3 | 2009-09-28 19:08:53 -0400 | [diff] [blame] | 4663 | if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4664 | != PackageManager.PERMISSION_GRANTED) { |
| 4665 | throw new SecurityException("Requires DISABLE_KEYGUARD permission"); |
| 4666 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4667 | |
Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 4668 | synchronized (mKeyguardTokenWatcher) { |
| 4669 | mKeyguardTokenWatcher.release(token); |
Jim Miller | d6b5705 | 2010-06-07 17:52:42 -0700 | [diff] [blame] | 4670 | |
Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 4671 | if (!mKeyguardTokenWatcher.isAcquired()) { |
| 4672 | // If we are the last one to reenable the keyguard wait until |
| 4673 | // we have actually finished reenabling until returning. |
| 4674 | // It is possible that reenableKeyguard() can be called before |
| 4675 | // the previous disableKeyguard() is handled, in which case |
| 4676 | // neither mKeyguardTokenWatcher.acquired() or released() would |
| 4677 | // be called. In that case mKeyguardDisabled will be false here |
| 4678 | // and we have nothing to wait for. |
| 4679 | while (mKeyguardDisabled) { |
| 4680 | try { |
| 4681 | mKeyguardTokenWatcher.wait(); |
| 4682 | } catch (InterruptedException e) { |
| 4683 | Thread.currentThread().interrupt(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4684 | } |
| 4685 | } |
| 4686 | } |
| 4687 | } |
| 4688 | } |
| 4689 | |
| 4690 | /** |
| 4691 | * @see android.app.KeyguardManager#exitKeyguardSecurely |
| 4692 | */ |
| 4693 | public void exitKeyguardSecurely(final IOnKeyguardExitResult callback) { |
Mike Lockwood | 733fdf3 | 2009-09-28 19:08:53 -0400 | [diff] [blame] | 4694 | if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4695 | != PackageManager.PERMISSION_GRANTED) { |
| 4696 | throw new SecurityException("Requires DISABLE_KEYGUARD permission"); |
| 4697 | } |
| 4698 | mPolicy.exitKeyguardSecurely(new WindowManagerPolicy.OnKeyguardExitResult() { |
| 4699 | public void onKeyguardExitResult(boolean success) { |
| 4700 | try { |
| 4701 | callback.onKeyguardExitResult(success); |
| 4702 | } catch (RemoteException e) { |
| 4703 | // Client has died, we don't care. |
| 4704 | } |
| 4705 | } |
| 4706 | }); |
| 4707 | } |
| 4708 | |
| 4709 | public boolean inKeyguardRestrictedInputMode() { |
| 4710 | return mPolicy.inKeyguardRestrictedKeyInputMode(); |
| 4711 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4712 | |
Dianne Hackborn | ffa4248 | 2009-09-23 22:20:11 -0700 | [diff] [blame] | 4713 | public void closeSystemDialogs(String reason) { |
| 4714 | synchronized(mWindowMap) { |
| 4715 | for (int i=mWindows.size()-1; i>=0; i--) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 4716 | WindowState w = mWindows.get(i); |
Dianne Hackborn | ffa4248 | 2009-09-23 22:20:11 -0700 | [diff] [blame] | 4717 | if (w.mSurface != null) { |
| 4718 | try { |
| 4719 | w.mClient.closeSystemDialogs(reason); |
| 4720 | } catch (RemoteException e) { |
| 4721 | } |
| 4722 | } |
| 4723 | } |
| 4724 | } |
| 4725 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 4726 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4727 | static float fixScale(float scale) { |
| 4728 | if (scale < 0) scale = 0; |
| 4729 | else if (scale > 20) scale = 20; |
| 4730 | return Math.abs(scale); |
| 4731 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4732 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4733 | public void setAnimationScale(int which, float scale) { |
| 4734 | if (!checkCallingPermission(android.Manifest.permission.SET_ANIMATION_SCALE, |
| 4735 | "setAnimationScale()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4736 | throw new SecurityException("Requires SET_ANIMATION_SCALE permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4737 | } |
| 4738 | |
| 4739 | if (scale < 0) scale = 0; |
| 4740 | else if (scale > 20) scale = 20; |
| 4741 | scale = Math.abs(scale); |
| 4742 | switch (which) { |
| 4743 | case 0: mWindowAnimationScale = fixScale(scale); break; |
| 4744 | case 1: mTransitionAnimationScale = fixScale(scale); break; |
| 4745 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4746 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4747 | // Persist setting |
| 4748 | mH.obtainMessage(H.PERSIST_ANIMATION_SCALE).sendToTarget(); |
| 4749 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4750 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4751 | public void setAnimationScales(float[] scales) { |
| 4752 | if (!checkCallingPermission(android.Manifest.permission.SET_ANIMATION_SCALE, |
| 4753 | "setAnimationScale()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4754 | throw new SecurityException("Requires SET_ANIMATION_SCALE permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4755 | } |
| 4756 | |
| 4757 | if (scales != null) { |
| 4758 | if (scales.length >= 1) { |
| 4759 | mWindowAnimationScale = fixScale(scales[0]); |
| 4760 | } |
| 4761 | if (scales.length >= 2) { |
| 4762 | mTransitionAnimationScale = fixScale(scales[1]); |
| 4763 | } |
| 4764 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4765 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4766 | // Persist setting |
| 4767 | mH.obtainMessage(H.PERSIST_ANIMATION_SCALE).sendToTarget(); |
| 4768 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4769 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4770 | public float getAnimationScale(int which) { |
| 4771 | switch (which) { |
| 4772 | case 0: return mWindowAnimationScale; |
| 4773 | case 1: return mTransitionAnimationScale; |
| 4774 | } |
| 4775 | return 0; |
| 4776 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4777 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4778 | public float[] getAnimationScales() { |
| 4779 | return new float[] { mWindowAnimationScale, mTransitionAnimationScale }; |
| 4780 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4781 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4782 | public int getSwitchState(int sw) { |
| 4783 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4784 | "getSwitchState()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4785 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4786 | } |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 4787 | return mInputManager.getSwitchState(-1, InputDevice.SOURCE_ANY, sw); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4788 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4789 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4790 | public int getSwitchStateForDevice(int devid, int sw) { |
| 4791 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4792 | "getSwitchStateForDevice()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4793 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4794 | } |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 4795 | return mInputManager.getSwitchState(devid, InputDevice.SOURCE_ANY, sw); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4796 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4797 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4798 | public int getScancodeState(int sw) { |
| 4799 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4800 | "getScancodeState()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4801 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4802 | } |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 4803 | return mInputManager.getScanCodeState(-1, InputDevice.SOURCE_ANY, sw); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4804 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4805 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4806 | public int getScancodeStateForDevice(int devid, int sw) { |
| 4807 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4808 | "getScancodeStateForDevice()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4809 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4810 | } |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 4811 | return mInputManager.getScanCodeState(devid, InputDevice.SOURCE_ANY, sw); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4812 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4813 | |
Dianne Hackborn | 1d62ea9 | 2009-11-17 12:49:50 -0800 | [diff] [blame] | 4814 | public int getTrackballScancodeState(int sw) { |
| 4815 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4816 | "getTrackballScancodeState()")) { |
| 4817 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
| 4818 | } |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 4819 | return mInputManager.getScanCodeState(-1, InputDevice.SOURCE_TRACKBALL, sw); |
Dianne Hackborn | 1d62ea9 | 2009-11-17 12:49:50 -0800 | [diff] [blame] | 4820 | } |
| 4821 | |
| 4822 | public int getDPadScancodeState(int sw) { |
| 4823 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4824 | "getDPadScancodeState()")) { |
| 4825 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
| 4826 | } |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 4827 | return mInputManager.getScanCodeState(-1, InputDevice.SOURCE_DPAD, sw); |
Dianne Hackborn | 1d62ea9 | 2009-11-17 12:49:50 -0800 | [diff] [blame] | 4828 | } |
| 4829 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4830 | public int getKeycodeState(int sw) { |
| 4831 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4832 | "getKeycodeState()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4833 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4834 | } |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 4835 | return mInputManager.getKeyCodeState(-1, InputDevice.SOURCE_ANY, sw); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4836 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4837 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4838 | public int getKeycodeStateForDevice(int devid, int sw) { |
| 4839 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4840 | "getKeycodeStateForDevice()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4841 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4842 | } |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 4843 | return mInputManager.getKeyCodeState(devid, InputDevice.SOURCE_ANY, sw); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4844 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4845 | |
Dianne Hackborn | 1d62ea9 | 2009-11-17 12:49:50 -0800 | [diff] [blame] | 4846 | public int getTrackballKeycodeState(int sw) { |
| 4847 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4848 | "getTrackballKeycodeState()")) { |
| 4849 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
| 4850 | } |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 4851 | return mInputManager.getKeyCodeState(-1, InputDevice.SOURCE_TRACKBALL, sw); |
Dianne Hackborn | 1d62ea9 | 2009-11-17 12:49:50 -0800 | [diff] [blame] | 4852 | } |
| 4853 | |
| 4854 | public int getDPadKeycodeState(int sw) { |
| 4855 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4856 | "getDPadKeycodeState()")) { |
| 4857 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
| 4858 | } |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 4859 | return mInputManager.getKeyCodeState(-1, InputDevice.SOURCE_DPAD, sw); |
Dianne Hackborn | 1d62ea9 | 2009-11-17 12:49:50 -0800 | [diff] [blame] | 4860 | } |
Jeff Brown | a41ca77 | 2010-08-11 14:46:32 -0700 | [diff] [blame] | 4861 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4862 | public boolean hasKeys(int[] keycodes, boolean[] keyExists) { |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 4863 | return mInputManager.hasKeys(-1, InputDevice.SOURCE_ANY, keycodes, keyExists); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4864 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4865 | |
Jeff Brown | a41ca77 | 2010-08-11 14:46:32 -0700 | [diff] [blame] | 4866 | public InputChannel monitorInput(String inputChannelName) { |
| 4867 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4868 | "monitorInput()")) { |
| 4869 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
| 4870 | } |
| 4871 | return mInputManager.monitorInput(inputChannelName); |
| 4872 | } |
| 4873 | |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 4874 | public InputDevice getInputDevice(int deviceId) { |
| 4875 | return mInputManager.getInputDevice(deviceId); |
| 4876 | } |
| 4877 | |
| 4878 | public int[] getInputDeviceIds() { |
| 4879 | return mInputManager.getInputDeviceIds(); |
| 4880 | } |
| 4881 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4882 | public void enableScreenAfterBoot() { |
| 4883 | synchronized(mWindowMap) { |
| 4884 | if (mSystemBooted) { |
| 4885 | return; |
| 4886 | } |
| 4887 | mSystemBooted = true; |
| 4888 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4889 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4890 | performEnableScreen(); |
| 4891 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4892 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4893 | public void enableScreenIfNeededLocked() { |
| 4894 | if (mDisplayEnabled) { |
| 4895 | return; |
| 4896 | } |
| 4897 | if (!mSystemBooted) { |
| 4898 | return; |
| 4899 | } |
| 4900 | mH.sendMessage(mH.obtainMessage(H.ENABLE_SCREEN)); |
| 4901 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4902 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4903 | public void performEnableScreen() { |
| 4904 | synchronized(mWindowMap) { |
| 4905 | if (mDisplayEnabled) { |
| 4906 | return; |
| 4907 | } |
| 4908 | if (!mSystemBooted) { |
| 4909 | return; |
| 4910 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4911 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4912 | // Don't enable the screen until all existing windows |
| 4913 | // have been drawn. |
| 4914 | final int N = mWindows.size(); |
| 4915 | for (int i=0; i<N; i++) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 4916 | WindowState w = mWindows.get(i); |
Dianne Hackborn | f3bea9c | 2009-12-09 18:26:21 -0800 | [diff] [blame] | 4917 | if (w.isVisibleLw() && !w.mObscured && !w.isDrawnLw()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4918 | return; |
| 4919 | } |
| 4920 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4921 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4922 | mDisplayEnabled = true; |
| 4923 | if (false) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4924 | Slog.i(TAG, "ENABLING SCREEN!"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4925 | StringWriter sw = new StringWriter(); |
| 4926 | PrintWriter pw = new PrintWriter(sw); |
| 4927 | this.dump(null, pw, null); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4928 | Slog.i(TAG, sw.toString()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4929 | } |
| 4930 | try { |
| 4931 | IBinder surfaceFlinger = ServiceManager.getService("SurfaceFlinger"); |
| 4932 | if (surfaceFlinger != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4933 | //Slog.i(TAG, "******* TELLING SURFACE FLINGER WE ARE BOOTED!"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4934 | Parcel data = Parcel.obtain(); |
| 4935 | data.writeInterfaceToken("android.ui.ISurfaceComposer"); |
| 4936 | surfaceFlinger.transact(IBinder.FIRST_CALL_TRANSACTION, |
| 4937 | data, null, 0); |
| 4938 | data.recycle(); |
| 4939 | } |
| 4940 | } catch (RemoteException ex) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4941 | Slog.e(TAG, "Boot completed: SurfaceFlinger is dead!"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4942 | } |
| 4943 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4944 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4945 | mPolicy.enableScreenAfterBoot(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4946 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4947 | // Make sure the last requested orientation has been applied. |
Dianne Hackborn | 321ae68 | 2009-03-27 16:16:03 -0700 | [diff] [blame] | 4948 | setRotationUnchecked(WindowManagerPolicy.USE_LAST_ROTATION, false, |
| 4949 | mLastRotationFlags | Surface.FLAGS_ORIENTATION_ANIMATION_DISABLE); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4950 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4951 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4952 | public void setInTouchMode(boolean mode) { |
| 4953 | synchronized(mWindowMap) { |
| 4954 | mInTouchMode = mode; |
| 4955 | } |
| 4956 | } |
| 4957 | |
Brad Fitzpatrick | 6804433 | 2010-11-22 18:19:48 -0800 | [diff] [blame] | 4958 | // TODO: more accounting of which pid(s) turned it on, keep count, |
| 4959 | // only allow disables from pids which have count on, etc. |
| 4960 | public void showStrictModeViolation(boolean on) { |
| 4961 | int pid = Binder.getCallingPid(); |
| 4962 | synchronized(mWindowMap) { |
| 4963 | // Ignoring requests to enable the red border from clients |
| 4964 | // which aren't on screen. (e.g. Broadcast Receivers in |
| 4965 | // the background..) |
| 4966 | if (on) { |
| 4967 | boolean isVisible = false; |
| 4968 | for (WindowState ws : mWindows) { |
| 4969 | if (ws.mSession.mPid == pid && ws.isVisibleLw()) { |
| 4970 | isVisible = true; |
| 4971 | break; |
| 4972 | } |
| 4973 | } |
| 4974 | if (!isVisible) { |
| 4975 | return; |
| 4976 | } |
| 4977 | } |
| 4978 | |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 4979 | if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION showStrictModeViolation"); |
Brad Fitzpatrick | 6804433 | 2010-11-22 18:19:48 -0800 | [diff] [blame] | 4980 | Surface.openTransaction(); |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 4981 | try { |
| 4982 | if (mStrictModeFlash == null) { |
| 4983 | mStrictModeFlash = new StrictModeFlash(mDisplay, mFxSession); |
| 4984 | } |
| 4985 | mStrictModeFlash.setVisibility(on); |
| 4986 | } finally { |
| 4987 | Surface.closeTransaction(); |
| 4988 | if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION showStrictModeViolation"); |
Brad Fitzpatrick | 6804433 | 2010-11-22 18:19:48 -0800 | [diff] [blame] | 4989 | } |
Brad Fitzpatrick | 6804433 | 2010-11-22 18:19:48 -0800 | [diff] [blame] | 4990 | } |
| 4991 | } |
| 4992 | |
Brad Fitzpatrick | c1a968a | 2010-11-24 08:56:40 -0800 | [diff] [blame] | 4993 | public void setStrictModeVisualIndicatorPreference(String value) { |
| 4994 | SystemProperties.set(StrictMode.VISUAL_PROPERTY, value); |
| 4995 | } |
| 4996 | |
Dianne Hackborn | d283593 | 2010-12-13 16:28:46 -0800 | [diff] [blame] | 4997 | public Bitmap screenshotApplications(IBinder appToken, int maxWidth, int maxHeight) { |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 4998 | if (!checkCallingPermission(android.Manifest.permission.READ_FRAME_BUFFER, |
| 4999 | "screenshotApplications()")) { |
| 5000 | throw new SecurityException("Requires READ_FRAME_BUFFER permission"); |
| 5001 | } |
| 5002 | |
| 5003 | Bitmap rawss; |
| 5004 | |
Dianne Hackborn | d283593 | 2010-12-13 16:28:46 -0800 | [diff] [blame] | 5005 | int maxLayer = 0; |
| 5006 | boolean foundApp; |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 5007 | final Rect frame = new Rect(); |
| 5008 | |
| 5009 | float scale; |
| 5010 | int sw, sh, dw, dh; |
| 5011 | int rot; |
| 5012 | |
| 5013 | synchronized(mWindowMap) { |
| 5014 | long ident = Binder.clearCallingIdentity(); |
| 5015 | |
| 5016 | int aboveAppLayer = mPolicy.windowTypeToLayerLw( |
| 5017 | WindowManager.LayoutParams.TYPE_APPLICATION) * TYPE_LAYER_MULTIPLIER |
| 5018 | + TYPE_LAYER_OFFSET; |
| 5019 | aboveAppLayer += TYPE_LAYER_MULTIPLIER; |
| 5020 | |
| 5021 | // Figure out the part of the screen that is actually the app. |
| 5022 | for (int i=0; i<mWindows.size(); i++) { |
| 5023 | WindowState ws = mWindows.get(i); |
| 5024 | if (ws.mSurface == null) { |
| 5025 | continue; |
| 5026 | } |
| 5027 | if (ws.mLayer >= aboveAppLayer) { |
| 5028 | break; |
| 5029 | } |
Dianne Hackborn | d283593 | 2010-12-13 16:28:46 -0800 | [diff] [blame] | 5030 | if (appToken != null && (ws.mAppToken == null |
| 5031 | || ws.mAppToken.token != appToken)) { |
| 5032 | continue; |
| 5033 | } |
| 5034 | if (maxLayer < ws.mAnimLayer) { |
| 5035 | maxLayer = ws.mAnimLayer; |
| 5036 | } |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 5037 | final Rect wf = ws.mFrame; |
| 5038 | final Rect cr = ws.mContentInsets; |
| 5039 | int left = wf.left + cr.left; |
| 5040 | int top = wf.top + cr.top; |
| 5041 | int right = wf.right - cr.right; |
| 5042 | int bottom = wf.bottom - cr.bottom; |
| 5043 | frame.union(left, top, right, bottom); |
| 5044 | } |
| 5045 | Binder.restoreCallingIdentity(ident); |
| 5046 | |
Dianne Hackborn | cb8f0e0 | 2010-12-16 11:15:18 -0800 | [diff] [blame] | 5047 | if (frame.isEmpty() || maxLayer == 0) { |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 5048 | return null; |
| 5049 | } |
| 5050 | |
| 5051 | // The screenshot API does not apply the current screen rotation. |
| 5052 | rot = mDisplay.getRotation(); |
| 5053 | int fw = frame.width(); |
| 5054 | int fh = frame.height(); |
| 5055 | |
| 5056 | // First try reducing to fit in x dimension. |
| 5057 | scale = maxWidth/(float)fw; |
| 5058 | sw = maxWidth; |
| 5059 | sh = (int)(fh*scale); |
| 5060 | if (sh > maxHeight) { |
| 5061 | // y dimension became too long; constrain by that. |
| 5062 | scale = maxHeight/(float)fh; |
| 5063 | sw = (int)(fw*scale); |
| 5064 | sh = maxHeight; |
| 5065 | } |
| 5066 | |
| 5067 | // The screen shot will contain the entire screen. |
| 5068 | dw = (int)(mDisplay.getWidth()*scale); |
| 5069 | dh = (int)(mDisplay.getHeight()*scale); |
| 5070 | if (rot == Surface.ROTATION_90 || rot == Surface.ROTATION_270) { |
| 5071 | int tmp = dw; |
| 5072 | dw = dh; |
| 5073 | dh = tmp; |
| 5074 | rot = (rot == Surface.ROTATION_90) ? Surface.ROTATION_270 : Surface.ROTATION_90; |
| 5075 | } |
Dianne Hackborn | d283593 | 2010-12-13 16:28:46 -0800 | [diff] [blame] | 5076 | rawss = Surface.screenshot(dw, dh, 0, maxLayer); |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 5077 | } |
| 5078 | |
Dianne Hackborn | cb8f0e0 | 2010-12-16 11:15:18 -0800 | [diff] [blame] | 5079 | if (rawss == null) { |
Dianne Hackborn | 88b03bd | 2010-12-16 11:15:18 -0800 | [diff] [blame] | 5080 | Log.w(TAG, "Failure taking screenshot for (" + dw + "x" + dh |
| 5081 | + ") to layer " + maxLayer); |
Dianne Hackborn | cb8f0e0 | 2010-12-16 11:15:18 -0800 | [diff] [blame] | 5082 | return null; |
| 5083 | } |
| 5084 | |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 5085 | Bitmap bm = Bitmap.createBitmap(sw, sh, rawss.getConfig()); |
| 5086 | Matrix matrix = new Matrix(); |
| 5087 | ScreenRotationAnimation.createRotationMatrix(rot, dw, dh, matrix); |
| 5088 | matrix.postTranslate(-(int)(frame.left*scale), -(int)(frame.top*scale)); |
| 5089 | Canvas canvas = new Canvas(bm); |
| 5090 | canvas.drawBitmap(rawss, matrix, null); |
| 5091 | |
| 5092 | rawss.recycle(); |
| 5093 | return bm; |
| 5094 | } |
| 5095 | |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 5096 | public void freezeRotation() { |
| 5097 | if (!checkCallingPermission(android.Manifest.permission.SET_ORIENTATION, |
| 5098 | "setRotation()")) { |
| 5099 | throw new SecurityException("Requires SET_ORIENTATION permission"); |
| 5100 | } |
| 5101 | |
| 5102 | mPolicy.setUserRotationMode(WindowManagerPolicy.USER_ROTATION_LOCKED, mRotation); |
| 5103 | setRotationUnchecked(WindowManagerPolicy.USE_LAST_ROTATION, false, 0); |
| 5104 | } |
| 5105 | |
| 5106 | public void thawRotation() { |
| 5107 | if (!checkCallingPermission(android.Manifest.permission.SET_ORIENTATION, |
| 5108 | "setRotation()")) { |
| 5109 | throw new SecurityException("Requires SET_ORIENTATION permission"); |
| 5110 | } |
| 5111 | |
| 5112 | mPolicy.setUserRotationMode(WindowManagerPolicy.USER_ROTATION_FREE, 0); |
| 5113 | setRotationUnchecked(WindowManagerPolicy.USE_LAST_ROTATION, false, 0); |
| 5114 | } |
| 5115 | |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5116 | public void setRotation(int rotation, |
Dianne Hackborn | 1e880db | 2009-03-27 16:04:08 -0700 | [diff] [blame] | 5117 | boolean alwaysSendConfiguration, int animFlags) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5118 | if (!checkCallingPermission(android.Manifest.permission.SET_ORIENTATION, |
Dianne Hackborn | 1e880db | 2009-03-27 16:04:08 -0700 | [diff] [blame] | 5119 | "setRotation()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5120 | throw new SecurityException("Requires SET_ORIENTATION permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5121 | } |
| 5122 | |
Dianne Hackborn | 1e880db | 2009-03-27 16:04:08 -0700 | [diff] [blame] | 5123 | setRotationUnchecked(rotation, alwaysSendConfiguration, animFlags); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5124 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5125 | |
Dianne Hackborn | 1e880db | 2009-03-27 16:04:08 -0700 | [diff] [blame] | 5126 | public void setRotationUnchecked(int rotation, |
| 5127 | boolean alwaysSendConfiguration, int animFlags) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5128 | if(DEBUG_ORIENTATION) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5129 | "alwaysSendConfiguration set to "+alwaysSendConfiguration); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5130 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5131 | long origId = Binder.clearCallingIdentity(); |
| 5132 | boolean changed; |
| 5133 | synchronized(mWindowMap) { |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 5134 | changed = setRotationUncheckedLocked(rotation, animFlags, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5135 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5136 | |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 5137 | if (changed || alwaysSendConfiguration) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5138 | sendNewConfiguration(); |
| 5139 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5140 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5141 | Binder.restoreCallingIdentity(origId); |
| 5142 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5143 | |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 5144 | /** |
| 5145 | * Apply a new rotation to the screen, respecting the requests of |
| 5146 | * applications. Use WindowManagerPolicy.USE_LAST_ROTATION to simply |
| 5147 | * re-evaluate the desired rotation. |
| 5148 | * |
| 5149 | * Returns null if the rotation has been changed. In this case YOU |
| 5150 | * MUST CALL setNewConfiguration() TO UNFREEZE THE SCREEN. |
| 5151 | */ |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 5152 | public boolean setRotationUncheckedLocked(int rotation, int animFlags, boolean inTransaction) { |
Dianne Hackborn | 89ba675 | 2011-01-23 16:51:16 -0800 | [diff] [blame] | 5153 | if (mDragState != null || mScreenRotationAnimation != null) { |
Christopher Tate | ccd24de | 2011-01-12 15:02:55 -0800 | [diff] [blame] | 5154 | // Potential rotation during a drag. Don't do the rotation now, but make |
| 5155 | // a note to perform the rotation later. |
Dianne Hackborn | 89ba675 | 2011-01-23 16:51:16 -0800 | [diff] [blame] | 5156 | if (DEBUG_ORIENTATION) Slog.v(TAG, "Deferring rotation."); |
| 5157 | if (rotation != WindowManagerPolicy.USE_LAST_ROTATION) { |
| 5158 | mDeferredRotation = rotation; |
| 5159 | mDeferredRotationAnimFlags = animFlags; |
| 5160 | } |
Christopher Tate | ccd24de | 2011-01-12 15:02:55 -0800 | [diff] [blame] | 5161 | return false; |
| 5162 | } |
| 5163 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5164 | boolean changed; |
| 5165 | if (rotation == WindowManagerPolicy.USE_LAST_ROTATION) { |
Dianne Hackborn | 89ba675 | 2011-01-23 16:51:16 -0800 | [diff] [blame] | 5166 | if (mDeferredRotation != WindowManagerPolicy.USE_LAST_ROTATION) { |
| 5167 | rotation = mDeferredRotation; |
| 5168 | mRequestedRotation = rotation; |
| 5169 | mLastRotationFlags = mDeferredRotationAnimFlags; |
| 5170 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5171 | rotation = mRequestedRotation; |
| 5172 | } else { |
| 5173 | mRequestedRotation = rotation; |
Dianne Hackborn | 321ae68 | 2009-03-27 16:16:03 -0700 | [diff] [blame] | 5174 | mLastRotationFlags = animFlags; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5175 | } |
Dianne Hackborn | 89ba675 | 2011-01-23 16:51:16 -0800 | [diff] [blame] | 5176 | mDeferredRotation = WindowManagerPolicy.USE_LAST_ROTATION; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5177 | 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] | 5178 | rotation = mPolicy.rotationForOrientationLw(mForcedAppOrientation, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5179 | mRotation, mDisplayEnabled); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5180 | 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] | 5181 | changed = mDisplayEnabled && mRotation != rotation; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5182 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5183 | if (changed) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5184 | if (DEBUG_ORIENTATION) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5185 | "Rotation changed to " + rotation |
| 5186 | + " from " + mRotation |
| 5187 | + " (forceApp=" + mForcedAppOrientation |
| 5188 | + ", req=" + mRequestedRotation + ")"); |
| 5189 | mRotation = rotation; |
| 5190 | mWindowsFreezingScreen = true; |
| 5191 | mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT); |
| 5192 | mH.sendMessageDelayed(mH.obtainMessage(H.WINDOW_FREEZE_TIMEOUT), |
| 5193 | 2000); |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 5194 | mWaitingForConfig = true; |
| 5195 | mLayoutNeeded = true; |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 5196 | startFreezingDisplayLocked(inTransaction); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5197 | Slog.i(TAG, "Setting rotation to " + rotation + ", animFlags=" + animFlags); |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 5198 | mInputManager.setDisplayOrientation(0, rotation); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5199 | if (mDisplayEnabled) { |
Dianne Hackborn | a111187 | 2010-11-23 20:55:11 -0800 | [diff] [blame] | 5200 | if (CUSTOM_SCREEN_ROTATION) { |
| 5201 | Surface.freezeDisplay(0); |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 5202 | if (!inTransaction) { |
| 5203 | if (SHOW_TRANSACTIONS) Slog.i(TAG, |
| 5204 | ">>> OPEN TRANSACTION setRotationUnchecked"); |
| 5205 | Surface.openTransaction(); |
Dianne Hackborn | a111187 | 2010-11-23 20:55:11 -0800 | [diff] [blame] | 5206 | } |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 5207 | try { |
| 5208 | if (mScreenRotationAnimation != null) { |
| 5209 | mScreenRotationAnimation.setRotation(rotation); |
| 5210 | } |
| 5211 | } finally { |
| 5212 | if (!inTransaction) { |
| 5213 | Surface.closeTransaction(); |
| 5214 | if (SHOW_TRANSACTIONS) Slog.i(TAG, |
| 5215 | "<<< CLOSE TRANSACTION setRotationUnchecked"); |
| 5216 | } |
| 5217 | } |
Dianne Hackborn | a111187 | 2010-11-23 20:55:11 -0800 | [diff] [blame] | 5218 | Surface.setOrientation(0, rotation, animFlags); |
| 5219 | Surface.unfreezeDisplay(0); |
| 5220 | } else { |
| 5221 | Surface.setOrientation(0, rotation, animFlags); |
| 5222 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5223 | } |
| 5224 | for (int i=mWindows.size()-1; i>=0; i--) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 5225 | WindowState w = mWindows.get(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5226 | if (w.mSurface != null) { |
| 5227 | w.mOrientationChanging = true; |
| 5228 | } |
| 5229 | } |
| 5230 | for (int i=mRotationWatchers.size()-1; i>=0; i--) { |
| 5231 | try { |
| 5232 | mRotationWatchers.get(i).onRotationChanged(rotation); |
| 5233 | } catch (RemoteException e) { |
| 5234 | } |
| 5235 | } |
| 5236 | } //end if changed |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5237 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5238 | return changed; |
| 5239 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5240 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5241 | public int getRotation() { |
| 5242 | return mRotation; |
| 5243 | } |
| 5244 | |
| 5245 | public int watchRotation(IRotationWatcher watcher) { |
| 5246 | final IBinder watcherBinder = watcher.asBinder(); |
| 5247 | IBinder.DeathRecipient dr = new IBinder.DeathRecipient() { |
| 5248 | public void binderDied() { |
| 5249 | synchronized (mWindowMap) { |
| 5250 | for (int i=0; i<mRotationWatchers.size(); i++) { |
| 5251 | if (watcherBinder == mRotationWatchers.get(i).asBinder()) { |
Suchi Amalapurapu | fff2fda | 2009-06-30 21:36:16 -0700 | [diff] [blame] | 5252 | IRotationWatcher removed = mRotationWatchers.remove(i); |
| 5253 | if (removed != null) { |
| 5254 | removed.asBinder().unlinkToDeath(this, 0); |
| 5255 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5256 | i--; |
| 5257 | } |
| 5258 | } |
| 5259 | } |
| 5260 | } |
| 5261 | }; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5262 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5263 | synchronized (mWindowMap) { |
| 5264 | try { |
| 5265 | watcher.asBinder().linkToDeath(dr, 0); |
| 5266 | mRotationWatchers.add(watcher); |
| 5267 | } catch (RemoteException e) { |
| 5268 | // Client died, no cleanup needed. |
| 5269 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5270 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5271 | return mRotation; |
| 5272 | } |
| 5273 | } |
| 5274 | |
| 5275 | /** |
| 5276 | * Starts the view server on the specified port. |
| 5277 | * |
| 5278 | * @param port The port to listener to. |
| 5279 | * |
| 5280 | * @return True if the server was successfully started, false otherwise. |
| 5281 | * |
| 5282 | * @see com.android.server.ViewServer |
| 5283 | * @see com.android.server.ViewServer#VIEW_SERVER_DEFAULT_PORT |
| 5284 | */ |
| 5285 | public boolean startViewServer(int port) { |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5286 | if (isSystemSecure()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5287 | return false; |
| 5288 | } |
| 5289 | |
| 5290 | if (!checkCallingPermission(Manifest.permission.DUMP, "startViewServer")) { |
| 5291 | return false; |
| 5292 | } |
| 5293 | |
| 5294 | if (port < 1024) { |
| 5295 | return false; |
| 5296 | } |
| 5297 | |
| 5298 | if (mViewServer != null) { |
| 5299 | if (!mViewServer.isRunning()) { |
| 5300 | try { |
| 5301 | return mViewServer.start(); |
| 5302 | } catch (IOException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5303 | Slog.w(TAG, "View server did not start"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5304 | } |
| 5305 | } |
| 5306 | return false; |
| 5307 | } |
| 5308 | |
| 5309 | try { |
| 5310 | mViewServer = new ViewServer(this, port); |
| 5311 | return mViewServer.start(); |
| 5312 | } catch (IOException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5313 | Slog.w(TAG, "View server did not start"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5314 | } |
| 5315 | return false; |
| 5316 | } |
| 5317 | |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5318 | private boolean isSystemSecure() { |
| 5319 | return "1".equals(SystemProperties.get(SYSTEM_SECURE, "1")) && |
| 5320 | "0".equals(SystemProperties.get(SYSTEM_DEBUGGABLE, "0")); |
| 5321 | } |
| 5322 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5323 | /** |
| 5324 | * Stops the view server if it exists. |
| 5325 | * |
| 5326 | * @return True if the server stopped, false if it wasn't started or |
| 5327 | * couldn't be stopped. |
| 5328 | * |
| 5329 | * @see com.android.server.ViewServer |
| 5330 | */ |
| 5331 | public boolean stopViewServer() { |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5332 | if (isSystemSecure()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5333 | return false; |
| 5334 | } |
| 5335 | |
| 5336 | if (!checkCallingPermission(Manifest.permission.DUMP, "stopViewServer")) { |
| 5337 | return false; |
| 5338 | } |
| 5339 | |
| 5340 | if (mViewServer != null) { |
| 5341 | return mViewServer.stop(); |
| 5342 | } |
| 5343 | return false; |
| 5344 | } |
| 5345 | |
| 5346 | /** |
| 5347 | * Indicates whether the view server is running. |
| 5348 | * |
| 5349 | * @return True if the server is running, false otherwise. |
| 5350 | * |
| 5351 | * @see com.android.server.ViewServer |
| 5352 | */ |
| 5353 | public boolean isViewServerRunning() { |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5354 | if (isSystemSecure()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5355 | return false; |
| 5356 | } |
| 5357 | |
| 5358 | if (!checkCallingPermission(Manifest.permission.DUMP, "isViewServerRunning")) { |
| 5359 | return false; |
| 5360 | } |
| 5361 | |
| 5362 | return mViewServer != null && mViewServer.isRunning(); |
| 5363 | } |
| 5364 | |
| 5365 | /** |
| 5366 | * Lists all availble windows in the system. The listing is written in the |
| 5367 | * specified Socket's output stream with the following syntax: |
| 5368 | * windowHashCodeInHexadecimal windowName |
| 5369 | * Each line of the ouput represents a different window. |
| 5370 | * |
| 5371 | * @param client The remote client to send the listing to. |
| 5372 | * @return False if an error occured, true otherwise. |
| 5373 | */ |
| 5374 | boolean viewServerListWindows(Socket client) { |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5375 | if (isSystemSecure()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5376 | return false; |
| 5377 | } |
| 5378 | |
| 5379 | boolean result = true; |
| 5380 | |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 5381 | WindowState[] windows; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5382 | synchronized (mWindowMap) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5383 | //noinspection unchecked |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 5384 | windows = mWindows.toArray(new WindowState[mWindows.size()]); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5385 | } |
| 5386 | |
| 5387 | BufferedWriter out = null; |
| 5388 | |
| 5389 | // Any uncaught exception will crash the system process |
| 5390 | try { |
| 5391 | OutputStream clientStream = client.getOutputStream(); |
| 5392 | out = new BufferedWriter(new OutputStreamWriter(clientStream), 8 * 1024); |
| 5393 | |
| 5394 | final int count = windows.length; |
| 5395 | for (int i = 0; i < count; i++) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 5396 | final WindowState w = windows[i]; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5397 | out.write(Integer.toHexString(System.identityHashCode(w))); |
| 5398 | out.write(' '); |
| 5399 | out.append(w.mAttrs.getTitle()); |
| 5400 | out.write('\n'); |
| 5401 | } |
| 5402 | |
| 5403 | out.write("DONE.\n"); |
| 5404 | out.flush(); |
| 5405 | } catch (Exception e) { |
| 5406 | result = false; |
| 5407 | } finally { |
| 5408 | if (out != null) { |
| 5409 | try { |
| 5410 | out.close(); |
| 5411 | } catch (IOException e) { |
| 5412 | result = false; |
| 5413 | } |
| 5414 | } |
| 5415 | } |
| 5416 | |
| 5417 | return result; |
| 5418 | } |
| 5419 | |
| 5420 | /** |
Konstantin Lopyrev | f962476 | 2010-07-14 17:02:37 -0700 | [diff] [blame] | 5421 | * Returns the focused window in the following format: |
| 5422 | * windowHashCodeInHexadecimal windowName |
| 5423 | * |
| 5424 | * @param client The remote client to send the listing to. |
| 5425 | * @return False if an error occurred, true otherwise. |
| 5426 | */ |
| 5427 | boolean viewServerGetFocusedWindow(Socket client) { |
| 5428 | if (isSystemSecure()) { |
| 5429 | return false; |
| 5430 | } |
| 5431 | |
| 5432 | boolean result = true; |
| 5433 | |
| 5434 | WindowState focusedWindow = getFocusedWindow(); |
| 5435 | |
| 5436 | BufferedWriter out = null; |
| 5437 | |
| 5438 | // Any uncaught exception will crash the system process |
| 5439 | try { |
| 5440 | OutputStream clientStream = client.getOutputStream(); |
| 5441 | out = new BufferedWriter(new OutputStreamWriter(clientStream), 8 * 1024); |
| 5442 | |
| 5443 | if(focusedWindow != null) { |
| 5444 | out.write(Integer.toHexString(System.identityHashCode(focusedWindow))); |
| 5445 | out.write(' '); |
| 5446 | out.append(focusedWindow.mAttrs.getTitle()); |
| 5447 | } |
| 5448 | out.write('\n'); |
| 5449 | out.flush(); |
| 5450 | } catch (Exception e) { |
| 5451 | result = false; |
| 5452 | } finally { |
| 5453 | if (out != null) { |
| 5454 | try { |
| 5455 | out.close(); |
| 5456 | } catch (IOException e) { |
| 5457 | result = false; |
| 5458 | } |
| 5459 | } |
| 5460 | } |
| 5461 | |
| 5462 | return result; |
| 5463 | } |
| 5464 | |
| 5465 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5466 | * Sends a command to a target window. The result of the command, if any, will be |
| 5467 | * written in the output stream of the specified socket. |
| 5468 | * |
| 5469 | * The parameters must follow this syntax: |
| 5470 | * windowHashcode extra |
| 5471 | * |
| 5472 | * Where XX is the length in characeters of the windowTitle. |
| 5473 | * |
| 5474 | * The first parameter is the target window. The window with the specified hashcode |
| 5475 | * will be the target. If no target can be found, nothing happens. The extra parameters |
| 5476 | * will be delivered to the target window and as parameters to the command itself. |
| 5477 | * |
| 5478 | * @param client The remote client to sent the result, if any, to. |
| 5479 | * @param command The command to execute. |
| 5480 | * @param parameters The command parameters. |
| 5481 | * |
| 5482 | * @return True if the command was successfully delivered, false otherwise. This does |
| 5483 | * not indicate whether the command itself was successful. |
| 5484 | */ |
| 5485 | boolean viewServerWindowCommand(Socket client, String command, String parameters) { |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5486 | if (isSystemSecure()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5487 | return false; |
| 5488 | } |
| 5489 | |
| 5490 | boolean success = true; |
| 5491 | Parcel data = null; |
| 5492 | Parcel reply = null; |
| 5493 | |
Konstantin Lopyrev | 43b9b48 | 2010-08-24 22:00:12 -0700 | [diff] [blame] | 5494 | BufferedWriter out = null; |
| 5495 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5496 | // Any uncaught exception will crash the system process |
| 5497 | try { |
| 5498 | // Find the hashcode of the window |
| 5499 | int index = parameters.indexOf(' '); |
| 5500 | if (index == -1) { |
| 5501 | index = parameters.length(); |
| 5502 | } |
| 5503 | final String code = parameters.substring(0, index); |
Romain Guy | 236092a | 2009-12-14 15:31:48 -0800 | [diff] [blame] | 5504 | int hashCode = (int) Long.parseLong(code, 16); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5505 | |
| 5506 | // Extract the command's parameter after the window description |
| 5507 | if (index < parameters.length()) { |
| 5508 | parameters = parameters.substring(index + 1); |
| 5509 | } else { |
| 5510 | parameters = ""; |
| 5511 | } |
| 5512 | |
| 5513 | final WindowManagerService.WindowState window = findWindow(hashCode); |
| 5514 | if (window == null) { |
| 5515 | return false; |
| 5516 | } |
| 5517 | |
| 5518 | data = Parcel.obtain(); |
| 5519 | data.writeInterfaceToken("android.view.IWindow"); |
| 5520 | data.writeString(command); |
| 5521 | data.writeString(parameters); |
| 5522 | data.writeInt(1); |
| 5523 | ParcelFileDescriptor.fromSocket(client).writeToParcel(data, 0); |
| 5524 | |
| 5525 | reply = Parcel.obtain(); |
| 5526 | |
| 5527 | final IBinder binder = window.mClient.asBinder(); |
| 5528 | // TODO: GET THE TRANSACTION CODE IN A SAFER MANNER |
| 5529 | binder.transact(IBinder.FIRST_CALL_TRANSACTION, data, reply, 0); |
| 5530 | |
| 5531 | reply.readException(); |
| 5532 | |
Konstantin Lopyrev | 43b9b48 | 2010-08-24 22:00:12 -0700 | [diff] [blame] | 5533 | if (!client.isOutputShutdown()) { |
| 5534 | out = new BufferedWriter(new OutputStreamWriter(client.getOutputStream())); |
| 5535 | out.write("DONE\n"); |
| 5536 | out.flush(); |
| 5537 | } |
| 5538 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5539 | } catch (Exception e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5540 | 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] | 5541 | success = false; |
| 5542 | } finally { |
| 5543 | if (data != null) { |
| 5544 | data.recycle(); |
| 5545 | } |
| 5546 | if (reply != null) { |
| 5547 | reply.recycle(); |
| 5548 | } |
Konstantin Lopyrev | 43b9b48 | 2010-08-24 22:00:12 -0700 | [diff] [blame] | 5549 | if (out != null) { |
| 5550 | try { |
| 5551 | out.close(); |
| 5552 | } catch (IOException e) { |
| 5553 | |
| 5554 | } |
| 5555 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5556 | } |
| 5557 | |
| 5558 | return success; |
| 5559 | } |
| 5560 | |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 5561 | public void addWindowChangeListener(WindowChangeListener listener) { |
| 5562 | synchronized(mWindowMap) { |
| 5563 | mWindowChangeListeners.add(listener); |
| 5564 | } |
| 5565 | } |
| 5566 | |
| 5567 | public void removeWindowChangeListener(WindowChangeListener listener) { |
| 5568 | synchronized(mWindowMap) { |
| 5569 | mWindowChangeListeners.remove(listener); |
| 5570 | } |
| 5571 | } |
| 5572 | |
| 5573 | private void notifyWindowsChanged() { |
| 5574 | WindowChangeListener[] windowChangeListeners; |
| 5575 | synchronized(mWindowMap) { |
| 5576 | if(mWindowChangeListeners.isEmpty()) { |
| 5577 | return; |
| 5578 | } |
| 5579 | windowChangeListeners = new WindowChangeListener[mWindowChangeListeners.size()]; |
| 5580 | windowChangeListeners = mWindowChangeListeners.toArray(windowChangeListeners); |
| 5581 | } |
| 5582 | int N = windowChangeListeners.length; |
| 5583 | for(int i = 0; i < N; i++) { |
| 5584 | windowChangeListeners[i].windowsChanged(); |
| 5585 | } |
| 5586 | } |
| 5587 | |
Konstantin Lopyrev | 6e0f65f | 2010-07-14 14:55:33 -0700 | [diff] [blame] | 5588 | private void notifyFocusChanged() { |
| 5589 | WindowChangeListener[] windowChangeListeners; |
| 5590 | synchronized(mWindowMap) { |
| 5591 | if(mWindowChangeListeners.isEmpty()) { |
| 5592 | return; |
| 5593 | } |
| 5594 | windowChangeListeners = new WindowChangeListener[mWindowChangeListeners.size()]; |
| 5595 | windowChangeListeners = mWindowChangeListeners.toArray(windowChangeListeners); |
| 5596 | } |
| 5597 | int N = windowChangeListeners.length; |
| 5598 | for(int i = 0; i < N; i++) { |
| 5599 | windowChangeListeners[i].focusChanged(); |
| 5600 | } |
| 5601 | } |
| 5602 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5603 | private WindowState findWindow(int hashCode) { |
| 5604 | if (hashCode == -1) { |
| 5605 | return getFocusedWindow(); |
| 5606 | } |
| 5607 | |
| 5608 | synchronized (mWindowMap) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 5609 | final ArrayList<WindowState> windows = mWindows; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5610 | final int count = windows.size(); |
| 5611 | |
| 5612 | for (int i = 0; i < count; i++) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 5613 | WindowState w = windows.get(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5614 | if (System.identityHashCode(w) == hashCode) { |
| 5615 | return w; |
| 5616 | } |
| 5617 | } |
| 5618 | } |
| 5619 | |
| 5620 | return null; |
| 5621 | } |
| 5622 | |
| 5623 | /* |
| 5624 | * Instruct the Activity Manager to fetch the current configuration and broadcast |
| 5625 | * that to config-changed listeners if appropriate. |
| 5626 | */ |
| 5627 | void sendNewConfiguration() { |
| 5628 | try { |
| 5629 | mActivityManager.updateConfiguration(null); |
| 5630 | } catch (RemoteException e) { |
| 5631 | } |
| 5632 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5633 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5634 | public Configuration computeNewConfiguration() { |
| 5635 | synchronized (mWindowMap) { |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 5636 | Configuration config = computeNewConfigurationLocked(); |
| 5637 | if (config == null && mWaitingForConfig) { |
| 5638 | // Nothing changed but we are waiting for something... stop that! |
| 5639 | mWaitingForConfig = false; |
| 5640 | performLayoutAndPlaceSurfacesLocked(); |
| 5641 | } |
| 5642 | return config; |
Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 5643 | } |
| 5644 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5645 | |
Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 5646 | Configuration computeNewConfigurationLocked() { |
| 5647 | Configuration config = new Configuration(); |
| 5648 | if (!computeNewConfigurationLocked(config)) { |
| 5649 | return null; |
| 5650 | } |
Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 5651 | return config; |
| 5652 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5653 | |
Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 5654 | boolean computeNewConfigurationLocked(Configuration config) { |
| 5655 | if (mDisplay == null) { |
| 5656 | return false; |
| 5657 | } |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 5658 | |
| 5659 | mInputManager.getInputConfiguration(config); |
Christopher Tate | b696aee | 2010-04-02 19:08:30 -0700 | [diff] [blame] | 5660 | |
| 5661 | // Use the effective "visual" dimensions based on current rotation |
| 5662 | final boolean rotated = (mRotation == Surface.ROTATION_90 |
| 5663 | || mRotation == Surface.ROTATION_270); |
| 5664 | final int dw = rotated ? mInitialDisplayHeight : mInitialDisplayWidth; |
| 5665 | final int dh = rotated ? mInitialDisplayWidth : mInitialDisplayHeight; |
| 5666 | |
Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 5667 | int orientation = Configuration.ORIENTATION_SQUARE; |
| 5668 | if (dw < dh) { |
| 5669 | orientation = Configuration.ORIENTATION_PORTRAIT; |
| 5670 | } else if (dw > dh) { |
| 5671 | orientation = Configuration.ORIENTATION_LANDSCAPE; |
| 5672 | } |
| 5673 | config.orientation = orientation; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 5674 | |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 5675 | DisplayMetrics dm = new DisplayMetrics(); |
| 5676 | mDisplay.getMetrics(dm); |
| 5677 | CompatibilityInfo.updateCompatibleScreenFrame(dm, orientation, mCompatibleScreenFrame); |
| 5678 | |
Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 5679 | if (mScreenLayout == Configuration.SCREENLAYOUT_SIZE_UNDEFINED) { |
Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 5680 | // Note we only do this once because at this point we don't |
| 5681 | // expect the screen to change in this way at runtime, and want |
| 5682 | // to avoid all of this computation for every config change. |
Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 5683 | int longSize = dw; |
| 5684 | int shortSize = dh; |
| 5685 | if (longSize < shortSize) { |
| 5686 | int tmp = longSize; |
| 5687 | longSize = shortSize; |
| 5688 | shortSize = tmp; |
| 5689 | } |
| 5690 | longSize = (int)(longSize/dm.density); |
| 5691 | shortSize = (int)(shortSize/dm.density); |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 5692 | |
Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 5693 | // These semi-magic numbers define our compatibility modes for |
| 5694 | // applications with different screens. Don't change unless you |
| 5695 | // make sure to test lots and lots of apps! |
| 5696 | if (longSize < 470) { |
| 5697 | // This is shorter than an HVGA normal density screen (which |
| 5698 | // is 480 pixels on its long side). |
Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 5699 | mScreenLayout = Configuration.SCREENLAYOUT_SIZE_SMALL |
| 5700 | | Configuration.SCREENLAYOUT_LONG_NO; |
Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 5701 | } else { |
Dianne Hackborn | 14cee9f | 2010-04-23 17:51:26 -0700 | [diff] [blame] | 5702 | // What size is this screen screen? |
| 5703 | if (longSize >= 800 && shortSize >= 600) { |
| 5704 | // SVGA or larger screens at medium density are the point |
| 5705 | // at which we consider it to be an extra large screen. |
| 5706 | mScreenLayout = Configuration.SCREENLAYOUT_SIZE_XLARGE; |
Dianne Hackborn | b51dc0f | 2010-10-21 15:34:47 -0700 | [diff] [blame] | 5707 | } else if (longSize >= 530 && shortSize >= 400) { |
| 5708 | // SVGA or larger screens at high density are the point |
Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 5709 | // at which we consider it to be a large screen. |
| 5710 | mScreenLayout = Configuration.SCREENLAYOUT_SIZE_LARGE; |
| 5711 | } else { |
| 5712 | mScreenLayout = Configuration.SCREENLAYOUT_SIZE_NORMAL; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 5713 | |
Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 5714 | // If this screen is wider than normal HVGA, or taller |
| 5715 | // than FWVGA, then for old apps we want to run in size |
| 5716 | // compatibility mode. |
| 5717 | if (shortSize > 321 || longSize > 570) { |
| 5718 | mScreenLayout |= Configuration.SCREENLAYOUT_COMPAT_NEEDED; |
| 5719 | } |
| 5720 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 5721 | |
Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 5722 | // Is this a long screen? |
| 5723 | if (((longSize*3)/5) >= (shortSize-1)) { |
| 5724 | // Anything wider than WVGA (5:3) is considering to be long. |
| 5725 | mScreenLayout |= Configuration.SCREENLAYOUT_LONG_YES; |
| 5726 | } else { |
| 5727 | mScreenLayout |= Configuration.SCREENLAYOUT_LONG_NO; |
| 5728 | } |
Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 5729 | } |
| 5730 | } |
Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 5731 | config.screenLayout = mScreenLayout; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 5732 | |
Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 5733 | config.keyboardHidden = Configuration.KEYBOARDHIDDEN_NO; |
| 5734 | config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_NO; |
| 5735 | mPolicy.adjustConfigurationLw(config); |
| 5736 | return true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5737 | } |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5738 | |
| 5739 | // ------------------------------------------------------------- |
| 5740 | // Drag and drop |
| 5741 | // ------------------------------------------------------------- |
| 5742 | |
| 5743 | IBinder prepareDragSurface(IWindow window, SurfaceSession session, |
Christopher Tate | 02d2b3b | 2011-01-10 20:43:53 -0800 | [diff] [blame] | 5744 | int flags, int width, int height, Surface outSurface) { |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5745 | if (DEBUG_DRAG) { |
| 5746 | Slog.d(TAG, "prepare drag surface: w=" + width + " h=" + height |
Christopher Tate | 02d2b3b | 2011-01-10 20:43:53 -0800 | [diff] [blame] | 5747 | + " flags=" + Integer.toHexString(flags) + " win=" + window |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5748 | + " asbinder=" + window.asBinder()); |
| 5749 | } |
| 5750 | |
| 5751 | final int callerPid = Binder.getCallingPid(); |
| 5752 | final long origId = Binder.clearCallingIdentity(); |
| 5753 | IBinder token = null; |
| 5754 | |
| 5755 | try { |
| 5756 | synchronized (mWindowMap) { |
| 5757 | try { |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5758 | if (mDragState == null) { |
| 5759 | Surface surface = new Surface(session, callerPid, "drag surface", 0, |
| 5760 | width, height, PixelFormat.TRANSLUCENT, Surface.HIDDEN); |
| 5761 | outSurface.copyFrom(surface); |
Chris Tate | 7b362e4 | 2010-11-04 16:02:52 -0700 | [diff] [blame] | 5762 | final IBinder winBinder = window.asBinder(); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5763 | token = new Binder(); |
Christopher Tate | 02d2b3b | 2011-01-10 20:43:53 -0800 | [diff] [blame] | 5764 | // TODO: preserve flags param in DragState |
| 5765 | mDragState = new DragState(token, surface, 0, winBinder); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5766 | mDragState.mSurface = surface; |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5767 | token = mDragState.mToken = new Binder(); |
| 5768 | |
| 5769 | // 5 second timeout for this window to actually begin the drag |
Chris Tate | 7b362e4 | 2010-11-04 16:02:52 -0700 | [diff] [blame] | 5770 | mH.removeMessages(H.DRAG_START_TIMEOUT, winBinder); |
| 5771 | Message msg = mH.obtainMessage(H.DRAG_START_TIMEOUT, winBinder); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5772 | mH.sendMessageDelayed(msg, 5000); |
| 5773 | } else { |
| 5774 | Slog.w(TAG, "Drag already in progress"); |
| 5775 | } |
| 5776 | } catch (Surface.OutOfResourcesException e) { |
| 5777 | Slog.e(TAG, "Can't allocate drag surface w=" + width + " h=" + height, e); |
| 5778 | if (mDragState != null) { |
| 5779 | mDragState.reset(); |
| 5780 | mDragState = null; |
| 5781 | } |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5782 | } |
| 5783 | } |
| 5784 | } finally { |
| 5785 | Binder.restoreCallingIdentity(origId); |
| 5786 | } |
| 5787 | |
| 5788 | return token; |
| 5789 | } |
| 5790 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5791 | // ------------------------------------------------------------- |
| 5792 | // Input Events and Focus Management |
| 5793 | // ------------------------------------------------------------- |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5794 | |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5795 | InputMonitor mInputMonitor = new InputMonitor(); |
| 5796 | |
| 5797 | /* Tracks the progress of input dispatch and ensures that input dispatch state |
| 5798 | * is kept in sync with changes in window focus, visibility, registration, and |
| 5799 | * other relevant Window Manager state transitions. */ |
| 5800 | final class InputMonitor { |
| 5801 | // Current window with input focus for keys and other non-touch events. May be null. |
| 5802 | private WindowState mInputFocus; |
| 5803 | |
| 5804 | // When true, prevents input dispatch from proceeding until set to false again. |
| 5805 | private boolean mInputDispatchFrozen; |
| 5806 | |
| 5807 | // When true, input dispatch proceeds normally. Otherwise all events are dropped. |
| 5808 | private boolean mInputDispatchEnabled = true; |
| 5809 | |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 5810 | // When true, need to call updateInputWindowsLw(). |
| 5811 | private boolean mUpdateInputWindowsNeeded = true; |
| 5812 | |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5813 | // Temporary list of windows information to provide to the input dispatcher. |
| 5814 | private InputWindowList mTempInputWindows = new InputWindowList(); |
| 5815 | |
| 5816 | // Temporary input application object to provide to the input dispatcher. |
| 5817 | private InputApplication mTempInputApplication = new InputApplication(); |
| 5818 | |
Jeff Brown | b09abc1 | 2011-01-13 21:08:27 -0800 | [diff] [blame] | 5819 | // Set to true when the first input device configuration change notification |
| 5820 | // is received to indicate that the input devices are ready. |
| 5821 | private final Object mInputDevicesReadyMonitor = new Object(); |
| 5822 | private boolean mInputDevicesReady; |
| 5823 | |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5824 | /* Notifies the window manager about a broken input channel. |
| 5825 | * |
| 5826 | * Called by the InputManager. |
| 5827 | */ |
Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame] | 5828 | public void notifyInputChannelBroken(InputWindowHandle inputWindowHandle) { |
| 5829 | if (inputWindowHandle == null) { |
| 5830 | return; |
| 5831 | } |
| 5832 | |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5833 | synchronized (mWindowMap) { |
Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame] | 5834 | WindowState windowState = (WindowState) inputWindowHandle.windowState; |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5835 | Slog.i(TAG, "WINDOW DIED " + windowState); |
| 5836 | removeWindowLocked(windowState.mSession, windowState); |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 5837 | } |
| 5838 | } |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5839 | |
Jeff Brown | 519e024 | 2010-09-15 15:18:56 -0700 | [diff] [blame] | 5840 | /* Notifies the window manager about an application that is not responding. |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 5841 | * Returns a new timeout to continue waiting in nanoseconds, or 0 to abort dispatch. |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5842 | * |
| 5843 | * Called by the InputManager. |
| 5844 | */ |
Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame] | 5845 | public long notifyANR(InputApplicationHandle inputApplicationHandle, |
| 5846 | InputWindowHandle inputWindowHandle) { |
Jeff Brown | 519e024 | 2010-09-15 15:18:56 -0700 | [diff] [blame] | 5847 | AppWindowToken appWindowToken = null; |
Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame] | 5848 | if (inputWindowHandle != null) { |
Jeff Brown | 519e024 | 2010-09-15 15:18:56 -0700 | [diff] [blame] | 5849 | synchronized (mWindowMap) { |
Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame] | 5850 | WindowState windowState = (WindowState) inputWindowHandle.windowState; |
Jeff Brown | 519e024 | 2010-09-15 15:18:56 -0700 | [diff] [blame] | 5851 | if (windowState != null) { |
| 5852 | Slog.i(TAG, "Input event dispatching timed out sending to " |
| 5853 | + windowState.mAttrs.getTitle()); |
| 5854 | appWindowToken = windowState.mAppToken; |
| 5855 | } |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5856 | } |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 5857 | } |
| 5858 | |
Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame] | 5859 | if (appWindowToken == null && inputApplicationHandle != null) { |
| 5860 | appWindowToken = inputApplicationHandle.appWindowToken; |
Jeff Brown | 519e024 | 2010-09-15 15:18:56 -0700 | [diff] [blame] | 5861 | Slog.i(TAG, "Input event dispatching timed out sending to application " |
| 5862 | + appWindowToken.stringName); |
| 5863 | } |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5864 | |
Jeff Brown | 519e024 | 2010-09-15 15:18:56 -0700 | [diff] [blame] | 5865 | if (appWindowToken != null && appWindowToken.appToken != null) { |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5866 | try { |
| 5867 | // Notify the activity manager about the timeout and let it decide whether |
| 5868 | // to abort dispatching or keep waiting. |
Jeff Brown | 519e024 | 2010-09-15 15:18:56 -0700 | [diff] [blame] | 5869 | boolean abort = appWindowToken.appToken.keyDispatchingTimedOut(); |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5870 | if (! abort) { |
| 5871 | // The activity manager declined to abort dispatching. |
| 5872 | // Wait a bit longer and timeout again later. |
Jeff Brown | 519e024 | 2010-09-15 15:18:56 -0700 | [diff] [blame] | 5873 | return appWindowToken.inputDispatchingTimeoutNanos; |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 5874 | } |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5875 | } catch (RemoteException ex) { |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 5876 | } |
| 5877 | } |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 5878 | return 0; // abort dispatching |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 5879 | } |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5880 | |
Chris Tate | a32dcf7 | 2010-10-14 12:13:50 -0700 | [diff] [blame] | 5881 | private void addDragInputWindowLw(InputWindowList windowList) { |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5882 | final InputWindow inputWindow = windowList.add(); |
| 5883 | inputWindow.inputChannel = mDragState.mServerChannel; |
| 5884 | inputWindow.name = "drag"; |
Christopher Tate | a159579 | 2011-01-19 17:26:50 -0800 | [diff] [blame] | 5885 | inputWindow.layoutParamsFlags = 0; |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5886 | inputWindow.layoutParamsType = WindowManager.LayoutParams.TYPE_DRAG; |
| 5887 | inputWindow.dispatchingTimeoutNanos = DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS; |
| 5888 | inputWindow.visible = true; |
| 5889 | inputWindow.canReceiveKeys = false; |
| 5890 | inputWindow.hasFocus = true; |
| 5891 | inputWindow.hasWallpaper = false; |
| 5892 | inputWindow.paused = false; |
Chris Tate | a32dcf7 | 2010-10-14 12:13:50 -0700 | [diff] [blame] | 5893 | inputWindow.layer = mDragState.getDragLayerLw(); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5894 | inputWindow.ownerPid = Process.myPid(); |
| 5895 | inputWindow.ownerUid = Process.myUid(); |
| 5896 | |
| 5897 | // The drag window covers the entire display |
| 5898 | inputWindow.frameLeft = 0; |
| 5899 | inputWindow.frameTop = 0; |
| 5900 | inputWindow.frameRight = mDisplay.getWidth(); |
| 5901 | inputWindow.frameBottom = mDisplay.getHeight(); |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 5902 | |
Jeff Brown | fbf0977 | 2011-01-16 14:06:57 -0800 | [diff] [blame] | 5903 | // The drag window cannot receive new touches. |
| 5904 | inputWindow.touchableRegion.setEmpty(); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5905 | } |
| 5906 | |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 5907 | public void setUpdateInputWindowsNeededLw() { |
| 5908 | mUpdateInputWindowsNeeded = true; |
| 5909 | } |
| 5910 | |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5911 | /* Updates the cached window information provided to the input dispatcher. */ |
Jeff Brown | 2e44b07 | 2011-01-24 15:21:56 -0800 | [diff] [blame^] | 5912 | public void updateInputWindowsLw(boolean force) { |
| 5913 | if (!force && !mUpdateInputWindowsNeeded) { |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 5914 | return; |
| 5915 | } |
| 5916 | mUpdateInputWindowsNeeded = false; |
| 5917 | |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5918 | // Populate the input window list with information about all of the windows that |
| 5919 | // could potentially receive input. |
| 5920 | // As an optimization, we could try to prune the list of windows but this turns |
| 5921 | // out to be difficult because only the native code knows for sure which window |
| 5922 | // currently has touch focus. |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 5923 | final ArrayList<WindowState> windows = mWindows; |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5924 | |
| 5925 | // If there's a drag in flight, provide a pseudowindow to catch drag input |
| 5926 | final boolean inDrag = (mDragState != null); |
| 5927 | if (inDrag) { |
| 5928 | if (DEBUG_DRAG) { |
| 5929 | Log.d(TAG, "Inserting drag window"); |
| 5930 | } |
Chris Tate | a32dcf7 | 2010-10-14 12:13:50 -0700 | [diff] [blame] | 5931 | addDragInputWindowLw(mTempInputWindows); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5932 | } |
| 5933 | |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 5934 | final int N = windows.size(); |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5935 | for (int i = N - 1; i >= 0; i--) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 5936 | final WindowState child = windows.get(i); |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 5937 | if (child.mInputChannel == null || child.mRemoved) { |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5938 | // Skip this window because it cannot possibly receive input. |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 5939 | continue; |
| 5940 | } |
| 5941 | |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5942 | final int flags = child.mAttrs.flags; |
| 5943 | final int type = child.mAttrs.type; |
| 5944 | |
| 5945 | final boolean hasFocus = (child == mInputFocus); |
| 5946 | final boolean isVisible = child.isVisibleLw(); |
| 5947 | final boolean hasWallpaper = (child == mWallpaperTarget) |
| 5948 | && (type != WindowManager.LayoutParams.TYPE_KEYGUARD); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5949 | |
| 5950 | // If there's a drag in progress and 'child' is a potential drop target, |
| 5951 | // make sure it's been told about the drag |
| 5952 | if (inDrag && isVisible) { |
| 5953 | mDragState.sendDragStartedIfNeededLw(child); |
| 5954 | } |
| 5955 | |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5956 | // Add a window to our list of input windows. |
| 5957 | final InputWindow inputWindow = mTempInputWindows.add(); |
Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame] | 5958 | inputWindow.inputWindowHandle = child.mInputWindowHandle; |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5959 | inputWindow.inputChannel = child.mInputChannel; |
Jeff Brown | 519e024 | 2010-09-15 15:18:56 -0700 | [diff] [blame] | 5960 | inputWindow.name = child.toString(); |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5961 | inputWindow.layoutParamsFlags = flags; |
| 5962 | inputWindow.layoutParamsType = type; |
| 5963 | inputWindow.dispatchingTimeoutNanos = child.getInputDispatchingTimeoutNanos(); |
| 5964 | inputWindow.visible = isVisible; |
Jeff Brown | 519e024 | 2010-09-15 15:18:56 -0700 | [diff] [blame] | 5965 | inputWindow.canReceiveKeys = child.canReceiveKeys(); |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5966 | inputWindow.hasFocus = hasFocus; |
| 5967 | inputWindow.hasWallpaper = hasWallpaper; |
| 5968 | inputWindow.paused = child.mAppToken != null ? child.mAppToken.paused : false; |
Jeff Brown | 519e024 | 2010-09-15 15:18:56 -0700 | [diff] [blame] | 5969 | inputWindow.layer = child.mLayer; |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5970 | inputWindow.ownerPid = child.mSession.mPid; |
| 5971 | inputWindow.ownerUid = child.mSession.mUid; |
| 5972 | |
| 5973 | final Rect frame = child.mFrame; |
| 5974 | inputWindow.frameLeft = frame.left; |
| 5975 | inputWindow.frameTop = frame.top; |
Jeff Brown | 85a3176 | 2010-09-01 17:01:00 -0700 | [diff] [blame] | 5976 | inputWindow.frameRight = frame.right; |
| 5977 | inputWindow.frameBottom = frame.bottom; |
Jeff Brown | fbf0977 | 2011-01-16 14:06:57 -0800 | [diff] [blame] | 5978 | |
| 5979 | child.getTouchableRegion(inputWindow.touchableRegion); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5980 | } |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 5981 | |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5982 | // Send windows to native code. |
| 5983 | mInputManager.setInputWindows(mTempInputWindows.toNullTerminatedArray()); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5984 | |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5985 | // Clear the list in preparation for the next round. |
| 5986 | // Also avoids keeping InputChannel objects referenced unnecessarily. |
| 5987 | mTempInputWindows.clear(); |
| 5988 | } |
Jeff Brown | b09abc1 | 2011-01-13 21:08:27 -0800 | [diff] [blame] | 5989 | |
| 5990 | /* Notifies that the input device configuration has changed. */ |
| 5991 | public void notifyConfigurationChanged() { |
| 5992 | sendNewConfiguration(); |
| 5993 | |
| 5994 | synchronized (mInputDevicesReadyMonitor) { |
| 5995 | if (!mInputDevicesReady) { |
| 5996 | mInputDevicesReady = true; |
| 5997 | mInputDevicesReadyMonitor.notifyAll(); |
| 5998 | } |
| 5999 | } |
| 6000 | } |
| 6001 | |
| 6002 | /* Waits until the built-in input devices have been configured. */ |
| 6003 | public boolean waitForInputDevicesReady(long timeoutMillis) { |
| 6004 | synchronized (mInputDevicesReadyMonitor) { |
| 6005 | if (!mInputDevicesReady) { |
| 6006 | try { |
| 6007 | mInputDevicesReadyMonitor.wait(timeoutMillis); |
| 6008 | } catch (InterruptedException ex) { |
| 6009 | } |
| 6010 | } |
| 6011 | return mInputDevicesReady; |
| 6012 | } |
| 6013 | } |
| 6014 | |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 6015 | /* Notifies that the lid switch changed state. */ |
| 6016 | public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen) { |
| 6017 | mPolicy.notifyLidSwitchChanged(whenNanos, lidOpen); |
| 6018 | } |
| 6019 | |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 6020 | /* Provides an opportunity for the window manager policy to intercept early key |
| 6021 | * processing as soon as the key has been read from the device. */ |
Jeff Brown | 1f24510 | 2010-11-18 20:53:46 -0800 | [diff] [blame] | 6022 | public int interceptKeyBeforeQueueing( |
| 6023 | KeyEvent event, int policyFlags, boolean isScreenOn) { |
| 6024 | return mPolicy.interceptKeyBeforeQueueing(event, policyFlags, isScreenOn); |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 6025 | } |
| 6026 | |
| 6027 | /* Provides an opportunity for the window manager policy to process a key before |
| 6028 | * ordinary dispatch. */ |
Jeff Brown | 1f24510 | 2010-11-18 20:53:46 -0800 | [diff] [blame] | 6029 | public boolean interceptKeyBeforeDispatching( |
Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame] | 6030 | InputWindowHandle focus, KeyEvent event, int policyFlags) { |
Jeff Brown | 00ae87d | 2011-01-13 19:58:24 -0800 | [diff] [blame] | 6031 | WindowState windowState = focus != null ? (WindowState) focus.windowState : null; |
Jeff Brown | 1f24510 | 2010-11-18 20:53:46 -0800 | [diff] [blame] | 6032 | return mPolicy.interceptKeyBeforeDispatching(windowState, event, policyFlags); |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 6033 | } |
| 6034 | |
Jeff Brown | 3915bb8 | 2010-11-05 15:02:16 -0700 | [diff] [blame] | 6035 | /* Provides an opportunity for the window manager policy to process a key that |
| 6036 | * the application did not handle. */ |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 6037 | public KeyEvent dispatchUnhandledKey( |
Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame] | 6038 | InputWindowHandle focus, KeyEvent event, int policyFlags) { |
Jeff Brown | 00ae87d | 2011-01-13 19:58:24 -0800 | [diff] [blame] | 6039 | WindowState windowState = focus != null ? (WindowState) focus.windowState : null; |
Jeff Brown | 1f24510 | 2010-11-18 20:53:46 -0800 | [diff] [blame] | 6040 | return mPolicy.dispatchUnhandledKey(windowState, event, policyFlags); |
Jeff Brown | 3915bb8 | 2010-11-05 15:02:16 -0700 | [diff] [blame] | 6041 | } |
| 6042 | |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 6043 | /* Called when the current input focus changes. |
| 6044 | * Layer assignment is assumed to be complete by the time this is called. |
| 6045 | */ |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 6046 | public void setInputFocusLw(WindowState newWindow, boolean updateInputWindows) { |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 6047 | if (DEBUG_INPUT) { |
| 6048 | Slog.d(TAG, "Input focus has changed to " + newWindow); |
| 6049 | } |
| 6050 | |
| 6051 | if (newWindow != mInputFocus) { |
| 6052 | if (newWindow != null && newWindow.canReceiveKeys()) { |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 6053 | // Displaying a window implicitly causes dispatching to be unpaused. |
| 6054 | // This is to protect against bugs if someone pauses dispatching but |
| 6055 | // forgets to resume. |
| 6056 | newWindow.mToken.paused = false; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 6057 | } |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 6058 | |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 6059 | mInputFocus = newWindow; |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 6060 | setUpdateInputWindowsNeededLw(); |
| 6061 | |
| 6062 | if (updateInputWindows) { |
Jeff Brown | 2e44b07 | 2011-01-24 15:21:56 -0800 | [diff] [blame^] | 6063 | updateInputWindowsLw(false /*force*/); |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 6064 | } |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 6065 | } |
| 6066 | } |
| 6067 | |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 6068 | public void setFocusedAppLw(AppWindowToken newApp) { |
| 6069 | // Focused app has changed. |
| 6070 | if (newApp == null) { |
| 6071 | mInputManager.setFocusedApplication(null); |
| 6072 | } else { |
Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame] | 6073 | mTempInputApplication.inputApplicationHandle = newApp.mInputApplicationHandle; |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 6074 | mTempInputApplication.name = newApp.toString(); |
| 6075 | mTempInputApplication.dispatchingTimeoutNanos = |
| 6076 | newApp.inputDispatchingTimeoutNanos; |
Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame] | 6077 | |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 6078 | mInputManager.setFocusedApplication(mTempInputApplication); |
Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame] | 6079 | |
| 6080 | mTempInputApplication.recycle(); |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 6081 | } |
| 6082 | } |
| 6083 | |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 6084 | public void pauseDispatchingLw(WindowToken window) { |
| 6085 | if (! window.paused) { |
| 6086 | if (DEBUG_INPUT) { |
| 6087 | Slog.v(TAG, "Pausing WindowToken " + window); |
| 6088 | } |
| 6089 | |
| 6090 | window.paused = true; |
Jeff Brown | 2e44b07 | 2011-01-24 15:21:56 -0800 | [diff] [blame^] | 6091 | updateInputWindowsLw(true /*force*/); |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 6092 | } |
| 6093 | } |
| 6094 | |
| 6095 | public void resumeDispatchingLw(WindowToken window) { |
| 6096 | if (window.paused) { |
| 6097 | if (DEBUG_INPUT) { |
| 6098 | Slog.v(TAG, "Resuming WindowToken " + window); |
| 6099 | } |
| 6100 | |
| 6101 | window.paused = false; |
Jeff Brown | 2e44b07 | 2011-01-24 15:21:56 -0800 | [diff] [blame^] | 6102 | updateInputWindowsLw(true /*force*/); |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 6103 | } |
| 6104 | } |
| 6105 | |
| 6106 | public void freezeInputDispatchingLw() { |
| 6107 | if (! mInputDispatchFrozen) { |
| 6108 | if (DEBUG_INPUT) { |
| 6109 | Slog.v(TAG, "Freezing input dispatching"); |
| 6110 | } |
| 6111 | |
| 6112 | mInputDispatchFrozen = true; |
| 6113 | updateInputDispatchModeLw(); |
| 6114 | } |
| 6115 | } |
| 6116 | |
| 6117 | public void thawInputDispatchingLw() { |
| 6118 | if (mInputDispatchFrozen) { |
| 6119 | if (DEBUG_INPUT) { |
| 6120 | Slog.v(TAG, "Thawing input dispatching"); |
| 6121 | } |
| 6122 | |
| 6123 | mInputDispatchFrozen = false; |
| 6124 | updateInputDispatchModeLw(); |
| 6125 | } |
| 6126 | } |
| 6127 | |
| 6128 | public void setEventDispatchingLw(boolean enabled) { |
| 6129 | if (mInputDispatchEnabled != enabled) { |
| 6130 | if (DEBUG_INPUT) { |
| 6131 | Slog.v(TAG, "Setting event dispatching to " + enabled); |
| 6132 | } |
| 6133 | |
| 6134 | mInputDispatchEnabled = enabled; |
| 6135 | updateInputDispatchModeLw(); |
| 6136 | } |
| 6137 | } |
| 6138 | |
| 6139 | private void updateInputDispatchModeLw() { |
| 6140 | mInputManager.setInputDispatchMode(mInputDispatchEnabled, mInputDispatchFrozen); |
| 6141 | } |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 6142 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6143 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6144 | public void pauseKeyDispatching(IBinder _token) { |
| 6145 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 6146 | "pauseKeyDispatching()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 6147 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6148 | } |
| 6149 | |
| 6150 | synchronized (mWindowMap) { |
| 6151 | WindowToken token = mTokenMap.get(_token); |
| 6152 | if (token != null) { |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 6153 | mInputMonitor.pauseDispatchingLw(token); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6154 | } |
| 6155 | } |
| 6156 | } |
| 6157 | |
| 6158 | public void resumeKeyDispatching(IBinder _token) { |
| 6159 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 6160 | "resumeKeyDispatching()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 6161 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6162 | } |
| 6163 | |
| 6164 | synchronized (mWindowMap) { |
| 6165 | WindowToken token = mTokenMap.get(_token); |
| 6166 | if (token != null) { |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 6167 | mInputMonitor.resumeDispatchingLw(token); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6168 | } |
| 6169 | } |
| 6170 | } |
| 6171 | |
| 6172 | public void setEventDispatching(boolean enabled) { |
| 6173 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 6174 | "resumeKeyDispatching()")) { |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 6175 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6176 | } |
| 6177 | |
| 6178 | synchronized (mWindowMap) { |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 6179 | mInputMonitor.setEventDispatchingLw(enabled); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6180 | } |
| 6181 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6182 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6183 | /** |
| 6184 | * Injects a keystroke event into the UI. |
Jeff Brown | bbda99d | 2010-07-28 15:48:59 -0700 | [diff] [blame] | 6185 | * Even when sync is false, this method may block while waiting for current |
| 6186 | * input events to be dispatched. |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6187 | * |
| 6188 | * @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] | 6189 | * {@link SystemClock#uptimeMillis()} as the timebase.) |
| 6190 | * @param sync If true, wait for the event to be completed before returning to the caller. |
| 6191 | * @return Returns true if event was dispatched, false if it was dropped for any reason |
| 6192 | */ |
| 6193 | public boolean injectKeyEvent(KeyEvent ev, boolean sync) { |
| 6194 | long downTime = ev.getDownTime(); |
| 6195 | long eventTime = ev.getEventTime(); |
| 6196 | |
| 6197 | int action = ev.getAction(); |
| 6198 | int code = ev.getKeyCode(); |
| 6199 | int repeatCount = ev.getRepeatCount(); |
| 6200 | int metaState = ev.getMetaState(); |
| 6201 | int deviceId = ev.getDeviceId(); |
| 6202 | int scancode = ev.getScanCode(); |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 6203 | int source = ev.getSource(); |
Mike Playle | c6ded10 | 2010-11-29 16:01:03 +0000 | [diff] [blame] | 6204 | int flags = ev.getFlags(); |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 6205 | |
| 6206 | if (source == InputDevice.SOURCE_UNKNOWN) { |
| 6207 | source = InputDevice.SOURCE_KEYBOARD; |
| 6208 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6209 | |
| 6210 | if (eventTime == 0) eventTime = SystemClock.uptimeMillis(); |
| 6211 | if (downTime == 0) downTime = eventTime; |
| 6212 | |
| 6213 | KeyEvent newEvent = new KeyEvent(downTime, eventTime, action, code, repeatCount, metaState, |
Jean-Baptiste Queru | 4a88013 | 2010-12-02 15:16:53 -0800 | [diff] [blame] | 6214 | deviceId, scancode, flags | KeyEvent.FLAG_FROM_SYSTEM, source); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6215 | |
Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 6216 | final int pid = Binder.getCallingPid(); |
| 6217 | final int uid = Binder.getCallingUid(); |
| 6218 | final long ident = Binder.clearCallingIdentity(); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 6219 | |
Jeff Brown | bbda99d | 2010-07-28 15:48:59 -0700 | [diff] [blame] | 6220 | final int result = mInputManager.injectInputEvent(newEvent, pid, uid, |
| 6221 | sync ? InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH |
| 6222 | : InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT, |
| 6223 | INJECTION_TIMEOUT_MILLIS); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 6224 | |
Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 6225 | Binder.restoreCallingIdentity(ident); |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 6226 | return reportInjectionResult(result); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6227 | } |
| 6228 | |
| 6229 | /** |
| 6230 | * Inject a pointer (touch) event into the UI. |
Jeff Brown | bbda99d | 2010-07-28 15:48:59 -0700 | [diff] [blame] | 6231 | * Even when sync is false, this method may block while waiting for current |
| 6232 | * input events to be dispatched. |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6233 | * |
| 6234 | * @param ev A motion event describing the pointer (touch) action. (As noted in |
| 6235 | * {@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] | 6236 | * {@link SystemClock#uptimeMillis()} as the timebase.) |
| 6237 | * @param sync If true, wait for the event to be completed before returning to the caller. |
| 6238 | * @return Returns true if event was dispatched, false if it was dropped for any reason |
| 6239 | */ |
| 6240 | public boolean injectPointerEvent(MotionEvent ev, boolean sync) { |
Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 6241 | final int pid = Binder.getCallingPid(); |
| 6242 | final int uid = Binder.getCallingUid(); |
| 6243 | final long ident = Binder.clearCallingIdentity(); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 6244 | |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 6245 | MotionEvent newEvent = MotionEvent.obtain(ev); |
| 6246 | if ((newEvent.getSource() & InputDevice.SOURCE_CLASS_POINTER) == 0) { |
| 6247 | newEvent.setSource(InputDevice.SOURCE_TOUCHSCREEN); |
| 6248 | } |
| 6249 | |
Jeff Brown | bbda99d | 2010-07-28 15:48:59 -0700 | [diff] [blame] | 6250 | final int result = mInputManager.injectInputEvent(newEvent, pid, uid, |
| 6251 | sync ? InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH |
| 6252 | : InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT, |
| 6253 | INJECTION_TIMEOUT_MILLIS); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 6254 | |
Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 6255 | Binder.restoreCallingIdentity(ident); |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 6256 | return reportInjectionResult(result); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6257 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6258 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6259 | /** |
| 6260 | * Inject a trackball (navigation device) event into the UI. |
Jeff Brown | bbda99d | 2010-07-28 15:48:59 -0700 | [diff] [blame] | 6261 | * Even when sync is false, this method may block while waiting for current |
| 6262 | * input events to be dispatched. |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6263 | * |
| 6264 | * @param ev A motion event describing the trackball action. (As noted in |
| 6265 | * {@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] | 6266 | * {@link SystemClock#uptimeMillis()} as the timebase.) |
| 6267 | * @param sync If true, wait for the event to be completed before returning to the caller. |
| 6268 | * @return Returns true if event was dispatched, false if it was dropped for any reason |
| 6269 | */ |
| 6270 | public boolean injectTrackballEvent(MotionEvent ev, boolean sync) { |
Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 6271 | final int pid = Binder.getCallingPid(); |
| 6272 | final int uid = Binder.getCallingUid(); |
| 6273 | final long ident = Binder.clearCallingIdentity(); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 6274 | |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 6275 | MotionEvent newEvent = MotionEvent.obtain(ev); |
| 6276 | if ((newEvent.getSource() & InputDevice.SOURCE_CLASS_TRACKBALL) == 0) { |
| 6277 | newEvent.setSource(InputDevice.SOURCE_TRACKBALL); |
| 6278 | } |
| 6279 | |
Jeff Brown | bbda99d | 2010-07-28 15:48:59 -0700 | [diff] [blame] | 6280 | final int result = mInputManager.injectInputEvent(newEvent, pid, uid, |
| 6281 | sync ? InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH |
| 6282 | : InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT, |
| 6283 | INJECTION_TIMEOUT_MILLIS); |
| 6284 | |
| 6285 | Binder.restoreCallingIdentity(ident); |
| 6286 | return reportInjectionResult(result); |
| 6287 | } |
| 6288 | |
| 6289 | /** |
| 6290 | * Inject an input event into the UI without waiting for dispatch to commence. |
| 6291 | * This variant is useful for fire-and-forget input event injection. It does not |
| 6292 | * block any longer than it takes to enqueue the input event. |
| 6293 | * |
| 6294 | * @param ev An input event. (Be sure to set the input source correctly.) |
| 6295 | * @return Returns true if event was dispatched, false if it was dropped for any reason |
| 6296 | */ |
| 6297 | public boolean injectInputEventNoWait(InputEvent ev) { |
| 6298 | final int pid = Binder.getCallingPid(); |
| 6299 | final int uid = Binder.getCallingUid(); |
| 6300 | final long ident = Binder.clearCallingIdentity(); |
| 6301 | |
| 6302 | final int result = mInputManager.injectInputEvent(ev, pid, uid, |
| 6303 | InputManager.INPUT_EVENT_INJECTION_SYNC_NONE, |
| 6304 | INJECTION_TIMEOUT_MILLIS); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 6305 | |
Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 6306 | Binder.restoreCallingIdentity(ident); |
Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 6307 | return reportInjectionResult(result); |
| 6308 | } |
| 6309 | |
| 6310 | private boolean reportInjectionResult(int result) { |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 6311 | switch (result) { |
| 6312 | case InputManager.INPUT_EVENT_INJECTION_PERMISSION_DENIED: |
| 6313 | Slog.w(TAG, "Input event injection permission denied."); |
| 6314 | throw new SecurityException( |
| 6315 | "Injecting to another application requires INJECT_EVENTS permission"); |
| 6316 | case InputManager.INPUT_EVENT_INJECTION_SUCCEEDED: |
Christopher Tate | 09e85dc | 2010-08-02 11:54:41 -0700 | [diff] [blame] | 6317 | //Slog.v(TAG, "Input event injection succeeded."); |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 6318 | return true; |
| 6319 | case InputManager.INPUT_EVENT_INJECTION_TIMED_OUT: |
| 6320 | Slog.w(TAG, "Input event injection timed out."); |
| 6321 | return false; |
| 6322 | case InputManager.INPUT_EVENT_INJECTION_FAILED: |
| 6323 | default: |
| 6324 | Slog.w(TAG, "Input event injection failed."); |
| 6325 | return false; |
Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 6326 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6327 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6328 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6329 | private WindowState getFocusedWindow() { |
| 6330 | synchronized (mWindowMap) { |
| 6331 | return getFocusedWindowLocked(); |
| 6332 | } |
| 6333 | } |
| 6334 | |
| 6335 | private WindowState getFocusedWindowLocked() { |
| 6336 | return mCurrentFocus; |
| 6337 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6338 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6339 | public boolean detectSafeMode() { |
Jeff Brown | b09abc1 | 2011-01-13 21:08:27 -0800 | [diff] [blame] | 6340 | if (!mInputMonitor.waitForInputDevicesReady( |
| 6341 | INPUT_DEVICES_READY_FOR_SAFE_MODE_DETECTION_TIMEOUT_MILLIS)) { |
| 6342 | Slog.w(TAG, "Devices still not ready after waiting " |
| 6343 | + INPUT_DEVICES_READY_FOR_SAFE_MODE_DETECTION_TIMEOUT_MILLIS |
| 6344 | + " milliseconds before attempting to detect safe mode."); |
| 6345 | } |
| 6346 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6347 | mSafeMode = mPolicy.detectSafeMode(); |
| 6348 | return mSafeMode; |
| 6349 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6350 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6351 | public void systemReady() { |
Dianne Hackborn | 5132b37 | 2010-07-29 12:51:35 -0700 | [diff] [blame] | 6352 | synchronized(mWindowMap) { |
| 6353 | if (mDisplay != null) { |
| 6354 | throw new IllegalStateException("Display already initialized"); |
| 6355 | } |
| 6356 | WindowManager wm = (WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE); |
| 6357 | mDisplay = wm.getDefaultDisplay(); |
| 6358 | mInitialDisplayWidth = mDisplay.getWidth(); |
| 6359 | mInitialDisplayHeight = mDisplay.getHeight(); |
Dianne Hackborn | 4c7cc34 | 2010-12-16 16:37:39 -0800 | [diff] [blame] | 6360 | mInputManager.setDisplaySize(0, Display.unmapDisplaySize(mInitialDisplayWidth), |
| 6361 | Display.unmapDisplaySize(mInitialDisplayHeight)); |
Dianne Hackborn | 5132b37 | 2010-07-29 12:51:35 -0700 | [diff] [blame] | 6362 | } |
| 6363 | |
| 6364 | try { |
| 6365 | mActivityManager.updateConfiguration(null); |
| 6366 | } catch (RemoteException e) { |
| 6367 | } |
Dianne Hackborn | 154db5f | 2010-07-29 19:15:19 -0700 | [diff] [blame] | 6368 | |
| 6369 | mPolicy.systemReady(); |
Dianne Hackborn | 5132b37 | 2010-07-29 12:51:35 -0700 | [diff] [blame] | 6370 | } |
| 6371 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6372 | // ------------------------------------------------------------- |
| 6373 | // Client Session State |
| 6374 | // ------------------------------------------------------------- |
| 6375 | |
| 6376 | private final class Session extends IWindowSession.Stub |
| 6377 | implements IBinder.DeathRecipient { |
| 6378 | final IInputMethodClient mClient; |
| 6379 | final IInputContext mInputContext; |
| 6380 | final int mUid; |
| 6381 | final int mPid; |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 6382 | final String mStringName; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6383 | SurfaceSession mSurfaceSession; |
| 6384 | int mNumWindow = 0; |
| 6385 | boolean mClientDead = false; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6386 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6387 | public Session(IInputMethodClient client, IInputContext inputContext) { |
| 6388 | mClient = client; |
| 6389 | mInputContext = inputContext; |
| 6390 | mUid = Binder.getCallingUid(); |
| 6391 | mPid = Binder.getCallingPid(); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 6392 | StringBuilder sb = new StringBuilder(); |
| 6393 | sb.append("Session{"); |
| 6394 | sb.append(Integer.toHexString(System.identityHashCode(this))); |
| 6395 | sb.append(" uid "); |
| 6396 | sb.append(mUid); |
| 6397 | sb.append("}"); |
| 6398 | mStringName = sb.toString(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6399 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6400 | synchronized (mWindowMap) { |
| 6401 | if (mInputMethodManager == null && mHaveInputMethods) { |
| 6402 | IBinder b = ServiceManager.getService( |
| 6403 | Context.INPUT_METHOD_SERVICE); |
| 6404 | mInputMethodManager = IInputMethodManager.Stub.asInterface(b); |
| 6405 | } |
| 6406 | } |
| 6407 | long ident = Binder.clearCallingIdentity(); |
| 6408 | try { |
| 6409 | // Note: it is safe to call in to the input method manager |
| 6410 | // here because we are not holding our lock. |
| 6411 | if (mInputMethodManager != null) { |
| 6412 | mInputMethodManager.addClient(client, inputContext, |
| 6413 | mUid, mPid); |
| 6414 | } else { |
| 6415 | client.setUsingInputMethod(false); |
| 6416 | } |
| 6417 | client.asBinder().linkToDeath(this, 0); |
| 6418 | } catch (RemoteException e) { |
| 6419 | // The caller has died, so we can just forget about this. |
| 6420 | try { |
| 6421 | if (mInputMethodManager != null) { |
| 6422 | mInputMethodManager.removeClient(client); |
| 6423 | } |
| 6424 | } catch (RemoteException ee) { |
| 6425 | } |
| 6426 | } finally { |
| 6427 | Binder.restoreCallingIdentity(ident); |
| 6428 | } |
| 6429 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6430 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6431 | @Override |
| 6432 | public boolean onTransact(int code, Parcel data, Parcel reply, int flags) |
| 6433 | throws RemoteException { |
| 6434 | try { |
| 6435 | return super.onTransact(code, data, reply, flags); |
| 6436 | } catch (RuntimeException e) { |
| 6437 | // Log all 'real' exceptions thrown to the caller |
| 6438 | if (!(e instanceof SecurityException)) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6439 | Slog.e(TAG, "Window Session Crash", e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6440 | } |
| 6441 | throw e; |
| 6442 | } |
| 6443 | } |
| 6444 | |
| 6445 | public void binderDied() { |
| 6446 | // Note: it is safe to call in to the input method manager |
| 6447 | // here because we are not holding our lock. |
| 6448 | try { |
| 6449 | if (mInputMethodManager != null) { |
| 6450 | mInputMethodManager.removeClient(mClient); |
| 6451 | } |
| 6452 | } catch (RemoteException e) { |
| 6453 | } |
| 6454 | synchronized(mWindowMap) { |
Suchi Amalapurapu | fff2fda | 2009-06-30 21:36:16 -0700 | [diff] [blame] | 6455 | mClient.asBinder().unlinkToDeath(this, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6456 | mClientDead = true; |
| 6457 | killSessionLocked(); |
| 6458 | } |
| 6459 | } |
| 6460 | |
| 6461 | public int add(IWindow window, WindowManager.LayoutParams attrs, |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 6462 | int viewVisibility, Rect outContentInsets, InputChannel outInputChannel) { |
| 6463 | return addWindow(this, window, attrs, viewVisibility, outContentInsets, |
| 6464 | outInputChannel); |
| 6465 | } |
| 6466 | |
| 6467 | public int addWithoutInputChannel(IWindow window, WindowManager.LayoutParams attrs, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6468 | int viewVisibility, Rect outContentInsets) { |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 6469 | return addWindow(this, window, attrs, viewVisibility, outContentInsets, null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6470 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6471 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6472 | public void remove(IWindow window) { |
| 6473 | removeWindow(this, window); |
| 6474 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6475 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6476 | public int relayout(IWindow window, WindowManager.LayoutParams attrs, |
| 6477 | int requestedWidth, int requestedHeight, int viewFlags, |
| 6478 | boolean insetsPending, Rect outFrame, Rect outContentInsets, |
Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 6479 | Rect outVisibleInsets, Configuration outConfig, Surface outSurface) { |
Dianne Hackborn | f123e49 | 2010-09-24 11:16:23 -0700 | [diff] [blame] | 6480 | //Log.d(TAG, ">>>>>> ENTERED relayout from " + Binder.getCallingPid()); |
| 6481 | int res = relayoutWindow(this, window, attrs, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6482 | requestedWidth, requestedHeight, viewFlags, insetsPending, |
Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 6483 | outFrame, outContentInsets, outVisibleInsets, outConfig, outSurface); |
Dianne Hackborn | f123e49 | 2010-09-24 11:16:23 -0700 | [diff] [blame] | 6484 | //Log.d(TAG, "<<<<<< EXITING relayout to " + Binder.getCallingPid()); |
| 6485 | return res; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6486 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6487 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6488 | public void setTransparentRegion(IWindow window, Region region) { |
| 6489 | setTransparentRegionWindow(this, window, region); |
| 6490 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6491 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6492 | public void setInsets(IWindow window, int touchableInsets, |
Jeff Brown | fbf0977 | 2011-01-16 14:06:57 -0800 | [diff] [blame] | 6493 | Rect contentInsets, Rect visibleInsets, Region touchableArea) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6494 | setInsetsWindow(this, window, touchableInsets, contentInsets, |
Jeff Brown | fbf0977 | 2011-01-16 14:06:57 -0800 | [diff] [blame] | 6495 | visibleInsets, touchableArea); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6496 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6497 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6498 | public void getDisplayFrame(IWindow window, Rect outDisplayFrame) { |
| 6499 | getWindowDisplayFrame(this, window, outDisplayFrame); |
| 6500 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6501 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6502 | public void finishDrawing(IWindow window) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6503 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6504 | TAG, "IWindow finishDrawing called for " + window); |
| 6505 | finishDrawingWindow(this, window); |
| 6506 | } |
| 6507 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6508 | public void setInTouchMode(boolean mode) { |
| 6509 | synchronized(mWindowMap) { |
| 6510 | mInTouchMode = mode; |
| 6511 | } |
| 6512 | } |
| 6513 | |
| 6514 | public boolean getInTouchMode() { |
| 6515 | synchronized(mWindowMap) { |
| 6516 | return mInTouchMode; |
| 6517 | } |
| 6518 | } |
| 6519 | |
| 6520 | public boolean performHapticFeedback(IWindow window, int effectId, |
| 6521 | boolean always) { |
| 6522 | synchronized(mWindowMap) { |
| 6523 | long ident = Binder.clearCallingIdentity(); |
| 6524 | try { |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 6525 | return mPolicy.performHapticFeedbackLw( |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 6526 | windowForClientLocked(this, window, true), |
| 6527 | effectId, always); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6528 | } finally { |
| 6529 | Binder.restoreCallingIdentity(ident); |
| 6530 | } |
| 6531 | } |
| 6532 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6533 | |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 6534 | /* Drag/drop */ |
Christopher Tate | 02d2b3b | 2011-01-10 20:43:53 -0800 | [diff] [blame] | 6535 | public IBinder prepareDrag(IWindow window, int flags, |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 6536 | int width, int height, Surface outSurface) { |
Christopher Tate | 02d2b3b | 2011-01-10 20:43:53 -0800 | [diff] [blame] | 6537 | return prepareDragSurface(window, mSurfaceSession, flags, |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 6538 | width, height, outSurface); |
| 6539 | } |
| 6540 | |
| 6541 | public boolean performDrag(IWindow window, IBinder dragToken, |
| 6542 | float touchX, float touchY, float thumbCenterX, float thumbCenterY, |
| 6543 | ClipData data) { |
| 6544 | if (DEBUG_DRAG) { |
| 6545 | Slog.d(TAG, "perform drag: win=" + window + " data=" + data); |
| 6546 | } |
| 6547 | |
| 6548 | synchronized (mWindowMap) { |
| 6549 | if (mDragState == null) { |
| 6550 | Slog.w(TAG, "No drag prepared"); |
| 6551 | throw new IllegalStateException("performDrag() without prepareDrag()"); |
| 6552 | } |
| 6553 | |
| 6554 | if (dragToken != mDragState.mToken) { |
| 6555 | Slog.w(TAG, "Performing mismatched drag"); |
| 6556 | throw new IllegalStateException("performDrag() does not match prepareDrag()"); |
| 6557 | } |
| 6558 | |
| 6559 | WindowState callingWin = windowForClientLocked(null, window, false); |
| 6560 | if (callingWin == null) { |
| 6561 | Slog.w(TAG, "Bad requesting window " + window); |
| 6562 | return false; // !!! TODO: throw here? |
| 6563 | } |
| 6564 | |
| 6565 | // !!! TODO: if input is not still focused on the initiating window, fail |
| 6566 | // the drag initiation (e.g. an alarm window popped up just as the application |
| 6567 | // called performDrag() |
| 6568 | |
| 6569 | mH.removeMessages(H.DRAG_START_TIMEOUT, window.asBinder()); |
| 6570 | |
Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 6571 | // !!! TODO: extract the current touch (x, y) in screen coordinates. That |
| 6572 | // will let us eliminate the (touchX,touchY) parameters from the API. |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 6573 | |
Chris Tate | b478f46 | 2010-10-15 16:02:26 -0700 | [diff] [blame] | 6574 | // !!! FIXME: put all this heavy stuff onto the mH looper, as well as |
| 6575 | // the actual drag event dispatch stuff in the dragstate |
| 6576 | |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 6577 | mDragState.register(); |
Jeff Brown | 2e44b07 | 2011-01-24 15:21:56 -0800 | [diff] [blame^] | 6578 | mInputMonitor.updateInputWindowsLw(true /*force*/); |
Chris Tate | ef70a07 | 2010-10-22 19:10:34 -0700 | [diff] [blame] | 6579 | if (!mInputManager.transferTouchFocus(callingWin.mInputChannel, |
| 6580 | mDragState.mServerChannel)) { |
| 6581 | Slog.e(TAG, "Unable to transfer touch focus"); |
| 6582 | mDragState.unregister(); |
| 6583 | mDragState = null; |
Jeff Brown | 2e44b07 | 2011-01-24 15:21:56 -0800 | [diff] [blame^] | 6584 | mInputMonitor.updateInputWindowsLw(true /*force*/); |
Chris Tate | ef70a07 | 2010-10-22 19:10:34 -0700 | [diff] [blame] | 6585 | return false; |
| 6586 | } |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 6587 | |
| 6588 | mDragState.mData = data; |
Chris Tate | b478f46 | 2010-10-15 16:02:26 -0700 | [diff] [blame] | 6589 | mDragState.mCurrentX = touchX; |
| 6590 | mDragState.mCurrentY = touchY; |
Chris Tate | b8203e9 | 2010-10-12 14:23:21 -0700 | [diff] [blame] | 6591 | mDragState.broadcastDragStartedLw(touchX, touchY); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 6592 | |
| 6593 | // remember the thumb offsets for later |
| 6594 | mDragState.mThumbOffsetX = thumbCenterX; |
| 6595 | mDragState.mThumbOffsetY = thumbCenterY; |
| 6596 | |
| 6597 | // Make the surface visible at the proper location |
| 6598 | final Surface surface = mDragState.mSurface; |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 6599 | if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION performDrag"); |
Chris Tate | b478f46 | 2010-10-15 16:02:26 -0700 | [diff] [blame] | 6600 | Surface.openTransaction(); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 6601 | try { |
| 6602 | surface.setPosition((int)(touchX - thumbCenterX), |
| 6603 | (int)(touchY - thumbCenterY)); |
Chris Tate | b478f46 | 2010-10-15 16:02:26 -0700 | [diff] [blame] | 6604 | surface.setAlpha(.7071f); |
Chris Tate | a32dcf7 | 2010-10-14 12:13:50 -0700 | [diff] [blame] | 6605 | surface.setLayer(mDragState.getDragLayerLw()); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 6606 | surface.show(); |
| 6607 | } finally { |
Chris Tate | b478f46 | 2010-10-15 16:02:26 -0700 | [diff] [blame] | 6608 | Surface.closeTransaction(); |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 6609 | if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION performDrag"); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 6610 | } |
| 6611 | } |
| 6612 | |
| 6613 | return true; // success! |
| 6614 | } |
| 6615 | |
Chris Tate | d4533f14 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 6616 | public void reportDropResult(IWindow window, boolean consumed) { |
| 6617 | IBinder token = window.asBinder(); |
| 6618 | if (DEBUG_DRAG) { |
| 6619 | Slog.d(TAG, "Drop result=" + consumed + " reported by " + token); |
| 6620 | } |
| 6621 | |
| 6622 | synchronized (mWindowMap) { |
Christopher Tate | ccd24de | 2011-01-12 15:02:55 -0800 | [diff] [blame] | 6623 | long ident = Binder.clearCallingIdentity(); |
| 6624 | try { |
Jeff Brown | fbf0977 | 2011-01-16 14:06:57 -0800 | [diff] [blame] | 6625 | if (mDragState == null || mDragState.mToken != token) { |
Christopher Tate | ccd24de | 2011-01-12 15:02:55 -0800 | [diff] [blame] | 6626 | Slog.w(TAG, "Invalid drop-result claim by " + window); |
| 6627 | throw new IllegalStateException("reportDropResult() by non-recipient"); |
| 6628 | } |
| 6629 | |
| 6630 | // The right window has responded, even if it's no longer around, |
| 6631 | // so be sure to halt the timeout even if the later WindowState |
| 6632 | // lookup fails. |
| 6633 | mH.removeMessages(H.DRAG_END_TIMEOUT, window.asBinder()); |
| 6634 | WindowState callingWin = windowForClientLocked(null, window, false); |
| 6635 | if (callingWin == null) { |
| 6636 | Slog.w(TAG, "Bad result-reporting window " + window); |
| 6637 | return; // !!! TODO: throw here? |
| 6638 | } |
| 6639 | |
| 6640 | mDragState.mDragResult = consumed; |
| 6641 | mDragState.endDragLw(); |
| 6642 | } finally { |
| 6643 | Binder.restoreCallingIdentity(ident); |
Chris Tate | d4533f14 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 6644 | } |
Chris Tate | d4533f14 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 6645 | } |
| 6646 | } |
| 6647 | |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 6648 | public void dragRecipientEntered(IWindow window) { |
| 6649 | if (DEBUG_DRAG) { |
Chris Tate | d4533f14 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 6650 | Slog.d(TAG, "Drag into new candidate view @ " + window.asBinder()); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 6651 | } |
| 6652 | } |
| 6653 | |
| 6654 | public void dragRecipientExited(IWindow window) { |
| 6655 | if (DEBUG_DRAG) { |
Chris Tate | d4533f14 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 6656 | Slog.d(TAG, "Drag from old candidate view @ " + window.asBinder()); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 6657 | } |
| 6658 | } |
| 6659 | |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 6660 | public void setWallpaperPosition(IBinder window, float x, float y, float xStep, float yStep) { |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 6661 | synchronized(mWindowMap) { |
| 6662 | long ident = Binder.clearCallingIdentity(); |
| 6663 | try { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 6664 | setWindowWallpaperPositionLocked( |
| 6665 | windowForClientLocked(this, window, true), |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 6666 | x, y, xStep, yStep); |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 6667 | } finally { |
| 6668 | Binder.restoreCallingIdentity(ident); |
| 6669 | } |
| 6670 | } |
| 6671 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6672 | |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 6673 | public void wallpaperOffsetsComplete(IBinder window) { |
| 6674 | WindowManagerService.this.wallpaperOffsetsComplete(window); |
| 6675 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6676 | |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 6677 | public Bundle sendWallpaperCommand(IBinder window, String action, int x, int y, |
| 6678 | int z, Bundle extras, boolean sync) { |
| 6679 | synchronized(mWindowMap) { |
| 6680 | long ident = Binder.clearCallingIdentity(); |
| 6681 | try { |
| 6682 | return sendWindowWallpaperCommandLocked( |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 6683 | windowForClientLocked(this, window, true), |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 6684 | action, x, y, z, extras, sync); |
| 6685 | } finally { |
| 6686 | Binder.restoreCallingIdentity(ident); |
| 6687 | } |
| 6688 | } |
| 6689 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6690 | |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 6691 | public void wallpaperCommandComplete(IBinder window, Bundle result) { |
| 6692 | WindowManagerService.this.wallpaperCommandComplete(window, result); |
| 6693 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6694 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6695 | void windowAddedLocked() { |
| 6696 | if (mSurfaceSession == null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6697 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6698 | TAG, "First window added to " + this + ", creating SurfaceSession"); |
| 6699 | mSurfaceSession = new SurfaceSession(); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6700 | if (SHOW_TRANSACTIONS) Slog.i( |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 6701 | TAG, " NEW SURFACE SESSION " + mSurfaceSession); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6702 | mSessions.add(this); |
| 6703 | } |
| 6704 | mNumWindow++; |
| 6705 | } |
| 6706 | |
| 6707 | void windowRemovedLocked() { |
| 6708 | mNumWindow--; |
| 6709 | killSessionLocked(); |
| 6710 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6711 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6712 | void killSessionLocked() { |
| 6713 | if (mNumWindow <= 0 && mClientDead) { |
| 6714 | mSessions.remove(this); |
| 6715 | if (mSurfaceSession != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6716 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6717 | TAG, "Last window removed from " + this |
| 6718 | + ", destroying " + mSurfaceSession); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6719 | if (SHOW_TRANSACTIONS) Slog.i( |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 6720 | TAG, " KILL SURFACE SESSION " + mSurfaceSession); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6721 | try { |
| 6722 | mSurfaceSession.kill(); |
| 6723 | } catch (Exception e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6724 | Slog.w(TAG, "Exception thrown when killing surface session " |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6725 | + mSurfaceSession + " in session " + this |
| 6726 | + ": " + e.toString()); |
| 6727 | } |
| 6728 | mSurfaceSession = null; |
| 6729 | } |
| 6730 | } |
| 6731 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6732 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6733 | void dump(PrintWriter pw, String prefix) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 6734 | pw.print(prefix); pw.print("mNumWindow="); pw.print(mNumWindow); |
| 6735 | pw.print(" mClientDead="); pw.print(mClientDead); |
| 6736 | pw.print(" mSurfaceSession="); pw.println(mSurfaceSession); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6737 | } |
| 6738 | |
| 6739 | @Override |
| 6740 | public String toString() { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 6741 | return mStringName; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6742 | } |
| 6743 | } |
| 6744 | |
| 6745 | // ------------------------------------------------------------- |
| 6746 | // Client Window State |
| 6747 | // ------------------------------------------------------------- |
| 6748 | |
| 6749 | private final class WindowState implements WindowManagerPolicy.WindowState { |
| 6750 | final Session mSession; |
| 6751 | final IWindow mClient; |
| 6752 | WindowToken mToken; |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 6753 | WindowToken mRootToken; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6754 | AppWindowToken mAppToken; |
| 6755 | AppWindowToken mTargetAppToken; |
| 6756 | final WindowManager.LayoutParams mAttrs = new WindowManager.LayoutParams(); |
| 6757 | final DeathRecipient mDeathRecipient; |
| 6758 | final WindowState mAttachedWindow; |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 6759 | final ArrayList<WindowState> mChildWindows = new ArrayList<WindowState>(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6760 | final int mBaseLayer; |
| 6761 | final int mSubLayer; |
| 6762 | final boolean mLayoutAttached; |
| 6763 | final boolean mIsImWindow; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 6764 | final boolean mIsWallpaper; |
| 6765 | final boolean mIsFloatingLayer; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6766 | int mViewVisibility; |
| 6767 | boolean mPolicyVisibility = true; |
| 6768 | boolean mPolicyVisibilityAfterAnim = true; |
| 6769 | boolean mAppFreezing; |
| 6770 | Surface mSurface; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 6771 | boolean mReportDestroySurface; |
| 6772 | boolean mSurfacePendingDestroy; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6773 | boolean mAttachedHidden; // is our parent window hidden? |
| 6774 | boolean mLastHidden; // was this window last hidden? |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 6775 | boolean mWallpaperVisible; // for wallpaper, what was last vis report? |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6776 | int mRequestedWidth; |
| 6777 | int mRequestedHeight; |
| 6778 | int mLastRequestedWidth; |
| 6779 | int mLastRequestedHeight; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6780 | int mLayer; |
| 6781 | int mAnimLayer; |
| 6782 | int mLastLayer; |
| 6783 | boolean mHaveFrame; |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 6784 | boolean mObscured; |
Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 6785 | boolean mTurnOnScreen; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6786 | |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 6787 | int mLayoutSeq = -1; |
| 6788 | |
| 6789 | Configuration mConfiguration = null; |
| 6790 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6791 | // Actual frame shown on-screen (may be modified by animation) |
| 6792 | final Rect mShownFrame = new Rect(); |
| 6793 | final Rect mLastShownFrame = new Rect(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6794 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6795 | /** |
Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 6796 | * Set when we have changed the size of the surface, to know that |
| 6797 | * we must tell them application to resize (and thus redraw itself). |
| 6798 | */ |
| 6799 | boolean mSurfaceResized; |
| 6800 | |
| 6801 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6802 | * Insets that determine the actually visible area |
| 6803 | */ |
| 6804 | final Rect mVisibleInsets = new Rect(); |
| 6805 | final Rect mLastVisibleInsets = new Rect(); |
| 6806 | boolean mVisibleInsetsChanged; |
| 6807 | |
| 6808 | /** |
| 6809 | * Insets that are covered by system windows |
| 6810 | */ |
| 6811 | final Rect mContentInsets = new Rect(); |
| 6812 | final Rect mLastContentInsets = new Rect(); |
| 6813 | boolean mContentInsetsChanged; |
| 6814 | |
| 6815 | /** |
| 6816 | * Set to true if we are waiting for this window to receive its |
| 6817 | * given internal insets before laying out other windows based on it. |
| 6818 | */ |
| 6819 | boolean mGivenInsetsPending; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6820 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6821 | /** |
| 6822 | * These are the content insets that were given during layout for |
| 6823 | * this window, to be applied to windows behind it. |
| 6824 | */ |
| 6825 | final Rect mGivenContentInsets = new Rect(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6826 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6827 | /** |
| 6828 | * These are the visible insets that were given during layout for |
| 6829 | * this window, to be applied to windows behind it. |
| 6830 | */ |
| 6831 | final Rect mGivenVisibleInsets = new Rect(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6832 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6833 | /** |
Jeff Brown | fbf0977 | 2011-01-16 14:06:57 -0800 | [diff] [blame] | 6834 | * This is the given touchable area relative to the window frame, or null if none. |
| 6835 | */ |
| 6836 | final Region mGivenTouchableRegion = new Region(); |
| 6837 | |
| 6838 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6839 | * Flag indicating whether the touchable region should be adjusted by |
| 6840 | * the visible insets; if false the area outside the visible insets is |
| 6841 | * NOT touchable, so we must use those to adjust the frame during hit |
| 6842 | * tests. |
| 6843 | */ |
| 6844 | int mTouchableInsets = ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6845 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6846 | // Current transformation being applied. |
Dianne Hackborn | 7da6ac3 | 2010-12-09 19:22:04 -0800 | [diff] [blame] | 6847 | boolean mHaveMatrix; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6848 | float mDsDx=1, mDtDx=0, mDsDy=0, mDtDy=1; |
| 6849 | float mLastDsDx=1, mLastDtDx=0, mLastDsDy=0, mLastDtDy=1; |
| 6850 | float mHScale=1, mVScale=1; |
| 6851 | float mLastHScale=1, mLastVScale=1; |
| 6852 | final Matrix mTmpMatrix = new Matrix(); |
| 6853 | |
| 6854 | // "Real" frame that the application sees. |
| 6855 | final Rect mFrame = new Rect(); |
| 6856 | final Rect mLastFrame = new Rect(); |
| 6857 | |
| 6858 | final Rect mContainingFrame = new Rect(); |
| 6859 | final Rect mDisplayFrame = new Rect(); |
| 6860 | final Rect mContentFrame = new Rect(); |
Dianne Hackborn | 1c24e95 | 2010-11-23 00:34:30 -0800 | [diff] [blame] | 6861 | final Rect mParentFrame = new Rect(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6862 | final Rect mVisibleFrame = new Rect(); |
| 6863 | |
Dianne Hackborn | 8e11ef0 | 2010-11-18 19:47:42 -0800 | [diff] [blame] | 6864 | boolean mContentChanged; |
| 6865 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6866 | float mShownAlpha = 1; |
| 6867 | float mAlpha = 1; |
| 6868 | float mLastAlpha = 1; |
| 6869 | |
| 6870 | // Set to true if, when the window gets displayed, it should perform |
| 6871 | // an enter animation. |
| 6872 | boolean mEnterAnimationPending; |
| 6873 | |
| 6874 | // Currently running animation. |
| 6875 | boolean mAnimating; |
| 6876 | boolean mLocalAnimating; |
| 6877 | Animation mAnimation; |
| 6878 | boolean mAnimationIsEntrance; |
| 6879 | boolean mHasTransformation; |
| 6880 | boolean mHasLocalTransformation; |
| 6881 | final Transformation mTransformation = new Transformation(); |
| 6882 | |
Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 6883 | // If a window showing a wallpaper: the requested offset for the |
| 6884 | // wallpaper; if a wallpaper window: the currently applied offset. |
| 6885 | float mWallpaperX = -1; |
| 6886 | float mWallpaperY = -1; |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 6887 | |
| 6888 | // If a window showing a wallpaper: what fraction of the offset |
| 6889 | // range corresponds to a full virtual screen. |
| 6890 | float mWallpaperXStep = -1; |
| 6891 | float mWallpaperYStep = -1; |
| 6892 | |
Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 6893 | // Wallpaper windows: pixels offset based on above variables. |
| 6894 | int mXOffset; |
| 6895 | int mYOffset; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6896 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6897 | // This is set after IWindowSession.relayout() has been called at |
| 6898 | // least once for the window. It allows us to detect the situation |
| 6899 | // where we don't yet have a surface, but should have one soon, so |
| 6900 | // we can give the window focus before waiting for the relayout. |
| 6901 | boolean mRelayoutCalled; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6902 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6903 | // This is set after the Surface has been created but before the |
| 6904 | // window has been drawn. During this time the surface is hidden. |
| 6905 | boolean mDrawPending; |
| 6906 | |
| 6907 | // This is set after the window has finished drawing for the first |
| 6908 | // time but before its surface is shown. The surface will be |
| 6909 | // displayed when the next layout is run. |
| 6910 | boolean mCommitDrawPending; |
| 6911 | |
| 6912 | // This is set during the time after the window's drawing has been |
| 6913 | // committed, and before its surface is actually shown. It is used |
| 6914 | // to delay showing the surface until all windows in a token are ready |
| 6915 | // to be shown. |
| 6916 | boolean mReadyToShow; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6917 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6918 | // Set when the window has been shown in the screen the first time. |
| 6919 | boolean mHasDrawn; |
| 6920 | |
| 6921 | // Currently running an exit animation? |
| 6922 | boolean mExiting; |
| 6923 | |
| 6924 | // Currently on the mDestroySurface list? |
| 6925 | boolean mDestroying; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6926 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6927 | // Completely remove from window manager after exit animation? |
| 6928 | boolean mRemoveOnExit; |
| 6929 | |
| 6930 | // Set when the orientation is changing and this window has not yet |
| 6931 | // been updated for the new orientation. |
| 6932 | boolean mOrientationChanging; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6933 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6934 | // Is this window now (or just being) removed? |
| 6935 | boolean mRemoved; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6936 | |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 6937 | // Temp for keeping track of windows that have been removed when |
| 6938 | // rebuilding window list. |
| 6939 | boolean mRebuilding; |
| 6940 | |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 6941 | // For debugging, this is the last information given to the surface flinger. |
| 6942 | boolean mSurfaceShown; |
| 6943 | int mSurfaceX, mSurfaceY, mSurfaceW, mSurfaceH; |
| 6944 | int mSurfaceLayer; |
| 6945 | float mSurfaceAlpha; |
| 6946 | |
Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame] | 6947 | // Input channel and input window handle used by the input dispatcher. |
| 6948 | InputWindowHandle mInputWindowHandle; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 6949 | InputChannel mInputChannel; |
| 6950 | |
Mattias Petersson | 1622eee | 2010-12-21 10:15:11 +0100 | [diff] [blame] | 6951 | // Used to improve performance of toString() |
| 6952 | String mStringNameCache; |
| 6953 | CharSequence mLastTitle; |
| 6954 | boolean mWasPaused; |
| 6955 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6956 | WindowState(Session s, IWindow c, WindowToken token, |
| 6957 | WindowState attachedWindow, WindowManager.LayoutParams a, |
| 6958 | int viewVisibility) { |
| 6959 | mSession = s; |
| 6960 | mClient = c; |
| 6961 | mToken = token; |
| 6962 | mAttrs.copyFrom(a); |
| 6963 | mViewVisibility = viewVisibility; |
| 6964 | DeathRecipient deathRecipient = new DeathRecipient(); |
| 6965 | mAlpha = a.alpha; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6966 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6967 | TAG, "Window " + this + " client=" + c.asBinder() |
| 6968 | + " token=" + token + " (" + mAttrs.token + ")"); |
| 6969 | try { |
| 6970 | c.asBinder().linkToDeath(deathRecipient, 0); |
| 6971 | } catch (RemoteException e) { |
| 6972 | mDeathRecipient = null; |
| 6973 | mAttachedWindow = null; |
| 6974 | mLayoutAttached = false; |
| 6975 | mIsImWindow = false; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 6976 | mIsWallpaper = false; |
| 6977 | mIsFloatingLayer = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6978 | mBaseLayer = 0; |
| 6979 | mSubLayer = 0; |
| 6980 | return; |
| 6981 | } |
| 6982 | mDeathRecipient = deathRecipient; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6983 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6984 | if ((mAttrs.type >= FIRST_SUB_WINDOW && |
| 6985 | mAttrs.type <= LAST_SUB_WINDOW)) { |
| 6986 | // The multiplier here is to reserve space for multiple |
| 6987 | // windows in the same type layer. |
| 6988 | mBaseLayer = mPolicy.windowTypeToLayerLw( |
| 6989 | attachedWindow.mAttrs.type) * TYPE_LAYER_MULTIPLIER |
| 6990 | + TYPE_LAYER_OFFSET; |
| 6991 | mSubLayer = mPolicy.subWindowTypeToLayerLw(a.type); |
| 6992 | mAttachedWindow = attachedWindow; |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 6993 | if (DEBUG_ADD_REMOVE) Slog.v(TAG, "Adding " + this + " to " + mAttachedWindow); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6994 | mAttachedWindow.mChildWindows.add(this); |
| 6995 | mLayoutAttached = mAttrs.type != |
| 6996 | WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG; |
| 6997 | mIsImWindow = attachedWindow.mAttrs.type == TYPE_INPUT_METHOD |
| 6998 | || attachedWindow.mAttrs.type == TYPE_INPUT_METHOD_DIALOG; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 6999 | mIsWallpaper = attachedWindow.mAttrs.type == TYPE_WALLPAPER; |
| 7000 | mIsFloatingLayer = mIsImWindow || mIsWallpaper; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7001 | } else { |
| 7002 | // The multiplier here is to reserve space for multiple |
| 7003 | // windows in the same type layer. |
| 7004 | mBaseLayer = mPolicy.windowTypeToLayerLw(a.type) |
| 7005 | * TYPE_LAYER_MULTIPLIER |
| 7006 | + TYPE_LAYER_OFFSET; |
| 7007 | mSubLayer = 0; |
| 7008 | mAttachedWindow = null; |
| 7009 | mLayoutAttached = false; |
| 7010 | mIsImWindow = mAttrs.type == TYPE_INPUT_METHOD |
| 7011 | || mAttrs.type == TYPE_INPUT_METHOD_DIALOG; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 7012 | mIsWallpaper = mAttrs.type == TYPE_WALLPAPER; |
| 7013 | mIsFloatingLayer = mIsImWindow || mIsWallpaper; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7014 | } |
| 7015 | |
| 7016 | WindowState appWin = this; |
| 7017 | while (appWin.mAttachedWindow != null) { |
| 7018 | appWin = mAttachedWindow; |
| 7019 | } |
| 7020 | WindowToken appToken = appWin.mToken; |
| 7021 | while (appToken.appWindowToken == null) { |
| 7022 | WindowToken parent = mTokenMap.get(appToken.token); |
| 7023 | if (parent == null || appToken == parent) { |
| 7024 | break; |
| 7025 | } |
| 7026 | appToken = parent; |
| 7027 | } |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 7028 | mRootToken = appToken; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7029 | mAppToken = appToken.appWindowToken; |
| 7030 | |
| 7031 | mSurface = null; |
| 7032 | mRequestedWidth = 0; |
| 7033 | mRequestedHeight = 0; |
| 7034 | mLastRequestedWidth = 0; |
| 7035 | mLastRequestedHeight = 0; |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 7036 | mXOffset = 0; |
| 7037 | mYOffset = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7038 | mLayer = 0; |
| 7039 | mAnimLayer = 0; |
| 7040 | mLastLayer = 0; |
Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame] | 7041 | mInputWindowHandle = new InputWindowHandle( |
| 7042 | mAppToken != null ? mAppToken.mInputApplicationHandle : null, this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7043 | } |
| 7044 | |
| 7045 | void attach() { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7046 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7047 | TAG, "Attaching " + this + " token=" + mToken |
| 7048 | + ", list=" + mToken.windows); |
| 7049 | mSession.windowAddedLocked(); |
| 7050 | } |
| 7051 | |
| 7052 | public void computeFrameLw(Rect pf, Rect df, Rect cf, Rect vf) { |
| 7053 | mHaveFrame = true; |
| 7054 | |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 7055 | final Rect container = mContainingFrame; |
| 7056 | container.set(pf); |
| 7057 | |
| 7058 | final Rect display = mDisplayFrame; |
| 7059 | display.set(df); |
| 7060 | |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 7061 | if ((mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0) { |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 7062 | container.intersect(mCompatibleScreenFrame); |
Mitsuru Oshima | d2967e2 | 2009-07-20 14:01:43 -0700 | [diff] [blame] | 7063 | if ((mAttrs.flags & FLAG_LAYOUT_NO_LIMITS) == 0) { |
| 7064 | display.intersect(mCompatibleScreenFrame); |
| 7065 | } |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 7066 | } |
| 7067 | |
| 7068 | final int pw = container.right - container.left; |
| 7069 | final int ph = container.bottom - container.top; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7070 | |
| 7071 | int w,h; |
| 7072 | if ((mAttrs.flags & mAttrs.FLAG_SCALED) != 0) { |
| 7073 | w = mAttrs.width < 0 ? pw : mAttrs.width; |
| 7074 | h = mAttrs.height< 0 ? ph : mAttrs.height; |
| 7075 | } else { |
Romain Guy | 980a938 | 2010-01-08 15:06:28 -0800 | [diff] [blame] | 7076 | w = mAttrs.width == mAttrs.MATCH_PARENT ? pw : mRequestedWidth; |
| 7077 | h = mAttrs.height== mAttrs.MATCH_PARENT ? ph : mRequestedHeight; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7078 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7079 | |
Dianne Hackborn | 1c24e95 | 2010-11-23 00:34:30 -0800 | [diff] [blame] | 7080 | if (!mParentFrame.equals(pf)) { |
Dianne Hackborn | 0f761d6 | 2010-11-30 22:06:10 -0800 | [diff] [blame] | 7081 | //Slog.i(TAG, "Window " + this + " content frame from " + mParentFrame |
| 7082 | // + " to " + pf); |
Dianne Hackborn | 1c24e95 | 2010-11-23 00:34:30 -0800 | [diff] [blame] | 7083 | mParentFrame.set(pf); |
| 7084 | mContentChanged = true; |
| 7085 | } |
| 7086 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7087 | final Rect content = mContentFrame; |
| 7088 | content.set(cf); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7089 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7090 | final Rect visible = mVisibleFrame; |
| 7091 | visible.set(vf); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7092 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7093 | final Rect frame = mFrame; |
Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 7094 | final int fw = frame.width(); |
| 7095 | final int fh = frame.height(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7096 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7097 | //System.out.println("In: w=" + w + " h=" + h + " container=" + |
| 7098 | // container + " x=" + mAttrs.x + " y=" + mAttrs.y); |
| 7099 | |
| 7100 | Gravity.apply(mAttrs.gravity, w, h, container, |
| 7101 | (int) (mAttrs.x + mAttrs.horizontalMargin * pw), |
| 7102 | (int) (mAttrs.y + mAttrs.verticalMargin * ph), frame); |
| 7103 | |
| 7104 | //System.out.println("Out: " + mFrame); |
| 7105 | |
| 7106 | // Now make sure the window fits in the overall display. |
| 7107 | Gravity.applyDisplay(mAttrs.gravity, df, frame); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7108 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7109 | // Make sure the content and visible frames are inside of the |
| 7110 | // final window frame. |
| 7111 | if (content.left < frame.left) content.left = frame.left; |
| 7112 | if (content.top < frame.top) content.top = frame.top; |
| 7113 | if (content.right > frame.right) content.right = frame.right; |
| 7114 | if (content.bottom > frame.bottom) content.bottom = frame.bottom; |
| 7115 | if (visible.left < frame.left) visible.left = frame.left; |
| 7116 | if (visible.top < frame.top) visible.top = frame.top; |
| 7117 | if (visible.right > frame.right) visible.right = frame.right; |
| 7118 | if (visible.bottom > frame.bottom) visible.bottom = frame.bottom; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7119 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7120 | final Rect contentInsets = mContentInsets; |
| 7121 | contentInsets.left = content.left-frame.left; |
| 7122 | contentInsets.top = content.top-frame.top; |
| 7123 | contentInsets.right = frame.right-content.right; |
| 7124 | contentInsets.bottom = frame.bottom-content.bottom; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7125 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7126 | final Rect visibleInsets = mVisibleInsets; |
| 7127 | visibleInsets.left = visible.left-frame.left; |
| 7128 | visibleInsets.top = visible.top-frame.top; |
| 7129 | visibleInsets.right = frame.right-visible.right; |
| 7130 | visibleInsets.bottom = frame.bottom-visible.bottom; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7131 | |
Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 7132 | if (mIsWallpaper && (fw != frame.width() || fh != frame.height())) { |
| 7133 | updateWallpaperOffsetLocked(this, mDisplay.getWidth(), |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 7134 | mDisplay.getHeight(), false); |
Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 7135 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7136 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7137 | if (localLOGV) { |
| 7138 | //if ("com.google.android.youtube".equals(mAttrs.packageName) |
| 7139 | // && mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_PANEL) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7140 | Slog.v(TAG, "Resolving (mRequestedWidth=" |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7141 | + mRequestedWidth + ", mRequestedheight=" |
| 7142 | + mRequestedHeight + ") to" + " (pw=" + pw + ", ph=" + ph |
| 7143 | + "): frame=" + mFrame.toShortString() |
| 7144 | + " ci=" + contentInsets.toShortString() |
| 7145 | + " vi=" + visibleInsets.toShortString()); |
| 7146 | //} |
| 7147 | } |
| 7148 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7149 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7150 | public Rect getFrameLw() { |
| 7151 | return mFrame; |
| 7152 | } |
| 7153 | |
| 7154 | public Rect getShownFrameLw() { |
| 7155 | return mShownFrame; |
| 7156 | } |
| 7157 | |
| 7158 | public Rect getDisplayFrameLw() { |
| 7159 | return mDisplayFrame; |
| 7160 | } |
| 7161 | |
| 7162 | public Rect getContentFrameLw() { |
| 7163 | return mContentFrame; |
| 7164 | } |
| 7165 | |
| 7166 | public Rect getVisibleFrameLw() { |
| 7167 | return mVisibleFrame; |
| 7168 | } |
| 7169 | |
| 7170 | public boolean getGivenInsetsPendingLw() { |
| 7171 | return mGivenInsetsPending; |
| 7172 | } |
| 7173 | |
| 7174 | public Rect getGivenContentInsetsLw() { |
| 7175 | return mGivenContentInsets; |
| 7176 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7177 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7178 | public Rect getGivenVisibleInsetsLw() { |
| 7179 | return mGivenVisibleInsets; |
| 7180 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7181 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7182 | public WindowManager.LayoutParams getAttrs() { |
| 7183 | return mAttrs; |
| 7184 | } |
| 7185 | |
| 7186 | public int getSurfaceLayer() { |
| 7187 | return mLayer; |
| 7188 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7189 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7190 | public IApplicationToken getAppToken() { |
| 7191 | return mAppToken != null ? mAppToken.appToken : null; |
| 7192 | } |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 7193 | |
| 7194 | public long getInputDispatchingTimeoutNanos() { |
| 7195 | return mAppToken != null |
| 7196 | ? mAppToken.inputDispatchingTimeoutNanos |
| 7197 | : DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS; |
| 7198 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7199 | |
| 7200 | public boolean hasAppShownWindows() { |
| 7201 | return mAppToken != null ? mAppToken.firstWindowDrawn : false; |
| 7202 | } |
| 7203 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7204 | public void setAnimation(Animation anim) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7205 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7206 | TAG, "Setting animation in " + this + ": " + anim); |
| 7207 | mAnimating = false; |
| 7208 | mLocalAnimating = false; |
| 7209 | mAnimation = anim; |
| 7210 | mAnimation.restrictDuration(MAX_ANIMATION_DURATION); |
| 7211 | mAnimation.scaleCurrentDuration(mWindowAnimationScale); |
| 7212 | } |
| 7213 | |
| 7214 | public void clearAnimation() { |
| 7215 | if (mAnimation != null) { |
| 7216 | mAnimating = true; |
| 7217 | mLocalAnimating = false; |
Brad Fitzpatrick | 3fe3851 | 2010-11-03 11:46:54 -0700 | [diff] [blame] | 7218 | mAnimation.cancel(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7219 | mAnimation = null; |
| 7220 | } |
| 7221 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7222 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7223 | Surface createSurfaceLocked() { |
| 7224 | if (mSurface == null) { |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 7225 | mReportDestroySurface = false; |
| 7226 | mSurfacePendingDestroy = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7227 | mDrawPending = true; |
| 7228 | mCommitDrawPending = false; |
| 7229 | mReadyToShow = false; |
| 7230 | if (mAppToken != null) { |
| 7231 | mAppToken.allDrawn = false; |
| 7232 | } |
| 7233 | |
| 7234 | int flags = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7235 | |
| 7236 | if ((mAttrs.flags&WindowManager.LayoutParams.FLAG_SECURE) != 0) { |
| 7237 | flags |= Surface.SECURE; |
| 7238 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7239 | if (DEBUG_VISIBILITY) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7240 | TAG, "Creating surface in session " |
| 7241 | + mSession.mSurfaceSession + " window " + this |
| 7242 | + " w=" + mFrame.width() |
| 7243 | + " h=" + mFrame.height() + " format=" |
| 7244 | + mAttrs.format + " flags=" + flags); |
| 7245 | |
| 7246 | int w = mFrame.width(); |
| 7247 | int h = mFrame.height(); |
| 7248 | if ((mAttrs.flags & LayoutParams.FLAG_SCALED) != 0) { |
| 7249 | // for a scaled surface, we always want the requested |
| 7250 | // size. |
| 7251 | w = mRequestedWidth; |
| 7252 | h = mRequestedHeight; |
| 7253 | } |
| 7254 | |
Romain Guy | 9825ec6 | 2009-10-01 00:58:09 -0700 | [diff] [blame] | 7255 | // Something is wrong and SurfaceFlinger will not like this, |
| 7256 | // try to revert to sane values |
| 7257 | if (w <= 0) w = 1; |
| 7258 | if (h <= 0) h = 1; |
| 7259 | |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 7260 | mSurfaceShown = false; |
| 7261 | mSurfaceLayer = 0; |
| 7262 | mSurfaceAlpha = 1; |
| 7263 | mSurfaceX = 0; |
| 7264 | mSurfaceY = 0; |
| 7265 | mSurfaceW = w; |
| 7266 | mSurfaceH = h; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7267 | try { |
Romain Guy | d10cd57 | 2010-10-10 13:33:22 -0700 | [diff] [blame] | 7268 | final boolean isHwAccelerated = (mAttrs.flags & |
| 7269 | WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED) != 0; |
| 7270 | final int format = isHwAccelerated ? PixelFormat.TRANSLUCENT : mAttrs.format; |
| 7271 | if (isHwAccelerated && mAttrs.format == PixelFormat.OPAQUE) { |
| 7272 | flags |= Surface.OPAQUE; |
| 7273 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7274 | mSurface = new Surface( |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7275 | mSession.mSurfaceSession, mSession.mPid, |
Mathias Agopian | 5d26c1e | 2010-03-01 16:09:43 -0800 | [diff] [blame] | 7276 | mAttrs.getTitle().toString(), |
Romain Guy | d10cd57 | 2010-10-10 13:33:22 -0700 | [diff] [blame] | 7277 | 0, w, h, format, flags); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7278 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " CREATE SURFACE " |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 7279 | + mSurface + " IN SESSION " |
| 7280 | + mSession.mSurfaceSession |
| 7281 | + ": pid=" + mSession.mPid + " format=" |
| 7282 | + mAttrs.format + " flags=0x" |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 7283 | + Integer.toHexString(flags) |
| 7284 | + " / " + this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7285 | } catch (Surface.OutOfResourcesException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7286 | Slog.w(TAG, "OutOfResourcesException creating surface"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7287 | reclaimSomeSurfaceMemoryLocked(this, "create"); |
| 7288 | return null; |
| 7289 | } catch (Exception e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7290 | Slog.e(TAG, "Exception creating surface", e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7291 | return null; |
| 7292 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7293 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7294 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7295 | TAG, "Got surface: " + mSurface |
| 7296 | + ", set left=" + mFrame.left + " top=" + mFrame.top |
| 7297 | + ", animLayer=" + mAnimLayer); |
| 7298 | if (SHOW_TRANSACTIONS) { |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 7299 | Slog.i(TAG, ">>> OPEN TRANSACTION createSurfaceLocked"); |
| 7300 | logSurface(this, "CREATE pos=(" + mFrame.left + "," + mFrame.top + ") (" + |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 7301 | mFrame.width() + "x" + mFrame.height() + "), layer=" + |
| 7302 | mAnimLayer + " HIDE", null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7303 | } |
| 7304 | Surface.openTransaction(); |
| 7305 | try { |
| 7306 | try { |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 7307 | mSurfaceX = mFrame.left + mXOffset; |
Dianne Hackborn | 529bef6 | 2010-03-25 11:48:43 -0700 | [diff] [blame] | 7308 | mSurfaceY = mFrame.top + mYOffset; |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 7309 | mSurface.setPosition(mSurfaceX, mSurfaceY); |
| 7310 | mSurfaceLayer = mAnimLayer; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7311 | mSurface.setLayer(mAnimLayer); |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 7312 | mSurfaceShown = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7313 | mSurface.hide(); |
| 7314 | if ((mAttrs.flags&WindowManager.LayoutParams.FLAG_DITHER) != 0) { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 7315 | if (SHOW_TRANSACTIONS) logSurface(this, "DITHER", null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7316 | mSurface.setFlags(Surface.SURFACE_DITHER, |
| 7317 | Surface.SURFACE_DITHER); |
| 7318 | } |
| 7319 | } catch (RuntimeException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7320 | Slog.w(TAG, "Error creating surface in " + w, e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7321 | reclaimSomeSurfaceMemoryLocked(this, "create-init"); |
| 7322 | } |
| 7323 | mLastHidden = true; |
| 7324 | } finally { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7325 | Surface.closeTransaction(); |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 7326 | if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION createSurfaceLocked"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7327 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7328 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7329 | TAG, "Created surface " + this); |
| 7330 | } |
| 7331 | return mSurface; |
| 7332 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7333 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7334 | void destroySurfaceLocked() { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7335 | if (mAppToken != null && this == mAppToken.startingWindow) { |
| 7336 | mAppToken.startingDisplayed = false; |
| 7337 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7338 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7339 | if (mSurface != null) { |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 7340 | mDrawPending = false; |
| 7341 | mCommitDrawPending = false; |
| 7342 | mReadyToShow = false; |
| 7343 | |
| 7344 | int i = mChildWindows.size(); |
| 7345 | while (i > 0) { |
| 7346 | i--; |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 7347 | WindowState c = mChildWindows.get(i); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 7348 | c.mAttachedHidden = true; |
| 7349 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7350 | |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 7351 | if (mReportDestroySurface) { |
| 7352 | mReportDestroySurface = false; |
| 7353 | mSurfacePendingDestroy = true; |
| 7354 | try { |
| 7355 | mClient.dispatchGetNewSurface(); |
| 7356 | // We'll really destroy on the next time around. |
| 7357 | return; |
| 7358 | } catch (RemoteException e) { |
| 7359 | } |
| 7360 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7361 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7362 | try { |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 7363 | if (DEBUG_VISIBILITY) { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 7364 | RuntimeException e = null; |
| 7365 | if (!HIDE_STACK_CRAWLS) { |
| 7366 | e = new RuntimeException(); |
| 7367 | e.fillInStackTrace(); |
| 7368 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7369 | Slog.w(TAG, "Window " + this + " destroying surface " |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 7370 | + mSurface + ", session " + mSession, e); |
| 7371 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7372 | if (SHOW_TRANSACTIONS) { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 7373 | RuntimeException e = null; |
| 7374 | if (!HIDE_STACK_CRAWLS) { |
| 7375 | e = new RuntimeException(); |
| 7376 | e.fillInStackTrace(); |
| 7377 | } |
| 7378 | if (SHOW_TRANSACTIONS) logSurface(this, "DESTROY", e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7379 | } |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 7380 | mSurface.destroy(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7381 | } catch (RuntimeException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7382 | Slog.w(TAG, "Exception thrown when destroying Window " + this |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7383 | + " surface " + mSurface + " session " + mSession |
| 7384 | + ": " + e.toString()); |
| 7385 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7386 | |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 7387 | mSurfaceShown = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7388 | mSurface = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7389 | } |
| 7390 | } |
| 7391 | |
| 7392 | boolean finishDrawingLocked() { |
| 7393 | if (mDrawPending) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7394 | if (SHOW_TRANSACTIONS || DEBUG_ORIENTATION) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7395 | TAG, "finishDrawingLocked: " + mSurface); |
| 7396 | mCommitDrawPending = true; |
| 7397 | mDrawPending = false; |
| 7398 | return true; |
| 7399 | } |
| 7400 | return false; |
| 7401 | } |
| 7402 | |
| 7403 | // This must be called while inside a transaction. |
Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 7404 | boolean commitFinishDrawingLocked(long currentTime) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7405 | //Slog.i(TAG, "commitFinishDrawingLocked: " + mSurface); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7406 | if (!mCommitDrawPending) { |
Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 7407 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7408 | } |
| 7409 | mCommitDrawPending = false; |
| 7410 | mReadyToShow = true; |
| 7411 | final boolean starting = mAttrs.type == TYPE_APPLICATION_STARTING; |
| 7412 | final AppWindowToken atoken = mAppToken; |
| 7413 | if (atoken == null || atoken.allDrawn || starting) { |
| 7414 | performShowLocked(); |
| 7415 | } |
Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 7416 | return true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7417 | } |
| 7418 | |
| 7419 | // This must be called while inside a transaction. |
| 7420 | boolean performShowLocked() { |
| 7421 | if (DEBUG_VISIBILITY) { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 7422 | RuntimeException e = null; |
| 7423 | if (!HIDE_STACK_CRAWLS) { |
| 7424 | e = new RuntimeException(); |
| 7425 | e.fillInStackTrace(); |
| 7426 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7427 | Slog.v(TAG, "performShow on " + this |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7428 | + ": readyToShow=" + mReadyToShow + " readyForDisplay=" + isReadyForDisplay() |
| 7429 | + " starting=" + (mAttrs.type == TYPE_APPLICATION_STARTING), e); |
| 7430 | } |
| 7431 | if (mReadyToShow && isReadyForDisplay()) { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 7432 | if (SHOW_TRANSACTIONS || DEBUG_ORIENTATION) logSurface(this, |
| 7433 | "SHOW (performShowLocked)", null); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7434 | if (DEBUG_VISIBILITY) Slog.v(TAG, "Showing " + this |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7435 | + " during animation: policyVis=" + mPolicyVisibility |
| 7436 | + " attHidden=" + mAttachedHidden |
| 7437 | + " tok.hiddenRequested=" |
| 7438 | + (mAppToken != null ? mAppToken.hiddenRequested : false) |
Dianne Hackborn | 248b188 | 2009-09-16 16:46:44 -0700 | [diff] [blame] | 7439 | + " tok.hidden=" |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7440 | + (mAppToken != null ? mAppToken.hidden : false) |
| 7441 | + " animating=" + mAnimating |
| 7442 | + " tok animating=" |
| 7443 | + (mAppToken != null ? mAppToken.animating : false)); |
| 7444 | if (!showSurfaceRobustlyLocked(this)) { |
| 7445 | return false; |
| 7446 | } |
| 7447 | mLastAlpha = -1; |
| 7448 | mHasDrawn = true; |
| 7449 | mLastHidden = false; |
| 7450 | mReadyToShow = false; |
| 7451 | enableScreenIfNeededLocked(); |
| 7452 | |
| 7453 | applyEnterAnimationLocked(this); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7454 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7455 | int i = mChildWindows.size(); |
| 7456 | while (i > 0) { |
| 7457 | i--; |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 7458 | WindowState c = mChildWindows.get(i); |
Dianne Hackborn | f09c1a2 | 2010-04-22 15:59:21 -0700 | [diff] [blame] | 7459 | if (c.mAttachedHidden) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7460 | c.mAttachedHidden = false; |
Dianne Hackborn | f09c1a2 | 2010-04-22 15:59:21 -0700 | [diff] [blame] | 7461 | if (c.mSurface != null) { |
| 7462 | c.performShowLocked(); |
| 7463 | // It hadn't been shown, which means layout not |
| 7464 | // performed on it, so now we want to make sure to |
| 7465 | // do a layout. If called from within the transaction |
| 7466 | // loop, this will cause it to restart with a new |
| 7467 | // layout. |
| 7468 | mLayoutNeeded = true; |
| 7469 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7470 | } |
| 7471 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7472 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7473 | if (mAttrs.type != TYPE_APPLICATION_STARTING |
| 7474 | && mAppToken != null) { |
| 7475 | mAppToken.firstWindowDrawn = true; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7476 | |
Dianne Hackborn | 248b188 | 2009-09-16 16:46:44 -0700 | [diff] [blame] | 7477 | if (mAppToken.startingData != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7478 | if (DEBUG_STARTING_WINDOW || DEBUG_ANIM) Slog.v(TAG, |
Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 7479 | "Finish starting " + mToken |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7480 | + ": first real window is shown, no animation"); |
Dianne Hackborn | 248b188 | 2009-09-16 16:46:44 -0700 | [diff] [blame] | 7481 | // If this initial window is animating, stop it -- we |
| 7482 | // will do an animation to reveal it from behind the |
| 7483 | // starting window, so there is no need for it to also |
| 7484 | // be doing its own stuff. |
| 7485 | if (mAnimation != null) { |
Brad Fitzpatrick | 3fe3851 | 2010-11-03 11:46:54 -0700 | [diff] [blame] | 7486 | mAnimation.cancel(); |
Dianne Hackborn | 248b188 | 2009-09-16 16:46:44 -0700 | [diff] [blame] | 7487 | mAnimation = null; |
| 7488 | // Make sure we clean up the animation. |
| 7489 | mAnimating = true; |
| 7490 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7491 | mFinishedStarting.add(mAppToken); |
| 7492 | mH.sendEmptyMessage(H.FINISHED_STARTING); |
| 7493 | } |
| 7494 | mAppToken.updateReportedVisibilityLocked(); |
| 7495 | } |
| 7496 | } |
| 7497 | return true; |
| 7498 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7499 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7500 | // This must be called while inside a transaction. Returns true if |
| 7501 | // there is more animation to run. |
| 7502 | boolean stepAnimationLocked(long currentTime, int dw, int dh) { |
Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 7503 | if (!mDisplayFrozen && mPolicy.isScreenOn()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7504 | // We will run animations as long as the display isn't frozen. |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7505 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7506 | if (!mDrawPending && !mCommitDrawPending && mAnimation != null) { |
| 7507 | mHasTransformation = true; |
| 7508 | mHasLocalTransformation = true; |
| 7509 | if (!mLocalAnimating) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7510 | if (DEBUG_ANIM) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7511 | TAG, "Starting animation in " + this + |
| 7512 | " @ " + currentTime + ": ww=" + mFrame.width() + " wh=" + mFrame.height() + |
| 7513 | " dw=" + dw + " dh=" + dh + " scale=" + mWindowAnimationScale); |
| 7514 | mAnimation.initialize(mFrame.width(), mFrame.height(), dw, dh); |
| 7515 | mAnimation.setStartTime(currentTime); |
| 7516 | mLocalAnimating = true; |
| 7517 | mAnimating = true; |
| 7518 | } |
| 7519 | mTransformation.clear(); |
| 7520 | final boolean more = mAnimation.getTransformation( |
| 7521 | currentTime, mTransformation); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7522 | if (DEBUG_ANIM) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7523 | TAG, "Stepped animation in " + this + |
| 7524 | ": more=" + more + ", xform=" + mTransformation); |
| 7525 | if (more) { |
| 7526 | // we're not done! |
| 7527 | return true; |
| 7528 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7529 | if (DEBUG_ANIM) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7530 | TAG, "Finished animation in " + this + |
| 7531 | " @ " + currentTime); |
Brad Fitzpatrick | 3fe3851 | 2010-11-03 11:46:54 -0700 | [diff] [blame] | 7532 | |
| 7533 | if (mAnimation != null) { |
| 7534 | mAnimation.cancel(); |
| 7535 | mAnimation = null; |
| 7536 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7537 | //WindowManagerService.this.dump(); |
| 7538 | } |
| 7539 | mHasLocalTransformation = false; |
| 7540 | if ((!mLocalAnimating || mAnimationIsEntrance) && mAppToken != null |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 7541 | && mAppToken.animation != null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7542 | // When our app token is animating, we kind-of pretend like |
| 7543 | // we are as well. Note the mLocalAnimating mAnimationIsEntrance |
| 7544 | // part of this check means that we will only do this if |
| 7545 | // our window is not currently exiting, or it is not |
| 7546 | // locally animating itself. The idea being that one that |
| 7547 | // is exiting and doing a local animation should be removed |
| 7548 | // once that animation is done. |
| 7549 | mAnimating = true; |
| 7550 | mHasTransformation = true; |
| 7551 | mTransformation.clear(); |
| 7552 | return false; |
| 7553 | } else if (mHasTransformation) { |
| 7554 | // Little trick to get through the path below to act like |
| 7555 | // we have finished an animation. |
| 7556 | mAnimating = true; |
| 7557 | } else if (isAnimating()) { |
| 7558 | mAnimating = true; |
| 7559 | } |
| 7560 | } else if (mAnimation != null) { |
| 7561 | // If the display is frozen, and there is a pending animation, |
| 7562 | // clear it and make sure we run the cleanup code. |
| 7563 | mAnimating = true; |
| 7564 | mLocalAnimating = true; |
Brad Fitzpatrick | 3fe3851 | 2010-11-03 11:46:54 -0700 | [diff] [blame] | 7565 | mAnimation.cancel(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7566 | mAnimation = null; |
| 7567 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7568 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7569 | if (!mAnimating && !mLocalAnimating) { |
| 7570 | return false; |
| 7571 | } |
| 7572 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7573 | if (DEBUG_ANIM) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7574 | TAG, "Animation done in " + this + ": exiting=" + mExiting |
| 7575 | + ", reportedVisible=" |
| 7576 | + (mAppToken != null ? mAppToken.reportedVisible : false)); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7577 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7578 | mAnimating = false; |
| 7579 | mLocalAnimating = false; |
Brad Fitzpatrick | 3fe3851 | 2010-11-03 11:46:54 -0700 | [diff] [blame] | 7580 | if (mAnimation != null) { |
| 7581 | mAnimation.cancel(); |
| 7582 | mAnimation = null; |
| 7583 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7584 | mAnimLayer = mLayer; |
| 7585 | if (mIsImWindow) { |
| 7586 | mAnimLayer += mInputMethodAnimLayerAdjustment; |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 7587 | } else if (mIsWallpaper) { |
| 7588 | mAnimLayer += mWallpaperAnimLayerAdjustment; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7589 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7590 | if (DEBUG_LAYERS) Slog.v(TAG, "Stepping win " + this |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7591 | + " anim layer: " + mAnimLayer); |
| 7592 | mHasTransformation = false; |
| 7593 | mHasLocalTransformation = false; |
Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 7594 | if (mPolicyVisibility != mPolicyVisibilityAfterAnim) { |
| 7595 | if (DEBUG_VISIBILITY) { |
| 7596 | Slog.v(TAG, "Policy visibility changing after anim in " + this + ": " |
| 7597 | + mPolicyVisibilityAfterAnim); |
| 7598 | } |
| 7599 | mPolicyVisibility = mPolicyVisibilityAfterAnim; |
| 7600 | if (!mPolicyVisibility) { |
| 7601 | if (mCurrentFocus == this) { |
| 7602 | mFocusMayChange = true; |
| 7603 | } |
| 7604 | // Window is no longer visible -- make sure if we were waiting |
| 7605 | // for it to be displayed before enabling the display, that |
| 7606 | // we allow the display to be enabled now. |
| 7607 | enableScreenIfNeededLocked(); |
| 7608 | } |
Dianne Hackborn | f3bea9c | 2009-12-09 18:26:21 -0800 | [diff] [blame] | 7609 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7610 | mTransformation.clear(); |
| 7611 | if (mHasDrawn |
| 7612 | && mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING |
| 7613 | && mAppToken != null |
| 7614 | && mAppToken.firstWindowDrawn |
| 7615 | && mAppToken.startingData != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7616 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Finish starting " |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7617 | + mToken + ": first real window done animating"); |
| 7618 | mFinishedStarting.add(mAppToken); |
| 7619 | mH.sendEmptyMessage(H.FINISHED_STARTING); |
| 7620 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7621 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7622 | finishExit(); |
| 7623 | |
| 7624 | if (mAppToken != null) { |
| 7625 | mAppToken.updateReportedVisibilityLocked(); |
| 7626 | } |
| 7627 | |
| 7628 | return false; |
| 7629 | } |
| 7630 | |
| 7631 | void finishExit() { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7632 | if (DEBUG_ANIM) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7633 | TAG, "finishExit in " + this |
| 7634 | + ": exiting=" + mExiting |
| 7635 | + " remove=" + mRemoveOnExit |
| 7636 | + " windowAnimating=" + isWindowAnimating()); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7637 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7638 | final int N = mChildWindows.size(); |
| 7639 | for (int i=0; i<N; i++) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 7640 | mChildWindows.get(i).finishExit(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7641 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7642 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7643 | if (!mExiting) { |
| 7644 | return; |
| 7645 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7646 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7647 | if (isWindowAnimating()) { |
| 7648 | return; |
| 7649 | } |
| 7650 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7651 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7652 | TAG, "Exit animation finished in " + this |
| 7653 | + ": remove=" + mRemoveOnExit); |
| 7654 | if (mSurface != null) { |
| 7655 | mDestroySurface.add(this); |
| 7656 | mDestroying = true; |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 7657 | if (SHOW_TRANSACTIONS) logSurface(this, "HIDE (finishExit)", null); |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 7658 | mSurfaceShown = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7659 | try { |
| 7660 | mSurface.hide(); |
| 7661 | } catch (RuntimeException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7662 | Slog.w(TAG, "Error hiding surface in " + this, e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7663 | } |
| 7664 | mLastHidden = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7665 | } |
| 7666 | mExiting = false; |
| 7667 | if (mRemoveOnExit) { |
| 7668 | mPendingRemove.add(this); |
| 7669 | mRemoveOnExit = false; |
| 7670 | } |
| 7671 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7672 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7673 | boolean isIdentityMatrix(float dsdx, float dtdx, float dsdy, float dtdy) { |
| 7674 | if (dsdx < .99999f || dsdx > 1.00001f) return false; |
| 7675 | if (dtdy < .99999f || dtdy > 1.00001f) return false; |
| 7676 | if (dtdx < -.000001f || dtdx > .000001f) return false; |
| 7677 | if (dsdy < -.000001f || dsdy > .000001f) return false; |
| 7678 | return true; |
| 7679 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7680 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7681 | void computeShownFrameLocked() { |
| 7682 | final boolean selfTransformation = mHasLocalTransformation; |
| 7683 | Transformation attachedTransformation = |
| 7684 | (mAttachedWindow != null && mAttachedWindow.mHasLocalTransformation) |
| 7685 | ? mAttachedWindow.mTransformation : null; |
| 7686 | Transformation appTransformation = |
| 7687 | (mAppToken != null && mAppToken.hasTransformation) |
| 7688 | ? mAppToken.transformation : null; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7689 | |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 7690 | // Wallpapers are animated based on the "real" window they |
| 7691 | // are currently targeting. |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 7692 | if (mAttrs.type == TYPE_WALLPAPER && mLowerWallpaperTarget == null |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 7693 | && mWallpaperTarget != null) { |
Dianne Hackborn | 5baba16 | 2009-09-23 17:01:12 -0700 | [diff] [blame] | 7694 | if (mWallpaperTarget.mHasLocalTransformation && |
| 7695 | mWallpaperTarget.mAnimation != null && |
| 7696 | !mWallpaperTarget.mAnimation.getDetachWallpaper()) { |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 7697 | attachedTransformation = mWallpaperTarget.mTransformation; |
Dianne Hackborn | 5baba16 | 2009-09-23 17:01:12 -0700 | [diff] [blame] | 7698 | if (DEBUG_WALLPAPER && attachedTransformation != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7699 | Slog.v(TAG, "WP target attached xform: " + attachedTransformation); |
Dianne Hackborn | 5baba16 | 2009-09-23 17:01:12 -0700 | [diff] [blame] | 7700 | } |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 7701 | } |
| 7702 | if (mWallpaperTarget.mAppToken != null && |
Dianne Hackborn | 5baba16 | 2009-09-23 17:01:12 -0700 | [diff] [blame] | 7703 | mWallpaperTarget.mAppToken.hasTransformation && |
| 7704 | mWallpaperTarget.mAppToken.animation != null && |
| 7705 | !mWallpaperTarget.mAppToken.animation.getDetachWallpaper()) { |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 7706 | appTransformation = mWallpaperTarget.mAppToken.transformation; |
Dianne Hackborn | 5baba16 | 2009-09-23 17:01:12 -0700 | [diff] [blame] | 7707 | if (DEBUG_WALLPAPER && appTransformation != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7708 | Slog.v(TAG, "WP target app xform: " + appTransformation); |
Dianne Hackborn | 5baba16 | 2009-09-23 17:01:12 -0700 | [diff] [blame] | 7709 | } |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 7710 | } |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 7711 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7712 | |
Dianne Hackborn | f9d0be9 | 2010-11-24 12:35:25 -0800 | [diff] [blame] | 7713 | final boolean screenAnimation = mScreenRotationAnimation != null |
| 7714 | && mScreenRotationAnimation.isAnimating(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7715 | if (selfTransformation || attachedTransformation != null |
Dianne Hackborn | f9d0be9 | 2010-11-24 12:35:25 -0800 | [diff] [blame] | 7716 | || appTransformation != null || screenAnimation) { |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7717 | // cache often used attributes locally |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7718 | final Rect frame = mFrame; |
| 7719 | final float tmpFloats[] = mTmpFloats; |
| 7720 | final Matrix tmpMatrix = mTmpMatrix; |
| 7721 | |
| 7722 | // Compute the desired transformation. |
Dianne Hackborn | 65c2387 | 2009-09-18 17:47:02 -0700 | [diff] [blame] | 7723 | tmpMatrix.setTranslate(0, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7724 | if (selfTransformation) { |
Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 7725 | tmpMatrix.postConcat(mTransformation.getMatrix()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7726 | } |
Dianne Hackborn | 65c2387 | 2009-09-18 17:47:02 -0700 | [diff] [blame] | 7727 | tmpMatrix.postTranslate(frame.left, frame.top); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7728 | if (attachedTransformation != null) { |
Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 7729 | tmpMatrix.postConcat(attachedTransformation.getMatrix()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7730 | } |
| 7731 | if (appTransformation != null) { |
Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 7732 | tmpMatrix.postConcat(appTransformation.getMatrix()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7733 | } |
Dianne Hackborn | f9d0be9 | 2010-11-24 12:35:25 -0800 | [diff] [blame] | 7734 | if (screenAnimation) { |
| 7735 | tmpMatrix.postConcat( |
| 7736 | mScreenRotationAnimation.getEnterTransformation().getMatrix()); |
| 7737 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7738 | |
| 7739 | // "convert" it into SurfaceFlinger's format |
| 7740 | // (a 2x2 matrix + an offset) |
| 7741 | // Here we must not transform the position of the surface |
| 7742 | // since it is already included in the transformation. |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7743 | //Slog.i(TAG, "Transform: " + matrix); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7744 | |
Dianne Hackborn | 7da6ac3 | 2010-12-09 19:22:04 -0800 | [diff] [blame] | 7745 | mHaveMatrix = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7746 | tmpMatrix.getValues(tmpFloats); |
| 7747 | mDsDx = tmpFloats[Matrix.MSCALE_X]; |
Dianne Hackborn | f9d0be9 | 2010-11-24 12:35:25 -0800 | [diff] [blame] | 7748 | mDtDx = tmpFloats[Matrix.MSKEW_Y]; |
| 7749 | mDsDy = tmpFloats[Matrix.MSKEW_X]; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7750 | mDtDy = tmpFloats[Matrix.MSCALE_Y]; |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 7751 | int x = (int)tmpFloats[Matrix.MTRANS_X] + mXOffset; |
| 7752 | int y = (int)tmpFloats[Matrix.MTRANS_Y] + mYOffset; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7753 | int w = frame.width(); |
| 7754 | int h = frame.height(); |
| 7755 | mShownFrame.set(x, y, x+w, y+h); |
| 7756 | |
| 7757 | // Now set the alpha... but because our current hardware |
| 7758 | // can't do alpha transformation on a non-opaque surface, |
| 7759 | // turn it off if we are running an animation that is also |
| 7760 | // transforming since it is more important to have that |
| 7761 | // animation be smooth. |
| 7762 | mShownAlpha = mAlpha; |
| 7763 | if (!mLimitedAlphaCompositing |
| 7764 | || (!PixelFormat.formatHasAlpha(mAttrs.format) |
| 7765 | || (isIdentityMatrix(mDsDx, mDtDx, mDsDy, mDtDy) |
| 7766 | && x == frame.left && y == frame.top))) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7767 | //Slog.i(TAG, "Applying alpha transform"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7768 | if (selfTransformation) { |
| 7769 | mShownAlpha *= mTransformation.getAlpha(); |
| 7770 | } |
| 7771 | if (attachedTransformation != null) { |
| 7772 | mShownAlpha *= attachedTransformation.getAlpha(); |
| 7773 | } |
| 7774 | if (appTransformation != null) { |
| 7775 | mShownAlpha *= appTransformation.getAlpha(); |
| 7776 | } |
Dianne Hackborn | f9d0be9 | 2010-11-24 12:35:25 -0800 | [diff] [blame] | 7777 | if (screenAnimation) { |
| 7778 | mShownAlpha *= |
| 7779 | mScreenRotationAnimation.getEnterTransformation().getAlpha(); |
| 7780 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7781 | } else { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7782 | //Slog.i(TAG, "Not applying alpha transform"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7783 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7784 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7785 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7786 | TAG, "Continuing animation in " + this + |
| 7787 | ": " + mShownFrame + |
| 7788 | ", alpha=" + mTransformation.getAlpha()); |
| 7789 | return; |
| 7790 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7791 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7792 | mShownFrame.set(mFrame); |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 7793 | if (mXOffset != 0 || mYOffset != 0) { |
| 7794 | mShownFrame.offset(mXOffset, mYOffset); |
| 7795 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7796 | mShownAlpha = mAlpha; |
Dianne Hackborn | 7da6ac3 | 2010-12-09 19:22:04 -0800 | [diff] [blame] | 7797 | mHaveMatrix = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7798 | mDsDx = 1; |
| 7799 | mDtDx = 0; |
| 7800 | mDsDy = 0; |
| 7801 | mDtDy = 1; |
| 7802 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7803 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7804 | /** |
| 7805 | * Is this window visible? It is not visible if there is no |
| 7806 | * surface, or we are in the process of running an exit animation |
| 7807 | * that will remove the surface, or its app token has been hidden. |
| 7808 | */ |
| 7809 | public boolean isVisibleLw() { |
| 7810 | final AppWindowToken atoken = mAppToken; |
| 7811 | return mSurface != null && mPolicyVisibility && !mAttachedHidden |
| 7812 | && (atoken == null || !atoken.hiddenRequested) |
| 7813 | && !mExiting && !mDestroying; |
| 7814 | } |
| 7815 | |
| 7816 | /** |
Dianne Hackborn | 3d163f07 | 2009-10-07 21:26:57 -0700 | [diff] [blame] | 7817 | * Like {@link #isVisibleLw}, but also counts a window that is currently |
| 7818 | * "hidden" behind the keyguard as visible. This allows us to apply |
| 7819 | * things like window flags that impact the keyguard. |
| 7820 | * XXX I am starting to think we need to have ANOTHER visibility flag |
| 7821 | * for this "hidden behind keyguard" state rather than overloading |
| 7822 | * mPolicyVisibility. Ungh. |
| 7823 | */ |
| 7824 | public boolean isVisibleOrBehindKeyguardLw() { |
| 7825 | final AppWindowToken atoken = mAppToken; |
| 7826 | return mSurface != null && !mAttachedHidden |
| 7827 | && (atoken == null ? mPolicyVisibility : !atoken.hiddenRequested) |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 7828 | && !mDrawPending && !mCommitDrawPending |
Dianne Hackborn | 3d163f07 | 2009-10-07 21:26:57 -0700 | [diff] [blame] | 7829 | && !mExiting && !mDestroying; |
| 7830 | } |
| 7831 | |
| 7832 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7833 | * Is this window visible, ignoring its app token? It is not visible |
| 7834 | * if there is no surface, or we are in the process of running an exit animation |
| 7835 | * that will remove the surface. |
| 7836 | */ |
| 7837 | public boolean isWinVisibleLw() { |
| 7838 | final AppWindowToken atoken = mAppToken; |
| 7839 | return mSurface != null && mPolicyVisibility && !mAttachedHidden |
| 7840 | && (atoken == null || !atoken.hiddenRequested || atoken.animating) |
| 7841 | && !mExiting && !mDestroying; |
| 7842 | } |
| 7843 | |
| 7844 | /** |
| 7845 | * The same as isVisible(), but follows the current hidden state of |
| 7846 | * the associated app token, not the pending requested hidden state. |
| 7847 | */ |
| 7848 | boolean isVisibleNow() { |
| 7849 | return mSurface != null && mPolicyVisibility && !mAttachedHidden |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 7850 | && !mRootToken.hidden && !mExiting && !mDestroying; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7851 | } |
| 7852 | |
| 7853 | /** |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 7854 | * Can this window possibly be a drag/drop target? The test here is |
| 7855 | * a combination of the above "visible now" with the check that the |
| 7856 | * Input Manager uses when discarding windows from input consideration. |
| 7857 | */ |
| 7858 | boolean isPotentialDragTarget() { |
| 7859 | return isVisibleNow() && (mInputChannel != null) && !mRemoved; |
| 7860 | } |
| 7861 | |
| 7862 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7863 | * Same as isVisible(), but we also count it as visible between the |
| 7864 | * call to IWindowSession.add() and the first relayout(). |
| 7865 | */ |
| 7866 | boolean isVisibleOrAdding() { |
| 7867 | final AppWindowToken atoken = mAppToken; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 7868 | return ((mSurface != null && !mReportDestroySurface) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7869 | || (!mRelayoutCalled && mViewVisibility == View.VISIBLE)) |
| 7870 | && mPolicyVisibility && !mAttachedHidden |
| 7871 | && (atoken == null || !atoken.hiddenRequested) |
| 7872 | && !mExiting && !mDestroying; |
| 7873 | } |
| 7874 | |
| 7875 | /** |
| 7876 | * Is this window currently on-screen? It is on-screen either if it |
| 7877 | * is visible or it is currently running an animation before no longer |
| 7878 | * being visible. |
| 7879 | */ |
| 7880 | boolean isOnScreen() { |
| 7881 | final AppWindowToken atoken = mAppToken; |
| 7882 | if (atoken != null) { |
| 7883 | return mSurface != null && mPolicyVisibility && !mDestroying |
| 7884 | && ((!mAttachedHidden && !atoken.hiddenRequested) |
Dianne Hackborn | 0cd4887 | 2009-08-13 18:51:59 -0700 | [diff] [blame] | 7885 | || mAnimation != null || atoken.animation != null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7886 | } else { |
| 7887 | return mSurface != null && mPolicyVisibility && !mDestroying |
Dianne Hackborn | 0cd4887 | 2009-08-13 18:51:59 -0700 | [diff] [blame] | 7888 | && (!mAttachedHidden || mAnimation != null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7889 | } |
| 7890 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7891 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7892 | /** |
| 7893 | * Like isOnScreen(), but we don't return true if the window is part |
| 7894 | * of a transition that has not yet been started. |
| 7895 | */ |
| 7896 | boolean isReadyForDisplay() { |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 7897 | if (mRootToken.waitingToShow && |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 7898 | mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 7899 | return false; |
| 7900 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7901 | final AppWindowToken atoken = mAppToken; |
Dianne Hackborn | 0cd4887 | 2009-08-13 18:51:59 -0700 | [diff] [blame] | 7902 | final boolean animating = atoken != null |
| 7903 | ? (atoken.animation != null) : false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7904 | return mSurface != null && mPolicyVisibility && !mDestroying |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 7905 | && ((!mAttachedHidden && mViewVisibility == View.VISIBLE |
| 7906 | && !mRootToken.hidden) |
Dianne Hackborn | 0cd4887 | 2009-08-13 18:51:59 -0700 | [diff] [blame] | 7907 | || mAnimation != null || animating); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7908 | } |
| 7909 | |
| 7910 | /** Is the window or its container currently animating? */ |
| 7911 | boolean isAnimating() { |
| 7912 | final WindowState attached = mAttachedWindow; |
| 7913 | final AppWindowToken atoken = mAppToken; |
| 7914 | return mAnimation != null |
| 7915 | || (attached != null && attached.mAnimation != null) |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7916 | || (atoken != null && |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7917 | (atoken.animation != null |
| 7918 | || atoken.inPendingTransaction)); |
| 7919 | } |
| 7920 | |
| 7921 | /** Is this window currently animating? */ |
| 7922 | boolean isWindowAnimating() { |
| 7923 | return mAnimation != null; |
| 7924 | } |
| 7925 | |
| 7926 | /** |
| 7927 | * Like isOnScreen, but returns false if the surface hasn't yet |
| 7928 | * been drawn. |
| 7929 | */ |
| 7930 | public boolean isDisplayedLw() { |
| 7931 | final AppWindowToken atoken = mAppToken; |
| 7932 | return mSurface != null && mPolicyVisibility && !mDestroying |
| 7933 | && !mDrawPending && !mCommitDrawPending |
| 7934 | && ((!mAttachedHidden && |
| 7935 | (atoken == null || !atoken.hiddenRequested)) |
| 7936 | || mAnimating); |
| 7937 | } |
| 7938 | |
Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 7939 | /** |
| 7940 | * Returns true if the window has a surface that it has drawn a |
| 7941 | * complete UI in to. |
| 7942 | */ |
| 7943 | public boolean isDrawnLw() { |
| 7944 | final AppWindowToken atoken = mAppToken; |
| 7945 | return mSurface != null && !mDestroying |
| 7946 | && !mDrawPending && !mCommitDrawPending; |
| 7947 | } |
| 7948 | |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 7949 | /** |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 7950 | * Return true if the window is opaque and fully drawn. This indicates |
| 7951 | * it may obscure windows behind it. |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 7952 | */ |
| 7953 | boolean isOpaqueDrawn() { |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 7954 | return (mAttrs.format == PixelFormat.OPAQUE |
| 7955 | || mAttrs.type == TYPE_WALLPAPER) |
| 7956 | && mSurface != null && mAnimation == null |
| 7957 | && (mAppToken == null || mAppToken.animation == null) |
| 7958 | && !mDrawPending && !mCommitDrawPending; |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 7959 | } |
| 7960 | |
Dianne Hackborn | 1c24e95 | 2010-11-23 00:34:30 -0800 | [diff] [blame] | 7961 | /** |
| 7962 | * Return whether this window is wanting to have a translation |
| 7963 | * animation applied to it for an in-progress move. (Only makes |
| 7964 | * sense to call from performLayoutAndPlaceSurfacesLockedInner().) |
| 7965 | */ |
| 7966 | boolean shouldAnimateMove() { |
Dianne Hackborn | 0f761d6 | 2010-11-30 22:06:10 -0800 | [diff] [blame] | 7967 | return mContentChanged && !mExiting && !mLastHidden && !mDisplayFrozen |
Dianne Hackborn | 1c24e95 | 2010-11-23 00:34:30 -0800 | [diff] [blame] | 7968 | && (mFrame.top != mLastFrame.top |
| 7969 | || mFrame.left != mLastFrame.left) |
Dianne Hackborn | 0f761d6 | 2010-11-30 22:06:10 -0800 | [diff] [blame] | 7970 | && (mAttachedWindow == null || !mAttachedWindow.shouldAnimateMove()) |
Dianne Hackborn | 1c24e95 | 2010-11-23 00:34:30 -0800 | [diff] [blame] | 7971 | && mPolicy.isScreenOn(); |
| 7972 | } |
| 7973 | |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 7974 | boolean needsBackgroundFiller(int screenWidth, int screenHeight) { |
| 7975 | return |
| 7976 | // only if the application is requesting compatible window |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 7977 | (mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0 && |
| 7978 | // only if it's visible |
| 7979 | mHasDrawn && mViewVisibility == View.VISIBLE && |
Mitsuru Oshima | d2967e2 | 2009-07-20 14:01:43 -0700 | [diff] [blame] | 7980 | // and only if the application fills the compatible screen |
| 7981 | mFrame.left <= mCompatibleScreenFrame.left && |
| 7982 | mFrame.top <= mCompatibleScreenFrame.top && |
| 7983 | mFrame.right >= mCompatibleScreenFrame.right && |
| 7984 | mFrame.bottom >= mCompatibleScreenFrame.bottom && |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 7985 | // and starting window do not need background filler |
Mitsuru Oshima | d2967e2 | 2009-07-20 14:01:43 -0700 | [diff] [blame] | 7986 | mAttrs.type != mAttrs.TYPE_APPLICATION_STARTING; |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 7987 | } |
| 7988 | |
| 7989 | boolean isFullscreen(int screenWidth, int screenHeight) { |
| 7990 | return mFrame.left <= 0 && mFrame.top <= 0 && |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 7991 | mFrame.right >= screenWidth && mFrame.bottom >= screenHeight; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7992 | } |
| 7993 | |
| 7994 | void removeLocked() { |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 7995 | disposeInputChannel(); |
| 7996 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7997 | if (mAttachedWindow != null) { |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 7998 | if (DEBUG_ADD_REMOVE) Slog.v(TAG, "Removing " + this + " from " + mAttachedWindow); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7999 | mAttachedWindow.mChildWindows.remove(this); |
| 8000 | } |
| 8001 | destroySurfaceLocked(); |
| 8002 | mSession.windowRemovedLocked(); |
| 8003 | try { |
| 8004 | mClient.asBinder().unlinkToDeath(mDeathRecipient, 0); |
| 8005 | } catch (RuntimeException e) { |
| 8006 | // Ignore if it has already been removed (usually because |
| 8007 | // we are doing this as part of processing a death note.) |
| 8008 | } |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 8009 | } |
| 8010 | |
| 8011 | void disposeInputChannel() { |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 8012 | if (mInputChannel != null) { |
| 8013 | mInputManager.unregisterInputChannel(mInputChannel); |
| 8014 | |
| 8015 | mInputChannel.dispose(); |
| 8016 | mInputChannel = null; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 8017 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8018 | } |
| 8019 | |
| 8020 | private class DeathRecipient implements IBinder.DeathRecipient { |
| 8021 | public void binderDied() { |
| 8022 | try { |
| 8023 | synchronized(mWindowMap) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 8024 | WindowState win = windowForClientLocked(mSession, mClient, false); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8025 | Slog.i(TAG, "WIN DEATH: " + win); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8026 | if (win != null) { |
| 8027 | removeWindowLocked(mSession, win); |
| 8028 | } |
| 8029 | } |
| 8030 | } catch (IllegalArgumentException ex) { |
| 8031 | // This will happen if the window has already been |
| 8032 | // removed. |
| 8033 | } |
| 8034 | } |
| 8035 | } |
| 8036 | |
| 8037 | /** Returns true if this window desires key events. */ |
| 8038 | public final boolean canReceiveKeys() { |
| 8039 | return isVisibleOrAdding() |
| 8040 | && (mViewVisibility == View.VISIBLE) |
| 8041 | && ((mAttrs.flags & WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) == 0); |
| 8042 | } |
| 8043 | |
| 8044 | public boolean hasDrawnLw() { |
| 8045 | return mHasDrawn; |
| 8046 | } |
| 8047 | |
| 8048 | public boolean showLw(boolean doAnimation) { |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8049 | return showLw(doAnimation, true); |
| 8050 | } |
| 8051 | |
| 8052 | boolean showLw(boolean doAnimation, boolean requestAnim) { |
| 8053 | if (mPolicyVisibility && mPolicyVisibilityAfterAnim) { |
| 8054 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8055 | } |
Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 8056 | if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility true: " + this); |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 8057 | if (doAnimation) { |
| 8058 | if (DEBUG_VISIBILITY) Slog.v(TAG, "doAnimation: mPolicyVisibility=" |
| 8059 | + mPolicyVisibility + " mAnimation=" + mAnimation); |
| 8060 | if (mDisplayFrozen || !mPolicy.isScreenOn()) { |
| 8061 | doAnimation = false; |
| 8062 | } else if (mPolicyVisibility && mAnimation == null) { |
| 8063 | // Check for the case where we are currently visible and |
| 8064 | // not animating; we do not want to do animation at such a |
| 8065 | // point to become visible when we already are. |
| 8066 | doAnimation = false; |
| 8067 | } |
| 8068 | } |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8069 | mPolicyVisibility = true; |
| 8070 | mPolicyVisibilityAfterAnim = true; |
| 8071 | if (doAnimation) { |
| 8072 | applyAnimationLocked(this, WindowManagerPolicy.TRANSIT_ENTER, true); |
| 8073 | } |
| 8074 | if (requestAnim) { |
| 8075 | requestAnimationLocked(0); |
| 8076 | } |
| 8077 | return true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8078 | } |
| 8079 | |
| 8080 | public boolean hideLw(boolean doAnimation) { |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8081 | return hideLw(doAnimation, true); |
| 8082 | } |
| 8083 | |
| 8084 | boolean hideLw(boolean doAnimation, boolean requestAnim) { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 8085 | if (doAnimation) { |
| 8086 | if (mDisplayFrozen || !mPolicy.isScreenOn()) { |
| 8087 | doAnimation = false; |
| 8088 | } |
| 8089 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8090 | boolean current = doAnimation ? mPolicyVisibilityAfterAnim |
| 8091 | : mPolicyVisibility; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8092 | if (!current) { |
| 8093 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8094 | } |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8095 | if (doAnimation) { |
| 8096 | applyAnimationLocked(this, WindowManagerPolicy.TRANSIT_EXIT, false); |
| 8097 | if (mAnimation == null) { |
| 8098 | doAnimation = false; |
| 8099 | } |
| 8100 | } |
| 8101 | if (doAnimation) { |
| 8102 | mPolicyVisibilityAfterAnim = false; |
| 8103 | } else { |
Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 8104 | if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility false: " + this); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8105 | mPolicyVisibilityAfterAnim = false; |
| 8106 | mPolicyVisibility = false; |
Dianne Hackborn | f3bea9c | 2009-12-09 18:26:21 -0800 | [diff] [blame] | 8107 | // Window is no longer visible -- make sure if we were waiting |
| 8108 | // for it to be displayed before enabling the display, that |
| 8109 | // we allow the display to be enabled now. |
| 8110 | enableScreenIfNeededLocked(); |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 8111 | if (mCurrentFocus == this) { |
| 8112 | mFocusMayChange = true; |
| 8113 | } |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8114 | } |
| 8115 | if (requestAnim) { |
| 8116 | requestAnimationLocked(0); |
| 8117 | } |
| 8118 | return true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8119 | } |
| 8120 | |
Jeff Brown | fbf0977 | 2011-01-16 14:06:57 -0800 | [diff] [blame] | 8121 | public void getTouchableRegion(Region outRegion) { |
| 8122 | final Rect frame = mFrame; |
| 8123 | switch (mTouchableInsets) { |
| 8124 | default: |
| 8125 | case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME: |
| 8126 | outRegion.set(frame); |
| 8127 | break; |
| 8128 | case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_CONTENT: { |
| 8129 | final Rect inset = mGivenContentInsets; |
| 8130 | outRegion.set( |
| 8131 | frame.left + inset.left, frame.top + inset.top, |
| 8132 | frame.right - inset.right, frame.bottom - inset.bottom); |
| 8133 | break; |
| 8134 | } |
| 8135 | case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_VISIBLE: { |
| 8136 | final Rect inset = mGivenVisibleInsets; |
| 8137 | outRegion.set( |
| 8138 | frame.left + inset.left, frame.top + inset.top, |
| 8139 | frame.right - inset.right, frame.bottom - inset.bottom); |
| 8140 | break; |
| 8141 | } |
| 8142 | case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_REGION: { |
| 8143 | final Region givenTouchableRegion = mGivenTouchableRegion; |
| 8144 | outRegion.set(givenTouchableRegion); |
| 8145 | outRegion.translate(frame.left, frame.top); |
| 8146 | break; |
| 8147 | } |
| 8148 | } |
| 8149 | } |
| 8150 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8151 | void dump(PrintWriter pw, String prefix) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8152 | pw.print(prefix); pw.print("mSession="); pw.print(mSession); |
| 8153 | pw.print(" mClient="); pw.println(mClient.asBinder()); |
| 8154 | pw.print(prefix); pw.print("mAttrs="); pw.println(mAttrs); |
| 8155 | if (mAttachedWindow != null || mLayoutAttached) { |
| 8156 | pw.print(prefix); pw.print("mAttachedWindow="); pw.print(mAttachedWindow); |
| 8157 | pw.print(" mLayoutAttached="); pw.println(mLayoutAttached); |
| 8158 | } |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 8159 | if (mIsImWindow || mIsWallpaper || mIsFloatingLayer) { |
| 8160 | pw.print(prefix); pw.print("mIsImWindow="); pw.print(mIsImWindow); |
| 8161 | pw.print(" mIsWallpaper="); pw.print(mIsWallpaper); |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 8162 | pw.print(" mIsFloatingLayer="); pw.print(mIsFloatingLayer); |
| 8163 | pw.print(" mWallpaperVisible="); pw.println(mWallpaperVisible); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8164 | } |
| 8165 | pw.print(prefix); pw.print("mBaseLayer="); pw.print(mBaseLayer); |
| 8166 | pw.print(" mSubLayer="); pw.print(mSubLayer); |
| 8167 | pw.print(" mAnimLayer="); pw.print(mLayer); pw.print("+"); |
| 8168 | pw.print((mTargetAppToken != null ? mTargetAppToken.animLayerAdjustment |
| 8169 | : (mAppToken != null ? mAppToken.animLayerAdjustment : 0))); |
| 8170 | pw.print("="); pw.print(mAnimLayer); |
| 8171 | pw.print(" mLastLayer="); pw.println(mLastLayer); |
| 8172 | if (mSurface != null) { |
| 8173 | pw.print(prefix); pw.print("mSurface="); pw.println(mSurface); |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 8174 | pw.print(prefix); pw.print("Surface: shown="); pw.print(mSurfaceShown); |
| 8175 | pw.print(" layer="); pw.print(mSurfaceLayer); |
| 8176 | pw.print(" alpha="); pw.print(mSurfaceAlpha); |
| 8177 | pw.print(" rect=("); pw.print(mSurfaceX); |
| 8178 | pw.print(","); pw.print(mSurfaceY); |
| 8179 | pw.print(") "); pw.print(mSurfaceW); |
| 8180 | pw.print(" x "); pw.println(mSurfaceH); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8181 | } |
| 8182 | pw.print(prefix); pw.print("mToken="); pw.println(mToken); |
| 8183 | pw.print(prefix); pw.print("mRootToken="); pw.println(mRootToken); |
| 8184 | if (mAppToken != null) { |
| 8185 | pw.print(prefix); pw.print("mAppToken="); pw.println(mAppToken); |
| 8186 | } |
| 8187 | if (mTargetAppToken != null) { |
| 8188 | pw.print(prefix); pw.print("mTargetAppToken="); pw.println(mTargetAppToken); |
| 8189 | } |
| 8190 | pw.print(prefix); pw.print("mViewVisibility=0x"); |
| 8191 | pw.print(Integer.toHexString(mViewVisibility)); |
| 8192 | pw.print(" mLastHidden="); pw.print(mLastHidden); |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 8193 | pw.print(" mHaveFrame="); pw.print(mHaveFrame); |
| 8194 | pw.print(" mObscured="); pw.println(mObscured); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8195 | if (!mPolicyVisibility || !mPolicyVisibilityAfterAnim || mAttachedHidden) { |
| 8196 | pw.print(prefix); pw.print("mPolicyVisibility="); |
| 8197 | pw.print(mPolicyVisibility); |
| 8198 | pw.print(" mPolicyVisibilityAfterAnim="); |
| 8199 | pw.print(mPolicyVisibilityAfterAnim); |
| 8200 | pw.print(" mAttachedHidden="); pw.println(mAttachedHidden); |
| 8201 | } |
Dianne Hackborn | 9b52a21 | 2009-12-11 14:51:35 -0800 | [diff] [blame] | 8202 | if (!mRelayoutCalled) { |
| 8203 | pw.print(prefix); pw.print("mRelayoutCalled="); pw.println(mRelayoutCalled); |
| 8204 | } |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8205 | pw.print(prefix); pw.print("Requested w="); pw.print(mRequestedWidth); |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 8206 | pw.print(" h="); pw.print(mRequestedHeight); |
| 8207 | pw.print(" mLayoutSeq="); pw.println(mLayoutSeq); |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 8208 | if (mXOffset != 0 || mYOffset != 0) { |
| 8209 | pw.print(prefix); pw.print("Offsets x="); pw.print(mXOffset); |
| 8210 | pw.print(" y="); pw.println(mYOffset); |
| 8211 | } |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8212 | pw.print(prefix); pw.print("mGivenContentInsets="); |
| 8213 | mGivenContentInsets.printShortString(pw); |
| 8214 | pw.print(" mGivenVisibleInsets="); |
| 8215 | mGivenVisibleInsets.printShortString(pw); |
| 8216 | pw.println(); |
| 8217 | if (mTouchableInsets != 0 || mGivenInsetsPending) { |
| 8218 | pw.print(prefix); pw.print("mTouchableInsets="); pw.print(mTouchableInsets); |
| 8219 | pw.print(" mGivenInsetsPending="); pw.println(mGivenInsetsPending); |
| 8220 | } |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 8221 | pw.print(prefix); pw.print("mConfiguration="); pw.println(mConfiguration); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8222 | pw.print(prefix); pw.print("mShownFrame="); |
| 8223 | mShownFrame.printShortString(pw); |
| 8224 | pw.print(" last="); mLastShownFrame.printShortString(pw); |
| 8225 | pw.println(); |
| 8226 | pw.print(prefix); pw.print("mFrame="); mFrame.printShortString(pw); |
| 8227 | pw.print(" last="); mLastFrame.printShortString(pw); |
| 8228 | pw.println(); |
| 8229 | pw.print(prefix); pw.print("mContainingFrame="); |
| 8230 | mContainingFrame.printShortString(pw); |
Dianne Hackborn | 1c24e95 | 2010-11-23 00:34:30 -0800 | [diff] [blame] | 8231 | pw.print(" mParentFrame="); |
| 8232 | mParentFrame.printShortString(pw); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8233 | pw.print(" mDisplayFrame="); |
| 8234 | mDisplayFrame.printShortString(pw); |
| 8235 | pw.println(); |
| 8236 | pw.print(prefix); pw.print("mContentFrame="); mContentFrame.printShortString(pw); |
| 8237 | pw.print(" mVisibleFrame="); mVisibleFrame.printShortString(pw); |
| 8238 | pw.println(); |
| 8239 | pw.print(prefix); pw.print("mContentInsets="); mContentInsets.printShortString(pw); |
| 8240 | pw.print(" last="); mLastContentInsets.printShortString(pw); |
| 8241 | pw.print(" mVisibleInsets="); mVisibleInsets.printShortString(pw); |
| 8242 | pw.print(" last="); mLastVisibleInsets.printShortString(pw); |
| 8243 | pw.println(); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8244 | if (mAnimating || mLocalAnimating || mAnimationIsEntrance |
| 8245 | || mAnimation != null) { |
| 8246 | pw.print(prefix); pw.print("mAnimating="); pw.print(mAnimating); |
| 8247 | pw.print(" mLocalAnimating="); pw.print(mLocalAnimating); |
| 8248 | pw.print(" mAnimationIsEntrance="); pw.print(mAnimationIsEntrance); |
| 8249 | pw.print(" mAnimation="); pw.println(mAnimation); |
| 8250 | } |
| 8251 | if (mHasTransformation || mHasLocalTransformation) { |
| 8252 | pw.print(prefix); pw.print("XForm: has="); |
| 8253 | pw.print(mHasTransformation); |
| 8254 | pw.print(" hasLocal="); pw.print(mHasLocalTransformation); |
| 8255 | pw.print(" "); mTransformation.printShortString(pw); |
| 8256 | pw.println(); |
| 8257 | } |
Dianne Hackborn | 7da6ac3 | 2010-12-09 19:22:04 -0800 | [diff] [blame] | 8258 | if (mShownAlpha != 1 || mAlpha != 1 || mLastAlpha != 1) { |
| 8259 | pw.print(prefix); pw.print("mShownAlpha="); pw.print(mShownAlpha); |
| 8260 | pw.print(" mAlpha="); pw.print(mAlpha); |
| 8261 | pw.print(" mLastAlpha="); pw.println(mLastAlpha); |
| 8262 | } |
| 8263 | if (mHaveMatrix) { |
| 8264 | pw.print(prefix); pw.print("mDsDx="); pw.print(mDsDx); |
| 8265 | pw.print(" mDtDx="); pw.print(mDtDx); |
| 8266 | pw.print(" mDsDy="); pw.print(mDsDy); |
| 8267 | pw.print(" mDtDy="); pw.println(mDtDy); |
| 8268 | } |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8269 | pw.print(prefix); pw.print("mDrawPending="); pw.print(mDrawPending); |
| 8270 | pw.print(" mCommitDrawPending="); pw.print(mCommitDrawPending); |
| 8271 | pw.print(" mReadyToShow="); pw.print(mReadyToShow); |
| 8272 | pw.print(" mHasDrawn="); pw.println(mHasDrawn); |
| 8273 | if (mExiting || mRemoveOnExit || mDestroying || mRemoved) { |
| 8274 | pw.print(prefix); pw.print("mExiting="); pw.print(mExiting); |
| 8275 | pw.print(" mRemoveOnExit="); pw.print(mRemoveOnExit); |
| 8276 | pw.print(" mDestroying="); pw.print(mDestroying); |
| 8277 | pw.print(" mRemoved="); pw.println(mRemoved); |
| 8278 | } |
Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 8279 | if (mOrientationChanging || mAppFreezing || mTurnOnScreen) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8280 | pw.print(prefix); pw.print("mOrientationChanging="); |
| 8281 | pw.print(mOrientationChanging); |
Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 8282 | pw.print(" mAppFreezing="); pw.print(mAppFreezing); |
| 8283 | pw.print(" mTurnOnScreen="); pw.println(mTurnOnScreen); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8284 | } |
Mitsuru Oshima | 589cebe | 2009-07-22 20:38:58 -0700 | [diff] [blame] | 8285 | if (mHScale != 1 || mVScale != 1) { |
| 8286 | pw.print(prefix); pw.print("mHScale="); pw.print(mHScale); |
| 8287 | pw.print(" mVScale="); pw.println(mVScale); |
| 8288 | } |
Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 8289 | if (mWallpaperX != -1 || mWallpaperY != -1) { |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 8290 | pw.print(prefix); pw.print("mWallpaperX="); pw.print(mWallpaperX); |
| 8291 | pw.print(" mWallpaperY="); pw.println(mWallpaperY); |
| 8292 | } |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 8293 | if (mWallpaperXStep != -1 || mWallpaperYStep != -1) { |
| 8294 | pw.print(prefix); pw.print("mWallpaperXStep="); pw.print(mWallpaperXStep); |
| 8295 | pw.print(" mWallpaperYStep="); pw.println(mWallpaperYStep); |
| 8296 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8297 | } |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 8298 | |
| 8299 | String makeInputChannelName() { |
| 8300 | return Integer.toHexString(System.identityHashCode(this)) |
| 8301 | + " " + mAttrs.getTitle(); |
| 8302 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8303 | |
| 8304 | @Override |
| 8305 | public String toString() { |
Mattias Petersson | 1622eee | 2010-12-21 10:15:11 +0100 | [diff] [blame] | 8306 | if (mStringNameCache == null || mLastTitle != mAttrs.getTitle() |
| 8307 | || mWasPaused != mToken.paused) { |
| 8308 | mLastTitle = mAttrs.getTitle(); |
| 8309 | mWasPaused = mToken.paused; |
| 8310 | mStringNameCache = "Window{" + Integer.toHexString(System.identityHashCode(this)) |
| 8311 | + " " + mLastTitle + " paused=" + mWasPaused + "}"; |
| 8312 | } |
| 8313 | return mStringNameCache; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8314 | } |
| 8315 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8316 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8317 | // ------------------------------------------------------------- |
| 8318 | // Window Token State |
| 8319 | // ------------------------------------------------------------- |
| 8320 | |
| 8321 | class WindowToken { |
| 8322 | // The actual token. |
| 8323 | final IBinder token; |
| 8324 | |
| 8325 | // The type of window this token is for, as per WindowManager.LayoutParams. |
| 8326 | final int windowType; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8327 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8328 | // Set if this token was explicitly added by a client, so should |
| 8329 | // not be removed when all windows are removed. |
| 8330 | final boolean explicit; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8331 | |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8332 | // For printing. |
| 8333 | String stringName; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8334 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8335 | // If this is an AppWindowToken, this is non-null. |
| 8336 | AppWindowToken appWindowToken; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8337 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8338 | // All of the windows associated with this token. |
| 8339 | final ArrayList<WindowState> windows = new ArrayList<WindowState>(); |
| 8340 | |
| 8341 | // Is key dispatching paused for this token? |
| 8342 | boolean paused = false; |
| 8343 | |
| 8344 | // Should this token's windows be hidden? |
| 8345 | boolean hidden; |
| 8346 | |
| 8347 | // Temporary for finding which tokens no longer have visible windows. |
| 8348 | boolean hasVisible; |
| 8349 | |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8350 | // Set to true when this token is in a pending transaction where it |
| 8351 | // will be shown. |
| 8352 | boolean waitingToShow; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8353 | |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8354 | // Set to true when this token is in a pending transaction where it |
| 8355 | // will be hidden. |
| 8356 | boolean waitingToHide; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8357 | |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8358 | // Set to true when this token is in a pending transaction where its |
| 8359 | // windows will be put to the bottom of the list. |
| 8360 | boolean sendingToBottom; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8361 | |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8362 | // Set to true when this token is in a pending transaction where its |
| 8363 | // windows will be put to the top of the list. |
| 8364 | boolean sendingToTop; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8365 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8366 | WindowToken(IBinder _token, int type, boolean _explicit) { |
| 8367 | token = _token; |
| 8368 | windowType = type; |
| 8369 | explicit = _explicit; |
| 8370 | } |
| 8371 | |
| 8372 | void dump(PrintWriter pw, String prefix) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8373 | pw.print(prefix); pw.print("token="); pw.println(token); |
| 8374 | pw.print(prefix); pw.print("windows="); pw.println(windows); |
| 8375 | pw.print(prefix); pw.print("windowType="); pw.print(windowType); |
| 8376 | pw.print(" hidden="); pw.print(hidden); |
| 8377 | pw.print(" hasVisible="); pw.println(hasVisible); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8378 | if (waitingToShow || waitingToHide || sendingToBottom || sendingToTop) { |
| 8379 | pw.print(prefix); pw.print("waitingToShow="); pw.print(waitingToShow); |
| 8380 | pw.print(" waitingToHide="); pw.print(waitingToHide); |
| 8381 | pw.print(" sendingToBottom="); pw.print(sendingToBottom); |
| 8382 | pw.print(" sendingToTop="); pw.println(sendingToTop); |
| 8383 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8384 | } |
| 8385 | |
| 8386 | @Override |
| 8387 | public String toString() { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8388 | if (stringName == null) { |
| 8389 | StringBuilder sb = new StringBuilder(); |
| 8390 | sb.append("WindowToken{"); |
| 8391 | sb.append(Integer.toHexString(System.identityHashCode(this))); |
| 8392 | sb.append(" token="); sb.append(token); sb.append('}'); |
| 8393 | stringName = sb.toString(); |
| 8394 | } |
| 8395 | return stringName; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8396 | } |
| 8397 | }; |
| 8398 | |
| 8399 | class AppWindowToken extends WindowToken { |
| 8400 | // Non-null only for application tokens. |
| 8401 | final IApplicationToken appToken; |
| 8402 | |
| 8403 | // All of the windows and child windows that are included in this |
| 8404 | // application token. Note this list is NOT sorted! |
| 8405 | final ArrayList<WindowState> allAppWindows = new ArrayList<WindowState>(); |
| 8406 | |
| 8407 | int groupId = -1; |
| 8408 | boolean appFullscreen; |
| 8409 | int requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 8410 | |
| 8411 | // The input dispatching timeout for this application token in nanoseconds. |
| 8412 | long inputDispatchingTimeoutNanos; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8413 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8414 | // These are used for determining when all windows associated with |
| 8415 | // an activity have been drawn, so they can be made visible together |
| 8416 | // at the same time. |
| 8417 | int lastTransactionSequence = mTransactionSequence-1; |
| 8418 | int numInterestingWindows; |
| 8419 | int numDrawnWindows; |
| 8420 | boolean inPendingTransaction; |
| 8421 | boolean allDrawn; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8422 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8423 | // Is this token going to be hidden in a little while? If so, it |
| 8424 | // won't be taken into account for setting the screen orientation. |
| 8425 | boolean willBeHidden; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8426 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8427 | // Is this window's surface needed? This is almost like hidden, except |
| 8428 | // it will sometimes be true a little earlier: when the token has |
| 8429 | // been shown, but is still waiting for its app transition to execute |
| 8430 | // before making its windows shown. |
| 8431 | boolean hiddenRequested; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8432 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8433 | // Have we told the window clients to hide themselves? |
| 8434 | boolean clientHidden; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8435 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8436 | // Last visibility state we reported to the app token. |
| 8437 | boolean reportedVisible; |
| 8438 | |
| 8439 | // Set to true when the token has been removed from the window mgr. |
| 8440 | boolean removed; |
| 8441 | |
| 8442 | // Have we been asked to have this token keep the screen frozen? |
| 8443 | boolean freezingScreen; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8444 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8445 | boolean animating; |
| 8446 | Animation animation; |
| 8447 | boolean hasTransformation; |
| 8448 | final Transformation transformation = new Transformation(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8449 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8450 | // Offset to the window of all layers in the token, for use by |
| 8451 | // AppWindowToken animations. |
| 8452 | int animLayerAdjustment; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8453 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8454 | // Information about an application starting window if displayed. |
| 8455 | StartingData startingData; |
| 8456 | WindowState startingWindow; |
| 8457 | View startingView; |
| 8458 | boolean startingDisplayed; |
| 8459 | boolean startingMoved; |
| 8460 | boolean firstWindowDrawn; |
| 8461 | |
Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame] | 8462 | // Input application handle used by the input dispatcher. |
| 8463 | InputApplicationHandle mInputApplicationHandle; |
| 8464 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8465 | AppWindowToken(IApplicationToken _token) { |
| 8466 | super(_token.asBinder(), |
| 8467 | WindowManager.LayoutParams.TYPE_APPLICATION, true); |
| 8468 | appWindowToken = this; |
| 8469 | appToken = _token; |
Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame] | 8470 | mInputApplicationHandle = new InputApplicationHandle(this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8471 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8472 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8473 | public void setAnimation(Animation anim) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8474 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8475 | TAG, "Setting animation in " + this + ": " + anim); |
| 8476 | animation = anim; |
| 8477 | animating = false; |
| 8478 | anim.restrictDuration(MAX_ANIMATION_DURATION); |
| 8479 | anim.scaleCurrentDuration(mTransitionAnimationScale); |
| 8480 | int zorder = anim.getZAdjustment(); |
| 8481 | int adj = 0; |
| 8482 | if (zorder == Animation.ZORDER_TOP) { |
| 8483 | adj = TYPE_LAYER_OFFSET; |
| 8484 | } else if (zorder == Animation.ZORDER_BOTTOM) { |
| 8485 | adj = -TYPE_LAYER_OFFSET; |
| 8486 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8487 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8488 | if (animLayerAdjustment != adj) { |
| 8489 | animLayerAdjustment = adj; |
| 8490 | updateLayers(); |
| 8491 | } |
| 8492 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8493 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8494 | public void setDummyAnimation() { |
| 8495 | if (animation == null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8496 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8497 | TAG, "Setting dummy animation in " + this); |
| 8498 | animation = sDummyAnimation; |
| 8499 | } |
| 8500 | } |
| 8501 | |
| 8502 | public void clearAnimation() { |
| 8503 | if (animation != null) { |
| 8504 | animation = null; |
| 8505 | animating = true; |
| 8506 | } |
| 8507 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8508 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8509 | void updateLayers() { |
| 8510 | final int N = allAppWindows.size(); |
| 8511 | final int adj = animLayerAdjustment; |
| 8512 | for (int i=0; i<N; i++) { |
| 8513 | WindowState w = allAppWindows.get(i); |
| 8514 | w.mAnimLayer = w.mLayer + adj; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8515 | if (DEBUG_LAYERS) Slog.v(TAG, "Updating layer " + w + ": " |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8516 | + w.mAnimLayer); |
| 8517 | if (w == mInputMethodTarget) { |
| 8518 | setInputMethodAnimLayerAdjustment(adj); |
| 8519 | } |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 8520 | if (w == mWallpaperTarget && mLowerWallpaperTarget == null) { |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 8521 | setWallpaperAnimLayerAdjustmentLocked(adj); |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 8522 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8523 | } |
| 8524 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8525 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8526 | void sendAppVisibilityToClients() { |
| 8527 | final int N = allAppWindows.size(); |
| 8528 | for (int i=0; i<N; i++) { |
| 8529 | WindowState win = allAppWindows.get(i); |
| 8530 | if (win == startingWindow && clientHidden) { |
| 8531 | // Don't hide the starting window. |
| 8532 | continue; |
| 8533 | } |
| 8534 | try { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8535 | if (DEBUG_VISIBILITY) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8536 | "Setting visibility of " + win + ": " + (!clientHidden)); |
| 8537 | win.mClient.dispatchAppVisibility(!clientHidden); |
| 8538 | } catch (RemoteException e) { |
| 8539 | } |
| 8540 | } |
| 8541 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8542 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8543 | void showAllWindowsLocked() { |
| 8544 | final int NW = allAppWindows.size(); |
| 8545 | for (int i=0; i<NW; i++) { |
| 8546 | WindowState w = allAppWindows.get(i); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8547 | if (DEBUG_VISIBILITY) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8548 | "performing show on: " + w); |
| 8549 | w.performShowLocked(); |
| 8550 | } |
| 8551 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8552 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8553 | // This must be called while inside a transaction. |
| 8554 | boolean stepAnimationLocked(long currentTime, int dw, int dh) { |
Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 8555 | if (!mDisplayFrozen && mPolicy.isScreenOn()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8556 | // We will run animations as long as the display isn't frozen. |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8557 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8558 | if (animation == sDummyAnimation) { |
| 8559 | // This guy is going to animate, but not yet. For now count |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 8560 | // it as not animating for purposes of scheduling transactions; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8561 | // when it is really time to animate, this will be set to |
| 8562 | // a real animation and the next call will execute normally. |
| 8563 | return false; |
| 8564 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8565 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8566 | if ((allDrawn || animating || startingDisplayed) && animation != null) { |
| 8567 | if (!animating) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8568 | if (DEBUG_ANIM) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8569 | TAG, "Starting animation in " + this + |
| 8570 | " @ " + currentTime + ": dw=" + dw + " dh=" + dh |
| 8571 | + " scale=" + mTransitionAnimationScale |
| 8572 | + " allDrawn=" + allDrawn + " animating=" + animating); |
| 8573 | animation.initialize(dw, dh, dw, dh); |
| 8574 | animation.setStartTime(currentTime); |
| 8575 | animating = true; |
| 8576 | } |
| 8577 | transformation.clear(); |
| 8578 | final boolean more = animation.getTransformation( |
| 8579 | currentTime, transformation); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8580 | if (DEBUG_ANIM) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8581 | TAG, "Stepped animation in " + this + |
| 8582 | ": more=" + more + ", xform=" + transformation); |
| 8583 | if (more) { |
| 8584 | // we're done! |
| 8585 | hasTransformation = true; |
| 8586 | return true; |
| 8587 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8588 | if (DEBUG_ANIM) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8589 | TAG, "Finished animation in " + this + |
| 8590 | " @ " + currentTime); |
| 8591 | animation = null; |
| 8592 | } |
| 8593 | } else if (animation != null) { |
| 8594 | // If the display is frozen, and there is a pending animation, |
| 8595 | // clear it and make sure we run the cleanup code. |
| 8596 | animating = true; |
| 8597 | animation = null; |
| 8598 | } |
| 8599 | |
| 8600 | hasTransformation = false; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8601 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8602 | if (!animating) { |
| 8603 | return false; |
| 8604 | } |
| 8605 | |
| 8606 | clearAnimation(); |
| 8607 | animating = false; |
| 8608 | if (mInputMethodTarget != null && mInputMethodTarget.mAppToken == this) { |
| 8609 | moveInputMethodWindowsIfNeededLocked(true); |
| 8610 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8611 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8612 | if (DEBUG_ANIM) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8613 | TAG, "Animation done in " + this |
| 8614 | + ": reportedVisible=" + reportedVisible); |
| 8615 | |
| 8616 | transformation.clear(); |
| 8617 | if (animLayerAdjustment != 0) { |
| 8618 | animLayerAdjustment = 0; |
| 8619 | updateLayers(); |
| 8620 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8621 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8622 | final int N = windows.size(); |
| 8623 | for (int i=0; i<N; i++) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 8624 | windows.get(i).finishExit(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8625 | } |
| 8626 | updateReportedVisibilityLocked(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8627 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8628 | return false; |
| 8629 | } |
| 8630 | |
| 8631 | void updateReportedVisibilityLocked() { |
| 8632 | if (appToken == null) { |
| 8633 | return; |
| 8634 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8635 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8636 | int numInteresting = 0; |
| 8637 | int numVisible = 0; |
| 8638 | boolean nowGone = true; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8639 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8640 | if (DEBUG_VISIBILITY) Slog.v(TAG, "Update reported visibility: " + this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8641 | final int N = allAppWindows.size(); |
| 8642 | for (int i=0; i<N; i++) { |
| 8643 | WindowState win = allAppWindows.get(i); |
Dianne Hackborn | 6cf67fa | 2009-12-21 16:46:34 -0800 | [diff] [blame] | 8644 | if (win == startingWindow || win.mAppFreezing |
The Android Open Source Project | 727cec0 | 2010-04-08 11:35:37 -0700 | [diff] [blame] | 8645 | || win.mViewVisibility != View.VISIBLE |
Ulf Rosdahl | 3935770 | 2010-09-29 12:34:38 +0200 | [diff] [blame] | 8646 | || win.mAttrs.type == TYPE_APPLICATION_STARTING |
| 8647 | || win.mDestroying) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8648 | continue; |
| 8649 | } |
| 8650 | if (DEBUG_VISIBILITY) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8651 | Slog.v(TAG, "Win " + win + ": isDrawn=" |
Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 8652 | + win.isDrawnLw() |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8653 | + ", isAnimating=" + win.isAnimating()); |
Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 8654 | if (!win.isDrawnLw()) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8655 | Slog.v(TAG, "Not displayed: s=" + win.mSurface |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8656 | + " pv=" + win.mPolicyVisibility |
| 8657 | + " dp=" + win.mDrawPending |
| 8658 | + " cdp=" + win.mCommitDrawPending |
| 8659 | + " ah=" + win.mAttachedHidden |
| 8660 | + " th=" |
| 8661 | + (win.mAppToken != null |
| 8662 | ? win.mAppToken.hiddenRequested : false) |
| 8663 | + " a=" + win.mAnimating); |
| 8664 | } |
| 8665 | } |
| 8666 | numInteresting++; |
Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 8667 | if (win.isDrawnLw()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8668 | if (!win.isAnimating()) { |
| 8669 | numVisible++; |
| 8670 | } |
| 8671 | nowGone = false; |
| 8672 | } else if (win.isAnimating()) { |
| 8673 | nowGone = false; |
| 8674 | } |
| 8675 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8676 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8677 | boolean nowVisible = numInteresting > 0 && numVisible >= numInteresting; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8678 | if (DEBUG_VISIBILITY) Slog.v(TAG, "VIS " + this + ": interesting=" |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8679 | + numInteresting + " visible=" + numVisible); |
| 8680 | if (nowVisible != reportedVisible) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8681 | if (DEBUG_VISIBILITY) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8682 | TAG, "Visibility changed in " + this |
| 8683 | + ": vis=" + nowVisible); |
| 8684 | reportedVisible = nowVisible; |
| 8685 | Message m = mH.obtainMessage( |
| 8686 | H.REPORT_APPLICATION_TOKEN_WINDOWS, |
| 8687 | nowVisible ? 1 : 0, |
| 8688 | nowGone ? 1 : 0, |
| 8689 | this); |
| 8690 | mH.sendMessage(m); |
| 8691 | } |
| 8692 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8693 | |
Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 8694 | WindowState findMainWindow() { |
| 8695 | int j = windows.size(); |
| 8696 | while (j > 0) { |
| 8697 | j--; |
| 8698 | WindowState win = windows.get(j); |
| 8699 | if (win.mAttrs.type == WindowManager.LayoutParams.TYPE_BASE_APPLICATION |
| 8700 | || win.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING) { |
| 8701 | return win; |
| 8702 | } |
| 8703 | } |
| 8704 | return null; |
| 8705 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8706 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8707 | void dump(PrintWriter pw, String prefix) { |
| 8708 | super.dump(pw, prefix); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8709 | if (appToken != null) { |
| 8710 | pw.print(prefix); pw.println("app=true"); |
| 8711 | } |
| 8712 | if (allAppWindows.size() > 0) { |
| 8713 | pw.print(prefix); pw.print("allAppWindows="); pw.println(allAppWindows); |
| 8714 | } |
| 8715 | pw.print(prefix); pw.print("groupId="); pw.print(groupId); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8716 | pw.print(" appFullscreen="); pw.print(appFullscreen); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8717 | pw.print(" requestedOrientation="); pw.println(requestedOrientation); |
| 8718 | pw.print(prefix); pw.print("hiddenRequested="); pw.print(hiddenRequested); |
| 8719 | pw.print(" clientHidden="); pw.print(clientHidden); |
| 8720 | pw.print(" willBeHidden="); pw.print(willBeHidden); |
| 8721 | pw.print(" reportedVisible="); pw.println(reportedVisible); |
| 8722 | if (paused || freezingScreen) { |
| 8723 | pw.print(prefix); pw.print("paused="); pw.print(paused); |
| 8724 | pw.print(" freezingScreen="); pw.println(freezingScreen); |
| 8725 | } |
| 8726 | if (numInterestingWindows != 0 || numDrawnWindows != 0 |
| 8727 | || inPendingTransaction || allDrawn) { |
| 8728 | pw.print(prefix); pw.print("numInterestingWindows="); |
| 8729 | pw.print(numInterestingWindows); |
| 8730 | pw.print(" numDrawnWindows="); pw.print(numDrawnWindows); |
| 8731 | pw.print(" inPendingTransaction="); pw.print(inPendingTransaction); |
| 8732 | pw.print(" allDrawn="); pw.println(allDrawn); |
| 8733 | } |
| 8734 | if (animating || animation != null) { |
| 8735 | pw.print(prefix); pw.print("animating="); pw.print(animating); |
| 8736 | pw.print(" animation="); pw.println(animation); |
| 8737 | } |
Dianne Hackborn | 7da6ac3 | 2010-12-09 19:22:04 -0800 | [diff] [blame] | 8738 | if (hasTransformation) { |
| 8739 | pw.print(prefix); pw.print("XForm: "); |
| 8740 | transformation.printShortString(pw); |
| 8741 | pw.println(); |
| 8742 | } |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8743 | if (animLayerAdjustment != 0) { |
| 8744 | pw.print(prefix); pw.print("animLayerAdjustment="); pw.println(animLayerAdjustment); |
| 8745 | } |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8746 | if (startingData != null || removed || firstWindowDrawn) { |
| 8747 | pw.print(prefix); pw.print("startingData="); pw.print(startingData); |
| 8748 | pw.print(" removed="); pw.print(removed); |
| 8749 | pw.print(" firstWindowDrawn="); pw.println(firstWindowDrawn); |
| 8750 | } |
| 8751 | if (startingWindow != null || startingView != null |
| 8752 | || startingDisplayed || startingMoved) { |
| 8753 | pw.print(prefix); pw.print("startingWindow="); pw.print(startingWindow); |
| 8754 | pw.print(" startingView="); pw.print(startingView); |
| 8755 | pw.print(" startingDisplayed="); pw.print(startingDisplayed); |
| 8756 | pw.print(" startingMoved"); pw.println(startingMoved); |
| 8757 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8758 | } |
| 8759 | |
| 8760 | @Override |
| 8761 | public String toString() { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8762 | if (stringName == null) { |
| 8763 | StringBuilder sb = new StringBuilder(); |
| 8764 | sb.append("AppWindowToken{"); |
| 8765 | sb.append(Integer.toHexString(System.identityHashCode(this))); |
| 8766 | sb.append(" token="); sb.append(token); sb.append('}'); |
| 8767 | stringName = sb.toString(); |
| 8768 | } |
| 8769 | return stringName; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8770 | } |
| 8771 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8772 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8773 | // ------------------------------------------------------------- |
| 8774 | // DummyAnimation |
| 8775 | // ------------------------------------------------------------- |
| 8776 | |
| 8777 | // This is an animation that does nothing: it just immediately finishes |
| 8778 | // itself every time it is called. It is used as a stub animation in cases |
| 8779 | // where we want to synchronize multiple things that may be animating. |
| 8780 | static final class DummyAnimation extends Animation { |
| 8781 | public boolean getTransformation(long currentTime, Transformation outTransformation) { |
| 8782 | return false; |
| 8783 | } |
| 8784 | } |
| 8785 | static final Animation sDummyAnimation = new DummyAnimation(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8786 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8787 | // ------------------------------------------------------------- |
| 8788 | // Async Handler |
| 8789 | // ------------------------------------------------------------- |
| 8790 | |
| 8791 | static final class StartingData { |
| 8792 | final String pkg; |
| 8793 | final int theme; |
| 8794 | final CharSequence nonLocalizedLabel; |
| 8795 | final int labelRes; |
| 8796 | final int icon; |
Dianne Hackborn | 7eec10e | 2010-11-12 18:03:47 -0800 | [diff] [blame] | 8797 | final int windowFlags; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8798 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8799 | StartingData(String _pkg, int _theme, CharSequence _nonLocalizedLabel, |
Dianne Hackborn | 7eec10e | 2010-11-12 18:03:47 -0800 | [diff] [blame] | 8800 | int _labelRes, int _icon, int _windowFlags) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8801 | pkg = _pkg; |
| 8802 | theme = _theme; |
| 8803 | nonLocalizedLabel = _nonLocalizedLabel; |
| 8804 | labelRes = _labelRes; |
| 8805 | icon = _icon; |
Dianne Hackborn | 7eec10e | 2010-11-12 18:03:47 -0800 | [diff] [blame] | 8806 | windowFlags = _windowFlags; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8807 | } |
| 8808 | } |
| 8809 | |
| 8810 | private final class H extends Handler { |
| 8811 | public static final int REPORT_FOCUS_CHANGE = 2; |
| 8812 | public static final int REPORT_LOSING_FOCUS = 3; |
| 8813 | public static final int ANIMATE = 4; |
| 8814 | public static final int ADD_STARTING = 5; |
| 8815 | public static final int REMOVE_STARTING = 6; |
| 8816 | public static final int FINISHED_STARTING = 7; |
| 8817 | public static final int REPORT_APPLICATION_TOKEN_WINDOWS = 8; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8818 | public static final int WINDOW_FREEZE_TIMEOUT = 11; |
| 8819 | public static final int HOLD_SCREEN_CHANGED = 12; |
| 8820 | public static final int APP_TRANSITION_TIMEOUT = 13; |
| 8821 | public static final int PERSIST_ANIMATION_SCALE = 14; |
| 8822 | public static final int FORCE_GC = 15; |
| 8823 | public static final int ENABLE_SCREEN = 16; |
| 8824 | public static final int APP_FREEZE_TIMEOUT = 17; |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 8825 | public static final int SEND_NEW_CONFIGURATION = 18; |
Konstantin Lopyrev | 6e0f65f | 2010-07-14 14:55:33 -0700 | [diff] [blame] | 8826 | public static final int REPORT_WINDOWS_CHANGE = 19; |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 8827 | public static final int DRAG_START_TIMEOUT = 20; |
Chris Tate | d4533f14 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 8828 | public static final int DRAG_END_TIMEOUT = 21; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8829 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8830 | private Session mLastReportedHold; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8831 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8832 | public H() { |
| 8833 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8834 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8835 | @Override |
| 8836 | public void handleMessage(Message msg) { |
| 8837 | switch (msg.what) { |
| 8838 | case REPORT_FOCUS_CHANGE: { |
| 8839 | WindowState lastFocus; |
| 8840 | WindowState newFocus; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8841 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8842 | synchronized(mWindowMap) { |
| 8843 | lastFocus = mLastFocus; |
| 8844 | newFocus = mCurrentFocus; |
| 8845 | if (lastFocus == newFocus) { |
| 8846 | // Focus is not changing, so nothing to do. |
| 8847 | return; |
| 8848 | } |
| 8849 | mLastFocus = newFocus; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8850 | //Slog.i(TAG, "Focus moving from " + lastFocus |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8851 | // + " to " + newFocus); |
| 8852 | if (newFocus != null && lastFocus != null |
| 8853 | && !newFocus.isDisplayedLw()) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8854 | //Slog.i(TAG, "Delaying loss of focus..."); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8855 | mLosingFocus.add(lastFocus); |
| 8856 | lastFocus = null; |
| 8857 | } |
| 8858 | } |
| 8859 | |
| 8860 | if (lastFocus != newFocus) { |
| 8861 | //System.out.println("Changing focus from " + lastFocus |
| 8862 | // + " to " + newFocus); |
| 8863 | if (newFocus != null) { |
| 8864 | try { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8865 | //Slog.i(TAG, "Gaining focus: " + newFocus); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8866 | newFocus.mClient.windowFocusChanged(true, mInTouchMode); |
| 8867 | } catch (RemoteException e) { |
| 8868 | // Ignore if process has died. |
| 8869 | } |
Konstantin Lopyrev | 5e7833a | 2010-08-09 17:01:11 -0700 | [diff] [blame] | 8870 | notifyFocusChanged(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8871 | } |
| 8872 | |
| 8873 | if (lastFocus != null) { |
| 8874 | try { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8875 | //Slog.i(TAG, "Losing focus: " + lastFocus); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8876 | lastFocus.mClient.windowFocusChanged(false, mInTouchMode); |
| 8877 | } catch (RemoteException e) { |
| 8878 | // Ignore if process has died. |
| 8879 | } |
| 8880 | } |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 8881 | |
| 8882 | mPolicy.focusChanged(lastFocus, newFocus); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8883 | } |
| 8884 | } break; |
| 8885 | |
| 8886 | case REPORT_LOSING_FOCUS: { |
| 8887 | ArrayList<WindowState> losers; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8888 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8889 | synchronized(mWindowMap) { |
| 8890 | losers = mLosingFocus; |
| 8891 | mLosingFocus = new ArrayList<WindowState>(); |
| 8892 | } |
| 8893 | |
| 8894 | final int N = losers.size(); |
| 8895 | for (int i=0; i<N; i++) { |
| 8896 | try { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8897 | //Slog.i(TAG, "Losing delayed focus: " + losers.get(i)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8898 | losers.get(i).mClient.windowFocusChanged(false, mInTouchMode); |
| 8899 | } catch (RemoteException e) { |
| 8900 | // Ignore if process has died. |
| 8901 | } |
| 8902 | } |
| 8903 | } break; |
| 8904 | |
| 8905 | case ANIMATE: { |
| 8906 | synchronized(mWindowMap) { |
| 8907 | mAnimationPending = false; |
| 8908 | performLayoutAndPlaceSurfacesLocked(); |
| 8909 | } |
| 8910 | } break; |
| 8911 | |
| 8912 | case ADD_STARTING: { |
| 8913 | final AppWindowToken wtoken = (AppWindowToken)msg.obj; |
| 8914 | final StartingData sd = wtoken.startingData; |
| 8915 | |
| 8916 | if (sd == null) { |
| 8917 | // Animation has been canceled... do nothing. |
| 8918 | return; |
| 8919 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8920 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8921 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Add starting " |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8922 | + wtoken + ": pkg=" + sd.pkg); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8923 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8924 | View view = null; |
| 8925 | try { |
| 8926 | view = mPolicy.addStartingWindow( |
| 8927 | wtoken.token, sd.pkg, |
| 8928 | sd.theme, sd.nonLocalizedLabel, sd.labelRes, |
Dianne Hackborn | 7eec10e | 2010-11-12 18:03:47 -0800 | [diff] [blame] | 8929 | sd.icon, sd.windowFlags); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8930 | } catch (Exception e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8931 | Slog.w(TAG, "Exception when adding starting window", e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8932 | } |
| 8933 | |
| 8934 | if (view != null) { |
| 8935 | boolean abort = false; |
| 8936 | |
| 8937 | synchronized(mWindowMap) { |
| 8938 | if (wtoken.removed || wtoken.startingData == null) { |
| 8939 | // If the window was successfully added, then |
| 8940 | // we need to remove it. |
| 8941 | if (wtoken.startingWindow != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8942 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8943 | "Aborted starting " + wtoken |
| 8944 | + ": removed=" + wtoken.removed |
| 8945 | + " startingData=" + wtoken.startingData); |
| 8946 | wtoken.startingWindow = null; |
| 8947 | wtoken.startingData = null; |
| 8948 | abort = true; |
| 8949 | } |
| 8950 | } else { |
| 8951 | wtoken.startingView = view; |
| 8952 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8953 | if (DEBUG_STARTING_WINDOW && !abort) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8954 | "Added starting " + wtoken |
| 8955 | + ": startingWindow=" |
| 8956 | + wtoken.startingWindow + " startingView=" |
| 8957 | + wtoken.startingView); |
| 8958 | } |
| 8959 | |
| 8960 | if (abort) { |
| 8961 | try { |
| 8962 | mPolicy.removeStartingWindow(wtoken.token, view); |
| 8963 | } catch (Exception e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8964 | Slog.w(TAG, "Exception when removing starting window", e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8965 | } |
| 8966 | } |
| 8967 | } |
| 8968 | } break; |
| 8969 | |
| 8970 | case REMOVE_STARTING: { |
| 8971 | final AppWindowToken wtoken = (AppWindowToken)msg.obj; |
| 8972 | IBinder token = null; |
| 8973 | View view = null; |
| 8974 | synchronized (mWindowMap) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8975 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Remove starting " |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8976 | + wtoken + ": startingWindow=" |
| 8977 | + wtoken.startingWindow + " startingView=" |
| 8978 | + wtoken.startingView); |
| 8979 | if (wtoken.startingWindow != null) { |
| 8980 | view = wtoken.startingView; |
| 8981 | token = wtoken.token; |
| 8982 | wtoken.startingData = null; |
| 8983 | wtoken.startingView = null; |
| 8984 | wtoken.startingWindow = null; |
| 8985 | } |
| 8986 | } |
| 8987 | if (view != null) { |
| 8988 | try { |
| 8989 | mPolicy.removeStartingWindow(token, view); |
| 8990 | } catch (Exception e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8991 | Slog.w(TAG, "Exception when removing starting window", e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8992 | } |
| 8993 | } |
| 8994 | } break; |
| 8995 | |
| 8996 | case FINISHED_STARTING: { |
| 8997 | IBinder token = null; |
| 8998 | View view = null; |
| 8999 | while (true) { |
| 9000 | synchronized (mWindowMap) { |
| 9001 | final int N = mFinishedStarting.size(); |
| 9002 | if (N <= 0) { |
| 9003 | break; |
| 9004 | } |
| 9005 | AppWindowToken wtoken = mFinishedStarting.remove(N-1); |
| 9006 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9007 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9008 | "Finished starting " + wtoken |
| 9009 | + ": startingWindow=" + wtoken.startingWindow |
| 9010 | + " startingView=" + wtoken.startingView); |
| 9011 | |
| 9012 | if (wtoken.startingWindow == null) { |
| 9013 | continue; |
| 9014 | } |
| 9015 | |
| 9016 | view = wtoken.startingView; |
| 9017 | token = wtoken.token; |
| 9018 | wtoken.startingData = null; |
| 9019 | wtoken.startingView = null; |
| 9020 | wtoken.startingWindow = null; |
| 9021 | } |
| 9022 | |
| 9023 | try { |
| 9024 | mPolicy.removeStartingWindow(token, view); |
| 9025 | } catch (Exception e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9026 | Slog.w(TAG, "Exception when removing starting window", e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9027 | } |
| 9028 | } |
| 9029 | } break; |
| 9030 | |
| 9031 | case REPORT_APPLICATION_TOKEN_WINDOWS: { |
| 9032 | final AppWindowToken wtoken = (AppWindowToken)msg.obj; |
| 9033 | |
| 9034 | boolean nowVisible = msg.arg1 != 0; |
| 9035 | boolean nowGone = msg.arg2 != 0; |
| 9036 | |
| 9037 | try { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9038 | if (DEBUG_VISIBILITY) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9039 | TAG, "Reporting visible in " + wtoken |
| 9040 | + " visible=" + nowVisible |
| 9041 | + " gone=" + nowGone); |
| 9042 | if (nowVisible) { |
| 9043 | wtoken.appToken.windowsVisible(); |
| 9044 | } else { |
| 9045 | wtoken.appToken.windowsGone(); |
| 9046 | } |
| 9047 | } catch (RemoteException ex) { |
| 9048 | } |
| 9049 | } break; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9050 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9051 | case WINDOW_FREEZE_TIMEOUT: { |
| 9052 | synchronized (mWindowMap) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9053 | Slog.w(TAG, "Window freeze timeout expired."); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9054 | int i = mWindows.size(); |
| 9055 | while (i > 0) { |
| 9056 | i--; |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 9057 | WindowState w = mWindows.get(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9058 | if (w.mOrientationChanging) { |
| 9059 | w.mOrientationChanging = false; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9060 | Slog.w(TAG, "Force clearing orientation change: " + w); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9061 | } |
| 9062 | } |
| 9063 | performLayoutAndPlaceSurfacesLocked(); |
| 9064 | } |
| 9065 | break; |
| 9066 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9067 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9068 | case HOLD_SCREEN_CHANGED: { |
| 9069 | Session oldHold; |
| 9070 | Session newHold; |
| 9071 | synchronized (mWindowMap) { |
| 9072 | oldHold = mLastReportedHold; |
| 9073 | newHold = (Session)msg.obj; |
| 9074 | mLastReportedHold = newHold; |
| 9075 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9076 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9077 | if (oldHold != newHold) { |
| 9078 | try { |
| 9079 | if (oldHold != null) { |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 9080 | mBatteryStats.noteStopWakelock(oldHold.mUid, -1, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9081 | "window", |
| 9082 | BatteryStats.WAKE_TYPE_WINDOW); |
| 9083 | } |
| 9084 | if (newHold != null) { |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 9085 | mBatteryStats.noteStartWakelock(newHold.mUid, -1, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9086 | "window", |
| 9087 | BatteryStats.WAKE_TYPE_WINDOW); |
| 9088 | } |
| 9089 | } catch (RemoteException e) { |
| 9090 | } |
| 9091 | } |
| 9092 | break; |
| 9093 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9094 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9095 | case APP_TRANSITION_TIMEOUT: { |
| 9096 | synchronized (mWindowMap) { |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 9097 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9098 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9099 | "*** APP TRANSITION TIMEOUT"); |
| 9100 | mAppTransitionReady = true; |
| 9101 | mAppTransitionTimeout = true; |
| 9102 | performLayoutAndPlaceSurfacesLocked(); |
| 9103 | } |
| 9104 | } |
| 9105 | break; |
| 9106 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9107 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9108 | case PERSIST_ANIMATION_SCALE: { |
| 9109 | Settings.System.putFloat(mContext.getContentResolver(), |
| 9110 | Settings.System.WINDOW_ANIMATION_SCALE, mWindowAnimationScale); |
| 9111 | Settings.System.putFloat(mContext.getContentResolver(), |
| 9112 | Settings.System.TRANSITION_ANIMATION_SCALE, mTransitionAnimationScale); |
| 9113 | break; |
| 9114 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9115 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9116 | case FORCE_GC: { |
| 9117 | synchronized(mWindowMap) { |
| 9118 | if (mAnimationPending) { |
| 9119 | // If we are animating, don't do the gc now but |
| 9120 | // delay a bit so we don't interrupt the animation. |
| 9121 | mH.sendMessageDelayed(mH.obtainMessage(H.FORCE_GC), |
| 9122 | 2000); |
| 9123 | return; |
| 9124 | } |
| 9125 | // If we are currently rotating the display, it will |
| 9126 | // schedule a new message when done. |
| 9127 | if (mDisplayFrozen) { |
| 9128 | return; |
| 9129 | } |
| 9130 | mFreezeGcPending = 0; |
| 9131 | } |
| 9132 | Runtime.getRuntime().gc(); |
| 9133 | break; |
| 9134 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9135 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9136 | case ENABLE_SCREEN: { |
| 9137 | performEnableScreen(); |
| 9138 | break; |
| 9139 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9140 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9141 | case APP_FREEZE_TIMEOUT: { |
| 9142 | synchronized (mWindowMap) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9143 | Slog.w(TAG, "App freeze timeout expired."); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9144 | int i = mAppTokens.size(); |
| 9145 | while (i > 0) { |
| 9146 | i--; |
| 9147 | AppWindowToken tok = mAppTokens.get(i); |
| 9148 | if (tok.freezingScreen) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9149 | Slog.w(TAG, "Force clearing freeze: " + tok); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9150 | unsetAppFreezingScreenLocked(tok, true, true); |
| 9151 | } |
| 9152 | } |
| 9153 | } |
| 9154 | break; |
| 9155 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9156 | |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 9157 | case SEND_NEW_CONFIGURATION: { |
| 9158 | removeMessages(SEND_NEW_CONFIGURATION); |
| 9159 | sendNewConfiguration(); |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 9160 | break; |
| 9161 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9162 | |
Konstantin Lopyrev | 6e0f65f | 2010-07-14 14:55:33 -0700 | [diff] [blame] | 9163 | case REPORT_WINDOWS_CHANGE: { |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 9164 | if (mWindowsChanged) { |
| 9165 | synchronized (mWindowMap) { |
| 9166 | mWindowsChanged = false; |
| 9167 | } |
| 9168 | notifyWindowsChanged(); |
| 9169 | } |
| 9170 | break; |
| 9171 | } |
| 9172 | |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 9173 | case DRAG_START_TIMEOUT: { |
| 9174 | IBinder win = (IBinder)msg.obj; |
| 9175 | if (DEBUG_DRAG) { |
| 9176 | Slog.w(TAG, "Timeout starting drag by win " + win); |
| 9177 | } |
| 9178 | synchronized (mWindowMap) { |
| 9179 | // !!! TODO: ANR the app that has failed to start the drag in time |
| 9180 | if (mDragState != null) { |
Chris Tate | d4533f14 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 9181 | mDragState.unregister(); |
Jeff Brown | 2e44b07 | 2011-01-24 15:21:56 -0800 | [diff] [blame^] | 9182 | mInputMonitor.updateInputWindowsLw(true /*force*/); |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 9183 | mDragState.reset(); |
| 9184 | mDragState = null; |
| 9185 | } |
| 9186 | } |
Chris Tate | d4533f14 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 9187 | break; |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 9188 | } |
| 9189 | |
Chris Tate | d4533f14 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 9190 | case DRAG_END_TIMEOUT: { |
| 9191 | IBinder win = (IBinder)msg.obj; |
| 9192 | if (DEBUG_DRAG) { |
| 9193 | Slog.w(TAG, "Timeout ending drag to win " + win); |
| 9194 | } |
| 9195 | synchronized (mWindowMap) { |
| 9196 | // !!! TODO: ANR the drag-receiving app |
| 9197 | mDragState.mDragResult = false; |
| 9198 | mDragState.endDragLw(); |
| 9199 | } |
| 9200 | break; |
| 9201 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9202 | } |
| 9203 | } |
| 9204 | } |
| 9205 | |
| 9206 | // ------------------------------------------------------------- |
| 9207 | // IWindowManager API |
| 9208 | // ------------------------------------------------------------- |
| 9209 | |
| 9210 | public IWindowSession openSession(IInputMethodClient client, |
| 9211 | IInputContext inputContext) { |
| 9212 | if (client == null) throw new IllegalArgumentException("null client"); |
| 9213 | if (inputContext == null) throw new IllegalArgumentException("null inputContext"); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 9214 | Session session = new Session(client, inputContext); |
| 9215 | return session; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9216 | } |
| 9217 | |
| 9218 | public boolean inputMethodClientHasFocus(IInputMethodClient client) { |
| 9219 | synchronized (mWindowMap) { |
| 9220 | // The focus for the client is the window immediately below |
| 9221 | // where we would place the input method window. |
| 9222 | int idx = findDesiredInputMethodWindowIndexLocked(false); |
| 9223 | WindowState imFocus; |
| 9224 | if (idx > 0) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 9225 | imFocus = mWindows.get(idx-1); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9226 | if (imFocus != null) { |
| 9227 | if (imFocus.mSession.mClient != null && |
| 9228 | imFocus.mSession.mClient.asBinder() == client.asBinder()) { |
| 9229 | return true; |
| 9230 | } |
| 9231 | } |
| 9232 | } |
| 9233 | } |
| 9234 | return false; |
| 9235 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9236 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9237 | // ------------------------------------------------------------- |
| 9238 | // Internals |
| 9239 | // ------------------------------------------------------------- |
| 9240 | |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 9241 | final WindowState windowForClientLocked(Session session, IWindow client, |
| 9242 | boolean throwOnError) { |
| 9243 | return windowForClientLocked(session, client.asBinder(), throwOnError); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9244 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9245 | |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 9246 | final WindowState windowForClientLocked(Session session, IBinder client, |
| 9247 | boolean throwOnError) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9248 | WindowState win = mWindowMap.get(client); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9249 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9250 | TAG, "Looking up client " + client + ": " + win); |
| 9251 | if (win == null) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 9252 | RuntimeException ex = new IllegalArgumentException( |
| 9253 | "Requested window " + client + " does not exist"); |
| 9254 | if (throwOnError) { |
| 9255 | throw ex; |
| 9256 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9257 | Slog.w(TAG, "Failed looking up window", ex); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9258 | return null; |
| 9259 | } |
| 9260 | if (session != null && win.mSession != session) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 9261 | RuntimeException ex = new IllegalArgumentException( |
| 9262 | "Requested window " + client + " is in session " + |
| 9263 | win.mSession + ", not " + session); |
| 9264 | if (throwOnError) { |
| 9265 | throw ex; |
| 9266 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9267 | Slog.w(TAG, "Failed looking up window", ex); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9268 | return null; |
| 9269 | } |
| 9270 | |
| 9271 | return win; |
| 9272 | } |
| 9273 | |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9274 | final void rebuildAppWindowListLocked() { |
| 9275 | int NW = mWindows.size(); |
| 9276 | int i; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9277 | int lastWallpaper = -1; |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 9278 | int numRemoved = 0; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9279 | |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 9280 | if (mRebuildTmp.length < NW) { |
| 9281 | mRebuildTmp = new WindowState[NW+10]; |
| 9282 | } |
| 9283 | |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9284 | // First remove all existing app windows. |
| 9285 | i=0; |
| 9286 | while (i < NW) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 9287 | WindowState w = mWindows.get(i); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9288 | if (w.mAppToken != null) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 9289 | WindowState win = mWindows.remove(i); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 9290 | win.mRebuilding = true; |
| 9291 | mRebuildTmp[numRemoved] = win; |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 9292 | mWindowsChanged = true; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9293 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, |
Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 9294 | "Rebuild removing window: " + win); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9295 | NW--; |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 9296 | numRemoved++; |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9297 | continue; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9298 | } else if (w.mAttrs.type == WindowManager.LayoutParams.TYPE_WALLPAPER |
| 9299 | && lastWallpaper == i-1) { |
| 9300 | lastWallpaper = i; |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9301 | } |
| 9302 | i++; |
| 9303 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9304 | |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9305 | // The wallpaper window(s) typically live at the bottom of the stack, |
| 9306 | // so skip them before adding app tokens. |
| 9307 | lastWallpaper++; |
| 9308 | i = lastWallpaper; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9309 | |
Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 9310 | // First add all of the exiting app tokens... these are no longer |
| 9311 | // in the main app list, but still have windows shown. We put them |
| 9312 | // in the back because now that the animation is over we no longer |
| 9313 | // will care about them. |
| 9314 | int NT = mExitingAppTokens.size(); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9315 | for (int j=0; j<NT; j++) { |
Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 9316 | i = reAddAppWindowsLocked(i, mExitingAppTokens.get(j)); |
| 9317 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9318 | |
Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 9319 | // And add in the still active app tokens in Z order. |
| 9320 | NT = mAppTokens.size(); |
| 9321 | for (int j=0; j<NT; j++) { |
| 9322 | i = reAddAppWindowsLocked(i, mAppTokens.get(j)); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9323 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9324 | |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9325 | i -= lastWallpaper; |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 9326 | if (i != numRemoved) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9327 | Slog.w(TAG, "Rebuild removed " + numRemoved |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 9328 | + " windows but added " + i); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 9329 | for (i=0; i<numRemoved; i++) { |
| 9330 | WindowState ws = mRebuildTmp[i]; |
| 9331 | if (ws.mRebuilding) { |
| 9332 | StringWriter sw = new StringWriter(); |
| 9333 | PrintWriter pw = new PrintWriter(sw); |
| 9334 | ws.dump(pw, ""); |
| 9335 | pw.flush(); |
| 9336 | Slog.w(TAG, "This window was lost: " + ws); |
| 9337 | Slog.w(TAG, sw.toString()); |
| 9338 | } |
| 9339 | } |
| 9340 | Slog.w(TAG, "Current app token list:"); |
| 9341 | dumpAppTokensLocked(); |
| 9342 | Slog.w(TAG, "Final window list:"); |
| 9343 | dumpWindowsLocked(); |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 9344 | } |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9345 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9346 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9347 | private final void assignLayersLocked() { |
| 9348 | int N = mWindows.size(); |
| 9349 | int curBaseLayer = 0; |
| 9350 | int curLayer = 0; |
| 9351 | int i; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9352 | |
Dianne Hackborn | 6c8e20f | 2010-11-09 18:59:09 -0800 | [diff] [blame] | 9353 | if (DEBUG_LAYERS) { |
| 9354 | RuntimeException here = new RuntimeException("here"); |
| 9355 | here.fillInStackTrace(); |
| 9356 | Log.v(TAG, "Assigning layers", here); |
| 9357 | } |
| 9358 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9359 | for (i=0; i<N; i++) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 9360 | WindowState w = mWindows.get(i); |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 9361 | if (w.mBaseLayer == curBaseLayer || w.mIsImWindow |
| 9362 | || (i > 0 && w.mIsWallpaper)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9363 | curLayer += WINDOW_LAYER_MULTIPLIER; |
| 9364 | w.mLayer = curLayer; |
| 9365 | } else { |
| 9366 | curBaseLayer = curLayer = w.mBaseLayer; |
| 9367 | w.mLayer = curLayer; |
| 9368 | } |
| 9369 | if (w.mTargetAppToken != null) { |
| 9370 | w.mAnimLayer = w.mLayer + w.mTargetAppToken.animLayerAdjustment; |
| 9371 | } else if (w.mAppToken != null) { |
| 9372 | w.mAnimLayer = w.mLayer + w.mAppToken.animLayerAdjustment; |
| 9373 | } else { |
| 9374 | w.mAnimLayer = w.mLayer; |
| 9375 | } |
| 9376 | if (w.mIsImWindow) { |
| 9377 | w.mAnimLayer += mInputMethodAnimLayerAdjustment; |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 9378 | } else if (w.mIsWallpaper) { |
| 9379 | w.mAnimLayer += mWallpaperAnimLayerAdjustment; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9380 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9381 | if (DEBUG_LAYERS) Slog.v(TAG, "Assign layer " + w + ": " |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9382 | + w.mAnimLayer); |
| 9383 | //System.out.println( |
| 9384 | // "Assigned layer " + curLayer + " to " + w.mClient.asBinder()); |
| 9385 | } |
| 9386 | } |
| 9387 | |
| 9388 | private boolean mInLayout = false; |
| 9389 | private final void performLayoutAndPlaceSurfacesLocked() { |
| 9390 | if (mInLayout) { |
Dave Bort | cfe6524 | 2009-04-09 14:51:04 -0700 | [diff] [blame] | 9391 | if (DEBUG) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9392 | throw new RuntimeException("Recursive call!"); |
| 9393 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9394 | Slog.w(TAG, "performLayoutAndPlaceSurfacesLocked called while in layout"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9395 | return; |
| 9396 | } |
| 9397 | |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 9398 | if (mWaitingForConfig) { |
| 9399 | // Our configuration has changed (most likely rotation), but we |
| 9400 | // don't yet have the complete configuration to report to |
| 9401 | // applications. Don't do any window layout until we have it. |
| 9402 | return; |
| 9403 | } |
| 9404 | |
Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 9405 | if (mDisplay == null) { |
| 9406 | // Not yet initialized, nothing to do. |
| 9407 | return; |
| 9408 | } |
| 9409 | |
Dianne Hackborn | 2e7ffa5 | 2011-01-12 13:21:28 -0800 | [diff] [blame] | 9410 | mInLayout = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9411 | boolean recoveringMemory = false; |
Dianne Hackborn | 2e7ffa5 | 2011-01-12 13:21:28 -0800 | [diff] [blame] | 9412 | |
| 9413 | try { |
| 9414 | if (mForceRemoves != null) { |
| 9415 | recoveringMemory = true; |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 9416 | // 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] | 9417 | for (int i=0; i<mForceRemoves.size(); i++) { |
| 9418 | WindowState ws = mForceRemoves.get(i); |
| 9419 | Slog.i(TAG, "Force removing: " + ws); |
| 9420 | removeWindowInnerLocked(ws.mSession, ws); |
| 9421 | } |
| 9422 | mForceRemoves = null; |
| 9423 | Slog.w(TAG, "Due to memory failure, waiting a bit for next layout"); |
| 9424 | Object tmp = new Object(); |
| 9425 | synchronized (tmp) { |
| 9426 | try { |
| 9427 | tmp.wait(250); |
| 9428 | } catch (InterruptedException e) { |
| 9429 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9430 | } |
| 9431 | } |
Dianne Hackborn | 2e7ffa5 | 2011-01-12 13:21:28 -0800 | [diff] [blame] | 9432 | } catch (RuntimeException e) { |
| 9433 | 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] | 9434 | } |
Dianne Hackborn | 2e7ffa5 | 2011-01-12 13:21:28 -0800 | [diff] [blame] | 9435 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9436 | try { |
| 9437 | performLayoutAndPlaceSurfacesLockedInner(recoveringMemory); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9438 | |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 9439 | int N = mPendingRemove.size(); |
| 9440 | if (N > 0) { |
| 9441 | if (mPendingRemoveTmp.length < N) { |
| 9442 | mPendingRemoveTmp = new WindowState[N+10]; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9443 | } |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 9444 | mPendingRemove.toArray(mPendingRemoveTmp); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9445 | mPendingRemove.clear(); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 9446 | for (int i=0; i<N; i++) { |
| 9447 | WindowState w = mPendingRemoveTmp[i]; |
| 9448 | removeWindowInnerLocked(w.mSession, w); |
| 9449 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9450 | |
| 9451 | mInLayout = false; |
| 9452 | assignLayersLocked(); |
| 9453 | mLayoutNeeded = true; |
| 9454 | performLayoutAndPlaceSurfacesLocked(); |
| 9455 | |
| 9456 | } else { |
| 9457 | mInLayout = false; |
| 9458 | if (mLayoutNeeded) { |
| 9459 | requestAnimationLocked(0); |
| 9460 | } |
| 9461 | } |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 9462 | if (mWindowsChanged && !mWindowChangeListeners.isEmpty()) { |
Konstantin Lopyrev | 6e0f65f | 2010-07-14 14:55:33 -0700 | [diff] [blame] | 9463 | mH.removeMessages(H.REPORT_WINDOWS_CHANGE); |
| 9464 | mH.sendMessage(mH.obtainMessage(H.REPORT_WINDOWS_CHANGE)); |
Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 9465 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9466 | } catch (RuntimeException e) { |
| 9467 | mInLayout = false; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9468 | 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] | 9469 | } |
| 9470 | } |
| 9471 | |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 9472 | private final int performLayoutLockedInner(boolean initial, boolean updateInputWindows) { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9473 | if (!mLayoutNeeded) { |
| 9474 | return 0; |
| 9475 | } |
| 9476 | |
| 9477 | mLayoutNeeded = false; |
| 9478 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9479 | final int dw = mDisplay.getWidth(); |
| 9480 | final int dh = mDisplay.getHeight(); |
| 9481 | |
| 9482 | final int N = mWindows.size(); |
| 9483 | int i; |
| 9484 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9485 | if (DEBUG_LAYOUT) Slog.v(TAG, "performLayout: needed=" |
Dianne Hackborn | 9b52a21 | 2009-12-11 14:51:35 -0800 | [diff] [blame] | 9486 | + mLayoutNeeded + " dw=" + dw + " dh=" + dh); |
| 9487 | |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9488 | mPolicy.beginLayoutLw(dw, dh); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9489 | |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9490 | int seq = mLayoutSeq+1; |
| 9491 | if (seq < 0) seq = 0; |
| 9492 | mLayoutSeq = seq; |
| 9493 | |
| 9494 | // First perform layout of any root windows (not attached |
| 9495 | // to another window). |
| 9496 | int topAttached = -1; |
| 9497 | for (i = N-1; i >= 0; i--) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 9498 | WindowState win = mWindows.get(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9499 | |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9500 | // Don't do layout of a window if it is not visible, or |
| 9501 | // soon won't be visible, to avoid wasting time and funky |
| 9502 | // changes while a window is animating away. |
| 9503 | final AppWindowToken atoken = win.mAppToken; |
| 9504 | final boolean gone = win.mViewVisibility == View.GONE |
| 9505 | || !win.mRelayoutCalled |
Dianne Hackborn | ff801ec | 2011-01-22 18:05:38 -0800 | [diff] [blame] | 9506 | || (atoken == null && win.mRootToken.hidden) |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9507 | || (atoken != null && atoken.hiddenRequested) |
| 9508 | || win.mAttachedHidden |
| 9509 | || win.mExiting || win.mDestroying; |
| 9510 | |
Dianne Hackborn | 1c24e95 | 2010-11-23 00:34:30 -0800 | [diff] [blame] | 9511 | if (DEBUG_LAYOUT && !win.mLayoutAttached) { |
| 9512 | Slog.v(TAG, "First pass " + win |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9513 | + ": gone=" + gone + " mHaveFrame=" + win.mHaveFrame |
| 9514 | + " mLayoutAttached=" + win.mLayoutAttached); |
Dianne Hackborn | 1c24e95 | 2010-11-23 00:34:30 -0800 | [diff] [blame] | 9515 | if (gone) Slog.v(TAG, " (mViewVisibility=" |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9516 | + win.mViewVisibility + " mRelayoutCalled=" |
| 9517 | + win.mRelayoutCalled + " hidden=" |
| 9518 | + win.mRootToken.hidden + " hiddenRequested=" |
| 9519 | + (atoken != null && atoken.hiddenRequested) |
| 9520 | + " mAttachedHidden=" + win.mAttachedHidden); |
| 9521 | } |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 9522 | |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9523 | // If this view is GONE, then skip it -- keep the current |
| 9524 | // frame, and let the caller know so they can ignore it |
| 9525 | // if they want. (We do the normal layout for INVISIBLE |
| 9526 | // windows, since that means "perform layout as normal, |
| 9527 | // just don't display"). |
| 9528 | if (!gone || !win.mHaveFrame) { |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 9529 | if (!win.mLayoutAttached) { |
Dianne Hackborn | 8e11ef0 | 2010-11-18 19:47:42 -0800 | [diff] [blame] | 9530 | if (initial) { |
Dianne Hackborn | 0f761d6 | 2010-11-30 22:06:10 -0800 | [diff] [blame] | 9531 | //Slog.i(TAG, "Window " + this + " clearing mContentChanged - initial"); |
Dianne Hackborn | 8e11ef0 | 2010-11-18 19:47:42 -0800 | [diff] [blame] | 9532 | win.mContentChanged = false; |
| 9533 | } |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9534 | mPolicy.layoutWindowLw(win, win.mAttrs, null); |
| 9535 | win.mLayoutSeq = seq; |
| 9536 | if (DEBUG_LAYOUT) Slog.v(TAG, "-> mFrame=" |
| 9537 | + win.mFrame + " mContainingFrame=" |
| 9538 | + win.mContainingFrame + " mDisplayFrame=" |
| 9539 | + win.mDisplayFrame); |
| 9540 | } else { |
| 9541 | if (topAttached < 0) topAttached = i; |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 9542 | } |
Dianne Hackborn | 958b9ad | 2009-03-31 18:00:36 -0700 | [diff] [blame] | 9543 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9544 | } |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9545 | |
| 9546 | // Now perform layout of attached windows, which usually |
| 9547 | // depend on the position of the window they are attached to. |
| 9548 | // XXX does not deal with windows that are attached to windows |
| 9549 | // that are themselves attached. |
| 9550 | for (i = topAttached; i >= 0; i--) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 9551 | WindowState win = mWindows.get(i); |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9552 | |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9553 | if (win.mLayoutAttached) { |
| 9554 | if (DEBUG_LAYOUT) Slog.v(TAG, "Second pass " + win |
| 9555 | + " mHaveFrame=" + win.mHaveFrame |
| 9556 | + " mViewVisibility=" + win.mViewVisibility |
| 9557 | + " mRelayoutCalled=" + win.mRelayoutCalled); |
Dianne Hackborn | 1c24e95 | 2010-11-23 00:34:30 -0800 | [diff] [blame] | 9558 | // If this view is GONE, then skip it -- keep the current |
| 9559 | // frame, and let the caller know so they can ignore it |
| 9560 | // if they want. (We do the normal layout for INVISIBLE |
| 9561 | // windows, since that means "perform layout as normal, |
| 9562 | // just don't display"). |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9563 | if ((win.mViewVisibility != View.GONE && win.mRelayoutCalled) |
| 9564 | || !win.mHaveFrame) { |
Dianne Hackborn | 8e11ef0 | 2010-11-18 19:47:42 -0800 | [diff] [blame] | 9565 | if (initial) { |
Dianne Hackborn | 0f761d6 | 2010-11-30 22:06:10 -0800 | [diff] [blame] | 9566 | //Slog.i(TAG, "Window " + this + " clearing mContentChanged - initial"); |
Dianne Hackborn | 8e11ef0 | 2010-11-18 19:47:42 -0800 | [diff] [blame] | 9567 | win.mContentChanged = false; |
| 9568 | } |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9569 | mPolicy.layoutWindowLw(win, win.mAttrs, win.mAttachedWindow); |
| 9570 | win.mLayoutSeq = seq; |
| 9571 | if (DEBUG_LAYOUT) Slog.v(TAG, "-> mFrame=" |
| 9572 | + win.mFrame + " mContainingFrame=" |
| 9573 | + win.mContainingFrame + " mDisplayFrame=" |
| 9574 | + win.mDisplayFrame); |
| 9575 | } |
| 9576 | } |
| 9577 | } |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 9578 | |
| 9579 | // Window frames may have changed. Tell the input dispatcher about it. |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 9580 | mInputMonitor.setUpdateInputWindowsNeededLw(); |
| 9581 | if (updateInputWindows) { |
Jeff Brown | 2e44b07 | 2011-01-24 15:21:56 -0800 | [diff] [blame^] | 9582 | mInputMonitor.updateInputWindowsLw(false /*force*/); |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 9583 | } |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9584 | |
| 9585 | return mPolicy.finishLayoutLw(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9586 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9587 | |
Brad Fitzpatrick | 6804433 | 2010-11-22 18:19:48 -0800 | [diff] [blame] | 9588 | // "Something has changed! Let's make it correct now." |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9589 | private final void performLayoutAndPlaceSurfacesLockedInner( |
| 9590 | boolean recoveringMemory) { |
Joe Onorato | 34bcebc | 2010-07-07 18:05:01 -0400 | [diff] [blame] | 9591 | if (mDisplay == null) { |
| 9592 | Slog.i(TAG, "skipping performLayoutAndPlaceSurfacesLockedInner with no mDisplay"); |
| 9593 | return; |
| 9594 | } |
| 9595 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9596 | final long currentTime = SystemClock.uptimeMillis(); |
| 9597 | final int dw = mDisplay.getWidth(); |
| 9598 | final int dh = mDisplay.getHeight(); |
| 9599 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9600 | int i; |
| 9601 | |
Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 9602 | if (mFocusMayChange) { |
| 9603 | mFocusMayChange = false; |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 9604 | updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES, |
| 9605 | false /*updateInputWindows*/); |
Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 9606 | } |
| 9607 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9608 | // Initialize state of exiting tokens. |
| 9609 | for (i=mExitingTokens.size()-1; i>=0; i--) { |
| 9610 | mExitingTokens.get(i).hasVisible = false; |
| 9611 | } |
| 9612 | |
| 9613 | // Initialize state of exiting applications. |
| 9614 | for (i=mExitingAppTokens.size()-1; i>=0; i--) { |
| 9615 | mExitingAppTokens.get(i).hasVisible = false; |
| 9616 | } |
| 9617 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9618 | boolean orientationChangeComplete = true; |
| 9619 | Session holdScreen = null; |
| 9620 | float screenBrightness = -1; |
Mike Lockwood | fb73f79 | 2009-11-20 11:31:18 -0500 | [diff] [blame] | 9621 | float buttonBrightness = -1; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9622 | boolean focusDisplayed = false; |
| 9623 | boolean animating = false; |
Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 9624 | boolean createWatermark = false; |
Dianne Hackborn | 89ba675 | 2011-01-23 16:51:16 -0800 | [diff] [blame] | 9625 | boolean updateRotation = false; |
Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 9626 | |
| 9627 | if (mFxSession == null) { |
| 9628 | mFxSession = new SurfaceSession(); |
| 9629 | createWatermark = true; |
| 9630 | } |
| 9631 | |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 9632 | if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION performLayoutAndPlaceSurfaces"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9633 | |
| 9634 | Surface.openTransaction(); |
Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 9635 | |
| 9636 | if (createWatermark) { |
| 9637 | createWatermark(); |
| 9638 | } |
| 9639 | if (mWatermark != null) { |
| 9640 | mWatermark.positionSurface(dw, dh); |
| 9641 | } |
Brad Fitzpatrick | 6804433 | 2010-11-22 18:19:48 -0800 | [diff] [blame] | 9642 | if (mStrictModeFlash != null) { |
| 9643 | mStrictModeFlash.positionSurface(dw, dh); |
| 9644 | } |
Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 9645 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9646 | try { |
Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 9647 | boolean wallpaperForceHidingChanged = false; |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9648 | int repeats = 0; |
| 9649 | int changes = 0; |
| 9650 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9651 | do { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9652 | repeats++; |
| 9653 | if (repeats > 6) { |
| 9654 | Slog.w(TAG, "Animation repeat aborted after too many iterations"); |
| 9655 | mLayoutNeeded = false; |
| 9656 | break; |
| 9657 | } |
| 9658 | |
| 9659 | if ((changes&(WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER |
| 9660 | | WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG |
| 9661 | | WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT)) != 0) { |
| 9662 | if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER) != 0) { |
| 9663 | if ((adjustWallpaperWindowsLocked()&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) { |
| 9664 | assignLayersLocked(); |
| 9665 | mLayoutNeeded = true; |
| 9666 | } |
| 9667 | } |
| 9668 | if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG) != 0) { |
| 9669 | if (DEBUG_LAYOUT) Slog.v(TAG, "Computing new config from layout"); |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 9670 | if (updateOrientationFromAppTokensLocked(true)) { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9671 | mLayoutNeeded = true; |
| 9672 | mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION); |
| 9673 | } |
| 9674 | } |
| 9675 | if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT) != 0) { |
| 9676 | mLayoutNeeded = true; |
| 9677 | } |
| 9678 | } |
| 9679 | |
| 9680 | // FIRST LOOP: Perform a layout, if needed. |
| 9681 | if (repeats < 4) { |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 9682 | changes = performLayoutLockedInner(repeats == 0, false /*updateInputWindows*/); |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9683 | if (changes != 0) { |
| 9684 | continue; |
| 9685 | } |
| 9686 | } else { |
| 9687 | Slog.w(TAG, "Layout repeat skipped after too many iterations"); |
| 9688 | changes = 0; |
| 9689 | } |
| 9690 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9691 | final int transactionSequence = ++mTransactionSequence; |
| 9692 | |
| 9693 | // Update animations of all applications, including those |
| 9694 | // associated with exiting/removed apps |
| 9695 | boolean tokensAnimating = false; |
| 9696 | final int NAT = mAppTokens.size(); |
| 9697 | for (i=0; i<NAT; i++) { |
| 9698 | if (mAppTokens.get(i).stepAnimationLocked(currentTime, dw, dh)) { |
| 9699 | tokensAnimating = true; |
| 9700 | } |
| 9701 | } |
| 9702 | final int NEAT = mExitingAppTokens.size(); |
| 9703 | for (i=0; i<NEAT; i++) { |
| 9704 | if (mExitingAppTokens.get(i).stepAnimationLocked(currentTime, dw, dh)) { |
| 9705 | tokensAnimating = true; |
| 9706 | } |
| 9707 | } |
| 9708 | |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9709 | // SECOND LOOP: Execute animations and update visibility of windows. |
| 9710 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9711 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "*** ANIM STEP: seq=" |
Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 9712 | + transactionSequence + " tokensAnimating=" |
| 9713 | + tokensAnimating); |
| 9714 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9715 | animating = tokensAnimating; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9716 | |
Dianne Hackborn | f9d0be9 | 2010-11-24 12:35:25 -0800 | [diff] [blame] | 9717 | if (mScreenRotationAnimation != null) { |
| 9718 | if (mScreenRotationAnimation.isAnimating()) { |
| 9719 | if (mScreenRotationAnimation.stepAnimation(currentTime)) { |
| 9720 | animating = true; |
| 9721 | } else { |
| 9722 | mScreenRotationAnimation = null; |
Dianne Hackborn | 89ba675 | 2011-01-23 16:51:16 -0800 | [diff] [blame] | 9723 | updateRotation = true; |
Dianne Hackborn | f9d0be9 | 2010-11-24 12:35:25 -0800 | [diff] [blame] | 9724 | } |
| 9725 | } |
| 9726 | } |
| 9727 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9728 | boolean tokenMayBeDrawn = false; |
Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 9729 | boolean wallpaperMayChange = false; |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9730 | boolean forceHiding = false; |
Dianne Hackborn | 6c8e20f | 2010-11-09 18:59:09 -0800 | [diff] [blame] | 9731 | WindowState windowDetachedWallpaper = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9732 | |
| 9733 | mPolicy.beginAnimationLw(dw, dh); |
| 9734 | |
Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 9735 | final int N = mWindows.size(); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9736 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9737 | for (i=N-1; i>=0; i--) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 9738 | WindowState w = mWindows.get(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9739 | |
| 9740 | final WindowManager.LayoutParams attrs = w.mAttrs; |
| 9741 | |
| 9742 | if (w.mSurface != null) { |
Dianne Hackborn | 8e11ef0 | 2010-11-18 19:47:42 -0800 | [diff] [blame] | 9743 | // Take care of the window being ready to display. |
Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 9744 | if (w.commitFinishDrawingLocked(currentTime)) { |
| 9745 | if ((w.mAttrs.flags |
| 9746 | & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER) != 0) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9747 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 9748 | "First draw done in potential wallpaper target " + w); |
Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 9749 | wallpaperMayChange = true; |
| 9750 | } |
| 9751 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9752 | |
Dianne Hackborn | 6c8e20f | 2010-11-09 18:59:09 -0800 | [diff] [blame] | 9753 | final boolean wasAnimating = w.mAnimating; |
Dianne Hackborn | 8e11ef0 | 2010-11-18 19:47:42 -0800 | [diff] [blame] | 9754 | |
| 9755 | int animDw = dw; |
| 9756 | int animDh = dh; |
| 9757 | |
| 9758 | // If the window has moved due to its containing |
| 9759 | // content frame changing, then we'd like to animate |
| 9760 | // it. The checks here are ordered by what is least |
Joe Onorato | 3fe7f2f | 2010-11-20 13:48:58 -0800 | [diff] [blame] | 9761 | // likely to be true first. |
Dianne Hackborn | 1c24e95 | 2010-11-23 00:34:30 -0800 | [diff] [blame] | 9762 | if (w.shouldAnimateMove()) { |
Dianne Hackborn | 8e11ef0 | 2010-11-18 19:47:42 -0800 | [diff] [blame] | 9763 | // Frame has moved, containing content frame |
| 9764 | // has also moved, and we're not currently animating... |
| 9765 | // let's do something. |
| 9766 | Animation a = AnimationUtils.loadAnimation(mContext, |
| 9767 | com.android.internal.R.anim.window_move_from_decor); |
| 9768 | w.setAnimation(a); |
| 9769 | animDw = w.mLastFrame.left - w.mFrame.left; |
| 9770 | animDh = w.mLastFrame.top - w.mFrame.top; |
| 9771 | } |
| 9772 | |
| 9773 | // Execute animation. |
| 9774 | final boolean nowAnimating = w.stepAnimationLocked(currentTime, |
| 9775 | animDw, animDh); |
Dianne Hackborn | 6c8e20f | 2010-11-09 18:59:09 -0800 | [diff] [blame] | 9776 | |
| 9777 | // If this window is animating, make a note that we have |
| 9778 | // an animating window and take care of a request to run |
| 9779 | // a detached wallpaper animation. |
| 9780 | if (nowAnimating) { |
| 9781 | if (w.mAnimation != null && w.mAnimation.getDetachWallpaper()) { |
| 9782 | windowDetachedWallpaper = w; |
| 9783 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9784 | animating = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9785 | } |
Dianne Hackborn | 6c8e20f | 2010-11-09 18:59:09 -0800 | [diff] [blame] | 9786 | |
| 9787 | // If this window's app token is running a detached wallpaper |
| 9788 | // animation, make a note so we can ensure the wallpaper is |
| 9789 | // displayed behind it. |
| 9790 | if (w.mAppToken != null && w.mAppToken.animation != null |
| 9791 | && w.mAppToken.animation.getDetachWallpaper()) { |
| 9792 | windowDetachedWallpaper = w; |
| 9793 | } |
| 9794 | |
Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 9795 | if (wasAnimating && !w.mAnimating && mWallpaperTarget == w) { |
| 9796 | wallpaperMayChange = true; |
| 9797 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9798 | |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9799 | if (mPolicy.doesForceHide(w, attrs)) { |
Dianne Hackborn | 6c8e20f | 2010-11-09 18:59:09 -0800 | [diff] [blame] | 9800 | if (!wasAnimating && nowAnimating) { |
Dianne Hackborn | 20cb56e | 2010-03-04 00:58:29 -0800 | [diff] [blame] | 9801 | if (DEBUG_VISIBILITY) Slog.v(TAG, |
Dianne Hackborn | 6c8e20f | 2010-11-09 18:59:09 -0800 | [diff] [blame] | 9802 | "Animation started that could impact force hide: " |
Dianne Hackborn | 20cb56e | 2010-03-04 00:58:29 -0800 | [diff] [blame] | 9803 | + w); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9804 | wallpaperForceHidingChanged = true; |
Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 9805 | mFocusMayChange = true; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9806 | } else if (w.isReadyForDisplay() && w.mAnimation == null) { |
| 9807 | forceHiding = true; |
| 9808 | } |
| 9809 | } else if (mPolicy.canBeForceHidden(w, attrs)) { |
| 9810 | boolean changed; |
| 9811 | if (forceHiding) { |
| 9812 | changed = w.hideLw(false, false); |
Dianne Hackborn | 20cb56e | 2010-03-04 00:58:29 -0800 | [diff] [blame] | 9813 | if (DEBUG_VISIBILITY && changed) Slog.v(TAG, |
| 9814 | "Now policy hidden: " + w); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9815 | } else { |
| 9816 | changed = w.showLw(false, false); |
Dianne Hackborn | 20cb56e | 2010-03-04 00:58:29 -0800 | [diff] [blame] | 9817 | if (DEBUG_VISIBILITY && changed) Slog.v(TAG, |
| 9818 | "Now policy shown: " + w); |
| 9819 | if (changed) { |
| 9820 | if (wallpaperForceHidingChanged |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9821 | && w.isVisibleNow() /*w.isReadyForDisplay()*/) { |
Dianne Hackborn | 20cb56e | 2010-03-04 00:58:29 -0800 | [diff] [blame] | 9822 | // Assume we will need to animate. If |
| 9823 | // we don't (because the wallpaper will |
| 9824 | // stay with the lock screen), then we will |
| 9825 | // clean up later. |
| 9826 | Animation a = mPolicy.createForceHideEnterAnimation(); |
| 9827 | if (a != null) { |
| 9828 | w.setAnimation(a); |
| 9829 | } |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9830 | } |
Dianne Hackborn | 20cb56e | 2010-03-04 00:58:29 -0800 | [diff] [blame] | 9831 | if (mCurrentFocus == null || |
| 9832 | mCurrentFocus.mLayer < w.mLayer) { |
| 9833 | // We are showing on to of the current |
| 9834 | // focus, so re-evaluate focus to make |
| 9835 | // sure it is correct. |
| 9836 | mFocusMayChange = true; |
| 9837 | } |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9838 | } |
| 9839 | } |
| 9840 | if (changed && (attrs.flags |
| 9841 | & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER) != 0) { |
| 9842 | wallpaperMayChange = true; |
| 9843 | } |
| 9844 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9845 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9846 | mPolicy.animatingWindowLw(w, attrs); |
| 9847 | } |
| 9848 | |
| 9849 | final AppWindowToken atoken = w.mAppToken; |
| 9850 | if (atoken != null && (!atoken.allDrawn || atoken.freezingScreen)) { |
| 9851 | if (atoken.lastTransactionSequence != transactionSequence) { |
| 9852 | atoken.lastTransactionSequence = transactionSequence; |
| 9853 | atoken.numInterestingWindows = atoken.numDrawnWindows = 0; |
| 9854 | atoken.startingDisplayed = false; |
| 9855 | } |
| 9856 | if ((w.isOnScreen() || w.mAttrs.type |
| 9857 | == WindowManager.LayoutParams.TYPE_BASE_APPLICATION) |
| 9858 | && !w.mExiting && !w.mDestroying) { |
| 9859 | if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9860 | Slog.v(TAG, "Eval win " + w + ": isDrawn=" |
Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 9861 | + w.isDrawnLw() |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9862 | + ", isAnimating=" + w.isAnimating()); |
Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 9863 | if (!w.isDrawnLw()) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9864 | Slog.v(TAG, "Not displayed: s=" + w.mSurface |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9865 | + " pv=" + w.mPolicyVisibility |
| 9866 | + " dp=" + w.mDrawPending |
| 9867 | + " cdp=" + w.mCommitDrawPending |
| 9868 | + " ah=" + w.mAttachedHidden |
| 9869 | + " th=" + atoken.hiddenRequested |
| 9870 | + " a=" + w.mAnimating); |
| 9871 | } |
| 9872 | } |
| 9873 | if (w != atoken.startingWindow) { |
| 9874 | if (!atoken.freezingScreen || !w.mAppFreezing) { |
| 9875 | atoken.numInterestingWindows++; |
Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 9876 | if (w.isDrawnLw()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9877 | atoken.numDrawnWindows++; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9878 | if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9879 | "tokenMayBeDrawn: " + atoken |
| 9880 | + " freezingScreen=" + atoken.freezingScreen |
| 9881 | + " mAppFreezing=" + w.mAppFreezing); |
| 9882 | tokenMayBeDrawn = true; |
| 9883 | } |
| 9884 | } |
Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 9885 | } else if (w.isDrawnLw()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9886 | atoken.startingDisplayed = true; |
| 9887 | } |
| 9888 | } |
| 9889 | } else if (w.mReadyToShow) { |
| 9890 | w.performShowLocked(); |
| 9891 | } |
| 9892 | } |
| 9893 | |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9894 | changes |= mPolicy.finishAnimationLw(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9895 | |
| 9896 | if (tokenMayBeDrawn) { |
| 9897 | // See if any windows have been drawn, so they (and others |
| 9898 | // associated with them) can now be shown. |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 9899 | final int NT = mAppTokens.size(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9900 | for (i=0; i<NT; i++) { |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 9901 | AppWindowToken wtoken = mAppTokens.get(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9902 | if (wtoken.freezingScreen) { |
| 9903 | int numInteresting = wtoken.numInterestingWindows; |
| 9904 | if (numInteresting > 0 && wtoken.numDrawnWindows >= numInteresting) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9905 | if (DEBUG_VISIBILITY) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9906 | "allDrawn: " + wtoken |
| 9907 | + " interesting=" + numInteresting |
| 9908 | + " drawn=" + wtoken.numDrawnWindows); |
| 9909 | wtoken.showAllWindowsLocked(); |
| 9910 | unsetAppFreezingScreenLocked(wtoken, false, true); |
| 9911 | orientationChangeComplete = true; |
| 9912 | } |
| 9913 | } else if (!wtoken.allDrawn) { |
| 9914 | int numInteresting = wtoken.numInterestingWindows; |
| 9915 | if (numInteresting > 0 && wtoken.numDrawnWindows >= numInteresting) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9916 | if (DEBUG_VISIBILITY) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9917 | "allDrawn: " + wtoken |
| 9918 | + " interesting=" + numInteresting |
| 9919 | + " drawn=" + wtoken.numDrawnWindows); |
| 9920 | wtoken.allDrawn = true; |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9921 | changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9922 | |
| 9923 | // We can now show all of the drawn windows! |
| 9924 | if (!mOpeningApps.contains(wtoken)) { |
| 9925 | wtoken.showAllWindowsLocked(); |
| 9926 | } |
| 9927 | } |
| 9928 | } |
| 9929 | } |
| 9930 | } |
| 9931 | |
| 9932 | // If we are ready to perform an app transition, check through |
| 9933 | // all of the app tokens to be shown and see if they are ready |
| 9934 | // to go. |
| 9935 | if (mAppTransitionReady) { |
| 9936 | int NN = mOpeningApps.size(); |
| 9937 | boolean goodToGo = true; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9938 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9939 | "Checking " + NN + " opening apps (frozen=" |
| 9940 | + mDisplayFrozen + " timeout=" |
| 9941 | + mAppTransitionTimeout + ")..."); |
| 9942 | if (!mDisplayFrozen && !mAppTransitionTimeout) { |
| 9943 | // If the display isn't frozen, wait to do anything until |
| 9944 | // all of the apps are ready. Otherwise just go because |
| 9945 | // we'll unfreeze the display when everyone is ready. |
| 9946 | for (i=0; i<NN && goodToGo; i++) { |
| 9947 | AppWindowToken wtoken = mOpeningApps.get(i); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9948 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9949 | "Check opening app" + wtoken + ": allDrawn=" |
| 9950 | + wtoken.allDrawn + " startingDisplayed=" |
| 9951 | + wtoken.startingDisplayed); |
| 9952 | if (!wtoken.allDrawn && !wtoken.startingDisplayed |
| 9953 | && !wtoken.startingMoved) { |
| 9954 | goodToGo = false; |
| 9955 | } |
| 9956 | } |
| 9957 | } |
| 9958 | if (goodToGo) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9959 | 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] | 9960 | int transit = mNextAppTransition; |
| 9961 | if (mSkipAppTransitionAnimation) { |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 9962 | transit = WindowManagerPolicy.TRANSIT_UNSET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9963 | } |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 9964 | mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9965 | mAppTransitionReady = false; |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9966 | mAppTransitionRunning = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9967 | mAppTransitionTimeout = false; |
| 9968 | mStartingIconInTransition = false; |
| 9969 | mSkipAppTransitionAnimation = false; |
| 9970 | |
| 9971 | mH.removeMessages(H.APP_TRANSITION_TIMEOUT); |
| 9972 | |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9973 | // If there are applications waiting to come to the |
| 9974 | // top of the stack, now is the time to move their windows. |
| 9975 | // (Note that we don't do apps going to the bottom |
| 9976 | // here -- we want to keep their windows in the old |
| 9977 | // Z-order until the animation completes.) |
| 9978 | if (mToTopApps.size() > 0) { |
| 9979 | NN = mAppTokens.size(); |
| 9980 | for (i=0; i<NN; i++) { |
| 9981 | AppWindowToken wtoken = mAppTokens.get(i); |
| 9982 | if (wtoken.sendingToTop) { |
| 9983 | wtoken.sendingToTop = false; |
| 9984 | moveAppWindowsLocked(wtoken, NN, false); |
| 9985 | } |
| 9986 | } |
| 9987 | mToTopApps.clear(); |
| 9988 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9989 | |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 9990 | WindowState oldWallpaper = mWallpaperTarget; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9991 | |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 9992 | adjustWallpaperWindowsLocked(); |
Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 9993 | wallpaperMayChange = false; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9994 | |
Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 9995 | // The top-most window will supply the layout params, |
| 9996 | // and we will determine it below. |
| 9997 | LayoutParams animLp = null; |
| 9998 | int bestAnimLayer = -1; |
Dianne Hackborn | 08121bc | 2011-01-17 17:54:31 -0800 | [diff] [blame] | 9999 | boolean fullscreenAnim = false; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10000 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10001 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 10002 | "New wallpaper target=" + mWallpaperTarget |
| 10003 | + ", lower target=" + mLowerWallpaperTarget |
| 10004 | + ", upper target=" + mUpperWallpaperTarget); |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 10005 | int foundWallpapers = 0; |
Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 10006 | // Do a first pass through the tokens for two |
| 10007 | // things: |
| 10008 | // (1) Determine if both the closing and opening |
| 10009 | // app token sets are wallpaper targets, in which |
| 10010 | // case special animations are needed |
| 10011 | // (since the wallpaper needs to stay static |
| 10012 | // behind them). |
| 10013 | // (2) Find the layout params of the top-most |
| 10014 | // application window in the tokens, which is |
| 10015 | // what will control the animation theme. |
| 10016 | final int NC = mClosingApps.size(); |
| 10017 | NN = NC + mOpeningApps.size(); |
| 10018 | for (i=0; i<NN; i++) { |
| 10019 | AppWindowToken wtoken; |
| 10020 | int mode; |
| 10021 | if (i < NC) { |
| 10022 | wtoken = mClosingApps.get(i); |
| 10023 | mode = 1; |
| 10024 | } else { |
| 10025 | wtoken = mOpeningApps.get(i-NC); |
| 10026 | mode = 2; |
| 10027 | } |
| 10028 | if (mLowerWallpaperTarget != null) { |
| 10029 | if (mLowerWallpaperTarget.mAppToken == wtoken |
| 10030 | || mUpperWallpaperTarget.mAppToken == wtoken) { |
| 10031 | foundWallpapers |= mode; |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 10032 | } |
| 10033 | } |
Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 10034 | if (wtoken.appFullscreen) { |
| 10035 | WindowState ws = wtoken.findMainWindow(); |
| 10036 | if (ws != null) { |
| 10037 | // If this is a compatibility mode |
| 10038 | // window, we will always use its anim. |
| 10039 | if ((ws.mAttrs.flags&FLAG_COMPATIBLE_WINDOW) != 0) { |
| 10040 | animLp = ws.mAttrs; |
| 10041 | bestAnimLayer = Integer.MAX_VALUE; |
Dianne Hackborn | 08121bc | 2011-01-17 17:54:31 -0800 | [diff] [blame] | 10042 | } else if (!fullscreenAnim || ws.mLayer > bestAnimLayer) { |
Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 10043 | animLp = ws.mAttrs; |
Dianne Hackborn | 08121bc | 2011-01-17 17:54:31 -0800 | [diff] [blame] | 10044 | bestAnimLayer = ws.mLayer; |
| 10045 | } |
| 10046 | fullscreenAnim = true; |
| 10047 | } |
| 10048 | } else if (!fullscreenAnim) { |
| 10049 | WindowState ws = wtoken.findMainWindow(); |
| 10050 | if (ws != null) { |
| 10051 | if (ws.mLayer > bestAnimLayer) { |
| 10052 | animLp = ws.mAttrs; |
Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 10053 | bestAnimLayer = ws.mLayer; |
| 10054 | } |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 10055 | } |
Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 10056 | } |
| 10057 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10058 | |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 10059 | if (foundWallpapers == 3) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10060 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 10061 | "Wallpaper animation!"); |
| 10062 | switch (transit) { |
| 10063 | case WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN: |
| 10064 | case WindowManagerPolicy.TRANSIT_TASK_OPEN: |
| 10065 | case WindowManagerPolicy.TRANSIT_TASK_TO_FRONT: |
| 10066 | transit = WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_OPEN; |
| 10067 | break; |
| 10068 | case WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE: |
| 10069 | case WindowManagerPolicy.TRANSIT_TASK_CLOSE: |
| 10070 | case WindowManagerPolicy.TRANSIT_TASK_TO_BACK: |
| 10071 | transit = WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_CLOSE; |
| 10072 | break; |
| 10073 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10074 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 10075 | "New transit: " + transit); |
| 10076 | } else if (oldWallpaper != null) { |
| 10077 | // We are transitioning from an activity with |
| 10078 | // a wallpaper to one without. |
| 10079 | transit = WindowManagerPolicy.TRANSIT_WALLPAPER_CLOSE; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10080 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 10081 | "New transit away from wallpaper: " + transit); |
| 10082 | } else if (mWallpaperTarget != null) { |
| 10083 | // We are transitioning from an activity without |
| 10084 | // a wallpaper to now showing the wallpaper |
| 10085 | transit = WindowManagerPolicy.TRANSIT_WALLPAPER_OPEN; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10086 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 10087 | "New transit into wallpaper: " + transit); |
| 10088 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10089 | |
Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 10090 | // If all closing windows are obscured, then there is |
| 10091 | // no need to do an animation. This is the case, for |
| 10092 | // example, when this transition is being done behind |
| 10093 | // the lock screen. |
| 10094 | if (!mPolicy.allowAppAnimationsLw()) { |
| 10095 | animLp = null; |
| 10096 | } |
| 10097 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10098 | NN = mOpeningApps.size(); |
| 10099 | for (i=0; i<NN; i++) { |
| 10100 | AppWindowToken wtoken = mOpeningApps.get(i); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10101 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10102 | "Now opening app" + wtoken); |
| 10103 | wtoken.reportedVisible = false; |
| 10104 | wtoken.inPendingTransaction = false; |
Dianne Hackborn | 83360b3 | 2009-08-24 18:43:32 -0700 | [diff] [blame] | 10105 | wtoken.animation = null; |
Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 10106 | setTokenVisibilityLocked(wtoken, animLp, true, transit, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10107 | wtoken.updateReportedVisibilityLocked(); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 10108 | wtoken.waitingToShow = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10109 | wtoken.showAllWindowsLocked(); |
| 10110 | } |
| 10111 | NN = mClosingApps.size(); |
| 10112 | for (i=0; i<NN; i++) { |
| 10113 | AppWindowToken wtoken = mClosingApps.get(i); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10114 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10115 | "Now closing app" + wtoken); |
| 10116 | wtoken.inPendingTransaction = false; |
Dianne Hackborn | 83360b3 | 2009-08-24 18:43:32 -0700 | [diff] [blame] | 10117 | wtoken.animation = null; |
Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 10118 | setTokenVisibilityLocked(wtoken, animLp, false, transit, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10119 | wtoken.updateReportedVisibilityLocked(); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 10120 | wtoken.waitingToHide = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10121 | // Force the allDrawn flag, because we want to start |
| 10122 | // this guy's animations regardless of whether it's |
| 10123 | // gotten drawn. |
| 10124 | wtoken.allDrawn = true; |
| 10125 | } |
| 10126 | |
Dianne Hackborn | 8b571a8 | 2009-09-25 16:09:43 -0700 | [diff] [blame] | 10127 | mNextAppTransitionPackage = null; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10128 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10129 | mOpeningApps.clear(); |
| 10130 | mClosingApps.clear(); |
| 10131 | |
| 10132 | // This has changed the visibility of windows, so perform |
| 10133 | // a new layout to get them all up-to-date. |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 10134 | changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT |
| 10135 | | WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10136 | mLayoutNeeded = true; |
Dianne Hackborn | 20583ff | 2009-07-27 21:51:05 -0700 | [diff] [blame] | 10137 | if (!moveInputMethodWindowsIfNeededLocked(true)) { |
| 10138 | assignLayersLocked(); |
| 10139 | } |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 10140 | updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES, |
| 10141 | false /*updateInputWindows*/); |
Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 10142 | mFocusMayChange = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10143 | } |
| 10144 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10145 | |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 10146 | int adjResult = 0; |
| 10147 | |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 10148 | if (!animating && mAppTransitionRunning) { |
| 10149 | // We have finished the animation of an app transition. To do |
| 10150 | // this, we have delayed a lot of operations like showing and |
| 10151 | // hiding apps, moving apps in Z-order, etc. The app token list |
| 10152 | // reflects the correct Z-order, but the window list may now |
| 10153 | // be out of sync with it. So here we will just rebuild the |
| 10154 | // entire app window list. Fun! |
| 10155 | mAppTransitionRunning = false; |
| 10156 | // Clear information about apps that were moving. |
| 10157 | mToBottomApps.clear(); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10158 | |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 10159 | rebuildAppWindowListLocked(); |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 10160 | changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT; |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 10161 | adjResult |= ADJUST_WALLPAPER_LAYERS_CHANGED; |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 10162 | moveInputMethodWindowsIfNeededLocked(false); |
| 10163 | wallpaperMayChange = true; |
Suchi Amalapurapu | c9568e3 | 2009-11-05 18:51:16 -0800 | [diff] [blame] | 10164 | // Since the window list has been rebuilt, focus might |
| 10165 | // have to be recomputed since the actual order of windows |
| 10166 | // might have changed again. |
Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 10167 | mFocusMayChange = true; |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 10168 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10169 | |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 10170 | if (wallpaperForceHidingChanged && changes == 0 && !mAppTransitionReady) { |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10171 | // At this point, there was a window with a wallpaper that |
| 10172 | // was force hiding other windows behind it, but now it |
| 10173 | // is going away. This may be simple -- just animate |
| 10174 | // away the wallpaper and its window -- or it may be |
| 10175 | // hard -- the wallpaper now needs to be shown behind |
| 10176 | // something that was hidden. |
| 10177 | WindowState oldWallpaper = mWallpaperTarget; |
Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 10178 | if (mLowerWallpaperTarget != null |
| 10179 | && mLowerWallpaperTarget.mAppToken != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10180 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 10181 | "wallpaperForceHiding changed with lower=" |
| 10182 | + mLowerWallpaperTarget); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10183 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 10184 | "hidden=" + mLowerWallpaperTarget.mAppToken.hidden + |
| 10185 | " hiddenRequested=" + mLowerWallpaperTarget.mAppToken.hiddenRequested); |
| 10186 | if (mLowerWallpaperTarget.mAppToken.hidden) { |
| 10187 | // The lower target has become hidden before we |
| 10188 | // actually started the animation... let's completely |
| 10189 | // re-evaluate everything. |
| 10190 | mLowerWallpaperTarget = mUpperWallpaperTarget = null; |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 10191 | changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM; |
Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 10192 | } |
| 10193 | } |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 10194 | adjResult |= adjustWallpaperWindowsLocked(); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10195 | wallpaperMayChange = false; |
Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 10196 | wallpaperForceHidingChanged = false; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10197 | if (DEBUG_WALLPAPER) Slog.v(TAG, "****** OLD: " + oldWallpaper |
Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 10198 | + " NEW: " + mWallpaperTarget |
| 10199 | + " LOWER: " + mLowerWallpaperTarget); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10200 | if (mLowerWallpaperTarget == null) { |
| 10201 | // Whoops, we don't need a special wallpaper animation. |
| 10202 | // Clear them out. |
| 10203 | forceHiding = false; |
| 10204 | for (i=N-1; i>=0; i--) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 10205 | WindowState w = mWindows.get(i); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10206 | if (w.mSurface != null) { |
| 10207 | final WindowManager.LayoutParams attrs = w.mAttrs; |
Suchi Amalapurapu | c03d28b | 2009-10-28 14:32:05 -0700 | [diff] [blame] | 10208 | if (mPolicy.doesForceHide(w, attrs) && w.isVisibleLw()) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10209 | if (DEBUG_FOCUS) Slog.i(TAG, "win=" + w + " force hides other windows"); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10210 | forceHiding = true; |
| 10211 | } else if (mPolicy.canBeForceHidden(w, attrs)) { |
| 10212 | if (!w.mAnimating) { |
| 10213 | // We set the animation above so it |
| 10214 | // is not yet running. |
| 10215 | w.clearAnimation(); |
| 10216 | } |
| 10217 | } |
| 10218 | } |
| 10219 | } |
| 10220 | } |
| 10221 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10222 | |
Dianne Hackborn | 6c8e20f | 2010-11-09 18:59:09 -0800 | [diff] [blame] | 10223 | if (mWindowDetachedWallpaper != windowDetachedWallpaper) { |
| 10224 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
| 10225 | "Detached wallpaper changed from " + mWindowDetachedWallpaper |
| 10226 | + windowDetachedWallpaper); |
| 10227 | mWindowDetachedWallpaper = windowDetachedWallpaper; |
| 10228 | wallpaperMayChange = true; |
| 10229 | } |
| 10230 | |
Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 10231 | if (wallpaperMayChange) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10232 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 10233 | "Wallpaper may change! Adjusting"); |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 10234 | adjResult |= adjustWallpaperWindowsLocked(); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10235 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10236 | |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10237 | if ((adjResult&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10238 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10239 | "Wallpaper layer changed: assigning layers + relayout"); |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 10240 | changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10241 | assignLayersLocked(); |
| 10242 | } else if ((adjResult&ADJUST_WALLPAPER_VISIBILITY_CHANGED) != 0) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10243 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10244 | "Wallpaper visibility changed: relayout"); |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 10245 | changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10246 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10247 | |
Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 10248 | if (mFocusMayChange) { |
| 10249 | mFocusMayChange = false; |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 10250 | if (updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES, |
| 10251 | false /*updateInputWindows*/)) { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 10252 | changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10253 | adjResult = 0; |
Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 10254 | } |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10255 | } |
| 10256 | |
| 10257 | if (mLayoutNeeded) { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 10258 | changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT; |
Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 10259 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10260 | |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 10261 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "*** ANIM STEP: changes=0x" |
| 10262 | + Integer.toHexString(changes)); |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 10263 | } while (changes != 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10264 | |
| 10265 | // THIRD LOOP: Update the surfaces of all windows. |
| 10266 | |
| 10267 | final boolean someoneLosingFocus = mLosingFocus.size() != 0; |
| 10268 | |
| 10269 | boolean obscured = false; |
| 10270 | boolean blurring = false; |
| 10271 | boolean dimming = false; |
| 10272 | boolean covered = false; |
Dianne Hackborn | 9ed4a4b | 2009-03-25 17:10:37 -0700 | [diff] [blame] | 10273 | boolean syswin = false; |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 10274 | boolean backgroundFillerShown = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10275 | |
Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 10276 | final int N = mWindows.size(); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10277 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10278 | for (i=N-1; i>=0; i--) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 10279 | WindowState w = mWindows.get(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10280 | |
| 10281 | boolean displayed = false; |
| 10282 | final WindowManager.LayoutParams attrs = w.mAttrs; |
| 10283 | final int attrFlags = attrs.flags; |
| 10284 | |
| 10285 | if (w.mSurface != null) { |
Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 10286 | // XXX NOTE: The logic here could be improved. We have |
| 10287 | // the decision about whether to resize a window separated |
| 10288 | // from whether to hide the surface. This can cause us to |
| 10289 | // resize a surface even if we are going to hide it. You |
| 10290 | // can see this by (1) holding device in landscape mode on |
| 10291 | // home screen; (2) tapping browser icon (device will rotate |
| 10292 | // to landscape; (3) tap home. The wallpaper will be resized |
| 10293 | // in step 2 but then immediately hidden, causing us to |
| 10294 | // have to resize and then redraw it again in step 3. It |
| 10295 | // would be nice to figure out how to avoid this, but it is |
| 10296 | // difficult because we do need to resize surfaces in some |
| 10297 | // cases while they are hidden such as when first showing a |
| 10298 | // window. |
| 10299 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10300 | w.computeShownFrameLocked(); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10301 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10302 | TAG, "Placing surface #" + i + " " + w.mSurface |
| 10303 | + ": new=" + w.mShownFrame + ", old=" |
| 10304 | + w.mLastShownFrame); |
| 10305 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10306 | int width, height; |
| 10307 | if ((w.mAttrs.flags & w.mAttrs.FLAG_SCALED) != 0) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10308 | // for a scaled surface, we just want to use |
| 10309 | // the requested size. |
| 10310 | width = w.mRequestedWidth; |
| 10311 | height = w.mRequestedHeight; |
| 10312 | w.mLastRequestedWidth = width; |
| 10313 | w.mLastRequestedHeight = height; |
| 10314 | w.mLastShownFrame.set(w.mShownFrame); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10315 | } else { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10316 | width = w.mShownFrame.width(); |
| 10317 | height = w.mShownFrame.height(); |
| 10318 | w.mLastShownFrame.set(w.mShownFrame); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10319 | } |
| 10320 | |
Jeff Brown | fbae722 | 2011-01-23 13:07:25 -0800 | [diff] [blame] | 10321 | if (w.mSurface != null) { |
| 10322 | if (w.mSurfaceX != w.mShownFrame.left |
| 10323 | || w.mSurfaceY != w.mShownFrame.top) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10324 | try { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 10325 | if (SHOW_TRANSACTIONS) logSurface(w, |
Jeff Brown | fbae722 | 2011-01-23 13:07:25 -0800 | [diff] [blame] | 10326 | "POS " + w.mShownFrame.left |
| 10327 | + ", " + w.mShownFrame.top, null); |
| 10328 | w.mSurfaceX = w.mShownFrame.left; |
| 10329 | w.mSurfaceY = w.mShownFrame.top; |
| 10330 | w.mSurface.setPosition(w.mShownFrame.left, w.mShownFrame.top); |
| 10331 | } catch (RuntimeException e) { |
| 10332 | Slog.w(TAG, "Error positioning surface of " + w |
| 10333 | + " pos=(" + w.mShownFrame.left |
| 10334 | + "," + w.mShownFrame.top + ")", e); |
| 10335 | if (!recoveringMemory) { |
| 10336 | reclaimSomeSurfaceMemoryLocked(w, "position"); |
| 10337 | } |
| 10338 | } |
| 10339 | } |
| 10340 | |
| 10341 | if (width < 1) { |
| 10342 | width = 1; |
| 10343 | } |
| 10344 | if (height < 1) { |
| 10345 | height = 1; |
| 10346 | } |
| 10347 | |
| 10348 | if (w.mSurfaceW != width || w.mSurfaceH != height) { |
| 10349 | try { |
| 10350 | if (SHOW_TRANSACTIONS) logSurface(w, |
| 10351 | "SIZE " + w.mShownFrame.width() + "x" |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 10352 | + w.mShownFrame.height(), null); |
Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 10353 | w.mSurfaceResized = true; |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 10354 | w.mSurfaceW = width; |
| 10355 | w.mSurfaceH = height; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10356 | w.mSurface.setSize(width, height); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10357 | } catch (RuntimeException e) { |
| 10358 | // If something goes wrong with the surface (such |
| 10359 | // as running out of memory), don't take down the |
| 10360 | // entire system. |
Jeff Brown | fbae722 | 2011-01-23 13:07:25 -0800 | [diff] [blame] | 10361 | Slog.e(TAG, "Error resizing surface of " + w |
| 10362 | + " size=(" + width + "x" + height + ")", e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10363 | if (!recoveringMemory) { |
| 10364 | reclaimSomeSurfaceMemoryLocked(w, "size"); |
| 10365 | } |
| 10366 | } |
| 10367 | } |
| 10368 | } |
Jeff Brown | fbae722 | 2011-01-23 13:07:25 -0800 | [diff] [blame] | 10369 | |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 10370 | if (!w.mAppFreezing && w.mLayoutSeq == mLayoutSeq) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10371 | w.mContentInsetsChanged = |
| 10372 | !w.mLastContentInsets.equals(w.mContentInsets); |
| 10373 | w.mVisibleInsetsChanged = |
| 10374 | !w.mLastVisibleInsets.equals(w.mVisibleInsets); |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 10375 | boolean configChanged = |
| 10376 | w.mConfiguration != mCurConfiguration |
| 10377 | && (w.mConfiguration == null |
| 10378 | || mCurConfiguration.diff(w.mConfiguration) != 0); |
Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 10379 | if (DEBUG_CONFIGURATION && configChanged) { |
| 10380 | Slog.v(TAG, "Win " + w + " config changed: " |
| 10381 | + mCurConfiguration); |
| 10382 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10383 | if (localLOGV) Slog.v(TAG, "Resizing " + w |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 10384 | + ": configChanged=" + configChanged |
| 10385 | + " last=" + w.mLastFrame + " frame=" + w.mFrame); |
Jeff Brown | fbae722 | 2011-01-23 13:07:25 -0800 | [diff] [blame] | 10386 | boolean frameChanged = !w.mLastFrame.equals(w.mFrame); |
| 10387 | if (frameChanged |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10388 | || w.mContentInsetsChanged |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 10389 | || w.mVisibleInsetsChanged |
Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 10390 | || w.mSurfaceResized |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 10391 | || configChanged) { |
Jeff Brown | fbae722 | 2011-01-23 13:07:25 -0800 | [diff] [blame] | 10392 | if (DEBUG_RESIZE || DEBUG_ORIENTATION) { |
| 10393 | Slog.v(TAG, "Resize reasons: " |
| 10394 | + "frameChanged=" + frameChanged |
| 10395 | + " contentInsetsChanged=" + w.mContentInsetsChanged |
| 10396 | + " visibleInsetsChanged=" + w.mVisibleInsetsChanged |
| 10397 | + " surfaceResized=" + w.mSurfaceResized |
| 10398 | + " configChanged=" + configChanged); |
| 10399 | } |
| 10400 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10401 | w.mLastFrame.set(w.mFrame); |
| 10402 | w.mLastContentInsets.set(w.mContentInsets); |
| 10403 | w.mLastVisibleInsets.set(w.mVisibleInsets); |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 10404 | // If the screen is currently frozen, then keep |
| 10405 | // it frozen until this window draws at its new |
| 10406 | // orientation. |
| 10407 | if (mDisplayFrozen) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10408 | if (DEBUG_ORIENTATION) Slog.v(TAG, |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 10409 | "Resizing while display frozen: " + w); |
| 10410 | w.mOrientationChanging = true; |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 10411 | if (!mWindowsFreezingScreen) { |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 10412 | mWindowsFreezingScreen = true; |
| 10413 | // XXX should probably keep timeout from |
| 10414 | // when we first froze the display. |
| 10415 | mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT); |
| 10416 | mH.sendMessageDelayed(mH.obtainMessage( |
| 10417 | H.WINDOW_FREEZE_TIMEOUT), 2000); |
| 10418 | } |
| 10419 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10420 | // If the orientation is changing, then we need to |
| 10421 | // hold off on unfreezing the display until this |
| 10422 | // window has been redrawn; to do that, we need |
| 10423 | // to go through the process of getting informed |
| 10424 | // by the application when it has finished drawing. |
| 10425 | if (w.mOrientationChanging) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10426 | if (DEBUG_ORIENTATION) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10427 | "Orientation start waiting for draw in " |
| 10428 | + w + ", surface " + w.mSurface); |
| 10429 | w.mDrawPending = true; |
| 10430 | w.mCommitDrawPending = false; |
| 10431 | w.mReadyToShow = false; |
| 10432 | if (w.mAppToken != null) { |
| 10433 | w.mAppToken.allDrawn = false; |
| 10434 | } |
| 10435 | } |
Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 10436 | if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10437 | "Resizing window " + w + " to " + w.mFrame); |
| 10438 | mResizingWindows.add(w); |
| 10439 | } else if (w.mOrientationChanging) { |
| 10440 | if (!w.mDrawPending && !w.mCommitDrawPending) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10441 | if (DEBUG_ORIENTATION) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10442 | "Orientation not waiting for draw in " |
| 10443 | + w + ", surface " + w.mSurface); |
| 10444 | w.mOrientationChanging = false; |
| 10445 | } |
| 10446 | } |
| 10447 | } |
| 10448 | |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10449 | if (w.mAttachedHidden || !w.isReadyForDisplay()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10450 | if (!w.mLastHidden) { |
| 10451 | //dump(); |
| 10452 | w.mLastHidden = true; |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 10453 | if (SHOW_TRANSACTIONS) logSurface(w, |
| 10454 | "HIDE (performLayout)", null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10455 | if (w.mSurface != null) { |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 10456 | w.mSurfaceShown = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10457 | try { |
| 10458 | w.mSurface.hide(); |
| 10459 | } catch (RuntimeException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10460 | Slog.w(TAG, "Exception hiding surface in " + w); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10461 | } |
| 10462 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10463 | } |
| 10464 | // If we are waiting for this window to handle an |
| 10465 | // orientation change, well, it is hidden, so |
| 10466 | // doesn't really matter. Note that this does |
| 10467 | // introduce a potential glitch if the window |
| 10468 | // becomes unhidden before it has drawn for the |
| 10469 | // new orientation. |
| 10470 | if (w.mOrientationChanging) { |
| 10471 | w.mOrientationChanging = false; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10472 | if (DEBUG_ORIENTATION) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10473 | "Orientation change skips hidden " + w); |
| 10474 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10475 | } else if (w.mLastLayer != w.mAnimLayer |
| 10476 | || w.mLastAlpha != w.mShownAlpha |
| 10477 | || w.mLastDsDx != w.mDsDx |
| 10478 | || w.mLastDtDx != w.mDtDx |
| 10479 | || w.mLastDsDy != w.mDsDy |
| 10480 | || w.mLastDtDy != w.mDtDy |
| 10481 | || w.mLastHScale != w.mHScale |
| 10482 | || w.mLastVScale != w.mVScale |
| 10483 | || w.mLastHidden) { |
| 10484 | displayed = true; |
| 10485 | w.mLastAlpha = w.mShownAlpha; |
| 10486 | w.mLastLayer = w.mAnimLayer; |
| 10487 | w.mLastDsDx = w.mDsDx; |
| 10488 | w.mLastDtDx = w.mDtDx; |
| 10489 | w.mLastDsDy = w.mDsDy; |
| 10490 | w.mLastDtDy = w.mDtDy; |
| 10491 | w.mLastHScale = w.mHScale; |
| 10492 | w.mLastVScale = w.mVScale; |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 10493 | if (SHOW_TRANSACTIONS) logSurface(w, |
| 10494 | "alpha=" + w.mShownAlpha + " layer=" + w.mAnimLayer |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 10495 | + " matrix=[" + (w.mDsDx*w.mHScale) |
| 10496 | + "," + (w.mDtDx*w.mVScale) |
| 10497 | + "][" + (w.mDsDy*w.mHScale) |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 10498 | + "," + (w.mDtDy*w.mVScale) + "]", null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10499 | if (w.mSurface != null) { |
| 10500 | try { |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 10501 | w.mSurfaceAlpha = w.mShownAlpha; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10502 | w.mSurface.setAlpha(w.mShownAlpha); |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 10503 | w.mSurfaceLayer = w.mAnimLayer; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10504 | w.mSurface.setLayer(w.mAnimLayer); |
| 10505 | w.mSurface.setMatrix( |
| 10506 | w.mDsDx*w.mHScale, w.mDtDx*w.mVScale, |
| 10507 | w.mDsDy*w.mHScale, w.mDtDy*w.mVScale); |
| 10508 | } catch (RuntimeException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10509 | Slog.w(TAG, "Error updating surface in " + w, e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10510 | if (!recoveringMemory) { |
| 10511 | reclaimSomeSurfaceMemoryLocked(w, "update"); |
| 10512 | } |
| 10513 | } |
| 10514 | } |
| 10515 | |
| 10516 | if (w.mLastHidden && !w.mDrawPending |
| 10517 | && !w.mCommitDrawPending |
| 10518 | && !w.mReadyToShow) { |
Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 10519 | if (SHOW_TRANSACTIONS) logSurface(w, |
| 10520 | "SHOW (performLayout)", null); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10521 | if (DEBUG_VISIBILITY) Slog.v(TAG, "Showing " + w |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10522 | + " during relayout"); |
| 10523 | if (showSurfaceRobustlyLocked(w)) { |
| 10524 | w.mHasDrawn = true; |
| 10525 | w.mLastHidden = false; |
| 10526 | } else { |
| 10527 | w.mOrientationChanging = false; |
| 10528 | } |
| 10529 | } |
| 10530 | if (w.mSurface != null) { |
| 10531 | w.mToken.hasVisible = true; |
| 10532 | } |
| 10533 | } else { |
| 10534 | displayed = true; |
| 10535 | } |
| 10536 | |
| 10537 | if (displayed) { |
| 10538 | if (!covered) { |
Romain Guy | 980a938 | 2010-01-08 15:06:28 -0800 | [diff] [blame] | 10539 | if (attrs.width == LayoutParams.MATCH_PARENT |
| 10540 | && attrs.height == LayoutParams.MATCH_PARENT) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10541 | covered = true; |
| 10542 | } |
| 10543 | } |
| 10544 | if (w.mOrientationChanging) { |
| 10545 | if (w.mDrawPending || w.mCommitDrawPending) { |
| 10546 | orientationChangeComplete = false; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10547 | if (DEBUG_ORIENTATION) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10548 | "Orientation continue waiting for draw in " + w); |
| 10549 | } else { |
| 10550 | w.mOrientationChanging = false; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10551 | if (DEBUG_ORIENTATION) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10552 | "Orientation change complete in " + w); |
| 10553 | } |
| 10554 | } |
| 10555 | w.mToken.hasVisible = true; |
| 10556 | } |
| 10557 | } else if (w.mOrientationChanging) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10558 | if (DEBUG_ORIENTATION) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10559 | "Orientation change skips hidden " + w); |
| 10560 | w.mOrientationChanging = false; |
| 10561 | } |
| 10562 | |
Dianne Hackborn | 0f761d6 | 2010-11-30 22:06:10 -0800 | [diff] [blame] | 10563 | if (w.mContentChanged) { |
| 10564 | //Slog.i(TAG, "Window " + this + " clearing mContentChanged - done placing"); |
| 10565 | w.mContentChanged = false; |
| 10566 | } |
| 10567 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10568 | final boolean canBeSeen = w.isDisplayedLw(); |
| 10569 | |
| 10570 | if (someoneLosingFocus && w == mCurrentFocus && canBeSeen) { |
| 10571 | focusDisplayed = true; |
| 10572 | } |
| 10573 | |
Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 10574 | final boolean obscuredChanged = w.mObscured != obscured; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10575 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10576 | // Update effect. |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 10577 | if (!(w.mObscured=obscured)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10578 | if (w.mSurface != null) { |
| 10579 | if ((attrFlags&FLAG_KEEP_SCREEN_ON) != 0) { |
| 10580 | holdScreen = w.mSession; |
| 10581 | } |
Dianne Hackborn | 9ed4a4b | 2009-03-25 17:10:37 -0700 | [diff] [blame] | 10582 | if (!syswin && w.mAttrs.screenBrightness >= 0 |
| 10583 | && screenBrightness < 0) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10584 | screenBrightness = w.mAttrs.screenBrightness; |
| 10585 | } |
Mike Lockwood | fb73f79 | 2009-11-20 11:31:18 -0500 | [diff] [blame] | 10586 | if (!syswin && w.mAttrs.buttonBrightness >= 0 |
| 10587 | && buttonBrightness < 0) { |
| 10588 | buttonBrightness = w.mAttrs.buttonBrightness; |
| 10589 | } |
Mike Lockwood | 46af6a8 | 2010-03-09 08:28:22 -0500 | [diff] [blame] | 10590 | if (canBeSeen |
| 10591 | && (attrs.type == WindowManager.LayoutParams.TYPE_SYSTEM_DIALOG |
| 10592 | || attrs.type == WindowManager.LayoutParams.TYPE_KEYGUARD |
| 10593 | || attrs.type == WindowManager.LayoutParams.TYPE_SYSTEM_ERROR)) { |
Dianne Hackborn | 9ed4a4b | 2009-03-25 17:10:37 -0700 | [diff] [blame] | 10594 | syswin = true; |
| 10595 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10596 | } |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 10597 | |
Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 10598 | boolean opaqueDrawn = canBeSeen && w.isOpaqueDrawn(); |
| 10599 | if (opaqueDrawn && w.isFullscreen(dw, dh)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10600 | // This window completely covers everything behind it, |
| 10601 | // so we want to leave all of them as unblurred (for |
| 10602 | // performance reasons). |
| 10603 | obscured = true; |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 10604 | } else if (opaqueDrawn && w.needsBackgroundFiller(dw, dh)) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10605 | if (SHOW_TRANSACTIONS) Slog.d(TAG, "showing background filler"); |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 10606 | // This window is in compatibility mode, and needs background filler. |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 10607 | obscured = true; |
| 10608 | if (mBackgroundFillerSurface == null) { |
| 10609 | try { |
| 10610 | mBackgroundFillerSurface = new Surface(mFxSession, 0, |
Mathias Agopian | 5d26c1e | 2010-03-01 16:09:43 -0800 | [diff] [blame] | 10611 | "BackGroundFiller", |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 10612 | 0, dw, dh, |
| 10613 | PixelFormat.OPAQUE, |
| 10614 | Surface.FX_SURFACE_NORMAL); |
| 10615 | } catch (Exception e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10616 | Slog.e(TAG, "Exception creating filler surface", e); |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 10617 | } |
| 10618 | } |
| 10619 | try { |
| 10620 | mBackgroundFillerSurface.setPosition(0, 0); |
| 10621 | mBackgroundFillerSurface.setSize(dw, dh); |
| 10622 | // Using the same layer as Dim because they will never be shown at the |
| 10623 | // same time. |
| 10624 | mBackgroundFillerSurface.setLayer(w.mAnimLayer - 1); |
| 10625 | mBackgroundFillerSurface.show(); |
| 10626 | } catch (RuntimeException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10627 | Slog.e(TAG, "Exception showing filler surface"); |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 10628 | } |
| 10629 | backgroundFillerShown = true; |
| 10630 | mBackgroundFillerShown = true; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10631 | } else if (canBeSeen && !obscured && |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10632 | (attrFlags&FLAG_BLUR_BEHIND|FLAG_DIM_BEHIND) != 0) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10633 | if (localLOGV) Slog.v(TAG, "Win " + w |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10634 | + ": blurring=" + blurring |
| 10635 | + " obscured=" + obscured |
| 10636 | + " displayed=" + displayed); |
| 10637 | if ((attrFlags&FLAG_DIM_BEHIND) != 0) { |
| 10638 | if (!dimming) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10639 | //Slog.i(TAG, "DIM BEHIND: " + w); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10640 | dimming = true; |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 10641 | if (mDimAnimator == null) { |
| 10642 | mDimAnimator = new DimAnimator(mFxSession); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10643 | } |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 10644 | mDimAnimator.show(dw, dh); |
Dianne Hackborn | 1c24e95 | 2010-11-23 00:34:30 -0800 | [diff] [blame] | 10645 | mDimAnimator.updateParameters(mContext.getResources(), |
| 10646 | w, currentTime); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10647 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10648 | } |
| 10649 | if ((attrFlags&FLAG_BLUR_BEHIND) != 0) { |
| 10650 | if (!blurring) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10651 | //Slog.i(TAG, "BLUR BEHIND: " + w); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10652 | blurring = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10653 | if (mBlurSurface == null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10654 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR " |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10655 | + mBlurSurface + ": CREATE"); |
| 10656 | try { |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10657 | mBlurSurface = new Surface(mFxSession, 0, |
Mathias Agopian | 5d26c1e | 2010-03-01 16:09:43 -0800 | [diff] [blame] | 10658 | "BlurSurface", |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10659 | -1, 16, 16, |
| 10660 | PixelFormat.OPAQUE, |
| 10661 | Surface.FX_SURFACE_BLUR); |
| 10662 | } catch (Exception e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10663 | Slog.e(TAG, "Exception creating Blur surface", e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10664 | } |
| 10665 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10666 | if (mBlurSurface != null) { |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 10667 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR " |
| 10668 | + mBlurSurface + ": pos=(0,0) (" + |
| 10669 | dw + "x" + dh + "), layer=" + (w.mAnimLayer-1)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10670 | mBlurSurface.setPosition(0, 0); |
| 10671 | mBlurSurface.setSize(dw, dh); |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 10672 | mBlurSurface.setLayer(w.mAnimLayer-2); |
| 10673 | if (!mBlurShown) { |
| 10674 | try { |
| 10675 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR " |
| 10676 | + mBlurSurface + ": SHOW"); |
| 10677 | mBlurSurface.show(); |
| 10678 | } catch (RuntimeException e) { |
| 10679 | Slog.w(TAG, "Failure showing blur surface", e); |
| 10680 | } |
| 10681 | mBlurShown = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10682 | } |
| 10683 | } |
| 10684 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10685 | } |
| 10686 | } |
| 10687 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10688 | |
Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 10689 | if (obscuredChanged && mWallpaperTarget == w) { |
| 10690 | // This is the wallpaper target and its obscured state |
| 10691 | // changed... make sure the current wallaper's visibility |
| 10692 | // has been updated accordingly. |
| 10693 | updateWallpaperVisibilityLocked(); |
| 10694 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10695 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10696 | |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 10697 | if (backgroundFillerShown == false && mBackgroundFillerShown) { |
| 10698 | mBackgroundFillerShown = false; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10699 | if (SHOW_TRANSACTIONS) Slog.d(TAG, "hiding background filler"); |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 10700 | try { |
| 10701 | mBackgroundFillerSurface.hide(); |
| 10702 | } catch (RuntimeException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10703 | Slog.e(TAG, "Exception hiding filler surface", e); |
Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 10704 | } |
| 10705 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10706 | |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 10707 | if (mDimAnimator != null && mDimAnimator.mDimShown) { |
Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 10708 | animating |= mDimAnimator.updateSurface(dimming, currentTime, |
| 10709 | mDisplayFrozen || !mPolicy.isScreenOn()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10710 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10711 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10712 | if (!blurring && mBlurShown) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10713 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR " + mBlurSurface |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10714 | + ": HIDE"); |
| 10715 | try { |
| 10716 | mBlurSurface.hide(); |
| 10717 | } catch (IllegalArgumentException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10718 | Slog.w(TAG, "Illegal argument exception hiding blur surface"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10719 | } |
| 10720 | mBlurShown = false; |
| 10721 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10722 | } catch (RuntimeException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10723 | Slog.e(TAG, "Unhandled exception in Window Manager", e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10724 | } |
| 10725 | |
| 10726 | Surface.closeTransaction(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10727 | |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 10728 | if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION performLayoutAndPlaceSurfaces"); |
| 10729 | |
Dianne Hackborn | b9fb170 | 2010-08-23 16:49:02 -0700 | [diff] [blame] | 10730 | if (mWatermark != null) { |
| 10731 | mWatermark.drawIfNeeded(); |
| 10732 | } |
| 10733 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10734 | if (DEBUG_ORIENTATION && mDisplayFrozen) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10735 | "With display frozen, orientationChangeComplete=" |
| 10736 | + orientationChangeComplete); |
| 10737 | if (orientationChangeComplete) { |
| 10738 | if (mWindowsFreezingScreen) { |
| 10739 | mWindowsFreezingScreen = false; |
| 10740 | mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT); |
| 10741 | } |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 10742 | stopFreezingDisplayLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10743 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10744 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10745 | i = mResizingWindows.size(); |
| 10746 | if (i > 0) { |
| 10747 | do { |
| 10748 | i--; |
| 10749 | WindowState win = mResizingWindows.get(i); |
| 10750 | try { |
Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 10751 | if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG, |
| 10752 | "Reporting new frame to " + win + ": " + win.mFrame); |
Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 10753 | int diff = 0; |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 10754 | boolean configChanged = |
| 10755 | win.mConfiguration != mCurConfiguration |
| 10756 | && (win.mConfiguration == null |
Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 10757 | || (diff=mCurConfiguration.diff(win.mConfiguration)) != 0); |
| 10758 | if ((DEBUG_RESIZE || DEBUG_ORIENTATION || DEBUG_CONFIGURATION) |
| 10759 | && configChanged) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10760 | Slog.i(TAG, "Sending new config to window " + win + ": " |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 10761 | + win.mFrame.width() + "x" + win.mFrame.height() |
Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 10762 | + " / " + mCurConfiguration + " / 0x" |
| 10763 | + Integer.toHexString(diff)); |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 10764 | } |
Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 10765 | win.mConfiguration = mCurConfiguration; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10766 | win.mClient.resized(win.mFrame.width(), |
| 10767 | win.mFrame.height(), win.mLastContentInsets, |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 10768 | win.mLastVisibleInsets, win.mDrawPending, |
| 10769 | configChanged ? win.mConfiguration : null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10770 | win.mContentInsetsChanged = false; |
| 10771 | win.mVisibleInsetsChanged = false; |
Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 10772 | win.mSurfaceResized = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10773 | } catch (RemoteException e) { |
| 10774 | win.mOrientationChanging = false; |
| 10775 | } |
| 10776 | } while (i > 0); |
| 10777 | mResizingWindows.clear(); |
| 10778 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10779 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10780 | // Destroy the surface of any windows that are no longer visible. |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 10781 | boolean wallpaperDestroyed = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10782 | i = mDestroySurface.size(); |
| 10783 | if (i > 0) { |
| 10784 | do { |
| 10785 | i--; |
| 10786 | WindowState win = mDestroySurface.get(i); |
| 10787 | win.mDestroying = false; |
| 10788 | if (mInputMethodWindow == win) { |
| 10789 | mInputMethodWindow = null; |
| 10790 | } |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 10791 | if (win == mWallpaperTarget) { |
| 10792 | wallpaperDestroyed = true; |
| 10793 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10794 | win.destroySurfaceLocked(); |
| 10795 | } while (i > 0); |
| 10796 | mDestroySurface.clear(); |
| 10797 | } |
| 10798 | |
| 10799 | // Time to remove any exiting tokens? |
| 10800 | for (i=mExitingTokens.size()-1; i>=0; i--) { |
| 10801 | WindowToken token = mExitingTokens.get(i); |
| 10802 | if (!token.hasVisible) { |
| 10803 | mExitingTokens.remove(i); |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 10804 | if (token.windowType == TYPE_WALLPAPER) { |
| 10805 | mWallpaperTokens.remove(token); |
| 10806 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10807 | } |
| 10808 | } |
| 10809 | |
| 10810 | // Time to remove any exiting applications? |
| 10811 | for (i=mExitingAppTokens.size()-1; i>=0; i--) { |
| 10812 | AppWindowToken token = mExitingAppTokens.get(i); |
| 10813 | if (!token.hasVisible && !mClosingApps.contains(token)) { |
Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 10814 | // Make sure there is no animation running on this token, |
| 10815 | // so any windows associated with it will be removed as |
| 10816 | // soon as their animations are complete |
| 10817 | token.animation = null; |
| 10818 | token.animating = false; |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 10819 | if (DEBUG_ADD_REMOVE || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG, |
| 10820 | "performLayout: App token exiting now removed" + token); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10821 | mAppTokens.remove(token); |
| 10822 | mExitingAppTokens.remove(i); |
| 10823 | } |
| 10824 | } |
| 10825 | |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 10826 | boolean needRelayout = false; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10827 | |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 10828 | if (!animating && mAppTransitionRunning) { |
| 10829 | // We have finished the animation of an app transition. To do |
| 10830 | // this, we have delayed a lot of operations like showing and |
| 10831 | // hiding apps, moving apps in Z-order, etc. The app token list |
| 10832 | // reflects the correct Z-order, but the window list may now |
| 10833 | // be out of sync with it. So here we will just rebuild the |
| 10834 | // entire app window list. Fun! |
| 10835 | mAppTransitionRunning = false; |
| 10836 | needRelayout = true; |
| 10837 | rebuildAppWindowListLocked(); |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 10838 | assignLayersLocked(); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 10839 | // Clear information about apps that were moving. |
| 10840 | mToBottomApps.clear(); |
| 10841 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10842 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10843 | if (focusDisplayed) { |
| 10844 | mH.sendEmptyMessage(H.REPORT_LOSING_FOCUS); |
| 10845 | } |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 10846 | if (wallpaperDestroyed) { |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 10847 | needRelayout = adjustWallpaperWindowsLocked() != 0; |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 10848 | } |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 10849 | if (needRelayout) { |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 10850 | requestAnimationLocked(0); |
| 10851 | } else if (animating) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10852 | requestAnimationLocked(currentTime+(1000/60)-SystemClock.uptimeMillis()); |
| 10853 | } |
Jeff Brown | eb857f1 | 2010-07-16 10:06:33 -0700 | [diff] [blame] | 10854 | |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 10855 | // Finally update all input windows now that the window changes have stabilized. |
Jeff Brown | 2e44b07 | 2011-01-24 15:21:56 -0800 | [diff] [blame^] | 10856 | mInputMonitor.updateInputWindowsLw(true /*force*/); |
Jeff Brown | eb857f1 | 2010-07-16 10:06:33 -0700 | [diff] [blame] | 10857 | |
Jeff Brown | 8e03b75 | 2010-06-13 19:16:55 -0700 | [diff] [blame] | 10858 | setHoldScreenLocked(holdScreen != null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10859 | if (screenBrightness < 0 || screenBrightness > 1.0f) { |
| 10860 | mPowerManager.setScreenBrightnessOverride(-1); |
| 10861 | } else { |
| 10862 | mPowerManager.setScreenBrightnessOverride((int) |
| 10863 | (screenBrightness * Power.BRIGHTNESS_ON)); |
| 10864 | } |
Mike Lockwood | fb73f79 | 2009-11-20 11:31:18 -0500 | [diff] [blame] | 10865 | if (buttonBrightness < 0 || buttonBrightness > 1.0f) { |
| 10866 | mPowerManager.setButtonBrightnessOverride(-1); |
| 10867 | } else { |
| 10868 | mPowerManager.setButtonBrightnessOverride((int) |
| 10869 | (buttonBrightness * Power.BRIGHTNESS_ON)); |
| 10870 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10871 | if (holdScreen != mHoldingScreenOn) { |
| 10872 | mHoldingScreenOn = holdScreen; |
| 10873 | Message m = mH.obtainMessage(H.HOLD_SCREEN_CHANGED, holdScreen); |
| 10874 | mH.sendMessage(m); |
| 10875 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10876 | |
Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 10877 | if (mTurnOnScreen) { |
Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 10878 | if (DEBUG_VISIBILITY) Slog.v(TAG, "Turning screen on after layout!"); |
Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 10879 | mPowerManager.userActivity(SystemClock.uptimeMillis(), false, |
| 10880 | LocalPowerManager.BUTTON_EVENT, true); |
| 10881 | mTurnOnScreen = false; |
| 10882 | } |
Dianne Hackborn | f3bea9c | 2009-12-09 18:26:21 -0800 | [diff] [blame] | 10883 | |
Dianne Hackborn | 89ba675 | 2011-01-23 16:51:16 -0800 | [diff] [blame] | 10884 | if (updateRotation) { |
| 10885 | if (DEBUG_ORIENTATION) Slog.d(TAG, "Performing post-rotate rotation"); |
| 10886 | boolean changed = setRotationUncheckedLocked( |
| 10887 | WindowManagerPolicy.USE_LAST_ROTATION, 0, false); |
| 10888 | if (changed) { |
| 10889 | sendNewConfiguration(); |
| 10890 | } |
| 10891 | } |
| 10892 | |
Dianne Hackborn | f3bea9c | 2009-12-09 18:26:21 -0800 | [diff] [blame] | 10893 | // Check to see if we are now in a state where the screen should |
| 10894 | // be enabled, because the window obscured flags have changed. |
| 10895 | enableScreenIfNeededLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10896 | } |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 10897 | |
| 10898 | /** |
| 10899 | * Must be called with the main window manager lock held. |
| 10900 | */ |
| 10901 | void setHoldScreenLocked(boolean holding) { |
| 10902 | boolean state = mHoldingScreenWakeLock.isHeld(); |
| 10903 | if (holding != state) { |
| 10904 | if (holding) { |
| 10905 | mHoldingScreenWakeLock.acquire(); |
| 10906 | } else { |
| 10907 | mPolicy.screenOnStoppedLw(); |
| 10908 | mHoldingScreenWakeLock.release(); |
| 10909 | } |
| 10910 | } |
| 10911 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10912 | |
| 10913 | void requestAnimationLocked(long delay) { |
| 10914 | if (!mAnimationPending) { |
| 10915 | mAnimationPending = true; |
| 10916 | mH.sendMessageDelayed(mH.obtainMessage(H.ANIMATE), delay); |
| 10917 | } |
| 10918 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10919 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10920 | /** |
| 10921 | * Have the surface flinger show a surface, robustly dealing with |
| 10922 | * error conditions. In particular, if there is not enough memory |
| 10923 | * to show the surface, then we will try to get rid of other surfaces |
| 10924 | * in order to succeed. |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10925 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10926 | * @return Returns true if the surface was successfully shown. |
| 10927 | */ |
| 10928 | boolean showSurfaceRobustlyLocked(WindowState win) { |
| 10929 | try { |
| 10930 | if (win.mSurface != null) { |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 10931 | win.mSurfaceShown = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10932 | win.mSurface.show(); |
Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 10933 | if (win.mTurnOnScreen) { |
Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 10934 | if (DEBUG_VISIBILITY) Slog.v(TAG, |
| 10935 | "Show surface turning screen on: " + win); |
Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 10936 | win.mTurnOnScreen = false; |
| 10937 | mTurnOnScreen = true; |
| 10938 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10939 | } |
| 10940 | return true; |
| 10941 | } catch (RuntimeException e) { |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 10942 | 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] | 10943 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10944 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10945 | reclaimSomeSurfaceMemoryLocked(win, "show"); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10946 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10947 | return false; |
| 10948 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10949 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10950 | void reclaimSomeSurfaceMemoryLocked(WindowState win, String operation) { |
| 10951 | final Surface surface = win.mSurface; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10952 | |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10953 | EventLog.writeEvent(EventLogTags.WM_NO_SURFACE_MEMORY, win.toString(), |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10954 | win.mSession.mPid, operation); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10955 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10956 | if (mForceRemoves == null) { |
| 10957 | mForceRemoves = new ArrayList<WindowState>(); |
| 10958 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10959 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10960 | long callingIdentity = Binder.clearCallingIdentity(); |
| 10961 | try { |
| 10962 | // There was some problem... first, do a sanity check of the |
| 10963 | // window list to make sure we haven't left any dangling surfaces |
| 10964 | // around. |
| 10965 | int N = mWindows.size(); |
| 10966 | boolean leakedSurface = false; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10967 | 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] | 10968 | for (int i=0; i<N; i++) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 10969 | WindowState ws = mWindows.get(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10970 | if (ws.mSurface != null) { |
| 10971 | if (!mSessions.contains(ws.mSession)) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10972 | Slog.w(TAG, "LEAKED SURFACE (session doesn't exist): " |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10973 | + ws + " surface=" + ws.mSurface |
| 10974 | + " token=" + win.mToken |
| 10975 | + " pid=" + ws.mSession.mPid |
| 10976 | + " uid=" + ws.mSession.mUid); |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 10977 | if (SHOW_TRANSACTIONS) logSurface(ws, "LEAK DESTROY", null); |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 10978 | ws.mSurface.destroy(); |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 10979 | ws.mSurfaceShown = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10980 | ws.mSurface = null; |
| 10981 | mForceRemoves.add(ws); |
| 10982 | i--; |
| 10983 | N--; |
| 10984 | leakedSurface = true; |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 10985 | } else if (ws.mAppToken != null && ws.mAppToken.clientHidden) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10986 | Slog.w(TAG, "LEAKED SURFACE (app token hidden): " |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10987 | + ws + " surface=" + ws.mSurface |
| 10988 | + " token=" + win.mAppToken); |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 10989 | if (SHOW_TRANSACTIONS) logSurface(ws, "LEAK DESTROY", null); |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 10990 | ws.mSurface.destroy(); |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 10991 | ws.mSurfaceShown = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10992 | ws.mSurface = null; |
| 10993 | leakedSurface = true; |
| 10994 | } |
| 10995 | } |
| 10996 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10997 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10998 | boolean killedApps = false; |
| 10999 | if (!leakedSurface) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 11000 | Slog.w(TAG, "No leaked surfaces; killing applicatons!"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11001 | SparseIntArray pidCandidates = new SparseIntArray(); |
| 11002 | for (int i=0; i<N; i++) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 11003 | WindowState ws = mWindows.get(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11004 | if (ws.mSurface != null) { |
| 11005 | pidCandidates.append(ws.mSession.mPid, ws.mSession.mPid); |
| 11006 | } |
| 11007 | } |
| 11008 | if (pidCandidates.size() > 0) { |
| 11009 | int[] pids = new int[pidCandidates.size()]; |
| 11010 | for (int i=0; i<pids.length; i++) { |
| 11011 | pids[i] = pidCandidates.keyAt(i); |
| 11012 | } |
| 11013 | try { |
Suchi Amalapurapu | e99bb5f | 2010-03-19 14:36:49 -0700 | [diff] [blame] | 11014 | if (mActivityManager.killPids(pids, "Free memory")) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11015 | killedApps = true; |
| 11016 | } |
| 11017 | } catch (RemoteException e) { |
| 11018 | } |
| 11019 | } |
| 11020 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 11021 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11022 | if (leakedSurface || killedApps) { |
| 11023 | // We managed to reclaim some memory, so get rid of the trouble |
| 11024 | // surface and ask the app to request another one. |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 11025 | 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] | 11026 | if (surface != null) { |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 11027 | if (SHOW_TRANSACTIONS) logSurface(win, "RECOVER DESTROY", null); |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 11028 | surface.destroy(); |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 11029 | win.mSurfaceShown = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11030 | win.mSurface = null; |
| 11031 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 11032 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11033 | try { |
| 11034 | win.mClient.dispatchGetNewSurface(); |
| 11035 | } catch (RemoteException e) { |
| 11036 | } |
| 11037 | } |
| 11038 | } finally { |
| 11039 | Binder.restoreCallingIdentity(callingIdentity); |
| 11040 | } |
| 11041 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 11042 | |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 11043 | private boolean updateFocusedWindowLocked(int mode, boolean updateInputWindows) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11044 | WindowState newFocus = computeFocusedWindowLocked(); |
| 11045 | if (mCurrentFocus != newFocus) { |
| 11046 | // This check makes sure that we don't already have the focus |
| 11047 | // change message pending. |
| 11048 | mH.removeMessages(H.REPORT_FOCUS_CHANGE); |
| 11049 | mH.sendEmptyMessage(H.REPORT_FOCUS_CHANGE); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 11050 | if (localLOGV) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11051 | TAG, "Changing focus from " + mCurrentFocus + " to " + newFocus); |
| 11052 | final WindowState oldFocus = mCurrentFocus; |
| 11053 | mCurrentFocus = newFocus; |
| 11054 | mLosingFocus.remove(newFocus); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 11055 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11056 | final WindowState imWindow = mInputMethodWindow; |
| 11057 | if (newFocus != imWindow && oldFocus != imWindow) { |
The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 11058 | if (moveInputMethodWindowsIfNeededLocked( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11059 | mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS && |
The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 11060 | mode != UPDATE_FOCUS_WILL_PLACE_SURFACES)) { |
| 11061 | mLayoutNeeded = true; |
| 11062 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11063 | if (mode == UPDATE_FOCUS_PLACING_SURFACES) { |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 11064 | performLayoutLockedInner(true /*initial*/, updateInputWindows); |
The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 11065 | } else if (mode == UPDATE_FOCUS_WILL_PLACE_SURFACES) { |
| 11066 | // Client will do the layout, but we need to assign layers |
| 11067 | // for handleNewWindowLocked() below. |
| 11068 | assignLayersLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11069 | } |
| 11070 | } |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 11071 | |
| 11072 | if (mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS) { |
| 11073 | // If we defer assigning layers, then the caller is responsible for |
| 11074 | // doing this part. |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 11075 | finishUpdateFocusedWindowAfterAssignLayersLocked(updateInputWindows); |
The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 11076 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11077 | return true; |
| 11078 | } |
| 11079 | return false; |
| 11080 | } |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 11081 | |
Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 11082 | private void finishUpdateFocusedWindowAfterAssignLayersLocked(boolean updateInputWindows) { |
| 11083 | mInputMonitor.setInputFocusLw(mCurrentFocus, updateInputWindows); |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 11084 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11085 | |
| 11086 | private WindowState computeFocusedWindowLocked() { |
| 11087 | WindowState result = null; |
| 11088 | WindowState win; |
| 11089 | |
| 11090 | int i = mWindows.size() - 1; |
| 11091 | int nextAppIndex = mAppTokens.size()-1; |
| 11092 | WindowToken nextApp = nextAppIndex >= 0 |
| 11093 | ? mAppTokens.get(nextAppIndex) : null; |
| 11094 | |
| 11095 | while (i >= 0) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 11096 | win = mWindows.get(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11097 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 11098 | if (localLOGV || DEBUG_FOCUS) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11099 | TAG, "Looking for focus: " + i |
| 11100 | + " = " + win |
| 11101 | + ", flags=" + win.mAttrs.flags |
| 11102 | + ", canReceive=" + win.canReceiveKeys()); |
| 11103 | |
| 11104 | AppWindowToken thisApp = win.mAppToken; |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 11105 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11106 | // If this window's application has been removed, just skip it. |
| 11107 | if (thisApp != null && thisApp.removed) { |
| 11108 | i--; |
| 11109 | continue; |
| 11110 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 11111 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11112 | // If there is a focused app, don't allow focus to go to any |
| 11113 | // windows below it. If this is an application window, step |
| 11114 | // through the app tokens until we find its app. |
| 11115 | if (thisApp != null && nextApp != null && thisApp != nextApp |
| 11116 | && win.mAttrs.type != TYPE_APPLICATION_STARTING) { |
| 11117 | int origAppIndex = nextAppIndex; |
| 11118 | while (nextAppIndex > 0) { |
| 11119 | if (nextApp == mFocusedApp) { |
| 11120 | // Whoops, we are below the focused app... no focus |
| 11121 | // for you! |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 11122 | if (localLOGV || DEBUG_FOCUS) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11123 | TAG, "Reached focused app: " + mFocusedApp); |
| 11124 | return null; |
| 11125 | } |
| 11126 | nextAppIndex--; |
| 11127 | nextApp = mAppTokens.get(nextAppIndex); |
| 11128 | if (nextApp == thisApp) { |
| 11129 | break; |
| 11130 | } |
| 11131 | } |
| 11132 | if (thisApp != nextApp) { |
| 11133 | // Uh oh, the app token doesn't exist! This shouldn't |
| 11134 | // happen, but if it does we can get totally hosed... |
| 11135 | // so restart at the original app. |
| 11136 | nextAppIndex = origAppIndex; |
| 11137 | nextApp = mAppTokens.get(nextAppIndex); |
| 11138 | } |
| 11139 | } |
| 11140 | |
| 11141 | // Dispatch to this window if it is wants key events. |
| 11142 | if (win.canReceiveKeys()) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 11143 | if (DEBUG_FOCUS) Slog.v( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11144 | TAG, "Found focus @ " + i + " = " + win); |
| 11145 | result = win; |
| 11146 | break; |
| 11147 | } |
| 11148 | |
| 11149 | i--; |
| 11150 | } |
| 11151 | |
| 11152 | return result; |
| 11153 | } |
| 11154 | |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 11155 | private void startFreezingDisplayLocked(boolean inTransaction) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11156 | if (mDisplayFrozen) { |
| 11157 | return; |
| 11158 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 11159 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11160 | mScreenFrozenLock.acquire(); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 11161 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11162 | long now = SystemClock.uptimeMillis(); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 11163 | //Slog.i(TAG, "Freezing, gc pending: " + mFreezeGcPending + ", now " + now); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11164 | if (mFreezeGcPending != 0) { |
| 11165 | if (now > (mFreezeGcPending+1000)) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 11166 | //Slog.i(TAG, "Gc! " + now + " > " + (mFreezeGcPending+1000)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11167 | mH.removeMessages(H.FORCE_GC); |
| 11168 | Runtime.getRuntime().gc(); |
| 11169 | mFreezeGcPending = now; |
| 11170 | } |
| 11171 | } else { |
| 11172 | mFreezeGcPending = now; |
| 11173 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 11174 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11175 | mDisplayFrozen = true; |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 11176 | |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 11177 | mInputMonitor.freezeInputDispatchingLw(); |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 11178 | |
Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 11179 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
| 11180 | mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET; |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 11181 | mNextAppTransitionPackage = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11182 | mAppTransitionReady = true; |
| 11183 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 11184 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11185 | if (PROFILE_ORIENTATION) { |
| 11186 | File file = new File("/data/system/frozen"); |
| 11187 | Debug.startMethodTracing(file.toString(), 8 * 1024 * 1024); |
| 11188 | } |
Dianne Hackborn | a111187 | 2010-11-23 20:55:11 -0800 | [diff] [blame] | 11189 | |
| 11190 | if (CUSTOM_SCREEN_ROTATION) { |
Dianne Hackborn | f9d0be9 | 2010-11-24 12:35:25 -0800 | [diff] [blame] | 11191 | if (mScreenRotationAnimation != null && mScreenRotationAnimation.isAnimating()) { |
| 11192 | mScreenRotationAnimation.kill(); |
| 11193 | mScreenRotationAnimation = null; |
| 11194 | } |
Dianne Hackborn | a111187 | 2010-11-23 20:55:11 -0800 | [diff] [blame] | 11195 | if (mScreenRotationAnimation == null) { |
Dianne Hackborn | f9d0be9 | 2010-11-24 12:35:25 -0800 | [diff] [blame] | 11196 | mScreenRotationAnimation = new ScreenRotationAnimation(mContext, |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 11197 | mDisplay, mFxSession, inTransaction); |
Dianne Hackborn | a111187 | 2010-11-23 20:55:11 -0800 | [diff] [blame] | 11198 | } |
| 11199 | } else { |
| 11200 | Surface.freezeDisplay(0); |
| 11201 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11202 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 11203 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11204 | private void stopFreezingDisplayLocked() { |
| 11205 | if (!mDisplayFrozen) { |
| 11206 | return; |
| 11207 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 11208 | |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 11209 | if (mWaitingForConfig || mAppsFreezingScreen > 0 || mWindowsFreezingScreen) { |
| 11210 | return; |
| 11211 | } |
| 11212 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11213 | mDisplayFrozen = false; |
| 11214 | mH.removeMessages(H.APP_FREEZE_TIMEOUT); |
| 11215 | if (PROFILE_ORIENTATION) { |
| 11216 | Debug.stopMethodTracing(); |
| 11217 | } |
Dianne Hackborn | a111187 | 2010-11-23 20:55:11 -0800 | [diff] [blame] | 11218 | |
Dianne Hackborn | 89ba675 | 2011-01-23 16:51:16 -0800 | [diff] [blame] | 11219 | boolean updateRotation = false; |
| 11220 | |
Dianne Hackborn | a111187 | 2010-11-23 20:55:11 -0800 | [diff] [blame] | 11221 | if (CUSTOM_SCREEN_ROTATION) { |
| 11222 | if (mScreenRotationAnimation != null) { |
Dianne Hackborn | f9d0be9 | 2010-11-24 12:35:25 -0800 | [diff] [blame] | 11223 | if (mScreenRotationAnimation.dismiss(MAX_ANIMATION_DURATION, |
| 11224 | mTransitionAnimationScale)) { |
| 11225 | requestAnimationLocked(0); |
| 11226 | } else { |
| 11227 | mScreenRotationAnimation = null; |
Dianne Hackborn | 89ba675 | 2011-01-23 16:51:16 -0800 | [diff] [blame] | 11228 | updateRotation = true; |
Dianne Hackborn | f9d0be9 | 2010-11-24 12:35:25 -0800 | [diff] [blame] | 11229 | } |
Dianne Hackborn | a111187 | 2010-11-23 20:55:11 -0800 | [diff] [blame] | 11230 | } |
| 11231 | } else { |
| 11232 | Surface.unfreezeDisplay(0); |
| 11233 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 11234 | |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 11235 | mInputMonitor.thawInputDispatchingLw(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11236 | |
Christopher Tate | b696aee | 2010-04-02 19:08:30 -0700 | [diff] [blame] | 11237 | // While the display is frozen we don't re-compute the orientation |
| 11238 | // to avoid inconsistent states. However, something interesting |
| 11239 | // could have actually changed during that time so re-evaluate it |
| 11240 | // now to catch that. |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 11241 | if (updateOrientationFromAppTokensLocked(false)) { |
Christopher Tate | b696aee | 2010-04-02 19:08:30 -0700 | [diff] [blame] | 11242 | mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION); |
| 11243 | } |
| 11244 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11245 | // A little kludge: a lot could have happened while the |
| 11246 | // display was frozen, so now that we are coming back we |
| 11247 | // do a gc so that any remote references the system |
| 11248 | // processes holds on others can be released if they are |
| 11249 | // no longer needed. |
| 11250 | mH.removeMessages(H.FORCE_GC); |
| 11251 | mH.sendMessageDelayed(mH.obtainMessage(H.FORCE_GC), |
| 11252 | 2000); |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 11253 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11254 | mScreenFrozenLock.release(); |
Dianne Hackborn | 89ba675 | 2011-01-23 16:51:16 -0800 | [diff] [blame] | 11255 | |
| 11256 | if (updateRotation) { |
| 11257 | if (DEBUG_ORIENTATION) Slog.d(TAG, "Performing post-rotate rotation"); |
| 11258 | boolean changed = setRotationUncheckedLocked( |
| 11259 | WindowManagerPolicy.USE_LAST_ROTATION, 0, false); |
| 11260 | if (changed) { |
| 11261 | sendNewConfiguration(); |
| 11262 | } |
| 11263 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11264 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 11265 | |
Dianne Hackborn | b9fb170 | 2010-08-23 16:49:02 -0700 | [diff] [blame] | 11266 | static int getPropertyInt(String[] tokens, int index, int defUnits, int defDps, |
| 11267 | DisplayMetrics dm) { |
| 11268 | if (index < tokens.length) { |
| 11269 | String str = tokens[index]; |
| 11270 | if (str != null && str.length() > 0) { |
| 11271 | try { |
| 11272 | int val = Integer.parseInt(str); |
| 11273 | return val; |
| 11274 | } catch (Exception e) { |
| 11275 | } |
| 11276 | } |
Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 11277 | } |
| 11278 | if (defUnits == TypedValue.COMPLEX_UNIT_PX) { |
| 11279 | return defDps; |
| 11280 | } |
| 11281 | int val = (int)TypedValue.applyDimension(defUnits, defDps, dm); |
| 11282 | return val; |
| 11283 | } |
| 11284 | |
Dianne Hackborn | ed7bfbf | 2010-11-05 13:08:35 -0700 | [diff] [blame] | 11285 | static class Watermark { |
Dianne Hackborn | b9fb170 | 2010-08-23 16:49:02 -0700 | [diff] [blame] | 11286 | final String[] mTokens; |
| 11287 | final String mText; |
| 11288 | final Paint mTextPaint; |
| 11289 | final int mTextWidth; |
| 11290 | final int mTextHeight; |
| 11291 | final int mTextAscent; |
| 11292 | final int mTextDescent; |
| 11293 | final int mDeltaX; |
| 11294 | final int mDeltaY; |
Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 11295 | |
Dianne Hackborn | b9fb170 | 2010-08-23 16:49:02 -0700 | [diff] [blame] | 11296 | Surface mSurface; |
| 11297 | int mLastDW; |
| 11298 | int mLastDH; |
| 11299 | boolean mDrawNeeded; |
| 11300 | |
Dianne Hackborn | ed7bfbf | 2010-11-05 13:08:35 -0700 | [diff] [blame] | 11301 | Watermark(Display display, SurfaceSession session, String[] tokens) { |
Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 11302 | final DisplayMetrics dm = new DisplayMetrics(); |
Dianne Hackborn | ed7bfbf | 2010-11-05 13:08:35 -0700 | [diff] [blame] | 11303 | display.getMetrics(dm); |
Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 11304 | |
Dianne Hackborn | b9fb170 | 2010-08-23 16:49:02 -0700 | [diff] [blame] | 11305 | if (false) { |
| 11306 | Log.i(TAG, "*********************** WATERMARK"); |
| 11307 | for (int i=0; i<tokens.length; i++) { |
| 11308 | Log.i(TAG, " TOKEN #" + i + ": " + tokens[i]); |
| 11309 | } |
| 11310 | } |
Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 11311 | |
Dianne Hackborn | b9fb170 | 2010-08-23 16:49:02 -0700 | [diff] [blame] | 11312 | mTokens = tokens; |
Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 11313 | |
Dianne Hackborn | b9fb170 | 2010-08-23 16:49:02 -0700 | [diff] [blame] | 11314 | StringBuilder builder = new StringBuilder(32); |
| 11315 | int len = mTokens[0].length(); |
| 11316 | len = len & ~1; |
| 11317 | for (int i=0; i<len; i+=2) { |
| 11318 | int c1 = mTokens[0].charAt(i); |
| 11319 | int c2 = mTokens[0].charAt(i+1); |
| 11320 | if (c1 >= 'a' && c1 <= 'f') c1 = c1 - 'a' + 10; |
| 11321 | else if (c1 >= 'A' && c1 <= 'F') c1 = c1 - 'A' + 10; |
| 11322 | else c1 -= '0'; |
| 11323 | if (c2 >= 'a' && c2 <= 'f') c2 = c2 - 'a' + 10; |
| 11324 | else if (c2 >= 'A' && c2 <= 'F') c2 = c2 - 'A' + 10; |
| 11325 | else c2 -= '0'; |
| 11326 | builder.append((char)(255-((c1*16)+c2))); |
| 11327 | } |
| 11328 | mText = builder.toString(); |
| 11329 | if (false) { |
| 11330 | Log.i(TAG, "Final text: " + mText); |
| 11331 | } |
| 11332 | |
| 11333 | int fontSize = getPropertyInt(tokens, 1, |
| 11334 | TypedValue.COMPLEX_UNIT_DIP, 20, dm); |
| 11335 | |
| 11336 | mTextPaint = new Paint(Paint.ANTI_ALIAS_FLAG); |
| 11337 | mTextPaint.setTextSize(fontSize); |
| 11338 | mTextPaint.setTypeface(Typeface.create(Typeface.SANS_SERIF, Typeface.BOLD)); |
| 11339 | |
| 11340 | FontMetricsInt fm = mTextPaint.getFontMetricsInt(); |
| 11341 | mTextWidth = (int)mTextPaint.measureText(mText); |
| 11342 | mTextAscent = fm.ascent; |
| 11343 | mTextDescent = fm.descent; |
| 11344 | mTextHeight = fm.descent - fm.ascent; |
| 11345 | |
| 11346 | mDeltaX = getPropertyInt(tokens, 2, |
| 11347 | TypedValue.COMPLEX_UNIT_PX, mTextWidth*2, dm); |
| 11348 | mDeltaY = getPropertyInt(tokens, 3, |
| 11349 | TypedValue.COMPLEX_UNIT_PX, mTextHeight*3, dm); |
| 11350 | int shadowColor = getPropertyInt(tokens, 4, |
| 11351 | TypedValue.COMPLEX_UNIT_PX, 0xb0000000, dm); |
| 11352 | int color = getPropertyInt(tokens, 5, |
| 11353 | TypedValue.COMPLEX_UNIT_PX, 0x60ffffff, dm); |
| 11354 | int shadowRadius = getPropertyInt(tokens, 6, |
| 11355 | TypedValue.COMPLEX_UNIT_PX, 7, dm); |
| 11356 | int shadowDx = getPropertyInt(tokens, 8, |
| 11357 | TypedValue.COMPLEX_UNIT_PX, 0, dm); |
| 11358 | int shadowDy = getPropertyInt(tokens, 9, |
| 11359 | TypedValue.COMPLEX_UNIT_PX, 0, dm); |
| 11360 | |
| 11361 | mTextPaint.setColor(color); |
| 11362 | mTextPaint.setShadowLayer(shadowRadius, shadowDx, shadowDy, shadowColor); |
Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 11363 | |
| 11364 | try { |
| 11365 | mSurface = new Surface(session, 0, |
Dianne Hackborn | b9fb170 | 2010-08-23 16:49:02 -0700 | [diff] [blame] | 11366 | "WatermarkSurface", -1, 1, 1, PixelFormat.TRANSLUCENT, 0); |
Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 11367 | mSurface.setLayer(TYPE_LAYER_MULTIPLIER*100); |
Dianne Hackborn | b9fb170 | 2010-08-23 16:49:02 -0700 | [diff] [blame] | 11368 | mSurface.setPosition(0, 0); |
Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 11369 | mSurface.show(); |
| 11370 | } catch (OutOfResourcesException e) { |
| 11371 | } |
| 11372 | } |
| 11373 | |
| 11374 | void positionSurface(int dw, int dh) { |
Dianne Hackborn | b9fb170 | 2010-08-23 16:49:02 -0700 | [diff] [blame] | 11375 | if (mLastDW != dw || mLastDH != dh) { |
| 11376 | mLastDW = dw; |
| 11377 | mLastDH = dh; |
| 11378 | mSurface.setSize(dw, dh); |
| 11379 | mDrawNeeded = true; |
| 11380 | } |
| 11381 | } |
| 11382 | |
| 11383 | void drawIfNeeded() { |
| 11384 | if (mDrawNeeded) { |
| 11385 | final int dw = mLastDW; |
| 11386 | final int dh = mLastDH; |
| 11387 | |
| 11388 | mDrawNeeded = false; |
| 11389 | Rect dirty = new Rect(0, 0, dw, dh); |
| 11390 | Canvas c = null; |
| 11391 | try { |
| 11392 | c = mSurface.lockCanvas(dirty); |
| 11393 | } catch (IllegalArgumentException e) { |
| 11394 | } catch (OutOfResourcesException e) { |
| 11395 | } |
| 11396 | if (c != null) { |
Dianne Hackborn | ed7bfbf | 2010-11-05 13:08:35 -0700 | [diff] [blame] | 11397 | c.drawColor(0, PorterDuff.Mode.CLEAR); |
| 11398 | |
Dianne Hackborn | b9fb170 | 2010-08-23 16:49:02 -0700 | [diff] [blame] | 11399 | int deltaX = mDeltaX; |
| 11400 | int deltaY = mDeltaY; |
| 11401 | |
| 11402 | // deltaX shouldn't be close to a round fraction of our |
| 11403 | // x step, or else things will line up too much. |
| 11404 | int div = (dw+mTextWidth)/deltaX; |
| 11405 | int rem = (dw+mTextWidth) - (div*deltaX); |
| 11406 | int qdelta = deltaX/4; |
| 11407 | if (rem < qdelta || rem > (deltaX-qdelta)) { |
| 11408 | deltaX += deltaX/3; |
| 11409 | } |
| 11410 | |
| 11411 | int y = -mTextHeight; |
| 11412 | int x = -mTextWidth; |
| 11413 | while (y < (dh+mTextHeight)) { |
| 11414 | c.drawText(mText, x, y, mTextPaint); |
| 11415 | x += deltaX; |
| 11416 | if (x >= dw) { |
| 11417 | x -= (dw+mTextWidth); |
| 11418 | y += deltaY; |
| 11419 | } |
| 11420 | } |
| 11421 | mSurface.unlockCanvasAndPost(c); |
| 11422 | } |
| 11423 | } |
Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 11424 | } |
| 11425 | } |
| 11426 | |
| 11427 | void createWatermark() { |
| 11428 | if (mWatermark != null) { |
| 11429 | return; |
| 11430 | } |
| 11431 | |
Dianne Hackborn | b9fb170 | 2010-08-23 16:49:02 -0700 | [diff] [blame] | 11432 | File file = new File("/system/etc/setup.conf"); |
| 11433 | FileInputStream in = null; |
| 11434 | try { |
| 11435 | in = new FileInputStream(file); |
| 11436 | DataInputStream ind = new DataInputStream(in); |
| 11437 | String line = ind.readLine(); |
| 11438 | if (line != null) { |
| 11439 | String[] toks = line.split("%"); |
| 11440 | if (toks != null && toks.length > 0) { |
Dianne Hackborn | ed7bfbf | 2010-11-05 13:08:35 -0700 | [diff] [blame] | 11441 | mWatermark = new Watermark(mDisplay, mFxSession, toks); |
Dianne Hackborn | b9fb170 | 2010-08-23 16:49:02 -0700 | [diff] [blame] | 11442 | } |
| 11443 | } |
| 11444 | } catch (FileNotFoundException e) { |
| 11445 | } catch (IOException e) { |
| 11446 | } finally { |
| 11447 | if (in != null) { |
| 11448 | try { |
| 11449 | in.close(); |
| 11450 | } catch (IOException e) { |
| 11451 | } |
| 11452 | } |
Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 11453 | } |
Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 11454 | } |
| 11455 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11456 | @Override |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 11457 | public void statusBarVisibilityChanged(int visibility) { |
| 11458 | synchronized (mWindowMap) { |
| 11459 | final int N = mWindows.size(); |
| 11460 | for (int i = 0; i < N; i++) { |
| 11461 | WindowState ws = mWindows.get(i); |
| 11462 | try { |
| 11463 | if (ws.getAttrs().hasSystemUiListeners) { |
| 11464 | ws.mClient.dispatchSystemUiVisibilityChanged(visibility); |
| 11465 | } |
| 11466 | } catch (RemoteException e) { |
| 11467 | // so sorry |
| 11468 | } |
| 11469 | } |
| 11470 | } |
| 11471 | } |
| 11472 | |
| 11473 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11474 | public void dump(FileDescriptor fd, PrintWriter pw, String[] args) { |
| 11475 | if (mContext.checkCallingOrSelfPermission("android.permission.DUMP") |
| 11476 | != PackageManager.PERMISSION_GRANTED) { |
| 11477 | pw.println("Permission Denial: can't dump WindowManager from from pid=" |
| 11478 | + Binder.getCallingPid() |
| 11479 | + ", uid=" + Binder.getCallingUid()); |
| 11480 | return; |
| 11481 | } |
Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 11482 | |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 11483 | mInputManager.dump(pw); |
Dianne Hackborn | a2e9226 | 2010-03-02 17:19:29 -0800 | [diff] [blame] | 11484 | pw.println(" "); |
| 11485 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11486 | synchronized(mWindowMap) { |
| 11487 | pw.println("Current Window Manager state:"); |
| 11488 | for (int i=mWindows.size()-1; i>=0; i--) { |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 11489 | WindowState w = mWindows.get(i); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11490 | pw.print(" Window #"); pw.print(i); pw.print(' '); |
| 11491 | pw.print(w); pw.println(":"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11492 | w.dump(pw, " "); |
| 11493 | } |
| 11494 | if (mInputMethodDialogs.size() > 0) { |
| 11495 | pw.println(" "); |
| 11496 | pw.println(" Input method dialogs:"); |
| 11497 | for (int i=mInputMethodDialogs.size()-1; i>=0; i--) { |
| 11498 | WindowState w = mInputMethodDialogs.get(i); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11499 | 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] | 11500 | } |
| 11501 | } |
| 11502 | if (mPendingRemove.size() > 0) { |
| 11503 | pw.println(" "); |
| 11504 | pw.println(" Remove pending for:"); |
| 11505 | for (int i=mPendingRemove.size()-1; i>=0; i--) { |
| 11506 | WindowState w = mPendingRemove.get(i); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11507 | pw.print(" Remove #"); pw.print(i); pw.print(' '); |
| 11508 | pw.print(w); pw.println(":"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11509 | w.dump(pw, " "); |
| 11510 | } |
| 11511 | } |
| 11512 | if (mForceRemoves != null && mForceRemoves.size() > 0) { |
| 11513 | pw.println(" "); |
| 11514 | pw.println(" Windows force removing:"); |
| 11515 | for (int i=mForceRemoves.size()-1; i>=0; i--) { |
| 11516 | WindowState w = mForceRemoves.get(i); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11517 | pw.print(" Removing #"); pw.print(i); pw.print(' '); |
| 11518 | pw.print(w); pw.println(":"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11519 | w.dump(pw, " "); |
| 11520 | } |
| 11521 | } |
| 11522 | if (mDestroySurface.size() > 0) { |
| 11523 | pw.println(" "); |
| 11524 | pw.println(" Windows waiting to destroy their surface:"); |
| 11525 | for (int i=mDestroySurface.size()-1; i>=0; i--) { |
| 11526 | WindowState w = mDestroySurface.get(i); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11527 | pw.print(" Destroy #"); pw.print(i); pw.print(' '); |
| 11528 | pw.print(w); pw.println(":"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11529 | w.dump(pw, " "); |
| 11530 | } |
| 11531 | } |
| 11532 | if (mLosingFocus.size() > 0) { |
| 11533 | pw.println(" "); |
| 11534 | pw.println(" Windows losing focus:"); |
| 11535 | for (int i=mLosingFocus.size()-1; i>=0; i--) { |
| 11536 | WindowState w = mLosingFocus.get(i); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11537 | pw.print(" Losing #"); pw.print(i); pw.print(' '); |
| 11538 | pw.print(w); pw.println(":"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11539 | w.dump(pw, " "); |
| 11540 | } |
| 11541 | } |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 11542 | if (mResizingWindows.size() > 0) { |
| 11543 | pw.println(" "); |
| 11544 | pw.println(" Windows waiting to resize:"); |
| 11545 | for (int i=mResizingWindows.size()-1; i>=0; i--) { |
| 11546 | WindowState w = mResizingWindows.get(i); |
| 11547 | pw.print(" Resizing #"); pw.print(i); pw.print(' '); |
| 11548 | pw.print(w); pw.println(":"); |
| 11549 | w.dump(pw, " "); |
| 11550 | } |
| 11551 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11552 | if (mSessions.size() > 0) { |
| 11553 | pw.println(" "); |
| 11554 | pw.println(" All active sessions:"); |
| 11555 | Iterator<Session> it = mSessions.iterator(); |
| 11556 | while (it.hasNext()) { |
| 11557 | Session s = it.next(); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11558 | pw.print(" Session "); pw.print(s); pw.println(':'); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11559 | s.dump(pw, " "); |
| 11560 | } |
| 11561 | } |
| 11562 | if (mTokenMap.size() > 0) { |
| 11563 | pw.println(" "); |
| 11564 | pw.println(" All tokens:"); |
| 11565 | Iterator<WindowToken> it = mTokenMap.values().iterator(); |
| 11566 | while (it.hasNext()) { |
| 11567 | WindowToken token = it.next(); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11568 | pw.print(" Token "); pw.print(token.token); pw.println(':'); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11569 | token.dump(pw, " "); |
| 11570 | } |
| 11571 | } |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 11572 | if (mWallpaperTokens.size() > 0) { |
| 11573 | pw.println(" "); |
| 11574 | pw.println(" Wallpaper tokens:"); |
| 11575 | for (int i=mWallpaperTokens.size()-1; i>=0; i--) { |
| 11576 | WindowToken token = mWallpaperTokens.get(i); |
| 11577 | pw.print(" Wallpaper #"); pw.print(i); |
| 11578 | pw.print(' '); pw.print(token); pw.println(':'); |
| 11579 | token.dump(pw, " "); |
| 11580 | } |
| 11581 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11582 | if (mAppTokens.size() > 0) { |
| 11583 | pw.println(" "); |
| 11584 | pw.println(" Application tokens in Z order:"); |
| 11585 | for (int i=mAppTokens.size()-1; i>=0; i--) { |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11586 | pw.print(" App #"); pw.print(i); pw.print(": "); |
| 11587 | pw.println(mAppTokens.get(i)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11588 | } |
| 11589 | } |
| 11590 | if (mFinishedStarting.size() > 0) { |
| 11591 | pw.println(" "); |
| 11592 | pw.println(" Finishing start of application tokens:"); |
| 11593 | for (int i=mFinishedStarting.size()-1; i>=0; i--) { |
| 11594 | WindowToken token = mFinishedStarting.get(i); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11595 | pw.print(" Finished Starting #"); pw.print(i); |
| 11596 | pw.print(' '); pw.print(token); pw.println(':'); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11597 | token.dump(pw, " "); |
| 11598 | } |
| 11599 | } |
| 11600 | if (mExitingTokens.size() > 0) { |
| 11601 | pw.println(" "); |
| 11602 | pw.println(" Exiting tokens:"); |
| 11603 | for (int i=mExitingTokens.size()-1; i>=0; i--) { |
| 11604 | WindowToken token = mExitingTokens.get(i); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11605 | pw.print(" Exiting #"); pw.print(i); |
| 11606 | pw.print(' '); pw.print(token); pw.println(':'); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11607 | token.dump(pw, " "); |
| 11608 | } |
| 11609 | } |
| 11610 | if (mExitingAppTokens.size() > 0) { |
| 11611 | pw.println(" "); |
| 11612 | pw.println(" Exiting application tokens:"); |
| 11613 | for (int i=mExitingAppTokens.size()-1; i>=0; i--) { |
| 11614 | WindowToken token = mExitingAppTokens.get(i); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11615 | pw.print(" Exiting App #"); pw.print(i); |
| 11616 | pw.print(' '); pw.print(token); pw.println(':'); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11617 | token.dump(pw, " "); |
| 11618 | } |
| 11619 | } |
| 11620 | pw.println(" "); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11621 | pw.print(" mCurrentFocus="); pw.println(mCurrentFocus); |
| 11622 | pw.print(" mLastFocus="); pw.println(mLastFocus); |
| 11623 | pw.print(" mFocusedApp="); pw.println(mFocusedApp); |
| 11624 | pw.print(" mInputMethodTarget="); pw.println(mInputMethodTarget); |
| 11625 | pw.print(" mInputMethodWindow="); pw.println(mInputMethodWindow); |
Dianne Hackborn | f21adf6 | 2009-08-13 10:20:21 -0700 | [diff] [blame] | 11626 | pw.print(" mWallpaperTarget="); pw.println(mWallpaperTarget); |
Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 11627 | if (mLowerWallpaperTarget != null && mUpperWallpaperTarget != null) { |
| 11628 | pw.print(" mLowerWallpaperTarget="); pw.println(mLowerWallpaperTarget); |
| 11629 | pw.print(" mUpperWallpaperTarget="); pw.println(mUpperWallpaperTarget); |
| 11630 | } |
Dianne Hackborn | 6c8e20f | 2010-11-09 18:59:09 -0800 | [diff] [blame] | 11631 | if (mWindowDetachedWallpaper != null) { |
| 11632 | pw.print(" mWindowDetachedWallpaper="); pw.println(mWindowDetachedWallpaper); |
| 11633 | } |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 11634 | pw.print(" mCurConfiguration="); pw.println(this.mCurConfiguration); |
| 11635 | pw.print(" mInTouchMode="); pw.print(mInTouchMode); |
| 11636 | pw.print(" mLayoutSeq="); pw.println(mLayoutSeq); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11637 | pw.print(" mSystemBooted="); pw.print(mSystemBooted); |
| 11638 | pw.print(" mDisplayEnabled="); pw.println(mDisplayEnabled); |
| 11639 | pw.print(" mLayoutNeeded="); pw.print(mLayoutNeeded); |
| 11640 | pw.print(" mBlurShown="); pw.println(mBlurShown); |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11641 | if (mDimAnimator != null) { |
| 11642 | mDimAnimator.printTo(pw); |
| 11643 | } else { |
Dianne Hackborn | a2e9226 | 2010-03-02 17:19:29 -0800 | [diff] [blame] | 11644 | pw.println( " no DimAnimator "); |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11645 | } |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11646 | pw.print(" mInputMethodAnimLayerAdjustment="); |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 11647 | pw.print(mInputMethodAnimLayerAdjustment); |
| 11648 | pw.print(" mWallpaperAnimLayerAdjustment="); |
| 11649 | pw.println(mWallpaperAnimLayerAdjustment); |
Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 11650 | pw.print(" mLastWallpaperX="); pw.print(mLastWallpaperX); |
| 11651 | pw.print(" mLastWallpaperY="); pw.println(mLastWallpaperY); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11652 | pw.print(" mDisplayFrozen="); pw.print(mDisplayFrozen); |
| 11653 | pw.print(" mWindowsFreezingScreen="); pw.print(mWindowsFreezingScreen); |
Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 11654 | pw.print(" mAppsFreezingScreen="); pw.print(mAppsFreezingScreen); |
| 11655 | pw.print(" mWaitingForConfig="); pw.println(mWaitingForConfig); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11656 | pw.print(" mRotation="); pw.print(mRotation); |
| 11657 | pw.print(", mForcedAppOrientation="); pw.print(mForcedAppOrientation); |
| 11658 | pw.print(", mRequestedRotation="); pw.println(mRequestedRotation); |
Dianne Hackborn | 89ba675 | 2011-01-23 16:51:16 -0800 | [diff] [blame] | 11659 | pw.print(" mDeferredRotation="); pw.print(mDeferredRotation); |
| 11660 | pw.print(", mDeferredRotationAnimFlags="); pw.print(mDeferredRotationAnimFlags); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11661 | pw.print(" mAnimationPending="); pw.print(mAnimationPending); |
| 11662 | pw.print(" mWindowAnimationScale="); pw.print(mWindowAnimationScale); |
| 11663 | pw.print(" mTransitionWindowAnimationScale="); pw.println(mTransitionAnimationScale); |
| 11664 | pw.print(" mNextAppTransition=0x"); |
| 11665 | pw.print(Integer.toHexString(mNextAppTransition)); |
| 11666 | pw.print(", mAppTransitionReady="); pw.print(mAppTransitionReady); |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 11667 | pw.print(", mAppTransitionRunning="); pw.print(mAppTransitionRunning); |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11668 | pw.print(", mAppTransitionTimeout="); pw.println( mAppTransitionTimeout); |
Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 11669 | if (mNextAppTransitionPackage != null) { |
| 11670 | pw.print(" mNextAppTransitionPackage="); |
| 11671 | pw.print(mNextAppTransitionPackage); |
| 11672 | pw.print(", mNextAppTransitionEnter=0x"); |
| 11673 | pw.print(Integer.toHexString(mNextAppTransitionEnter)); |
| 11674 | pw.print(", mNextAppTransitionExit=0x"); |
| 11675 | pw.print(Integer.toHexString(mNextAppTransitionExit)); |
| 11676 | } |
Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11677 | pw.print(" mStartingIconInTransition="); pw.print(mStartingIconInTransition); |
| 11678 | pw.print(", mSkipAppTransitionAnimation="); pw.println(mSkipAppTransitionAnimation); |
| 11679 | if (mOpeningApps.size() > 0) { |
| 11680 | pw.print(" mOpeningApps="); pw.println(mOpeningApps); |
| 11681 | } |
| 11682 | if (mClosingApps.size() > 0) { |
| 11683 | pw.print(" mClosingApps="); pw.println(mClosingApps); |
| 11684 | } |
Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 11685 | if (mToTopApps.size() > 0) { |
| 11686 | pw.print(" mToTopApps="); pw.println(mToTopApps); |
| 11687 | } |
| 11688 | if (mToBottomApps.size() > 0) { |
| 11689 | pw.print(" mToBottomApps="); pw.println(mToBottomApps); |
| 11690 | } |
Dianne Hackborn | 87fc308 | 2010-12-03 13:09:12 -0800 | [diff] [blame] | 11691 | if (mDisplay != null) { |
| 11692 | pw.print(" DisplayWidth="); pw.print(mDisplay.getWidth()); |
| 11693 | pw.print(" DisplayHeight="); pw.println(mDisplay.getHeight()); |
| 11694 | } else { |
| 11695 | pw.println(" NO DISPLAY"); |
| 11696 | } |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 11697 | pw.println(" Policy:"); |
| 11698 | mPolicy.dump(" ", fd, pw, args); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11699 | } |
| 11700 | } |
| 11701 | |
Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 11702 | // 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] | 11703 | public void monitor() { |
| 11704 | synchronized (mWindowMap) { } |
Mike Lockwood | 983ee09 | 2009-11-22 01:42:24 -0500 | [diff] [blame] | 11705 | synchronized (mKeyguardTokenWatcher) { } |
Dianne Hackborn | ddca3ee | 2009-07-23 19:01:31 -0700 | [diff] [blame] | 11706 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 11707 | |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11708 | /** |
| 11709 | * DimAnimator class that controls the dim animation. This holds the surface and |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 11710 | * all state used for dim animation. |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11711 | */ |
| 11712 | private static class DimAnimator { |
| 11713 | Surface mDimSurface; |
| 11714 | boolean mDimShown = false; |
| 11715 | float mDimCurrentAlpha; |
| 11716 | float mDimTargetAlpha; |
| 11717 | float mDimDeltaPerMs; |
| 11718 | long mLastDimAnimTime; |
Dianne Hackborn | f83c555 | 2010-03-31 22:19:32 -0700 | [diff] [blame] | 11719 | |
| 11720 | int mLastDimWidth, mLastDimHeight; |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11721 | |
| 11722 | DimAnimator (SurfaceSession session) { |
| 11723 | if (mDimSurface == null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 11724 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11725 | + mDimSurface + ": CREATE"); |
| 11726 | try { |
Mathias Agopian | 5d26c1e | 2010-03-01 16:09:43 -0800 | [diff] [blame] | 11727 | mDimSurface = new Surface(session, 0, |
| 11728 | "DimSurface", |
| 11729 | -1, 16, 16, PixelFormat.OPAQUE, |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11730 | Surface.FX_SURFACE_DIM); |
Maciej Białka | 9ee5c22 | 2010-03-24 10:25:40 +0100 | [diff] [blame] | 11731 | mDimSurface.setAlpha(0.0f); |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11732 | } catch (Exception e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 11733 | Slog.e(TAG, "Exception creating Dim surface", e); |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11734 | } |
| 11735 | } |
| 11736 | } |
| 11737 | |
| 11738 | /** |
| 11739 | * Show the dim surface. |
| 11740 | */ |
| 11741 | void show(int dw, int dh) { |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 11742 | if (!mDimShown) { |
| 11743 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface + ": SHOW pos=(0,0) (" + |
| 11744 | dw + "x" + dh + ")"); |
| 11745 | mDimShown = true; |
| 11746 | try { |
Dianne Hackborn | f83c555 | 2010-03-31 22:19:32 -0700 | [diff] [blame] | 11747 | mLastDimWidth = dw; |
| 11748 | mLastDimHeight = dh; |
Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 11749 | mDimSurface.setPosition(0, 0); |
| 11750 | mDimSurface.setSize(dw, dh); |
| 11751 | mDimSurface.show(); |
| 11752 | } catch (RuntimeException e) { |
| 11753 | Slog.w(TAG, "Failure showing dim surface", e); |
| 11754 | } |
Dianne Hackborn | f83c555 | 2010-03-31 22:19:32 -0700 | [diff] [blame] | 11755 | } else if (mLastDimWidth != dw || mLastDimHeight != dh) { |
| 11756 | mLastDimWidth = dw; |
| 11757 | mLastDimHeight = dh; |
| 11758 | mDimSurface.setSize(dw, dh); |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11759 | } |
| 11760 | } |
| 11761 | |
| 11762 | /** |
| 11763 | * Set's the dim surface's layer and update dim parameters that will be used in |
| 11764 | * {@link updateSurface} after all windows are examined. |
| 11765 | */ |
Dianne Hackborn | 1c24e95 | 2010-11-23 00:34:30 -0800 | [diff] [blame] | 11766 | void updateParameters(Resources res, WindowState w, long currentTime) { |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11767 | mDimSurface.setLayer(w.mAnimLayer-1); |
| 11768 | |
| 11769 | final float target = w.mExiting ? 0 : w.mAttrs.dimAmount; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 11770 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 11771 | + ": layer=" + (w.mAnimLayer-1) + " target=" + target); |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11772 | if (mDimTargetAlpha != target) { |
| 11773 | // If the desired dim level has changed, then |
| 11774 | // start an animation to it. |
| 11775 | mLastDimAnimTime = currentTime; |
| 11776 | long duration = (w.mAnimating && w.mAnimation != null) |
| 11777 | ? w.mAnimation.computeDurationHint() |
| 11778 | : DEFAULT_DIM_DURATION; |
| 11779 | if (target > mDimTargetAlpha) { |
Dianne Hackborn | 1c24e95 | 2010-11-23 00:34:30 -0800 | [diff] [blame] | 11780 | TypedValue tv = new TypedValue(); |
| 11781 | res.getValue(com.android.internal.R.fraction.config_dimBehindFadeDuration, |
| 11782 | tv, true); |
| 11783 | if (tv.type == TypedValue.TYPE_FRACTION) { |
| 11784 | duration = (long)tv.getFraction((float)duration, (float)duration); |
| 11785 | } else if (tv.type >= TypedValue.TYPE_FIRST_INT |
| 11786 | && tv.type <= TypedValue.TYPE_LAST_INT) { |
| 11787 | duration = tv.data; |
| 11788 | } |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11789 | } |
| 11790 | if (duration < 1) { |
| 11791 | // Don't divide by zero |
| 11792 | duration = 1; |
| 11793 | } |
| 11794 | mDimTargetAlpha = target; |
| 11795 | mDimDeltaPerMs = (mDimTargetAlpha-mDimCurrentAlpha) / duration; |
| 11796 | } |
| 11797 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 11798 | |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11799 | /** |
| 11800 | * Updating the surface's alpha. Returns true if the animation continues, or returns |
| 11801 | * false when the animation is finished and the dim surface is hidden. |
| 11802 | */ |
| 11803 | boolean updateSurface(boolean dimming, long currentTime, boolean displayFrozen) { |
| 11804 | if (!dimming) { |
| 11805 | if (mDimTargetAlpha != 0) { |
| 11806 | mLastDimAnimTime = currentTime; |
| 11807 | mDimTargetAlpha = 0; |
| 11808 | mDimDeltaPerMs = (-mDimCurrentAlpha) / DEFAULT_DIM_DURATION; |
| 11809 | } |
| 11810 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 11811 | |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11812 | boolean animating = false; |
| 11813 | if (mLastDimAnimTime != 0) { |
| 11814 | mDimCurrentAlpha += mDimDeltaPerMs |
| 11815 | * (currentTime-mLastDimAnimTime); |
| 11816 | boolean more = true; |
| 11817 | if (displayFrozen) { |
| 11818 | // If the display is frozen, there is no reason to animate. |
| 11819 | more = false; |
| 11820 | } else if (mDimDeltaPerMs > 0) { |
| 11821 | if (mDimCurrentAlpha > mDimTargetAlpha) { |
| 11822 | more = false; |
| 11823 | } |
| 11824 | } else if (mDimDeltaPerMs < 0) { |
| 11825 | if (mDimCurrentAlpha < mDimTargetAlpha) { |
| 11826 | more = false; |
| 11827 | } |
| 11828 | } else { |
| 11829 | more = false; |
| 11830 | } |
| 11831 | |
| 11832 | // Do we need to continue animating? |
| 11833 | if (more) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 11834 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11835 | + mDimSurface + ": alpha=" + mDimCurrentAlpha); |
| 11836 | mLastDimAnimTime = currentTime; |
| 11837 | mDimSurface.setAlpha(mDimCurrentAlpha); |
| 11838 | animating = true; |
| 11839 | } else { |
| 11840 | mDimCurrentAlpha = mDimTargetAlpha; |
| 11841 | mLastDimAnimTime = 0; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 11842 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11843 | + mDimSurface + ": final alpha=" + mDimCurrentAlpha); |
| 11844 | mDimSurface.setAlpha(mDimCurrentAlpha); |
| 11845 | if (!dimming) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 11846 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11847 | + ": HIDE"); |
| 11848 | try { |
| 11849 | mDimSurface.hide(); |
| 11850 | } catch (RuntimeException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 11851 | Slog.w(TAG, "Illegal argument exception hiding dim surface"); |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11852 | } |
| 11853 | mDimShown = false; |
| 11854 | } |
| 11855 | } |
| 11856 | } |
| 11857 | return animating; |
| 11858 | } |
| 11859 | |
| 11860 | public void printTo(PrintWriter pw) { |
| 11861 | pw.print(" mDimShown="); pw.print(mDimShown); |
| 11862 | pw.print(" current="); pw.print(mDimCurrentAlpha); |
| 11863 | pw.print(" target="); pw.print(mDimTargetAlpha); |
| 11864 | pw.print(" delta="); pw.print(mDimDeltaPerMs); |
| 11865 | pw.print(" lastAnimTime="); pw.println(mLastDimAnimTime); |
| 11866 | } |
| 11867 | } |
| 11868 | |
| 11869 | /** |
| 11870 | * Animation that fade in after 0.5 interpolate time, or fade out in reverse order. |
| 11871 | * This is used for opening/closing transition for apps in compatible mode. |
| 11872 | */ |
| 11873 | private static class FadeInOutAnimation extends Animation { |
| 11874 | int mWidth; |
| 11875 | boolean mFadeIn; |
| 11876 | |
| 11877 | public FadeInOutAnimation(boolean fadeIn) { |
| 11878 | setInterpolator(new AccelerateInterpolator()); |
| 11879 | setDuration(DEFAULT_FADE_IN_OUT_DURATION); |
| 11880 | mFadeIn = fadeIn; |
| 11881 | } |
| 11882 | |
| 11883 | @Override |
| 11884 | protected void applyTransformation(float interpolatedTime, Transformation t) { |
| 11885 | float x = interpolatedTime; |
| 11886 | if (!mFadeIn) { |
| 11887 | x = 1.0f - x; // reverse the interpolation for fade out |
| 11888 | } |
| 11889 | if (x < 0.5) { |
| 11890 | // move the window out of the screen. |
| 11891 | t.getMatrix().setTranslate(mWidth, 0); |
| 11892 | } else { |
| 11893 | t.getMatrix().setTranslate(0, 0);// show |
| 11894 | t.setAlpha((x - 0.5f) * 2); |
| 11895 | } |
| 11896 | } |
| 11897 | |
| 11898 | @Override |
| 11899 | public void initialize(int width, int height, int parentWidth, int parentHeight) { |
| 11900 | // width is the screen width {@see AppWindowToken#stepAnimatinoLocked} |
| 11901 | mWidth = width; |
| 11902 | } |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11903 | |
| 11904 | @Override |
Mitsuru Oshima | 5a2b91d | 2009-07-16 16:30:02 -0700 | [diff] [blame] | 11905 | public int getZAdjustment() { |
| 11906 | return Animation.ZORDER_TOP; |
Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11907 | } |
| 11908 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11909 | } |