| 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 | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 108 | import android.view.InputChannel; |
| Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 109 | import android.view.InputDevice; |
| Jeff Brown | bbda99d | 2010-07-28 15:48:59 -0700 | [diff] [blame] | 110 | import android.view.InputEvent; |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 111 | import android.view.InputHandler; |
| 112 | import android.view.InputQueue; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 113 | import android.view.KeyEvent; |
| 114 | import android.view.MotionEvent; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 115 | import android.view.Surface; |
| 116 | import android.view.SurfaceSession; |
| 117 | import android.view.View; |
| 118 | import android.view.ViewTreeObserver; |
| 119 | import android.view.WindowManager; |
| 120 | import android.view.WindowManagerImpl; |
| 121 | import android.view.WindowManagerPolicy; |
| Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 122 | import android.view.Surface.OutOfResourcesException; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 123 | import android.view.WindowManager.LayoutParams; |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 124 | import android.view.animation.AccelerateInterpolator; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 125 | import android.view.animation.Animation; |
| 126 | import android.view.animation.AnimationUtils; |
| 127 | import android.view.animation.Transformation; |
| 128 | |
| 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 | |
| Jeff Brown | 2992ea7 | 2011-01-28 22:04:14 -0800 | [diff] [blame^] | 457 | boolean mHardKeyboardAvailable; |
| 458 | boolean mHardKeyboardEnabled; |
| 459 | OnHardKeyboardStatusChangeListener mHardKeyboardStatusChangeListener; |
| 460 | |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 461 | final ArrayList<WindowToken> mWallpaperTokens = new ArrayList<WindowToken>(); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 462 | |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 463 | // If non-null, this is the currently visible window that is associated |
| 464 | // with the wallpaper. |
| 465 | WindowState mWallpaperTarget = null; |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 466 | // If non-null, we are in the middle of animating from one wallpaper target |
| 467 | // to another, and this is the lower one in Z-order. |
| 468 | WindowState mLowerWallpaperTarget = null; |
| 469 | // If non-null, we are in the middle of animating from one wallpaper target |
| 470 | // to another, and this is the higher one in Z-order. |
| 471 | WindowState mUpperWallpaperTarget = null; |
| Dianne Hackborn | 6c8e20f | 2010-11-09 18:59:09 -0800 | [diff] [blame] | 472 | // Window currently running an animation that has requested it be detached |
| 473 | // from the wallpaper. This means we need to ensure the wallpaper is |
| 474 | // visible behind it in case it animates in a way that would allow it to be |
| 475 | // seen. |
| 476 | WindowState mWindowDetachedWallpaper = null; |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 477 | int mWallpaperAnimLayerAdjustment; |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 478 | float mLastWallpaperX = -1; |
| 479 | float mLastWallpaperY = -1; |
| Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 480 | float mLastWallpaperXStep = -1; |
| 481 | float mLastWallpaperYStep = -1; |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 482 | // This is set when we are waiting for a wallpaper to tell us it is done |
| 483 | // changing its scroll position. |
| 484 | WindowState mWaitingOnWallpaper; |
| 485 | // The last time we had a timeout when waiting for a wallpaper. |
| 486 | long mLastWallpaperTimeoutTime; |
| 487 | // We give a wallpaper up to 150ms to finish scrolling. |
| 488 | static final long WALLPAPER_TIMEOUT = 150; |
| 489 | // Time we wait after a timeout before trying to wait again. |
| 490 | static final long WALLPAPER_TIMEOUT_RECOVERY = 10000; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 491 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 492 | AppWindowToken mFocusedApp = null; |
| 493 | |
| 494 | PowerManagerService mPowerManager; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 495 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 496 | float mWindowAnimationScale = 1.0f; |
| 497 | float mTransitionAnimationScale = 1.0f; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 498 | |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 499 | final InputManager mInputManager; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 500 | |
| 501 | // Who is holding the screen on. |
| 502 | Session mHoldingScreenOn; |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 503 | PowerManager.WakeLock mHoldingScreenWakeLock; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 504 | |
| Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 505 | boolean mTurnOnScreen; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 506 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 507 | /** |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 508 | * Drag/drop state |
| 509 | */ |
| 510 | class DragState { |
| 511 | IBinder mToken; |
| 512 | Surface mSurface; |
| Christopher Tate | 02d2b3b | 2011-01-10 20:43:53 -0800 | [diff] [blame] | 513 | int mFlags; |
| Chris Tate | 7b362e4 | 2010-11-04 16:02:52 -0700 | [diff] [blame] | 514 | IBinder mLocalWin; |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 515 | ClipData mData; |
| 516 | ClipDescription mDataDescription; |
| Chris Tate | d4533f14 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 517 | boolean mDragResult; |
| Chris Tate | b478f46 | 2010-10-15 16:02:26 -0700 | [diff] [blame] | 518 | float mCurrentX, mCurrentY; |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 519 | float mThumbOffsetX, mThumbOffsetY; |
| 520 | InputChannel mServerChannel, mClientChannel; |
| 521 | WindowState mTargetWindow; |
| 522 | ArrayList<WindowState> mNotifiedWindows; |
| Christopher Tate | 5ada6cb | 2010-10-05 14:15:29 -0700 | [diff] [blame] | 523 | boolean mDragInProgress; |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 524 | |
| Jeff Brown | fbf0977 | 2011-01-16 14:06:57 -0800 | [diff] [blame] | 525 | private final Region mTmpRegion = new Region(); |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 526 | |
| Christopher Tate | 02d2b3b | 2011-01-10 20:43:53 -0800 | [diff] [blame] | 527 | DragState(IBinder token, Surface surface, int flags, IBinder localWin) { |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 528 | mToken = token; |
| 529 | mSurface = surface; |
| Christopher Tate | 02d2b3b | 2011-01-10 20:43:53 -0800 | [diff] [blame] | 530 | mFlags = flags; |
| Chris Tate | 7b362e4 | 2010-11-04 16:02:52 -0700 | [diff] [blame] | 531 | mLocalWin = localWin; |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 532 | mNotifiedWindows = new ArrayList<WindowState>(); |
| 533 | } |
| 534 | |
| 535 | void reset() { |
| 536 | if (mSurface != null) { |
| 537 | mSurface.destroy(); |
| 538 | } |
| 539 | mSurface = null; |
| Christopher Tate | 02d2b3b | 2011-01-10 20:43:53 -0800 | [diff] [blame] | 540 | mFlags = 0; |
| Chris Tate | 7b362e4 | 2010-11-04 16:02:52 -0700 | [diff] [blame] | 541 | mLocalWin = null; |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 542 | mToken = null; |
| 543 | mData = null; |
| 544 | mThumbOffsetX = mThumbOffsetY = 0; |
| 545 | mNotifiedWindows = null; |
| 546 | } |
| 547 | |
| 548 | void register() { |
| 549 | if (DEBUG_DRAG) Slog.d(TAG, "registering drag input channel"); |
| 550 | if (mClientChannel != null) { |
| 551 | Slog.e(TAG, "Duplicate register of drag input channel"); |
| 552 | } else { |
| 553 | InputChannel[] channels = InputChannel.openInputChannelPair("drag"); |
| 554 | mServerChannel = channels[0]; |
| 555 | mClientChannel = channels[1]; |
| Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame] | 556 | mInputManager.registerInputChannel(mServerChannel, null); |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 557 | InputQueue.registerInputChannel(mClientChannel, mDragInputHandler, |
| 558 | mH.getLooper().getQueue()); |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | void unregister() { |
| 563 | if (DEBUG_DRAG) Slog.d(TAG, "unregistering drag input channel"); |
| 564 | if (mClientChannel == null) { |
| 565 | Slog.e(TAG, "Unregister of nonexistent drag input channel"); |
| 566 | } else { |
| 567 | mInputManager.unregisterInputChannel(mServerChannel); |
| 568 | InputQueue.unregisterInputChannel(mClientChannel); |
| 569 | mClientChannel.dispose(); |
| Chris Tate | ef70a07 | 2010-10-22 19:10:34 -0700 | [diff] [blame] | 570 | mServerChannel.dispose(); |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 571 | mClientChannel = null; |
| 572 | mServerChannel = null; |
| 573 | } |
| 574 | } |
| 575 | |
| Chris Tate | a32dcf7 | 2010-10-14 12:13:50 -0700 | [diff] [blame] | 576 | int getDragLayerLw() { |
| 577 | return mPolicy.windowTypeToLayerLw(WindowManager.LayoutParams.TYPE_DRAG) |
| 578 | * TYPE_LAYER_MULTIPLIER |
| 579 | + TYPE_LAYER_OFFSET; |
| 580 | } |
| 581 | |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 582 | /* call out to each visible window/session informing it about the drag |
| 583 | */ |
| Chris Tate | b8203e9 | 2010-10-12 14:23:21 -0700 | [diff] [blame] | 584 | void broadcastDragStartedLw(final float touchX, final float touchY) { |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 585 | // Cache a base-class instance of the clip metadata so that parceling |
| 586 | // works correctly in calling out to the apps. |
| Christopher Tate | 1fc014f | 2011-01-19 12:56:26 -0800 | [diff] [blame] | 587 | mDataDescription = (mData != null) ? mData.getDescription() : null; |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 588 | mNotifiedWindows.clear(); |
| Christopher Tate | 5ada6cb | 2010-10-05 14:15:29 -0700 | [diff] [blame] | 589 | mDragInProgress = true; |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 590 | |
| 591 | if (DEBUG_DRAG) { |
| Chris Tate | b478f46 | 2010-10-15 16:02:26 -0700 | [diff] [blame] | 592 | Slog.d(TAG, "broadcasting DRAG_STARTED at (" + touchX + ", " + touchY + ")"); |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 593 | } |
| 594 | |
| Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 595 | final int N = mWindows.size(); |
| 596 | for (int i = 0; i < N; i++) { |
| Chris Tate | b478f46 | 2010-10-15 16:02:26 -0700 | [diff] [blame] | 597 | sendDragStartedLw(mWindows.get(i), touchX, touchY, mDataDescription); |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 598 | } |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 599 | } |
| 600 | |
| 601 | /* helper - send a caller-provided event, presumed to be DRAG_STARTED, if the |
| 602 | * designated window is potentially a drop recipient. There are race situations |
| 603 | * around DRAG_ENDED broadcast, so we make sure that once we've declared that |
| 604 | * 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] | 605 | * |
| 606 | * This method clones the 'event' parameter if it's being delivered to the same |
| 607 | * 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] | 608 | */ |
| Chris Tate | b478f46 | 2010-10-15 16:02:26 -0700 | [diff] [blame] | 609 | private void sendDragStartedLw(WindowState newWin, float touchX, float touchY, |
| 610 | ClipDescription desc) { |
| Chris Tate | 7b362e4 | 2010-11-04 16:02:52 -0700 | [diff] [blame] | 611 | // Don't actually send the event if the drag is supposed to be pinned |
| 612 | // to the originating window but 'newWin' is not that window. |
| Christopher Tate | 02d2b3b | 2011-01-10 20:43:53 -0800 | [diff] [blame] | 613 | if ((mFlags & View.DRAG_FLAG_GLOBAL) == 0) { |
| Chris Tate | 7b362e4 | 2010-11-04 16:02:52 -0700 | [diff] [blame] | 614 | final IBinder winBinder = newWin.mClient.asBinder(); |
| 615 | if (winBinder != mLocalWin) { |
| 616 | if (DEBUG_DRAG) { |
| 617 | Slog.d(TAG, "Not dispatching local DRAG_STARTED to " + newWin); |
| 618 | } |
| 619 | return; |
| 620 | } |
| 621 | } |
| 622 | |
| Christopher Tate | 5ada6cb | 2010-10-05 14:15:29 -0700 | [diff] [blame] | 623 | if (mDragInProgress && newWin.isPotentialDragTarget()) { |
| Chris Tate | b478f46 | 2010-10-15 16:02:26 -0700 | [diff] [blame] | 624 | DragEvent event = DragEvent.obtain(DragEvent.ACTION_DRAG_STARTED, |
| 625 | touchX - newWin.mFrame.left, touchY - newWin.mFrame.top, |
| Christopher Tate | 407b4e9 | 2010-11-30 17:14:08 -0800 | [diff] [blame] | 626 | null, desc, null, false); |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 627 | try { |
| 628 | newWin.mClient.dispatchDragEvent(event); |
| 629 | // track each window that we've notified that the drag is starting |
| 630 | mNotifiedWindows.add(newWin); |
| 631 | } catch (RemoteException e) { |
| 632 | Slog.w(TAG, "Unable to drag-start window " + newWin); |
| Chris Tate | b478f46 | 2010-10-15 16:02:26 -0700 | [diff] [blame] | 633 | } finally { |
| 634 | // if the callee was local, the dispatch has already recycled the event |
| 635 | if (Process.myPid() != newWin.mSession.mPid) { |
| 636 | event.recycle(); |
| 637 | } |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 638 | } |
| 639 | } |
| 640 | } |
| 641 | |
| 642 | /* helper - construct and send a DRAG_STARTED event only if the window has not |
| 643 | * previously been notified, i.e. it became visible after the drag operation |
| 644 | * was begun. This is a rare case. |
| 645 | */ |
| 646 | private void sendDragStartedIfNeededLw(WindowState newWin) { |
| Christopher Tate | 5ada6cb | 2010-10-05 14:15:29 -0700 | [diff] [blame] | 647 | if (mDragInProgress) { |
| 648 | // If we have sent the drag-started, we needn't do so again |
| 649 | for (WindowState ws : mNotifiedWindows) { |
| 650 | if (ws == newWin) { |
| 651 | return; |
| 652 | } |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 653 | } |
| Christopher Tate | 5ada6cb | 2010-10-05 14:15:29 -0700 | [diff] [blame] | 654 | if (DEBUG_DRAG) { |
| Chris Tate | ef70a07 | 2010-10-22 19:10:34 -0700 | [diff] [blame] | 655 | Slog.d(TAG, "need to send DRAG_STARTED to new window " + newWin); |
| Christopher Tate | 5ada6cb | 2010-10-05 14:15:29 -0700 | [diff] [blame] | 656 | } |
| Chris Tate | b478f46 | 2010-10-15 16:02:26 -0700 | [diff] [blame] | 657 | sendDragStartedLw(newWin, mCurrentX, mCurrentY, mDataDescription); |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 658 | } |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 659 | } |
| 660 | |
| Chris Tate | d4533f14 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 661 | void broadcastDragEndedLw() { |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 662 | if (DEBUG_DRAG) { |
| 663 | Slog.d(TAG, "broadcasting DRAG_ENDED"); |
| 664 | } |
| Chris Tate | d4533f14 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 665 | DragEvent evt = DragEvent.obtain(DragEvent.ACTION_DRAG_ENDED, |
| Christopher Tate | 407b4e9 | 2010-11-30 17:14:08 -0800 | [diff] [blame] | 666 | 0, 0, null, null, null, mDragResult); |
| Chris Tate | d4533f14 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 667 | for (WindowState ws: mNotifiedWindows) { |
| 668 | try { |
| 669 | ws.mClient.dispatchDragEvent(evt); |
| 670 | } catch (RemoteException e) { |
| 671 | Slog.w(TAG, "Unable to drag-end window " + ws); |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 672 | } |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 673 | } |
| Chris Tate | d4533f14 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 674 | mNotifiedWindows.clear(); |
| 675 | mDragInProgress = false; |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 676 | evt.recycle(); |
| 677 | } |
| 678 | |
| Chris Tate | d4533f14 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 679 | void endDragLw() { |
| 680 | mDragState.broadcastDragEndedLw(); |
| 681 | |
| 682 | // stop intercepting input |
| 683 | mDragState.unregister(); |
| Jeff Brown | 2e44b07 | 2011-01-24 15:21:56 -0800 | [diff] [blame] | 684 | mInputMonitor.updateInputWindowsLw(true /*force*/); |
| Chris Tate | d4533f14 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 685 | |
| 686 | // free our resources and drop all the object references |
| 687 | mDragState.reset(); |
| 688 | mDragState = null; |
| Christopher Tate | ccd24de | 2011-01-12 15:02:55 -0800 | [diff] [blame] | 689 | |
| Dianne Hackborn | 89ba675 | 2011-01-23 16:51:16 -0800 | [diff] [blame] | 690 | if (DEBUG_ORIENTATION) Slog.d(TAG, "Performing post-drag rotation"); |
| 691 | boolean changed = setRotationUncheckedLocked( |
| 692 | WindowManagerPolicy.USE_LAST_ROTATION, 0, false); |
| 693 | if (changed) { |
| 694 | sendNewConfiguration(); |
| Christopher Tate | ccd24de | 2011-01-12 15:02:55 -0800 | [diff] [blame] | 695 | } |
| Chris Tate | d4533f14 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 696 | } |
| 697 | |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 698 | void notifyMoveLw(float x, float y) { |
| Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 699 | final int myPid = Process.myPid(); |
| 700 | |
| 701 | // Move the surface to the given touch |
| Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 702 | if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION notifyMoveLw"); |
| Christopher Tate | f01af75 | 2011-01-19 16:22:07 -0800 | [diff] [blame] | 703 | Surface.openTransaction(); |
| Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 704 | try { |
| 705 | mSurface.setPosition((int)(x - mThumbOffsetX), (int)(y - mThumbOffsetY)); |
| 706 | } finally { |
| Christopher Tate | f01af75 | 2011-01-19 16:22:07 -0800 | [diff] [blame] | 707 | Surface.closeTransaction(); |
| Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 708 | if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION notifyMoveLw"); |
| 709 | } |
| Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 710 | |
| 711 | // Tell the affected window |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 712 | WindowState touchedWin = getTouchedWinAtPointLw(x, y); |
| Christopher Tate | f01af75 | 2011-01-19 16:22:07 -0800 | [diff] [blame] | 713 | if (touchedWin == null) { |
| 714 | if (DEBUG_DRAG) Slog.d(TAG, "No touched win at x=" + x + " y=" + y); |
| 715 | return; |
| 716 | } |
| Christopher Tate | 02d2b3b | 2011-01-10 20:43:53 -0800 | [diff] [blame] | 717 | if ((mFlags & View.DRAG_FLAG_GLOBAL) == 0) { |
| Chris Tate | 7b362e4 | 2010-11-04 16:02:52 -0700 | [diff] [blame] | 718 | final IBinder touchedBinder = touchedWin.mClient.asBinder(); |
| 719 | if (touchedBinder != mLocalWin) { |
| 720 | // This drag is pinned only to the originating window, but the drag |
| 721 | // point is outside that window. Pretend it's over empty space. |
| 722 | touchedWin = null; |
| 723 | } |
| 724 | } |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 725 | try { |
| 726 | // have we dragged over a new window? |
| 727 | if ((touchedWin != mTargetWindow) && (mTargetWindow != null)) { |
| 728 | if (DEBUG_DRAG) { |
| 729 | Slog.d(TAG, "sending DRAG_EXITED to " + mTargetWindow); |
| 730 | } |
| 731 | // force DRAG_EXITED_EVENT if appropriate |
| 732 | DragEvent evt = DragEvent.obtain(DragEvent.ACTION_DRAG_EXITED, |
| Chris Tate | b478f46 | 2010-10-15 16:02:26 -0700 | [diff] [blame] | 733 | x - mTargetWindow.mFrame.left, y - mTargetWindow.mFrame.top, |
| Christopher Tate | 407b4e9 | 2010-11-30 17:14:08 -0800 | [diff] [blame] | 734 | null, null, null, false); |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 735 | mTargetWindow.mClient.dispatchDragEvent(evt); |
| Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 736 | if (myPid != mTargetWindow.mSession.mPid) { |
| 737 | evt.recycle(); |
| 738 | } |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 739 | } |
| 740 | if (touchedWin != null) { |
| Chris Tate | 9d1ab88 | 2010-11-02 15:55:39 -0700 | [diff] [blame] | 741 | if (false && DEBUG_DRAG) { |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 742 | Slog.d(TAG, "sending DRAG_LOCATION to " + touchedWin); |
| 743 | } |
| 744 | DragEvent evt = DragEvent.obtain(DragEvent.ACTION_DRAG_LOCATION, |
| Chris Tate | b478f46 | 2010-10-15 16:02:26 -0700 | [diff] [blame] | 745 | x - touchedWin.mFrame.left, y - touchedWin.mFrame.top, |
| Christopher Tate | 407b4e9 | 2010-11-30 17:14:08 -0800 | [diff] [blame] | 746 | null, null, null, false); |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 747 | touchedWin.mClient.dispatchDragEvent(evt); |
| Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 748 | if (myPid != touchedWin.mSession.mPid) { |
| 749 | evt.recycle(); |
| 750 | } |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 751 | } |
| 752 | } catch (RemoteException e) { |
| 753 | Slog.w(TAG, "can't send drag notification to windows"); |
| 754 | } |
| 755 | mTargetWindow = touchedWin; |
| 756 | } |
| 757 | |
| Chris Tate | d4533f14 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 758 | // Tell the drop target about the data. Returns 'true' if we can immediately |
| 759 | // dispatch the global drag-ended message, 'false' if we need to wait for a |
| 760 | // result from the recipient. |
| 761 | boolean notifyDropLw(float x, float y) { |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 762 | WindowState touchedWin = getTouchedWinAtPointLw(x, y); |
| Chris Tate | d4533f14 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 763 | if (touchedWin == null) { |
| 764 | // "drop" outside a valid window -- no recipient to apply a |
| 765 | // timeout to, and we can send the drag-ended message immediately. |
| 766 | mDragResult = false; |
| 767 | return true; |
| 768 | } |
| 769 | |
| 770 | if (DEBUG_DRAG) { |
| 771 | Slog.d(TAG, "sending DROP to " + touchedWin); |
| 772 | } |
| 773 | final int myPid = Process.myPid(); |
| 774 | final IBinder token = touchedWin.mClient.asBinder(); |
| 775 | DragEvent evt = DragEvent.obtain(DragEvent.ACTION_DROP, |
| 776 | x - touchedWin.mFrame.left, y - touchedWin.mFrame.top, |
| Christopher Tate | 407b4e9 | 2010-11-30 17:14:08 -0800 | [diff] [blame] | 777 | null, null, mData, false); |
| Chris Tate | d4533f14 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 778 | try { |
| 779 | touchedWin.mClient.dispatchDragEvent(evt); |
| 780 | |
| 781 | // 5 second timeout for this window to respond to the drop |
| 782 | mH.removeMessages(H.DRAG_END_TIMEOUT, token); |
| 783 | Message msg = mH.obtainMessage(H.DRAG_END_TIMEOUT, token); |
| 784 | mH.sendMessageDelayed(msg, 5000); |
| 785 | } catch (RemoteException e) { |
| 786 | Slog.w(TAG, "can't send drop notification to win " + touchedWin); |
| 787 | return true; |
| 788 | } finally { |
| Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 789 | if (myPid != touchedWin.mSession.mPid) { |
| 790 | evt.recycle(); |
| 791 | } |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 792 | } |
| Chris Tate | d4533f14 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 793 | mToken = token; |
| 794 | return false; |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 795 | } |
| 796 | |
| 797 | // Find the visible, touch-deliverable window under the given point |
| 798 | private WindowState getTouchedWinAtPointLw(float xf, float yf) { |
| 799 | WindowState touchedWin = null; |
| 800 | final int x = (int) xf; |
| 801 | final int y = (int) yf; |
| 802 | final ArrayList<WindowState> windows = mWindows; |
| 803 | final int N = windows.size(); |
| 804 | for (int i = N - 1; i >= 0; i--) { |
| 805 | WindowState child = windows.get(i); |
| 806 | final int flags = child.mAttrs.flags; |
| 807 | if (!child.isVisibleLw()) { |
| 808 | // not visible == don't tell about drags |
| 809 | continue; |
| 810 | } |
| 811 | if ((flags & WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE) != 0) { |
| 812 | // not touchable == don't tell about drags |
| 813 | continue; |
| 814 | } |
| Jeff Brown | fbf0977 | 2011-01-16 14:06:57 -0800 | [diff] [blame] | 815 | |
| 816 | child.getTouchableRegion(mTmpRegion); |
| 817 | |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 818 | final int touchFlags = flags & |
| Jeff Brown | fbf0977 | 2011-01-16 14:06:57 -0800 | [diff] [blame] | 819 | (WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE |
| 820 | | WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL); |
| 821 | if (mTmpRegion.contains(x, y) || touchFlags == 0) { |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 822 | // Found it |
| 823 | touchedWin = child; |
| 824 | break; |
| 825 | } |
| 826 | } |
| 827 | |
| 828 | return touchedWin; |
| 829 | } |
| 830 | } |
| 831 | |
| 832 | DragState mDragState = null; |
| 833 | private final InputHandler mDragInputHandler = new BaseInputHandler() { |
| 834 | @Override |
| Jeff Brown | 3915bb8 | 2010-11-05 15:02:16 -0700 | [diff] [blame] | 835 | public void handleMotion(MotionEvent event, InputQueue.FinishedCallback finishedCallback) { |
| 836 | boolean handled = false; |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 837 | try { |
| Jeff Brown | 3915bb8 | 2010-11-05 15:02:16 -0700 | [diff] [blame] | 838 | if ((event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0 |
| 839 | && mDragState != null) { |
| 840 | boolean endDrag = false; |
| 841 | final float newX = event.getRawX(); |
| 842 | final float newY = event.getRawY(); |
| 843 | |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 844 | switch (event.getAction()) { |
| 845 | case MotionEvent.ACTION_DOWN: { |
| 846 | if (DEBUG_DRAG) { |
| 847 | Slog.w(TAG, "Unexpected ACTION_DOWN in drag layer"); |
| 848 | } |
| 849 | } break; |
| 850 | |
| 851 | case MotionEvent.ACTION_MOVE: { |
| 852 | synchronized (mWindowMap) { |
| Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 853 | // move the surface and tell the involved window(s) where we are |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 854 | mDragState.notifyMoveLw(newX, newY); |
| 855 | } |
| 856 | } break; |
| 857 | |
| 858 | case MotionEvent.ACTION_UP: { |
| 859 | if (DEBUG_DRAG) Slog.d(TAG, "Got UP on move channel; dropping at " |
| 860 | + newX + "," + newY); |
| 861 | synchronized (mWindowMap) { |
| Chris Tate | d4533f14 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 862 | endDrag = mDragState.notifyDropLw(newX, newY); |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 863 | } |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 864 | } break; |
| 865 | |
| 866 | case MotionEvent.ACTION_CANCEL: { |
| 867 | if (DEBUG_DRAG) Slog.d(TAG, "Drag cancelled!"); |
| 868 | endDrag = true; |
| 869 | } break; |
| 870 | } |
| 871 | |
| 872 | if (endDrag) { |
| 873 | if (DEBUG_DRAG) Slog.d(TAG, "Drag ended; tearing down state"); |
| 874 | // tell all the windows that the drag has ended |
| Chris Tate | 5994359 | 2010-10-11 20:33:44 -0700 | [diff] [blame] | 875 | synchronized (mWindowMap) { |
| Chris Tate | d4533f14 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 876 | mDragState.endDragLw(); |
| Chris Tate | 5994359 | 2010-10-11 20:33:44 -0700 | [diff] [blame] | 877 | } |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 878 | } |
| Jeff Brown | 3915bb8 | 2010-11-05 15:02:16 -0700 | [diff] [blame] | 879 | |
| 880 | handled = true; |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 881 | } |
| 882 | } catch (Exception e) { |
| 883 | Slog.e(TAG, "Exception caught by drag handleMotion", e); |
| 884 | } finally { |
| Jeff Brown | 3915bb8 | 2010-11-05 15:02:16 -0700 | [diff] [blame] | 885 | finishedCallback.finished(handled); |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 886 | } |
| 887 | } |
| 888 | }; |
| 889 | |
| 890 | /** |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 891 | * Whether the UI is currently running in touch mode (not showing |
| 892 | * navigational focus because the user is directly pressing the screen). |
| 893 | */ |
| 894 | boolean mInTouchMode = false; |
| 895 | |
| 896 | private ViewServer mViewServer; |
| Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 897 | private ArrayList<WindowChangeListener> mWindowChangeListeners = |
| 898 | new ArrayList<WindowChangeListener>(); |
| 899 | private boolean mWindowsChanged = false; |
| 900 | |
| 901 | public interface WindowChangeListener { |
| 902 | public void windowsChanged(); |
| Konstantin Lopyrev | 6e0f65f | 2010-07-14 14:55:33 -0700 | [diff] [blame] | 903 | public void focusChanged(); |
| Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 904 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 905 | |
| Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 906 | final Configuration mTempConfiguration = new Configuration(); |
| Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 907 | int mScreenLayout = Configuration.SCREENLAYOUT_SIZE_UNDEFINED; |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 908 | |
| 909 | // The frame use to limit the size of the app running in compatibility mode. |
| 910 | Rect mCompatibleScreenFrame = new Rect(); |
| 911 | // The surface used to fill the outer rim of the app running in compatibility mode. |
| 912 | Surface mBackgroundFillerSurface = null; |
| 913 | boolean mBackgroundFillerShown = false; |
| 914 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 915 | public static WindowManagerService main(Context context, |
| 916 | PowerManagerService pm, boolean haveInputMethods) { |
| 917 | WMThread thr = new WMThread(context, pm, haveInputMethods); |
| 918 | thr.start(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 919 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 920 | synchronized (thr) { |
| 921 | while (thr.mService == null) { |
| 922 | try { |
| 923 | thr.wait(); |
| 924 | } catch (InterruptedException e) { |
| 925 | } |
| 926 | } |
| 927 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 928 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 929 | return thr.mService; |
| 930 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 931 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 932 | static class WMThread extends Thread { |
| 933 | WindowManagerService mService; |
| 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 | private final Context mContext; |
| 936 | private final PowerManagerService mPM; |
| 937 | private final boolean mHaveInputMethods; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 938 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 939 | public WMThread(Context context, PowerManagerService pm, |
| 940 | boolean haveInputMethods) { |
| 941 | super("WindowManager"); |
| 942 | mContext = context; |
| 943 | mPM = pm; |
| 944 | mHaveInputMethods = haveInputMethods; |
| 945 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 946 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 947 | public void run() { |
| 948 | Looper.prepare(); |
| 949 | WindowManagerService s = new WindowManagerService(mContext, mPM, |
| 950 | mHaveInputMethods); |
| 951 | android.os.Process.setThreadPriority( |
| 952 | android.os.Process.THREAD_PRIORITY_DISPLAY); |
| Christopher Tate | 160edb3 | 2010-06-30 17:46:30 -0700 | [diff] [blame] | 953 | android.os.Process.setCanSelfBackground(false); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 954 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 955 | synchronized (this) { |
| 956 | mService = s; |
| 957 | notifyAll(); |
| 958 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 959 | |
| Brad Fitzpatrick | ec062f6 | 2010-11-03 09:56:54 -0700 | [diff] [blame] | 960 | // For debug builds, log event loop stalls to dropbox for analysis. |
| 961 | if (StrictMode.conditionallyEnableDebugLogging()) { |
| 962 | Slog.i(TAG, "Enabled StrictMode logging for WMThread's Looper"); |
| 963 | } |
| 964 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 965 | Looper.loop(); |
| 966 | } |
| 967 | } |
| 968 | |
| 969 | static class PolicyThread extends Thread { |
| 970 | private final WindowManagerPolicy mPolicy; |
| 971 | private final WindowManagerService mService; |
| 972 | private final Context mContext; |
| 973 | private final PowerManagerService mPM; |
| 974 | boolean mRunning = false; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 975 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 976 | public PolicyThread(WindowManagerPolicy policy, |
| 977 | WindowManagerService service, Context context, |
| 978 | PowerManagerService pm) { |
| 979 | super("WindowManagerPolicy"); |
| 980 | mPolicy = policy; |
| 981 | mService = service; |
| 982 | mContext = context; |
| 983 | mPM = pm; |
| 984 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 985 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 986 | public void run() { |
| 987 | Looper.prepare(); |
| Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 988 | WindowManagerPolicyThread.set(this, Looper.myLooper()); |
| 989 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 990 | //Looper.myLooper().setMessageLogging(new LogPrinter( |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 991 | // Log.VERBOSE, "WindowManagerPolicy", Log.LOG_ID_SYSTEM)); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 992 | android.os.Process.setThreadPriority( |
| 993 | android.os.Process.THREAD_PRIORITY_FOREGROUND); |
| Christopher Tate | 160edb3 | 2010-06-30 17:46:30 -0700 | [diff] [blame] | 994 | android.os.Process.setCanSelfBackground(false); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 995 | mPolicy.init(mContext, mService, mPM); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 996 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 997 | synchronized (this) { |
| 998 | mRunning = true; |
| 999 | notifyAll(); |
| 1000 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1001 | |
| Brad Fitzpatrick | ec062f6 | 2010-11-03 09:56:54 -0700 | [diff] [blame] | 1002 | // For debug builds, log event loop stalls to dropbox for analysis. |
| 1003 | if (StrictMode.conditionallyEnableDebugLogging()) { |
| 1004 | Slog.i(TAG, "Enabled StrictMode for PolicyThread's Looper"); |
| 1005 | } |
| 1006 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1007 | Looper.loop(); |
| 1008 | } |
| 1009 | } |
| 1010 | |
| 1011 | private WindowManagerService(Context context, PowerManagerService pm, |
| 1012 | boolean haveInputMethods) { |
| 1013 | mContext = context; |
| 1014 | mHaveInputMethods = haveInputMethods; |
| 1015 | mLimitedAlphaCompositing = context.getResources().getBoolean( |
| 1016 | com.android.internal.R.bool.config_sf_limitedAlpha); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1017 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1018 | mPowerManager = pm; |
| 1019 | mPowerManager.setPolicy(mPolicy); |
| 1020 | PowerManager pmc = (PowerManager)context.getSystemService(Context.POWER_SERVICE); |
| 1021 | mScreenFrozenLock = pmc.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, |
| 1022 | "SCREEN_FROZEN"); |
| 1023 | mScreenFrozenLock.setReferenceCounted(false); |
| 1024 | |
| 1025 | mActivityManager = ActivityManagerNative.getDefault(); |
| 1026 | mBatteryStats = BatteryStatsService.getService(); |
| 1027 | |
| 1028 | // Get persisted window scale setting |
| 1029 | mWindowAnimationScale = Settings.System.getFloat(context.getContentResolver(), |
| 1030 | Settings.System.WINDOW_ANIMATION_SCALE, mWindowAnimationScale); |
| 1031 | mTransitionAnimationScale = Settings.System.getFloat(context.getContentResolver(), |
| 1032 | Settings.System.TRANSITION_ANIMATION_SCALE, mTransitionAnimationScale); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1033 | |
| Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 1034 | // Track changes to DevicePolicyManager state so we can enable/disable keyguard. |
| 1035 | IntentFilter filter = new IntentFilter(); |
| 1036 | filter.addAction(DevicePolicyManager.ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED); |
| 1037 | mContext.registerReceiver(mBroadcastReceiver, filter); |
| 1038 | |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1039 | mHoldingScreenWakeLock = pmc.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK, |
| 1040 | "KEEP_SCREEN_ON_FLAG"); |
| 1041 | mHoldingScreenWakeLock.setReferenceCounted(false); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1042 | |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1043 | mInputManager = new InputManager(context, this); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1044 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1045 | PolicyThread thr = new PolicyThread(mPolicy, this, context, pm); |
| 1046 | thr.start(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1047 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1048 | synchronized (thr) { |
| 1049 | while (!thr.mRunning) { |
| 1050 | try { |
| 1051 | thr.wait(); |
| 1052 | } catch (InterruptedException e) { |
| 1053 | } |
| 1054 | } |
| 1055 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1056 | |
| Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 1057 | mInputManager.start(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1058 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1059 | // Add ourself to the Watchdog monitors. |
| 1060 | Watchdog.getInstance().addMonitor(this); |
| 1061 | } |
| 1062 | |
| 1063 | @Override |
| 1064 | public boolean onTransact(int code, Parcel data, Parcel reply, int flags) |
| 1065 | throws RemoteException { |
| 1066 | try { |
| 1067 | return super.onTransact(code, data, reply, flags); |
| 1068 | } catch (RuntimeException e) { |
| 1069 | // The window manager only throws security exceptions, so let's |
| 1070 | // log all others. |
| 1071 | if (!(e instanceof SecurityException)) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1072 | Slog.e(TAG, "Window Manager Crash", e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1073 | } |
| 1074 | throw e; |
| 1075 | } |
| 1076 | } |
| 1077 | |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1078 | private void placeWindowAfter(WindowState pos, WindowState window) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1079 | final int i = mWindows.indexOf(pos); |
| Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 1080 | 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] | 1081 | TAG, "Adding window " + window + " at " |
| 1082 | + (i+1) + " of " + mWindows.size() + " (after " + pos + ")"); |
| 1083 | mWindows.add(i+1, window); |
| Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 1084 | mWindowsChanged = true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1085 | } |
| 1086 | |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1087 | private void placeWindowBefore(WindowState pos, WindowState window) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1088 | final int i = mWindows.indexOf(pos); |
| Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 1089 | 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] | 1090 | TAG, "Adding window " + window + " at " |
| 1091 | + i + " of " + mWindows.size() + " (before " + pos + ")"); |
| 1092 | mWindows.add(i, window); |
| Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 1093 | mWindowsChanged = true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1094 | } |
| 1095 | |
| 1096 | //This method finds out the index of a window that has the same app token as |
| 1097 | //win. used for z ordering the windows in mWindows |
| 1098 | private int findIdxBasedOnAppTokens(WindowState win) { |
| 1099 | //use a local variable to cache mWindows |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1100 | ArrayList<WindowState> localmWindows = mWindows; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1101 | int jmax = localmWindows.size(); |
| 1102 | if(jmax == 0) { |
| 1103 | return -1; |
| 1104 | } |
| 1105 | for(int j = (jmax-1); j >= 0; j--) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1106 | WindowState wentry = localmWindows.get(j); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1107 | if(wentry.mAppToken == win.mAppToken) { |
| 1108 | return j; |
| 1109 | } |
| 1110 | } |
| 1111 | return -1; |
| 1112 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1113 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1114 | private void addWindowToListInOrderLocked(WindowState win, boolean addToToken) { |
| 1115 | final IWindow client = win.mClient; |
| 1116 | final WindowToken token = win.mToken; |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1117 | final ArrayList<WindowState> localmWindows = mWindows; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1118 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1119 | final int N = localmWindows.size(); |
| 1120 | final WindowState attached = win.mAttachedWindow; |
| 1121 | int i; |
| 1122 | if (attached == null) { |
| 1123 | int tokenWindowsPos = token.windows.size(); |
| 1124 | if (token.appWindowToken != null) { |
| 1125 | int index = tokenWindowsPos-1; |
| 1126 | if (index >= 0) { |
| 1127 | // If this application has existing windows, we |
| 1128 | // simply place the new window on top of them... but |
| 1129 | // keep the starting window on top. |
| 1130 | if (win.mAttrs.type == TYPE_BASE_APPLICATION) { |
| 1131 | // Base windows go behind everything else. |
| 1132 | placeWindowBefore(token.windows.get(0), win); |
| 1133 | tokenWindowsPos = 0; |
| 1134 | } else { |
| 1135 | AppWindowToken atoken = win.mAppToken; |
| 1136 | if (atoken != null && |
| 1137 | token.windows.get(index) == atoken.startingWindow) { |
| 1138 | placeWindowBefore(token.windows.get(index), win); |
| 1139 | tokenWindowsPos--; |
| 1140 | } else { |
| 1141 | int newIdx = findIdxBasedOnAppTokens(win); |
| 1142 | if(newIdx != -1) { |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1143 | //there is a window above this one associated with the same |
| 1144 | //apptoken note that the window could be a floating window |
| 1145 | //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] | 1146 | //windows associated with this token. |
| Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 1147 | if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) { |
| 1148 | Slog.v(TAG, "Adding window " + win + " at " |
| 1149 | + (newIdx+1) + " of " + N); |
| 1150 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1151 | localmWindows.add(newIdx+1, win); |
| Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 1152 | mWindowsChanged = true; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1153 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1154 | } |
| 1155 | } |
| 1156 | } else { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1157 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1158 | TAG, "Figuring out where to add app window " |
| 1159 | + client.asBinder() + " (token=" + token + ")"); |
| 1160 | // Figure out where the window should go, based on the |
| 1161 | // order of applications. |
| 1162 | final int NA = mAppTokens.size(); |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1163 | WindowState pos = null; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1164 | for (i=NA-1; i>=0; i--) { |
| 1165 | AppWindowToken t = mAppTokens.get(i); |
| 1166 | if (t == token) { |
| 1167 | i--; |
| 1168 | break; |
| 1169 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1170 | |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 1171 | // We haven't reached the token yet; if this token |
| 1172 | // is not going to the bottom and has windows, we can |
| 1173 | // use it as an anchor for when we do reach the token. |
| 1174 | if (!t.sendingToBottom && t.windows.size() > 0) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1175 | pos = t.windows.get(0); |
| 1176 | } |
| 1177 | } |
| 1178 | // We now know the index into the apps. If we found |
| 1179 | // an app window above, that gives us the position; else |
| 1180 | // we need to look some more. |
| 1181 | if (pos != null) { |
| 1182 | // Move behind any windows attached to this one. |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1183 | WindowToken atoken = mTokenMap.get(pos.mClient.asBinder()); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1184 | if (atoken != null) { |
| 1185 | final int NC = atoken.windows.size(); |
| 1186 | if (NC > 0) { |
| 1187 | WindowState bottom = atoken.windows.get(0); |
| 1188 | if (bottom.mSubLayer < 0) { |
| 1189 | pos = bottom; |
| 1190 | } |
| 1191 | } |
| 1192 | } |
| 1193 | placeWindowBefore(pos, win); |
| 1194 | } else { |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 1195 | // Continue looking down until we find the first |
| 1196 | // token that has windows. |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1197 | while (i >= 0) { |
| 1198 | AppWindowToken t = mAppTokens.get(i); |
| 1199 | final int NW = t.windows.size(); |
| 1200 | if (NW > 0) { |
| 1201 | pos = t.windows.get(NW-1); |
| 1202 | break; |
| 1203 | } |
| 1204 | i--; |
| 1205 | } |
| 1206 | if (pos != null) { |
| 1207 | // Move in front of any windows attached to this |
| 1208 | // one. |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1209 | WindowToken atoken = mTokenMap.get(pos.mClient.asBinder()); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1210 | if (atoken != null) { |
| 1211 | final int NC = atoken.windows.size(); |
| 1212 | if (NC > 0) { |
| 1213 | WindowState top = atoken.windows.get(NC-1); |
| 1214 | if (top.mSubLayer >= 0) { |
| 1215 | pos = top; |
| 1216 | } |
| 1217 | } |
| 1218 | } |
| 1219 | placeWindowAfter(pos, win); |
| 1220 | } else { |
| 1221 | // Just search for the start of this layer. |
| 1222 | final int myLayer = win.mBaseLayer; |
| 1223 | for (i=0; i<N; i++) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1224 | WindowState w = localmWindows.get(i); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1225 | if (w.mBaseLayer > myLayer) { |
| 1226 | break; |
| 1227 | } |
| 1228 | } |
| Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 1229 | if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) { |
| 1230 | Slog.v(TAG, "Adding window " + win + " at " |
| 1231 | + i + " of " + N); |
| 1232 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1233 | localmWindows.add(i, win); |
| Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 1234 | mWindowsChanged = true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1235 | } |
| 1236 | } |
| 1237 | } |
| 1238 | } else { |
| 1239 | // Figure out where window should go, based on layer. |
| 1240 | final int myLayer = win.mBaseLayer; |
| 1241 | for (i=N-1; i>=0; i--) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1242 | if (localmWindows.get(i).mBaseLayer <= myLayer) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1243 | i++; |
| 1244 | break; |
| 1245 | } |
| 1246 | } |
| 1247 | if (i < 0) i = 0; |
| Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 1248 | if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) Slog.v( |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 1249 | TAG, "Adding window " + win + " at " |
| 1250 | + i + " of " + N); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1251 | localmWindows.add(i, win); |
| Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 1252 | mWindowsChanged = true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1253 | } |
| 1254 | if (addToToken) { |
| Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 1255 | 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] | 1256 | token.windows.add(tokenWindowsPos, win); |
| 1257 | } |
| 1258 | |
| 1259 | } else { |
| 1260 | // Figure out this window's ordering relative to the window |
| 1261 | // it is attached to. |
| 1262 | final int NA = token.windows.size(); |
| 1263 | final int sublayer = win.mSubLayer; |
| 1264 | int largestSublayer = Integer.MIN_VALUE; |
| 1265 | WindowState windowWithLargestSublayer = null; |
| 1266 | for (i=0; i<NA; i++) { |
| 1267 | WindowState w = token.windows.get(i); |
| 1268 | final int wSublayer = w.mSubLayer; |
| 1269 | if (wSublayer >= largestSublayer) { |
| 1270 | largestSublayer = wSublayer; |
| 1271 | windowWithLargestSublayer = w; |
| 1272 | } |
| 1273 | if (sublayer < 0) { |
| 1274 | // For negative sublayers, we go below all windows |
| 1275 | // in the same sublayer. |
| 1276 | if (wSublayer >= sublayer) { |
| 1277 | if (addToToken) { |
| Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 1278 | 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] | 1279 | token.windows.add(i, win); |
| 1280 | } |
| 1281 | placeWindowBefore( |
| 1282 | wSublayer >= 0 ? attached : w, win); |
| 1283 | break; |
| 1284 | } |
| 1285 | } else { |
| 1286 | // For positive sublayers, we go above all windows |
| 1287 | // in the same sublayer. |
| 1288 | if (wSublayer > sublayer) { |
| 1289 | if (addToToken) { |
| Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 1290 | 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] | 1291 | token.windows.add(i, win); |
| 1292 | } |
| 1293 | placeWindowBefore(w, win); |
| 1294 | break; |
| 1295 | } |
| 1296 | } |
| 1297 | } |
| 1298 | if (i >= NA) { |
| 1299 | if (addToToken) { |
| Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 1300 | 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] | 1301 | token.windows.add(win); |
| 1302 | } |
| 1303 | if (sublayer < 0) { |
| 1304 | placeWindowBefore(attached, win); |
| 1305 | } else { |
| 1306 | placeWindowAfter(largestSublayer >= 0 |
| 1307 | ? windowWithLargestSublayer |
| 1308 | : attached, |
| 1309 | win); |
| 1310 | } |
| 1311 | } |
| 1312 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1313 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1314 | if (win.mAppToken != null && addToToken) { |
| 1315 | win.mAppToken.allAppWindows.add(win); |
| 1316 | } |
| 1317 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1318 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1319 | static boolean canBeImeTarget(WindowState w) { |
| 1320 | final int fl = w.mAttrs.flags |
| 1321 | & (FLAG_NOT_FOCUSABLE|FLAG_ALT_FOCUSABLE_IM); |
| Dianne Hackborn | e75d872 | 2011-01-27 19:37:40 -0800 | [diff] [blame] | 1322 | if (fl == 0 || fl == (FLAG_NOT_FOCUSABLE|FLAG_ALT_FOCUSABLE_IM) |
| 1323 | || w.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING) { |
| 1324 | if (DEBUG_INPUT_METHOD) { |
| 1325 | Slog.i(TAG, "isVisibleOrAdding " + w + ": " + w.isVisibleOrAdding()); |
| 1326 | if (!w.isVisibleOrAdding()) { |
| 1327 | Slog.i(TAG, " mSurface=" + w.mSurface + " reportDestroy=" + w.mReportDestroySurface |
| 1328 | + " relayoutCalled=" + w.mRelayoutCalled + " viewVis=" + w.mViewVisibility |
| 1329 | + " policyVis=" + w.mPolicyVisibility + " attachHid=" + w.mAttachedHidden |
| 1330 | + " exiting=" + w.mExiting + " destroying=" + w.mDestroying); |
| 1331 | if (w.mAppToken != null) { |
| 1332 | Slog.i(TAG, " mAppToken.hiddenRequested=" + w.mAppToken.hiddenRequested); |
| 1333 | } |
| 1334 | } |
| 1335 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1336 | return w.isVisibleOrAdding(); |
| 1337 | } |
| 1338 | return false; |
| 1339 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1340 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1341 | int findDesiredInputMethodWindowIndexLocked(boolean willMove) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1342 | final ArrayList<WindowState> localmWindows = mWindows; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1343 | final int N = localmWindows.size(); |
| 1344 | WindowState w = null; |
| 1345 | int i = N; |
| 1346 | while (i > 0) { |
| 1347 | i--; |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1348 | w = localmWindows.get(i); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1349 | |
| Dianne Hackborn | e75d872 | 2011-01-27 19:37:40 -0800 | [diff] [blame] | 1350 | if (DEBUG_INPUT_METHOD && willMove) Slog.i(TAG, "Checking window @" + i |
| 1351 | + " " + w + " fl=0x" + Integer.toHexString(w.mAttrs.flags)); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1352 | if (canBeImeTarget(w)) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1353 | //Slog.i(TAG, "Putting input method here!"); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1354 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1355 | // Yet more tricksyness! If this window is a "starting" |
| 1356 | // window, we do actually want to be on top of it, but |
| 1357 | // it is not -really- where input will go. So if the caller |
| 1358 | // is not actually looking to move the IME, look down below |
| 1359 | // for a real window to target... |
| 1360 | if (!willMove |
| 1361 | && w.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING |
| 1362 | && i > 0) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1363 | WindowState wb = localmWindows.get(i-1); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1364 | if (wb.mAppToken == w.mAppToken && canBeImeTarget(wb)) { |
| 1365 | i--; |
| 1366 | w = wb; |
| 1367 | } |
| 1368 | } |
| 1369 | break; |
| 1370 | } |
| 1371 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1372 | |
| Dianne Hackborn | e75d872 | 2011-01-27 19:37:40 -0800 | [diff] [blame] | 1373 | if (DEBUG_INPUT_METHOD && willMove) Slog.v(TAG, "Proposed new IME target: " + w); |
| 1374 | |
| Dianne Hackborn | 7eab094 | 2011-01-01 13:21:50 -0800 | [diff] [blame] | 1375 | // Now, a special case -- if the last target's window is in the |
| 1376 | // process of exiting, and is above the new target, keep on the |
| 1377 | // last target to avoid flicker. Consider for example a Dialog with |
| 1378 | // the IME shown: when the Dialog is dismissed, we want to keep |
| 1379 | // the IME above it until it is completely gone so it doesn't drop |
| 1380 | // behind the dialog or its full-screen scrim. |
| 1381 | if (mInputMethodTarget != null && w != null |
| 1382 | && mInputMethodTarget.isDisplayedLw() |
| 1383 | && mInputMethodTarget.mExiting) { |
| 1384 | if (mInputMethodTarget.mAnimLayer > w.mAnimLayer) { |
| 1385 | w = mInputMethodTarget; |
| 1386 | i = localmWindows.indexOf(w); |
| Dianne Hackborn | e75d872 | 2011-01-27 19:37:40 -0800 | [diff] [blame] | 1387 | if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Current target higher, switching to: " + w); |
| Dianne Hackborn | 7eab094 | 2011-01-01 13:21:50 -0800 | [diff] [blame] | 1388 | } |
| 1389 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1390 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1391 | 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] | 1392 | + w + " willMove=" + willMove); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1393 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1394 | if (willMove && w != null) { |
| 1395 | final WindowState curTarget = mInputMethodTarget; |
| 1396 | if (curTarget != null && curTarget.mAppToken != null) { |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1397 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1398 | // Now some fun for dealing with window animations that |
| 1399 | // modify the Z order. We need to look at all windows below |
| 1400 | // the current target that are in this app, finding the highest |
| 1401 | // visible one in layering. |
| 1402 | AppWindowToken token = curTarget.mAppToken; |
| 1403 | WindowState highestTarget = null; |
| 1404 | int highestPos = 0; |
| 1405 | if (token.animating || token.animation != null) { |
| 1406 | int pos = 0; |
| 1407 | pos = localmWindows.indexOf(curTarget); |
| 1408 | while (pos >= 0) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1409 | WindowState win = localmWindows.get(pos); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1410 | if (win.mAppToken != token) { |
| 1411 | break; |
| 1412 | } |
| 1413 | if (!win.mRemoved) { |
| 1414 | if (highestTarget == null || win.mAnimLayer > |
| 1415 | highestTarget.mAnimLayer) { |
| 1416 | highestTarget = win; |
| 1417 | highestPos = pos; |
| 1418 | } |
| 1419 | } |
| 1420 | pos--; |
| 1421 | } |
| 1422 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1423 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1424 | if (highestTarget != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1425 | if (DEBUG_INPUT_METHOD) Slog.v(TAG, "mNextAppTransition=" |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1426 | + mNextAppTransition + " " + highestTarget |
| 1427 | + " animating=" + highestTarget.isAnimating() |
| 1428 | + " layer=" + highestTarget.mAnimLayer |
| 1429 | + " new layer=" + w.mAnimLayer); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1430 | |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 1431 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1432 | // If we are currently setting up for an animation, |
| 1433 | // hold everything until we can find out what will happen. |
| 1434 | mInputMethodTargetWaitingAnim = true; |
| 1435 | mInputMethodTarget = highestTarget; |
| 1436 | return highestPos + 1; |
| 1437 | } else if (highestTarget.isAnimating() && |
| 1438 | highestTarget.mAnimLayer > w.mAnimLayer) { |
| 1439 | // If the window we are currently targeting is involved |
| 1440 | // with an animation, and it is on top of the next target |
| 1441 | // we will be over, then hold off on moving until |
| 1442 | // that is done. |
| Dianne Hackborn | e75d872 | 2011-01-27 19:37:40 -0800 | [diff] [blame] | 1443 | mInputMethodTargetWaitingAnim = true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1444 | mInputMethodTarget = highestTarget; |
| 1445 | return highestPos + 1; |
| 1446 | } |
| 1447 | } |
| 1448 | } |
| 1449 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1450 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1451 | //Slog.i(TAG, "Placing input method @" + (i+1)); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1452 | if (w != null) { |
| 1453 | if (willMove) { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 1454 | if (DEBUG_INPUT_METHOD) { |
| 1455 | RuntimeException e = null; |
| 1456 | if (!HIDE_STACK_CRAWLS) { |
| 1457 | e = new RuntimeException(); |
| 1458 | e.fillInStackTrace(); |
| 1459 | } |
| 1460 | Slog.w(TAG, "Moving IM target from " |
| 1461 | + mInputMethodTarget + " to " + w, e); |
| 1462 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1463 | mInputMethodTarget = w; |
| Dianne Hackborn | e75d872 | 2011-01-27 19:37:40 -0800 | [diff] [blame] | 1464 | mInputMethodTargetWaitingAnim = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1465 | if (w.mAppToken != null) { |
| 1466 | setInputMethodAnimLayerAdjustment(w.mAppToken.animLayerAdjustment); |
| 1467 | } else { |
| 1468 | setInputMethodAnimLayerAdjustment(0); |
| 1469 | } |
| 1470 | } |
| 1471 | return i+1; |
| 1472 | } |
| 1473 | if (willMove) { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 1474 | if (DEBUG_INPUT_METHOD) { |
| 1475 | RuntimeException e = null; |
| 1476 | if (!HIDE_STACK_CRAWLS) { |
| 1477 | e = new RuntimeException(); |
| 1478 | e.fillInStackTrace(); |
| 1479 | } |
| 1480 | Slog.w(TAG, "Moving IM target from " |
| 1481 | + mInputMethodTarget + " to null", e); |
| 1482 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1483 | mInputMethodTarget = null; |
| 1484 | setInputMethodAnimLayerAdjustment(0); |
| 1485 | } |
| 1486 | return -1; |
| 1487 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1488 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1489 | void addInputMethodWindowToListLocked(WindowState win) { |
| 1490 | int pos = findDesiredInputMethodWindowIndexLocked(true); |
| 1491 | if (pos >= 0) { |
| 1492 | win.mTargetAppToken = mInputMethodTarget.mAppToken; |
| Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 1493 | if (DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) Slog.v( |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 1494 | TAG, "Adding input method window " + win + " at " + pos); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1495 | mWindows.add(pos, win); |
| Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 1496 | mWindowsChanged = true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1497 | moveInputMethodDialogsLocked(pos+1); |
| 1498 | return; |
| 1499 | } |
| 1500 | win.mTargetAppToken = null; |
| 1501 | addWindowToListInOrderLocked(win, true); |
| 1502 | moveInputMethodDialogsLocked(pos); |
| 1503 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1504 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1505 | void setInputMethodAnimLayerAdjustment(int adj) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1506 | 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] | 1507 | mInputMethodAnimLayerAdjustment = adj; |
| 1508 | WindowState imw = mInputMethodWindow; |
| 1509 | if (imw != null) { |
| 1510 | imw.mAnimLayer = imw.mLayer + adj; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1511 | if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + imw |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1512 | + " anim layer: " + imw.mAnimLayer); |
| 1513 | int wi = imw.mChildWindows.size(); |
| 1514 | while (wi > 0) { |
| 1515 | wi--; |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1516 | WindowState cw = imw.mChildWindows.get(wi); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1517 | cw.mAnimLayer = cw.mLayer + adj; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1518 | if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + cw |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1519 | + " anim layer: " + cw.mAnimLayer); |
| 1520 | } |
| 1521 | } |
| 1522 | int di = mInputMethodDialogs.size(); |
| 1523 | while (di > 0) { |
| 1524 | di --; |
| 1525 | imw = mInputMethodDialogs.get(di); |
| 1526 | imw.mAnimLayer = imw.mLayer + adj; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1527 | if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + imw |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1528 | + " anim layer: " + imw.mAnimLayer); |
| 1529 | } |
| 1530 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1531 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1532 | private int tmpRemoveWindowLocked(int interestingPos, WindowState win) { |
| 1533 | int wpos = mWindows.indexOf(win); |
| 1534 | if (wpos >= 0) { |
| 1535 | if (wpos < interestingPos) interestingPos--; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1536 | 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] | 1537 | mWindows.remove(wpos); |
| Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 1538 | mWindowsChanged = true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1539 | int NC = win.mChildWindows.size(); |
| 1540 | while (NC > 0) { |
| 1541 | NC--; |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1542 | WindowState cw = win.mChildWindows.get(NC); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1543 | int cpos = mWindows.indexOf(cw); |
| 1544 | if (cpos >= 0) { |
| 1545 | if (cpos < interestingPos) interestingPos--; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1546 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Temp removing child at " |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 1547 | + cpos + ": " + cw); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1548 | mWindows.remove(cpos); |
| 1549 | } |
| 1550 | } |
| 1551 | } |
| 1552 | return interestingPos; |
| 1553 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1554 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1555 | private void reAddWindowToListInOrderLocked(WindowState win) { |
| 1556 | addWindowToListInOrderLocked(win, false); |
| 1557 | // This is a hack to get all of the child windows added as well |
| 1558 | // at the right position. Child windows should be rare and |
| 1559 | // this case should be rare, so it shouldn't be that big a deal. |
| 1560 | int wpos = mWindows.indexOf(win); |
| 1561 | if (wpos >= 0) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1562 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "ReAdd removing from " + wpos |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 1563 | + ": " + win); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1564 | mWindows.remove(wpos); |
| Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 1565 | mWindowsChanged = true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1566 | reAddWindowLocked(wpos, win); |
| 1567 | } |
| 1568 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1569 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1570 | void logWindowList(String prefix) { |
| 1571 | int N = mWindows.size(); |
| 1572 | while (N > 0) { |
| 1573 | N--; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1574 | Slog.v(TAG, prefix + "#" + N + ": " + mWindows.get(N)); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1575 | } |
| 1576 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1577 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1578 | void moveInputMethodDialogsLocked(int pos) { |
| 1579 | ArrayList<WindowState> dialogs = mInputMethodDialogs; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1580 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1581 | final int N = dialogs.size(); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1582 | 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] | 1583 | for (int i=0; i<N; i++) { |
| 1584 | pos = tmpRemoveWindowLocked(pos, dialogs.get(i)); |
| 1585 | } |
| 1586 | if (DEBUG_INPUT_METHOD) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1587 | Slog.v(TAG, "Window list w/pos=" + pos); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1588 | logWindowList(" "); |
| 1589 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1590 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1591 | if (pos >= 0) { |
| 1592 | final AppWindowToken targetAppToken = mInputMethodTarget.mAppToken; |
| 1593 | if (pos < mWindows.size()) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1594 | WindowState wp = mWindows.get(pos); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1595 | if (wp == mInputMethodWindow) { |
| 1596 | pos++; |
| 1597 | } |
| 1598 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1599 | 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] | 1600 | for (int i=0; i<N; i++) { |
| 1601 | WindowState win = dialogs.get(i); |
| 1602 | win.mTargetAppToken = targetAppToken; |
| 1603 | pos = reAddWindowLocked(pos, win); |
| 1604 | } |
| 1605 | if (DEBUG_INPUT_METHOD) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1606 | Slog.v(TAG, "Final window list:"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1607 | logWindowList(" "); |
| 1608 | } |
| 1609 | return; |
| 1610 | } |
| 1611 | for (int i=0; i<N; i++) { |
| 1612 | WindowState win = dialogs.get(i); |
| 1613 | win.mTargetAppToken = null; |
| 1614 | reAddWindowToListInOrderLocked(win); |
| 1615 | if (DEBUG_INPUT_METHOD) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1616 | Slog.v(TAG, "No IM target, final list:"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1617 | logWindowList(" "); |
| 1618 | } |
| 1619 | } |
| 1620 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1621 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1622 | boolean moveInputMethodWindowsIfNeededLocked(boolean needAssignLayers) { |
| 1623 | final WindowState imWin = mInputMethodWindow; |
| 1624 | final int DN = mInputMethodDialogs.size(); |
| 1625 | if (imWin == null && DN == 0) { |
| 1626 | return false; |
| 1627 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1628 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1629 | int imPos = findDesiredInputMethodWindowIndexLocked(true); |
| 1630 | if (imPos >= 0) { |
| 1631 | // In this case, the input method windows are to be placed |
| 1632 | // immediately above the window they are targeting. |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1633 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1634 | // First check to see if the input method windows are already |
| 1635 | // located here, and contiguous. |
| 1636 | final int N = mWindows.size(); |
| 1637 | WindowState firstImWin = imPos < N |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1638 | ? mWindows.get(imPos) : null; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1639 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1640 | // Figure out the actual input method window that should be |
| 1641 | // at the bottom of their stack. |
| 1642 | WindowState baseImWin = imWin != null |
| 1643 | ? imWin : mInputMethodDialogs.get(0); |
| 1644 | if (baseImWin.mChildWindows.size() > 0) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1645 | WindowState cw = baseImWin.mChildWindows.get(0); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1646 | if (cw.mSubLayer < 0) baseImWin = cw; |
| 1647 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1648 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1649 | if (firstImWin == baseImWin) { |
| 1650 | // The windows haven't moved... but are they still contiguous? |
| 1651 | // First find the top IM window. |
| 1652 | int pos = imPos+1; |
| 1653 | while (pos < N) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1654 | if (!(mWindows.get(pos)).mIsImWindow) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1655 | break; |
| 1656 | } |
| 1657 | pos++; |
| 1658 | } |
| 1659 | pos++; |
| 1660 | // Now there should be no more input method windows above. |
| 1661 | while (pos < N) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1662 | if ((mWindows.get(pos)).mIsImWindow) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1663 | break; |
| 1664 | } |
| 1665 | pos++; |
| 1666 | } |
| 1667 | if (pos >= N) { |
| 1668 | // All is good! |
| 1669 | return false; |
| 1670 | } |
| 1671 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1672 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1673 | if (imWin != null) { |
| 1674 | if (DEBUG_INPUT_METHOD) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1675 | Slog.v(TAG, "Moving IM from " + imPos); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1676 | logWindowList(" "); |
| 1677 | } |
| 1678 | imPos = tmpRemoveWindowLocked(imPos, imWin); |
| 1679 | if (DEBUG_INPUT_METHOD) { |
| Dianne Hackborn | 7eab094 | 2011-01-01 13:21:50 -0800 | [diff] [blame] | 1680 | 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] | 1681 | logWindowList(" "); |
| 1682 | } |
| 1683 | imWin.mTargetAppToken = mInputMethodTarget.mAppToken; |
| 1684 | reAddWindowLocked(imPos, imWin); |
| 1685 | if (DEBUG_INPUT_METHOD) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1686 | Slog.v(TAG, "List after moving IM to " + imPos + ":"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1687 | logWindowList(" "); |
| 1688 | } |
| 1689 | if (DN > 0) moveInputMethodDialogsLocked(imPos+1); |
| 1690 | } else { |
| 1691 | moveInputMethodDialogsLocked(imPos); |
| 1692 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1693 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1694 | } else { |
| 1695 | // In this case, the input method windows go in a fixed layer, |
| 1696 | // because they aren't currently associated with a focus window. |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1697 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1698 | if (imWin != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1699 | 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] | 1700 | tmpRemoveWindowLocked(0, imWin); |
| 1701 | imWin.mTargetAppToken = null; |
| 1702 | reAddWindowToListInOrderLocked(imWin); |
| 1703 | if (DEBUG_INPUT_METHOD) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1704 | Slog.v(TAG, "List with no IM target:"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1705 | logWindowList(" "); |
| 1706 | } |
| 1707 | if (DN > 0) moveInputMethodDialogsLocked(-1);; |
| 1708 | } else { |
| 1709 | moveInputMethodDialogsLocked(-1);; |
| 1710 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1711 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1712 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1713 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1714 | if (needAssignLayers) { |
| 1715 | assignLayersLocked(); |
| 1716 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1717 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1718 | return true; |
| 1719 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1720 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1721 | void adjustInputMethodDialogsLocked() { |
| 1722 | moveInputMethodDialogsLocked(findDesiredInputMethodWindowIndexLocked(true)); |
| 1723 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 1724 | |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 1725 | final boolean isWallpaperVisible(WindowState wallpaperTarget) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1726 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper vis: target obscured=" |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 1727 | + (wallpaperTarget != null ? Boolean.toString(wallpaperTarget.mObscured) : "??") |
| 1728 | + " anim=" + ((wallpaperTarget != null && wallpaperTarget.mAppToken != null) |
| 1729 | ? wallpaperTarget.mAppToken.animation : null) |
| 1730 | + " upper=" + mUpperWallpaperTarget |
| 1731 | + " lower=" + mLowerWallpaperTarget); |
| 1732 | return (wallpaperTarget != null |
| 1733 | && (!wallpaperTarget.mObscured || (wallpaperTarget.mAppToken != null |
| 1734 | && wallpaperTarget.mAppToken.animation != null))) |
| 1735 | || mUpperWallpaperTarget != null |
| 1736 | || mLowerWallpaperTarget != null; |
| 1737 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1738 | |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 1739 | static final int ADJUST_WALLPAPER_LAYERS_CHANGED = 1<<1; |
| 1740 | static final int ADJUST_WALLPAPER_VISIBILITY_CHANGED = 1<<2; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1741 | |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 1742 | int adjustWallpaperWindowsLocked() { |
| 1743 | int changed = 0; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1744 | |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1745 | final int dw = mDisplay.getWidth(); |
| 1746 | final int dh = mDisplay.getHeight(); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1747 | |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1748 | // First find top-most window that has asked to be on top of the |
| 1749 | // wallpaper; all wallpapers go behind it. |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1750 | final ArrayList<WindowState> localmWindows = mWindows; |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1751 | int N = localmWindows.size(); |
| 1752 | WindowState w = null; |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1753 | WindowState foundW = null; |
| 1754 | int foundI = 0; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1755 | WindowState topCurW = null; |
| 1756 | int topCurI = 0; |
| Dianne Hackborn | 6c8e20f | 2010-11-09 18:59:09 -0800 | [diff] [blame] | 1757 | int windowDetachedI = -1; |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1758 | int i = N; |
| 1759 | while (i > 0) { |
| 1760 | i--; |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1761 | w = localmWindows.get(i); |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1762 | if ((w.mAttrs.type == WindowManager.LayoutParams.TYPE_WALLPAPER)) { |
| 1763 | if (topCurW == null) { |
| 1764 | topCurW = w; |
| 1765 | topCurI = i; |
| 1766 | } |
| 1767 | continue; |
| 1768 | } |
| 1769 | topCurW = null; |
| Dianne Hackborn | 6c8e20f | 2010-11-09 18:59:09 -0800 | [diff] [blame] | 1770 | if (w != mWindowDetachedWallpaper && w.mAppToken != null) { |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1771 | // If this window's app token is hidden and not animating, |
| 1772 | // it is of no interest to us. |
| 1773 | if (w.mAppToken.hidden && w.mAppToken.animation == null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1774 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
| Dianne Hackborn | 6c8e20f | 2010-11-09 18:59:09 -0800 | [diff] [blame] | 1775 | "Skipping not hidden or animating token: " + w); |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1776 | continue; |
| 1777 | } |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1778 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1779 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Win " + w + ": readyfordisplay=" |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1780 | + w.isReadyForDisplay() + " drawpending=" + w.mDrawPending |
| 1781 | + " commitdrawpending=" + w.mCommitDrawPending); |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1782 | if ((w.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0 && w.isReadyForDisplay() |
| Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 1783 | && (mWallpaperTarget == w |
| 1784 | || (!w.mDrawPending && !w.mCommitDrawPending))) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1785 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1786 | "Found wallpaper activity: #" + i + "=" + w); |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1787 | foundW = w; |
| 1788 | foundI = i; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1789 | if (w == mWallpaperTarget && ((w.mAppToken != null |
| 1790 | && w.mAppToken.animation != null) |
| 1791 | || w.mAnimation != null)) { |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1792 | // The current wallpaper target is animating, so we'll |
| 1793 | // look behind it for another possible target and figure |
| 1794 | // out what is going on below. |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1795 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Win " + w |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1796 | + ": token animating, looking behind."); |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1797 | continue; |
| 1798 | } |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1799 | break; |
| Dianne Hackborn | 6c8e20f | 2010-11-09 18:59:09 -0800 | [diff] [blame] | 1800 | } else if (w == mWindowDetachedWallpaper) { |
| 1801 | windowDetachedI = i; |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1802 | } |
| 1803 | } |
| 1804 | |
| Dianne Hackborn | 6c8e20f | 2010-11-09 18:59:09 -0800 | [diff] [blame] | 1805 | if (foundW == null && windowDetachedI >= 0) { |
| 1806 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
| 1807 | "Found animating detached wallpaper activity: #" + i + "=" + w); |
| 1808 | foundW = w; |
| 1809 | foundI = windowDetachedI; |
| 1810 | } |
| 1811 | |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 1812 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1813 | // If we are currently waiting for an app transition, and either |
| 1814 | // the current target or the next target are involved with it, |
| 1815 | // then hold off on doing anything with the wallpaper. |
| 1816 | // Note that we are checking here for just whether the target |
| 1817 | // is part of an app token... which is potentially overly aggressive |
| 1818 | // (the app token may not be involved in the transition), but good |
| 1819 | // enough (we'll just wait until whatever transition is pending |
| 1820 | // executes). |
| 1821 | if (mWallpaperTarget != null && mWallpaperTarget.mAppToken != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1822 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1823 | "Wallpaper not changing: waiting for app anim in current target"); |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 1824 | return 0; |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1825 | } |
| 1826 | if (foundW != null && foundW.mAppToken != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1827 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1828 | "Wallpaper not changing: waiting for app anim in found target"); |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 1829 | return 0; |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1830 | } |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1831 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1832 | |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1833 | if (mWallpaperTarget != foundW) { |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1834 | if (DEBUG_WALLPAPER) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1835 | Slog.v(TAG, "New wallpaper target: " + foundW |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1836 | + " oldTarget: " + mWallpaperTarget); |
| 1837 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1838 | |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1839 | mLowerWallpaperTarget = null; |
| 1840 | mUpperWallpaperTarget = null; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1841 | |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1842 | WindowState oldW = mWallpaperTarget; |
| 1843 | mWallpaperTarget = foundW; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1844 | |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1845 | // Now what is happening... if the current and new targets are |
| 1846 | // animating, then we are in our super special mode! |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1847 | if (foundW != null && oldW != null) { |
| 1848 | boolean oldAnim = oldW.mAnimation != null |
| 1849 | || (oldW.mAppToken != null && oldW.mAppToken.animation != null); |
| 1850 | boolean foundAnim = foundW.mAnimation != null |
| 1851 | || (foundW.mAppToken != null && foundW.mAppToken.animation != null); |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1852 | if (DEBUG_WALLPAPER) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1853 | Slog.v(TAG, "New animation: " + foundAnim |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1854 | + " old animation: " + oldAnim); |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1855 | } |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1856 | if (foundAnim && oldAnim) { |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1857 | int oldI = localmWindows.indexOf(oldW); |
| 1858 | if (DEBUG_WALLPAPER) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1859 | Slog.v(TAG, "New i: " + foundI + " old i: " + oldI); |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1860 | } |
| 1861 | if (oldI >= 0) { |
| 1862 | if (DEBUG_WALLPAPER) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1863 | Slog.v(TAG, "Animating wallpapers: old#" + oldI |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1864 | + "=" + oldW + "; new#" + foundI |
| 1865 | + "=" + foundW); |
| 1866 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1867 | |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1868 | // Set the new target correctly. |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1869 | if (foundW.mAppToken != null && foundW.mAppToken.hiddenRequested) { |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1870 | if (DEBUG_WALLPAPER) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1871 | Slog.v(TAG, "Old wallpaper still the target."); |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1872 | } |
| 1873 | mWallpaperTarget = oldW; |
| 1874 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1875 | |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1876 | // Now set the upper and lower wallpaper targets |
| 1877 | // correctly, and make sure that we are positioning |
| 1878 | // the wallpaper below the lower. |
| 1879 | if (foundI > oldI) { |
| 1880 | // The new target is on top of the old one. |
| 1881 | if (DEBUG_WALLPAPER) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1882 | Slog.v(TAG, "Found target above old target."); |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1883 | } |
| 1884 | mUpperWallpaperTarget = foundW; |
| 1885 | mLowerWallpaperTarget = oldW; |
| 1886 | foundW = oldW; |
| 1887 | foundI = oldI; |
| 1888 | } else { |
| 1889 | // The new target is below the old one. |
| 1890 | if (DEBUG_WALLPAPER) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1891 | Slog.v(TAG, "Found target below old target."); |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1892 | } |
| 1893 | mUpperWallpaperTarget = oldW; |
| 1894 | mLowerWallpaperTarget = foundW; |
| 1895 | } |
| 1896 | } |
| 1897 | } |
| 1898 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1899 | |
| Dianne Hackborn | 6b1cb35 | 2009-09-28 18:27:26 -0700 | [diff] [blame] | 1900 | } else if (mLowerWallpaperTarget != null) { |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1901 | // Is it time to stop animating? |
| Dianne Hackborn | 6b1cb35 | 2009-09-28 18:27:26 -0700 | [diff] [blame] | 1902 | boolean lowerAnimating = mLowerWallpaperTarget.mAnimation != null |
| 1903 | || (mLowerWallpaperTarget.mAppToken != null |
| 1904 | && mLowerWallpaperTarget.mAppToken.animation != null); |
| 1905 | boolean upperAnimating = mUpperWallpaperTarget.mAnimation != null |
| 1906 | || (mUpperWallpaperTarget.mAppToken != null |
| 1907 | && mUpperWallpaperTarget.mAppToken.animation != null); |
| 1908 | if (!lowerAnimating || !upperAnimating) { |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1909 | if (DEBUG_WALLPAPER) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1910 | Slog.v(TAG, "No longer animating wallpaper targets!"); |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1911 | } |
| 1912 | mLowerWallpaperTarget = null; |
| 1913 | mUpperWallpaperTarget = null; |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1914 | } |
| 1915 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1916 | |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1917 | boolean visible = foundW != null; |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 1918 | if (visible) { |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1919 | // The window is visible to the compositor... but is it visible |
| 1920 | // to the user? That is what the wallpaper cares about. |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 1921 | visible = isWallpaperVisible(foundW); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1922 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper visibility: " + visible); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1923 | |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1924 | // If the wallpaper target is animating, we may need to copy |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1925 | // its layer adjustment. Only do this if we are not transfering |
| 1926 | // between two wallpaper targets. |
| 1927 | mWallpaperAnimLayerAdjustment = |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1928 | (mLowerWallpaperTarget == null && foundW.mAppToken != null) |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1929 | ? foundW.mAppToken.animLayerAdjustment : 0; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1930 | |
| Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 1931 | final int maxLayer = mPolicy.getMaxWallpaperLayer() |
| 1932 | * TYPE_LAYER_MULTIPLIER |
| 1933 | + TYPE_LAYER_OFFSET; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1934 | |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1935 | // Now w is the window we are supposed to be behind... but we |
| 1936 | // 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] | 1937 | // AND any starting window associated with it, AND below the |
| 1938 | // maximum layer the policy allows for wallpapers. |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1939 | while (foundI > 0) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1940 | WindowState wb = localmWindows.get(foundI-1); |
| Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 1941 | if (wb.mBaseLayer < maxLayer && |
| 1942 | wb.mAttachedWindow != foundW && |
| Dianne Hackborn | 428ecb6 | 2011-01-26 14:53:23 -0800 | [diff] [blame] | 1943 | (foundW.mAttachedWindow == null || |
| 1944 | wb.mAttachedWindow != foundW.mAttachedWindow) && |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1945 | (wb.mAttrs.type != TYPE_APPLICATION_STARTING || |
| Dianne Hackborn | 428ecb6 | 2011-01-26 14:53:23 -0800 | [diff] [blame] | 1946 | foundW.mToken == null || wb.mToken != foundW.mToken)) { |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1947 | // This window is not related to the previous one in any |
| 1948 | // interesting way, so stop here. |
| 1949 | break; |
| 1950 | } |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 1951 | foundW = wb; |
| 1952 | foundI--; |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1953 | } |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 1954 | } else { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1955 | if (DEBUG_WALLPAPER) Slog.v(TAG, "No wallpaper target"); |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1956 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1957 | |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1958 | if (foundW == null && topCurW != null) { |
| 1959 | // There is no wallpaper target, so it goes at the bottom. |
| 1960 | // We will assume it is the same place as last time, if known. |
| 1961 | foundW = topCurW; |
| 1962 | foundI = topCurI+1; |
| 1963 | } else { |
| 1964 | // Okay i is the position immediately above the wallpaper. Look at |
| 1965 | // what is below it for later. |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1966 | foundW = foundI > 0 ? localmWindows.get(foundI-1) : null; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 1967 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1968 | |
| Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 1969 | if (visible) { |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1970 | if (mWallpaperTarget.mWallpaperX >= 0) { |
| 1971 | mLastWallpaperX = mWallpaperTarget.mWallpaperX; |
| Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 1972 | mLastWallpaperXStep = mWallpaperTarget.mWallpaperXStep; |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1973 | } |
| 1974 | if (mWallpaperTarget.mWallpaperY >= 0) { |
| 1975 | mLastWallpaperY = mWallpaperTarget.mWallpaperY; |
| Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 1976 | mLastWallpaperYStep = mWallpaperTarget.mWallpaperYStep; |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 1977 | } |
| Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 1978 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1979 | |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1980 | // Start stepping backwards from here, ensuring that our wallpaper windows |
| 1981 | // are correctly placed. |
| 1982 | int curTokenIndex = mWallpaperTokens.size(); |
| 1983 | while (curTokenIndex > 0) { |
| 1984 | curTokenIndex--; |
| 1985 | WindowToken token = mWallpaperTokens.get(curTokenIndex); |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 1986 | if (token.hidden == visible) { |
| 1987 | changed |= ADJUST_WALLPAPER_VISIBILITY_CHANGED; |
| 1988 | token.hidden = !visible; |
| 1989 | // Need to do a layout to ensure the wallpaper now has the |
| 1990 | // correct size. |
| 1991 | mLayoutNeeded = true; |
| 1992 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1993 | |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1994 | int curWallpaperIndex = token.windows.size(); |
| 1995 | while (curWallpaperIndex > 0) { |
| 1996 | curWallpaperIndex--; |
| 1997 | WindowState wallpaper = token.windows.get(curWallpaperIndex); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1998 | |
| Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 1999 | if (visible) { |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 2000 | updateWallpaperOffsetLocked(wallpaper, dw, dh, false); |
| Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 2001 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2002 | |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 2003 | // First, make sure the client has the current visibility |
| 2004 | // state. |
| 2005 | if (wallpaper.mWallpaperVisible != visible) { |
| 2006 | wallpaper.mWallpaperVisible = visible; |
| 2007 | try { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2008 | if (DEBUG_VISIBILITY || DEBUG_WALLPAPER) Slog.v(TAG, |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 2009 | "Setting visibility of wallpaper " + wallpaper |
| 2010 | + ": " + visible); |
| 2011 | wallpaper.mClient.dispatchAppVisibility(visible); |
| 2012 | } catch (RemoteException e) { |
| 2013 | } |
| 2014 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2015 | |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 2016 | wallpaper.mAnimLayer = wallpaper.mLayer + mWallpaperAnimLayerAdjustment; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2017 | if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper win " |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 2018 | + wallpaper + " anim layer: " + wallpaper.mAnimLayer); |
| 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 | // First, if this window is at the current index, then all |
| 2021 | // is well. |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 2022 | if (wallpaper == foundW) { |
| 2023 | foundI--; |
| 2024 | foundW = foundI > 0 |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 2025 | ? localmWindows.get(foundI-1) : null; |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2026 | continue; |
| 2027 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2028 | |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2029 | // The window didn't match... the current wallpaper window, |
| 2030 | // wherever it is, is in the wrong place, so make sure it is |
| 2031 | // not in the list. |
| 2032 | int oldIndex = localmWindows.indexOf(wallpaper); |
| 2033 | if (oldIndex >= 0) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2034 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Wallpaper removing at " |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 2035 | + oldIndex + ": " + wallpaper); |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2036 | localmWindows.remove(oldIndex); |
| Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 2037 | mWindowsChanged = true; |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 2038 | if (oldIndex < foundI) { |
| 2039 | foundI--; |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2040 | } |
| 2041 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2042 | |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2043 | // Now stick it in. |
| Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 2044 | if (DEBUG_WALLPAPER || DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) { |
| 2045 | Slog.v(TAG, "Moving wallpaper " + wallpaper |
| 2046 | + " from " + oldIndex + " to " + foundI); |
| 2047 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2048 | |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 2049 | localmWindows.add(foundI, wallpaper); |
| Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 2050 | mWindowsChanged = true; |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 2051 | changed |= ADJUST_WALLPAPER_LAYERS_CHANGED; |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2052 | } |
| 2053 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2054 | |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2055 | return changed; |
| 2056 | } |
| 2057 | |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 2058 | void setWallpaperAnimLayerAdjustmentLocked(int adj) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2059 | if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG, |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 2060 | "Setting wallpaper layer adj to " + adj); |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 2061 | mWallpaperAnimLayerAdjustment = adj; |
| 2062 | int curTokenIndex = mWallpaperTokens.size(); |
| 2063 | while (curTokenIndex > 0) { |
| 2064 | curTokenIndex--; |
| 2065 | WindowToken token = mWallpaperTokens.get(curTokenIndex); |
| 2066 | int curWallpaperIndex = token.windows.size(); |
| 2067 | while (curWallpaperIndex > 0) { |
| 2068 | curWallpaperIndex--; |
| 2069 | WindowState wallpaper = token.windows.get(curWallpaperIndex); |
| 2070 | wallpaper.mAnimLayer = wallpaper.mLayer + adj; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2071 | if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper win " |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 2072 | + wallpaper + " anim layer: " + wallpaper.mAnimLayer); |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 2073 | } |
| 2074 | } |
| 2075 | } |
| 2076 | |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 2077 | boolean updateWallpaperOffsetLocked(WindowState wallpaperWin, int dw, int dh, |
| 2078 | boolean sync) { |
| Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 2079 | boolean changed = false; |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 2080 | boolean rawChanged = false; |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 2081 | float wpx = mLastWallpaperX >= 0 ? mLastWallpaperX : 0.5f; |
| Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 2082 | float wpxs = mLastWallpaperXStep >= 0 ? mLastWallpaperXStep : -1.0f; |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 2083 | int availw = wallpaperWin.mFrame.right-wallpaperWin.mFrame.left-dw; |
| 2084 | int offset = availw > 0 ? -(int)(availw*wpx+.5f) : 0; |
| 2085 | changed = wallpaperWin.mXOffset != offset; |
| 2086 | if (changed) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2087 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Update wallpaper " |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 2088 | + wallpaperWin + " x: " + offset); |
| 2089 | wallpaperWin.mXOffset = offset; |
| 2090 | } |
| Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 2091 | if (wallpaperWin.mWallpaperX != wpx || wallpaperWin.mWallpaperXStep != wpxs) { |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 2092 | wallpaperWin.mWallpaperX = wpx; |
| Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 2093 | wallpaperWin.mWallpaperXStep = wpxs; |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 2094 | rawChanged = true; |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 2095 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2096 | |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 2097 | float wpy = mLastWallpaperY >= 0 ? mLastWallpaperY : 0.5f; |
| Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 2098 | float wpys = mLastWallpaperYStep >= 0 ? mLastWallpaperYStep : -1.0f; |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 2099 | int availh = wallpaperWin.mFrame.bottom-wallpaperWin.mFrame.top-dh; |
| 2100 | offset = availh > 0 ? -(int)(availh*wpy+.5f) : 0; |
| 2101 | if (wallpaperWin.mYOffset != offset) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2102 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Update wallpaper " |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 2103 | + wallpaperWin + " y: " + offset); |
| 2104 | changed = true; |
| 2105 | wallpaperWin.mYOffset = offset; |
| 2106 | } |
| Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 2107 | if (wallpaperWin.mWallpaperY != wpy || wallpaperWin.mWallpaperYStep != wpys) { |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 2108 | wallpaperWin.mWallpaperY = wpy; |
| Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 2109 | wallpaperWin.mWallpaperYStep = wpys; |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 2110 | rawChanged = true; |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 2111 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2112 | |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 2113 | if (rawChanged) { |
| Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 2114 | try { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2115 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Report new wp offset " |
| Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 2116 | + wallpaperWin + " x=" + wallpaperWin.mWallpaperX |
| 2117 | + " y=" + wallpaperWin.mWallpaperY); |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 2118 | if (sync) { |
| Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 2119 | mWaitingOnWallpaper = wallpaperWin; |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 2120 | } |
| Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 2121 | wallpaperWin.mClient.dispatchWallpaperOffsets( |
| Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 2122 | wallpaperWin.mWallpaperX, wallpaperWin.mWallpaperY, |
| 2123 | wallpaperWin.mWallpaperXStep, wallpaperWin.mWallpaperYStep, sync); |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 2124 | if (sync) { |
| Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 2125 | if (mWaitingOnWallpaper != null) { |
| 2126 | long start = SystemClock.uptimeMillis(); |
| 2127 | if ((mLastWallpaperTimeoutTime+WALLPAPER_TIMEOUT_RECOVERY) |
| 2128 | < start) { |
| 2129 | try { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2130 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
| Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 2131 | "Waiting for offset complete..."); |
| 2132 | mWindowMap.wait(WALLPAPER_TIMEOUT); |
| 2133 | } catch (InterruptedException e) { |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 2134 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2135 | if (DEBUG_WALLPAPER) Slog.v(TAG, "Offset complete!"); |
| Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 2136 | if ((start+WALLPAPER_TIMEOUT) |
| 2137 | < SystemClock.uptimeMillis()) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2138 | Slog.i(TAG, "Timeout waiting for wallpaper to offset: " |
| Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 2139 | + wallpaperWin); |
| 2140 | mLastWallpaperTimeoutTime = start; |
| 2141 | } |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 2142 | } |
| Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 2143 | mWaitingOnWallpaper = null; |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 2144 | } |
| 2145 | } |
| Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 2146 | } catch (RemoteException e) { |
| 2147 | } |
| 2148 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2149 | |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 2150 | return changed; |
| 2151 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2152 | |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 2153 | void wallpaperOffsetsComplete(IBinder window) { |
| Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 2154 | synchronized (mWindowMap) { |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 2155 | if (mWaitingOnWallpaper != null && |
| 2156 | mWaitingOnWallpaper.mClient.asBinder() == window) { |
| 2157 | mWaitingOnWallpaper = null; |
| Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 2158 | mWindowMap.notifyAll(); |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 2159 | } |
| 2160 | } |
| 2161 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2162 | |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 2163 | boolean updateWallpaperOffsetLocked(WindowState changingTarget, boolean sync) { |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 2164 | final int dw = mDisplay.getWidth(); |
| 2165 | final int dh = mDisplay.getHeight(); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2166 | |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 2167 | boolean changed = false; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2168 | |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 2169 | WindowState target = mWallpaperTarget; |
| 2170 | if (target != null) { |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 2171 | if (target.mWallpaperX >= 0) { |
| 2172 | mLastWallpaperX = target.mWallpaperX; |
| 2173 | } else if (changingTarget.mWallpaperX >= 0) { |
| 2174 | mLastWallpaperX = changingTarget.mWallpaperX; |
| 2175 | } |
| 2176 | if (target.mWallpaperY >= 0) { |
| 2177 | mLastWallpaperY = target.mWallpaperY; |
| 2178 | } else if (changingTarget.mWallpaperY >= 0) { |
| 2179 | mLastWallpaperY = changingTarget.mWallpaperY; |
| 2180 | } |
| 2181 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2182 | |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 2183 | int curTokenIndex = mWallpaperTokens.size(); |
| 2184 | while (curTokenIndex > 0) { |
| 2185 | curTokenIndex--; |
| 2186 | WindowToken token = mWallpaperTokens.get(curTokenIndex); |
| 2187 | int curWallpaperIndex = token.windows.size(); |
| 2188 | while (curWallpaperIndex > 0) { |
| 2189 | curWallpaperIndex--; |
| 2190 | WindowState wallpaper = token.windows.get(curWallpaperIndex); |
| 2191 | if (updateWallpaperOffsetLocked(wallpaper, dw, dh, sync)) { |
| 2192 | wallpaper.computeShownFrameLocked(); |
| 2193 | changed = true; |
| 2194 | // We only want to be synchronous with one wallpaper. |
| 2195 | sync = false; |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 2196 | } |
| 2197 | } |
| 2198 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2199 | |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 2200 | return changed; |
| 2201 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2202 | |
| Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 2203 | void updateWallpaperVisibilityLocked() { |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 2204 | final boolean visible = isWallpaperVisible(mWallpaperTarget); |
| Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 2205 | final int dw = mDisplay.getWidth(); |
| 2206 | final int dh = mDisplay.getHeight(); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2207 | |
| Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 2208 | int curTokenIndex = mWallpaperTokens.size(); |
| 2209 | while (curTokenIndex > 0) { |
| 2210 | curTokenIndex--; |
| 2211 | WindowToken token = mWallpaperTokens.get(curTokenIndex); |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 2212 | if (token.hidden == visible) { |
| 2213 | token.hidden = !visible; |
| 2214 | // Need to do a layout to ensure the wallpaper now has the |
| 2215 | // correct size. |
| 2216 | mLayoutNeeded = true; |
| 2217 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2218 | |
| Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 2219 | int curWallpaperIndex = token.windows.size(); |
| 2220 | while (curWallpaperIndex > 0) { |
| 2221 | curWallpaperIndex--; |
| 2222 | WindowState wallpaper = token.windows.get(curWallpaperIndex); |
| 2223 | if (visible) { |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 2224 | updateWallpaperOffsetLocked(wallpaper, dw, dh, false); |
| Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 2225 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2226 | |
| Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 2227 | if (wallpaper.mWallpaperVisible != visible) { |
| 2228 | wallpaper.mWallpaperVisible = visible; |
| 2229 | try { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2230 | if (DEBUG_VISIBILITY || DEBUG_WALLPAPER) Slog.v(TAG, |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 2231 | "Updating visibility of wallpaper " + wallpaper |
| Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 2232 | + ": " + visible); |
| 2233 | wallpaper.mClient.dispatchAppVisibility(visible); |
| 2234 | } catch (RemoteException e) { |
| 2235 | } |
| 2236 | } |
| 2237 | } |
| 2238 | } |
| 2239 | } |
| Dianne Hackborn | 90d2db3 | 2010-02-11 22:19:06 -0800 | [diff] [blame] | 2240 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2241 | public int addWindow(Session session, IWindow client, |
| 2242 | WindowManager.LayoutParams attrs, int viewVisibility, |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 2243 | Rect outContentInsets, InputChannel outInputChannel) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2244 | int res = mPolicy.checkAddPermission(attrs); |
| 2245 | if (res != WindowManagerImpl.ADD_OKAY) { |
| 2246 | return res; |
| 2247 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2248 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2249 | boolean reportNewConfig = false; |
| 2250 | WindowState attachedWindow = null; |
| 2251 | WindowState win = null; |
| Dianne Hackborn | 5132b37 | 2010-07-29 12:51:35 -0700 | [diff] [blame] | 2252 | long origId; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2253 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2254 | synchronized(mWindowMap) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2255 | if (mDisplay == null) { |
| Dianne Hackborn | 5132b37 | 2010-07-29 12:51:35 -0700 | [diff] [blame] | 2256 | throw new IllegalStateException("Display has not been initialialized"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2257 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2258 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2259 | if (mWindowMap.containsKey(client.asBinder())) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2260 | Slog.w(TAG, "Window " + client + " is already added"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2261 | return WindowManagerImpl.ADD_DUPLICATE_ADD; |
| 2262 | } |
| 2263 | |
| 2264 | if (attrs.type >= FIRST_SUB_WINDOW && attrs.type <= LAST_SUB_WINDOW) { |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2265 | attachedWindow = windowForClientLocked(null, attrs.token, false); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2266 | if (attachedWindow == null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2267 | 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] | 2268 | + attrs.token + ". Aborting."); |
| 2269 | return WindowManagerImpl.ADD_BAD_SUBWINDOW_TOKEN; |
| 2270 | } |
| 2271 | if (attachedWindow.mAttrs.type >= FIRST_SUB_WINDOW |
| 2272 | && attachedWindow.mAttrs.type <= LAST_SUB_WINDOW) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2273 | 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] | 2274 | + attrs.token + ". Aborting."); |
| 2275 | return WindowManagerImpl.ADD_BAD_SUBWINDOW_TOKEN; |
| 2276 | } |
| 2277 | } |
| 2278 | |
| 2279 | boolean addToken = false; |
| 2280 | WindowToken token = mTokenMap.get(attrs.token); |
| 2281 | if (token == null) { |
| 2282 | if (attrs.type >= FIRST_APPLICATION_WINDOW |
| 2283 | && attrs.type <= LAST_APPLICATION_WINDOW) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2284 | 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] | 2285 | + attrs.token + ". Aborting."); |
| 2286 | return WindowManagerImpl.ADD_BAD_APP_TOKEN; |
| 2287 | } |
| 2288 | if (attrs.type == TYPE_INPUT_METHOD) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2289 | 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] | 2290 | + attrs.token + ". Aborting."); |
| 2291 | return WindowManagerImpl.ADD_BAD_APP_TOKEN; |
| 2292 | } |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2293 | if (attrs.type == TYPE_WALLPAPER) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2294 | Slog.w(TAG, "Attempted to add wallpaper window with unknown token " |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2295 | + attrs.token + ". Aborting."); |
| 2296 | return WindowManagerImpl.ADD_BAD_APP_TOKEN; |
| 2297 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2298 | token = new WindowToken(attrs.token, -1, false); |
| 2299 | addToken = true; |
| 2300 | } else if (attrs.type >= FIRST_APPLICATION_WINDOW |
| 2301 | && attrs.type <= LAST_APPLICATION_WINDOW) { |
| 2302 | AppWindowToken atoken = token.appWindowToken; |
| 2303 | if (atoken == null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2304 | 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] | 2305 | + token + ". Aborting."); |
| 2306 | return WindowManagerImpl.ADD_NOT_APP_TOKEN; |
| 2307 | } else if (atoken.removed) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2308 | 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] | 2309 | + token + ". Aborting."); |
| 2310 | return WindowManagerImpl.ADD_APP_EXITING; |
| 2311 | } |
| 2312 | if (attrs.type == TYPE_APPLICATION_STARTING && atoken.firstWindowDrawn) { |
| 2313 | // No need for this guy! |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2314 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2315 | TAG, "**** NO NEED TO START: " + attrs.getTitle()); |
| 2316 | return WindowManagerImpl.ADD_STARTING_NOT_NEEDED; |
| 2317 | } |
| 2318 | } else if (attrs.type == TYPE_INPUT_METHOD) { |
| 2319 | if (token.windowType != TYPE_INPUT_METHOD) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2320 | 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] | 2321 | + attrs.token + ". Aborting."); |
| 2322 | return WindowManagerImpl.ADD_BAD_APP_TOKEN; |
| 2323 | } |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2324 | } else if (attrs.type == TYPE_WALLPAPER) { |
| 2325 | if (token.windowType != TYPE_WALLPAPER) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2326 | Slog.w(TAG, "Attempted to add wallpaper window with bad token " |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2327 | + attrs.token + ". Aborting."); |
| 2328 | return WindowManagerImpl.ADD_BAD_APP_TOKEN; |
| 2329 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2330 | } |
| 2331 | |
| 2332 | win = new WindowState(session, client, token, |
| 2333 | attachedWindow, attrs, viewVisibility); |
| 2334 | if (win.mDeathRecipient == null) { |
| 2335 | // Client has apparently died, so there is no reason to |
| 2336 | // continue. |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2337 | Slog.w(TAG, "Adding window client " + client.asBinder() |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2338 | + " that is dead, aborting."); |
| 2339 | return WindowManagerImpl.ADD_APP_EXITING; |
| 2340 | } |
| 2341 | |
| 2342 | mPolicy.adjustWindowParamsLw(win.mAttrs); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2343 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2344 | res = mPolicy.prepareAddWindowLw(win, attrs); |
| 2345 | if (res != WindowManagerImpl.ADD_OKAY) { |
| 2346 | return res; |
| 2347 | } |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 2348 | |
| Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 2349 | if (outInputChannel != null) { |
| 2350 | String name = win.makeInputChannelName(); |
| 2351 | InputChannel[] inputChannels = InputChannel.openInputChannelPair(name); |
| 2352 | win.mInputChannel = inputChannels[0]; |
| 2353 | inputChannels[1].transferToBinderOutParameter(outInputChannel); |
| 2354 | |
| Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame] | 2355 | mInputManager.registerInputChannel(win.mInputChannel, win.mInputWindowHandle); |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 2356 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2357 | |
| 2358 | // From now on, no exceptions or errors allowed! |
| 2359 | |
| 2360 | res = WindowManagerImpl.ADD_OKAY; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2361 | |
| Dianne Hackborn | 5132b37 | 2010-07-29 12:51:35 -0700 | [diff] [blame] | 2362 | origId = Binder.clearCallingIdentity(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2363 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2364 | if (addToken) { |
| 2365 | mTokenMap.put(attrs.token, token); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2366 | } |
| 2367 | win.attach(); |
| 2368 | mWindowMap.put(client.asBinder(), win); |
| 2369 | |
| 2370 | if (attrs.type == TYPE_APPLICATION_STARTING && |
| 2371 | token.appWindowToken != null) { |
| 2372 | token.appWindowToken.startingWindow = win; |
| 2373 | } |
| 2374 | |
| 2375 | boolean imMayMove = true; |
| 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 (attrs.type == TYPE_INPUT_METHOD) { |
| 2378 | mInputMethodWindow = win; |
| 2379 | addInputMethodWindowToListLocked(win); |
| 2380 | imMayMove = false; |
| 2381 | } else if (attrs.type == TYPE_INPUT_METHOD_DIALOG) { |
| 2382 | mInputMethodDialogs.add(win); |
| 2383 | addWindowToListInOrderLocked(win, true); |
| 2384 | adjustInputMethodDialogsLocked(); |
| 2385 | imMayMove = false; |
| 2386 | } else { |
| 2387 | addWindowToListInOrderLocked(win, true); |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 2388 | if (attrs.type == TYPE_WALLPAPER) { |
| 2389 | mLastWallpaperTimeoutTime = 0; |
| 2390 | adjustWallpaperWindowsLocked(); |
| 2391 | } else if ((attrs.flags&FLAG_SHOW_WALLPAPER) != 0) { |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2392 | adjustWallpaperWindowsLocked(); |
| 2393 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2394 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2395 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2396 | win.mEnterAnimationPending = true; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2397 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2398 | mPolicy.getContentInsetHintLw(attrs, outContentInsets); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2399 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2400 | if (mInTouchMode) { |
| 2401 | res |= WindowManagerImpl.ADD_FLAG_IN_TOUCH_MODE; |
| 2402 | } |
| 2403 | if (win == null || win.mAppToken == null || !win.mAppToken.clientHidden) { |
| 2404 | res |= WindowManagerImpl.ADD_FLAG_APP_VISIBLE; |
| 2405 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2406 | |
| Jeff Brown | 2e44b07 | 2011-01-24 15:21:56 -0800 | [diff] [blame] | 2407 | mInputMonitor.setUpdateInputWindowsNeededLw(); |
| 2408 | |
| The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 2409 | boolean focusChanged = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2410 | if (win.canReceiveKeys()) { |
| Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 2411 | focusChanged = updateFocusedWindowLocked(UPDATE_FOCUS_WILL_ASSIGN_LAYERS, |
| 2412 | false /*updateInputWindows*/); |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 2413 | if (focusChanged) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2414 | imMayMove = false; |
| 2415 | } |
| 2416 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2417 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2418 | if (imMayMove) { |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2419 | moveInputMethodWindowsIfNeededLocked(false); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2420 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2421 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2422 | assignLayersLocked(); |
| 2423 | // Don't do layout here, the window must call |
| 2424 | // relayout to be displayed, so we'll do it there. |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2425 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2426 | //dump(); |
| 2427 | |
| The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 2428 | if (focusChanged) { |
| Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 2429 | finishUpdateFocusedWindowAfterAssignLayersLocked(false /*updateInputWindows*/); |
| The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 2430 | } |
| Jeff Brown | 2e44b07 | 2011-01-24 15:21:56 -0800 | [diff] [blame] | 2431 | mInputMonitor.updateInputWindowsLw(false /*force*/); |
| Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 2432 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2433 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2434 | TAG, "New client " + client.asBinder() |
| 2435 | + ": window=" + win); |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2436 | |
| Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 2437 | if (win.isVisibleOrAdding() && updateOrientationFromAppTokensLocked(false)) { |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2438 | reportNewConfig = true; |
| 2439 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2440 | } |
| 2441 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2442 | if (reportNewConfig) { |
| 2443 | sendNewConfiguration(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2444 | } |
| Dianne Hackborn | 5132b37 | 2010-07-29 12:51:35 -0700 | [diff] [blame] | 2445 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2446 | Binder.restoreCallingIdentity(origId); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2447 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2448 | return res; |
| 2449 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2450 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2451 | public void removeWindow(Session session, IWindow client) { |
| 2452 | synchronized(mWindowMap) { |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2453 | WindowState win = windowForClientLocked(session, client, false); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2454 | if (win == null) { |
| 2455 | return; |
| 2456 | } |
| 2457 | removeWindowLocked(session, win); |
| 2458 | } |
| 2459 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2460 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2461 | public void removeWindowLocked(Session session, WindowState win) { |
| 2462 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2463 | if (localLOGV || DEBUG_FOCUS) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2464 | TAG, "Remove " + win + " client=" |
| 2465 | + Integer.toHexString(System.identityHashCode( |
| 2466 | win.mClient.asBinder())) |
| 2467 | + ", surface=" + win.mSurface); |
| 2468 | |
| 2469 | final long origId = Binder.clearCallingIdentity(); |
| Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 2470 | |
| 2471 | win.disposeInputChannel(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2472 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2473 | if (DEBUG_APP_TRANSITIONS) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2474 | TAG, "Remove " + win + ": mSurface=" + win.mSurface |
| 2475 | + " mExiting=" + win.mExiting |
| 2476 | + " isAnimating=" + win.isAnimating() |
| 2477 | + " app-animation=" |
| 2478 | + (win.mAppToken != null ? win.mAppToken.animation : null) |
| 2479 | + " inPendingTransaction=" |
| 2480 | + (win.mAppToken != null ? win.mAppToken.inPendingTransaction : false) |
| 2481 | + " mDisplayFrozen=" + mDisplayFrozen); |
| 2482 | // Visibility of the removed window. Will be used later to update orientation later on. |
| 2483 | boolean wasVisible = false; |
| 2484 | // First, see if we need to run an animation. If we do, we have |
| 2485 | // to hold off on removing the window until the animation is done. |
| 2486 | // If the display is frozen, just remove immediately, since the |
| 2487 | // animation wouldn't be seen. |
| Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 2488 | if (win.mSurface != null && !mDisplayFrozen && mPolicy.isScreenOn()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2489 | // If we are not currently running the exit animation, we |
| 2490 | // need to see about starting one. |
| 2491 | if (wasVisible=win.isWinVisibleLw()) { |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2492 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2493 | int transit = WindowManagerPolicy.TRANSIT_EXIT; |
| 2494 | if (win.getAttrs().type == TYPE_APPLICATION_STARTING) { |
| 2495 | transit = WindowManagerPolicy.TRANSIT_PREVIEW_DONE; |
| 2496 | } |
| 2497 | // Try starting an animation. |
| 2498 | if (applyAnimationLocked(win, transit, false)) { |
| 2499 | win.mExiting = true; |
| 2500 | } |
| 2501 | } |
| 2502 | if (win.mExiting || win.isAnimating()) { |
| 2503 | // The exit animation is running... wait for it! |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2504 | //Slog.i(TAG, "*** Running exit animation..."); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2505 | win.mExiting = true; |
| 2506 | win.mRemoveOnExit = true; |
| 2507 | mLayoutNeeded = true; |
| Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 2508 | updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES, |
| 2509 | false /*updateInputWindows*/); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2510 | performLayoutAndPlaceSurfacesLocked(); |
| Jeff Brown | 2e44b07 | 2011-01-24 15:21:56 -0800 | [diff] [blame] | 2511 | mInputMonitor.updateInputWindowsLw(false /*force*/); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2512 | if (win.mAppToken != null) { |
| 2513 | win.mAppToken.updateReportedVisibilityLocked(); |
| 2514 | } |
| 2515 | //dump(); |
| 2516 | Binder.restoreCallingIdentity(origId); |
| 2517 | return; |
| 2518 | } |
| 2519 | } |
| 2520 | |
| 2521 | removeWindowInnerLocked(session, win); |
| 2522 | // Removing a visible window will effect the computed orientation |
| 2523 | // So just update orientation if needed. |
| The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 2524 | if (wasVisible && computeForcedAppOrientationLocked() |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2525 | != mForcedAppOrientation |
| Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 2526 | && updateOrientationFromAppTokensLocked(false)) { |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2527 | mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2528 | } |
| Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 2529 | updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL, true /*updateInputWindows*/); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2530 | Binder.restoreCallingIdentity(origId); |
| 2531 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2532 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2533 | private void removeWindowInnerLocked(Session session, WindowState win) { |
| Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 2534 | if (win.mRemoved) { |
| 2535 | // Nothing to do. |
| 2536 | return; |
| 2537 | } |
| 2538 | |
| 2539 | for (int i=win.mChildWindows.size()-1; i>=0; i--) { |
| 2540 | WindowState cwin = win.mChildWindows.get(i); |
| 2541 | Slog.w(TAG, "Force-removing child win " + cwin + " from container " |
| 2542 | + win); |
| 2543 | removeWindowInnerLocked(cwin.mSession, cwin); |
| 2544 | } |
| 2545 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2546 | win.mRemoved = true; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2547 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2548 | if (mInputMethodTarget == win) { |
| 2549 | moveInputMethodWindowsIfNeededLocked(false); |
| 2550 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2551 | |
| Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 2552 | if (false) { |
| 2553 | RuntimeException e = new RuntimeException("here"); |
| 2554 | e.fillInStackTrace(); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2555 | Slog.w(TAG, "Removing window " + win, e); |
| Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 2556 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2557 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2558 | mPolicy.removeWindowLw(win); |
| 2559 | win.removeLocked(); |
| 2560 | |
| Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 2561 | if (DEBUG_ADD_REMOVE) Slog.v(TAG, "removeWindowInnerLocked: " + win); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2562 | mWindowMap.remove(win.mClient.asBinder()); |
| 2563 | mWindows.remove(win); |
| Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 2564 | mPendingRemove.remove(win); |
| Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 2565 | mWindowsChanged = true; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2566 | 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] | 2567 | |
| 2568 | if (mInputMethodWindow == win) { |
| 2569 | mInputMethodWindow = null; |
| 2570 | } else if (win.mAttrs.type == TYPE_INPUT_METHOD_DIALOG) { |
| 2571 | mInputMethodDialogs.remove(win); |
| 2572 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2573 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2574 | final WindowToken token = win.mToken; |
| 2575 | final AppWindowToken atoken = win.mAppToken; |
| Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 2576 | 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] | 2577 | token.windows.remove(win); |
| 2578 | if (atoken != null) { |
| 2579 | atoken.allAppWindows.remove(win); |
| 2580 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2581 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2582 | TAG, "**** Removing window " + win + ": count=" |
| 2583 | + token.windows.size()); |
| 2584 | if (token.windows.size() == 0) { |
| 2585 | if (!token.explicit) { |
| 2586 | mTokenMap.remove(token.token); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2587 | } else if (atoken != null) { |
| 2588 | atoken.firstWindowDrawn = false; |
| 2589 | } |
| 2590 | } |
| 2591 | |
| 2592 | if (atoken != null) { |
| 2593 | if (atoken.startingWindow == win) { |
| 2594 | atoken.startingWindow = null; |
| 2595 | } else if (atoken.allAppWindows.size() == 0 && atoken.startingData != null) { |
| 2596 | // If this is the last window and we had requested a starting |
| 2597 | // transition window, well there is no point now. |
| 2598 | atoken.startingData = null; |
| 2599 | } else if (atoken.allAppWindows.size() == 1 && atoken.startingView != null) { |
| 2600 | // If this is the last window except for a starting transition |
| 2601 | // window, we need to get rid of the starting transition. |
| 2602 | if (DEBUG_STARTING_WINDOW) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2603 | Slog.v(TAG, "Schedule remove starting " + token |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2604 | + ": no more real windows"); |
| 2605 | } |
| 2606 | Message m = mH.obtainMessage(H.REMOVE_STARTING, atoken); |
| 2607 | mH.sendMessage(m); |
| 2608 | } |
| 2609 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2610 | |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 2611 | if (win.mAttrs.type == TYPE_WALLPAPER) { |
| 2612 | mLastWallpaperTimeoutTime = 0; |
| 2613 | adjustWallpaperWindowsLocked(); |
| 2614 | } else if ((win.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0) { |
| Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 2615 | adjustWallpaperWindowsLocked(); |
| 2616 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2617 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2618 | if (!mInLayout) { |
| 2619 | assignLayersLocked(); |
| 2620 | mLayoutNeeded = true; |
| 2621 | performLayoutAndPlaceSurfacesLocked(); |
| 2622 | if (win.mAppToken != null) { |
| 2623 | win.mAppToken.updateReportedVisibilityLocked(); |
| 2624 | } |
| 2625 | } |
| Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 2626 | |
| Jeff Brown | 2e44b07 | 2011-01-24 15:21:56 -0800 | [diff] [blame] | 2627 | mInputMonitor.updateInputWindowsLw(true /*force*/); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2628 | } |
| 2629 | |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 2630 | private static void logSurface(WindowState w, String msg, RuntimeException where) { |
| 2631 | String str = " SURFACE " + Integer.toHexString(w.hashCode()) |
| 2632 | + ": " + msg + " / " + w.mAttrs.getTitle(); |
| 2633 | if (where != null) { |
| 2634 | Slog.i(TAG, str, where); |
| 2635 | } else { |
| 2636 | Slog.i(TAG, str); |
| 2637 | } |
| 2638 | } |
| 2639 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2640 | private void setTransparentRegionWindow(Session session, IWindow client, Region region) { |
| 2641 | long origId = Binder.clearCallingIdentity(); |
| 2642 | try { |
| 2643 | synchronized (mWindowMap) { |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2644 | WindowState w = windowForClientLocked(session, client, false); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2645 | if ((w != null) && (w.mSurface != null)) { |
| Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 2646 | if (SHOW_TRANSACTIONS) Slog.i(TAG, |
| 2647 | ">>> OPEN TRANSACTION setTransparentRegion"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2648 | Surface.openTransaction(); |
| 2649 | try { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 2650 | if (SHOW_TRANSACTIONS) logSurface(w, |
| 2651 | "transparentRegionHint=" + region, null); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2652 | w.mSurface.setTransparentRegionHint(region); |
| 2653 | } finally { |
| 2654 | Surface.closeTransaction(); |
| Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 2655 | if (SHOW_TRANSACTIONS) Slog.i(TAG, |
| 2656 | "<<< CLOSE TRANSACTION setTransparentRegion"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2657 | } |
| 2658 | } |
| 2659 | } |
| 2660 | } finally { |
| 2661 | Binder.restoreCallingIdentity(origId); |
| 2662 | } |
| 2663 | } |
| 2664 | |
| 2665 | void setInsetsWindow(Session session, IWindow client, |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2666 | int touchableInsets, Rect contentInsets, |
| Jeff Brown | fbf0977 | 2011-01-16 14:06:57 -0800 | [diff] [blame] | 2667 | Rect visibleInsets, Region touchableRegion) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2668 | long origId = Binder.clearCallingIdentity(); |
| 2669 | try { |
| 2670 | synchronized (mWindowMap) { |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2671 | WindowState w = windowForClientLocked(session, client, false); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2672 | if (w != null) { |
| 2673 | w.mGivenInsetsPending = false; |
| 2674 | w.mGivenContentInsets.set(contentInsets); |
| 2675 | w.mGivenVisibleInsets.set(visibleInsets); |
| Jeff Brown | fbf0977 | 2011-01-16 14:06:57 -0800 | [diff] [blame] | 2676 | w.mGivenTouchableRegion.set(touchableRegion); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2677 | w.mTouchableInsets = touchableInsets; |
| 2678 | mLayoutNeeded = true; |
| 2679 | performLayoutAndPlaceSurfacesLocked(); |
| 2680 | } |
| 2681 | } |
| 2682 | } finally { |
| 2683 | Binder.restoreCallingIdentity(origId); |
| 2684 | } |
| 2685 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2686 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2687 | public void getWindowDisplayFrame(Session session, IWindow client, |
| 2688 | Rect outDisplayFrame) { |
| 2689 | synchronized(mWindowMap) { |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2690 | WindowState win = windowForClientLocked(session, client, false); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2691 | if (win == null) { |
| 2692 | outDisplayFrame.setEmpty(); |
| 2693 | return; |
| 2694 | } |
| 2695 | outDisplayFrame.set(win.mDisplayFrame); |
| 2696 | } |
| 2697 | } |
| 2698 | |
| Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 2699 | public void setWindowWallpaperPositionLocked(WindowState window, float x, float y, |
| 2700 | float xStep, float yStep) { |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 2701 | if (window.mWallpaperX != x || window.mWallpaperY != y) { |
| 2702 | window.mWallpaperX = x; |
| 2703 | window.mWallpaperY = y; |
| Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 2704 | window.mWallpaperXStep = xStep; |
| 2705 | window.mWallpaperYStep = yStep; |
| Dianne Hackborn | 73e92b4 | 2009-10-15 14:29:19 -0700 | [diff] [blame] | 2706 | if (updateWallpaperOffsetLocked(window, true)) { |
| 2707 | performLayoutAndPlaceSurfacesLocked(); |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 2708 | } |
| 2709 | } |
| 2710 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2711 | |
| Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 2712 | void wallpaperCommandComplete(IBinder window, Bundle result) { |
| 2713 | synchronized (mWindowMap) { |
| 2714 | if (mWaitingOnWallpaper != null && |
| 2715 | mWaitingOnWallpaper.mClient.asBinder() == window) { |
| 2716 | mWaitingOnWallpaper = null; |
| 2717 | mWindowMap.notifyAll(); |
| 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 | public Bundle sendWindowWallpaperCommandLocked(WindowState window, |
| 2723 | String action, int x, int y, int z, Bundle extras, boolean sync) { |
| 2724 | if (window == mWallpaperTarget || window == mLowerWallpaperTarget |
| 2725 | || window == mUpperWallpaperTarget) { |
| 2726 | boolean doWait = sync; |
| 2727 | int curTokenIndex = mWallpaperTokens.size(); |
| 2728 | while (curTokenIndex > 0) { |
| 2729 | curTokenIndex--; |
| 2730 | WindowToken token = mWallpaperTokens.get(curTokenIndex); |
| 2731 | int curWallpaperIndex = token.windows.size(); |
| 2732 | while (curWallpaperIndex > 0) { |
| 2733 | curWallpaperIndex--; |
| 2734 | WindowState wallpaper = token.windows.get(curWallpaperIndex); |
| 2735 | try { |
| 2736 | wallpaper.mClient.dispatchWallpaperCommand(action, |
| 2737 | x, y, z, extras, sync); |
| 2738 | // We only want to be synchronous with one wallpaper. |
| 2739 | sync = false; |
| 2740 | } catch (RemoteException e) { |
| 2741 | } |
| 2742 | } |
| 2743 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2744 | |
| Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 2745 | if (doWait) { |
| 2746 | // XXX Need to wait for result. |
| 2747 | } |
| 2748 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2749 | |
| Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 2750 | return null; |
| 2751 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2752 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2753 | public int relayoutWindow(Session session, IWindow client, |
| 2754 | WindowManager.LayoutParams attrs, int requestedWidth, |
| 2755 | int requestedHeight, int viewVisibility, boolean insetsPending, |
| 2756 | Rect outFrame, Rect outContentInsets, Rect outVisibleInsets, |
| Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 2757 | Configuration outConfig, Surface outSurface) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2758 | boolean displayed = false; |
| 2759 | boolean inTouchMode; |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2760 | boolean configChanged; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2761 | long origId = Binder.clearCallingIdentity(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2762 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2763 | synchronized(mWindowMap) { |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 2764 | WindowState win = windowForClientLocked(session, client, false); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2765 | if (win == null) { |
| 2766 | return 0; |
| 2767 | } |
| 2768 | win.mRequestedWidth = requestedWidth; |
| 2769 | win.mRequestedHeight = requestedHeight; |
| 2770 | |
| 2771 | if (attrs != null) { |
| 2772 | mPolicy.adjustWindowParamsLw(attrs); |
| 2773 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2774 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2775 | int attrChanges = 0; |
| 2776 | int flagChanges = 0; |
| 2777 | if (attrs != null) { |
| 2778 | flagChanges = win.mAttrs.flags ^= attrs.flags; |
| 2779 | attrChanges = win.mAttrs.copyFrom(attrs); |
| 2780 | } |
| 2781 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2782 | 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] | 2783 | |
| 2784 | if ((attrChanges & WindowManager.LayoutParams.ALPHA_CHANGED) != 0) { |
| 2785 | win.mAlpha = attrs.alpha; |
| 2786 | } |
| 2787 | |
| 2788 | final boolean scaledWindow = |
| 2789 | ((win.mAttrs.flags & WindowManager.LayoutParams.FLAG_SCALED) != 0); |
| 2790 | |
| 2791 | if (scaledWindow) { |
| 2792 | // requested{Width|Height} Surface's physical size |
| 2793 | // attrs.{width|height} Size on screen |
| 2794 | win.mHScale = (attrs.width != requestedWidth) ? |
| 2795 | (attrs.width / (float)requestedWidth) : 1.0f; |
| 2796 | win.mVScale = (attrs.height != requestedHeight) ? |
| 2797 | (attrs.height / (float)requestedHeight) : 1.0f; |
| Dianne Hackborn | 9b52a21 | 2009-12-11 14:51:35 -0800 | [diff] [blame] | 2798 | } else { |
| 2799 | win.mHScale = win.mVScale = 1; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2800 | } |
| 2801 | |
| 2802 | boolean imMayMove = (flagChanges&( |
| 2803 | WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM | |
| 2804 | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE)) != 0; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2805 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2806 | boolean focusMayChange = win.mViewVisibility != viewVisibility |
| 2807 | || ((flagChanges&WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) != 0) |
| 2808 | || (!win.mRelayoutCalled); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2809 | |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2810 | boolean wallpaperMayMove = win.mViewVisibility != viewVisibility |
| 2811 | && (win.mAttrs.flags & FLAG_SHOW_WALLPAPER) != 0; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2812 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2813 | win.mRelayoutCalled = true; |
| 2814 | final int oldVisibility = win.mViewVisibility; |
| 2815 | win.mViewVisibility = viewVisibility; |
| 2816 | if (viewVisibility == View.VISIBLE && |
| 2817 | (win.mAppToken == null || !win.mAppToken.clientHidden)) { |
| 2818 | displayed = !win.isVisibleLw(); |
| 2819 | if (win.mExiting) { |
| 2820 | win.mExiting = false; |
| Brad Fitzpatrick | 3fe3851 | 2010-11-03 11:46:54 -0700 | [diff] [blame] | 2821 | if (win.mAnimation != null) { |
| 2822 | win.mAnimation.cancel(); |
| 2823 | win.mAnimation = null; |
| 2824 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2825 | } |
| 2826 | if (win.mDestroying) { |
| 2827 | win.mDestroying = false; |
| 2828 | mDestroySurface.remove(win); |
| 2829 | } |
| 2830 | if (oldVisibility == View.GONE) { |
| 2831 | win.mEnterAnimationPending = true; |
| 2832 | } |
| Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 2833 | if (displayed) { |
| 2834 | if (win.mSurface != null && !win.mDrawPending |
| 2835 | && !win.mCommitDrawPending && !mDisplayFrozen |
| 2836 | && mPolicy.isScreenOn()) { |
| 2837 | applyEnterAnimationLocked(win); |
| 2838 | } |
| 2839 | if ((win.mAttrs.flags |
| 2840 | & WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON) != 0) { |
| 2841 | if (DEBUG_VISIBILITY) Slog.v(TAG, |
| 2842 | "Relayout window turning screen on: " + win); |
| 2843 | win.mTurnOnScreen = true; |
| 2844 | } |
| 2845 | int diff = 0; |
| 2846 | if (win.mConfiguration != mCurConfiguration |
| 2847 | && (win.mConfiguration == null |
| 2848 | || (diff=mCurConfiguration.diff(win.mConfiguration)) != 0)) { |
| 2849 | win.mConfiguration = mCurConfiguration; |
| 2850 | if (DEBUG_CONFIGURATION) { |
| 2851 | Slog.i(TAG, "Window " + win + " visible with new config: " |
| 2852 | + win.mConfiguration + " / 0x" |
| 2853 | + Integer.toHexString(diff)); |
| 2854 | } |
| 2855 | outConfig.setTo(mCurConfiguration); |
| 2856 | } |
| Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 2857 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2858 | if ((attrChanges&WindowManager.LayoutParams.FORMAT_CHANGED) != 0) { |
| 2859 | // To change the format, we need to re-build the surface. |
| 2860 | win.destroySurfaceLocked(); |
| 2861 | displayed = true; |
| 2862 | } |
| 2863 | try { |
| 2864 | Surface surface = win.createSurfaceLocked(); |
| 2865 | if (surface != null) { |
| 2866 | outSurface.copyFrom(surface); |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2867 | win.mReportDestroySurface = false; |
| 2868 | win.mSurfacePendingDestroy = false; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2869 | if (SHOW_TRANSACTIONS) Slog.i(TAG, |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 2870 | " OUT SURFACE " + outSurface + ": copied"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2871 | } else { |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 2872 | // For some reason there isn't a surface. Clear the |
| 2873 | // caller's object so they see the same state. |
| 2874 | outSurface.release(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2875 | } |
| 2876 | } catch (Exception e) { |
| Jeff Brown | 2e44b07 | 2011-01-24 15:21:56 -0800 | [diff] [blame] | 2877 | mInputMonitor.updateInputWindowsLw(true /*force*/); |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 2878 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2879 | Slog.w(TAG, "Exception thrown when creating surface for client " |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 2880 | + client + " (" + win.mAttrs.getTitle() + ")", |
| 2881 | e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2882 | Binder.restoreCallingIdentity(origId); |
| 2883 | return 0; |
| 2884 | } |
| 2885 | if (displayed) { |
| 2886 | focusMayChange = true; |
| 2887 | } |
| 2888 | if (win.mAttrs.type == TYPE_INPUT_METHOD |
| 2889 | && mInputMethodWindow == null) { |
| 2890 | mInputMethodWindow = win; |
| 2891 | imMayMove = true; |
| 2892 | } |
| Dianne Hackborn | 558947c | 2009-12-18 16:02:50 -0800 | [diff] [blame] | 2893 | if (win.mAttrs.type == TYPE_BASE_APPLICATION |
| 2894 | && win.mAppToken != null |
| 2895 | && win.mAppToken.startingWindow != null) { |
| 2896 | // Special handling of starting window over the base |
| 2897 | // window of the app: propagate lock screen flags to it, |
| 2898 | // to provide the correct semantics while starting. |
| 2899 | final int mask = |
| 2900 | WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED |
| Mike Lockwood | ef73162 | 2010-01-27 17:51:34 -0500 | [diff] [blame] | 2901 | | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD |
| 2902 | | WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON; |
| Dianne Hackborn | 558947c | 2009-12-18 16:02:50 -0800 | [diff] [blame] | 2903 | WindowManager.LayoutParams sa = win.mAppToken.startingWindow.mAttrs; |
| 2904 | sa.flags = (sa.flags&~mask) | (win.mAttrs.flags&mask); |
| 2905 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2906 | } else { |
| 2907 | win.mEnterAnimationPending = false; |
| 2908 | if (win.mSurface != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2909 | if (DEBUG_VISIBILITY) Slog.i(TAG, "Relayout invis " + win |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2910 | + ": mExiting=" + win.mExiting |
| 2911 | + " mSurfacePendingDestroy=" + win.mSurfacePendingDestroy); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2912 | // If we are not currently running the exit animation, we |
| 2913 | // need to see about starting one. |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2914 | if (!win.mExiting || win.mSurfacePendingDestroy) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2915 | // Try starting an animation; if there isn't one, we |
| 2916 | // can destroy the surface right away. |
| 2917 | int transit = WindowManagerPolicy.TRANSIT_EXIT; |
| 2918 | if (win.getAttrs().type == TYPE_APPLICATION_STARTING) { |
| 2919 | transit = WindowManagerPolicy.TRANSIT_PREVIEW_DONE; |
| 2920 | } |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2921 | if (!win.mSurfacePendingDestroy && win.isWinVisibleLw() && |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2922 | applyAnimationLocked(win, transit, false)) { |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2923 | focusMayChange = true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2924 | win.mExiting = true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2925 | } else if (win.isAnimating()) { |
| 2926 | // Currently in a hide animation... turn this into |
| 2927 | // an exit. |
| 2928 | win.mExiting = true; |
| Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 2929 | } else if (win == mWallpaperTarget) { |
| 2930 | // If the wallpaper is currently behind this |
| 2931 | // window, we need to change both of them inside |
| 2932 | // of a transaction to avoid artifacts. |
| 2933 | win.mExiting = true; |
| 2934 | win.mAnimating = true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2935 | } else { |
| 2936 | if (mInputMethodWindow == win) { |
| 2937 | mInputMethodWindow = null; |
| 2938 | } |
| 2939 | win.destroySurfaceLocked(); |
| 2940 | } |
| 2941 | } |
| 2942 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2943 | |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2944 | if (win.mSurface == null || (win.getAttrs().flags |
| 2945 | & WindowManager.LayoutParams.FLAG_KEEP_SURFACE_WHILE_ANIMATING) == 0 |
| 2946 | || win.mSurfacePendingDestroy) { |
| 2947 | // We are being called from a local process, which |
| 2948 | // means outSurface holds its current surface. Ensure the |
| 2949 | // surface object is cleared, but we don't want it actually |
| 2950 | // destroyed at this point. |
| 2951 | win.mSurfacePendingDestroy = false; |
| 2952 | outSurface.release(); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2953 | if (DEBUG_VISIBILITY) Slog.i(TAG, "Releasing surface in: " + win); |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2954 | } else if (win.mSurface != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2955 | if (DEBUG_VISIBILITY) Slog.i(TAG, |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 2956 | "Keeping surface, will report destroy: " + win); |
| 2957 | win.mReportDestroySurface = true; |
| 2958 | outSurface.copyFrom(win.mSurface); |
| 2959 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2960 | } |
| 2961 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2962 | if (focusMayChange) { |
| 2963 | //System.out.println("Focus may change: " + win.mAttrs.getTitle()); |
| Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 2964 | if (updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES, |
| 2965 | false /*updateInputWindows*/)) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2966 | imMayMove = false; |
| 2967 | } |
| 2968 | //System.out.println("Relayout " + win + ": focus=" + mCurrentFocus); |
| 2969 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2970 | |
| The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 2971 | // updateFocusedWindowLocked() already assigned layers so we only need to |
| 2972 | // reassign them at this point if the IM window state gets shuffled |
| 2973 | boolean assignLayers = false; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2974 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2975 | if (imMayMove) { |
| Dianne Hackborn | 8abd5f0 | 2009-11-20 18:09:03 -0800 | [diff] [blame] | 2976 | if (moveInputMethodWindowsIfNeededLocked(false) || displayed) { |
| 2977 | // Little hack here -- we -should- be able to rely on the |
| 2978 | // function to return true if the IME has moved and needs |
| 2979 | // its layer recomputed. However, if the IME was hidden |
| 2980 | // and isn't actually moved in the list, its layer may be |
| 2981 | // 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] | 2982 | assignLayers = true; |
| 2983 | } |
| 2984 | } |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2985 | if (wallpaperMayMove) { |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 2986 | if ((adjustWallpaperWindowsLocked()&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) { |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2987 | assignLayers = true; |
| 2988 | } |
| 2989 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 2990 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2991 | mLayoutNeeded = true; |
| 2992 | win.mGivenInsetsPending = insetsPending; |
| 2993 | if (assignLayers) { |
| 2994 | assignLayersLocked(); |
| 2995 | } |
| Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 2996 | configChanged = updateOrientationFromAppTokensLocked(false); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2997 | performLayoutAndPlaceSurfacesLocked(); |
| Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 2998 | if (displayed && win.mIsWallpaper) { |
| 2999 | updateWallpaperOffsetLocked(win, mDisplay.getWidth(), |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 3000 | mDisplay.getHeight(), false); |
| Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 3001 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3002 | if (win.mAppToken != null) { |
| 3003 | win.mAppToken.updateReportedVisibilityLocked(); |
| 3004 | } |
| 3005 | outFrame.set(win.mFrame); |
| 3006 | outContentInsets.set(win.mContentInsets); |
| 3007 | outVisibleInsets.set(win.mVisibleInsets); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3008 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3009 | TAG, "Relayout given client " + client.asBinder() |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3010 | + ", requestedWidth=" + requestedWidth |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3011 | + ", requestedHeight=" + requestedHeight |
| 3012 | + ", viewVisibility=" + viewVisibility |
| 3013 | + "\nRelayout returning frame=" + outFrame |
| 3014 | + ", surface=" + outSurface); |
| 3015 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3016 | if (localLOGV || DEBUG_FOCUS) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3017 | TAG, "Relayout of " + win + ": focusMayChange=" + focusMayChange); |
| 3018 | |
| 3019 | inTouchMode = mInTouchMode; |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 3020 | |
| Jeff Brown | 2e44b07 | 2011-01-24 15:21:56 -0800 | [diff] [blame] | 3021 | mInputMonitor.updateInputWindowsLw(true /*force*/); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3022 | } |
| 3023 | |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3024 | if (configChanged) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3025 | sendNewConfiguration(); |
| 3026 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3027 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3028 | Binder.restoreCallingIdentity(origId); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3029 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3030 | return (inTouchMode ? WindowManagerImpl.RELAYOUT_IN_TOUCH_MODE : 0) |
| 3031 | | (displayed ? WindowManagerImpl.RELAYOUT_FIRST_TIME : 0); |
| 3032 | } |
| 3033 | |
| 3034 | public void finishDrawingWindow(Session session, IWindow client) { |
| 3035 | final long origId = Binder.clearCallingIdentity(); |
| 3036 | synchronized(mWindowMap) { |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3037 | WindowState win = windowForClientLocked(session, client, false); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3038 | if (win != null && win.finishDrawingLocked()) { |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 3039 | if ((win.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0) { |
| 3040 | adjustWallpaperWindowsLocked(); |
| 3041 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3042 | mLayoutNeeded = true; |
| 3043 | performLayoutAndPlaceSurfacesLocked(); |
| 3044 | } |
| 3045 | } |
| 3046 | Binder.restoreCallingIdentity(origId); |
| 3047 | } |
| 3048 | |
| 3049 | private AttributeCache.Entry getCachedAnimations(WindowManager.LayoutParams lp) { |
| Dianne Hackborn | 08121bc | 2011-01-17 17:54:31 -0800 | [diff] [blame] | 3050 | 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] | 3051 | + (lp != null ? lp.packageName : null) |
| 3052 | + " resId=0x" + (lp != null ? Integer.toHexString(lp.windowAnimations) : null)); |
| 3053 | if (lp != null && lp.windowAnimations != 0) { |
| 3054 | // If this is a system resource, don't try to load it from the |
| 3055 | // application resources. It is nice to avoid loading application |
| 3056 | // resources if we can. |
| 3057 | String packageName = lp.packageName != null ? lp.packageName : "android"; |
| 3058 | int resId = lp.windowAnimations; |
| 3059 | if ((resId&0xFF000000) == 0x01000000) { |
| 3060 | packageName = "android"; |
| 3061 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3062 | 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] | 3063 | + packageName); |
| 3064 | return AttributeCache.instance().get(packageName, resId, |
| 3065 | com.android.internal.R.styleable.WindowAnimation); |
| 3066 | } |
| 3067 | return null; |
| 3068 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3069 | |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 3070 | private AttributeCache.Entry getCachedAnimations(String packageName, int resId) { |
| Dianne Hackborn | 08121bc | 2011-01-17 17:54:31 -0800 | [diff] [blame] | 3071 | if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: package=" |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 3072 | + packageName + " resId=0x" + Integer.toHexString(resId)); |
| 3073 | if (packageName != null) { |
| 3074 | if ((resId&0xFF000000) == 0x01000000) { |
| 3075 | packageName = "android"; |
| 3076 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3077 | if (DEBUG_ANIM) Slog.v(TAG, "Loading animations: picked package=" |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 3078 | + packageName); |
| 3079 | return AttributeCache.instance().get(packageName, resId, |
| 3080 | com.android.internal.R.styleable.WindowAnimation); |
| 3081 | } |
| 3082 | return null; |
| 3083 | } |
| 3084 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3085 | private void applyEnterAnimationLocked(WindowState win) { |
| 3086 | int transit = WindowManagerPolicy.TRANSIT_SHOW; |
| 3087 | if (win.mEnterAnimationPending) { |
| 3088 | win.mEnterAnimationPending = false; |
| 3089 | transit = WindowManagerPolicy.TRANSIT_ENTER; |
| 3090 | } |
| 3091 | |
| 3092 | applyAnimationLocked(win, transit, true); |
| 3093 | } |
| 3094 | |
| 3095 | private boolean applyAnimationLocked(WindowState win, |
| 3096 | int transit, boolean isEntrance) { |
| 3097 | if (win.mLocalAnimating && win.mAnimationIsEntrance == isEntrance) { |
| 3098 | // If we are trying to apply an animation, but already running |
| 3099 | // an animation of the same type, then just leave that one alone. |
| 3100 | return true; |
| 3101 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3102 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3103 | // Only apply an animation if the display isn't frozen. If it is |
| 3104 | // frozen, there is no reason to animate and it can cause strange |
| 3105 | // artifacts when we unfreeze the display if some different animation |
| 3106 | // is running. |
| Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 3107 | if (!mDisplayFrozen && mPolicy.isScreenOn()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3108 | int anim = mPolicy.selectAnimationLw(win, transit); |
| 3109 | int attr = -1; |
| 3110 | Animation a = null; |
| 3111 | if (anim != 0) { |
| 3112 | a = AnimationUtils.loadAnimation(mContext, anim); |
| 3113 | } else { |
| 3114 | switch (transit) { |
| 3115 | case WindowManagerPolicy.TRANSIT_ENTER: |
| 3116 | attr = com.android.internal.R.styleable.WindowAnimation_windowEnterAnimation; |
| 3117 | break; |
| 3118 | case WindowManagerPolicy.TRANSIT_EXIT: |
| 3119 | attr = com.android.internal.R.styleable.WindowAnimation_windowExitAnimation; |
| 3120 | break; |
| 3121 | case WindowManagerPolicy.TRANSIT_SHOW: |
| 3122 | attr = com.android.internal.R.styleable.WindowAnimation_windowShowAnimation; |
| 3123 | break; |
| 3124 | case WindowManagerPolicy.TRANSIT_HIDE: |
| 3125 | attr = com.android.internal.R.styleable.WindowAnimation_windowHideAnimation; |
| 3126 | break; |
| 3127 | } |
| 3128 | if (attr >= 0) { |
| 3129 | a = loadAnimation(win.mAttrs, attr); |
| 3130 | } |
| 3131 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3132 | if (DEBUG_ANIM) Slog.v(TAG, "applyAnimation: win=" + win |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3133 | + " anim=" + anim + " attr=0x" + Integer.toHexString(attr) |
| 3134 | + " mAnimation=" + win.mAnimation |
| 3135 | + " isEntrance=" + isEntrance); |
| 3136 | if (a != null) { |
| 3137 | if (DEBUG_ANIM) { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 3138 | RuntimeException e = null; |
| 3139 | if (!HIDE_STACK_CRAWLS) { |
| 3140 | e = new RuntimeException(); |
| 3141 | e.fillInStackTrace(); |
| 3142 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3143 | Slog.v(TAG, "Loaded animation " + a + " for " + win, e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3144 | } |
| 3145 | win.setAnimation(a); |
| 3146 | win.mAnimationIsEntrance = isEntrance; |
| 3147 | } |
| 3148 | } else { |
| 3149 | win.clearAnimation(); |
| 3150 | } |
| 3151 | |
| 3152 | return win.mAnimation != null; |
| 3153 | } |
| 3154 | |
| 3155 | private Animation loadAnimation(WindowManager.LayoutParams lp, int animAttr) { |
| 3156 | int anim = 0; |
| 3157 | Context context = mContext; |
| 3158 | if (animAttr >= 0) { |
| 3159 | AttributeCache.Entry ent = getCachedAnimations(lp); |
| 3160 | if (ent != null) { |
| 3161 | context = ent.context; |
| 3162 | anim = ent.array.getResourceId(animAttr, 0); |
| 3163 | } |
| 3164 | } |
| 3165 | if (anim != 0) { |
| 3166 | return AnimationUtils.loadAnimation(context, anim); |
| 3167 | } |
| 3168 | return null; |
| 3169 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3170 | |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 3171 | private Animation loadAnimation(String packageName, int resId) { |
| 3172 | int anim = 0; |
| 3173 | Context context = mContext; |
| 3174 | if (resId >= 0) { |
| 3175 | AttributeCache.Entry ent = getCachedAnimations(packageName, resId); |
| 3176 | if (ent != null) { |
| 3177 | context = ent.context; |
| 3178 | anim = resId; |
| 3179 | } |
| 3180 | } |
| 3181 | if (anim != 0) { |
| 3182 | return AnimationUtils.loadAnimation(context, anim); |
| 3183 | } |
| 3184 | return null; |
| 3185 | } |
| 3186 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3187 | private boolean applyAnimationLocked(AppWindowToken wtoken, |
| 3188 | WindowManager.LayoutParams lp, int transit, boolean enter) { |
| 3189 | // Only apply an animation if the display isn't frozen. If it is |
| 3190 | // frozen, there is no reason to animate and it can cause strange |
| 3191 | // artifacts when we unfreeze the display if some different animation |
| 3192 | // is running. |
| Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 3193 | if (!mDisplayFrozen && mPolicy.isScreenOn()) { |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 3194 | Animation a; |
| Mitsuru Oshima | d2967e2 | 2009-07-20 14:01:43 -0700 | [diff] [blame] | 3195 | if (lp != null && (lp.flags & FLAG_COMPATIBLE_WINDOW) != 0) { |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 3196 | a = new FadeInOutAnimation(enter); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3197 | if (DEBUG_ANIM) Slog.v(TAG, |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 3198 | "applying FadeInOutAnimation for a window in compatibility mode"); |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 3199 | } else if (mNextAppTransitionPackage != null) { |
| 3200 | a = loadAnimation(mNextAppTransitionPackage, enter ? |
| 3201 | mNextAppTransitionEnter : mNextAppTransitionExit); |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 3202 | } else { |
| 3203 | int animAttr = 0; |
| 3204 | switch (transit) { |
| 3205 | case WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN: |
| 3206 | animAttr = enter |
| 3207 | ? com.android.internal.R.styleable.WindowAnimation_activityOpenEnterAnimation |
| 3208 | : com.android.internal.R.styleable.WindowAnimation_activityOpenExitAnimation; |
| 3209 | break; |
| 3210 | case WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE: |
| 3211 | animAttr = enter |
| 3212 | ? com.android.internal.R.styleable.WindowAnimation_activityCloseEnterAnimation |
| 3213 | : com.android.internal.R.styleable.WindowAnimation_activityCloseExitAnimation; |
| 3214 | break; |
| 3215 | case WindowManagerPolicy.TRANSIT_TASK_OPEN: |
| 3216 | animAttr = enter |
| 3217 | ? com.android.internal.R.styleable.WindowAnimation_taskOpenEnterAnimation |
| 3218 | : com.android.internal.R.styleable.WindowAnimation_taskOpenExitAnimation; |
| 3219 | break; |
| 3220 | case WindowManagerPolicy.TRANSIT_TASK_CLOSE: |
| 3221 | animAttr = enter |
| 3222 | ? com.android.internal.R.styleable.WindowAnimation_taskCloseEnterAnimation |
| 3223 | : com.android.internal.R.styleable.WindowAnimation_taskCloseExitAnimation; |
| 3224 | break; |
| 3225 | case WindowManagerPolicy.TRANSIT_TASK_TO_FRONT: |
| 3226 | animAttr = enter |
| 3227 | ? com.android.internal.R.styleable.WindowAnimation_taskToFrontEnterAnimation |
| 3228 | : com.android.internal.R.styleable.WindowAnimation_taskToFrontExitAnimation; |
| 3229 | break; |
| 3230 | case WindowManagerPolicy.TRANSIT_TASK_TO_BACK: |
| 3231 | animAttr = enter |
| Mitsuru Oshima | 5a2b91d | 2009-07-16 16:30:02 -0700 | [diff] [blame] | 3232 | ? com.android.internal.R.styleable.WindowAnimation_taskToBackEnterAnimation |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 3233 | : com.android.internal.R.styleable.WindowAnimation_taskToBackExitAnimation; |
| 3234 | break; |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 3235 | case WindowManagerPolicy.TRANSIT_WALLPAPER_OPEN: |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 3236 | animAttr = enter |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 3237 | ? com.android.internal.R.styleable.WindowAnimation_wallpaperOpenEnterAnimation |
| 3238 | : com.android.internal.R.styleable.WindowAnimation_wallpaperOpenExitAnimation; |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 3239 | break; |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 3240 | case WindowManagerPolicy.TRANSIT_WALLPAPER_CLOSE: |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 3241 | animAttr = enter |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 3242 | ? com.android.internal.R.styleable.WindowAnimation_wallpaperCloseEnterAnimation |
| 3243 | : com.android.internal.R.styleable.WindowAnimation_wallpaperCloseExitAnimation; |
| 3244 | break; |
| 3245 | case WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_OPEN: |
| 3246 | animAttr = enter |
| 3247 | ? com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenEnterAnimation |
| 3248 | : com.android.internal.R.styleable.WindowAnimation_wallpaperIntraOpenExitAnimation; |
| 3249 | break; |
| 3250 | case WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_CLOSE: |
| 3251 | animAttr = enter |
| 3252 | ? com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseEnterAnimation |
| 3253 | : com.android.internal.R.styleable.WindowAnimation_wallpaperIntraCloseExitAnimation; |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 3254 | break; |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 3255 | } |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 3256 | a = animAttr != 0 ? loadAnimation(lp, animAttr) : null; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3257 | if (DEBUG_ANIM) Slog.v(TAG, "applyAnimation: wtoken=" + wtoken |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 3258 | + " anim=" + a |
| 3259 | + " animAttr=0x" + Integer.toHexString(animAttr) |
| 3260 | + " transit=" + transit); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3261 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3262 | if (a != null) { |
| 3263 | if (DEBUG_ANIM) { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 3264 | RuntimeException e = null; |
| 3265 | if (!HIDE_STACK_CRAWLS) { |
| 3266 | e = new RuntimeException(); |
| 3267 | e.fillInStackTrace(); |
| 3268 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3269 | Slog.v(TAG, "Loaded animation " + a + " for " + wtoken, e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3270 | } |
| 3271 | wtoken.setAnimation(a); |
| 3272 | } |
| 3273 | } else { |
| 3274 | wtoken.clearAnimation(); |
| 3275 | } |
| 3276 | |
| 3277 | return wtoken.animation != null; |
| 3278 | } |
| 3279 | |
| 3280 | // ------------------------------------------------------------- |
| 3281 | // Application Window Tokens |
| 3282 | // ------------------------------------------------------------- |
| 3283 | |
| 3284 | public void validateAppTokens(List tokens) { |
| 3285 | int v = tokens.size()-1; |
| 3286 | int m = mAppTokens.size()-1; |
| 3287 | while (v >= 0 && m >= 0) { |
| 3288 | AppWindowToken wtoken = mAppTokens.get(m); |
| 3289 | if (wtoken.removed) { |
| 3290 | m--; |
| 3291 | continue; |
| 3292 | } |
| 3293 | if (tokens.get(v) != wtoken.token) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3294 | 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] | 3295 | + " @ " + v + ", internal is " + wtoken.token + " @ " + m); |
| 3296 | } |
| 3297 | v--; |
| 3298 | m--; |
| 3299 | } |
| 3300 | while (v >= 0) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3301 | 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] | 3302 | v--; |
| 3303 | } |
| 3304 | while (m >= 0) { |
| 3305 | AppWindowToken wtoken = mAppTokens.get(m); |
| 3306 | if (!wtoken.removed) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3307 | Slog.w(TAG, "Invalid internal token: " + wtoken.token + " @ " + m); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3308 | } |
| 3309 | m--; |
| 3310 | } |
| 3311 | } |
| 3312 | |
| 3313 | boolean checkCallingPermission(String permission, String func) { |
| 3314 | // Quick check: if the calling permission is me, it's all okay. |
| 3315 | if (Binder.getCallingPid() == Process.myPid()) { |
| 3316 | return true; |
| 3317 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3318 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3319 | if (mContext.checkCallingPermission(permission) |
| 3320 | == PackageManager.PERMISSION_GRANTED) { |
| 3321 | return true; |
| 3322 | } |
| 3323 | String msg = "Permission Denial: " + func + " from pid=" |
| 3324 | + Binder.getCallingPid() |
| 3325 | + ", uid=" + Binder.getCallingUid() |
| 3326 | + " requires " + permission; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3327 | Slog.w(TAG, msg); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3328 | return false; |
| 3329 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3330 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3331 | AppWindowToken findAppWindowToken(IBinder token) { |
| 3332 | WindowToken wtoken = mTokenMap.get(token); |
| 3333 | if (wtoken == null) { |
| 3334 | return null; |
| 3335 | } |
| 3336 | return wtoken.appWindowToken; |
| 3337 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3338 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3339 | public void addWindowToken(IBinder token, int type) { |
| 3340 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3341 | "addWindowToken()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3342 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3343 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3344 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3345 | synchronized(mWindowMap) { |
| 3346 | WindowToken wtoken = mTokenMap.get(token); |
| 3347 | if (wtoken != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3348 | 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] | 3349 | return; |
| 3350 | } |
| 3351 | wtoken = new WindowToken(token, type, true); |
| 3352 | mTokenMap.put(token, wtoken); |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 3353 | if (type == TYPE_WALLPAPER) { |
| 3354 | mWallpaperTokens.add(wtoken); |
| 3355 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3356 | } |
| 3357 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3358 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3359 | public void removeWindowToken(IBinder token) { |
| 3360 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3361 | "removeWindowToken()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3362 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3363 | } |
| 3364 | |
| 3365 | final long origId = Binder.clearCallingIdentity(); |
| 3366 | synchronized(mWindowMap) { |
| 3367 | WindowToken wtoken = mTokenMap.remove(token); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3368 | if (wtoken != null) { |
| 3369 | boolean delayed = false; |
| 3370 | if (!wtoken.hidden) { |
| 3371 | wtoken.hidden = true; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3372 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3373 | final int N = wtoken.windows.size(); |
| 3374 | boolean changed = false; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3375 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3376 | for (int i=0; i<N; i++) { |
| 3377 | WindowState win = wtoken.windows.get(i); |
| 3378 | |
| 3379 | if (win.isAnimating()) { |
| 3380 | delayed = true; |
| 3381 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3382 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3383 | if (win.isVisibleNow()) { |
| 3384 | applyAnimationLocked(win, |
| 3385 | WindowManagerPolicy.TRANSIT_EXIT, false); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3386 | changed = true; |
| 3387 | } |
| 3388 | } |
| 3389 | |
| 3390 | if (changed) { |
| 3391 | mLayoutNeeded = true; |
| 3392 | performLayoutAndPlaceSurfacesLocked(); |
| Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 3393 | updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL, |
| 3394 | false /*updateInputWindows*/); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3395 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3396 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3397 | if (delayed) { |
| 3398 | mExitingTokens.add(wtoken); |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 3399 | } else if (wtoken.windowType == TYPE_WALLPAPER) { |
| 3400 | mWallpaperTokens.remove(wtoken); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3401 | } |
| 3402 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3403 | |
| Jeff Brown | 2e44b07 | 2011-01-24 15:21:56 -0800 | [diff] [blame] | 3404 | mInputMonitor.updateInputWindowsLw(true /*force*/); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3405 | } else { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3406 | 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] | 3407 | } |
| 3408 | } |
| 3409 | Binder.restoreCallingIdentity(origId); |
| 3410 | } |
| 3411 | |
| 3412 | public void addAppToken(int addPos, IApplicationToken token, |
| 3413 | int groupId, int requestedOrientation, boolean fullscreen) { |
| 3414 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3415 | "addAppToken()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3416 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3417 | } |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 3418 | |
| 3419 | // Get the dispatching timeout here while we are not holding any locks so that it |
| 3420 | // can be cached by the AppWindowToken. The timeout value is used later by the |
| 3421 | // input dispatcher in code that does hold locks. If we did not cache the value |
| 3422 | // here we would run the chance of introducing a deadlock between the window manager |
| 3423 | // (which holds locks while updating the input dispatcher state) and the activity manager |
| 3424 | // (which holds locks while querying the application token). |
| 3425 | long inputDispatchingTimeoutNanos; |
| 3426 | try { |
| 3427 | inputDispatchingTimeoutNanos = token.getKeyDispatchingTimeout() * 1000000L; |
| 3428 | } catch (RemoteException ex) { |
| 3429 | Slog.w(TAG, "Could not get dispatching timeout.", ex); |
| 3430 | inputDispatchingTimeoutNanos = DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS; |
| 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 | synchronized(mWindowMap) { |
| 3434 | AppWindowToken wtoken = findAppWindowToken(token.asBinder()); |
| 3435 | if (wtoken != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3436 | 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] | 3437 | return; |
| 3438 | } |
| 3439 | wtoken = new AppWindowToken(token); |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 3440 | wtoken.inputDispatchingTimeoutNanos = inputDispatchingTimeoutNanos; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3441 | wtoken.groupId = groupId; |
| 3442 | wtoken.appFullscreen = fullscreen; |
| 3443 | wtoken.requestedOrientation = requestedOrientation; |
| Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 3444 | 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] | 3445 | mAppTokens.add(addPos, wtoken); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3446 | mTokenMap.put(token.asBinder(), wtoken); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3447 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3448 | // Application tokens start out hidden. |
| 3449 | wtoken.hidden = true; |
| 3450 | wtoken.hiddenRequested = true; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3451 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3452 | //dump(); |
| 3453 | } |
| 3454 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3455 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3456 | public void setAppGroupId(IBinder token, int groupId) { |
| 3457 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3458 | "setAppStartingIcon()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3459 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3460 | } |
| 3461 | |
| 3462 | synchronized(mWindowMap) { |
| 3463 | AppWindowToken wtoken = findAppWindowToken(token); |
| 3464 | if (wtoken == null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3465 | 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] | 3466 | return; |
| 3467 | } |
| 3468 | wtoken.groupId = groupId; |
| 3469 | } |
| 3470 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3471 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3472 | public int getOrientationFromWindowsLocked() { |
| 3473 | int pos = mWindows.size() - 1; |
| 3474 | while (pos >= 0) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 3475 | WindowState wtoken = mWindows.get(pos); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3476 | pos--; |
| 3477 | if (wtoken.mAppToken != null) { |
| 3478 | // We hit an application window. so the orientation will be determined by the |
| 3479 | // app window. No point in continuing further. |
| 3480 | return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
| 3481 | } |
| Christopher Tate | b696aee | 2010-04-02 19:08:30 -0700 | [diff] [blame] | 3482 | if (!wtoken.isVisibleLw() || !wtoken.mPolicyVisibilityAfterAnim) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3483 | continue; |
| 3484 | } |
| 3485 | int req = wtoken.mAttrs.screenOrientation; |
| 3486 | if((req == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) || |
| 3487 | (req == ActivityInfo.SCREEN_ORIENTATION_BEHIND)){ |
| 3488 | continue; |
| 3489 | } else { |
| 3490 | return req; |
| 3491 | } |
| 3492 | } |
| 3493 | return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
| 3494 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3495 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3496 | public int getOrientationFromAppTokensLocked() { |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3497 | int pos = mAppTokens.size() - 1; |
| 3498 | int curGroup = 0; |
| 3499 | int lastOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
| 3500 | boolean findingBehind = false; |
| 3501 | boolean haveGroup = false; |
| 3502 | boolean lastFullscreen = false; |
| 3503 | while (pos >= 0) { |
| 3504 | AppWindowToken wtoken = mAppTokens.get(pos); |
| 3505 | pos--; |
| 3506 | // if we're about to tear down this window and not seek for |
| 3507 | // the behind activity, don't use it for orientation |
| 3508 | if (!findingBehind |
| 3509 | && (!wtoken.hidden && wtoken.hiddenRequested)) { |
| 3510 | continue; |
| 3511 | } |
| 3512 | |
| 3513 | if (!haveGroup) { |
| 3514 | // We ignore any hidden applications on the top. |
| 3515 | if (wtoken.hiddenRequested || wtoken.willBeHidden) { |
| The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3516 | continue; |
| 3517 | } |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3518 | haveGroup = true; |
| 3519 | curGroup = wtoken.groupId; |
| 3520 | lastOrientation = wtoken.requestedOrientation; |
| 3521 | } else if (curGroup != wtoken.groupId) { |
| 3522 | // If we have hit a new application group, and the bottom |
| 3523 | // of the previous group didn't explicitly say to use |
| 3524 | // the orientation behind it, and the last app was |
| 3525 | // full screen, then we'll stick with the |
| 3526 | // user's orientation. |
| 3527 | if (lastOrientation != ActivityInfo.SCREEN_ORIENTATION_BEHIND |
| 3528 | && lastFullscreen) { |
| 3529 | return lastOrientation; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3530 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3531 | } |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3532 | int or = wtoken.requestedOrientation; |
| 3533 | // If this application is fullscreen, and didn't explicitly say |
| 3534 | // to use the orientation behind it, then just take whatever |
| 3535 | // orientation it has and ignores whatever is under it. |
| 3536 | lastFullscreen = wtoken.appFullscreen; |
| 3537 | if (lastFullscreen |
| 3538 | && or != ActivityInfo.SCREEN_ORIENTATION_BEHIND) { |
| 3539 | return or; |
| 3540 | } |
| 3541 | // If this application has requested an explicit orientation, |
| 3542 | // then use it. |
| Dianne Hackborn | e5439f2 | 2010-10-02 16:53:50 -0700 | [diff] [blame] | 3543 | if (or != ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED |
| 3544 | && or != ActivityInfo.SCREEN_ORIENTATION_BEHIND) { |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3545 | return or; |
| 3546 | } |
| 3547 | findingBehind |= (or == ActivityInfo.SCREEN_ORIENTATION_BEHIND); |
| 3548 | } |
| 3549 | return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3550 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3551 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3552 | public Configuration updateOrientationFromAppTokens( |
| The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3553 | Configuration currentConfig, IBinder freezeThisOneIfNeeded) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3554 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3555 | "updateOrientationFromAppTokens()")) { |
| 3556 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| 3557 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3558 | |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3559 | Configuration config = null; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3560 | long ident = Binder.clearCallingIdentity(); |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3561 | |
| 3562 | synchronized(mWindowMap) { |
| Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 3563 | if (updateOrientationFromAppTokensLocked(false)) { |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3564 | if (freezeThisOneIfNeeded != null) { |
| 3565 | AppWindowToken wtoken = findAppWindowToken( |
| 3566 | freezeThisOneIfNeeded); |
| 3567 | if (wtoken != null) { |
| 3568 | startAppFreezingScreenLocked(wtoken, |
| 3569 | ActivityInfo.CONFIG_ORIENTATION); |
| 3570 | } |
| 3571 | } |
| 3572 | config = computeNewConfigurationLocked(); |
| 3573 | |
| 3574 | } else if (currentConfig != null) { |
| 3575 | // No obvious action we need to take, but if our current |
| Casey Burkhardt | 0920ba5 | 2010-08-03 12:04:19 -0700 | [diff] [blame] | 3576 | // state mismatches the activity manager's, update it, |
| 3577 | // disregarding font scale, which should remain set to |
| 3578 | // the value of the previous configuration. |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3579 | mTempConfiguration.setToDefaults(); |
| Casey Burkhardt | 0920ba5 | 2010-08-03 12:04:19 -0700 | [diff] [blame] | 3580 | mTempConfiguration.fontScale = currentConfig.fontScale; |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3581 | if (computeNewConfigurationLocked(mTempConfiguration)) { |
| 3582 | if (currentConfig.diff(mTempConfiguration) != 0) { |
| 3583 | mWaitingForConfig = true; |
| 3584 | mLayoutNeeded = true; |
| Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 3585 | startFreezingDisplayLocked(false); |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3586 | config = new Configuration(mTempConfiguration); |
| 3587 | } |
| 3588 | } |
| 3589 | } |
| 3590 | } |
| 3591 | |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3592 | Binder.restoreCallingIdentity(ident); |
| 3593 | return config; |
| 3594 | } |
| 3595 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3596 | /* |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3597 | * Determine the new desired orientation of the display, returning |
| 3598 | * a non-null new Configuration if it has changed from the current |
| 3599 | * orientation. IF TRUE IS RETURNED SOMEONE MUST CALL |
| 3600 | * setNewConfiguration() TO TELL THE WINDOW MANAGER IT CAN UNFREEZE THE |
| 3601 | * SCREEN. This will typically be done for you if you call |
| 3602 | * sendNewConfiguration(). |
| 3603 | * |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3604 | * The orientation is computed from non-application windows first. If none of |
| 3605 | * the non-application windows specify orientation, the orientation is computed from |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3606 | * application tokens. |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3607 | * @see android.view.IWindowManager#updateOrientationFromAppTokens( |
| 3608 | * android.os.IBinder) |
| 3609 | */ |
| Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 3610 | boolean updateOrientationFromAppTokensLocked(boolean inTransaction) { |
| 3611 | if (mDisplayFrozen || mOpeningApps.size() > 0 || mClosingApps.size() > 0) { |
| Christopher Tate | b696aee | 2010-04-02 19:08:30 -0700 | [diff] [blame] | 3612 | // If the display is frozen, some activities may be in the middle |
| 3613 | // of restarting, and thus have removed their old window. If the |
| 3614 | // window has the flag to hide the lock screen, then the lock screen |
| 3615 | // can re-appear and inflict its own orientation on us. Keep the |
| 3616 | // orientation stable until this all settles down. |
| 3617 | return false; |
| 3618 | } |
| 3619 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3620 | boolean changed = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3621 | long ident = Binder.clearCallingIdentity(); |
| 3622 | try { |
| The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 3623 | int req = computeForcedAppOrientationLocked(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3624 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3625 | if (req != mForcedAppOrientation) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3626 | mForcedAppOrientation = req; |
| 3627 | //send a message to Policy indicating orientation change to take |
| 3628 | //action like disabling/enabling sensors etc., |
| The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 3629 | mPolicy.setCurrentOrientationLw(req); |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3630 | if (setRotationUncheckedLocked(WindowManagerPolicy.USE_LAST_ROTATION, |
| Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 3631 | mLastRotationFlags | Surface.FLAGS_ORIENTATION_ANIMATION_DISABLE, |
| 3632 | inTransaction)) { |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3633 | changed = true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3634 | } |
| 3635 | } |
| The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3636 | |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3637 | return changed; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3638 | } finally { |
| 3639 | Binder.restoreCallingIdentity(ident); |
| 3640 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3641 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3642 | |
| The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 3643 | int computeForcedAppOrientationLocked() { |
| 3644 | int req = getOrientationFromWindowsLocked(); |
| 3645 | if (req == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) { |
| 3646 | req = getOrientationFromAppTokensLocked(); |
| 3647 | } |
| 3648 | return req; |
| 3649 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3650 | |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 3651 | public void setNewConfiguration(Configuration config) { |
| 3652 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3653 | "setNewConfiguration()")) { |
| 3654 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| 3655 | } |
| 3656 | |
| 3657 | synchronized(mWindowMap) { |
| 3658 | mCurConfiguration = new Configuration(config); |
| 3659 | mWaitingForConfig = false; |
| 3660 | performLayoutAndPlaceSurfacesLocked(); |
| 3661 | } |
| 3662 | } |
| 3663 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3664 | public void setAppOrientation(IApplicationToken token, int requestedOrientation) { |
| 3665 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3666 | "setAppOrientation()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3667 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3668 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3669 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3670 | synchronized(mWindowMap) { |
| 3671 | AppWindowToken wtoken = findAppWindowToken(token.asBinder()); |
| 3672 | if (wtoken == null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3673 | 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] | 3674 | return; |
| 3675 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3676 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3677 | wtoken.requestedOrientation = requestedOrientation; |
| 3678 | } |
| 3679 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3680 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3681 | public int getAppOrientation(IApplicationToken token) { |
| 3682 | synchronized(mWindowMap) { |
| 3683 | AppWindowToken wtoken = findAppWindowToken(token.asBinder()); |
| 3684 | if (wtoken == null) { |
| 3685 | return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
| 3686 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3687 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3688 | return wtoken.requestedOrientation; |
| 3689 | } |
| 3690 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3691 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3692 | public void setFocusedApp(IBinder token, boolean moveFocusNow) { |
| 3693 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3694 | "setFocusedApp()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3695 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3696 | } |
| 3697 | |
| 3698 | synchronized(mWindowMap) { |
| 3699 | boolean changed = false; |
| 3700 | if (token == null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3701 | 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] | 3702 | changed = mFocusedApp != null; |
| 3703 | mFocusedApp = null; |
| Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 3704 | if (changed) { |
| 3705 | mInputMonitor.setFocusedAppLw(null); |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 3706 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3707 | } else { |
| 3708 | AppWindowToken newFocus = findAppWindowToken(token); |
| 3709 | if (newFocus == null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3710 | 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] | 3711 | return; |
| 3712 | } |
| 3713 | changed = mFocusedApp != newFocus; |
| 3714 | mFocusedApp = newFocus; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3715 | if (DEBUG_FOCUS) Slog.v(TAG, "Set focused app to: " + mFocusedApp); |
| Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 3716 | if (changed) { |
| 3717 | mInputMonitor.setFocusedAppLw(newFocus); |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 3718 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3719 | } |
| 3720 | |
| 3721 | if (moveFocusNow && changed) { |
| 3722 | final long origId = Binder.clearCallingIdentity(); |
| Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 3723 | updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL, true /*updateInputWindows*/); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3724 | Binder.restoreCallingIdentity(origId); |
| 3725 | } |
| 3726 | } |
| 3727 | } |
| 3728 | |
| Dianne Hackborn | 7da6ac3 | 2010-12-09 19:22:04 -0800 | [diff] [blame] | 3729 | public void prepareAppTransition(int transit, boolean alwaysKeepCurrent) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3730 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3731 | "prepareAppTransition()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3732 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3733 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3734 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3735 | synchronized(mWindowMap) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3736 | if (DEBUG_APP_TRANSITIONS) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3737 | TAG, "Prepare app transition: transit=" + transit |
| 3738 | + " mNextAppTransition=" + mNextAppTransition); |
| Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 3739 | if (!mDisplayFrozen && mPolicy.isScreenOn()) { |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 3740 | if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET |
| 3741 | || mNextAppTransition == WindowManagerPolicy.TRANSIT_NONE) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3742 | mNextAppTransition = transit; |
| Dianne Hackborn | 7da6ac3 | 2010-12-09 19:22:04 -0800 | [diff] [blame] | 3743 | } else if (!alwaysKeepCurrent) { |
| 3744 | if (transit == WindowManagerPolicy.TRANSIT_TASK_OPEN |
| 3745 | && mNextAppTransition == WindowManagerPolicy.TRANSIT_TASK_CLOSE) { |
| 3746 | // Opening a new task always supersedes a close for the anim. |
| 3747 | mNextAppTransition = transit; |
| 3748 | } else if (transit == WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN |
| 3749 | && mNextAppTransition == WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE) { |
| 3750 | // Opening a new activity always supersedes a close for the anim. |
| 3751 | mNextAppTransition = transit; |
| 3752 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3753 | } |
| 3754 | mAppTransitionReady = false; |
| 3755 | mAppTransitionTimeout = false; |
| 3756 | mStartingIconInTransition = false; |
| 3757 | mSkipAppTransitionAnimation = false; |
| 3758 | mH.removeMessages(H.APP_TRANSITION_TIMEOUT); |
| 3759 | mH.sendMessageDelayed(mH.obtainMessage(H.APP_TRANSITION_TIMEOUT), |
| 3760 | 5000); |
| 3761 | } |
| 3762 | } |
| 3763 | } |
| 3764 | |
| 3765 | public int getPendingAppTransition() { |
| 3766 | return mNextAppTransition; |
| 3767 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3768 | |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 3769 | public void overridePendingAppTransition(String packageName, |
| 3770 | int enterAnim, int exitAnim) { |
| Dianne Hackborn | 8b571a8 | 2009-09-25 16:09:43 -0700 | [diff] [blame] | 3771 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 3772 | mNextAppTransitionPackage = packageName; |
| 3773 | mNextAppTransitionEnter = enterAnim; |
| 3774 | mNextAppTransitionExit = exitAnim; |
| 3775 | } |
| 3776 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3777 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3778 | public void executeAppTransition() { |
| 3779 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3780 | "executeAppTransition()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3781 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3782 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3783 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3784 | synchronized(mWindowMap) { |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 3785 | if (DEBUG_APP_TRANSITIONS) { |
| 3786 | RuntimeException e = new RuntimeException("here"); |
| 3787 | e.fillInStackTrace(); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3788 | Slog.w(TAG, "Execute app transition: mNextAppTransition=" |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 3789 | + mNextAppTransition, e); |
| 3790 | } |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 3791 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3792 | mAppTransitionReady = true; |
| 3793 | final long origId = Binder.clearCallingIdentity(); |
| 3794 | performLayoutAndPlaceSurfacesLocked(); |
| 3795 | Binder.restoreCallingIdentity(origId); |
| 3796 | } |
| 3797 | } |
| 3798 | } |
| 3799 | |
| 3800 | public void setAppStartingWindow(IBinder token, String pkg, |
| 3801 | int theme, CharSequence nonLocalizedLabel, int labelRes, int icon, |
| Dianne Hackborn | 7eec10e | 2010-11-12 18:03:47 -0800 | [diff] [blame] | 3802 | int windowFlags, IBinder transferFrom, boolean createIfNeeded) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3803 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3804 | "setAppStartingIcon()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3805 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3806 | } |
| 3807 | |
| 3808 | synchronized(mWindowMap) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3809 | if (DEBUG_STARTING_WINDOW) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3810 | TAG, "setAppStartingIcon: token=" + token + " pkg=" + pkg |
| 3811 | + " transferFrom=" + transferFrom); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3812 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3813 | AppWindowToken wtoken = findAppWindowToken(token); |
| 3814 | if (wtoken == null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3815 | 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] | 3816 | return; |
| 3817 | } |
| 3818 | |
| 3819 | // If the display is frozen, we won't do anything until the |
| 3820 | // actual window is displayed so there is no reason to put in |
| 3821 | // the starting window. |
| Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 3822 | if (mDisplayFrozen || !mPolicy.isScreenOn()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3823 | return; |
| 3824 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3825 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3826 | if (wtoken.startingData != null) { |
| 3827 | return; |
| 3828 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3829 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3830 | if (transferFrom != null) { |
| 3831 | AppWindowToken ttoken = findAppWindowToken(transferFrom); |
| 3832 | if (ttoken != null) { |
| 3833 | WindowState startingWindow = ttoken.startingWindow; |
| 3834 | if (startingWindow != null) { |
| 3835 | if (mStartingIconInTransition) { |
| 3836 | // In this case, the starting icon has already |
| 3837 | // been displayed, so start letting windows get |
| 3838 | // shown immediately without any more transitions. |
| 3839 | mSkipAppTransitionAnimation = true; |
| 3840 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3841 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3842 | "Moving existing starting from " + ttoken |
| 3843 | + " to " + wtoken); |
| 3844 | final long origId = Binder.clearCallingIdentity(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3845 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3846 | // Transfer the starting window over to the new |
| 3847 | // token. |
| 3848 | wtoken.startingData = ttoken.startingData; |
| 3849 | wtoken.startingView = ttoken.startingView; |
| 3850 | wtoken.startingWindow = startingWindow; |
| 3851 | ttoken.startingData = null; |
| 3852 | ttoken.startingView = null; |
| 3853 | ttoken.startingWindow = null; |
| 3854 | ttoken.startingMoved = true; |
| 3855 | startingWindow.mToken = wtoken; |
| Dianne Hackborn | ef49c57 | 2009-03-24 19:27:32 -0700 | [diff] [blame] | 3856 | startingWindow.mRootToken = wtoken; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3857 | startingWindow.mAppToken = wtoken; |
| Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 3858 | if (DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) Slog.v(TAG, |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 3859 | "Removing starting window: " + startingWindow); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3860 | mWindows.remove(startingWindow); |
| Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 3861 | mWindowsChanged = true; |
| Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 3862 | if (DEBUG_ADD_REMOVE) Slog.v(TAG, "Removing starting " + startingWindow |
| 3863 | + " from " + ttoken); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3864 | ttoken.windows.remove(startingWindow); |
| 3865 | ttoken.allAppWindows.remove(startingWindow); |
| 3866 | addWindowToListInOrderLocked(startingWindow, true); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3867 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3868 | // Propagate other interesting state between the |
| 3869 | // tokens. If the old token is displayed, we should |
| 3870 | // immediately force the new one to be displayed. If |
| 3871 | // it is animating, we need to move that animation to |
| 3872 | // the new one. |
| 3873 | if (ttoken.allDrawn) { |
| 3874 | wtoken.allDrawn = true; |
| 3875 | } |
| 3876 | if (ttoken.firstWindowDrawn) { |
| 3877 | wtoken.firstWindowDrawn = true; |
| 3878 | } |
| 3879 | if (!ttoken.hidden) { |
| 3880 | wtoken.hidden = false; |
| 3881 | wtoken.hiddenRequested = false; |
| 3882 | wtoken.willBeHidden = false; |
| 3883 | } |
| 3884 | if (wtoken.clientHidden != ttoken.clientHidden) { |
| 3885 | wtoken.clientHidden = ttoken.clientHidden; |
| 3886 | wtoken.sendAppVisibilityToClients(); |
| 3887 | } |
| 3888 | if (ttoken.animation != null) { |
| 3889 | wtoken.animation = ttoken.animation; |
| 3890 | wtoken.animating = ttoken.animating; |
| 3891 | wtoken.animLayerAdjustment = ttoken.animLayerAdjustment; |
| 3892 | ttoken.animation = null; |
| 3893 | ttoken.animLayerAdjustment = 0; |
| 3894 | wtoken.updateLayers(); |
| 3895 | ttoken.updateLayers(); |
| 3896 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3897 | |
| Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 3898 | updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES, |
| 3899 | true /*updateInputWindows*/); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3900 | mLayoutNeeded = true; |
| 3901 | performLayoutAndPlaceSurfacesLocked(); |
| 3902 | Binder.restoreCallingIdentity(origId); |
| 3903 | return; |
| 3904 | } else if (ttoken.startingData != null) { |
| 3905 | // The previous app was getting ready to show a |
| 3906 | // starting window, but hasn't yet done so. Steal it! |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3907 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3908 | "Moving pending starting from " + ttoken |
| 3909 | + " to " + wtoken); |
| 3910 | wtoken.startingData = ttoken.startingData; |
| 3911 | ttoken.startingData = null; |
| 3912 | ttoken.startingMoved = true; |
| 3913 | Message m = mH.obtainMessage(H.ADD_STARTING, wtoken); |
| 3914 | // Note: we really want to do sendMessageAtFrontOfQueue() because we |
| 3915 | // want to process the message ASAP, before any other queued |
| 3916 | // messages. |
| 3917 | mH.sendMessageAtFrontOfQueue(m); |
| 3918 | return; |
| 3919 | } |
| 3920 | } |
| 3921 | } |
| 3922 | |
| 3923 | // There is no existing starting window, and the caller doesn't |
| 3924 | // want us to create one, so that's it! |
| 3925 | if (!createIfNeeded) { |
| 3926 | return; |
| 3927 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3928 | |
| Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 3929 | // If this is a translucent or wallpaper window, then don't |
| 3930 | // show a starting window -- the current effect (a full-screen |
| 3931 | // opaque starting window that fades away to the real contents |
| 3932 | // when it is ready) does not work for this. |
| 3933 | if (theme != 0) { |
| 3934 | AttributeCache.Entry ent = AttributeCache.instance().get(pkg, theme, |
| 3935 | com.android.internal.R.styleable.Window); |
| 3936 | if (ent.array.getBoolean( |
| 3937 | com.android.internal.R.styleable.Window_windowIsTranslucent, false)) { |
| 3938 | return; |
| 3939 | } |
| 3940 | if (ent.array.getBoolean( |
| Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 3941 | com.android.internal.R.styleable.Window_windowIsFloating, false)) { |
| 3942 | return; |
| 3943 | } |
| 3944 | if (ent.array.getBoolean( |
| Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 3945 | com.android.internal.R.styleable.Window_windowShowWallpaper, false)) { |
| 3946 | return; |
| 3947 | } |
| 3948 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3949 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3950 | mStartingIconInTransition = true; |
| 3951 | wtoken.startingData = new StartingData( |
| 3952 | pkg, theme, nonLocalizedLabel, |
| Dianne Hackborn | 7eec10e | 2010-11-12 18:03:47 -0800 | [diff] [blame] | 3953 | labelRes, icon, windowFlags); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3954 | Message m = mH.obtainMessage(H.ADD_STARTING, wtoken); |
| 3955 | // Note: we really want to do sendMessageAtFrontOfQueue() because we |
| 3956 | // want to process the message ASAP, before any other queued |
| 3957 | // messages. |
| 3958 | mH.sendMessageAtFrontOfQueue(m); |
| 3959 | } |
| 3960 | } |
| 3961 | |
| 3962 | public void setAppWillBeHidden(IBinder token) { |
| 3963 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 3964 | "setAppWillBeHidden()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 3965 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3966 | } |
| 3967 | |
| 3968 | AppWindowToken wtoken; |
| 3969 | |
| 3970 | synchronized(mWindowMap) { |
| 3971 | wtoken = findAppWindowToken(token); |
| 3972 | if (wtoken == null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3973 | 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] | 3974 | return; |
| 3975 | } |
| 3976 | wtoken.willBeHidden = true; |
| 3977 | } |
| 3978 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3979 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3980 | boolean setTokenVisibilityLocked(AppWindowToken wtoken, WindowManager.LayoutParams lp, |
| 3981 | boolean visible, int transit, boolean performLayout) { |
| 3982 | boolean delayed = false; |
| 3983 | |
| 3984 | if (wtoken.clientHidden == visible) { |
| 3985 | wtoken.clientHidden = !visible; |
| 3986 | wtoken.sendAppVisibilityToClients(); |
| 3987 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3988 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3989 | wtoken.willBeHidden = false; |
| 3990 | if (wtoken.hidden == visible) { |
| 3991 | final int N = wtoken.allAppWindows.size(); |
| 3992 | boolean changed = false; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3993 | if (DEBUG_APP_TRANSITIONS) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3994 | TAG, "Changing app " + wtoken + " hidden=" + wtoken.hidden |
| 3995 | + " performLayout=" + performLayout); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3996 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3997 | boolean runningAppAnimation = false; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 3998 | |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 3999 | if (transit != WindowManagerPolicy.TRANSIT_UNSET) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4000 | if (wtoken.animation == sDummyAnimation) { |
| 4001 | wtoken.animation = null; |
| 4002 | } |
| 4003 | applyAnimationLocked(wtoken, lp, transit, visible); |
| 4004 | changed = true; |
| 4005 | if (wtoken.animation != null) { |
| 4006 | delayed = runningAppAnimation = true; |
| 4007 | } |
| 4008 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4009 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4010 | for (int i=0; i<N; i++) { |
| 4011 | WindowState win = wtoken.allAppWindows.get(i); |
| 4012 | if (win == wtoken.startingWindow) { |
| 4013 | continue; |
| 4014 | } |
| 4015 | |
| 4016 | if (win.isAnimating()) { |
| 4017 | delayed = true; |
| 4018 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4019 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4020 | //Slog.i(TAG, "Window " + win + ": vis=" + win.isVisible()); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4021 | //win.dump(" "); |
| 4022 | if (visible) { |
| 4023 | if (!win.isVisibleNow()) { |
| 4024 | if (!runningAppAnimation) { |
| 4025 | applyAnimationLocked(win, |
| 4026 | WindowManagerPolicy.TRANSIT_ENTER, true); |
| 4027 | } |
| 4028 | changed = true; |
| 4029 | } |
| 4030 | } else if (win.isVisibleNow()) { |
| 4031 | if (!runningAppAnimation) { |
| 4032 | applyAnimationLocked(win, |
| 4033 | WindowManagerPolicy.TRANSIT_EXIT, false); |
| 4034 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4035 | changed = true; |
| 4036 | } |
| 4037 | } |
| 4038 | |
| 4039 | wtoken.hidden = wtoken.hiddenRequested = !visible; |
| 4040 | if (!visible) { |
| 4041 | unsetAppFreezingScreenLocked(wtoken, true, true); |
| 4042 | } else { |
| 4043 | // If we are being set visible, and the starting window is |
| 4044 | // not yet displayed, then make sure it doesn't get displayed. |
| 4045 | WindowState swin = wtoken.startingWindow; |
| 4046 | if (swin != null && (swin.mDrawPending |
| 4047 | || swin.mCommitDrawPending)) { |
| 4048 | swin.mPolicyVisibility = false; |
| 4049 | swin.mPolicyVisibilityAfterAnim = false; |
| 4050 | } |
| 4051 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4052 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4053 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "setTokenVisibilityLocked: " + wtoken |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4054 | + ": hidden=" + wtoken.hidden + " hiddenRequested=" |
| 4055 | + wtoken.hiddenRequested); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4056 | |
| Dianne Hackborn | 9b52a21 | 2009-12-11 14:51:35 -0800 | [diff] [blame] | 4057 | if (changed) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4058 | mLayoutNeeded = true; |
| Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 4059 | mInputMonitor.setUpdateInputWindowsNeededLw(); |
| Dianne Hackborn | 9b52a21 | 2009-12-11 14:51:35 -0800 | [diff] [blame] | 4060 | if (performLayout) { |
| Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 4061 | updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES, |
| 4062 | false /*updateInputWindows*/); |
| Dianne Hackborn | 9b52a21 | 2009-12-11 14:51:35 -0800 | [diff] [blame] | 4063 | performLayoutAndPlaceSurfacesLocked(); |
| 4064 | } |
| Jeff Brown | 2e44b07 | 2011-01-24 15:21:56 -0800 | [diff] [blame] | 4065 | mInputMonitor.updateInputWindowsLw(false /*force*/); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4066 | } |
| 4067 | } |
| 4068 | |
| 4069 | if (wtoken.animation != null) { |
| 4070 | delayed = true; |
| 4071 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4072 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4073 | return delayed; |
| 4074 | } |
| 4075 | |
| 4076 | public void setAppVisibility(IBinder token, boolean visible) { |
| 4077 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 4078 | "setAppVisibility()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4079 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4080 | } |
| 4081 | |
| 4082 | AppWindowToken wtoken; |
| 4083 | |
| 4084 | synchronized(mWindowMap) { |
| 4085 | wtoken = findAppWindowToken(token); |
| 4086 | if (wtoken == null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4087 | 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] | 4088 | return; |
| 4089 | } |
| 4090 | |
| 4091 | if (DEBUG_APP_TRANSITIONS || DEBUG_ORIENTATION) { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 4092 | RuntimeException e = null; |
| 4093 | if (!HIDE_STACK_CRAWLS) { |
| 4094 | e = new RuntimeException(); |
| 4095 | e.fillInStackTrace(); |
| 4096 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4097 | Slog.v(TAG, "setAppVisibility(" + token + ", " + visible |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4098 | + "): mNextAppTransition=" + mNextAppTransition |
| 4099 | + " hidden=" + wtoken.hidden |
| 4100 | + " hiddenRequested=" + wtoken.hiddenRequested, e); |
| 4101 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4102 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4103 | // If we are preparing an app transition, then delay changing |
| 4104 | // the visibility of this token until we execute that transition. |
| Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 4105 | if (!mDisplayFrozen && mPolicy.isScreenOn() |
| 4106 | && mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4107 | // Already in requested state, don't do anything more. |
| 4108 | if (wtoken.hiddenRequested != visible) { |
| 4109 | return; |
| 4110 | } |
| 4111 | wtoken.hiddenRequested = !visible; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4112 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4113 | if (DEBUG_APP_TRANSITIONS) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4114 | TAG, "Setting dummy animation on: " + wtoken); |
| 4115 | wtoken.setDummyAnimation(); |
| 4116 | mOpeningApps.remove(wtoken); |
| 4117 | mClosingApps.remove(wtoken); |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4118 | wtoken.waitingToShow = wtoken.waitingToHide = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4119 | wtoken.inPendingTransaction = true; |
| 4120 | if (visible) { |
| 4121 | mOpeningApps.add(wtoken); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4122 | wtoken.startingDisplayed = false; |
| 4123 | wtoken.startingMoved = false; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 4124 | |
| Dianne Hackborn | 195f6a0 | 2009-11-24 11:26:00 -0800 | [diff] [blame] | 4125 | // If the token is currently hidden (should be the |
| 4126 | // common case), then we need to set up to wait for |
| 4127 | // its windows to be ready. |
| 4128 | if (wtoken.hidden) { |
| 4129 | wtoken.allDrawn = false; |
| 4130 | wtoken.waitingToShow = true; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 4131 | |
| Dianne Hackborn | 195f6a0 | 2009-11-24 11:26:00 -0800 | [diff] [blame] | 4132 | if (wtoken.clientHidden) { |
| 4133 | // In the case where we are making an app visible |
| 4134 | // but holding off for a transition, we still need |
| 4135 | // to tell the client to make its windows visible so |
| 4136 | // they get drawn. Otherwise, we will wait on |
| 4137 | // performing the transition until all windows have |
| 4138 | // been drawn, they never will be, and we are sad. |
| 4139 | wtoken.clientHidden = false; |
| 4140 | wtoken.sendAppVisibilityToClients(); |
| 4141 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4142 | } |
| 4143 | } else { |
| 4144 | mClosingApps.add(wtoken); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 4145 | |
| Dianne Hackborn | 195f6a0 | 2009-11-24 11:26:00 -0800 | [diff] [blame] | 4146 | // If the token is currently visible (should be the |
| 4147 | // common case), then set up to wait for it to be hidden. |
| 4148 | if (!wtoken.hidden) { |
| 4149 | wtoken.waitingToHide = true; |
| 4150 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4151 | } |
| 4152 | return; |
| 4153 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4154 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4155 | final long origId = Binder.clearCallingIdentity(); |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 4156 | setTokenVisibilityLocked(wtoken, null, visible, WindowManagerPolicy.TRANSIT_UNSET, true); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4157 | wtoken.updateReportedVisibilityLocked(); |
| 4158 | Binder.restoreCallingIdentity(origId); |
| 4159 | } |
| 4160 | } |
| 4161 | |
| 4162 | void unsetAppFreezingScreenLocked(AppWindowToken wtoken, |
| 4163 | boolean unfreezeSurfaceNow, boolean force) { |
| 4164 | if (wtoken.freezingScreen) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4165 | 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] | 4166 | + " force=" + force); |
| 4167 | final int N = wtoken.allAppWindows.size(); |
| 4168 | boolean unfrozeWindows = false; |
| 4169 | for (int i=0; i<N; i++) { |
| 4170 | WindowState w = wtoken.allAppWindows.get(i); |
| 4171 | if (w.mAppFreezing) { |
| 4172 | w.mAppFreezing = false; |
| 4173 | if (w.mSurface != null && !w.mOrientationChanging) { |
| 4174 | w.mOrientationChanging = true; |
| 4175 | } |
| 4176 | unfrozeWindows = true; |
| 4177 | } |
| 4178 | } |
| 4179 | if (force || unfrozeWindows) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4180 | 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] | 4181 | wtoken.freezingScreen = false; |
| 4182 | mAppsFreezingScreen--; |
| 4183 | } |
| 4184 | if (unfreezeSurfaceNow) { |
| 4185 | if (unfrozeWindows) { |
| 4186 | mLayoutNeeded = true; |
| 4187 | performLayoutAndPlaceSurfacesLocked(); |
| 4188 | } |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 4189 | stopFreezingDisplayLocked(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4190 | } |
| 4191 | } |
| 4192 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4193 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4194 | public void startAppFreezingScreenLocked(AppWindowToken wtoken, |
| 4195 | int configChanges) { |
| 4196 | if (DEBUG_ORIENTATION) { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 4197 | RuntimeException e = null; |
| 4198 | if (!HIDE_STACK_CRAWLS) { |
| 4199 | e = new RuntimeException(); |
| 4200 | e.fillInStackTrace(); |
| 4201 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4202 | Slog.i(TAG, "Set freezing of " + wtoken.appToken |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4203 | + ": hidden=" + wtoken.hidden + " freezing=" |
| 4204 | + wtoken.freezingScreen, e); |
| 4205 | } |
| 4206 | if (!wtoken.hiddenRequested) { |
| 4207 | if (!wtoken.freezingScreen) { |
| 4208 | wtoken.freezingScreen = true; |
| 4209 | mAppsFreezingScreen++; |
| 4210 | if (mAppsFreezingScreen == 1) { |
| Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 4211 | startFreezingDisplayLocked(false); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4212 | mH.removeMessages(H.APP_FREEZE_TIMEOUT); |
| 4213 | mH.sendMessageDelayed(mH.obtainMessage(H.APP_FREEZE_TIMEOUT), |
| 4214 | 5000); |
| 4215 | } |
| 4216 | } |
| 4217 | final int N = wtoken.allAppWindows.size(); |
| 4218 | for (int i=0; i<N; i++) { |
| 4219 | WindowState w = wtoken.allAppWindows.get(i); |
| 4220 | w.mAppFreezing = true; |
| 4221 | } |
| 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 startAppFreezingScreen(IBinder token, int configChanges) { |
| 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) { |
| Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 4232 | if (configChanges == 0 && !mDisplayFrozen && mPolicy.isScreenOn()) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4233 | 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] | 4234 | return; |
| 4235 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4236 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4237 | AppWindowToken wtoken = findAppWindowToken(token); |
| 4238 | if (wtoken == null || wtoken.appToken == null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4239 | 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] | 4240 | return; |
| 4241 | } |
| 4242 | final long origId = Binder.clearCallingIdentity(); |
| 4243 | startAppFreezingScreenLocked(wtoken, configChanges); |
| 4244 | Binder.restoreCallingIdentity(origId); |
| 4245 | } |
| 4246 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4247 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4248 | public void stopAppFreezingScreen(IBinder token, boolean force) { |
| 4249 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 4250 | "setAppFreezingScreen()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4251 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4252 | } |
| 4253 | |
| 4254 | synchronized(mWindowMap) { |
| 4255 | AppWindowToken wtoken = findAppWindowToken(token); |
| 4256 | if (wtoken == null || wtoken.appToken == null) { |
| 4257 | return; |
| 4258 | } |
| 4259 | final long origId = Binder.clearCallingIdentity(); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4260 | 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] | 4261 | + ": hidden=" + wtoken.hidden + " freezing=" + wtoken.freezingScreen); |
| 4262 | unsetAppFreezingScreenLocked(wtoken, true, force); |
| 4263 | Binder.restoreCallingIdentity(origId); |
| 4264 | } |
| 4265 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4266 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4267 | public void removeAppToken(IBinder token) { |
| 4268 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 4269 | "removeAppToken()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4270 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4271 | } |
| 4272 | |
| 4273 | AppWindowToken wtoken = null; |
| 4274 | AppWindowToken startingToken = null; |
| 4275 | boolean delayed = false; |
| 4276 | |
| 4277 | final long origId = Binder.clearCallingIdentity(); |
| 4278 | synchronized(mWindowMap) { |
| 4279 | WindowToken basewtoken = mTokenMap.remove(token); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4280 | if (basewtoken != null && (wtoken=basewtoken.appWindowToken) != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4281 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "Removing app token: " + wtoken); |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 4282 | delayed = setTokenVisibilityLocked(wtoken, null, false, WindowManagerPolicy.TRANSIT_UNSET, true); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4283 | wtoken.inPendingTransaction = false; |
| 4284 | mOpeningApps.remove(wtoken); |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4285 | wtoken.waitingToShow = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4286 | if (mClosingApps.contains(wtoken)) { |
| 4287 | delayed = true; |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 4288 | } else if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4289 | mClosingApps.add(wtoken); |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4290 | wtoken.waitingToHide = true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4291 | delayed = true; |
| 4292 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4293 | if (DEBUG_APP_TRANSITIONS) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4294 | TAG, "Removing app " + wtoken + " delayed=" + delayed |
| 4295 | + " animation=" + wtoken.animation |
| 4296 | + " animating=" + wtoken.animating); |
| 4297 | if (delayed) { |
| 4298 | // 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] | 4299 | if (DEBUG_ADD_REMOVE || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG, |
| 4300 | "removeAppToken make exiting: " + wtoken); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4301 | mExitingAppTokens.add(wtoken); |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 4302 | } else { |
| 4303 | // Make sure there is no animation running on this token, |
| 4304 | // so any windows associated with it will be removed as |
| 4305 | // soon as their animations are complete |
| 4306 | wtoken.animation = null; |
| 4307 | wtoken.animating = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4308 | } |
| Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 4309 | if (DEBUG_ADD_REMOVE || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG, |
| 4310 | "removeAppToken: " + wtoken); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4311 | mAppTokens.remove(wtoken); |
| 4312 | wtoken.removed = true; |
| 4313 | if (wtoken.startingData != null) { |
| 4314 | startingToken = wtoken; |
| 4315 | } |
| 4316 | unsetAppFreezingScreenLocked(wtoken, true, true); |
| 4317 | if (mFocusedApp == wtoken) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4318 | 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] | 4319 | mFocusedApp = null; |
| Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 4320 | updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL, true /*updateInputWindows*/); |
| Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 4321 | mInputMonitor.setFocusedAppLw(null); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4322 | } |
| 4323 | } else { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4324 | 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] | 4325 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4326 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4327 | if (!delayed && wtoken != null) { |
| 4328 | wtoken.updateReportedVisibilityLocked(); |
| 4329 | } |
| 4330 | } |
| 4331 | Binder.restoreCallingIdentity(origId); |
| 4332 | |
| 4333 | if (startingToken != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4334 | 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] | 4335 | + startingToken + ": app token removed"); |
| 4336 | Message m = mH.obtainMessage(H.REMOVE_STARTING, startingToken); |
| 4337 | mH.sendMessage(m); |
| 4338 | } |
| 4339 | } |
| 4340 | |
| 4341 | private boolean tmpRemoveAppWindowsLocked(WindowToken token) { |
| 4342 | final int NW = token.windows.size(); |
| 4343 | for (int i=0; i<NW; i++) { |
| 4344 | WindowState win = token.windows.get(i); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4345 | 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] | 4346 | mWindows.remove(win); |
| Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 4347 | mWindowsChanged = true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4348 | int j = win.mChildWindows.size(); |
| 4349 | while (j > 0) { |
| 4350 | j--; |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 4351 | WindowState cwin = win.mChildWindows.get(j); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4352 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, |
| Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 4353 | "Tmp removing child window " + cwin); |
| 4354 | mWindows.remove(cwin); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4355 | } |
| 4356 | } |
| 4357 | return NW > 0; |
| 4358 | } |
| 4359 | |
| 4360 | void dumpAppTokensLocked() { |
| 4361 | for (int i=mAppTokens.size()-1; i>=0; i--) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4362 | Slog.v(TAG, " #" + i + ": " + mAppTokens.get(i).token); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4363 | } |
| 4364 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4365 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4366 | void dumpWindowsLocked() { |
| 4367 | for (int i=mWindows.size()-1; i>=0; i--) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4368 | Slog.v(TAG, " #" + i + ": " + mWindows.get(i)); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4369 | } |
| 4370 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4371 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4372 | private int findWindowOffsetLocked(int tokenPos) { |
| 4373 | final int NW = mWindows.size(); |
| 4374 | |
| 4375 | if (tokenPos >= mAppTokens.size()) { |
| 4376 | int i = NW; |
| 4377 | while (i > 0) { |
| 4378 | i--; |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 4379 | WindowState win = mWindows.get(i); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4380 | if (win.getAppToken() != null) { |
| 4381 | return i+1; |
| 4382 | } |
| 4383 | } |
| 4384 | } |
| 4385 | |
| 4386 | while (tokenPos > 0) { |
| 4387 | // Find the first app token below the new position that has |
| 4388 | // a window displayed. |
| 4389 | final AppWindowToken wtoken = mAppTokens.get(tokenPos-1); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4390 | 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] | 4391 | + tokenPos + " -- " + wtoken.token); |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4392 | if (wtoken.sendingToBottom) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4393 | if (DEBUG_REORDER) Slog.v(TAG, |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4394 | "Skipping token -- currently sending to bottom"); |
| 4395 | tokenPos--; |
| 4396 | continue; |
| 4397 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4398 | int i = wtoken.windows.size(); |
| 4399 | while (i > 0) { |
| 4400 | i--; |
| 4401 | WindowState win = wtoken.windows.get(i); |
| 4402 | int j = win.mChildWindows.size(); |
| 4403 | while (j > 0) { |
| 4404 | j--; |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 4405 | WindowState cwin = win.mChildWindows.get(j); |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4406 | if (cwin.mSubLayer >= 0) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4407 | for (int pos=NW-1; pos>=0; pos--) { |
| 4408 | if (mWindows.get(pos) == cwin) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4409 | if (DEBUG_REORDER) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4410 | "Found child win @" + (pos+1)); |
| 4411 | return pos+1; |
| 4412 | } |
| 4413 | } |
| 4414 | } |
| 4415 | } |
| 4416 | for (int pos=NW-1; pos>=0; pos--) { |
| 4417 | if (mWindows.get(pos) == win) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4418 | 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] | 4419 | return pos+1; |
| 4420 | } |
| 4421 | } |
| 4422 | } |
| 4423 | tokenPos--; |
| 4424 | } |
| 4425 | |
| 4426 | return 0; |
| 4427 | } |
| 4428 | |
| 4429 | private final int reAddWindowLocked(int index, WindowState win) { |
| 4430 | final int NCW = win.mChildWindows.size(); |
| 4431 | boolean added = false; |
| 4432 | for (int j=0; j<NCW; j++) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 4433 | WindowState cwin = win.mChildWindows.get(j); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4434 | if (!added && cwin.mSubLayer >= 0) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4435 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding child window at " |
| Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 4436 | + index + ": " + cwin); |
| Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 4437 | win.mRebuilding = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4438 | mWindows.add(index, win); |
| 4439 | index++; |
| 4440 | added = true; |
| 4441 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4442 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding window at " |
| Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 4443 | + index + ": " + cwin); |
| Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 4444 | cwin.mRebuilding = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4445 | mWindows.add(index, cwin); |
| 4446 | index++; |
| 4447 | } |
| 4448 | if (!added) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4449 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding window at " |
| Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 4450 | + index + ": " + win); |
| Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 4451 | win.mRebuilding = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4452 | mWindows.add(index, win); |
| 4453 | index++; |
| 4454 | } |
| Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 4455 | mWindowsChanged = true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4456 | return index; |
| 4457 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4458 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4459 | private final int reAddAppWindowsLocked(int index, WindowToken token) { |
| 4460 | final int NW = token.windows.size(); |
| 4461 | for (int i=0; i<NW; i++) { |
| 4462 | index = reAddWindowLocked(index, token.windows.get(i)); |
| 4463 | } |
| 4464 | return index; |
| 4465 | } |
| 4466 | |
| 4467 | public void moveAppToken(int index, IBinder token) { |
| 4468 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 4469 | "moveAppToken()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4470 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4471 | } |
| 4472 | |
| 4473 | synchronized(mWindowMap) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4474 | if (DEBUG_REORDER) Slog.v(TAG, "Initial app tokens:"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4475 | if (DEBUG_REORDER) dumpAppTokensLocked(); |
| 4476 | final AppWindowToken wtoken = findAppWindowToken(token); |
| Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 4477 | if (DEBUG_TOKEN_MOVEMENT || DEBUG_REORDER) Slog.v(TAG, |
| 4478 | "Start moving token " + wtoken + " initially at " |
| 4479 | + mAppTokens.indexOf(wtoken)); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4480 | if (wtoken == null || !mAppTokens.remove(wtoken)) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4481 | 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] | 4482 | + token + " (" + wtoken + ")"); |
| 4483 | return; |
| 4484 | } |
| 4485 | mAppTokens.add(index, wtoken); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4486 | if (DEBUG_REORDER) Slog.v(TAG, "Moved " + token + " to " + index + ":"); |
| Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 4487 | 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] | 4488 | if (DEBUG_REORDER) dumpAppTokensLocked(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4489 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4490 | final long origId = Binder.clearCallingIdentity(); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4491 | 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] | 4492 | if (DEBUG_REORDER) dumpWindowsLocked(); |
| 4493 | if (tmpRemoveAppWindowsLocked(wtoken)) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4494 | 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] | 4495 | if (DEBUG_REORDER) dumpWindowsLocked(); |
| 4496 | reAddAppWindowsLocked(findWindowOffsetLocked(index), wtoken); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4497 | if (DEBUG_REORDER) Slog.v(TAG, "Final window list:"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4498 | if (DEBUG_REORDER) dumpWindowsLocked(); |
| Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 4499 | updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES, |
| 4500 | false /*updateInputWindows*/); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4501 | mLayoutNeeded = true; |
| Jeff Brown | 2e44b07 | 2011-01-24 15:21:56 -0800 | [diff] [blame] | 4502 | mInputMonitor.setUpdateInputWindowsNeededLw(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4503 | performLayoutAndPlaceSurfacesLocked(); |
| Jeff Brown | 2e44b07 | 2011-01-24 15:21:56 -0800 | [diff] [blame] | 4504 | mInputMonitor.updateInputWindowsLw(false /*force*/); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4505 | } |
| 4506 | Binder.restoreCallingIdentity(origId); |
| 4507 | } |
| 4508 | } |
| 4509 | |
| 4510 | private void removeAppTokensLocked(List<IBinder> tokens) { |
| 4511 | // XXX This should be done more efficiently! |
| 4512 | // (take advantage of the fact that both lists should be |
| 4513 | // ordered in the same way.) |
| 4514 | int N = tokens.size(); |
| 4515 | for (int i=0; i<N; i++) { |
| 4516 | IBinder token = tokens.get(i); |
| 4517 | final AppWindowToken wtoken = findAppWindowToken(token); |
| Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 4518 | if (DEBUG_REORDER || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG, |
| 4519 | "Temporarily removing " + wtoken + " from " + mAppTokens.indexOf(wtoken)); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4520 | if (!mAppTokens.remove(wtoken)) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4521 | 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] | 4522 | + token + " (" + wtoken + ")"); |
| 4523 | i--; |
| 4524 | N--; |
| 4525 | } |
| 4526 | } |
| 4527 | } |
| 4528 | |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4529 | private void moveAppWindowsLocked(AppWindowToken wtoken, int tokenPos, |
| 4530 | boolean updateFocusAndLayout) { |
| 4531 | // First remove all of the windows from the list. |
| 4532 | tmpRemoveAppWindowsLocked(wtoken); |
| 4533 | |
| 4534 | // Where to start adding? |
| 4535 | int pos = findWindowOffsetLocked(tokenPos); |
| 4536 | |
| 4537 | // And now add them back at the correct place. |
| 4538 | pos = reAddAppWindowsLocked(pos, wtoken); |
| 4539 | |
| 4540 | if (updateFocusAndLayout) { |
| Jeff Brown | 2e44b07 | 2011-01-24 15:21:56 -0800 | [diff] [blame] | 4541 | mInputMonitor.setUpdateInputWindowsNeededLw(); |
| Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 4542 | if (!updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES, |
| 4543 | false /*updateInputWindows*/)) { |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4544 | assignLayersLocked(); |
| 4545 | } |
| 4546 | mLayoutNeeded = true; |
| 4547 | performLayoutAndPlaceSurfacesLocked(); |
| Jeff Brown | 2e44b07 | 2011-01-24 15:21:56 -0800 | [diff] [blame] | 4548 | mInputMonitor.updateInputWindowsLw(false /*force*/); |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4549 | } |
| 4550 | } |
| 4551 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4552 | private void moveAppWindowsLocked(List<IBinder> tokens, int tokenPos) { |
| 4553 | // First remove all of the windows from the list. |
| 4554 | final int N = tokens.size(); |
| 4555 | int i; |
| 4556 | for (i=0; i<N; i++) { |
| 4557 | WindowToken token = mTokenMap.get(tokens.get(i)); |
| 4558 | if (token != null) { |
| 4559 | tmpRemoveAppWindowsLocked(token); |
| 4560 | } |
| 4561 | } |
| 4562 | |
| 4563 | // Where to start adding? |
| 4564 | int pos = findWindowOffsetLocked(tokenPos); |
| 4565 | |
| 4566 | // And now add them back at the correct place. |
| 4567 | for (i=0; i<N; i++) { |
| 4568 | WindowToken token = mTokenMap.get(tokens.get(i)); |
| 4569 | if (token != null) { |
| 4570 | pos = reAddAppWindowsLocked(pos, token); |
| 4571 | } |
| 4572 | } |
| 4573 | |
| Jeff Brown | 2e44b07 | 2011-01-24 15:21:56 -0800 | [diff] [blame] | 4574 | mInputMonitor.setUpdateInputWindowsNeededLw(); |
| Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 4575 | if (!updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES, |
| 4576 | false /*updateInputWindows*/)) { |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4577 | assignLayersLocked(); |
| 4578 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4579 | mLayoutNeeded = true; |
| 4580 | performLayoutAndPlaceSurfacesLocked(); |
| Jeff Brown | 2e44b07 | 2011-01-24 15:21:56 -0800 | [diff] [blame] | 4581 | mInputMonitor.updateInputWindowsLw(false /*force*/); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4582 | |
| 4583 | //dump(); |
| 4584 | } |
| 4585 | |
| 4586 | public void moveAppTokensToTop(List<IBinder> tokens) { |
| 4587 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 4588 | "moveAppTokensToTop()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4589 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4590 | } |
| 4591 | |
| 4592 | final long origId = Binder.clearCallingIdentity(); |
| 4593 | synchronized(mWindowMap) { |
| 4594 | removeAppTokensLocked(tokens); |
| 4595 | final int N = tokens.size(); |
| 4596 | for (int i=0; i<N; i++) { |
| 4597 | AppWindowToken wt = findAppWindowToken(tokens.get(i)); |
| 4598 | if (wt != null) { |
| Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 4599 | if (DEBUG_TOKEN_MOVEMENT || DEBUG_REORDER) Slog.v(TAG, |
| 4600 | "Adding next to top: " + wt); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4601 | mAppTokens.add(wt); |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 4602 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4603 | mToTopApps.remove(wt); |
| 4604 | mToBottomApps.remove(wt); |
| 4605 | mToTopApps.add(wt); |
| 4606 | wt.sendingToBottom = false; |
| 4607 | wt.sendingToTop = true; |
| 4608 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4609 | } |
| 4610 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 4611 | |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 4612 | if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET) { |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4613 | moveAppWindowsLocked(tokens, mAppTokens.size()); |
| 4614 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4615 | } |
| 4616 | Binder.restoreCallingIdentity(origId); |
| 4617 | } |
| 4618 | |
| 4619 | public void moveAppTokensToBottom(List<IBinder> tokens) { |
| 4620 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 4621 | "moveAppTokensToBottom()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4622 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4623 | } |
| 4624 | |
| 4625 | final long origId = Binder.clearCallingIdentity(); |
| 4626 | synchronized(mWindowMap) { |
| 4627 | removeAppTokensLocked(tokens); |
| 4628 | final int N = tokens.size(); |
| 4629 | int pos = 0; |
| 4630 | for (int i=0; i<N; i++) { |
| 4631 | AppWindowToken wt = findAppWindowToken(tokens.get(i)); |
| 4632 | if (wt != null) { |
| Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 4633 | if (DEBUG_TOKEN_MOVEMENT) Slog.v(TAG, |
| 4634 | "Adding next to bottom: " + wt + " at " + pos); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4635 | mAppTokens.add(pos, wt); |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 4636 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4637 | mToTopApps.remove(wt); |
| 4638 | mToBottomApps.remove(wt); |
| 4639 | mToBottomApps.add(i, wt); |
| 4640 | wt.sendingToTop = false; |
| 4641 | wt.sendingToBottom = true; |
| 4642 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4643 | pos++; |
| 4644 | } |
| 4645 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 4646 | |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 4647 | if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET) { |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 4648 | moveAppWindowsLocked(tokens, 0); |
| 4649 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4650 | } |
| 4651 | Binder.restoreCallingIdentity(origId); |
| 4652 | } |
| 4653 | |
| 4654 | // ------------------------------------------------------------- |
| 4655 | // Misc IWindowSession methods |
| 4656 | // ------------------------------------------------------------- |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4657 | |
| Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 4658 | private boolean shouldAllowDisableKeyguard() |
| Jim Miller | d6b5705 | 2010-06-07 17:52:42 -0700 | [diff] [blame] | 4659 | { |
| Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 4660 | // We fail safe and prevent disabling keyguard in the unlikely event this gets |
| 4661 | // called before DevicePolicyManagerService has started. |
| 4662 | if (mAllowDisableKeyguard == ALLOW_DISABLE_UNKNOWN) { |
| 4663 | DevicePolicyManager dpm = (DevicePolicyManager) mContext.getSystemService( |
| 4664 | Context.DEVICE_POLICY_SERVICE); |
| 4665 | if (dpm != null) { |
| 4666 | mAllowDisableKeyguard = dpm.getPasswordQuality(null) |
| 4667 | == DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED ? |
| 4668 | ALLOW_DISABLE_YES : ALLOW_DISABLE_NO; |
| 4669 | } |
| 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 | return mAllowDisableKeyguard == ALLOW_DISABLE_YES; |
| Jim Miller | d6b5705 | 2010-06-07 17:52:42 -0700 | [diff] [blame] | 4672 | } |
| 4673 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4674 | public void disableKeyguard(IBinder token, String tag) { |
| Mike Lockwood | 733fdf3 | 2009-09-28 19:08:53 -0400 | [diff] [blame] | 4675 | if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD) |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4676 | != PackageManager.PERMISSION_GRANTED) { |
| 4677 | throw new SecurityException("Requires DISABLE_KEYGUARD permission"); |
| 4678 | } |
| Jim Miller | d6b5705 | 2010-06-07 17:52:42 -0700 | [diff] [blame] | 4679 | |
| Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 4680 | synchronized (mKeyguardTokenWatcher) { |
| 4681 | mKeyguardTokenWatcher.acquire(token, tag); |
| Mike Lockwood | dd88468 | 2009-10-11 16:57:08 -0400 | [diff] [blame] | 4682 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4683 | } |
| 4684 | |
| 4685 | public void reenableKeyguard(IBinder token) { |
| Mike Lockwood | 733fdf3 | 2009-09-28 19:08:53 -0400 | [diff] [blame] | 4686 | if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD) |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4687 | != PackageManager.PERMISSION_GRANTED) { |
| 4688 | throw new SecurityException("Requires DISABLE_KEYGUARD permission"); |
| 4689 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4690 | |
| Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 4691 | synchronized (mKeyguardTokenWatcher) { |
| 4692 | mKeyguardTokenWatcher.release(token); |
| Jim Miller | d6b5705 | 2010-06-07 17:52:42 -0700 | [diff] [blame] | 4693 | |
| Jim Miller | 284b62e | 2010-06-08 14:27:42 -0700 | [diff] [blame] | 4694 | if (!mKeyguardTokenWatcher.isAcquired()) { |
| 4695 | // If we are the last one to reenable the keyguard wait until |
| 4696 | // we have actually finished reenabling until returning. |
| 4697 | // It is possible that reenableKeyguard() can be called before |
| 4698 | // the previous disableKeyguard() is handled, in which case |
| 4699 | // neither mKeyguardTokenWatcher.acquired() or released() would |
| 4700 | // be called. In that case mKeyguardDisabled will be false here |
| 4701 | // and we have nothing to wait for. |
| 4702 | while (mKeyguardDisabled) { |
| 4703 | try { |
| 4704 | mKeyguardTokenWatcher.wait(); |
| 4705 | } catch (InterruptedException e) { |
| 4706 | Thread.currentThread().interrupt(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4707 | } |
| 4708 | } |
| 4709 | } |
| 4710 | } |
| 4711 | } |
| 4712 | |
| 4713 | /** |
| 4714 | * @see android.app.KeyguardManager#exitKeyguardSecurely |
| 4715 | */ |
| 4716 | public void exitKeyguardSecurely(final IOnKeyguardExitResult callback) { |
| Mike Lockwood | 733fdf3 | 2009-09-28 19:08:53 -0400 | [diff] [blame] | 4717 | if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD) |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4718 | != PackageManager.PERMISSION_GRANTED) { |
| 4719 | throw new SecurityException("Requires DISABLE_KEYGUARD permission"); |
| 4720 | } |
| 4721 | mPolicy.exitKeyguardSecurely(new WindowManagerPolicy.OnKeyguardExitResult() { |
| 4722 | public void onKeyguardExitResult(boolean success) { |
| 4723 | try { |
| 4724 | callback.onKeyguardExitResult(success); |
| 4725 | } catch (RemoteException e) { |
| 4726 | // Client has died, we don't care. |
| 4727 | } |
| 4728 | } |
| 4729 | }); |
| 4730 | } |
| 4731 | |
| 4732 | public boolean inKeyguardRestrictedInputMode() { |
| 4733 | return mPolicy.inKeyguardRestrictedKeyInputMode(); |
| 4734 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4735 | |
| Dianne Hackborn | ffa4248 | 2009-09-23 22:20:11 -0700 | [diff] [blame] | 4736 | public void closeSystemDialogs(String reason) { |
| 4737 | synchronized(mWindowMap) { |
| 4738 | for (int i=mWindows.size()-1; i>=0; i--) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 4739 | WindowState w = mWindows.get(i); |
| Dianne Hackborn | ffa4248 | 2009-09-23 22:20:11 -0700 | [diff] [blame] | 4740 | if (w.mSurface != null) { |
| 4741 | try { |
| 4742 | w.mClient.closeSystemDialogs(reason); |
| 4743 | } catch (RemoteException e) { |
| 4744 | } |
| 4745 | } |
| 4746 | } |
| 4747 | } |
| 4748 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 4749 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4750 | static float fixScale(float scale) { |
| 4751 | if (scale < 0) scale = 0; |
| 4752 | else if (scale > 20) scale = 20; |
| 4753 | return Math.abs(scale); |
| 4754 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4755 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4756 | public void setAnimationScale(int which, float scale) { |
| 4757 | if (!checkCallingPermission(android.Manifest.permission.SET_ANIMATION_SCALE, |
| 4758 | "setAnimationScale()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4759 | throw new SecurityException("Requires SET_ANIMATION_SCALE permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4760 | } |
| 4761 | |
| 4762 | if (scale < 0) scale = 0; |
| 4763 | else if (scale > 20) scale = 20; |
| 4764 | scale = Math.abs(scale); |
| 4765 | switch (which) { |
| 4766 | case 0: mWindowAnimationScale = fixScale(scale); break; |
| 4767 | case 1: mTransitionAnimationScale = fixScale(scale); break; |
| 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 | // Persist setting |
| 4771 | mH.obtainMessage(H.PERSIST_ANIMATION_SCALE).sendToTarget(); |
| 4772 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4773 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4774 | public void setAnimationScales(float[] scales) { |
| 4775 | if (!checkCallingPermission(android.Manifest.permission.SET_ANIMATION_SCALE, |
| 4776 | "setAnimationScale()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4777 | throw new SecurityException("Requires SET_ANIMATION_SCALE permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4778 | } |
| 4779 | |
| 4780 | if (scales != null) { |
| 4781 | if (scales.length >= 1) { |
| 4782 | mWindowAnimationScale = fixScale(scales[0]); |
| 4783 | } |
| 4784 | if (scales.length >= 2) { |
| 4785 | mTransitionAnimationScale = fixScale(scales[1]); |
| 4786 | } |
| 4787 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4788 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4789 | // Persist setting |
| 4790 | mH.obtainMessage(H.PERSIST_ANIMATION_SCALE).sendToTarget(); |
| 4791 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4792 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4793 | public float getAnimationScale(int which) { |
| 4794 | switch (which) { |
| 4795 | case 0: return mWindowAnimationScale; |
| 4796 | case 1: return mTransitionAnimationScale; |
| 4797 | } |
| 4798 | return 0; |
| 4799 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4800 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4801 | public float[] getAnimationScales() { |
| 4802 | return new float[] { mWindowAnimationScale, mTransitionAnimationScale }; |
| 4803 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4804 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4805 | public int getSwitchState(int sw) { |
| 4806 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4807 | "getSwitchState()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4808 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4809 | } |
| Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 4810 | return mInputManager.getSwitchState(-1, InputDevice.SOURCE_ANY, sw); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4811 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4812 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4813 | public int getSwitchStateForDevice(int devid, int sw) { |
| 4814 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4815 | "getSwitchStateForDevice()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4816 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4817 | } |
| Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 4818 | return mInputManager.getSwitchState(devid, InputDevice.SOURCE_ANY, sw); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4819 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4820 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4821 | public int getScancodeState(int sw) { |
| 4822 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4823 | "getScancodeState()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4824 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4825 | } |
| Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 4826 | return mInputManager.getScanCodeState(-1, InputDevice.SOURCE_ANY, sw); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4827 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4828 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4829 | public int getScancodeStateForDevice(int devid, int sw) { |
| 4830 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4831 | "getScancodeStateForDevice()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4832 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4833 | } |
| Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 4834 | return mInputManager.getScanCodeState(devid, InputDevice.SOURCE_ANY, sw); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4835 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4836 | |
| Dianne Hackborn | 1d62ea9 | 2009-11-17 12:49:50 -0800 | [diff] [blame] | 4837 | public int getTrackballScancodeState(int sw) { |
| 4838 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4839 | "getTrackballScancodeState()")) { |
| 4840 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
| 4841 | } |
| Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 4842 | return mInputManager.getScanCodeState(-1, InputDevice.SOURCE_TRACKBALL, sw); |
| Dianne Hackborn | 1d62ea9 | 2009-11-17 12:49:50 -0800 | [diff] [blame] | 4843 | } |
| 4844 | |
| 4845 | public int getDPadScancodeState(int sw) { |
| 4846 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4847 | "getDPadScancodeState()")) { |
| 4848 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
| 4849 | } |
| Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 4850 | return mInputManager.getScanCodeState(-1, InputDevice.SOURCE_DPAD, sw); |
| Dianne Hackborn | 1d62ea9 | 2009-11-17 12:49:50 -0800 | [diff] [blame] | 4851 | } |
| 4852 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4853 | public int getKeycodeState(int sw) { |
| 4854 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4855 | "getKeycodeState()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4856 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4857 | } |
| Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 4858 | return mInputManager.getKeyCodeState(-1, InputDevice.SOURCE_ANY, sw); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4859 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4860 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4861 | public int getKeycodeStateForDevice(int devid, int sw) { |
| 4862 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4863 | "getKeycodeStateForDevice()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 4864 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4865 | } |
| Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 4866 | return mInputManager.getKeyCodeState(devid, InputDevice.SOURCE_ANY, sw); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4867 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4868 | |
| Dianne Hackborn | 1d62ea9 | 2009-11-17 12:49:50 -0800 | [diff] [blame] | 4869 | public int getTrackballKeycodeState(int sw) { |
| 4870 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4871 | "getTrackballKeycodeState()")) { |
| 4872 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
| 4873 | } |
| Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 4874 | return mInputManager.getKeyCodeState(-1, InputDevice.SOURCE_TRACKBALL, sw); |
| Dianne Hackborn | 1d62ea9 | 2009-11-17 12:49:50 -0800 | [diff] [blame] | 4875 | } |
| 4876 | |
| 4877 | public int getDPadKeycodeState(int sw) { |
| 4878 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4879 | "getDPadKeycodeState()")) { |
| 4880 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
| 4881 | } |
| Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 4882 | return mInputManager.getKeyCodeState(-1, InputDevice.SOURCE_DPAD, sw); |
| Dianne Hackborn | 1d62ea9 | 2009-11-17 12:49:50 -0800 | [diff] [blame] | 4883 | } |
| Jeff Brown | a41ca77 | 2010-08-11 14:46:32 -0700 | [diff] [blame] | 4884 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4885 | public boolean hasKeys(int[] keycodes, boolean[] keyExists) { |
| Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 4886 | return mInputManager.hasKeys(-1, InputDevice.SOURCE_ANY, keycodes, keyExists); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4887 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4888 | |
| Jeff Brown | a41ca77 | 2010-08-11 14:46:32 -0700 | [diff] [blame] | 4889 | public InputChannel monitorInput(String inputChannelName) { |
| 4890 | if (!checkCallingPermission(android.Manifest.permission.READ_INPUT_STATE, |
| 4891 | "monitorInput()")) { |
| 4892 | throw new SecurityException("Requires READ_INPUT_STATE permission"); |
| 4893 | } |
| 4894 | return mInputManager.monitorInput(inputChannelName); |
| 4895 | } |
| 4896 | |
| Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 4897 | public InputDevice getInputDevice(int deviceId) { |
| 4898 | return mInputManager.getInputDevice(deviceId); |
| 4899 | } |
| 4900 | |
| 4901 | public int[] getInputDeviceIds() { |
| 4902 | return mInputManager.getInputDeviceIds(); |
| 4903 | } |
| 4904 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4905 | public void enableScreenAfterBoot() { |
| 4906 | synchronized(mWindowMap) { |
| 4907 | if (mSystemBooted) { |
| 4908 | return; |
| 4909 | } |
| 4910 | mSystemBooted = true; |
| 4911 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4912 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4913 | performEnableScreen(); |
| 4914 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4915 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4916 | public void enableScreenIfNeededLocked() { |
| 4917 | if (mDisplayEnabled) { |
| 4918 | return; |
| 4919 | } |
| 4920 | if (!mSystemBooted) { |
| 4921 | return; |
| 4922 | } |
| 4923 | mH.sendMessage(mH.obtainMessage(H.ENABLE_SCREEN)); |
| 4924 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4925 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4926 | public void performEnableScreen() { |
| 4927 | synchronized(mWindowMap) { |
| 4928 | if (mDisplayEnabled) { |
| 4929 | return; |
| 4930 | } |
| 4931 | if (!mSystemBooted) { |
| 4932 | return; |
| 4933 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4934 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4935 | // Don't enable the screen until all existing windows |
| 4936 | // have been drawn. |
| 4937 | final int N = mWindows.size(); |
| 4938 | for (int i=0; i<N; i++) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 4939 | WindowState w = mWindows.get(i); |
| Dianne Hackborn | f3bea9c | 2009-12-09 18:26:21 -0800 | [diff] [blame] | 4940 | if (w.isVisibleLw() && !w.mObscured && !w.isDrawnLw()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4941 | return; |
| 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 | mDisplayEnabled = true; |
| 4946 | if (false) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4947 | Slog.i(TAG, "ENABLING SCREEN!"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4948 | StringWriter sw = new StringWriter(); |
| 4949 | PrintWriter pw = new PrintWriter(sw); |
| 4950 | this.dump(null, pw, null); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4951 | Slog.i(TAG, sw.toString()); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4952 | } |
| 4953 | try { |
| 4954 | IBinder surfaceFlinger = ServiceManager.getService("SurfaceFlinger"); |
| 4955 | if (surfaceFlinger != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4956 | //Slog.i(TAG, "******* TELLING SURFACE FLINGER WE ARE BOOTED!"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4957 | Parcel data = Parcel.obtain(); |
| 4958 | data.writeInterfaceToken("android.ui.ISurfaceComposer"); |
| 4959 | surfaceFlinger.transact(IBinder.FIRST_CALL_TRANSACTION, |
| 4960 | data, null, 0); |
| 4961 | data.recycle(); |
| 4962 | } |
| 4963 | } catch (RemoteException ex) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4964 | Slog.e(TAG, "Boot completed: SurfaceFlinger is dead!"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4965 | } |
| 4966 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4967 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4968 | mPolicy.enableScreenAfterBoot(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4969 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4970 | // Make sure the last requested orientation has been applied. |
| Dianne Hackborn | 321ae68 | 2009-03-27 16:16:03 -0700 | [diff] [blame] | 4971 | setRotationUnchecked(WindowManagerPolicy.USE_LAST_ROTATION, false, |
| 4972 | mLastRotationFlags | Surface.FLAGS_ORIENTATION_ANIMATION_DISABLE); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4973 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 4974 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4975 | public void setInTouchMode(boolean mode) { |
| 4976 | synchronized(mWindowMap) { |
| 4977 | mInTouchMode = mode; |
| 4978 | } |
| 4979 | } |
| 4980 | |
| Brad Fitzpatrick | 6804433 | 2010-11-22 18:19:48 -0800 | [diff] [blame] | 4981 | // TODO: more accounting of which pid(s) turned it on, keep count, |
| 4982 | // only allow disables from pids which have count on, etc. |
| 4983 | public void showStrictModeViolation(boolean on) { |
| 4984 | int pid = Binder.getCallingPid(); |
| 4985 | synchronized(mWindowMap) { |
| 4986 | // Ignoring requests to enable the red border from clients |
| 4987 | // which aren't on screen. (e.g. Broadcast Receivers in |
| 4988 | // the background..) |
| 4989 | if (on) { |
| 4990 | boolean isVisible = false; |
| 4991 | for (WindowState ws : mWindows) { |
| 4992 | if (ws.mSession.mPid == pid && ws.isVisibleLw()) { |
| 4993 | isVisible = true; |
| 4994 | break; |
| 4995 | } |
| 4996 | } |
| 4997 | if (!isVisible) { |
| 4998 | return; |
| 4999 | } |
| 5000 | } |
| 5001 | |
| Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 5002 | if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION showStrictModeViolation"); |
| Brad Fitzpatrick | 6804433 | 2010-11-22 18:19:48 -0800 | [diff] [blame] | 5003 | Surface.openTransaction(); |
| Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 5004 | try { |
| 5005 | if (mStrictModeFlash == null) { |
| 5006 | mStrictModeFlash = new StrictModeFlash(mDisplay, mFxSession); |
| 5007 | } |
| 5008 | mStrictModeFlash.setVisibility(on); |
| 5009 | } finally { |
| 5010 | Surface.closeTransaction(); |
| 5011 | if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION showStrictModeViolation"); |
| Brad Fitzpatrick | 6804433 | 2010-11-22 18:19:48 -0800 | [diff] [blame] | 5012 | } |
| Brad Fitzpatrick | 6804433 | 2010-11-22 18:19:48 -0800 | [diff] [blame] | 5013 | } |
| 5014 | } |
| 5015 | |
| Brad Fitzpatrick | c1a968a | 2010-11-24 08:56:40 -0800 | [diff] [blame] | 5016 | public void setStrictModeVisualIndicatorPreference(String value) { |
| 5017 | SystemProperties.set(StrictMode.VISUAL_PROPERTY, value); |
| 5018 | } |
| 5019 | |
| Dianne Hackborn | d283593 | 2010-12-13 16:28:46 -0800 | [diff] [blame] | 5020 | public Bitmap screenshotApplications(IBinder appToken, int maxWidth, int maxHeight) { |
| Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 5021 | if (!checkCallingPermission(android.Manifest.permission.READ_FRAME_BUFFER, |
| 5022 | "screenshotApplications()")) { |
| 5023 | throw new SecurityException("Requires READ_FRAME_BUFFER permission"); |
| 5024 | } |
| 5025 | |
| 5026 | Bitmap rawss; |
| 5027 | |
| Dianne Hackborn | d283593 | 2010-12-13 16:28:46 -0800 | [diff] [blame] | 5028 | int maxLayer = 0; |
| Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 5029 | final Rect frame = new Rect(); |
| 5030 | |
| 5031 | float scale; |
| 5032 | int sw, sh, dw, dh; |
| 5033 | int rot; |
| 5034 | |
| 5035 | synchronized(mWindowMap) { |
| 5036 | long ident = Binder.clearCallingIdentity(); |
| 5037 | |
| Dianne Hackborn | 428ecb6 | 2011-01-26 14:53:23 -0800 | [diff] [blame] | 5038 | dw = mDisplay.getWidth(); |
| 5039 | dh = mDisplay.getHeight(); |
| 5040 | |
| Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 5041 | int aboveAppLayer = mPolicy.windowTypeToLayerLw( |
| 5042 | WindowManager.LayoutParams.TYPE_APPLICATION) * TYPE_LAYER_MULTIPLIER |
| 5043 | + TYPE_LAYER_OFFSET; |
| 5044 | aboveAppLayer += TYPE_LAYER_MULTIPLIER; |
| 5045 | |
| Dianne Hackborn | 428ecb6 | 2011-01-26 14:53:23 -0800 | [diff] [blame] | 5046 | boolean isImeTarget = mInputMethodTarget != null |
| 5047 | && mInputMethodTarget.mAppToken != null |
| 5048 | && mInputMethodTarget.mAppToken.appToken != null |
| 5049 | && mInputMethodTarget.mAppToken.appToken.asBinder() == appToken; |
| 5050 | |
| Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 5051 | // Figure out the part of the screen that is actually the app. |
| Dianne Hackborn | 428ecb6 | 2011-01-26 14:53:23 -0800 | [diff] [blame] | 5052 | boolean including = false; |
| 5053 | for (int i=mWindows.size()-1; i>=0; i--) { |
| Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 5054 | WindowState ws = mWindows.get(i); |
| 5055 | if (ws.mSurface == null) { |
| 5056 | continue; |
| 5057 | } |
| 5058 | if (ws.mLayer >= aboveAppLayer) { |
| Dianne Hackborn | d283593 | 2010-12-13 16:28:46 -0800 | [diff] [blame] | 5059 | continue; |
| 5060 | } |
| Dianne Hackborn | 428ecb6 | 2011-01-26 14:53:23 -0800 | [diff] [blame] | 5061 | // When we will skip windows: when we are not including |
| 5062 | // ones behind a window we didn't skip, and we are actually |
| 5063 | // taking a screenshot of a specific app. |
| 5064 | if (!including && appToken != null) { |
| 5065 | // Also, we can possibly skip this window if it is not |
| 5066 | // an IME target or the application for the screenshot |
| 5067 | // is not the current IME target. |
| 5068 | if (!ws.mIsImWindow || !isImeTarget) { |
| 5069 | // And finally, this window is of no interest if it |
| 5070 | // is not associated with the screenshot app. |
| 5071 | if (ws.mAppToken == null || ws.mAppToken.token != appToken) { |
| 5072 | continue; |
| 5073 | } |
| 5074 | } |
| 5075 | } |
| 5076 | |
| 5077 | // We keep on including windows until we go past a full-screen |
| 5078 | // window. |
| 5079 | including = !ws.mIsImWindow && !ws.isFullscreen(dw, dh); |
| 5080 | |
| Dianne Hackborn | d283593 | 2010-12-13 16:28:46 -0800 | [diff] [blame] | 5081 | if (maxLayer < ws.mAnimLayer) { |
| 5082 | maxLayer = ws.mAnimLayer; |
| 5083 | } |
| Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 5084 | final Rect wf = ws.mFrame; |
| 5085 | final Rect cr = ws.mContentInsets; |
| 5086 | int left = wf.left + cr.left; |
| 5087 | int top = wf.top + cr.top; |
| 5088 | int right = wf.right - cr.right; |
| 5089 | int bottom = wf.bottom - cr.bottom; |
| 5090 | frame.union(left, top, right, bottom); |
| 5091 | } |
| 5092 | Binder.restoreCallingIdentity(ident); |
| 5093 | |
| Dianne Hackborn | cb8f0e0 | 2010-12-16 11:15:18 -0800 | [diff] [blame] | 5094 | if (frame.isEmpty() || maxLayer == 0) { |
| Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 5095 | return null; |
| 5096 | } |
| 5097 | |
| 5098 | // The screenshot API does not apply the current screen rotation. |
| 5099 | rot = mDisplay.getRotation(); |
| 5100 | int fw = frame.width(); |
| 5101 | int fh = frame.height(); |
| 5102 | |
| 5103 | // First try reducing to fit in x dimension. |
| 5104 | scale = maxWidth/(float)fw; |
| 5105 | sw = maxWidth; |
| 5106 | sh = (int)(fh*scale); |
| 5107 | if (sh > maxHeight) { |
| 5108 | // y dimension became too long; constrain by that. |
| 5109 | scale = maxHeight/(float)fh; |
| 5110 | sw = (int)(fw*scale); |
| 5111 | sh = maxHeight; |
| 5112 | } |
| 5113 | |
| 5114 | // The screen shot will contain the entire screen. |
| Dianne Hackborn | 428ecb6 | 2011-01-26 14:53:23 -0800 | [diff] [blame] | 5115 | dw = (int)(dw*scale); |
| 5116 | dh = (int)(dh*scale); |
| Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 5117 | if (rot == Surface.ROTATION_90 || rot == Surface.ROTATION_270) { |
| 5118 | int tmp = dw; |
| 5119 | dw = dh; |
| 5120 | dh = tmp; |
| 5121 | rot = (rot == Surface.ROTATION_90) ? Surface.ROTATION_270 : Surface.ROTATION_90; |
| 5122 | } |
| Dianne Hackborn | d283593 | 2010-12-13 16:28:46 -0800 | [diff] [blame] | 5123 | rawss = Surface.screenshot(dw, dh, 0, maxLayer); |
| Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 5124 | } |
| 5125 | |
| Dianne Hackborn | cb8f0e0 | 2010-12-16 11:15:18 -0800 | [diff] [blame] | 5126 | if (rawss == null) { |
| Dianne Hackborn | 88b03bd | 2010-12-16 11:15:18 -0800 | [diff] [blame] | 5127 | Log.w(TAG, "Failure taking screenshot for (" + dw + "x" + dh |
| 5128 | + ") to layer " + maxLayer); |
| Dianne Hackborn | cb8f0e0 | 2010-12-16 11:15:18 -0800 | [diff] [blame] | 5129 | return null; |
| 5130 | } |
| 5131 | |
| Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 5132 | Bitmap bm = Bitmap.createBitmap(sw, sh, rawss.getConfig()); |
| 5133 | Matrix matrix = new Matrix(); |
| 5134 | ScreenRotationAnimation.createRotationMatrix(rot, dw, dh, matrix); |
| 5135 | matrix.postTranslate(-(int)(frame.left*scale), -(int)(frame.top*scale)); |
| 5136 | Canvas canvas = new Canvas(bm); |
| 5137 | canvas.drawBitmap(rawss, matrix, null); |
| 5138 | |
| 5139 | rawss.recycle(); |
| 5140 | return bm; |
| 5141 | } |
| 5142 | |
| Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 5143 | public void freezeRotation() { |
| 5144 | if (!checkCallingPermission(android.Manifest.permission.SET_ORIENTATION, |
| 5145 | "setRotation()")) { |
| 5146 | throw new SecurityException("Requires SET_ORIENTATION permission"); |
| 5147 | } |
| 5148 | |
| 5149 | mPolicy.setUserRotationMode(WindowManagerPolicy.USER_ROTATION_LOCKED, mRotation); |
| 5150 | setRotationUnchecked(WindowManagerPolicy.USE_LAST_ROTATION, false, 0); |
| 5151 | } |
| 5152 | |
| 5153 | public void thawRotation() { |
| 5154 | if (!checkCallingPermission(android.Manifest.permission.SET_ORIENTATION, |
| 5155 | "setRotation()")) { |
| 5156 | throw new SecurityException("Requires SET_ORIENTATION permission"); |
| 5157 | } |
| 5158 | |
| 5159 | mPolicy.setUserRotationMode(WindowManagerPolicy.USER_ROTATION_FREE, 0); |
| 5160 | setRotationUnchecked(WindowManagerPolicy.USE_LAST_ROTATION, false, 0); |
| 5161 | } |
| 5162 | |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5163 | public void setRotation(int rotation, |
| Dianne Hackborn | 1e880db | 2009-03-27 16:04:08 -0700 | [diff] [blame] | 5164 | boolean alwaysSendConfiguration, int animFlags) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5165 | if (!checkCallingPermission(android.Manifest.permission.SET_ORIENTATION, |
| Dianne Hackborn | 1e880db | 2009-03-27 16:04:08 -0700 | [diff] [blame] | 5166 | "setRotation()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 5167 | throw new SecurityException("Requires SET_ORIENTATION permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5168 | } |
| 5169 | |
| Dianne Hackborn | 1e880db | 2009-03-27 16:04:08 -0700 | [diff] [blame] | 5170 | setRotationUnchecked(rotation, alwaysSendConfiguration, animFlags); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5171 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5172 | |
| Dianne Hackborn | 1e880db | 2009-03-27 16:04:08 -0700 | [diff] [blame] | 5173 | public void setRotationUnchecked(int rotation, |
| 5174 | boolean alwaysSendConfiguration, int animFlags) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5175 | if(DEBUG_ORIENTATION) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5176 | "alwaysSendConfiguration set to "+alwaysSendConfiguration); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5177 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5178 | long origId = Binder.clearCallingIdentity(); |
| 5179 | boolean changed; |
| 5180 | synchronized(mWindowMap) { |
| Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 5181 | changed = setRotationUncheckedLocked(rotation, animFlags, false); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5182 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5183 | |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 5184 | if (changed || alwaysSendConfiguration) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5185 | sendNewConfiguration(); |
| 5186 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5187 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5188 | Binder.restoreCallingIdentity(origId); |
| 5189 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5190 | |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 5191 | /** |
| 5192 | * Apply a new rotation to the screen, respecting the requests of |
| 5193 | * applications. Use WindowManagerPolicy.USE_LAST_ROTATION to simply |
| 5194 | * re-evaluate the desired rotation. |
| 5195 | * |
| 5196 | * Returns null if the rotation has been changed. In this case YOU |
| 5197 | * MUST CALL setNewConfiguration() TO UNFREEZE THE SCREEN. |
| 5198 | */ |
| Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 5199 | public boolean setRotationUncheckedLocked(int rotation, int animFlags, boolean inTransaction) { |
| Dianne Hackborn | 89ba675 | 2011-01-23 16:51:16 -0800 | [diff] [blame] | 5200 | if (mDragState != null || mScreenRotationAnimation != null) { |
| Christopher Tate | ccd24de | 2011-01-12 15:02:55 -0800 | [diff] [blame] | 5201 | // Potential rotation during a drag. Don't do the rotation now, but make |
| 5202 | // a note to perform the rotation later. |
| Dianne Hackborn | 89ba675 | 2011-01-23 16:51:16 -0800 | [diff] [blame] | 5203 | if (DEBUG_ORIENTATION) Slog.v(TAG, "Deferring rotation."); |
| 5204 | if (rotation != WindowManagerPolicy.USE_LAST_ROTATION) { |
| 5205 | mDeferredRotation = rotation; |
| 5206 | mDeferredRotationAnimFlags = animFlags; |
| 5207 | } |
| Christopher Tate | ccd24de | 2011-01-12 15:02:55 -0800 | [diff] [blame] | 5208 | return false; |
| 5209 | } |
| 5210 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5211 | boolean changed; |
| 5212 | if (rotation == WindowManagerPolicy.USE_LAST_ROTATION) { |
| Dianne Hackborn | 89ba675 | 2011-01-23 16:51:16 -0800 | [diff] [blame] | 5213 | if (mDeferredRotation != WindowManagerPolicy.USE_LAST_ROTATION) { |
| 5214 | rotation = mDeferredRotation; |
| 5215 | mRequestedRotation = rotation; |
| 5216 | mLastRotationFlags = mDeferredRotationAnimFlags; |
| 5217 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5218 | rotation = mRequestedRotation; |
| 5219 | } else { |
| 5220 | mRequestedRotation = rotation; |
| Dianne Hackborn | 321ae68 | 2009-03-27 16:16:03 -0700 | [diff] [blame] | 5221 | mLastRotationFlags = animFlags; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5222 | } |
| Dianne Hackborn | 89ba675 | 2011-01-23 16:51:16 -0800 | [diff] [blame] | 5223 | mDeferredRotation = WindowManagerPolicy.USE_LAST_ROTATION; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5224 | 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] | 5225 | rotation = mPolicy.rotationForOrientationLw(mForcedAppOrientation, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5226 | mRotation, mDisplayEnabled); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5227 | 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] | 5228 | changed = mDisplayEnabled && mRotation != rotation; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5229 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5230 | if (changed) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5231 | if (DEBUG_ORIENTATION) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5232 | "Rotation changed to " + rotation |
| 5233 | + " from " + mRotation |
| 5234 | + " (forceApp=" + mForcedAppOrientation |
| 5235 | + ", req=" + mRequestedRotation + ")"); |
| 5236 | mRotation = rotation; |
| 5237 | mWindowsFreezingScreen = true; |
| 5238 | mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT); |
| 5239 | mH.sendMessageDelayed(mH.obtainMessage(H.WINDOW_FREEZE_TIMEOUT), |
| 5240 | 2000); |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 5241 | mWaitingForConfig = true; |
| 5242 | mLayoutNeeded = true; |
| Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 5243 | startFreezingDisplayLocked(inTransaction); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5244 | Slog.i(TAG, "Setting rotation to " + rotation + ", animFlags=" + animFlags); |
| Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 5245 | mInputManager.setDisplayOrientation(0, rotation); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5246 | if (mDisplayEnabled) { |
| Dianne Hackborn | a111187 | 2010-11-23 20:55:11 -0800 | [diff] [blame] | 5247 | if (CUSTOM_SCREEN_ROTATION) { |
| 5248 | Surface.freezeDisplay(0); |
| Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 5249 | if (!inTransaction) { |
| 5250 | if (SHOW_TRANSACTIONS) Slog.i(TAG, |
| 5251 | ">>> OPEN TRANSACTION setRotationUnchecked"); |
| 5252 | Surface.openTransaction(); |
| Dianne Hackborn | a111187 | 2010-11-23 20:55:11 -0800 | [diff] [blame] | 5253 | } |
| Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 5254 | try { |
| 5255 | if (mScreenRotationAnimation != null) { |
| 5256 | mScreenRotationAnimation.setRotation(rotation); |
| 5257 | } |
| 5258 | } finally { |
| 5259 | if (!inTransaction) { |
| 5260 | Surface.closeTransaction(); |
| 5261 | if (SHOW_TRANSACTIONS) Slog.i(TAG, |
| 5262 | "<<< CLOSE TRANSACTION setRotationUnchecked"); |
| 5263 | } |
| 5264 | } |
| Dianne Hackborn | a111187 | 2010-11-23 20:55:11 -0800 | [diff] [blame] | 5265 | Surface.setOrientation(0, rotation, animFlags); |
| 5266 | Surface.unfreezeDisplay(0); |
| 5267 | } else { |
| 5268 | Surface.setOrientation(0, rotation, animFlags); |
| 5269 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5270 | } |
| 5271 | for (int i=mWindows.size()-1; i>=0; i--) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 5272 | WindowState w = mWindows.get(i); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5273 | if (w.mSurface != null) { |
| 5274 | w.mOrientationChanging = true; |
| 5275 | } |
| 5276 | } |
| 5277 | for (int i=mRotationWatchers.size()-1; i>=0; i--) { |
| 5278 | try { |
| 5279 | mRotationWatchers.get(i).onRotationChanged(rotation); |
| 5280 | } catch (RemoteException e) { |
| 5281 | } |
| 5282 | } |
| 5283 | } //end if changed |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5284 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5285 | return changed; |
| 5286 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5287 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5288 | public int getRotation() { |
| 5289 | return mRotation; |
| 5290 | } |
| 5291 | |
| 5292 | public int watchRotation(IRotationWatcher watcher) { |
| 5293 | final IBinder watcherBinder = watcher.asBinder(); |
| 5294 | IBinder.DeathRecipient dr = new IBinder.DeathRecipient() { |
| 5295 | public void binderDied() { |
| 5296 | synchronized (mWindowMap) { |
| 5297 | for (int i=0; i<mRotationWatchers.size(); i++) { |
| 5298 | if (watcherBinder == mRotationWatchers.get(i).asBinder()) { |
| Suchi Amalapurapu | fff2fda | 2009-06-30 21:36:16 -0700 | [diff] [blame] | 5299 | IRotationWatcher removed = mRotationWatchers.remove(i); |
| 5300 | if (removed != null) { |
| 5301 | removed.asBinder().unlinkToDeath(this, 0); |
| 5302 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5303 | i--; |
| 5304 | } |
| 5305 | } |
| 5306 | } |
| 5307 | } |
| 5308 | }; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5309 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5310 | synchronized (mWindowMap) { |
| 5311 | try { |
| 5312 | watcher.asBinder().linkToDeath(dr, 0); |
| 5313 | mRotationWatchers.add(watcher); |
| 5314 | } catch (RemoteException e) { |
| 5315 | // Client died, no cleanup needed. |
| 5316 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5317 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5318 | return mRotation; |
| 5319 | } |
| 5320 | } |
| 5321 | |
| 5322 | /** |
| 5323 | * Starts the view server on the specified port. |
| 5324 | * |
| 5325 | * @param port The port to listener to. |
| 5326 | * |
| 5327 | * @return True if the server was successfully started, false otherwise. |
| 5328 | * |
| 5329 | * @see com.android.server.ViewServer |
| 5330 | * @see com.android.server.ViewServer#VIEW_SERVER_DEFAULT_PORT |
| 5331 | */ |
| 5332 | public boolean startViewServer(int port) { |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5333 | if (isSystemSecure()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5334 | return false; |
| 5335 | } |
| 5336 | |
| 5337 | if (!checkCallingPermission(Manifest.permission.DUMP, "startViewServer")) { |
| 5338 | return false; |
| 5339 | } |
| 5340 | |
| 5341 | if (port < 1024) { |
| 5342 | return false; |
| 5343 | } |
| 5344 | |
| 5345 | if (mViewServer != null) { |
| 5346 | if (!mViewServer.isRunning()) { |
| 5347 | try { |
| 5348 | return mViewServer.start(); |
| 5349 | } catch (IOException e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5350 | Slog.w(TAG, "View server did not start"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5351 | } |
| 5352 | } |
| 5353 | return false; |
| 5354 | } |
| 5355 | |
| 5356 | try { |
| 5357 | mViewServer = new ViewServer(this, port); |
| 5358 | return mViewServer.start(); |
| 5359 | } catch (IOException e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5360 | Slog.w(TAG, "View server did not start"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5361 | } |
| 5362 | return false; |
| 5363 | } |
| 5364 | |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5365 | private boolean isSystemSecure() { |
| 5366 | return "1".equals(SystemProperties.get(SYSTEM_SECURE, "1")) && |
| 5367 | "0".equals(SystemProperties.get(SYSTEM_DEBUGGABLE, "0")); |
| 5368 | } |
| 5369 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5370 | /** |
| 5371 | * Stops the view server if it exists. |
| 5372 | * |
| 5373 | * @return True if the server stopped, false if it wasn't started or |
| 5374 | * couldn't be stopped. |
| 5375 | * |
| 5376 | * @see com.android.server.ViewServer |
| 5377 | */ |
| 5378 | public boolean stopViewServer() { |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5379 | if (isSystemSecure()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5380 | return false; |
| 5381 | } |
| 5382 | |
| 5383 | if (!checkCallingPermission(Manifest.permission.DUMP, "stopViewServer")) { |
| 5384 | return false; |
| 5385 | } |
| 5386 | |
| 5387 | if (mViewServer != null) { |
| 5388 | return mViewServer.stop(); |
| 5389 | } |
| 5390 | return false; |
| 5391 | } |
| 5392 | |
| 5393 | /** |
| 5394 | * Indicates whether the view server is running. |
| 5395 | * |
| 5396 | * @return True if the server is running, false otherwise. |
| 5397 | * |
| 5398 | * @see com.android.server.ViewServer |
| 5399 | */ |
| 5400 | public boolean isViewServerRunning() { |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5401 | if (isSystemSecure()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5402 | return false; |
| 5403 | } |
| 5404 | |
| 5405 | if (!checkCallingPermission(Manifest.permission.DUMP, "isViewServerRunning")) { |
| 5406 | return false; |
| 5407 | } |
| 5408 | |
| 5409 | return mViewServer != null && mViewServer.isRunning(); |
| 5410 | } |
| 5411 | |
| 5412 | /** |
| 5413 | * Lists all availble windows in the system. The listing is written in the |
| 5414 | * specified Socket's output stream with the following syntax: |
| 5415 | * windowHashCodeInHexadecimal windowName |
| 5416 | * Each line of the ouput represents a different window. |
| 5417 | * |
| 5418 | * @param client The remote client to send the listing to. |
| 5419 | * @return False if an error occured, true otherwise. |
| 5420 | */ |
| 5421 | boolean viewServerListWindows(Socket client) { |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5422 | if (isSystemSecure()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5423 | return false; |
| 5424 | } |
| 5425 | |
| 5426 | boolean result = true; |
| 5427 | |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 5428 | WindowState[] windows; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5429 | synchronized (mWindowMap) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5430 | //noinspection unchecked |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 5431 | windows = mWindows.toArray(new WindowState[mWindows.size()]); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5432 | } |
| 5433 | |
| 5434 | BufferedWriter out = null; |
| 5435 | |
| 5436 | // Any uncaught exception will crash the system process |
| 5437 | try { |
| 5438 | OutputStream clientStream = client.getOutputStream(); |
| 5439 | out = new BufferedWriter(new OutputStreamWriter(clientStream), 8 * 1024); |
| 5440 | |
| 5441 | final int count = windows.length; |
| 5442 | for (int i = 0; i < count; i++) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 5443 | final WindowState w = windows[i]; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5444 | out.write(Integer.toHexString(System.identityHashCode(w))); |
| 5445 | out.write(' '); |
| 5446 | out.append(w.mAttrs.getTitle()); |
| 5447 | out.write('\n'); |
| 5448 | } |
| 5449 | |
| 5450 | out.write("DONE.\n"); |
| 5451 | out.flush(); |
| 5452 | } catch (Exception e) { |
| 5453 | result = false; |
| 5454 | } finally { |
| 5455 | if (out != null) { |
| 5456 | try { |
| 5457 | out.close(); |
| 5458 | } catch (IOException e) { |
| 5459 | result = false; |
| 5460 | } |
| 5461 | } |
| 5462 | } |
| 5463 | |
| 5464 | return result; |
| 5465 | } |
| 5466 | |
| 5467 | /** |
| Konstantin Lopyrev | f962476 | 2010-07-14 17:02:37 -0700 | [diff] [blame] | 5468 | * Returns the focused window in the following format: |
| 5469 | * windowHashCodeInHexadecimal windowName |
| 5470 | * |
| 5471 | * @param client The remote client to send the listing to. |
| 5472 | * @return False if an error occurred, true otherwise. |
| 5473 | */ |
| 5474 | boolean viewServerGetFocusedWindow(Socket client) { |
| 5475 | if (isSystemSecure()) { |
| 5476 | return false; |
| 5477 | } |
| 5478 | |
| 5479 | boolean result = true; |
| 5480 | |
| 5481 | WindowState focusedWindow = getFocusedWindow(); |
| 5482 | |
| 5483 | BufferedWriter out = null; |
| 5484 | |
| 5485 | // Any uncaught exception will crash the system process |
| 5486 | try { |
| 5487 | OutputStream clientStream = client.getOutputStream(); |
| 5488 | out = new BufferedWriter(new OutputStreamWriter(clientStream), 8 * 1024); |
| 5489 | |
| 5490 | if(focusedWindow != null) { |
| 5491 | out.write(Integer.toHexString(System.identityHashCode(focusedWindow))); |
| 5492 | out.write(' '); |
| 5493 | out.append(focusedWindow.mAttrs.getTitle()); |
| 5494 | } |
| 5495 | out.write('\n'); |
| 5496 | out.flush(); |
| 5497 | } catch (Exception e) { |
| 5498 | result = false; |
| 5499 | } finally { |
| 5500 | if (out != null) { |
| 5501 | try { |
| 5502 | out.close(); |
| 5503 | } catch (IOException e) { |
| 5504 | result = false; |
| 5505 | } |
| 5506 | } |
| 5507 | } |
| 5508 | |
| 5509 | return result; |
| 5510 | } |
| 5511 | |
| 5512 | /** |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5513 | * Sends a command to a target window. The result of the command, if any, will be |
| 5514 | * written in the output stream of the specified socket. |
| 5515 | * |
| 5516 | * The parameters must follow this syntax: |
| 5517 | * windowHashcode extra |
| 5518 | * |
| 5519 | * Where XX is the length in characeters of the windowTitle. |
| 5520 | * |
| 5521 | * The first parameter is the target window. The window with the specified hashcode |
| 5522 | * will be the target. If no target can be found, nothing happens. The extra parameters |
| 5523 | * will be delivered to the target window and as parameters to the command itself. |
| 5524 | * |
| 5525 | * @param client The remote client to sent the result, if any, to. |
| 5526 | * @param command The command to execute. |
| 5527 | * @param parameters The command parameters. |
| 5528 | * |
| 5529 | * @return True if the command was successfully delivered, false otherwise. This does |
| 5530 | * not indicate whether the command itself was successful. |
| 5531 | */ |
| 5532 | boolean viewServerWindowCommand(Socket client, String command, String parameters) { |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5533 | if (isSystemSecure()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5534 | return false; |
| 5535 | } |
| 5536 | |
| 5537 | boolean success = true; |
| 5538 | Parcel data = null; |
| 5539 | Parcel reply = null; |
| 5540 | |
| Konstantin Lopyrev | 43b9b48 | 2010-08-24 22:00:12 -0700 | [diff] [blame] | 5541 | BufferedWriter out = null; |
| 5542 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5543 | // Any uncaught exception will crash the system process |
| 5544 | try { |
| 5545 | // Find the hashcode of the window |
| 5546 | int index = parameters.indexOf(' '); |
| 5547 | if (index == -1) { |
| 5548 | index = parameters.length(); |
| 5549 | } |
| 5550 | final String code = parameters.substring(0, index); |
| Romain Guy | 236092a | 2009-12-14 15:31:48 -0800 | [diff] [blame] | 5551 | int hashCode = (int) Long.parseLong(code, 16); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5552 | |
| 5553 | // Extract the command's parameter after the window description |
| 5554 | if (index < parameters.length()) { |
| 5555 | parameters = parameters.substring(index + 1); |
| 5556 | } else { |
| 5557 | parameters = ""; |
| 5558 | } |
| 5559 | |
| 5560 | final WindowManagerService.WindowState window = findWindow(hashCode); |
| 5561 | if (window == null) { |
| 5562 | return false; |
| 5563 | } |
| 5564 | |
| 5565 | data = Parcel.obtain(); |
| 5566 | data.writeInterfaceToken("android.view.IWindow"); |
| 5567 | data.writeString(command); |
| 5568 | data.writeString(parameters); |
| 5569 | data.writeInt(1); |
| 5570 | ParcelFileDescriptor.fromSocket(client).writeToParcel(data, 0); |
| 5571 | |
| 5572 | reply = Parcel.obtain(); |
| 5573 | |
| 5574 | final IBinder binder = window.mClient.asBinder(); |
| 5575 | // TODO: GET THE TRANSACTION CODE IN A SAFER MANNER |
| 5576 | binder.transact(IBinder.FIRST_CALL_TRANSACTION, data, reply, 0); |
| 5577 | |
| 5578 | reply.readException(); |
| 5579 | |
| Konstantin Lopyrev | 43b9b48 | 2010-08-24 22:00:12 -0700 | [diff] [blame] | 5580 | if (!client.isOutputShutdown()) { |
| 5581 | out = new BufferedWriter(new OutputStreamWriter(client.getOutputStream())); |
| 5582 | out.write("DONE\n"); |
| 5583 | out.flush(); |
| 5584 | } |
| 5585 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5586 | } catch (Exception e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 5587 | 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] | 5588 | success = false; |
| 5589 | } finally { |
| 5590 | if (data != null) { |
| 5591 | data.recycle(); |
| 5592 | } |
| 5593 | if (reply != null) { |
| 5594 | reply.recycle(); |
| 5595 | } |
| Konstantin Lopyrev | 43b9b48 | 2010-08-24 22:00:12 -0700 | [diff] [blame] | 5596 | if (out != null) { |
| 5597 | try { |
| 5598 | out.close(); |
| 5599 | } catch (IOException e) { |
| 5600 | |
| 5601 | } |
| 5602 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5603 | } |
| 5604 | |
| 5605 | return success; |
| 5606 | } |
| 5607 | |
| Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 5608 | public void addWindowChangeListener(WindowChangeListener listener) { |
| 5609 | synchronized(mWindowMap) { |
| 5610 | mWindowChangeListeners.add(listener); |
| 5611 | } |
| 5612 | } |
| 5613 | |
| 5614 | public void removeWindowChangeListener(WindowChangeListener listener) { |
| 5615 | synchronized(mWindowMap) { |
| 5616 | mWindowChangeListeners.remove(listener); |
| 5617 | } |
| 5618 | } |
| 5619 | |
| 5620 | private void notifyWindowsChanged() { |
| 5621 | WindowChangeListener[] windowChangeListeners; |
| 5622 | synchronized(mWindowMap) { |
| 5623 | if(mWindowChangeListeners.isEmpty()) { |
| 5624 | return; |
| 5625 | } |
| 5626 | windowChangeListeners = new WindowChangeListener[mWindowChangeListeners.size()]; |
| 5627 | windowChangeListeners = mWindowChangeListeners.toArray(windowChangeListeners); |
| 5628 | } |
| 5629 | int N = windowChangeListeners.length; |
| 5630 | for(int i = 0; i < N; i++) { |
| 5631 | windowChangeListeners[i].windowsChanged(); |
| 5632 | } |
| 5633 | } |
| 5634 | |
| Konstantin Lopyrev | 6e0f65f | 2010-07-14 14:55:33 -0700 | [diff] [blame] | 5635 | private void notifyFocusChanged() { |
| 5636 | WindowChangeListener[] windowChangeListeners; |
| 5637 | synchronized(mWindowMap) { |
| 5638 | if(mWindowChangeListeners.isEmpty()) { |
| 5639 | return; |
| 5640 | } |
| 5641 | windowChangeListeners = new WindowChangeListener[mWindowChangeListeners.size()]; |
| 5642 | windowChangeListeners = mWindowChangeListeners.toArray(windowChangeListeners); |
| 5643 | } |
| 5644 | int N = windowChangeListeners.length; |
| 5645 | for(int i = 0; i < N; i++) { |
| 5646 | windowChangeListeners[i].focusChanged(); |
| 5647 | } |
| 5648 | } |
| 5649 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5650 | private WindowState findWindow(int hashCode) { |
| 5651 | if (hashCode == -1) { |
| 5652 | return getFocusedWindow(); |
| 5653 | } |
| 5654 | |
| 5655 | synchronized (mWindowMap) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 5656 | final ArrayList<WindowState> windows = mWindows; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5657 | final int count = windows.size(); |
| 5658 | |
| 5659 | for (int i = 0; i < count; i++) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 5660 | WindowState w = windows.get(i); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5661 | if (System.identityHashCode(w) == hashCode) { |
| 5662 | return w; |
| 5663 | } |
| 5664 | } |
| 5665 | } |
| 5666 | |
| 5667 | return null; |
| 5668 | } |
| 5669 | |
| 5670 | /* |
| 5671 | * Instruct the Activity Manager to fetch the current configuration and broadcast |
| 5672 | * that to config-changed listeners if appropriate. |
| 5673 | */ |
| 5674 | void sendNewConfiguration() { |
| 5675 | try { |
| 5676 | mActivityManager.updateConfiguration(null); |
| 5677 | } catch (RemoteException e) { |
| 5678 | } |
| 5679 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5680 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5681 | public Configuration computeNewConfiguration() { |
| 5682 | synchronized (mWindowMap) { |
| Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 5683 | Configuration config = computeNewConfigurationLocked(); |
| 5684 | if (config == null && mWaitingForConfig) { |
| 5685 | // Nothing changed but we are waiting for something... stop that! |
| 5686 | mWaitingForConfig = false; |
| 5687 | performLayoutAndPlaceSurfacesLocked(); |
| 5688 | } |
| 5689 | return config; |
| Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 5690 | } |
| 5691 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5692 | |
| Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 5693 | Configuration computeNewConfigurationLocked() { |
| 5694 | Configuration config = new Configuration(); |
| 5695 | if (!computeNewConfigurationLocked(config)) { |
| 5696 | return null; |
| 5697 | } |
| Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 5698 | return config; |
| 5699 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 5700 | |
| Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 5701 | boolean computeNewConfigurationLocked(Configuration config) { |
| 5702 | if (mDisplay == null) { |
| 5703 | return false; |
| 5704 | } |
| Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 5705 | |
| 5706 | mInputManager.getInputConfiguration(config); |
| Christopher Tate | b696aee | 2010-04-02 19:08:30 -0700 | [diff] [blame] | 5707 | |
| 5708 | // Use the effective "visual" dimensions based on current rotation |
| 5709 | final boolean rotated = (mRotation == Surface.ROTATION_90 |
| 5710 | || mRotation == Surface.ROTATION_270); |
| 5711 | final int dw = rotated ? mInitialDisplayHeight : mInitialDisplayWidth; |
| 5712 | final int dh = rotated ? mInitialDisplayWidth : mInitialDisplayHeight; |
| 5713 | |
| Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 5714 | int orientation = Configuration.ORIENTATION_SQUARE; |
| 5715 | if (dw < dh) { |
| 5716 | orientation = Configuration.ORIENTATION_PORTRAIT; |
| 5717 | } else if (dw > dh) { |
| 5718 | orientation = Configuration.ORIENTATION_LANDSCAPE; |
| 5719 | } |
| 5720 | config.orientation = orientation; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 5721 | |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 5722 | DisplayMetrics dm = new DisplayMetrics(); |
| 5723 | mDisplay.getMetrics(dm); |
| 5724 | CompatibilityInfo.updateCompatibleScreenFrame(dm, orientation, mCompatibleScreenFrame); |
| 5725 | |
| Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 5726 | if (mScreenLayout == Configuration.SCREENLAYOUT_SIZE_UNDEFINED) { |
| Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 5727 | // Note we only do this once because at this point we don't |
| 5728 | // expect the screen to change in this way at runtime, and want |
| 5729 | // to avoid all of this computation for every config change. |
| Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 5730 | int longSize = dw; |
| 5731 | int shortSize = dh; |
| 5732 | if (longSize < shortSize) { |
| 5733 | int tmp = longSize; |
| 5734 | longSize = shortSize; |
| 5735 | shortSize = tmp; |
| 5736 | } |
| 5737 | longSize = (int)(longSize/dm.density); |
| 5738 | shortSize = (int)(shortSize/dm.density); |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 5739 | |
| Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 5740 | // These semi-magic numbers define our compatibility modes for |
| 5741 | // applications with different screens. Don't change unless you |
| 5742 | // make sure to test lots and lots of apps! |
| 5743 | if (longSize < 470) { |
| 5744 | // This is shorter than an HVGA normal density screen (which |
| 5745 | // is 480 pixels on its long side). |
| Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 5746 | mScreenLayout = Configuration.SCREENLAYOUT_SIZE_SMALL |
| 5747 | | Configuration.SCREENLAYOUT_LONG_NO; |
| Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 5748 | } else { |
| Dianne Hackborn | 14cee9f | 2010-04-23 17:51:26 -0700 | [diff] [blame] | 5749 | // What size is this screen screen? |
| 5750 | if (longSize >= 800 && shortSize >= 600) { |
| 5751 | // SVGA or larger screens at medium density are the point |
| 5752 | // at which we consider it to be an extra large screen. |
| 5753 | mScreenLayout = Configuration.SCREENLAYOUT_SIZE_XLARGE; |
| Dianne Hackborn | b51dc0f | 2010-10-21 15:34:47 -0700 | [diff] [blame] | 5754 | } else if (longSize >= 530 && shortSize >= 400) { |
| 5755 | // SVGA or larger screens at high density are the point |
| Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 5756 | // at which we consider it to be a large screen. |
| 5757 | mScreenLayout = Configuration.SCREENLAYOUT_SIZE_LARGE; |
| 5758 | } else { |
| 5759 | mScreenLayout = Configuration.SCREENLAYOUT_SIZE_NORMAL; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 5760 | |
| Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 5761 | // If this screen is wider than normal HVGA, or taller |
| 5762 | // than FWVGA, then for old apps we want to run in size |
| 5763 | // compatibility mode. |
| 5764 | if (shortSize > 321 || longSize > 570) { |
| 5765 | mScreenLayout |= Configuration.SCREENLAYOUT_COMPAT_NEEDED; |
| 5766 | } |
| 5767 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 5768 | |
| Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 5769 | // Is this a long screen? |
| 5770 | if (((longSize*3)/5) >= (shortSize-1)) { |
| 5771 | // Anything wider than WVGA (5:3) is considering to be long. |
| 5772 | mScreenLayout |= Configuration.SCREENLAYOUT_LONG_YES; |
| 5773 | } else { |
| 5774 | mScreenLayout |= Configuration.SCREENLAYOUT_LONG_NO; |
| 5775 | } |
| Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 5776 | } |
| 5777 | } |
| Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 5778 | config.screenLayout = mScreenLayout; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 5779 | |
| Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 5780 | config.keyboardHidden = Configuration.KEYBOARDHIDDEN_NO; |
| 5781 | config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_NO; |
| 5782 | mPolicy.adjustConfigurationLw(config); |
| Jeff Brown | 2992ea7 | 2011-01-28 22:04:14 -0800 | [diff] [blame^] | 5783 | |
| 5784 | // Adjust the hard keyboard configuration based on whether the hard keyboard is enabled. |
| 5785 | boolean hardKeyboardAvailable = config.keyboard != Configuration.KEYBOARD_NOKEYS; |
| 5786 | if (hardKeyboardAvailable != mHardKeyboardAvailable) { |
| 5787 | mHardKeyboardAvailable = hardKeyboardAvailable; |
| 5788 | mHardKeyboardEnabled = hardKeyboardAvailable; |
| 5789 | |
| 5790 | mH.removeMessages(H.REPORT_HARD_KEYBOARD_STATUS_CHANGE); |
| 5791 | mH.sendEmptyMessage(H.REPORT_HARD_KEYBOARD_STATUS_CHANGE); |
| 5792 | } |
| 5793 | if (!mHardKeyboardEnabled) { |
| 5794 | config.keyboard = Configuration.KEYBOARD_NOKEYS; |
| 5795 | config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_NO; |
| 5796 | } |
| Dianne Hackborn | c485a60 | 2009-03-24 22:39:49 -0700 | [diff] [blame] | 5797 | return true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5798 | } |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5799 | |
| Jeff Brown | 2992ea7 | 2011-01-28 22:04:14 -0800 | [diff] [blame^] | 5800 | public boolean isHardKeyboardAvailable() { |
| 5801 | synchronized (mWindowMap) { |
| 5802 | return mHardKeyboardAvailable; |
| 5803 | } |
| 5804 | } |
| 5805 | |
| 5806 | public boolean isHardKeyboardEnabled() { |
| 5807 | synchronized (mWindowMap) { |
| 5808 | return mHardKeyboardEnabled; |
| 5809 | } |
| 5810 | } |
| 5811 | |
| 5812 | public void setHardKeyboardEnabled(boolean enabled) { |
| 5813 | synchronized (mWindowMap) { |
| 5814 | if (mHardKeyboardEnabled != enabled) { |
| 5815 | mHardKeyboardEnabled = enabled; |
| 5816 | mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION); |
| 5817 | } |
| 5818 | } |
| 5819 | } |
| 5820 | |
| 5821 | public void setOnHardKeyboardStatusChangeListener( |
| 5822 | OnHardKeyboardStatusChangeListener listener) { |
| 5823 | synchronized (mWindowMap) { |
| 5824 | mHardKeyboardStatusChangeListener = listener; |
| 5825 | } |
| 5826 | } |
| 5827 | |
| 5828 | void notifyHardKeyboardStatusChange() { |
| 5829 | final boolean available, enabled; |
| 5830 | final OnHardKeyboardStatusChangeListener listener; |
| 5831 | synchronized (mWindowMap) { |
| 5832 | listener = mHardKeyboardStatusChangeListener; |
| 5833 | available = mHardKeyboardAvailable; |
| 5834 | enabled = mHardKeyboardEnabled; |
| 5835 | } |
| 5836 | if (listener != null) { |
| 5837 | listener.onHardKeyboardStatusChange(available, enabled); |
| 5838 | } |
| 5839 | } |
| 5840 | |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5841 | // ------------------------------------------------------------- |
| 5842 | // Drag and drop |
| 5843 | // ------------------------------------------------------------- |
| 5844 | |
| 5845 | IBinder prepareDragSurface(IWindow window, SurfaceSession session, |
| Christopher Tate | 02d2b3b | 2011-01-10 20:43:53 -0800 | [diff] [blame] | 5846 | int flags, int width, int height, Surface outSurface) { |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5847 | if (DEBUG_DRAG) { |
| 5848 | Slog.d(TAG, "prepare drag surface: w=" + width + " h=" + height |
| Christopher Tate | 02d2b3b | 2011-01-10 20:43:53 -0800 | [diff] [blame] | 5849 | + " flags=" + Integer.toHexString(flags) + " win=" + window |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5850 | + " asbinder=" + window.asBinder()); |
| 5851 | } |
| 5852 | |
| 5853 | final int callerPid = Binder.getCallingPid(); |
| 5854 | final long origId = Binder.clearCallingIdentity(); |
| 5855 | IBinder token = null; |
| 5856 | |
| 5857 | try { |
| 5858 | synchronized (mWindowMap) { |
| 5859 | try { |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5860 | if (mDragState == null) { |
| 5861 | Surface surface = new Surface(session, callerPid, "drag surface", 0, |
| 5862 | width, height, PixelFormat.TRANSLUCENT, Surface.HIDDEN); |
| 5863 | outSurface.copyFrom(surface); |
| Chris Tate | 7b362e4 | 2010-11-04 16:02:52 -0700 | [diff] [blame] | 5864 | final IBinder winBinder = window.asBinder(); |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5865 | token = new Binder(); |
| Christopher Tate | 02d2b3b | 2011-01-10 20:43:53 -0800 | [diff] [blame] | 5866 | // TODO: preserve flags param in DragState |
| 5867 | mDragState = new DragState(token, surface, 0, winBinder); |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5868 | mDragState.mSurface = surface; |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5869 | token = mDragState.mToken = new Binder(); |
| 5870 | |
| 5871 | // 5 second timeout for this window to actually begin the drag |
| Chris Tate | 7b362e4 | 2010-11-04 16:02:52 -0700 | [diff] [blame] | 5872 | mH.removeMessages(H.DRAG_START_TIMEOUT, winBinder); |
| 5873 | Message msg = mH.obtainMessage(H.DRAG_START_TIMEOUT, winBinder); |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5874 | mH.sendMessageDelayed(msg, 5000); |
| 5875 | } else { |
| 5876 | Slog.w(TAG, "Drag already in progress"); |
| 5877 | } |
| 5878 | } catch (Surface.OutOfResourcesException e) { |
| 5879 | Slog.e(TAG, "Can't allocate drag surface w=" + width + " h=" + height, e); |
| 5880 | if (mDragState != null) { |
| 5881 | mDragState.reset(); |
| 5882 | mDragState = null; |
| 5883 | } |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5884 | } |
| 5885 | } |
| 5886 | } finally { |
| 5887 | Binder.restoreCallingIdentity(origId); |
| 5888 | } |
| 5889 | |
| 5890 | return token; |
| 5891 | } |
| 5892 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5893 | // ------------------------------------------------------------- |
| 5894 | // Input Events and Focus Management |
| 5895 | // ------------------------------------------------------------- |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5896 | |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5897 | InputMonitor mInputMonitor = new InputMonitor(); |
| 5898 | |
| 5899 | /* Tracks the progress of input dispatch and ensures that input dispatch state |
| 5900 | * is kept in sync with changes in window focus, visibility, registration, and |
| 5901 | * other relevant Window Manager state transitions. */ |
| 5902 | final class InputMonitor { |
| 5903 | // Current window with input focus for keys and other non-touch events. May be null. |
| 5904 | private WindowState mInputFocus; |
| 5905 | |
| 5906 | // When true, prevents input dispatch from proceeding until set to false again. |
| 5907 | private boolean mInputDispatchFrozen; |
| 5908 | |
| 5909 | // When true, input dispatch proceeds normally. Otherwise all events are dropped. |
| 5910 | private boolean mInputDispatchEnabled = true; |
| 5911 | |
| Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 5912 | // When true, need to call updateInputWindowsLw(). |
| 5913 | private boolean mUpdateInputWindowsNeeded = true; |
| 5914 | |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5915 | // Temporary list of windows information to provide to the input dispatcher. |
| 5916 | private InputWindowList mTempInputWindows = new InputWindowList(); |
| 5917 | |
| 5918 | // Temporary input application object to provide to the input dispatcher. |
| 5919 | private InputApplication mTempInputApplication = new InputApplication(); |
| 5920 | |
| Jeff Brown | b09abc1 | 2011-01-13 21:08:27 -0800 | [diff] [blame] | 5921 | // Set to true when the first input device configuration change notification |
| 5922 | // is received to indicate that the input devices are ready. |
| 5923 | private final Object mInputDevicesReadyMonitor = new Object(); |
| 5924 | private boolean mInputDevicesReady; |
| 5925 | |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5926 | /* Notifies the window manager about a broken input channel. |
| 5927 | * |
| 5928 | * Called by the InputManager. |
| 5929 | */ |
| Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame] | 5930 | public void notifyInputChannelBroken(InputWindowHandle inputWindowHandle) { |
| 5931 | if (inputWindowHandle == null) { |
| 5932 | return; |
| 5933 | } |
| 5934 | |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5935 | synchronized (mWindowMap) { |
| Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame] | 5936 | WindowState windowState = (WindowState) inputWindowHandle.windowState; |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5937 | Slog.i(TAG, "WINDOW DIED " + windowState); |
| 5938 | removeWindowLocked(windowState.mSession, windowState); |
| Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 5939 | } |
| 5940 | } |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 5941 | |
| Jeff Brown | 519e024 | 2010-09-15 15:18:56 -0700 | [diff] [blame] | 5942 | /* Notifies the window manager about an application that is not responding. |
| Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 5943 | * 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] | 5944 | * |
| 5945 | * Called by the InputManager. |
| 5946 | */ |
| Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame] | 5947 | public long notifyANR(InputApplicationHandle inputApplicationHandle, |
| 5948 | InputWindowHandle inputWindowHandle) { |
| Jeff Brown | 519e024 | 2010-09-15 15:18:56 -0700 | [diff] [blame] | 5949 | AppWindowToken appWindowToken = null; |
| Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame] | 5950 | if (inputWindowHandle != null) { |
| Jeff Brown | 519e024 | 2010-09-15 15:18:56 -0700 | [diff] [blame] | 5951 | synchronized (mWindowMap) { |
| Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame] | 5952 | WindowState windowState = (WindowState) inputWindowHandle.windowState; |
| Jeff Brown | 519e024 | 2010-09-15 15:18:56 -0700 | [diff] [blame] | 5953 | if (windowState != null) { |
| 5954 | Slog.i(TAG, "Input event dispatching timed out sending to " |
| 5955 | + windowState.mAttrs.getTitle()); |
| 5956 | appWindowToken = windowState.mAppToken; |
| 5957 | } |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5958 | } |
| Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 5959 | } |
| 5960 | |
| Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame] | 5961 | if (appWindowToken == null && inputApplicationHandle != null) { |
| 5962 | appWindowToken = inputApplicationHandle.appWindowToken; |
| Jeff Brown | 519e024 | 2010-09-15 15:18:56 -0700 | [diff] [blame] | 5963 | Slog.i(TAG, "Input event dispatching timed out sending to application " |
| 5964 | + appWindowToken.stringName); |
| 5965 | } |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5966 | |
| Jeff Brown | 519e024 | 2010-09-15 15:18:56 -0700 | [diff] [blame] | 5967 | if (appWindowToken != null && appWindowToken.appToken != null) { |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5968 | try { |
| 5969 | // Notify the activity manager about the timeout and let it decide whether |
| 5970 | // to abort dispatching or keep waiting. |
| Jeff Brown | 519e024 | 2010-09-15 15:18:56 -0700 | [diff] [blame] | 5971 | boolean abort = appWindowToken.appToken.keyDispatchingTimedOut(); |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5972 | if (! abort) { |
| 5973 | // The activity manager declined to abort dispatching. |
| 5974 | // Wait a bit longer and timeout again later. |
| Jeff Brown | 519e024 | 2010-09-15 15:18:56 -0700 | [diff] [blame] | 5975 | return appWindowToken.inputDispatchingTimeoutNanos; |
| Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 5976 | } |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 5977 | } catch (RemoteException ex) { |
| Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 5978 | } |
| 5979 | } |
| Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 5980 | return 0; // abort dispatching |
| Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 5981 | } |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5982 | |
| Chris Tate | a32dcf7 | 2010-10-14 12:13:50 -0700 | [diff] [blame] | 5983 | private void addDragInputWindowLw(InputWindowList windowList) { |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5984 | final InputWindow inputWindow = windowList.add(); |
| 5985 | inputWindow.inputChannel = mDragState.mServerChannel; |
| 5986 | inputWindow.name = "drag"; |
| Christopher Tate | a159579 | 2011-01-19 17:26:50 -0800 | [diff] [blame] | 5987 | inputWindow.layoutParamsFlags = 0; |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5988 | inputWindow.layoutParamsType = WindowManager.LayoutParams.TYPE_DRAG; |
| 5989 | inputWindow.dispatchingTimeoutNanos = DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS; |
| 5990 | inputWindow.visible = true; |
| 5991 | inputWindow.canReceiveKeys = false; |
| 5992 | inputWindow.hasFocus = true; |
| 5993 | inputWindow.hasWallpaper = false; |
| 5994 | inputWindow.paused = false; |
| Chris Tate | a32dcf7 | 2010-10-14 12:13:50 -0700 | [diff] [blame] | 5995 | inputWindow.layer = mDragState.getDragLayerLw(); |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 5996 | inputWindow.ownerPid = Process.myPid(); |
| 5997 | inputWindow.ownerUid = Process.myUid(); |
| 5998 | |
| 5999 | // The drag window covers the entire display |
| 6000 | inputWindow.frameLeft = 0; |
| 6001 | inputWindow.frameTop = 0; |
| 6002 | inputWindow.frameRight = mDisplay.getWidth(); |
| 6003 | inputWindow.frameBottom = mDisplay.getHeight(); |
| Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 6004 | |
| Jeff Brown | fbf0977 | 2011-01-16 14:06:57 -0800 | [diff] [blame] | 6005 | // The drag window cannot receive new touches. |
| 6006 | inputWindow.touchableRegion.setEmpty(); |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 6007 | } |
| 6008 | |
| Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 6009 | public void setUpdateInputWindowsNeededLw() { |
| 6010 | mUpdateInputWindowsNeeded = true; |
| 6011 | } |
| 6012 | |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 6013 | /* Updates the cached window information provided to the input dispatcher. */ |
| Jeff Brown | 2e44b07 | 2011-01-24 15:21:56 -0800 | [diff] [blame] | 6014 | public void updateInputWindowsLw(boolean force) { |
| 6015 | if (!force && !mUpdateInputWindowsNeeded) { |
| Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 6016 | return; |
| 6017 | } |
| 6018 | mUpdateInputWindowsNeeded = false; |
| 6019 | |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 6020 | // Populate the input window list with information about all of the windows that |
| 6021 | // could potentially receive input. |
| 6022 | // As an optimization, we could try to prune the list of windows but this turns |
| 6023 | // out to be difficult because only the native code knows for sure which window |
| 6024 | // currently has touch focus. |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 6025 | final ArrayList<WindowState> windows = mWindows; |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 6026 | |
| 6027 | // If there's a drag in flight, provide a pseudowindow to catch drag input |
| 6028 | final boolean inDrag = (mDragState != null); |
| 6029 | if (inDrag) { |
| 6030 | if (DEBUG_DRAG) { |
| 6031 | Log.d(TAG, "Inserting drag window"); |
| 6032 | } |
| Chris Tate | a32dcf7 | 2010-10-14 12:13:50 -0700 | [diff] [blame] | 6033 | addDragInputWindowLw(mTempInputWindows); |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 6034 | } |
| 6035 | |
| Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 6036 | final int N = windows.size(); |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 6037 | for (int i = N - 1; i >= 0; i--) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 6038 | final WindowState child = windows.get(i); |
| Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 6039 | if (child.mInputChannel == null || child.mRemoved) { |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 6040 | // Skip this window because it cannot possibly receive input. |
| Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 6041 | continue; |
| 6042 | } |
| 6043 | |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 6044 | final int flags = child.mAttrs.flags; |
| 6045 | final int type = child.mAttrs.type; |
| 6046 | |
| 6047 | final boolean hasFocus = (child == mInputFocus); |
| 6048 | final boolean isVisible = child.isVisibleLw(); |
| 6049 | final boolean hasWallpaper = (child == mWallpaperTarget) |
| 6050 | && (type != WindowManager.LayoutParams.TYPE_KEYGUARD); |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 6051 | |
| 6052 | // If there's a drag in progress and 'child' is a potential drop target, |
| 6053 | // make sure it's been told about the drag |
| 6054 | if (inDrag && isVisible) { |
| 6055 | mDragState.sendDragStartedIfNeededLw(child); |
| 6056 | } |
| 6057 | |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 6058 | // Add a window to our list of input windows. |
| 6059 | final InputWindow inputWindow = mTempInputWindows.add(); |
| Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame] | 6060 | inputWindow.inputWindowHandle = child.mInputWindowHandle; |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 6061 | inputWindow.inputChannel = child.mInputChannel; |
| Jeff Brown | 519e024 | 2010-09-15 15:18:56 -0700 | [diff] [blame] | 6062 | inputWindow.name = child.toString(); |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 6063 | inputWindow.layoutParamsFlags = flags; |
| 6064 | inputWindow.layoutParamsType = type; |
| 6065 | inputWindow.dispatchingTimeoutNanos = child.getInputDispatchingTimeoutNanos(); |
| 6066 | inputWindow.visible = isVisible; |
| Jeff Brown | 519e024 | 2010-09-15 15:18:56 -0700 | [diff] [blame] | 6067 | inputWindow.canReceiveKeys = child.canReceiveKeys(); |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 6068 | inputWindow.hasFocus = hasFocus; |
| 6069 | inputWindow.hasWallpaper = hasWallpaper; |
| 6070 | inputWindow.paused = child.mAppToken != null ? child.mAppToken.paused : false; |
| Jeff Brown | 519e024 | 2010-09-15 15:18:56 -0700 | [diff] [blame] | 6071 | inputWindow.layer = child.mLayer; |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 6072 | inputWindow.ownerPid = child.mSession.mPid; |
| 6073 | inputWindow.ownerUid = child.mSession.mUid; |
| 6074 | |
| 6075 | final Rect frame = child.mFrame; |
| 6076 | inputWindow.frameLeft = frame.left; |
| 6077 | inputWindow.frameTop = frame.top; |
| Jeff Brown | 85a3176 | 2010-09-01 17:01:00 -0700 | [diff] [blame] | 6078 | inputWindow.frameRight = frame.right; |
| 6079 | inputWindow.frameBottom = frame.bottom; |
| Jeff Brown | fbf0977 | 2011-01-16 14:06:57 -0800 | [diff] [blame] | 6080 | |
| 6081 | child.getTouchableRegion(inputWindow.touchableRegion); |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 6082 | } |
| Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 6083 | |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 6084 | // Send windows to native code. |
| 6085 | mInputManager.setInputWindows(mTempInputWindows.toNullTerminatedArray()); |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 6086 | |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 6087 | // Clear the list in preparation for the next round. |
| 6088 | // Also avoids keeping InputChannel objects referenced unnecessarily. |
| 6089 | mTempInputWindows.clear(); |
| 6090 | } |
| Jeff Brown | b09abc1 | 2011-01-13 21:08:27 -0800 | [diff] [blame] | 6091 | |
| 6092 | /* Notifies that the input device configuration has changed. */ |
| 6093 | public void notifyConfigurationChanged() { |
| 6094 | sendNewConfiguration(); |
| 6095 | |
| 6096 | synchronized (mInputDevicesReadyMonitor) { |
| 6097 | if (!mInputDevicesReady) { |
| 6098 | mInputDevicesReady = true; |
| 6099 | mInputDevicesReadyMonitor.notifyAll(); |
| 6100 | } |
| 6101 | } |
| 6102 | } |
| 6103 | |
| 6104 | /* Waits until the built-in input devices have been configured. */ |
| 6105 | public boolean waitForInputDevicesReady(long timeoutMillis) { |
| 6106 | synchronized (mInputDevicesReadyMonitor) { |
| 6107 | if (!mInputDevicesReady) { |
| 6108 | try { |
| 6109 | mInputDevicesReadyMonitor.wait(timeoutMillis); |
| 6110 | } catch (InterruptedException ex) { |
| 6111 | } |
| 6112 | } |
| 6113 | return mInputDevicesReady; |
| 6114 | } |
| 6115 | } |
| 6116 | |
| Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 6117 | /* Notifies that the lid switch changed state. */ |
| 6118 | public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen) { |
| 6119 | mPolicy.notifyLidSwitchChanged(whenNanos, lidOpen); |
| 6120 | } |
| 6121 | |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 6122 | /* Provides an opportunity for the window manager policy to intercept early key |
| 6123 | * processing as soon as the key has been read from the device. */ |
| Jeff Brown | 1f24510 | 2010-11-18 20:53:46 -0800 | [diff] [blame] | 6124 | public int interceptKeyBeforeQueueing( |
| 6125 | KeyEvent event, int policyFlags, boolean isScreenOn) { |
| 6126 | return mPolicy.interceptKeyBeforeQueueing(event, policyFlags, isScreenOn); |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 6127 | } |
| 6128 | |
| 6129 | /* Provides an opportunity for the window manager policy to process a key before |
| 6130 | * ordinary dispatch. */ |
| Jeff Brown | 1f24510 | 2010-11-18 20:53:46 -0800 | [diff] [blame] | 6131 | public boolean interceptKeyBeforeDispatching( |
| Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame] | 6132 | InputWindowHandle focus, KeyEvent event, int policyFlags) { |
| Jeff Brown | 00ae87d | 2011-01-13 19:58:24 -0800 | [diff] [blame] | 6133 | WindowState windowState = focus != null ? (WindowState) focus.windowState : null; |
| Jeff Brown | 1f24510 | 2010-11-18 20:53:46 -0800 | [diff] [blame] | 6134 | return mPolicy.interceptKeyBeforeDispatching(windowState, event, policyFlags); |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 6135 | } |
| 6136 | |
| Jeff Brown | 3915bb8 | 2010-11-05 15:02:16 -0700 | [diff] [blame] | 6137 | /* Provides an opportunity for the window manager policy to process a key that |
| 6138 | * the application did not handle. */ |
| Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 6139 | public KeyEvent dispatchUnhandledKey( |
| Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame] | 6140 | InputWindowHandle focus, KeyEvent event, int policyFlags) { |
| Jeff Brown | 00ae87d | 2011-01-13 19:58:24 -0800 | [diff] [blame] | 6141 | WindowState windowState = focus != null ? (WindowState) focus.windowState : null; |
| Jeff Brown | 1f24510 | 2010-11-18 20:53:46 -0800 | [diff] [blame] | 6142 | return mPolicy.dispatchUnhandledKey(windowState, event, policyFlags); |
| Jeff Brown | 3915bb8 | 2010-11-05 15:02:16 -0700 | [diff] [blame] | 6143 | } |
| 6144 | |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 6145 | /* Called when the current input focus changes. |
| 6146 | * Layer assignment is assumed to be complete by the time this is called. |
| 6147 | */ |
| Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 6148 | public void setInputFocusLw(WindowState newWindow, boolean updateInputWindows) { |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 6149 | if (DEBUG_INPUT) { |
| 6150 | Slog.d(TAG, "Input focus has changed to " + newWindow); |
| 6151 | } |
| 6152 | |
| 6153 | if (newWindow != mInputFocus) { |
| 6154 | if (newWindow != null && newWindow.canReceiveKeys()) { |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 6155 | // Displaying a window implicitly causes dispatching to be unpaused. |
| 6156 | // This is to protect against bugs if someone pauses dispatching but |
| 6157 | // forgets to resume. |
| 6158 | newWindow.mToken.paused = false; |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 6159 | } |
| Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 6160 | |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 6161 | mInputFocus = newWindow; |
| Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 6162 | setUpdateInputWindowsNeededLw(); |
| 6163 | |
| 6164 | if (updateInputWindows) { |
| Jeff Brown | 2e44b07 | 2011-01-24 15:21:56 -0800 | [diff] [blame] | 6165 | updateInputWindowsLw(false /*force*/); |
| Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 6166 | } |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 6167 | } |
| 6168 | } |
| 6169 | |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 6170 | public void setFocusedAppLw(AppWindowToken newApp) { |
| 6171 | // Focused app has changed. |
| 6172 | if (newApp == null) { |
| 6173 | mInputManager.setFocusedApplication(null); |
| 6174 | } else { |
| Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame] | 6175 | mTempInputApplication.inputApplicationHandle = newApp.mInputApplicationHandle; |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 6176 | mTempInputApplication.name = newApp.toString(); |
| 6177 | mTempInputApplication.dispatchingTimeoutNanos = |
| 6178 | newApp.inputDispatchingTimeoutNanos; |
| Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame] | 6179 | |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 6180 | mInputManager.setFocusedApplication(mTempInputApplication); |
| Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame] | 6181 | |
| 6182 | mTempInputApplication.recycle(); |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 6183 | } |
| 6184 | } |
| 6185 | |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 6186 | public void pauseDispatchingLw(WindowToken window) { |
| 6187 | if (! window.paused) { |
| 6188 | if (DEBUG_INPUT) { |
| 6189 | Slog.v(TAG, "Pausing WindowToken " + window); |
| 6190 | } |
| 6191 | |
| 6192 | window.paused = true; |
| Jeff Brown | 2e44b07 | 2011-01-24 15:21:56 -0800 | [diff] [blame] | 6193 | updateInputWindowsLw(true /*force*/); |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 6194 | } |
| 6195 | } |
| 6196 | |
| 6197 | public void resumeDispatchingLw(WindowToken window) { |
| 6198 | if (window.paused) { |
| 6199 | if (DEBUG_INPUT) { |
| 6200 | Slog.v(TAG, "Resuming WindowToken " + window); |
| 6201 | } |
| 6202 | |
| 6203 | window.paused = false; |
| Jeff Brown | 2e44b07 | 2011-01-24 15:21:56 -0800 | [diff] [blame] | 6204 | updateInputWindowsLw(true /*force*/); |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 6205 | } |
| 6206 | } |
| 6207 | |
| 6208 | public void freezeInputDispatchingLw() { |
| 6209 | if (! mInputDispatchFrozen) { |
| 6210 | if (DEBUG_INPUT) { |
| 6211 | Slog.v(TAG, "Freezing input dispatching"); |
| 6212 | } |
| 6213 | |
| 6214 | mInputDispatchFrozen = true; |
| 6215 | updateInputDispatchModeLw(); |
| 6216 | } |
| 6217 | } |
| 6218 | |
| 6219 | public void thawInputDispatchingLw() { |
| 6220 | if (mInputDispatchFrozen) { |
| 6221 | if (DEBUG_INPUT) { |
| 6222 | Slog.v(TAG, "Thawing input dispatching"); |
| 6223 | } |
| 6224 | |
| 6225 | mInputDispatchFrozen = false; |
| 6226 | updateInputDispatchModeLw(); |
| 6227 | } |
| 6228 | } |
| 6229 | |
| 6230 | public void setEventDispatchingLw(boolean enabled) { |
| 6231 | if (mInputDispatchEnabled != enabled) { |
| 6232 | if (DEBUG_INPUT) { |
| 6233 | Slog.v(TAG, "Setting event dispatching to " + enabled); |
| 6234 | } |
| 6235 | |
| 6236 | mInputDispatchEnabled = enabled; |
| 6237 | updateInputDispatchModeLw(); |
| 6238 | } |
| 6239 | } |
| 6240 | |
| 6241 | private void updateInputDispatchModeLw() { |
| 6242 | mInputManager.setInputDispatchMode(mInputDispatchEnabled, mInputDispatchFrozen); |
| 6243 | } |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 6244 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6245 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6246 | public void pauseKeyDispatching(IBinder _token) { |
| 6247 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 6248 | "pauseKeyDispatching()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 6249 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6250 | } |
| 6251 | |
| 6252 | synchronized (mWindowMap) { |
| 6253 | WindowToken token = mTokenMap.get(_token); |
| 6254 | if (token != null) { |
| Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 6255 | mInputMonitor.pauseDispatchingLw(token); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6256 | } |
| 6257 | } |
| 6258 | } |
| 6259 | |
| 6260 | public void resumeKeyDispatching(IBinder _token) { |
| 6261 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 6262 | "resumeKeyDispatching()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 6263 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6264 | } |
| 6265 | |
| 6266 | synchronized (mWindowMap) { |
| 6267 | WindowToken token = mTokenMap.get(_token); |
| 6268 | if (token != null) { |
| Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 6269 | mInputMonitor.resumeDispatchingLw(token); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6270 | } |
| 6271 | } |
| 6272 | } |
| 6273 | |
| 6274 | public void setEventDispatching(boolean enabled) { |
| 6275 | if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS, |
| 6276 | "resumeKeyDispatching()")) { |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 6277 | throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6278 | } |
| 6279 | |
| 6280 | synchronized (mWindowMap) { |
| Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 6281 | mInputMonitor.setEventDispatchingLw(enabled); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6282 | } |
| 6283 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6284 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6285 | /** |
| 6286 | * Injects a keystroke event into the UI. |
| Jeff Brown | bbda99d | 2010-07-28 15:48:59 -0700 | [diff] [blame] | 6287 | * Even when sync is false, this method may block while waiting for current |
| 6288 | * input events to be dispatched. |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6289 | * |
| 6290 | * @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] | 6291 | * {@link SystemClock#uptimeMillis()} as the timebase.) |
| 6292 | * @param sync If true, wait for the event to be completed before returning to the caller. |
| 6293 | * @return Returns true if event was dispatched, false if it was dropped for any reason |
| 6294 | */ |
| 6295 | public boolean injectKeyEvent(KeyEvent ev, boolean sync) { |
| 6296 | long downTime = ev.getDownTime(); |
| 6297 | long eventTime = ev.getEventTime(); |
| 6298 | |
| 6299 | int action = ev.getAction(); |
| 6300 | int code = ev.getKeyCode(); |
| 6301 | int repeatCount = ev.getRepeatCount(); |
| 6302 | int metaState = ev.getMetaState(); |
| 6303 | int deviceId = ev.getDeviceId(); |
| 6304 | int scancode = ev.getScanCode(); |
| Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 6305 | int source = ev.getSource(); |
| Mike Playle | c6ded10 | 2010-11-29 16:01:03 +0000 | [diff] [blame] | 6306 | int flags = ev.getFlags(); |
| Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 6307 | |
| 6308 | if (source == InputDevice.SOURCE_UNKNOWN) { |
| 6309 | source = InputDevice.SOURCE_KEYBOARD; |
| 6310 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6311 | |
| 6312 | if (eventTime == 0) eventTime = SystemClock.uptimeMillis(); |
| 6313 | if (downTime == 0) downTime = eventTime; |
| 6314 | |
| 6315 | KeyEvent newEvent = new KeyEvent(downTime, eventTime, action, code, repeatCount, metaState, |
| Jean-Baptiste Queru | 4a88013 | 2010-12-02 15:16:53 -0800 | [diff] [blame] | 6316 | deviceId, scancode, flags | KeyEvent.FLAG_FROM_SYSTEM, source); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6317 | |
| Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 6318 | final int pid = Binder.getCallingPid(); |
| 6319 | final int uid = Binder.getCallingUid(); |
| 6320 | final long ident = Binder.clearCallingIdentity(); |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 6321 | |
| Jeff Brown | bbda99d | 2010-07-28 15:48:59 -0700 | [diff] [blame] | 6322 | final int result = mInputManager.injectInputEvent(newEvent, pid, uid, |
| 6323 | sync ? InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH |
| 6324 | : InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT, |
| 6325 | INJECTION_TIMEOUT_MILLIS); |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 6326 | |
| Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 6327 | Binder.restoreCallingIdentity(ident); |
| Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 6328 | return reportInjectionResult(result); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6329 | } |
| 6330 | |
| 6331 | /** |
| 6332 | * Inject a pointer (touch) event into the UI. |
| Jeff Brown | bbda99d | 2010-07-28 15:48:59 -0700 | [diff] [blame] | 6333 | * Even when sync is false, this method may block while waiting for current |
| 6334 | * input events to be dispatched. |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6335 | * |
| 6336 | * @param ev A motion event describing the pointer (touch) action. (As noted in |
| 6337 | * {@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] | 6338 | * {@link SystemClock#uptimeMillis()} as the timebase.) |
| 6339 | * @param sync If true, wait for the event to be completed before returning to the caller. |
| 6340 | * @return Returns true if event was dispatched, false if it was dropped for any reason |
| 6341 | */ |
| 6342 | public boolean injectPointerEvent(MotionEvent ev, boolean sync) { |
| Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 6343 | final int pid = Binder.getCallingPid(); |
| 6344 | final int uid = Binder.getCallingUid(); |
| 6345 | final long ident = Binder.clearCallingIdentity(); |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 6346 | |
| Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 6347 | MotionEvent newEvent = MotionEvent.obtain(ev); |
| 6348 | if ((newEvent.getSource() & InputDevice.SOURCE_CLASS_POINTER) == 0) { |
| 6349 | newEvent.setSource(InputDevice.SOURCE_TOUCHSCREEN); |
| 6350 | } |
| 6351 | |
| Jeff Brown | bbda99d | 2010-07-28 15:48:59 -0700 | [diff] [blame] | 6352 | final int result = mInputManager.injectInputEvent(newEvent, pid, uid, |
| 6353 | sync ? InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH |
| 6354 | : InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT, |
| 6355 | INJECTION_TIMEOUT_MILLIS); |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 6356 | |
| Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 6357 | Binder.restoreCallingIdentity(ident); |
| Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 6358 | return reportInjectionResult(result); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6359 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6360 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6361 | /** |
| 6362 | * Inject a trackball (navigation device) event into the UI. |
| Jeff Brown | bbda99d | 2010-07-28 15:48:59 -0700 | [diff] [blame] | 6363 | * Even when sync is false, this method may block while waiting for current |
| 6364 | * input events to be dispatched. |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6365 | * |
| 6366 | * @param ev A motion event describing the trackball action. (As noted in |
| 6367 | * {@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] | 6368 | * {@link SystemClock#uptimeMillis()} as the timebase.) |
| 6369 | * @param sync If true, wait for the event to be completed before returning to the caller. |
| 6370 | * @return Returns true if event was dispatched, false if it was dropped for any reason |
| 6371 | */ |
| 6372 | public boolean injectTrackballEvent(MotionEvent ev, boolean sync) { |
| Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 6373 | final int pid = Binder.getCallingPid(); |
| 6374 | final int uid = Binder.getCallingUid(); |
| 6375 | final long ident = Binder.clearCallingIdentity(); |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 6376 | |
| Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 6377 | MotionEvent newEvent = MotionEvent.obtain(ev); |
| 6378 | if ((newEvent.getSource() & InputDevice.SOURCE_CLASS_TRACKBALL) == 0) { |
| 6379 | newEvent.setSource(InputDevice.SOURCE_TRACKBALL); |
| 6380 | } |
| 6381 | |
| Jeff Brown | bbda99d | 2010-07-28 15:48:59 -0700 | [diff] [blame] | 6382 | final int result = mInputManager.injectInputEvent(newEvent, pid, uid, |
| 6383 | sync ? InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH |
| 6384 | : InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT, |
| 6385 | INJECTION_TIMEOUT_MILLIS); |
| 6386 | |
| 6387 | Binder.restoreCallingIdentity(ident); |
| 6388 | return reportInjectionResult(result); |
| 6389 | } |
| 6390 | |
| 6391 | /** |
| 6392 | * Inject an input event into the UI without waiting for dispatch to commence. |
| 6393 | * This variant is useful for fire-and-forget input event injection. It does not |
| 6394 | * block any longer than it takes to enqueue the input event. |
| 6395 | * |
| 6396 | * @param ev An input event. (Be sure to set the input source correctly.) |
| 6397 | * @return Returns true if event was dispatched, false if it was dropped for any reason |
| 6398 | */ |
| 6399 | public boolean injectInputEventNoWait(InputEvent ev) { |
| 6400 | final int pid = Binder.getCallingPid(); |
| 6401 | final int uid = Binder.getCallingUid(); |
| 6402 | final long ident = Binder.clearCallingIdentity(); |
| 6403 | |
| 6404 | final int result = mInputManager.injectInputEvent(ev, pid, uid, |
| 6405 | InputManager.INPUT_EVENT_INJECTION_SYNC_NONE, |
| 6406 | INJECTION_TIMEOUT_MILLIS); |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 6407 | |
| Dianne Hackborn | 2bd33d7 | 2009-06-26 18:59:01 -0700 | [diff] [blame] | 6408 | Binder.restoreCallingIdentity(ident); |
| Jeff Brown | 7fbdc84 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 6409 | return reportInjectionResult(result); |
| 6410 | } |
| 6411 | |
| 6412 | private boolean reportInjectionResult(int result) { |
| Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 6413 | switch (result) { |
| 6414 | case InputManager.INPUT_EVENT_INJECTION_PERMISSION_DENIED: |
| 6415 | Slog.w(TAG, "Input event injection permission denied."); |
| 6416 | throw new SecurityException( |
| 6417 | "Injecting to another application requires INJECT_EVENTS permission"); |
| 6418 | case InputManager.INPUT_EVENT_INJECTION_SUCCEEDED: |
| Christopher Tate | 09e85dc | 2010-08-02 11:54:41 -0700 | [diff] [blame] | 6419 | //Slog.v(TAG, "Input event injection succeeded."); |
| Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 6420 | return true; |
| 6421 | case InputManager.INPUT_EVENT_INJECTION_TIMED_OUT: |
| 6422 | Slog.w(TAG, "Input event injection timed out."); |
| 6423 | return false; |
| 6424 | case InputManager.INPUT_EVENT_INJECTION_FAILED: |
| 6425 | default: |
| 6426 | Slog.w(TAG, "Input event injection failed."); |
| 6427 | return false; |
| Dianne Hackborn | cfaef69 | 2009-06-15 14:24:44 -0700 | [diff] [blame] | 6428 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 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 | private WindowState getFocusedWindow() { |
| 6432 | synchronized (mWindowMap) { |
| 6433 | return getFocusedWindowLocked(); |
| 6434 | } |
| 6435 | } |
| 6436 | |
| 6437 | private WindowState getFocusedWindowLocked() { |
| 6438 | return mCurrentFocus; |
| 6439 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6440 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6441 | public boolean detectSafeMode() { |
| Jeff Brown | b09abc1 | 2011-01-13 21:08:27 -0800 | [diff] [blame] | 6442 | if (!mInputMonitor.waitForInputDevicesReady( |
| 6443 | INPUT_DEVICES_READY_FOR_SAFE_MODE_DETECTION_TIMEOUT_MILLIS)) { |
| 6444 | Slog.w(TAG, "Devices still not ready after waiting " |
| 6445 | + INPUT_DEVICES_READY_FOR_SAFE_MODE_DETECTION_TIMEOUT_MILLIS |
| 6446 | + " milliseconds before attempting to detect safe mode."); |
| 6447 | } |
| 6448 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6449 | mSafeMode = mPolicy.detectSafeMode(); |
| 6450 | return mSafeMode; |
| 6451 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6452 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6453 | public void systemReady() { |
| Dianne Hackborn | 5132b37 | 2010-07-29 12:51:35 -0700 | [diff] [blame] | 6454 | synchronized(mWindowMap) { |
| 6455 | if (mDisplay != null) { |
| 6456 | throw new IllegalStateException("Display already initialized"); |
| 6457 | } |
| 6458 | WindowManager wm = (WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE); |
| 6459 | mDisplay = wm.getDefaultDisplay(); |
| 6460 | mInitialDisplayWidth = mDisplay.getWidth(); |
| 6461 | mInitialDisplayHeight = mDisplay.getHeight(); |
| Dianne Hackborn | 4c7cc34 | 2010-12-16 16:37:39 -0800 | [diff] [blame] | 6462 | mInputManager.setDisplaySize(0, Display.unmapDisplaySize(mInitialDisplayWidth), |
| 6463 | Display.unmapDisplaySize(mInitialDisplayHeight)); |
| Dianne Hackborn | 5132b37 | 2010-07-29 12:51:35 -0700 | [diff] [blame] | 6464 | } |
| 6465 | |
| 6466 | try { |
| 6467 | mActivityManager.updateConfiguration(null); |
| 6468 | } catch (RemoteException e) { |
| 6469 | } |
| Dianne Hackborn | 154db5f | 2010-07-29 19:15:19 -0700 | [diff] [blame] | 6470 | |
| 6471 | mPolicy.systemReady(); |
| Dianne Hackborn | 5132b37 | 2010-07-29 12:51:35 -0700 | [diff] [blame] | 6472 | } |
| 6473 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6474 | // ------------------------------------------------------------- |
| 6475 | // Client Session State |
| 6476 | // ------------------------------------------------------------- |
| 6477 | |
| 6478 | private final class Session extends IWindowSession.Stub |
| 6479 | implements IBinder.DeathRecipient { |
| 6480 | final IInputMethodClient mClient; |
| 6481 | final IInputContext mInputContext; |
| 6482 | final int mUid; |
| 6483 | final int mPid; |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 6484 | final String mStringName; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6485 | SurfaceSession mSurfaceSession; |
| 6486 | int mNumWindow = 0; |
| 6487 | boolean mClientDead = false; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6488 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6489 | public Session(IInputMethodClient client, IInputContext inputContext) { |
| 6490 | mClient = client; |
| 6491 | mInputContext = inputContext; |
| 6492 | mUid = Binder.getCallingUid(); |
| 6493 | mPid = Binder.getCallingPid(); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 6494 | StringBuilder sb = new StringBuilder(); |
| 6495 | sb.append("Session{"); |
| 6496 | sb.append(Integer.toHexString(System.identityHashCode(this))); |
| 6497 | sb.append(" uid "); |
| 6498 | sb.append(mUid); |
| 6499 | sb.append("}"); |
| 6500 | mStringName = sb.toString(); |
| 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 | synchronized (mWindowMap) { |
| 6503 | if (mInputMethodManager == null && mHaveInputMethods) { |
| 6504 | IBinder b = ServiceManager.getService( |
| 6505 | Context.INPUT_METHOD_SERVICE); |
| 6506 | mInputMethodManager = IInputMethodManager.Stub.asInterface(b); |
| 6507 | } |
| 6508 | } |
| 6509 | long ident = Binder.clearCallingIdentity(); |
| 6510 | try { |
| 6511 | // Note: it is safe to call in to the input method manager |
| 6512 | // here because we are not holding our lock. |
| 6513 | if (mInputMethodManager != null) { |
| 6514 | mInputMethodManager.addClient(client, inputContext, |
| 6515 | mUid, mPid); |
| 6516 | } else { |
| 6517 | client.setUsingInputMethod(false); |
| 6518 | } |
| 6519 | client.asBinder().linkToDeath(this, 0); |
| 6520 | } catch (RemoteException e) { |
| 6521 | // The caller has died, so we can just forget about this. |
| 6522 | try { |
| 6523 | if (mInputMethodManager != null) { |
| 6524 | mInputMethodManager.removeClient(client); |
| 6525 | } |
| 6526 | } catch (RemoteException ee) { |
| 6527 | } |
| 6528 | } finally { |
| 6529 | Binder.restoreCallingIdentity(ident); |
| 6530 | } |
| 6531 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6532 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6533 | @Override |
| 6534 | public boolean onTransact(int code, Parcel data, Parcel reply, int flags) |
| 6535 | throws RemoteException { |
| 6536 | try { |
| 6537 | return super.onTransact(code, data, reply, flags); |
| 6538 | } catch (RuntimeException e) { |
| 6539 | // Log all 'real' exceptions thrown to the caller |
| 6540 | if (!(e instanceof SecurityException)) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6541 | Slog.e(TAG, "Window Session Crash", e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6542 | } |
| 6543 | throw e; |
| 6544 | } |
| 6545 | } |
| 6546 | |
| 6547 | public void binderDied() { |
| 6548 | // Note: it is safe to call in to the input method manager |
| 6549 | // here because we are not holding our lock. |
| 6550 | try { |
| 6551 | if (mInputMethodManager != null) { |
| 6552 | mInputMethodManager.removeClient(mClient); |
| 6553 | } |
| 6554 | } catch (RemoteException e) { |
| 6555 | } |
| 6556 | synchronized(mWindowMap) { |
| Suchi Amalapurapu | fff2fda | 2009-06-30 21:36:16 -0700 | [diff] [blame] | 6557 | mClient.asBinder().unlinkToDeath(this, 0); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6558 | mClientDead = true; |
| 6559 | killSessionLocked(); |
| 6560 | } |
| 6561 | } |
| 6562 | |
| 6563 | public int add(IWindow window, WindowManager.LayoutParams attrs, |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 6564 | int viewVisibility, Rect outContentInsets, InputChannel outInputChannel) { |
| 6565 | return addWindow(this, window, attrs, viewVisibility, outContentInsets, |
| 6566 | outInputChannel); |
| 6567 | } |
| 6568 | |
| 6569 | public int addWithoutInputChannel(IWindow window, WindowManager.LayoutParams attrs, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6570 | int viewVisibility, Rect outContentInsets) { |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 6571 | return addWindow(this, window, attrs, viewVisibility, outContentInsets, null); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6572 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6573 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6574 | public void remove(IWindow window) { |
| 6575 | removeWindow(this, window); |
| 6576 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6577 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6578 | public int relayout(IWindow window, WindowManager.LayoutParams attrs, |
| 6579 | int requestedWidth, int requestedHeight, int viewFlags, |
| 6580 | boolean insetsPending, Rect outFrame, Rect outContentInsets, |
| Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 6581 | Rect outVisibleInsets, Configuration outConfig, Surface outSurface) { |
| Dianne Hackborn | f123e49 | 2010-09-24 11:16:23 -0700 | [diff] [blame] | 6582 | //Log.d(TAG, ">>>>>> ENTERED relayout from " + Binder.getCallingPid()); |
| 6583 | int res = relayoutWindow(this, window, attrs, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6584 | requestedWidth, requestedHeight, viewFlags, insetsPending, |
| Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 6585 | outFrame, outContentInsets, outVisibleInsets, outConfig, outSurface); |
| Dianne Hackborn | f123e49 | 2010-09-24 11:16:23 -0700 | [diff] [blame] | 6586 | //Log.d(TAG, "<<<<<< EXITING relayout to " + Binder.getCallingPid()); |
| 6587 | return res; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6588 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6589 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6590 | public void setTransparentRegion(IWindow window, Region region) { |
| 6591 | setTransparentRegionWindow(this, window, region); |
| 6592 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6593 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6594 | public void setInsets(IWindow window, int touchableInsets, |
| Jeff Brown | fbf0977 | 2011-01-16 14:06:57 -0800 | [diff] [blame] | 6595 | Rect contentInsets, Rect visibleInsets, Region touchableArea) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6596 | setInsetsWindow(this, window, touchableInsets, contentInsets, |
| Jeff Brown | fbf0977 | 2011-01-16 14:06:57 -0800 | [diff] [blame] | 6597 | visibleInsets, touchableArea); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6598 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6599 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6600 | public void getDisplayFrame(IWindow window, Rect outDisplayFrame) { |
| 6601 | getWindowDisplayFrame(this, window, outDisplayFrame); |
| 6602 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6603 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6604 | public void finishDrawing(IWindow window) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6605 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6606 | TAG, "IWindow finishDrawing called for " + window); |
| 6607 | finishDrawingWindow(this, window); |
| 6608 | } |
| 6609 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6610 | public void setInTouchMode(boolean mode) { |
| 6611 | synchronized(mWindowMap) { |
| 6612 | mInTouchMode = mode; |
| 6613 | } |
| 6614 | } |
| 6615 | |
| 6616 | public boolean getInTouchMode() { |
| 6617 | synchronized(mWindowMap) { |
| 6618 | return mInTouchMode; |
| 6619 | } |
| 6620 | } |
| 6621 | |
| 6622 | public boolean performHapticFeedback(IWindow window, int effectId, |
| 6623 | boolean always) { |
| 6624 | synchronized(mWindowMap) { |
| 6625 | long ident = Binder.clearCallingIdentity(); |
| 6626 | try { |
| The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 6627 | return mPolicy.performHapticFeedbackLw( |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 6628 | windowForClientLocked(this, window, true), |
| 6629 | effectId, always); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6630 | } finally { |
| 6631 | Binder.restoreCallingIdentity(ident); |
| 6632 | } |
| 6633 | } |
| 6634 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6635 | |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 6636 | /* Drag/drop */ |
| Christopher Tate | 02d2b3b | 2011-01-10 20:43:53 -0800 | [diff] [blame] | 6637 | public IBinder prepareDrag(IWindow window, int flags, |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 6638 | int width, int height, Surface outSurface) { |
| Christopher Tate | 02d2b3b | 2011-01-10 20:43:53 -0800 | [diff] [blame] | 6639 | return prepareDragSurface(window, mSurfaceSession, flags, |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 6640 | width, height, outSurface); |
| 6641 | } |
| 6642 | |
| 6643 | public boolean performDrag(IWindow window, IBinder dragToken, |
| 6644 | float touchX, float touchY, float thumbCenterX, float thumbCenterY, |
| 6645 | ClipData data) { |
| 6646 | if (DEBUG_DRAG) { |
| 6647 | Slog.d(TAG, "perform drag: win=" + window + " data=" + data); |
| 6648 | } |
| 6649 | |
| 6650 | synchronized (mWindowMap) { |
| 6651 | if (mDragState == null) { |
| 6652 | Slog.w(TAG, "No drag prepared"); |
| 6653 | throw new IllegalStateException("performDrag() without prepareDrag()"); |
| 6654 | } |
| 6655 | |
| 6656 | if (dragToken != mDragState.mToken) { |
| 6657 | Slog.w(TAG, "Performing mismatched drag"); |
| 6658 | throw new IllegalStateException("performDrag() does not match prepareDrag()"); |
| 6659 | } |
| 6660 | |
| 6661 | WindowState callingWin = windowForClientLocked(null, window, false); |
| 6662 | if (callingWin == null) { |
| 6663 | Slog.w(TAG, "Bad requesting window " + window); |
| 6664 | return false; // !!! TODO: throw here? |
| 6665 | } |
| 6666 | |
| 6667 | // !!! TODO: if input is not still focused on the initiating window, fail |
| 6668 | // the drag initiation (e.g. an alarm window popped up just as the application |
| 6669 | // called performDrag() |
| 6670 | |
| 6671 | mH.removeMessages(H.DRAG_START_TIMEOUT, window.asBinder()); |
| 6672 | |
| Christopher Tate | 2c095f3 | 2010-10-04 14:13:40 -0700 | [diff] [blame] | 6673 | // !!! TODO: extract the current touch (x, y) in screen coordinates. That |
| 6674 | // will let us eliminate the (touchX,touchY) parameters from the API. |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 6675 | |
| Chris Tate | b478f46 | 2010-10-15 16:02:26 -0700 | [diff] [blame] | 6676 | // !!! FIXME: put all this heavy stuff onto the mH looper, as well as |
| 6677 | // the actual drag event dispatch stuff in the dragstate |
| 6678 | |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 6679 | mDragState.register(); |
| Jeff Brown | 2e44b07 | 2011-01-24 15:21:56 -0800 | [diff] [blame] | 6680 | mInputMonitor.updateInputWindowsLw(true /*force*/); |
| Chris Tate | ef70a07 | 2010-10-22 19:10:34 -0700 | [diff] [blame] | 6681 | if (!mInputManager.transferTouchFocus(callingWin.mInputChannel, |
| 6682 | mDragState.mServerChannel)) { |
| 6683 | Slog.e(TAG, "Unable to transfer touch focus"); |
| 6684 | mDragState.unregister(); |
| 6685 | mDragState = null; |
| Jeff Brown | 2e44b07 | 2011-01-24 15:21:56 -0800 | [diff] [blame] | 6686 | mInputMonitor.updateInputWindowsLw(true /*force*/); |
| Chris Tate | ef70a07 | 2010-10-22 19:10:34 -0700 | [diff] [blame] | 6687 | return false; |
| 6688 | } |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 6689 | |
| 6690 | mDragState.mData = data; |
| Chris Tate | b478f46 | 2010-10-15 16:02:26 -0700 | [diff] [blame] | 6691 | mDragState.mCurrentX = touchX; |
| 6692 | mDragState.mCurrentY = touchY; |
| Chris Tate | b8203e9 | 2010-10-12 14:23:21 -0700 | [diff] [blame] | 6693 | mDragState.broadcastDragStartedLw(touchX, touchY); |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 6694 | |
| 6695 | // remember the thumb offsets for later |
| 6696 | mDragState.mThumbOffsetX = thumbCenterX; |
| 6697 | mDragState.mThumbOffsetY = thumbCenterY; |
| 6698 | |
| 6699 | // Make the surface visible at the proper location |
| 6700 | final Surface surface = mDragState.mSurface; |
| Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 6701 | if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION performDrag"); |
| Chris Tate | b478f46 | 2010-10-15 16:02:26 -0700 | [diff] [blame] | 6702 | Surface.openTransaction(); |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 6703 | try { |
| 6704 | surface.setPosition((int)(touchX - thumbCenterX), |
| 6705 | (int)(touchY - thumbCenterY)); |
| Chris Tate | b478f46 | 2010-10-15 16:02:26 -0700 | [diff] [blame] | 6706 | surface.setAlpha(.7071f); |
| Chris Tate | a32dcf7 | 2010-10-14 12:13:50 -0700 | [diff] [blame] | 6707 | surface.setLayer(mDragState.getDragLayerLw()); |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 6708 | surface.show(); |
| 6709 | } finally { |
| Chris Tate | b478f46 | 2010-10-15 16:02:26 -0700 | [diff] [blame] | 6710 | Surface.closeTransaction(); |
| Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 6711 | if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION performDrag"); |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 6712 | } |
| 6713 | } |
| 6714 | |
| 6715 | return true; // success! |
| 6716 | } |
| 6717 | |
| Chris Tate | d4533f14 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 6718 | public void reportDropResult(IWindow window, boolean consumed) { |
| 6719 | IBinder token = window.asBinder(); |
| 6720 | if (DEBUG_DRAG) { |
| 6721 | Slog.d(TAG, "Drop result=" + consumed + " reported by " + token); |
| 6722 | } |
| 6723 | |
| 6724 | synchronized (mWindowMap) { |
| Christopher Tate | ccd24de | 2011-01-12 15:02:55 -0800 | [diff] [blame] | 6725 | long ident = Binder.clearCallingIdentity(); |
| 6726 | try { |
| Jeff Brown | fbf0977 | 2011-01-16 14:06:57 -0800 | [diff] [blame] | 6727 | if (mDragState == null || mDragState.mToken != token) { |
| Christopher Tate | ccd24de | 2011-01-12 15:02:55 -0800 | [diff] [blame] | 6728 | Slog.w(TAG, "Invalid drop-result claim by " + window); |
| 6729 | throw new IllegalStateException("reportDropResult() by non-recipient"); |
| 6730 | } |
| 6731 | |
| 6732 | // The right window has responded, even if it's no longer around, |
| 6733 | // so be sure to halt the timeout even if the later WindowState |
| 6734 | // lookup fails. |
| 6735 | mH.removeMessages(H.DRAG_END_TIMEOUT, window.asBinder()); |
| 6736 | WindowState callingWin = windowForClientLocked(null, window, false); |
| 6737 | if (callingWin == null) { |
| 6738 | Slog.w(TAG, "Bad result-reporting window " + window); |
| 6739 | return; // !!! TODO: throw here? |
| 6740 | } |
| 6741 | |
| 6742 | mDragState.mDragResult = consumed; |
| 6743 | mDragState.endDragLw(); |
| 6744 | } finally { |
| 6745 | Binder.restoreCallingIdentity(ident); |
| Chris Tate | d4533f14 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 6746 | } |
| Chris Tate | d4533f14 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 6747 | } |
| 6748 | } |
| 6749 | |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 6750 | public void dragRecipientEntered(IWindow window) { |
| 6751 | if (DEBUG_DRAG) { |
| Chris Tate | d4533f14 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 6752 | Slog.d(TAG, "Drag into new candidate view @ " + window.asBinder()); |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 6753 | } |
| 6754 | } |
| 6755 | |
| 6756 | public void dragRecipientExited(IWindow window) { |
| 6757 | if (DEBUG_DRAG) { |
| Chris Tate | d4533f14 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 6758 | Slog.d(TAG, "Drag from old candidate view @ " + window.asBinder()); |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 6759 | } |
| 6760 | } |
| 6761 | |
| Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 6762 | 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] | 6763 | synchronized(mWindowMap) { |
| 6764 | long ident = Binder.clearCallingIdentity(); |
| 6765 | try { |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 6766 | setWindowWallpaperPositionLocked( |
| 6767 | windowForClientLocked(this, window, true), |
| Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 6768 | x, y, xStep, yStep); |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 6769 | } finally { |
| 6770 | Binder.restoreCallingIdentity(ident); |
| 6771 | } |
| 6772 | } |
| 6773 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6774 | |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 6775 | public void wallpaperOffsetsComplete(IBinder window) { |
| 6776 | WindowManagerService.this.wallpaperOffsetsComplete(window); |
| 6777 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6778 | |
| Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 6779 | public Bundle sendWallpaperCommand(IBinder window, String action, int x, int y, |
| 6780 | int z, Bundle extras, boolean sync) { |
| 6781 | synchronized(mWindowMap) { |
| 6782 | long ident = Binder.clearCallingIdentity(); |
| 6783 | try { |
| 6784 | return sendWindowWallpaperCommandLocked( |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 6785 | windowForClientLocked(this, window, true), |
| Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 6786 | action, x, y, z, extras, sync); |
| 6787 | } finally { |
| 6788 | Binder.restoreCallingIdentity(ident); |
| 6789 | } |
| 6790 | } |
| 6791 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6792 | |
| Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 6793 | public void wallpaperCommandComplete(IBinder window, Bundle result) { |
| 6794 | WindowManagerService.this.wallpaperCommandComplete(window, result); |
| 6795 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6796 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6797 | void windowAddedLocked() { |
| 6798 | if (mSurfaceSession == null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6799 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6800 | TAG, "First window added to " + this + ", creating SurfaceSession"); |
| 6801 | mSurfaceSession = new SurfaceSession(); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6802 | if (SHOW_TRANSACTIONS) Slog.i( |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 6803 | TAG, " NEW SURFACE SESSION " + mSurfaceSession); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6804 | mSessions.add(this); |
| 6805 | } |
| 6806 | mNumWindow++; |
| 6807 | } |
| 6808 | |
| 6809 | void windowRemovedLocked() { |
| 6810 | mNumWindow--; |
| 6811 | killSessionLocked(); |
| 6812 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6813 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6814 | void killSessionLocked() { |
| 6815 | if (mNumWindow <= 0 && mClientDead) { |
| 6816 | mSessions.remove(this); |
| 6817 | if (mSurfaceSession != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6818 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6819 | TAG, "Last window removed from " + this |
| 6820 | + ", destroying " + mSurfaceSession); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6821 | if (SHOW_TRANSACTIONS) Slog.i( |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 6822 | TAG, " KILL SURFACE SESSION " + mSurfaceSession); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6823 | try { |
| 6824 | mSurfaceSession.kill(); |
| 6825 | } catch (Exception e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 6826 | Slog.w(TAG, "Exception thrown when killing surface session " |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6827 | + mSurfaceSession + " in session " + this |
| 6828 | + ": " + e.toString()); |
| 6829 | } |
| 6830 | mSurfaceSession = null; |
| 6831 | } |
| 6832 | } |
| 6833 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6834 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6835 | void dump(PrintWriter pw, String prefix) { |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 6836 | pw.print(prefix); pw.print("mNumWindow="); pw.print(mNumWindow); |
| 6837 | pw.print(" mClientDead="); pw.print(mClientDead); |
| 6838 | pw.print(" mSurfaceSession="); pw.println(mSurfaceSession); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6839 | } |
| 6840 | |
| 6841 | @Override |
| 6842 | public String toString() { |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 6843 | return mStringName; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6844 | } |
| 6845 | } |
| 6846 | |
| 6847 | // ------------------------------------------------------------- |
| 6848 | // Client Window State |
| 6849 | // ------------------------------------------------------------- |
| 6850 | |
| 6851 | private final class WindowState implements WindowManagerPolicy.WindowState { |
| 6852 | final Session mSession; |
| 6853 | final IWindow mClient; |
| 6854 | WindowToken mToken; |
| The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 6855 | WindowToken mRootToken; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6856 | AppWindowToken mAppToken; |
| 6857 | AppWindowToken mTargetAppToken; |
| 6858 | final WindowManager.LayoutParams mAttrs = new WindowManager.LayoutParams(); |
| 6859 | final DeathRecipient mDeathRecipient; |
| 6860 | final WindowState mAttachedWindow; |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 6861 | final ArrayList<WindowState> mChildWindows = new ArrayList<WindowState>(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6862 | final int mBaseLayer; |
| 6863 | final int mSubLayer; |
| 6864 | final boolean mLayoutAttached; |
| 6865 | final boolean mIsImWindow; |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 6866 | final boolean mIsWallpaper; |
| 6867 | final boolean mIsFloatingLayer; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6868 | int mViewVisibility; |
| 6869 | boolean mPolicyVisibility = true; |
| 6870 | boolean mPolicyVisibilityAfterAnim = true; |
| 6871 | boolean mAppFreezing; |
| 6872 | Surface mSurface; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 6873 | boolean mReportDestroySurface; |
| 6874 | boolean mSurfacePendingDestroy; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6875 | boolean mAttachedHidden; // is our parent window hidden? |
| 6876 | boolean mLastHidden; // was this window last hidden? |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 6877 | boolean mWallpaperVisible; // for wallpaper, what was last vis report? |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6878 | int mRequestedWidth; |
| 6879 | int mRequestedHeight; |
| 6880 | int mLastRequestedWidth; |
| 6881 | int mLastRequestedHeight; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6882 | int mLayer; |
| 6883 | int mAnimLayer; |
| 6884 | int mLastLayer; |
| 6885 | boolean mHaveFrame; |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 6886 | boolean mObscured; |
| Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 6887 | boolean mTurnOnScreen; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6888 | |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 6889 | int mLayoutSeq = -1; |
| 6890 | |
| 6891 | Configuration mConfiguration = null; |
| 6892 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6893 | // Actual frame shown on-screen (may be modified by animation) |
| 6894 | final Rect mShownFrame = new Rect(); |
| 6895 | final Rect mLastShownFrame = new Rect(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6896 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6897 | /** |
| Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 6898 | * Set when we have changed the size of the surface, to know that |
| 6899 | * we must tell them application to resize (and thus redraw itself). |
| 6900 | */ |
| 6901 | boolean mSurfaceResized; |
| 6902 | |
| 6903 | /** |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6904 | * Insets that determine the actually visible area |
| 6905 | */ |
| 6906 | final Rect mVisibleInsets = new Rect(); |
| 6907 | final Rect mLastVisibleInsets = new Rect(); |
| 6908 | boolean mVisibleInsetsChanged; |
| 6909 | |
| 6910 | /** |
| 6911 | * Insets that are covered by system windows |
| 6912 | */ |
| 6913 | final Rect mContentInsets = new Rect(); |
| 6914 | final Rect mLastContentInsets = new Rect(); |
| 6915 | boolean mContentInsetsChanged; |
| 6916 | |
| 6917 | /** |
| 6918 | * Set to true if we are waiting for this window to receive its |
| 6919 | * given internal insets before laying out other windows based on it. |
| 6920 | */ |
| 6921 | boolean mGivenInsetsPending; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6922 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6923 | /** |
| 6924 | * These are the content insets that were given during layout for |
| 6925 | * this window, to be applied to windows behind it. |
| 6926 | */ |
| 6927 | final Rect mGivenContentInsets = new Rect(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6928 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6929 | /** |
| 6930 | * These are the visible insets that were given during layout for |
| 6931 | * this window, to be applied to windows behind it. |
| 6932 | */ |
| 6933 | final Rect mGivenVisibleInsets = new Rect(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6934 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6935 | /** |
| Jeff Brown | fbf0977 | 2011-01-16 14:06:57 -0800 | [diff] [blame] | 6936 | * This is the given touchable area relative to the window frame, or null if none. |
| 6937 | */ |
| 6938 | final Region mGivenTouchableRegion = new Region(); |
| 6939 | |
| 6940 | /** |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6941 | * Flag indicating whether the touchable region should be adjusted by |
| 6942 | * the visible insets; if false the area outside the visible insets is |
| 6943 | * NOT touchable, so we must use those to adjust the frame during hit |
| 6944 | * tests. |
| 6945 | */ |
| 6946 | int mTouchableInsets = ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 6947 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6948 | // Current transformation being applied. |
| Dianne Hackborn | 7da6ac3 | 2010-12-09 19:22:04 -0800 | [diff] [blame] | 6949 | boolean mHaveMatrix; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6950 | float mDsDx=1, mDtDx=0, mDsDy=0, mDtDy=1; |
| 6951 | float mLastDsDx=1, mLastDtDx=0, mLastDsDy=0, mLastDtDy=1; |
| 6952 | float mHScale=1, mVScale=1; |
| 6953 | float mLastHScale=1, mLastVScale=1; |
| 6954 | final Matrix mTmpMatrix = new Matrix(); |
| 6955 | |
| 6956 | // "Real" frame that the application sees. |
| 6957 | final Rect mFrame = new Rect(); |
| 6958 | final Rect mLastFrame = new Rect(); |
| 6959 | |
| 6960 | final Rect mContainingFrame = new Rect(); |
| 6961 | final Rect mDisplayFrame = new Rect(); |
| 6962 | final Rect mContentFrame = new Rect(); |
| Dianne Hackborn | 1c24e95 | 2010-11-23 00:34:30 -0800 | [diff] [blame] | 6963 | final Rect mParentFrame = new Rect(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6964 | final Rect mVisibleFrame = new Rect(); |
| 6965 | |
| Dianne Hackborn | 8e11ef0 | 2010-11-18 19:47:42 -0800 | [diff] [blame] | 6966 | boolean mContentChanged; |
| 6967 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6968 | float mShownAlpha = 1; |
| 6969 | float mAlpha = 1; |
| 6970 | float mLastAlpha = 1; |
| 6971 | |
| 6972 | // Set to true if, when the window gets displayed, it should perform |
| 6973 | // an enter animation. |
| 6974 | boolean mEnterAnimationPending; |
| 6975 | |
| 6976 | // Currently running animation. |
| 6977 | boolean mAnimating; |
| 6978 | boolean mLocalAnimating; |
| 6979 | Animation mAnimation; |
| 6980 | boolean mAnimationIsEntrance; |
| 6981 | boolean mHasTransformation; |
| 6982 | boolean mHasLocalTransformation; |
| 6983 | final Transformation mTransformation = new Transformation(); |
| 6984 | |
| Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 6985 | // If a window showing a wallpaper: the requested offset for the |
| 6986 | // wallpaper; if a wallpaper window: the currently applied offset. |
| 6987 | float mWallpaperX = -1; |
| 6988 | float mWallpaperY = -1; |
| Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 6989 | |
| 6990 | // If a window showing a wallpaper: what fraction of the offset |
| 6991 | // range corresponds to a full virtual screen. |
| 6992 | float mWallpaperXStep = -1; |
| 6993 | float mWallpaperYStep = -1; |
| 6994 | |
| Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 6995 | // Wallpaper windows: pixels offset based on above variables. |
| 6996 | int mXOffset; |
| 6997 | int mYOffset; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6998 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 6999 | // This is set after IWindowSession.relayout() has been called at |
| 7000 | // least once for the window. It allows us to detect the situation |
| 7001 | // where we don't yet have a surface, but should have one soon, so |
| 7002 | // we can give the window focus before waiting for the relayout. |
| 7003 | boolean mRelayoutCalled; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7004 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7005 | // This is set after the Surface has been created but before the |
| 7006 | // window has been drawn. During this time the surface is hidden. |
| 7007 | boolean mDrawPending; |
| 7008 | |
| 7009 | // This is set after the window has finished drawing for the first |
| 7010 | // time but before its surface is shown. The surface will be |
| 7011 | // displayed when the next layout is run. |
| 7012 | boolean mCommitDrawPending; |
| 7013 | |
| 7014 | // This is set during the time after the window's drawing has been |
| 7015 | // committed, and before its surface is actually shown. It is used |
| 7016 | // to delay showing the surface until all windows in a token are ready |
| 7017 | // to be shown. |
| 7018 | boolean mReadyToShow; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7019 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7020 | // Set when the window has been shown in the screen the first time. |
| 7021 | boolean mHasDrawn; |
| 7022 | |
| 7023 | // Currently running an exit animation? |
| 7024 | boolean mExiting; |
| 7025 | |
| 7026 | // Currently on the mDestroySurface list? |
| 7027 | boolean mDestroying; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7028 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7029 | // Completely remove from window manager after exit animation? |
| 7030 | boolean mRemoveOnExit; |
| 7031 | |
| 7032 | // Set when the orientation is changing and this window has not yet |
| 7033 | // been updated for the new orientation. |
| 7034 | boolean mOrientationChanging; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7035 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7036 | // Is this window now (or just being) removed? |
| 7037 | boolean mRemoved; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7038 | |
| Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 7039 | // Temp for keeping track of windows that have been removed when |
| 7040 | // rebuilding window list. |
| 7041 | boolean mRebuilding; |
| 7042 | |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 7043 | // For debugging, this is the last information given to the surface flinger. |
| 7044 | boolean mSurfaceShown; |
| 7045 | int mSurfaceX, mSurfaceY, mSurfaceW, mSurfaceH; |
| 7046 | int mSurfaceLayer; |
| 7047 | float mSurfaceAlpha; |
| 7048 | |
| Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame] | 7049 | // Input channel and input window handle used by the input dispatcher. |
| 7050 | InputWindowHandle mInputWindowHandle; |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 7051 | InputChannel mInputChannel; |
| 7052 | |
| Mattias Petersson | 1622eee | 2010-12-21 10:15:11 +0100 | [diff] [blame] | 7053 | // Used to improve performance of toString() |
| 7054 | String mStringNameCache; |
| 7055 | CharSequence mLastTitle; |
| 7056 | boolean mWasPaused; |
| 7057 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7058 | WindowState(Session s, IWindow c, WindowToken token, |
| 7059 | WindowState attachedWindow, WindowManager.LayoutParams a, |
| 7060 | int viewVisibility) { |
| 7061 | mSession = s; |
| 7062 | mClient = c; |
| 7063 | mToken = token; |
| 7064 | mAttrs.copyFrom(a); |
| 7065 | mViewVisibility = viewVisibility; |
| 7066 | DeathRecipient deathRecipient = new DeathRecipient(); |
| 7067 | mAlpha = a.alpha; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7068 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7069 | TAG, "Window " + this + " client=" + c.asBinder() |
| 7070 | + " token=" + token + " (" + mAttrs.token + ")"); |
| 7071 | try { |
| 7072 | c.asBinder().linkToDeath(deathRecipient, 0); |
| 7073 | } catch (RemoteException e) { |
| 7074 | mDeathRecipient = null; |
| 7075 | mAttachedWindow = null; |
| 7076 | mLayoutAttached = false; |
| 7077 | mIsImWindow = false; |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 7078 | mIsWallpaper = false; |
| 7079 | mIsFloatingLayer = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7080 | mBaseLayer = 0; |
| 7081 | mSubLayer = 0; |
| 7082 | return; |
| 7083 | } |
| 7084 | mDeathRecipient = deathRecipient; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7085 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7086 | if ((mAttrs.type >= FIRST_SUB_WINDOW && |
| 7087 | mAttrs.type <= LAST_SUB_WINDOW)) { |
| 7088 | // The multiplier here is to reserve space for multiple |
| 7089 | // windows in the same type layer. |
| 7090 | mBaseLayer = mPolicy.windowTypeToLayerLw( |
| 7091 | attachedWindow.mAttrs.type) * TYPE_LAYER_MULTIPLIER |
| 7092 | + TYPE_LAYER_OFFSET; |
| 7093 | mSubLayer = mPolicy.subWindowTypeToLayerLw(a.type); |
| 7094 | mAttachedWindow = attachedWindow; |
| Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 7095 | 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] | 7096 | mAttachedWindow.mChildWindows.add(this); |
| 7097 | mLayoutAttached = mAttrs.type != |
| 7098 | WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG; |
| 7099 | mIsImWindow = attachedWindow.mAttrs.type == TYPE_INPUT_METHOD |
| 7100 | || attachedWindow.mAttrs.type == TYPE_INPUT_METHOD_DIALOG; |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 7101 | mIsWallpaper = attachedWindow.mAttrs.type == TYPE_WALLPAPER; |
| 7102 | mIsFloatingLayer = mIsImWindow || mIsWallpaper; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7103 | } else { |
| 7104 | // The multiplier here is to reserve space for multiple |
| 7105 | // windows in the same type layer. |
| 7106 | mBaseLayer = mPolicy.windowTypeToLayerLw(a.type) |
| 7107 | * TYPE_LAYER_MULTIPLIER |
| 7108 | + TYPE_LAYER_OFFSET; |
| 7109 | mSubLayer = 0; |
| 7110 | mAttachedWindow = null; |
| 7111 | mLayoutAttached = false; |
| 7112 | mIsImWindow = mAttrs.type == TYPE_INPUT_METHOD |
| 7113 | || mAttrs.type == TYPE_INPUT_METHOD_DIALOG; |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 7114 | mIsWallpaper = mAttrs.type == TYPE_WALLPAPER; |
| 7115 | mIsFloatingLayer = mIsImWindow || mIsWallpaper; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7116 | } |
| 7117 | |
| 7118 | WindowState appWin = this; |
| 7119 | while (appWin.mAttachedWindow != null) { |
| 7120 | appWin = mAttachedWindow; |
| 7121 | } |
| 7122 | WindowToken appToken = appWin.mToken; |
| 7123 | while (appToken.appWindowToken == null) { |
| 7124 | WindowToken parent = mTokenMap.get(appToken.token); |
| 7125 | if (parent == null || appToken == parent) { |
| 7126 | break; |
| 7127 | } |
| 7128 | appToken = parent; |
| 7129 | } |
| The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 7130 | mRootToken = appToken; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7131 | mAppToken = appToken.appWindowToken; |
| 7132 | |
| 7133 | mSurface = null; |
| 7134 | mRequestedWidth = 0; |
| 7135 | mRequestedHeight = 0; |
| 7136 | mLastRequestedWidth = 0; |
| 7137 | mLastRequestedHeight = 0; |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 7138 | mXOffset = 0; |
| 7139 | mYOffset = 0; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7140 | mLayer = 0; |
| 7141 | mAnimLayer = 0; |
| 7142 | mLastLayer = 0; |
| Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame] | 7143 | mInputWindowHandle = new InputWindowHandle( |
| 7144 | mAppToken != null ? mAppToken.mInputApplicationHandle : null, this); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7145 | } |
| 7146 | |
| 7147 | void attach() { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7148 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7149 | TAG, "Attaching " + this + " token=" + mToken |
| 7150 | + ", list=" + mToken.windows); |
| 7151 | mSession.windowAddedLocked(); |
| 7152 | } |
| 7153 | |
| 7154 | public void computeFrameLw(Rect pf, Rect df, Rect cf, Rect vf) { |
| 7155 | mHaveFrame = true; |
| 7156 | |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 7157 | final Rect container = mContainingFrame; |
| 7158 | container.set(pf); |
| 7159 | |
| 7160 | final Rect display = mDisplayFrame; |
| 7161 | display.set(df); |
| 7162 | |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 7163 | if ((mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0) { |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 7164 | container.intersect(mCompatibleScreenFrame); |
| Mitsuru Oshima | d2967e2 | 2009-07-20 14:01:43 -0700 | [diff] [blame] | 7165 | if ((mAttrs.flags & FLAG_LAYOUT_NO_LIMITS) == 0) { |
| 7166 | display.intersect(mCompatibleScreenFrame); |
| 7167 | } |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 7168 | } |
| 7169 | |
| 7170 | final int pw = container.right - container.left; |
| 7171 | final int ph = container.bottom - container.top; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7172 | |
| 7173 | int w,h; |
| 7174 | if ((mAttrs.flags & mAttrs.FLAG_SCALED) != 0) { |
| 7175 | w = mAttrs.width < 0 ? pw : mAttrs.width; |
| 7176 | h = mAttrs.height< 0 ? ph : mAttrs.height; |
| 7177 | } else { |
| Romain Guy | 980a938 | 2010-01-08 15:06:28 -0800 | [diff] [blame] | 7178 | w = mAttrs.width == mAttrs.MATCH_PARENT ? pw : mRequestedWidth; |
| 7179 | h = mAttrs.height== mAttrs.MATCH_PARENT ? ph : mRequestedHeight; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7180 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7181 | |
| Dianne Hackborn | 1c24e95 | 2010-11-23 00:34:30 -0800 | [diff] [blame] | 7182 | if (!mParentFrame.equals(pf)) { |
| Dianne Hackborn | 0f761d6 | 2010-11-30 22:06:10 -0800 | [diff] [blame] | 7183 | //Slog.i(TAG, "Window " + this + " content frame from " + mParentFrame |
| 7184 | // + " to " + pf); |
| Dianne Hackborn | 1c24e95 | 2010-11-23 00:34:30 -0800 | [diff] [blame] | 7185 | mParentFrame.set(pf); |
| 7186 | mContentChanged = true; |
| 7187 | } |
| 7188 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7189 | final Rect content = mContentFrame; |
| 7190 | content.set(cf); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7191 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7192 | final Rect visible = mVisibleFrame; |
| 7193 | visible.set(vf); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7194 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7195 | final Rect frame = mFrame; |
| Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 7196 | final int fw = frame.width(); |
| 7197 | final int fh = frame.height(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7198 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7199 | //System.out.println("In: w=" + w + " h=" + h + " container=" + |
| 7200 | // container + " x=" + mAttrs.x + " y=" + mAttrs.y); |
| 7201 | |
| 7202 | Gravity.apply(mAttrs.gravity, w, h, container, |
| 7203 | (int) (mAttrs.x + mAttrs.horizontalMargin * pw), |
| 7204 | (int) (mAttrs.y + mAttrs.verticalMargin * ph), frame); |
| 7205 | |
| 7206 | //System.out.println("Out: " + mFrame); |
| 7207 | |
| 7208 | // Now make sure the window fits in the overall display. |
| 7209 | Gravity.applyDisplay(mAttrs.gravity, df, frame); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7210 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7211 | // Make sure the content and visible frames are inside of the |
| 7212 | // final window frame. |
| 7213 | if (content.left < frame.left) content.left = frame.left; |
| 7214 | if (content.top < frame.top) content.top = frame.top; |
| 7215 | if (content.right > frame.right) content.right = frame.right; |
| 7216 | if (content.bottom > frame.bottom) content.bottom = frame.bottom; |
| 7217 | if (visible.left < frame.left) visible.left = frame.left; |
| 7218 | if (visible.top < frame.top) visible.top = frame.top; |
| 7219 | if (visible.right > frame.right) visible.right = frame.right; |
| 7220 | if (visible.bottom > frame.bottom) visible.bottom = frame.bottom; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7221 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7222 | final Rect contentInsets = mContentInsets; |
| 7223 | contentInsets.left = content.left-frame.left; |
| 7224 | contentInsets.top = content.top-frame.top; |
| 7225 | contentInsets.right = frame.right-content.right; |
| 7226 | contentInsets.bottom = frame.bottom-content.bottom; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7227 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7228 | final Rect visibleInsets = mVisibleInsets; |
| 7229 | visibleInsets.left = visible.left-frame.left; |
| 7230 | visibleInsets.top = visible.top-frame.top; |
| 7231 | visibleInsets.right = frame.right-visible.right; |
| 7232 | visibleInsets.bottom = frame.bottom-visible.bottom; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7233 | |
| Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 7234 | if (mIsWallpaper && (fw != frame.width() || fh != frame.height())) { |
| 7235 | updateWallpaperOffsetLocked(this, mDisplay.getWidth(), |
| Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 7236 | mDisplay.getHeight(), false); |
| Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 7237 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7238 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7239 | if (localLOGV) { |
| 7240 | //if ("com.google.android.youtube".equals(mAttrs.packageName) |
| 7241 | // && mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_PANEL) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7242 | Slog.v(TAG, "Resolving (mRequestedWidth=" |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7243 | + mRequestedWidth + ", mRequestedheight=" |
| 7244 | + mRequestedHeight + ") to" + " (pw=" + pw + ", ph=" + ph |
| 7245 | + "): frame=" + mFrame.toShortString() |
| 7246 | + " ci=" + contentInsets.toShortString() |
| 7247 | + " vi=" + visibleInsets.toShortString()); |
| 7248 | //} |
| 7249 | } |
| 7250 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7251 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7252 | public Rect getFrameLw() { |
| 7253 | return mFrame; |
| 7254 | } |
| 7255 | |
| 7256 | public Rect getShownFrameLw() { |
| 7257 | return mShownFrame; |
| 7258 | } |
| 7259 | |
| 7260 | public Rect getDisplayFrameLw() { |
| 7261 | return mDisplayFrame; |
| 7262 | } |
| 7263 | |
| 7264 | public Rect getContentFrameLw() { |
| 7265 | return mContentFrame; |
| 7266 | } |
| 7267 | |
| 7268 | public Rect getVisibleFrameLw() { |
| 7269 | return mVisibleFrame; |
| 7270 | } |
| 7271 | |
| 7272 | public boolean getGivenInsetsPendingLw() { |
| 7273 | return mGivenInsetsPending; |
| 7274 | } |
| 7275 | |
| 7276 | public Rect getGivenContentInsetsLw() { |
| 7277 | return mGivenContentInsets; |
| 7278 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7279 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7280 | public Rect getGivenVisibleInsetsLw() { |
| 7281 | return mGivenVisibleInsets; |
| 7282 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7283 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7284 | public WindowManager.LayoutParams getAttrs() { |
| 7285 | return mAttrs; |
| 7286 | } |
| 7287 | |
| 7288 | public int getSurfaceLayer() { |
| 7289 | return mLayer; |
| 7290 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7291 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7292 | public IApplicationToken getAppToken() { |
| 7293 | return mAppToken != null ? mAppToken.appToken : null; |
| 7294 | } |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 7295 | |
| 7296 | public long getInputDispatchingTimeoutNanos() { |
| 7297 | return mAppToken != null |
| 7298 | ? mAppToken.inputDispatchingTimeoutNanos |
| 7299 | : DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS; |
| 7300 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7301 | |
| 7302 | public boolean hasAppShownWindows() { |
| 7303 | return mAppToken != null ? mAppToken.firstWindowDrawn : false; |
| 7304 | } |
| 7305 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7306 | public void setAnimation(Animation anim) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7307 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7308 | TAG, "Setting animation in " + this + ": " + anim); |
| 7309 | mAnimating = false; |
| 7310 | mLocalAnimating = false; |
| 7311 | mAnimation = anim; |
| 7312 | mAnimation.restrictDuration(MAX_ANIMATION_DURATION); |
| 7313 | mAnimation.scaleCurrentDuration(mWindowAnimationScale); |
| 7314 | } |
| 7315 | |
| 7316 | public void clearAnimation() { |
| 7317 | if (mAnimation != null) { |
| 7318 | mAnimating = true; |
| 7319 | mLocalAnimating = false; |
| Brad Fitzpatrick | 3fe3851 | 2010-11-03 11:46:54 -0700 | [diff] [blame] | 7320 | mAnimation.cancel(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7321 | mAnimation = null; |
| 7322 | } |
| 7323 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7324 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7325 | Surface createSurfaceLocked() { |
| 7326 | if (mSurface == null) { |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 7327 | mReportDestroySurface = false; |
| 7328 | mSurfacePendingDestroy = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7329 | mDrawPending = true; |
| 7330 | mCommitDrawPending = false; |
| 7331 | mReadyToShow = false; |
| 7332 | if (mAppToken != null) { |
| 7333 | mAppToken.allDrawn = false; |
| 7334 | } |
| 7335 | |
| 7336 | int flags = 0; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7337 | |
| 7338 | if ((mAttrs.flags&WindowManager.LayoutParams.FLAG_SECURE) != 0) { |
| 7339 | flags |= Surface.SECURE; |
| 7340 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7341 | if (DEBUG_VISIBILITY) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7342 | TAG, "Creating surface in session " |
| 7343 | + mSession.mSurfaceSession + " window " + this |
| 7344 | + " w=" + mFrame.width() |
| 7345 | + " h=" + mFrame.height() + " format=" |
| 7346 | + mAttrs.format + " flags=" + flags); |
| 7347 | |
| 7348 | int w = mFrame.width(); |
| 7349 | int h = mFrame.height(); |
| 7350 | if ((mAttrs.flags & LayoutParams.FLAG_SCALED) != 0) { |
| 7351 | // for a scaled surface, we always want the requested |
| 7352 | // size. |
| 7353 | w = mRequestedWidth; |
| 7354 | h = mRequestedHeight; |
| 7355 | } |
| 7356 | |
| Romain Guy | 9825ec6 | 2009-10-01 00:58:09 -0700 | [diff] [blame] | 7357 | // Something is wrong and SurfaceFlinger will not like this, |
| 7358 | // try to revert to sane values |
| 7359 | if (w <= 0) w = 1; |
| 7360 | if (h <= 0) h = 1; |
| 7361 | |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 7362 | mSurfaceShown = false; |
| 7363 | mSurfaceLayer = 0; |
| 7364 | mSurfaceAlpha = 1; |
| 7365 | mSurfaceX = 0; |
| 7366 | mSurfaceY = 0; |
| 7367 | mSurfaceW = w; |
| 7368 | mSurfaceH = h; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7369 | try { |
| Romain Guy | d10cd57 | 2010-10-10 13:33:22 -0700 | [diff] [blame] | 7370 | final boolean isHwAccelerated = (mAttrs.flags & |
| 7371 | WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED) != 0; |
| 7372 | final int format = isHwAccelerated ? PixelFormat.TRANSLUCENT : mAttrs.format; |
| 7373 | if (isHwAccelerated && mAttrs.format == PixelFormat.OPAQUE) { |
| 7374 | flags |= Surface.OPAQUE; |
| 7375 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7376 | mSurface = new Surface( |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7377 | mSession.mSurfaceSession, mSession.mPid, |
| Mathias Agopian | 5d26c1e | 2010-03-01 16:09:43 -0800 | [diff] [blame] | 7378 | mAttrs.getTitle().toString(), |
| Romain Guy | d10cd57 | 2010-10-10 13:33:22 -0700 | [diff] [blame] | 7379 | 0, w, h, format, flags); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7380 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " CREATE SURFACE " |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 7381 | + mSurface + " IN SESSION " |
| 7382 | + mSession.mSurfaceSession |
| 7383 | + ": pid=" + mSession.mPid + " format=" |
| 7384 | + mAttrs.format + " flags=0x" |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 7385 | + Integer.toHexString(flags) |
| 7386 | + " / " + this); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7387 | } catch (Surface.OutOfResourcesException e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7388 | Slog.w(TAG, "OutOfResourcesException creating surface"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7389 | reclaimSomeSurfaceMemoryLocked(this, "create"); |
| 7390 | return null; |
| 7391 | } catch (Exception e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7392 | Slog.e(TAG, "Exception creating surface", e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7393 | return null; |
| 7394 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7395 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7396 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7397 | TAG, "Got surface: " + mSurface |
| 7398 | + ", set left=" + mFrame.left + " top=" + mFrame.top |
| 7399 | + ", animLayer=" + mAnimLayer); |
| 7400 | if (SHOW_TRANSACTIONS) { |
| Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 7401 | Slog.i(TAG, ">>> OPEN TRANSACTION createSurfaceLocked"); |
| 7402 | logSurface(this, "CREATE pos=(" + mFrame.left + "," + mFrame.top + ") (" + |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 7403 | mFrame.width() + "x" + mFrame.height() + "), layer=" + |
| 7404 | mAnimLayer + " HIDE", null); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7405 | } |
| 7406 | Surface.openTransaction(); |
| 7407 | try { |
| 7408 | try { |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 7409 | mSurfaceX = mFrame.left + mXOffset; |
| Dianne Hackborn | 529bef6 | 2010-03-25 11:48:43 -0700 | [diff] [blame] | 7410 | mSurfaceY = mFrame.top + mYOffset; |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 7411 | mSurface.setPosition(mSurfaceX, mSurfaceY); |
| 7412 | mSurfaceLayer = mAnimLayer; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7413 | mSurface.setLayer(mAnimLayer); |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 7414 | mSurfaceShown = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7415 | mSurface.hide(); |
| 7416 | if ((mAttrs.flags&WindowManager.LayoutParams.FLAG_DITHER) != 0) { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 7417 | if (SHOW_TRANSACTIONS) logSurface(this, "DITHER", null); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7418 | mSurface.setFlags(Surface.SURFACE_DITHER, |
| 7419 | Surface.SURFACE_DITHER); |
| 7420 | } |
| 7421 | } catch (RuntimeException e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7422 | Slog.w(TAG, "Error creating surface in " + w, e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7423 | reclaimSomeSurfaceMemoryLocked(this, "create-init"); |
| 7424 | } |
| 7425 | mLastHidden = true; |
| 7426 | } finally { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7427 | Surface.closeTransaction(); |
| Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 7428 | if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION createSurfaceLocked"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7429 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7430 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7431 | TAG, "Created surface " + this); |
| 7432 | } |
| 7433 | return mSurface; |
| 7434 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7435 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7436 | void destroySurfaceLocked() { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7437 | if (mAppToken != null && this == mAppToken.startingWindow) { |
| 7438 | mAppToken.startingDisplayed = false; |
| 7439 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7440 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7441 | if (mSurface != null) { |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 7442 | mDrawPending = false; |
| 7443 | mCommitDrawPending = false; |
| 7444 | mReadyToShow = false; |
| 7445 | |
| 7446 | int i = mChildWindows.size(); |
| 7447 | while (i > 0) { |
| 7448 | i--; |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 7449 | WindowState c = mChildWindows.get(i); |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 7450 | c.mAttachedHidden = true; |
| 7451 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7452 | |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 7453 | if (mReportDestroySurface) { |
| 7454 | mReportDestroySurface = false; |
| 7455 | mSurfacePendingDestroy = true; |
| 7456 | try { |
| 7457 | mClient.dispatchGetNewSurface(); |
| 7458 | // We'll really destroy on the next time around. |
| 7459 | return; |
| 7460 | } catch (RemoteException e) { |
| 7461 | } |
| 7462 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7463 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7464 | try { |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 7465 | if (DEBUG_VISIBILITY) { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 7466 | RuntimeException e = null; |
| 7467 | if (!HIDE_STACK_CRAWLS) { |
| 7468 | e = new RuntimeException(); |
| 7469 | e.fillInStackTrace(); |
| 7470 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7471 | Slog.w(TAG, "Window " + this + " destroying surface " |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 7472 | + mSurface + ", session " + mSession, e); |
| 7473 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7474 | if (SHOW_TRANSACTIONS) { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 7475 | RuntimeException e = null; |
| 7476 | if (!HIDE_STACK_CRAWLS) { |
| 7477 | e = new RuntimeException(); |
| 7478 | e.fillInStackTrace(); |
| 7479 | } |
| 7480 | if (SHOW_TRANSACTIONS) logSurface(this, "DESTROY", e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7481 | } |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 7482 | mSurface.destroy(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7483 | } catch (RuntimeException e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7484 | Slog.w(TAG, "Exception thrown when destroying Window " + this |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7485 | + " surface " + mSurface + " session " + mSession |
| 7486 | + ": " + e.toString()); |
| 7487 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7488 | |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 7489 | mSurfaceShown = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7490 | mSurface = null; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7491 | } |
| 7492 | } |
| 7493 | |
| 7494 | boolean finishDrawingLocked() { |
| 7495 | if (mDrawPending) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7496 | if (SHOW_TRANSACTIONS || DEBUG_ORIENTATION) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7497 | TAG, "finishDrawingLocked: " + mSurface); |
| 7498 | mCommitDrawPending = true; |
| 7499 | mDrawPending = false; |
| 7500 | return true; |
| 7501 | } |
| 7502 | return false; |
| 7503 | } |
| 7504 | |
| 7505 | // This must be called while inside a transaction. |
| Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 7506 | boolean commitFinishDrawingLocked(long currentTime) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7507 | //Slog.i(TAG, "commitFinishDrawingLocked: " + mSurface); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7508 | if (!mCommitDrawPending) { |
| Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 7509 | return false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7510 | } |
| 7511 | mCommitDrawPending = false; |
| 7512 | mReadyToShow = true; |
| 7513 | final boolean starting = mAttrs.type == TYPE_APPLICATION_STARTING; |
| 7514 | final AppWindowToken atoken = mAppToken; |
| 7515 | if (atoken == null || atoken.allDrawn || starting) { |
| 7516 | performShowLocked(); |
| 7517 | } |
| Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 7518 | return true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7519 | } |
| 7520 | |
| 7521 | // This must be called while inside a transaction. |
| 7522 | boolean performShowLocked() { |
| 7523 | if (DEBUG_VISIBILITY) { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 7524 | RuntimeException e = null; |
| 7525 | if (!HIDE_STACK_CRAWLS) { |
| 7526 | e = new RuntimeException(); |
| 7527 | e.fillInStackTrace(); |
| 7528 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7529 | Slog.v(TAG, "performShow on " + this |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7530 | + ": readyToShow=" + mReadyToShow + " readyForDisplay=" + isReadyForDisplay() |
| 7531 | + " starting=" + (mAttrs.type == TYPE_APPLICATION_STARTING), e); |
| 7532 | } |
| 7533 | if (mReadyToShow && isReadyForDisplay()) { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 7534 | if (SHOW_TRANSACTIONS || DEBUG_ORIENTATION) logSurface(this, |
| 7535 | "SHOW (performShowLocked)", null); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7536 | if (DEBUG_VISIBILITY) Slog.v(TAG, "Showing " + this |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7537 | + " during animation: policyVis=" + mPolicyVisibility |
| 7538 | + " attHidden=" + mAttachedHidden |
| 7539 | + " tok.hiddenRequested=" |
| 7540 | + (mAppToken != null ? mAppToken.hiddenRequested : false) |
| Dianne Hackborn | 248b188 | 2009-09-16 16:46:44 -0700 | [diff] [blame] | 7541 | + " tok.hidden=" |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7542 | + (mAppToken != null ? mAppToken.hidden : false) |
| 7543 | + " animating=" + mAnimating |
| 7544 | + " tok animating=" |
| 7545 | + (mAppToken != null ? mAppToken.animating : false)); |
| 7546 | if (!showSurfaceRobustlyLocked(this)) { |
| 7547 | return false; |
| 7548 | } |
| 7549 | mLastAlpha = -1; |
| 7550 | mHasDrawn = true; |
| 7551 | mLastHidden = false; |
| 7552 | mReadyToShow = false; |
| 7553 | enableScreenIfNeededLocked(); |
| 7554 | |
| 7555 | applyEnterAnimationLocked(this); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7556 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7557 | int i = mChildWindows.size(); |
| 7558 | while (i > 0) { |
| 7559 | i--; |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 7560 | WindowState c = mChildWindows.get(i); |
| Dianne Hackborn | f09c1a2 | 2010-04-22 15:59:21 -0700 | [diff] [blame] | 7561 | if (c.mAttachedHidden) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7562 | c.mAttachedHidden = false; |
| Dianne Hackborn | f09c1a2 | 2010-04-22 15:59:21 -0700 | [diff] [blame] | 7563 | if (c.mSurface != null) { |
| 7564 | c.performShowLocked(); |
| 7565 | // It hadn't been shown, which means layout not |
| 7566 | // performed on it, so now we want to make sure to |
| 7567 | // do a layout. If called from within the transaction |
| 7568 | // loop, this will cause it to restart with a new |
| 7569 | // layout. |
| 7570 | mLayoutNeeded = true; |
| 7571 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7572 | } |
| 7573 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7574 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7575 | if (mAttrs.type != TYPE_APPLICATION_STARTING |
| 7576 | && mAppToken != null) { |
| 7577 | mAppToken.firstWindowDrawn = true; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7578 | |
| Dianne Hackborn | 248b188 | 2009-09-16 16:46:44 -0700 | [diff] [blame] | 7579 | if (mAppToken.startingData != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7580 | if (DEBUG_STARTING_WINDOW || DEBUG_ANIM) Slog.v(TAG, |
| Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 7581 | "Finish starting " + mToken |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7582 | + ": first real window is shown, no animation"); |
| Dianne Hackborn | 248b188 | 2009-09-16 16:46:44 -0700 | [diff] [blame] | 7583 | // If this initial window is animating, stop it -- we |
| 7584 | // will do an animation to reveal it from behind the |
| 7585 | // starting window, so there is no need for it to also |
| 7586 | // be doing its own stuff. |
| 7587 | if (mAnimation != null) { |
| Brad Fitzpatrick | 3fe3851 | 2010-11-03 11:46:54 -0700 | [diff] [blame] | 7588 | mAnimation.cancel(); |
| Dianne Hackborn | 248b188 | 2009-09-16 16:46:44 -0700 | [diff] [blame] | 7589 | mAnimation = null; |
| 7590 | // Make sure we clean up the animation. |
| 7591 | mAnimating = true; |
| 7592 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7593 | mFinishedStarting.add(mAppToken); |
| 7594 | mH.sendEmptyMessage(H.FINISHED_STARTING); |
| 7595 | } |
| 7596 | mAppToken.updateReportedVisibilityLocked(); |
| 7597 | } |
| 7598 | } |
| 7599 | return true; |
| 7600 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7601 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7602 | // This must be called while inside a transaction. Returns true if |
| 7603 | // there is more animation to run. |
| 7604 | boolean stepAnimationLocked(long currentTime, int dw, int dh) { |
| Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 7605 | if (!mDisplayFrozen && mPolicy.isScreenOn()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7606 | // We will run animations as long as the display isn't frozen. |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7607 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7608 | if (!mDrawPending && !mCommitDrawPending && mAnimation != null) { |
| 7609 | mHasTransformation = true; |
| 7610 | mHasLocalTransformation = true; |
| 7611 | if (!mLocalAnimating) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7612 | if (DEBUG_ANIM) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7613 | TAG, "Starting animation in " + this + |
| 7614 | " @ " + currentTime + ": ww=" + mFrame.width() + " wh=" + mFrame.height() + |
| 7615 | " dw=" + dw + " dh=" + dh + " scale=" + mWindowAnimationScale); |
| 7616 | mAnimation.initialize(mFrame.width(), mFrame.height(), dw, dh); |
| 7617 | mAnimation.setStartTime(currentTime); |
| 7618 | mLocalAnimating = true; |
| 7619 | mAnimating = true; |
| 7620 | } |
| 7621 | mTransformation.clear(); |
| 7622 | final boolean more = mAnimation.getTransformation( |
| 7623 | currentTime, mTransformation); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7624 | if (DEBUG_ANIM) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7625 | TAG, "Stepped animation in " + this + |
| 7626 | ": more=" + more + ", xform=" + mTransformation); |
| 7627 | if (more) { |
| 7628 | // we're not done! |
| 7629 | return true; |
| 7630 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7631 | if (DEBUG_ANIM) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7632 | TAG, "Finished animation in " + this + |
| 7633 | " @ " + currentTime); |
| Brad Fitzpatrick | 3fe3851 | 2010-11-03 11:46:54 -0700 | [diff] [blame] | 7634 | |
| 7635 | if (mAnimation != null) { |
| 7636 | mAnimation.cancel(); |
| 7637 | mAnimation = null; |
| 7638 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7639 | //WindowManagerService.this.dump(); |
| 7640 | } |
| 7641 | mHasLocalTransformation = false; |
| 7642 | if ((!mLocalAnimating || mAnimationIsEntrance) && mAppToken != null |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 7643 | && mAppToken.animation != null) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7644 | // When our app token is animating, we kind-of pretend like |
| 7645 | // we are as well. Note the mLocalAnimating mAnimationIsEntrance |
| 7646 | // part of this check means that we will only do this if |
| 7647 | // our window is not currently exiting, or it is not |
| 7648 | // locally animating itself. The idea being that one that |
| 7649 | // is exiting and doing a local animation should be removed |
| 7650 | // once that animation is done. |
| 7651 | mAnimating = true; |
| 7652 | mHasTransformation = true; |
| 7653 | mTransformation.clear(); |
| 7654 | return false; |
| 7655 | } else if (mHasTransformation) { |
| 7656 | // Little trick to get through the path below to act like |
| 7657 | // we have finished an animation. |
| 7658 | mAnimating = true; |
| 7659 | } else if (isAnimating()) { |
| 7660 | mAnimating = true; |
| 7661 | } |
| 7662 | } else if (mAnimation != null) { |
| 7663 | // If the display is frozen, and there is a pending animation, |
| 7664 | // clear it and make sure we run the cleanup code. |
| 7665 | mAnimating = true; |
| 7666 | mLocalAnimating = true; |
| Brad Fitzpatrick | 3fe3851 | 2010-11-03 11:46:54 -0700 | [diff] [blame] | 7667 | mAnimation.cancel(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7668 | mAnimation = null; |
| 7669 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7670 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7671 | if (!mAnimating && !mLocalAnimating) { |
| 7672 | return false; |
| 7673 | } |
| 7674 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7675 | if (DEBUG_ANIM) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7676 | TAG, "Animation done in " + this + ": exiting=" + mExiting |
| 7677 | + ", reportedVisible=" |
| 7678 | + (mAppToken != null ? mAppToken.reportedVisible : false)); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7679 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7680 | mAnimating = false; |
| 7681 | mLocalAnimating = false; |
| Brad Fitzpatrick | 3fe3851 | 2010-11-03 11:46:54 -0700 | [diff] [blame] | 7682 | if (mAnimation != null) { |
| 7683 | mAnimation.cancel(); |
| 7684 | mAnimation = null; |
| 7685 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7686 | mAnimLayer = mLayer; |
| 7687 | if (mIsImWindow) { |
| 7688 | mAnimLayer += mInputMethodAnimLayerAdjustment; |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 7689 | } else if (mIsWallpaper) { |
| 7690 | mAnimLayer += mWallpaperAnimLayerAdjustment; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7691 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7692 | if (DEBUG_LAYERS) Slog.v(TAG, "Stepping win " + this |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7693 | + " anim layer: " + mAnimLayer); |
| 7694 | mHasTransformation = false; |
| 7695 | mHasLocalTransformation = false; |
| Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 7696 | if (mPolicyVisibility != mPolicyVisibilityAfterAnim) { |
| 7697 | if (DEBUG_VISIBILITY) { |
| 7698 | Slog.v(TAG, "Policy visibility changing after anim in " + this + ": " |
| 7699 | + mPolicyVisibilityAfterAnim); |
| 7700 | } |
| 7701 | mPolicyVisibility = mPolicyVisibilityAfterAnim; |
| 7702 | if (!mPolicyVisibility) { |
| 7703 | if (mCurrentFocus == this) { |
| 7704 | mFocusMayChange = true; |
| 7705 | } |
| 7706 | // Window is no longer visible -- make sure if we were waiting |
| 7707 | // for it to be displayed before enabling the display, that |
| 7708 | // we allow the display to be enabled now. |
| 7709 | enableScreenIfNeededLocked(); |
| 7710 | } |
| Dianne Hackborn | f3bea9c | 2009-12-09 18:26:21 -0800 | [diff] [blame] | 7711 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7712 | mTransformation.clear(); |
| 7713 | if (mHasDrawn |
| 7714 | && mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING |
| 7715 | && mAppToken != null |
| 7716 | && mAppToken.firstWindowDrawn |
| 7717 | && mAppToken.startingData != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7718 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Finish starting " |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7719 | + mToken + ": first real window done animating"); |
| 7720 | mFinishedStarting.add(mAppToken); |
| 7721 | mH.sendEmptyMessage(H.FINISHED_STARTING); |
| 7722 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7723 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7724 | finishExit(); |
| 7725 | |
| 7726 | if (mAppToken != null) { |
| 7727 | mAppToken.updateReportedVisibilityLocked(); |
| 7728 | } |
| 7729 | |
| 7730 | return false; |
| 7731 | } |
| 7732 | |
| 7733 | void finishExit() { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7734 | if (DEBUG_ANIM) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7735 | TAG, "finishExit in " + this |
| 7736 | + ": exiting=" + mExiting |
| 7737 | + " remove=" + mRemoveOnExit |
| 7738 | + " windowAnimating=" + isWindowAnimating()); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7739 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7740 | final int N = mChildWindows.size(); |
| 7741 | for (int i=0; i<N; i++) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 7742 | mChildWindows.get(i).finishExit(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7743 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7744 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7745 | if (!mExiting) { |
| 7746 | return; |
| 7747 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7748 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7749 | if (isWindowAnimating()) { |
| 7750 | return; |
| 7751 | } |
| 7752 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7753 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7754 | TAG, "Exit animation finished in " + this |
| 7755 | + ": remove=" + mRemoveOnExit); |
| 7756 | if (mSurface != null) { |
| 7757 | mDestroySurface.add(this); |
| 7758 | mDestroying = true; |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 7759 | if (SHOW_TRANSACTIONS) logSurface(this, "HIDE (finishExit)", null); |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 7760 | mSurfaceShown = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7761 | try { |
| 7762 | mSurface.hide(); |
| 7763 | } catch (RuntimeException e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7764 | Slog.w(TAG, "Error hiding surface in " + this, e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7765 | } |
| 7766 | mLastHidden = true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7767 | } |
| 7768 | mExiting = false; |
| 7769 | if (mRemoveOnExit) { |
| 7770 | mPendingRemove.add(this); |
| 7771 | mRemoveOnExit = false; |
| 7772 | } |
| 7773 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7774 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7775 | boolean isIdentityMatrix(float dsdx, float dtdx, float dsdy, float dtdy) { |
| 7776 | if (dsdx < .99999f || dsdx > 1.00001f) return false; |
| 7777 | if (dtdy < .99999f || dtdy > 1.00001f) return false; |
| 7778 | if (dtdx < -.000001f || dtdx > .000001f) return false; |
| 7779 | if (dsdy < -.000001f || dsdy > .000001f) return false; |
| 7780 | return true; |
| 7781 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7782 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7783 | void computeShownFrameLocked() { |
| 7784 | final boolean selfTransformation = mHasLocalTransformation; |
| 7785 | Transformation attachedTransformation = |
| 7786 | (mAttachedWindow != null && mAttachedWindow.mHasLocalTransformation) |
| 7787 | ? mAttachedWindow.mTransformation : null; |
| 7788 | Transformation appTransformation = |
| 7789 | (mAppToken != null && mAppToken.hasTransformation) |
| 7790 | ? mAppToken.transformation : null; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7791 | |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 7792 | // Wallpapers are animated based on the "real" window they |
| 7793 | // are currently targeting. |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 7794 | if (mAttrs.type == TYPE_WALLPAPER && mLowerWallpaperTarget == null |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 7795 | && mWallpaperTarget != null) { |
| Dianne Hackborn | 5baba16 | 2009-09-23 17:01:12 -0700 | [diff] [blame] | 7796 | if (mWallpaperTarget.mHasLocalTransformation && |
| 7797 | mWallpaperTarget.mAnimation != null && |
| 7798 | !mWallpaperTarget.mAnimation.getDetachWallpaper()) { |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 7799 | attachedTransformation = mWallpaperTarget.mTransformation; |
| Dianne Hackborn | 5baba16 | 2009-09-23 17:01:12 -0700 | [diff] [blame] | 7800 | if (DEBUG_WALLPAPER && attachedTransformation != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7801 | Slog.v(TAG, "WP target attached xform: " + attachedTransformation); |
| Dianne Hackborn | 5baba16 | 2009-09-23 17:01:12 -0700 | [diff] [blame] | 7802 | } |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 7803 | } |
| 7804 | if (mWallpaperTarget.mAppToken != null && |
| Dianne Hackborn | 5baba16 | 2009-09-23 17:01:12 -0700 | [diff] [blame] | 7805 | mWallpaperTarget.mAppToken.hasTransformation && |
| 7806 | mWallpaperTarget.mAppToken.animation != null && |
| 7807 | !mWallpaperTarget.mAppToken.animation.getDetachWallpaper()) { |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 7808 | appTransformation = mWallpaperTarget.mAppToken.transformation; |
| Dianne Hackborn | 5baba16 | 2009-09-23 17:01:12 -0700 | [diff] [blame] | 7809 | if (DEBUG_WALLPAPER && appTransformation != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7810 | Slog.v(TAG, "WP target app xform: " + appTransformation); |
| Dianne Hackborn | 5baba16 | 2009-09-23 17:01:12 -0700 | [diff] [blame] | 7811 | } |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 7812 | } |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 7813 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7814 | |
| Dianne Hackborn | f9d0be9 | 2010-11-24 12:35:25 -0800 | [diff] [blame] | 7815 | final boolean screenAnimation = mScreenRotationAnimation != null |
| 7816 | && mScreenRotationAnimation.isAnimating(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7817 | if (selfTransformation || attachedTransformation != null |
| Dianne Hackborn | f9d0be9 | 2010-11-24 12:35:25 -0800 | [diff] [blame] | 7818 | || appTransformation != null || screenAnimation) { |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7819 | // cache often used attributes locally |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7820 | final Rect frame = mFrame; |
| 7821 | final float tmpFloats[] = mTmpFloats; |
| 7822 | final Matrix tmpMatrix = mTmpMatrix; |
| 7823 | |
| 7824 | // Compute the desired transformation. |
| Dianne Hackborn | 65c2387 | 2009-09-18 17:47:02 -0700 | [diff] [blame] | 7825 | tmpMatrix.setTranslate(0, 0); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7826 | if (selfTransformation) { |
| Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 7827 | tmpMatrix.postConcat(mTransformation.getMatrix()); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7828 | } |
| Dianne Hackborn | 65c2387 | 2009-09-18 17:47:02 -0700 | [diff] [blame] | 7829 | tmpMatrix.postTranslate(frame.left, frame.top); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7830 | if (attachedTransformation != null) { |
| Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 7831 | tmpMatrix.postConcat(attachedTransformation.getMatrix()); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7832 | } |
| 7833 | if (appTransformation != null) { |
| Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 7834 | tmpMatrix.postConcat(appTransformation.getMatrix()); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7835 | } |
| Dianne Hackborn | f9d0be9 | 2010-11-24 12:35:25 -0800 | [diff] [blame] | 7836 | if (screenAnimation) { |
| 7837 | tmpMatrix.postConcat( |
| 7838 | mScreenRotationAnimation.getEnterTransformation().getMatrix()); |
| 7839 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7840 | |
| 7841 | // "convert" it into SurfaceFlinger's format |
| 7842 | // (a 2x2 matrix + an offset) |
| 7843 | // Here we must not transform the position of the surface |
| 7844 | // since it is already included in the transformation. |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7845 | //Slog.i(TAG, "Transform: " + matrix); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7846 | |
| Dianne Hackborn | 7da6ac3 | 2010-12-09 19:22:04 -0800 | [diff] [blame] | 7847 | mHaveMatrix = true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7848 | tmpMatrix.getValues(tmpFloats); |
| 7849 | mDsDx = tmpFloats[Matrix.MSCALE_X]; |
| Dianne Hackborn | f9d0be9 | 2010-11-24 12:35:25 -0800 | [diff] [blame] | 7850 | mDtDx = tmpFloats[Matrix.MSKEW_Y]; |
| 7851 | mDsDy = tmpFloats[Matrix.MSKEW_X]; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7852 | mDtDy = tmpFloats[Matrix.MSCALE_Y]; |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 7853 | int x = (int)tmpFloats[Matrix.MTRANS_X] + mXOffset; |
| 7854 | int y = (int)tmpFloats[Matrix.MTRANS_Y] + mYOffset; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7855 | int w = frame.width(); |
| 7856 | int h = frame.height(); |
| 7857 | mShownFrame.set(x, y, x+w, y+h); |
| 7858 | |
| 7859 | // Now set the alpha... but because our current hardware |
| 7860 | // can't do alpha transformation on a non-opaque surface, |
| 7861 | // turn it off if we are running an animation that is also |
| 7862 | // transforming since it is more important to have that |
| 7863 | // animation be smooth. |
| 7864 | mShownAlpha = mAlpha; |
| 7865 | if (!mLimitedAlphaCompositing |
| 7866 | || (!PixelFormat.formatHasAlpha(mAttrs.format) |
| 7867 | || (isIdentityMatrix(mDsDx, mDtDx, mDsDy, mDtDy) |
| 7868 | && x == frame.left && y == frame.top))) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7869 | //Slog.i(TAG, "Applying alpha transform"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7870 | if (selfTransformation) { |
| 7871 | mShownAlpha *= mTransformation.getAlpha(); |
| 7872 | } |
| 7873 | if (attachedTransformation != null) { |
| 7874 | mShownAlpha *= attachedTransformation.getAlpha(); |
| 7875 | } |
| 7876 | if (appTransformation != null) { |
| 7877 | mShownAlpha *= appTransformation.getAlpha(); |
| 7878 | } |
| Dianne Hackborn | f9d0be9 | 2010-11-24 12:35:25 -0800 | [diff] [blame] | 7879 | if (screenAnimation) { |
| 7880 | mShownAlpha *= |
| 7881 | mScreenRotationAnimation.getEnterTransformation().getAlpha(); |
| 7882 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7883 | } else { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7884 | //Slog.i(TAG, "Not applying alpha transform"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7885 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7886 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 7887 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7888 | TAG, "Continuing animation in " + this + |
| 7889 | ": " + mShownFrame + |
| 7890 | ", alpha=" + mTransformation.getAlpha()); |
| 7891 | return; |
| 7892 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7893 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7894 | mShownFrame.set(mFrame); |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 7895 | if (mXOffset != 0 || mYOffset != 0) { |
| 7896 | mShownFrame.offset(mXOffset, mYOffset); |
| 7897 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7898 | mShownAlpha = mAlpha; |
| Dianne Hackborn | 7da6ac3 | 2010-12-09 19:22:04 -0800 | [diff] [blame] | 7899 | mHaveMatrix = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7900 | mDsDx = 1; |
| 7901 | mDtDx = 0; |
| 7902 | mDsDy = 0; |
| 7903 | mDtDy = 1; |
| 7904 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7905 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7906 | /** |
| 7907 | * Is this window visible? It is not visible if there is no |
| 7908 | * surface, or we are in the process of running an exit animation |
| 7909 | * that will remove the surface, or its app token has been hidden. |
| 7910 | */ |
| 7911 | public boolean isVisibleLw() { |
| 7912 | final AppWindowToken atoken = mAppToken; |
| 7913 | return mSurface != null && mPolicyVisibility && !mAttachedHidden |
| 7914 | && (atoken == null || !atoken.hiddenRequested) |
| 7915 | && !mExiting && !mDestroying; |
| 7916 | } |
| 7917 | |
| 7918 | /** |
| Dianne Hackborn | 3d163f07 | 2009-10-07 21:26:57 -0700 | [diff] [blame] | 7919 | * Like {@link #isVisibleLw}, but also counts a window that is currently |
| 7920 | * "hidden" behind the keyguard as visible. This allows us to apply |
| 7921 | * things like window flags that impact the keyguard. |
| 7922 | * XXX I am starting to think we need to have ANOTHER visibility flag |
| 7923 | * for this "hidden behind keyguard" state rather than overloading |
| 7924 | * mPolicyVisibility. Ungh. |
| 7925 | */ |
| 7926 | public boolean isVisibleOrBehindKeyguardLw() { |
| 7927 | final AppWindowToken atoken = mAppToken; |
| 7928 | return mSurface != null && !mAttachedHidden |
| 7929 | && (atoken == null ? mPolicyVisibility : !atoken.hiddenRequested) |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 7930 | && !mDrawPending && !mCommitDrawPending |
| Dianne Hackborn | 3d163f07 | 2009-10-07 21:26:57 -0700 | [diff] [blame] | 7931 | && !mExiting && !mDestroying; |
| 7932 | } |
| 7933 | |
| 7934 | /** |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7935 | * Is this window visible, ignoring its app token? It is not visible |
| 7936 | * if there is no surface, or we are in the process of running an exit animation |
| 7937 | * that will remove the surface. |
| 7938 | */ |
| 7939 | public boolean isWinVisibleLw() { |
| 7940 | final AppWindowToken atoken = mAppToken; |
| 7941 | return mSurface != null && mPolicyVisibility && !mAttachedHidden |
| 7942 | && (atoken == null || !atoken.hiddenRequested || atoken.animating) |
| 7943 | && !mExiting && !mDestroying; |
| 7944 | } |
| 7945 | |
| 7946 | /** |
| 7947 | * The same as isVisible(), but follows the current hidden state of |
| 7948 | * the associated app token, not the pending requested hidden state. |
| 7949 | */ |
| 7950 | boolean isVisibleNow() { |
| 7951 | return mSurface != null && mPolicyVisibility && !mAttachedHidden |
| The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 7952 | && !mRootToken.hidden && !mExiting && !mDestroying; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7953 | } |
| 7954 | |
| 7955 | /** |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 7956 | * Can this window possibly be a drag/drop target? The test here is |
| 7957 | * a combination of the above "visible now" with the check that the |
| 7958 | * Input Manager uses when discarding windows from input consideration. |
| 7959 | */ |
| 7960 | boolean isPotentialDragTarget() { |
| 7961 | return isVisibleNow() && (mInputChannel != null) && !mRemoved; |
| 7962 | } |
| 7963 | |
| 7964 | /** |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7965 | * Same as isVisible(), but we also count it as visible between the |
| 7966 | * call to IWindowSession.add() and the first relayout(). |
| 7967 | */ |
| 7968 | boolean isVisibleOrAdding() { |
| 7969 | final AppWindowToken atoken = mAppToken; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 7970 | return ((mSurface != null && !mReportDestroySurface) |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7971 | || (!mRelayoutCalled && mViewVisibility == View.VISIBLE)) |
| 7972 | && mPolicyVisibility && !mAttachedHidden |
| 7973 | && (atoken == null || !atoken.hiddenRequested) |
| 7974 | && !mExiting && !mDestroying; |
| 7975 | } |
| 7976 | |
| 7977 | /** |
| 7978 | * Is this window currently on-screen? It is on-screen either if it |
| 7979 | * is visible or it is currently running an animation before no longer |
| 7980 | * being visible. |
| 7981 | */ |
| 7982 | boolean isOnScreen() { |
| 7983 | final AppWindowToken atoken = mAppToken; |
| 7984 | if (atoken != null) { |
| 7985 | return mSurface != null && mPolicyVisibility && !mDestroying |
| 7986 | && ((!mAttachedHidden && !atoken.hiddenRequested) |
| Dianne Hackborn | 0cd4887 | 2009-08-13 18:51:59 -0700 | [diff] [blame] | 7987 | || mAnimation != null || atoken.animation != null); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7988 | } else { |
| 7989 | return mSurface != null && mPolicyVisibility && !mDestroying |
| Dianne Hackborn | 0cd4887 | 2009-08-13 18:51:59 -0700 | [diff] [blame] | 7990 | && (!mAttachedHidden || mAnimation != null); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7991 | } |
| 7992 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 7993 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7994 | /** |
| 7995 | * Like isOnScreen(), but we don't return true if the window is part |
| 7996 | * of a transition that has not yet been started. |
| 7997 | */ |
| 7998 | boolean isReadyForDisplay() { |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 7999 | if (mRootToken.waitingToShow && |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 8000 | mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8001 | return false; |
| 8002 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8003 | final AppWindowToken atoken = mAppToken; |
| Dianne Hackborn | 0cd4887 | 2009-08-13 18:51:59 -0700 | [diff] [blame] | 8004 | final boolean animating = atoken != null |
| 8005 | ? (atoken.animation != null) : false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8006 | return mSurface != null && mPolicyVisibility && !mDestroying |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 8007 | && ((!mAttachedHidden && mViewVisibility == View.VISIBLE |
| 8008 | && !mRootToken.hidden) |
| Dianne Hackborn | 0cd4887 | 2009-08-13 18:51:59 -0700 | [diff] [blame] | 8009 | || mAnimation != null || animating); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8010 | } |
| 8011 | |
| 8012 | /** Is the window or its container currently animating? */ |
| 8013 | boolean isAnimating() { |
| 8014 | final WindowState attached = mAttachedWindow; |
| 8015 | final AppWindowToken atoken = mAppToken; |
| 8016 | return mAnimation != null |
| 8017 | || (attached != null && attached.mAnimation != null) |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8018 | || (atoken != null && |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8019 | (atoken.animation != null |
| 8020 | || atoken.inPendingTransaction)); |
| 8021 | } |
| 8022 | |
| 8023 | /** Is this window currently animating? */ |
| 8024 | boolean isWindowAnimating() { |
| 8025 | return mAnimation != null; |
| 8026 | } |
| 8027 | |
| 8028 | /** |
| 8029 | * Like isOnScreen, but returns false if the surface hasn't yet |
| 8030 | * been drawn. |
| 8031 | */ |
| 8032 | public boolean isDisplayedLw() { |
| 8033 | final AppWindowToken atoken = mAppToken; |
| 8034 | return mSurface != null && mPolicyVisibility && !mDestroying |
| 8035 | && !mDrawPending && !mCommitDrawPending |
| 8036 | && ((!mAttachedHidden && |
| 8037 | (atoken == null || !atoken.hiddenRequested)) |
| 8038 | || mAnimating); |
| 8039 | } |
| 8040 | |
| Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 8041 | /** |
| 8042 | * Returns true if the window has a surface that it has drawn a |
| 8043 | * complete UI in to. |
| 8044 | */ |
| 8045 | public boolean isDrawnLw() { |
| 8046 | final AppWindowToken atoken = mAppToken; |
| 8047 | return mSurface != null && !mDestroying |
| 8048 | && !mDrawPending && !mCommitDrawPending; |
| 8049 | } |
| 8050 | |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 8051 | /** |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 8052 | * Return true if the window is opaque and fully drawn. This indicates |
| 8053 | * it may obscure windows behind it. |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 8054 | */ |
| 8055 | boolean isOpaqueDrawn() { |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 8056 | return (mAttrs.format == PixelFormat.OPAQUE |
| 8057 | || mAttrs.type == TYPE_WALLPAPER) |
| 8058 | && mSurface != null && mAnimation == null |
| 8059 | && (mAppToken == null || mAppToken.animation == null) |
| 8060 | && !mDrawPending && !mCommitDrawPending; |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 8061 | } |
| 8062 | |
| Dianne Hackborn | 1c24e95 | 2010-11-23 00:34:30 -0800 | [diff] [blame] | 8063 | /** |
| 8064 | * Return whether this window is wanting to have a translation |
| 8065 | * animation applied to it for an in-progress move. (Only makes |
| 8066 | * sense to call from performLayoutAndPlaceSurfacesLockedInner().) |
| 8067 | */ |
| 8068 | boolean shouldAnimateMove() { |
| Dianne Hackborn | 0f761d6 | 2010-11-30 22:06:10 -0800 | [diff] [blame] | 8069 | return mContentChanged && !mExiting && !mLastHidden && !mDisplayFrozen |
| Dianne Hackborn | 1c24e95 | 2010-11-23 00:34:30 -0800 | [diff] [blame] | 8070 | && (mFrame.top != mLastFrame.top |
| 8071 | || mFrame.left != mLastFrame.left) |
| Dianne Hackborn | 0f761d6 | 2010-11-30 22:06:10 -0800 | [diff] [blame] | 8072 | && (mAttachedWindow == null || !mAttachedWindow.shouldAnimateMove()) |
| Dianne Hackborn | 1c24e95 | 2010-11-23 00:34:30 -0800 | [diff] [blame] | 8073 | && mPolicy.isScreenOn(); |
| 8074 | } |
| 8075 | |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 8076 | boolean needsBackgroundFiller(int screenWidth, int screenHeight) { |
| 8077 | return |
| 8078 | // only if the application is requesting compatible window |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 8079 | (mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0 && |
| 8080 | // only if it's visible |
| 8081 | mHasDrawn && mViewVisibility == View.VISIBLE && |
| Mitsuru Oshima | d2967e2 | 2009-07-20 14:01:43 -0700 | [diff] [blame] | 8082 | // and only if the application fills the compatible screen |
| 8083 | mFrame.left <= mCompatibleScreenFrame.left && |
| 8084 | mFrame.top <= mCompatibleScreenFrame.top && |
| 8085 | mFrame.right >= mCompatibleScreenFrame.right && |
| 8086 | mFrame.bottom >= mCompatibleScreenFrame.bottom && |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 8087 | // and starting window do not need background filler |
| Mitsuru Oshima | d2967e2 | 2009-07-20 14:01:43 -0700 | [diff] [blame] | 8088 | mAttrs.type != mAttrs.TYPE_APPLICATION_STARTING; |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 8089 | } |
| 8090 | |
| 8091 | boolean isFullscreen(int screenWidth, int screenHeight) { |
| 8092 | return mFrame.left <= 0 && mFrame.top <= 0 && |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 8093 | mFrame.right >= screenWidth && mFrame.bottom >= screenHeight; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8094 | } |
| 8095 | |
| 8096 | void removeLocked() { |
| Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 8097 | disposeInputChannel(); |
| 8098 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8099 | if (mAttachedWindow != null) { |
| Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 8100 | 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] | 8101 | mAttachedWindow.mChildWindows.remove(this); |
| 8102 | } |
| 8103 | destroySurfaceLocked(); |
| 8104 | mSession.windowRemovedLocked(); |
| 8105 | try { |
| 8106 | mClient.asBinder().unlinkToDeath(mDeathRecipient, 0); |
| 8107 | } catch (RuntimeException e) { |
| 8108 | // Ignore if it has already been removed (usually because |
| 8109 | // we are doing this as part of processing a death note.) |
| 8110 | } |
| Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 8111 | } |
| 8112 | |
| 8113 | void disposeInputChannel() { |
| Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 8114 | if (mInputChannel != null) { |
| 8115 | mInputManager.unregisterInputChannel(mInputChannel); |
| 8116 | |
| 8117 | mInputChannel.dispose(); |
| 8118 | mInputChannel = null; |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 8119 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8120 | } |
| 8121 | |
| 8122 | private class DeathRecipient implements IBinder.DeathRecipient { |
| 8123 | public void binderDied() { |
| 8124 | try { |
| 8125 | synchronized(mWindowMap) { |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 8126 | WindowState win = windowForClientLocked(mSession, mClient, false); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8127 | Slog.i(TAG, "WIN DEATH: " + win); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8128 | if (win != null) { |
| 8129 | removeWindowLocked(mSession, win); |
| 8130 | } |
| 8131 | } |
| 8132 | } catch (IllegalArgumentException ex) { |
| 8133 | // This will happen if the window has already been |
| 8134 | // removed. |
| 8135 | } |
| 8136 | } |
| 8137 | } |
| 8138 | |
| 8139 | /** Returns true if this window desires key events. */ |
| 8140 | public final boolean canReceiveKeys() { |
| 8141 | return isVisibleOrAdding() |
| 8142 | && (mViewVisibility == View.VISIBLE) |
| 8143 | && ((mAttrs.flags & WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) == 0); |
| 8144 | } |
| 8145 | |
| 8146 | public boolean hasDrawnLw() { |
| 8147 | return mHasDrawn; |
| 8148 | } |
| 8149 | |
| 8150 | public boolean showLw(boolean doAnimation) { |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8151 | return showLw(doAnimation, true); |
| 8152 | } |
| 8153 | |
| 8154 | boolean showLw(boolean doAnimation, boolean requestAnim) { |
| 8155 | if (mPolicyVisibility && mPolicyVisibilityAfterAnim) { |
| 8156 | return false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8157 | } |
| Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 8158 | if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility true: " + this); |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 8159 | if (doAnimation) { |
| 8160 | if (DEBUG_VISIBILITY) Slog.v(TAG, "doAnimation: mPolicyVisibility=" |
| 8161 | + mPolicyVisibility + " mAnimation=" + mAnimation); |
| 8162 | if (mDisplayFrozen || !mPolicy.isScreenOn()) { |
| 8163 | doAnimation = false; |
| 8164 | } else if (mPolicyVisibility && mAnimation == null) { |
| 8165 | // Check for the case where we are currently visible and |
| 8166 | // not animating; we do not want to do animation at such a |
| 8167 | // point to become visible when we already are. |
| 8168 | doAnimation = false; |
| 8169 | } |
| 8170 | } |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8171 | mPolicyVisibility = true; |
| 8172 | mPolicyVisibilityAfterAnim = true; |
| 8173 | if (doAnimation) { |
| 8174 | applyAnimationLocked(this, WindowManagerPolicy.TRANSIT_ENTER, true); |
| 8175 | } |
| 8176 | if (requestAnim) { |
| 8177 | requestAnimationLocked(0); |
| 8178 | } |
| 8179 | return true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8180 | } |
| 8181 | |
| 8182 | public boolean hideLw(boolean doAnimation) { |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8183 | return hideLw(doAnimation, true); |
| 8184 | } |
| 8185 | |
| 8186 | boolean hideLw(boolean doAnimation, boolean requestAnim) { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 8187 | if (doAnimation) { |
| 8188 | if (mDisplayFrozen || !mPolicy.isScreenOn()) { |
| 8189 | doAnimation = false; |
| 8190 | } |
| 8191 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8192 | boolean current = doAnimation ? mPolicyVisibilityAfterAnim |
| 8193 | : mPolicyVisibility; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8194 | if (!current) { |
| 8195 | return false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8196 | } |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8197 | if (doAnimation) { |
| 8198 | applyAnimationLocked(this, WindowManagerPolicy.TRANSIT_EXIT, false); |
| 8199 | if (mAnimation == null) { |
| 8200 | doAnimation = false; |
| 8201 | } |
| 8202 | } |
| 8203 | if (doAnimation) { |
| 8204 | mPolicyVisibilityAfterAnim = false; |
| 8205 | } else { |
| Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 8206 | if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility false: " + this); |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8207 | mPolicyVisibilityAfterAnim = false; |
| 8208 | mPolicyVisibility = false; |
| Dianne Hackborn | f3bea9c | 2009-12-09 18:26:21 -0800 | [diff] [blame] | 8209 | // Window is no longer visible -- make sure if we were waiting |
| 8210 | // for it to be displayed before enabling the display, that |
| 8211 | // we allow the display to be enabled now. |
| 8212 | enableScreenIfNeededLocked(); |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 8213 | if (mCurrentFocus == this) { |
| 8214 | mFocusMayChange = true; |
| 8215 | } |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 8216 | } |
| 8217 | if (requestAnim) { |
| 8218 | requestAnimationLocked(0); |
| 8219 | } |
| 8220 | return true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8221 | } |
| 8222 | |
| Jeff Brown | fbf0977 | 2011-01-16 14:06:57 -0800 | [diff] [blame] | 8223 | public void getTouchableRegion(Region outRegion) { |
| 8224 | final Rect frame = mFrame; |
| 8225 | switch (mTouchableInsets) { |
| 8226 | default: |
| 8227 | case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME: |
| 8228 | outRegion.set(frame); |
| 8229 | break; |
| 8230 | case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_CONTENT: { |
| 8231 | final Rect inset = mGivenContentInsets; |
| 8232 | outRegion.set( |
| 8233 | frame.left + inset.left, frame.top + inset.top, |
| 8234 | frame.right - inset.right, frame.bottom - inset.bottom); |
| 8235 | break; |
| 8236 | } |
| 8237 | case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_VISIBLE: { |
| 8238 | final Rect inset = mGivenVisibleInsets; |
| 8239 | outRegion.set( |
| 8240 | frame.left + inset.left, frame.top + inset.top, |
| 8241 | frame.right - inset.right, frame.bottom - inset.bottom); |
| 8242 | break; |
| 8243 | } |
| 8244 | case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_REGION: { |
| 8245 | final Region givenTouchableRegion = mGivenTouchableRegion; |
| 8246 | outRegion.set(givenTouchableRegion); |
| 8247 | outRegion.translate(frame.left, frame.top); |
| 8248 | break; |
| 8249 | } |
| 8250 | } |
| 8251 | } |
| 8252 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8253 | void dump(PrintWriter pw, String prefix) { |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8254 | pw.print(prefix); pw.print("mSession="); pw.print(mSession); |
| 8255 | pw.print(" mClient="); pw.println(mClient.asBinder()); |
| 8256 | pw.print(prefix); pw.print("mAttrs="); pw.println(mAttrs); |
| 8257 | if (mAttachedWindow != null || mLayoutAttached) { |
| 8258 | pw.print(prefix); pw.print("mAttachedWindow="); pw.print(mAttachedWindow); |
| 8259 | pw.print(" mLayoutAttached="); pw.println(mLayoutAttached); |
| 8260 | } |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 8261 | if (mIsImWindow || mIsWallpaper || mIsFloatingLayer) { |
| 8262 | pw.print(prefix); pw.print("mIsImWindow="); pw.print(mIsImWindow); |
| 8263 | pw.print(" mIsWallpaper="); pw.print(mIsWallpaper); |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 8264 | pw.print(" mIsFloatingLayer="); pw.print(mIsFloatingLayer); |
| 8265 | pw.print(" mWallpaperVisible="); pw.println(mWallpaperVisible); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8266 | } |
| 8267 | pw.print(prefix); pw.print("mBaseLayer="); pw.print(mBaseLayer); |
| 8268 | pw.print(" mSubLayer="); pw.print(mSubLayer); |
| 8269 | pw.print(" mAnimLayer="); pw.print(mLayer); pw.print("+"); |
| 8270 | pw.print((mTargetAppToken != null ? mTargetAppToken.animLayerAdjustment |
| 8271 | : (mAppToken != null ? mAppToken.animLayerAdjustment : 0))); |
| 8272 | pw.print("="); pw.print(mAnimLayer); |
| 8273 | pw.print(" mLastLayer="); pw.println(mLastLayer); |
| 8274 | if (mSurface != null) { |
| 8275 | pw.print(prefix); pw.print("mSurface="); pw.println(mSurface); |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 8276 | pw.print(prefix); pw.print("Surface: shown="); pw.print(mSurfaceShown); |
| 8277 | pw.print(" layer="); pw.print(mSurfaceLayer); |
| 8278 | pw.print(" alpha="); pw.print(mSurfaceAlpha); |
| 8279 | pw.print(" rect=("); pw.print(mSurfaceX); |
| 8280 | pw.print(","); pw.print(mSurfaceY); |
| 8281 | pw.print(") "); pw.print(mSurfaceW); |
| 8282 | pw.print(" x "); pw.println(mSurfaceH); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8283 | } |
| 8284 | pw.print(prefix); pw.print("mToken="); pw.println(mToken); |
| 8285 | pw.print(prefix); pw.print("mRootToken="); pw.println(mRootToken); |
| 8286 | if (mAppToken != null) { |
| 8287 | pw.print(prefix); pw.print("mAppToken="); pw.println(mAppToken); |
| 8288 | } |
| 8289 | if (mTargetAppToken != null) { |
| 8290 | pw.print(prefix); pw.print("mTargetAppToken="); pw.println(mTargetAppToken); |
| 8291 | } |
| 8292 | pw.print(prefix); pw.print("mViewVisibility=0x"); |
| 8293 | pw.print(Integer.toHexString(mViewVisibility)); |
| 8294 | pw.print(" mLastHidden="); pw.print(mLastHidden); |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 8295 | pw.print(" mHaveFrame="); pw.print(mHaveFrame); |
| 8296 | pw.print(" mObscured="); pw.println(mObscured); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8297 | if (!mPolicyVisibility || !mPolicyVisibilityAfterAnim || mAttachedHidden) { |
| 8298 | pw.print(prefix); pw.print("mPolicyVisibility="); |
| 8299 | pw.print(mPolicyVisibility); |
| 8300 | pw.print(" mPolicyVisibilityAfterAnim="); |
| 8301 | pw.print(mPolicyVisibilityAfterAnim); |
| 8302 | pw.print(" mAttachedHidden="); pw.println(mAttachedHidden); |
| 8303 | } |
| Dianne Hackborn | 9b52a21 | 2009-12-11 14:51:35 -0800 | [diff] [blame] | 8304 | if (!mRelayoutCalled) { |
| 8305 | pw.print(prefix); pw.print("mRelayoutCalled="); pw.println(mRelayoutCalled); |
| 8306 | } |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8307 | pw.print(prefix); pw.print("Requested w="); pw.print(mRequestedWidth); |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 8308 | pw.print(" h="); pw.print(mRequestedHeight); |
| 8309 | pw.print(" mLayoutSeq="); pw.println(mLayoutSeq); |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 8310 | if (mXOffset != 0 || mYOffset != 0) { |
| 8311 | pw.print(prefix); pw.print("Offsets x="); pw.print(mXOffset); |
| 8312 | pw.print(" y="); pw.println(mYOffset); |
| 8313 | } |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8314 | pw.print(prefix); pw.print("mGivenContentInsets="); |
| 8315 | mGivenContentInsets.printShortString(pw); |
| 8316 | pw.print(" mGivenVisibleInsets="); |
| 8317 | mGivenVisibleInsets.printShortString(pw); |
| 8318 | pw.println(); |
| 8319 | if (mTouchableInsets != 0 || mGivenInsetsPending) { |
| 8320 | pw.print(prefix); pw.print("mTouchableInsets="); pw.print(mTouchableInsets); |
| 8321 | pw.print(" mGivenInsetsPending="); pw.println(mGivenInsetsPending); |
| 8322 | } |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 8323 | pw.print(prefix); pw.print("mConfiguration="); pw.println(mConfiguration); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8324 | pw.print(prefix); pw.print("mShownFrame="); |
| 8325 | mShownFrame.printShortString(pw); |
| 8326 | pw.print(" last="); mLastShownFrame.printShortString(pw); |
| 8327 | pw.println(); |
| 8328 | pw.print(prefix); pw.print("mFrame="); mFrame.printShortString(pw); |
| 8329 | pw.print(" last="); mLastFrame.printShortString(pw); |
| 8330 | pw.println(); |
| 8331 | pw.print(prefix); pw.print("mContainingFrame="); |
| 8332 | mContainingFrame.printShortString(pw); |
| Dianne Hackborn | 1c24e95 | 2010-11-23 00:34:30 -0800 | [diff] [blame] | 8333 | pw.print(" mParentFrame="); |
| 8334 | mParentFrame.printShortString(pw); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8335 | pw.print(" mDisplayFrame="); |
| 8336 | mDisplayFrame.printShortString(pw); |
| 8337 | pw.println(); |
| 8338 | pw.print(prefix); pw.print("mContentFrame="); mContentFrame.printShortString(pw); |
| 8339 | pw.print(" mVisibleFrame="); mVisibleFrame.printShortString(pw); |
| 8340 | pw.println(); |
| 8341 | pw.print(prefix); pw.print("mContentInsets="); mContentInsets.printShortString(pw); |
| 8342 | pw.print(" last="); mLastContentInsets.printShortString(pw); |
| 8343 | pw.print(" mVisibleInsets="); mVisibleInsets.printShortString(pw); |
| 8344 | pw.print(" last="); mLastVisibleInsets.printShortString(pw); |
| 8345 | pw.println(); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8346 | if (mAnimating || mLocalAnimating || mAnimationIsEntrance |
| 8347 | || mAnimation != null) { |
| 8348 | pw.print(prefix); pw.print("mAnimating="); pw.print(mAnimating); |
| 8349 | pw.print(" mLocalAnimating="); pw.print(mLocalAnimating); |
| 8350 | pw.print(" mAnimationIsEntrance="); pw.print(mAnimationIsEntrance); |
| 8351 | pw.print(" mAnimation="); pw.println(mAnimation); |
| 8352 | } |
| 8353 | if (mHasTransformation || mHasLocalTransformation) { |
| 8354 | pw.print(prefix); pw.print("XForm: has="); |
| 8355 | pw.print(mHasTransformation); |
| 8356 | pw.print(" hasLocal="); pw.print(mHasLocalTransformation); |
| 8357 | pw.print(" "); mTransformation.printShortString(pw); |
| 8358 | pw.println(); |
| 8359 | } |
| Dianne Hackborn | 7da6ac3 | 2010-12-09 19:22:04 -0800 | [diff] [blame] | 8360 | if (mShownAlpha != 1 || mAlpha != 1 || mLastAlpha != 1) { |
| 8361 | pw.print(prefix); pw.print("mShownAlpha="); pw.print(mShownAlpha); |
| 8362 | pw.print(" mAlpha="); pw.print(mAlpha); |
| 8363 | pw.print(" mLastAlpha="); pw.println(mLastAlpha); |
| 8364 | } |
| 8365 | if (mHaveMatrix) { |
| 8366 | pw.print(prefix); pw.print("mDsDx="); pw.print(mDsDx); |
| 8367 | pw.print(" mDtDx="); pw.print(mDtDx); |
| 8368 | pw.print(" mDsDy="); pw.print(mDsDy); |
| 8369 | pw.print(" mDtDy="); pw.println(mDtDy); |
| 8370 | } |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8371 | pw.print(prefix); pw.print("mDrawPending="); pw.print(mDrawPending); |
| 8372 | pw.print(" mCommitDrawPending="); pw.print(mCommitDrawPending); |
| 8373 | pw.print(" mReadyToShow="); pw.print(mReadyToShow); |
| 8374 | pw.print(" mHasDrawn="); pw.println(mHasDrawn); |
| 8375 | if (mExiting || mRemoveOnExit || mDestroying || mRemoved) { |
| 8376 | pw.print(prefix); pw.print("mExiting="); pw.print(mExiting); |
| 8377 | pw.print(" mRemoveOnExit="); pw.print(mRemoveOnExit); |
| 8378 | pw.print(" mDestroying="); pw.print(mDestroying); |
| 8379 | pw.print(" mRemoved="); pw.println(mRemoved); |
| 8380 | } |
| Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 8381 | if (mOrientationChanging || mAppFreezing || mTurnOnScreen) { |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8382 | pw.print(prefix); pw.print("mOrientationChanging="); |
| 8383 | pw.print(mOrientationChanging); |
| Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 8384 | pw.print(" mAppFreezing="); pw.print(mAppFreezing); |
| 8385 | pw.print(" mTurnOnScreen="); pw.println(mTurnOnScreen); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8386 | } |
| Mitsuru Oshima | 589cebe | 2009-07-22 20:38:58 -0700 | [diff] [blame] | 8387 | if (mHScale != 1 || mVScale != 1) { |
| 8388 | pw.print(prefix); pw.print("mHScale="); pw.print(mHScale); |
| 8389 | pw.print(" mVScale="); pw.println(mVScale); |
| 8390 | } |
| Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 8391 | if (mWallpaperX != -1 || mWallpaperY != -1) { |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 8392 | pw.print(prefix); pw.print("mWallpaperX="); pw.print(mWallpaperX); |
| 8393 | pw.print(" mWallpaperY="); pw.println(mWallpaperY); |
| 8394 | } |
| Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 8395 | if (mWallpaperXStep != -1 || mWallpaperYStep != -1) { |
| 8396 | pw.print(prefix); pw.print("mWallpaperXStep="); pw.print(mWallpaperXStep); |
| 8397 | pw.print(" mWallpaperYStep="); pw.println(mWallpaperYStep); |
| 8398 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8399 | } |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 8400 | |
| 8401 | String makeInputChannelName() { |
| 8402 | return Integer.toHexString(System.identityHashCode(this)) |
| 8403 | + " " + mAttrs.getTitle(); |
| 8404 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8405 | |
| 8406 | @Override |
| 8407 | public String toString() { |
| Mattias Petersson | 1622eee | 2010-12-21 10:15:11 +0100 | [diff] [blame] | 8408 | if (mStringNameCache == null || mLastTitle != mAttrs.getTitle() |
| 8409 | || mWasPaused != mToken.paused) { |
| 8410 | mLastTitle = mAttrs.getTitle(); |
| 8411 | mWasPaused = mToken.paused; |
| 8412 | mStringNameCache = "Window{" + Integer.toHexString(System.identityHashCode(this)) |
| 8413 | + " " + mLastTitle + " paused=" + mWasPaused + "}"; |
| 8414 | } |
| 8415 | return mStringNameCache; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8416 | } |
| 8417 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8418 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8419 | // ------------------------------------------------------------- |
| 8420 | // Window Token State |
| 8421 | // ------------------------------------------------------------- |
| 8422 | |
| 8423 | class WindowToken { |
| 8424 | // The actual token. |
| 8425 | final IBinder token; |
| 8426 | |
| 8427 | // The type of window this token is for, as per WindowManager.LayoutParams. |
| 8428 | final int windowType; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8429 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8430 | // Set if this token was explicitly added by a client, so should |
| 8431 | // not be removed when all windows are removed. |
| 8432 | final boolean explicit; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8433 | |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8434 | // For printing. |
| 8435 | String stringName; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8436 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8437 | // If this is an AppWindowToken, this is non-null. |
| 8438 | AppWindowToken appWindowToken; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8439 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8440 | // All of the windows associated with this token. |
| 8441 | final ArrayList<WindowState> windows = new ArrayList<WindowState>(); |
| 8442 | |
| 8443 | // Is key dispatching paused for this token? |
| 8444 | boolean paused = false; |
| 8445 | |
| 8446 | // Should this token's windows be hidden? |
| 8447 | boolean hidden; |
| 8448 | |
| 8449 | // Temporary for finding which tokens no longer have visible windows. |
| 8450 | boolean hasVisible; |
| 8451 | |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8452 | // Set to true when this token is in a pending transaction where it |
| 8453 | // will be shown. |
| 8454 | boolean waitingToShow; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8455 | |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8456 | // Set to true when this token is in a pending transaction where it |
| 8457 | // will be hidden. |
| 8458 | boolean waitingToHide; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8459 | |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8460 | // Set to true when this token is in a pending transaction where its |
| 8461 | // windows will be put to the bottom of the list. |
| 8462 | boolean sendingToBottom; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8463 | |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8464 | // Set to true when this token is in a pending transaction where its |
| 8465 | // windows will be put to the top of the list. |
| 8466 | boolean sendingToTop; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8467 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8468 | WindowToken(IBinder _token, int type, boolean _explicit) { |
| 8469 | token = _token; |
| 8470 | windowType = type; |
| 8471 | explicit = _explicit; |
| 8472 | } |
| 8473 | |
| 8474 | void dump(PrintWriter pw, String prefix) { |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8475 | pw.print(prefix); pw.print("token="); pw.println(token); |
| 8476 | pw.print(prefix); pw.print("windows="); pw.println(windows); |
| 8477 | pw.print(prefix); pw.print("windowType="); pw.print(windowType); |
| 8478 | pw.print(" hidden="); pw.print(hidden); |
| 8479 | pw.print(" hasVisible="); pw.println(hasVisible); |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8480 | if (waitingToShow || waitingToHide || sendingToBottom || sendingToTop) { |
| 8481 | pw.print(prefix); pw.print("waitingToShow="); pw.print(waitingToShow); |
| 8482 | pw.print(" waitingToHide="); pw.print(waitingToHide); |
| 8483 | pw.print(" sendingToBottom="); pw.print(sendingToBottom); |
| 8484 | pw.print(" sendingToTop="); pw.println(sendingToTop); |
| 8485 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8486 | } |
| 8487 | |
| 8488 | @Override |
| 8489 | public String toString() { |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8490 | if (stringName == null) { |
| 8491 | StringBuilder sb = new StringBuilder(); |
| 8492 | sb.append("WindowToken{"); |
| 8493 | sb.append(Integer.toHexString(System.identityHashCode(this))); |
| 8494 | sb.append(" token="); sb.append(token); sb.append('}'); |
| 8495 | stringName = sb.toString(); |
| 8496 | } |
| 8497 | return stringName; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8498 | } |
| 8499 | }; |
| 8500 | |
| 8501 | class AppWindowToken extends WindowToken { |
| 8502 | // Non-null only for application tokens. |
| 8503 | final IApplicationToken appToken; |
| 8504 | |
| 8505 | // All of the windows and child windows that are included in this |
| 8506 | // application token. Note this list is NOT sorted! |
| 8507 | final ArrayList<WindowState> allAppWindows = new ArrayList<WindowState>(); |
| 8508 | |
| 8509 | int groupId = -1; |
| 8510 | boolean appFullscreen; |
| 8511 | int requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 8512 | |
| 8513 | // The input dispatching timeout for this application token in nanoseconds. |
| 8514 | long inputDispatchingTimeoutNanos; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8515 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8516 | // These are used for determining when all windows associated with |
| 8517 | // an activity have been drawn, so they can be made visible together |
| 8518 | // at the same time. |
| 8519 | int lastTransactionSequence = mTransactionSequence-1; |
| 8520 | int numInterestingWindows; |
| 8521 | int numDrawnWindows; |
| 8522 | boolean inPendingTransaction; |
| 8523 | boolean allDrawn; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8524 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8525 | // Is this token going to be hidden in a little while? If so, it |
| 8526 | // won't be taken into account for setting the screen orientation. |
| 8527 | boolean willBeHidden; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8528 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8529 | // Is this window's surface needed? This is almost like hidden, except |
| 8530 | // it will sometimes be true a little earlier: when the token has |
| 8531 | // been shown, but is still waiting for its app transition to execute |
| 8532 | // before making its windows shown. |
| 8533 | boolean hiddenRequested; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8534 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8535 | // Have we told the window clients to hide themselves? |
| 8536 | boolean clientHidden; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8537 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8538 | // Last visibility state we reported to the app token. |
| 8539 | boolean reportedVisible; |
| 8540 | |
| 8541 | // Set to true when the token has been removed from the window mgr. |
| 8542 | boolean removed; |
| 8543 | |
| 8544 | // Have we been asked to have this token keep the screen frozen? |
| 8545 | boolean freezingScreen; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8546 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8547 | boolean animating; |
| 8548 | Animation animation; |
| 8549 | boolean hasTransformation; |
| 8550 | final Transformation transformation = new Transformation(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8551 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8552 | // Offset to the window of all layers in the token, for use by |
| 8553 | // AppWindowToken animations. |
| 8554 | int animLayerAdjustment; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8555 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8556 | // Information about an application starting window if displayed. |
| 8557 | StartingData startingData; |
| 8558 | WindowState startingWindow; |
| 8559 | View startingView; |
| 8560 | boolean startingDisplayed; |
| 8561 | boolean startingMoved; |
| 8562 | boolean firstWindowDrawn; |
| 8563 | |
| Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame] | 8564 | // Input application handle used by the input dispatcher. |
| 8565 | InputApplicationHandle mInputApplicationHandle; |
| 8566 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8567 | AppWindowToken(IApplicationToken _token) { |
| 8568 | super(_token.asBinder(), |
| 8569 | WindowManager.LayoutParams.TYPE_APPLICATION, true); |
| 8570 | appWindowToken = this; |
| 8571 | appToken = _token; |
| Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame] | 8572 | mInputApplicationHandle = new InputApplicationHandle(this); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8573 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8574 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8575 | public void setAnimation(Animation anim) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8576 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8577 | TAG, "Setting animation in " + this + ": " + anim); |
| 8578 | animation = anim; |
| 8579 | animating = false; |
| 8580 | anim.restrictDuration(MAX_ANIMATION_DURATION); |
| 8581 | anim.scaleCurrentDuration(mTransitionAnimationScale); |
| 8582 | int zorder = anim.getZAdjustment(); |
| 8583 | int adj = 0; |
| 8584 | if (zorder == Animation.ZORDER_TOP) { |
| 8585 | adj = TYPE_LAYER_OFFSET; |
| 8586 | } else if (zorder == Animation.ZORDER_BOTTOM) { |
| 8587 | adj = -TYPE_LAYER_OFFSET; |
| 8588 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8589 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8590 | if (animLayerAdjustment != adj) { |
| 8591 | animLayerAdjustment = adj; |
| 8592 | updateLayers(); |
| 8593 | } |
| 8594 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8595 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8596 | public void setDummyAnimation() { |
| 8597 | if (animation == null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8598 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8599 | TAG, "Setting dummy animation in " + this); |
| 8600 | animation = sDummyAnimation; |
| 8601 | } |
| 8602 | } |
| 8603 | |
| 8604 | public void clearAnimation() { |
| 8605 | if (animation != null) { |
| 8606 | animation = null; |
| 8607 | animating = true; |
| 8608 | } |
| 8609 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8610 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8611 | void updateLayers() { |
| 8612 | final int N = allAppWindows.size(); |
| 8613 | final int adj = animLayerAdjustment; |
| 8614 | for (int i=0; i<N; i++) { |
| 8615 | WindowState w = allAppWindows.get(i); |
| 8616 | w.mAnimLayer = w.mLayer + adj; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8617 | if (DEBUG_LAYERS) Slog.v(TAG, "Updating layer " + w + ": " |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8618 | + w.mAnimLayer); |
| Dianne Hackborn | e75d872 | 2011-01-27 19:37:40 -0800 | [diff] [blame] | 8619 | if (w == mInputMethodTarget && !mInputMethodTargetWaitingAnim) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8620 | setInputMethodAnimLayerAdjustment(adj); |
| 8621 | } |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 8622 | if (w == mWallpaperTarget && mLowerWallpaperTarget == null) { |
| Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 8623 | setWallpaperAnimLayerAdjustmentLocked(adj); |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 8624 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8625 | } |
| 8626 | } |
| 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 | void sendAppVisibilityToClients() { |
| 8629 | final int N = allAppWindows.size(); |
| 8630 | for (int i=0; i<N; i++) { |
| 8631 | WindowState win = allAppWindows.get(i); |
| 8632 | if (win == startingWindow && clientHidden) { |
| 8633 | // Don't hide the starting window. |
| 8634 | continue; |
| 8635 | } |
| 8636 | try { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8637 | if (DEBUG_VISIBILITY) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8638 | "Setting visibility of " + win + ": " + (!clientHidden)); |
| 8639 | win.mClient.dispatchAppVisibility(!clientHidden); |
| 8640 | } catch (RemoteException e) { |
| 8641 | } |
| 8642 | } |
| 8643 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8644 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8645 | void showAllWindowsLocked() { |
| 8646 | final int NW = allAppWindows.size(); |
| 8647 | for (int i=0; i<NW; i++) { |
| 8648 | WindowState w = allAppWindows.get(i); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8649 | if (DEBUG_VISIBILITY) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8650 | "performing show on: " + w); |
| 8651 | w.performShowLocked(); |
| 8652 | } |
| 8653 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8654 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8655 | // This must be called while inside a transaction. |
| 8656 | boolean stepAnimationLocked(long currentTime, int dw, int dh) { |
| Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 8657 | if (!mDisplayFrozen && mPolicy.isScreenOn()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8658 | // We will run animations as long as the display isn't frozen. |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8659 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8660 | if (animation == sDummyAnimation) { |
| 8661 | // This guy is going to animate, but not yet. For now count |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 8662 | // it as not animating for purposes of scheduling transactions; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8663 | // when it is really time to animate, this will be set to |
| 8664 | // a real animation and the next call will execute normally. |
| 8665 | return false; |
| 8666 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8667 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8668 | if ((allDrawn || animating || startingDisplayed) && animation != null) { |
| 8669 | if (!animating) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8670 | if (DEBUG_ANIM) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8671 | TAG, "Starting animation in " + this + |
| 8672 | " @ " + currentTime + ": dw=" + dw + " dh=" + dh |
| 8673 | + " scale=" + mTransitionAnimationScale |
| 8674 | + " allDrawn=" + allDrawn + " animating=" + animating); |
| 8675 | animation.initialize(dw, dh, dw, dh); |
| 8676 | animation.setStartTime(currentTime); |
| 8677 | animating = true; |
| 8678 | } |
| 8679 | transformation.clear(); |
| 8680 | final boolean more = animation.getTransformation( |
| 8681 | currentTime, transformation); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8682 | if (DEBUG_ANIM) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8683 | TAG, "Stepped animation in " + this + |
| 8684 | ": more=" + more + ", xform=" + transformation); |
| 8685 | if (more) { |
| 8686 | // we're done! |
| 8687 | hasTransformation = true; |
| 8688 | return true; |
| 8689 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8690 | if (DEBUG_ANIM) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8691 | TAG, "Finished animation in " + this + |
| 8692 | " @ " + currentTime); |
| 8693 | animation = null; |
| 8694 | } |
| 8695 | } else if (animation != null) { |
| 8696 | // If the display is frozen, and there is a pending animation, |
| 8697 | // clear it and make sure we run the cleanup code. |
| 8698 | animating = true; |
| 8699 | animation = null; |
| 8700 | } |
| 8701 | |
| 8702 | hasTransformation = false; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8703 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8704 | if (!animating) { |
| 8705 | return false; |
| 8706 | } |
| 8707 | |
| 8708 | clearAnimation(); |
| 8709 | animating = false; |
| Dianne Hackborn | e75d872 | 2011-01-27 19:37:40 -0800 | [diff] [blame] | 8710 | if (animLayerAdjustment != 0) { |
| 8711 | animLayerAdjustment = 0; |
| 8712 | updateLayers(); |
| 8713 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8714 | if (mInputMethodTarget != null && mInputMethodTarget.mAppToken == this) { |
| 8715 | moveInputMethodWindowsIfNeededLocked(true); |
| 8716 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8717 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8718 | if (DEBUG_ANIM) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8719 | TAG, "Animation done in " + this |
| 8720 | + ": reportedVisible=" + reportedVisible); |
| 8721 | |
| 8722 | transformation.clear(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8723 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8724 | final int N = windows.size(); |
| 8725 | for (int i=0; i<N; i++) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 8726 | windows.get(i).finishExit(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8727 | } |
| 8728 | updateReportedVisibilityLocked(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8729 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8730 | return false; |
| 8731 | } |
| 8732 | |
| 8733 | void updateReportedVisibilityLocked() { |
| 8734 | if (appToken == null) { |
| 8735 | return; |
| 8736 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8737 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8738 | int numInteresting = 0; |
| 8739 | int numVisible = 0; |
| 8740 | boolean nowGone = true; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8741 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8742 | 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] | 8743 | final int N = allAppWindows.size(); |
| 8744 | for (int i=0; i<N; i++) { |
| 8745 | WindowState win = allAppWindows.get(i); |
| Dianne Hackborn | 6cf67fa | 2009-12-21 16:46:34 -0800 | [diff] [blame] | 8746 | if (win == startingWindow || win.mAppFreezing |
| The Android Open Source Project | 727cec0 | 2010-04-08 11:35:37 -0700 | [diff] [blame] | 8747 | || win.mViewVisibility != View.VISIBLE |
| Ulf Rosdahl | 3935770 | 2010-09-29 12:34:38 +0200 | [diff] [blame] | 8748 | || win.mAttrs.type == TYPE_APPLICATION_STARTING |
| 8749 | || win.mDestroying) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8750 | continue; |
| 8751 | } |
| 8752 | if (DEBUG_VISIBILITY) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8753 | Slog.v(TAG, "Win " + win + ": isDrawn=" |
| Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 8754 | + win.isDrawnLw() |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8755 | + ", isAnimating=" + win.isAnimating()); |
| Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 8756 | if (!win.isDrawnLw()) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8757 | Slog.v(TAG, "Not displayed: s=" + win.mSurface |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8758 | + " pv=" + win.mPolicyVisibility |
| 8759 | + " dp=" + win.mDrawPending |
| 8760 | + " cdp=" + win.mCommitDrawPending |
| 8761 | + " ah=" + win.mAttachedHidden |
| 8762 | + " th=" |
| 8763 | + (win.mAppToken != null |
| 8764 | ? win.mAppToken.hiddenRequested : false) |
| 8765 | + " a=" + win.mAnimating); |
| 8766 | } |
| 8767 | } |
| 8768 | numInteresting++; |
| Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 8769 | if (win.isDrawnLw()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8770 | if (!win.isAnimating()) { |
| 8771 | numVisible++; |
| 8772 | } |
| 8773 | nowGone = false; |
| 8774 | } else if (win.isAnimating()) { |
| 8775 | nowGone = false; |
| 8776 | } |
| 8777 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8778 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8779 | boolean nowVisible = numInteresting > 0 && numVisible >= numInteresting; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8780 | if (DEBUG_VISIBILITY) Slog.v(TAG, "VIS " + this + ": interesting=" |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8781 | + numInteresting + " visible=" + numVisible); |
| 8782 | if (nowVisible != reportedVisible) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8783 | if (DEBUG_VISIBILITY) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8784 | TAG, "Visibility changed in " + this |
| 8785 | + ": vis=" + nowVisible); |
| 8786 | reportedVisible = nowVisible; |
| 8787 | Message m = mH.obtainMessage( |
| 8788 | H.REPORT_APPLICATION_TOKEN_WINDOWS, |
| 8789 | nowVisible ? 1 : 0, |
| 8790 | nowGone ? 1 : 0, |
| 8791 | this); |
| 8792 | mH.sendMessage(m); |
| 8793 | } |
| 8794 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8795 | |
| Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 8796 | WindowState findMainWindow() { |
| 8797 | int j = windows.size(); |
| 8798 | while (j > 0) { |
| 8799 | j--; |
| 8800 | WindowState win = windows.get(j); |
| 8801 | if (win.mAttrs.type == WindowManager.LayoutParams.TYPE_BASE_APPLICATION |
| 8802 | || win.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING) { |
| 8803 | return win; |
| 8804 | } |
| 8805 | } |
| 8806 | return null; |
| 8807 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8808 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8809 | void dump(PrintWriter pw, String prefix) { |
| 8810 | super.dump(pw, prefix); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8811 | if (appToken != null) { |
| 8812 | pw.print(prefix); pw.println("app=true"); |
| 8813 | } |
| 8814 | if (allAppWindows.size() > 0) { |
| 8815 | pw.print(prefix); pw.print("allAppWindows="); pw.println(allAppWindows); |
| 8816 | } |
| 8817 | pw.print(prefix); pw.print("groupId="); pw.print(groupId); |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 8818 | pw.print(" appFullscreen="); pw.print(appFullscreen); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8819 | pw.print(" requestedOrientation="); pw.println(requestedOrientation); |
| 8820 | pw.print(prefix); pw.print("hiddenRequested="); pw.print(hiddenRequested); |
| 8821 | pw.print(" clientHidden="); pw.print(clientHidden); |
| 8822 | pw.print(" willBeHidden="); pw.print(willBeHidden); |
| 8823 | pw.print(" reportedVisible="); pw.println(reportedVisible); |
| 8824 | if (paused || freezingScreen) { |
| 8825 | pw.print(prefix); pw.print("paused="); pw.print(paused); |
| 8826 | pw.print(" freezingScreen="); pw.println(freezingScreen); |
| 8827 | } |
| 8828 | if (numInterestingWindows != 0 || numDrawnWindows != 0 |
| 8829 | || inPendingTransaction || allDrawn) { |
| 8830 | pw.print(prefix); pw.print("numInterestingWindows="); |
| 8831 | pw.print(numInterestingWindows); |
| 8832 | pw.print(" numDrawnWindows="); pw.print(numDrawnWindows); |
| 8833 | pw.print(" inPendingTransaction="); pw.print(inPendingTransaction); |
| 8834 | pw.print(" allDrawn="); pw.println(allDrawn); |
| 8835 | } |
| 8836 | if (animating || animation != null) { |
| 8837 | pw.print(prefix); pw.print("animating="); pw.print(animating); |
| 8838 | pw.print(" animation="); pw.println(animation); |
| 8839 | } |
| Dianne Hackborn | 7da6ac3 | 2010-12-09 19:22:04 -0800 | [diff] [blame] | 8840 | if (hasTransformation) { |
| 8841 | pw.print(prefix); pw.print("XForm: "); |
| 8842 | transformation.printShortString(pw); |
| 8843 | pw.println(); |
| 8844 | } |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8845 | if (animLayerAdjustment != 0) { |
| 8846 | pw.print(prefix); pw.print("animLayerAdjustment="); pw.println(animLayerAdjustment); |
| 8847 | } |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8848 | if (startingData != null || removed || firstWindowDrawn) { |
| 8849 | pw.print(prefix); pw.print("startingData="); pw.print(startingData); |
| 8850 | pw.print(" removed="); pw.print(removed); |
| 8851 | pw.print(" firstWindowDrawn="); pw.println(firstWindowDrawn); |
| 8852 | } |
| 8853 | if (startingWindow != null || startingView != null |
| 8854 | || startingDisplayed || startingMoved) { |
| 8855 | pw.print(prefix); pw.print("startingWindow="); pw.print(startingWindow); |
| 8856 | pw.print(" startingView="); pw.print(startingView); |
| 8857 | pw.print(" startingDisplayed="); pw.print(startingDisplayed); |
| 8858 | pw.print(" startingMoved"); pw.println(startingMoved); |
| 8859 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8860 | } |
| 8861 | |
| 8862 | @Override |
| 8863 | public String toString() { |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 8864 | if (stringName == null) { |
| 8865 | StringBuilder sb = new StringBuilder(); |
| 8866 | sb.append("AppWindowToken{"); |
| 8867 | sb.append(Integer.toHexString(System.identityHashCode(this))); |
| 8868 | sb.append(" token="); sb.append(token); sb.append('}'); |
| 8869 | stringName = sb.toString(); |
| 8870 | } |
| 8871 | return stringName; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8872 | } |
| 8873 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8874 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8875 | // ------------------------------------------------------------- |
| 8876 | // DummyAnimation |
| 8877 | // ------------------------------------------------------------- |
| 8878 | |
| 8879 | // This is an animation that does nothing: it just immediately finishes |
| 8880 | // itself every time it is called. It is used as a stub animation in cases |
| 8881 | // where we want to synchronize multiple things that may be animating. |
| 8882 | static final class DummyAnimation extends Animation { |
| 8883 | public boolean getTransformation(long currentTime, Transformation outTransformation) { |
| 8884 | return false; |
| 8885 | } |
| 8886 | } |
| 8887 | static final Animation sDummyAnimation = new DummyAnimation(); |
| 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 | // ------------------------------------------------------------- |
| 8890 | // Async Handler |
| 8891 | // ------------------------------------------------------------- |
| 8892 | |
| 8893 | static final class StartingData { |
| 8894 | final String pkg; |
| 8895 | final int theme; |
| 8896 | final CharSequence nonLocalizedLabel; |
| 8897 | final int labelRes; |
| 8898 | final int icon; |
| Dianne Hackborn | 7eec10e | 2010-11-12 18:03:47 -0800 | [diff] [blame] | 8899 | final int windowFlags; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8900 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8901 | StartingData(String _pkg, int _theme, CharSequence _nonLocalizedLabel, |
| Dianne Hackborn | 7eec10e | 2010-11-12 18:03:47 -0800 | [diff] [blame] | 8902 | int _labelRes, int _icon, int _windowFlags) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8903 | pkg = _pkg; |
| 8904 | theme = _theme; |
| 8905 | nonLocalizedLabel = _nonLocalizedLabel; |
| 8906 | labelRes = _labelRes; |
| 8907 | icon = _icon; |
| Dianne Hackborn | 7eec10e | 2010-11-12 18:03:47 -0800 | [diff] [blame] | 8908 | windowFlags = _windowFlags; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8909 | } |
| 8910 | } |
| 8911 | |
| 8912 | private final class H extends Handler { |
| 8913 | public static final int REPORT_FOCUS_CHANGE = 2; |
| 8914 | public static final int REPORT_LOSING_FOCUS = 3; |
| 8915 | public static final int ANIMATE = 4; |
| 8916 | public static final int ADD_STARTING = 5; |
| 8917 | public static final int REMOVE_STARTING = 6; |
| 8918 | public static final int FINISHED_STARTING = 7; |
| 8919 | public static final int REPORT_APPLICATION_TOKEN_WINDOWS = 8; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8920 | public static final int WINDOW_FREEZE_TIMEOUT = 11; |
| 8921 | public static final int HOLD_SCREEN_CHANGED = 12; |
| 8922 | public static final int APP_TRANSITION_TIMEOUT = 13; |
| 8923 | public static final int PERSIST_ANIMATION_SCALE = 14; |
| 8924 | public static final int FORCE_GC = 15; |
| 8925 | public static final int ENABLE_SCREEN = 16; |
| 8926 | public static final int APP_FREEZE_TIMEOUT = 17; |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 8927 | public static final int SEND_NEW_CONFIGURATION = 18; |
| Konstantin Lopyrev | 6e0f65f | 2010-07-14 14:55:33 -0700 | [diff] [blame] | 8928 | public static final int REPORT_WINDOWS_CHANGE = 19; |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 8929 | public static final int DRAG_START_TIMEOUT = 20; |
| Chris Tate | d4533f14 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 8930 | public static final int DRAG_END_TIMEOUT = 21; |
| Jeff Brown | 2992ea7 | 2011-01-28 22:04:14 -0800 | [diff] [blame^] | 8931 | public static final int REPORT_HARD_KEYBOARD_STATUS_CHANGE = 22; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8932 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8933 | private Session mLastReportedHold; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8934 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8935 | public H() { |
| 8936 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8937 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8938 | @Override |
| 8939 | public void handleMessage(Message msg) { |
| 8940 | switch (msg.what) { |
| 8941 | case REPORT_FOCUS_CHANGE: { |
| 8942 | WindowState lastFocus; |
| 8943 | WindowState newFocus; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8944 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8945 | synchronized(mWindowMap) { |
| 8946 | lastFocus = mLastFocus; |
| 8947 | newFocus = mCurrentFocus; |
| 8948 | if (lastFocus == newFocus) { |
| 8949 | // Focus is not changing, so nothing to do. |
| 8950 | return; |
| 8951 | } |
| 8952 | mLastFocus = newFocus; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8953 | //Slog.i(TAG, "Focus moving from " + lastFocus |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8954 | // + " to " + newFocus); |
| 8955 | if (newFocus != null && lastFocus != null |
| 8956 | && !newFocus.isDisplayedLw()) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8957 | //Slog.i(TAG, "Delaying loss of focus..."); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8958 | mLosingFocus.add(lastFocus); |
| 8959 | lastFocus = null; |
| 8960 | } |
| 8961 | } |
| 8962 | |
| 8963 | if (lastFocus != newFocus) { |
| 8964 | //System.out.println("Changing focus from " + lastFocus |
| 8965 | // + " to " + newFocus); |
| 8966 | if (newFocus != null) { |
| 8967 | try { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8968 | //Slog.i(TAG, "Gaining focus: " + newFocus); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8969 | newFocus.mClient.windowFocusChanged(true, mInTouchMode); |
| 8970 | } catch (RemoteException e) { |
| 8971 | // Ignore if process has died. |
| 8972 | } |
| Konstantin Lopyrev | 5e7833a | 2010-08-09 17:01:11 -0700 | [diff] [blame] | 8973 | notifyFocusChanged(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8974 | } |
| 8975 | |
| 8976 | if (lastFocus != null) { |
| 8977 | try { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 8978 | //Slog.i(TAG, "Losing focus: " + lastFocus); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8979 | lastFocus.mClient.windowFocusChanged(false, mInTouchMode); |
| 8980 | } catch (RemoteException e) { |
| 8981 | // Ignore if process has died. |
| 8982 | } |
| 8983 | } |
| Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 8984 | |
| 8985 | mPolicy.focusChanged(lastFocus, newFocus); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8986 | } |
| 8987 | } break; |
| 8988 | |
| 8989 | case REPORT_LOSING_FOCUS: { |
| 8990 | ArrayList<WindowState> losers; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 8991 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8992 | synchronized(mWindowMap) { |
| 8993 | losers = mLosingFocus; |
| 8994 | mLosingFocus = new ArrayList<WindowState>(); |
| 8995 | } |
| 8996 | |
| 8997 | final int N = losers.size(); |
| 8998 | for (int i=0; i<N; i++) { |
| 8999 | try { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9000 | //Slog.i(TAG, "Losing delayed focus: " + losers.get(i)); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9001 | losers.get(i).mClient.windowFocusChanged(false, mInTouchMode); |
| 9002 | } catch (RemoteException e) { |
| 9003 | // Ignore if process has died. |
| 9004 | } |
| 9005 | } |
| 9006 | } break; |
| 9007 | |
| 9008 | case ANIMATE: { |
| 9009 | synchronized(mWindowMap) { |
| 9010 | mAnimationPending = false; |
| 9011 | performLayoutAndPlaceSurfacesLocked(); |
| 9012 | } |
| 9013 | } break; |
| 9014 | |
| 9015 | case ADD_STARTING: { |
| 9016 | final AppWindowToken wtoken = (AppWindowToken)msg.obj; |
| 9017 | final StartingData sd = wtoken.startingData; |
| 9018 | |
| 9019 | if (sd == null) { |
| 9020 | // Animation has been canceled... do nothing. |
| 9021 | return; |
| 9022 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9023 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9024 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Add starting " |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9025 | + wtoken + ": pkg=" + sd.pkg); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9026 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9027 | View view = null; |
| 9028 | try { |
| 9029 | view = mPolicy.addStartingWindow( |
| 9030 | wtoken.token, sd.pkg, |
| 9031 | sd.theme, sd.nonLocalizedLabel, sd.labelRes, |
| Dianne Hackborn | 7eec10e | 2010-11-12 18:03:47 -0800 | [diff] [blame] | 9032 | sd.icon, sd.windowFlags); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9033 | } catch (Exception e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9034 | Slog.w(TAG, "Exception when adding starting window", e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9035 | } |
| 9036 | |
| 9037 | if (view != null) { |
| 9038 | boolean abort = false; |
| 9039 | |
| 9040 | synchronized(mWindowMap) { |
| 9041 | if (wtoken.removed || wtoken.startingData == null) { |
| 9042 | // If the window was successfully added, then |
| 9043 | // we need to remove it. |
| 9044 | if (wtoken.startingWindow != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9045 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9046 | "Aborted starting " + wtoken |
| 9047 | + ": removed=" + wtoken.removed |
| 9048 | + " startingData=" + wtoken.startingData); |
| 9049 | wtoken.startingWindow = null; |
| 9050 | wtoken.startingData = null; |
| 9051 | abort = true; |
| 9052 | } |
| 9053 | } else { |
| 9054 | wtoken.startingView = view; |
| 9055 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9056 | if (DEBUG_STARTING_WINDOW && !abort) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9057 | "Added starting " + wtoken |
| 9058 | + ": startingWindow=" |
| 9059 | + wtoken.startingWindow + " startingView=" |
| 9060 | + wtoken.startingView); |
| 9061 | } |
| 9062 | |
| 9063 | if (abort) { |
| 9064 | try { |
| 9065 | mPolicy.removeStartingWindow(wtoken.token, view); |
| 9066 | } catch (Exception e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9067 | Slog.w(TAG, "Exception when removing starting window", e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9068 | } |
| 9069 | } |
| 9070 | } |
| 9071 | } break; |
| 9072 | |
| 9073 | case REMOVE_STARTING: { |
| 9074 | final AppWindowToken wtoken = (AppWindowToken)msg.obj; |
| 9075 | IBinder token = null; |
| 9076 | View view = null; |
| 9077 | synchronized (mWindowMap) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9078 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Remove starting " |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9079 | + wtoken + ": startingWindow=" |
| 9080 | + wtoken.startingWindow + " startingView=" |
| 9081 | + wtoken.startingView); |
| 9082 | if (wtoken.startingWindow != null) { |
| 9083 | view = wtoken.startingView; |
| 9084 | token = wtoken.token; |
| 9085 | wtoken.startingData = null; |
| 9086 | wtoken.startingView = null; |
| 9087 | wtoken.startingWindow = null; |
| 9088 | } |
| 9089 | } |
| 9090 | if (view != null) { |
| 9091 | try { |
| 9092 | mPolicy.removeStartingWindow(token, view); |
| 9093 | } catch (Exception e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9094 | Slog.w(TAG, "Exception when removing starting window", e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9095 | } |
| 9096 | } |
| 9097 | } break; |
| 9098 | |
| 9099 | case FINISHED_STARTING: { |
| 9100 | IBinder token = null; |
| 9101 | View view = null; |
| 9102 | while (true) { |
| 9103 | synchronized (mWindowMap) { |
| 9104 | final int N = mFinishedStarting.size(); |
| 9105 | if (N <= 0) { |
| 9106 | break; |
| 9107 | } |
| 9108 | AppWindowToken wtoken = mFinishedStarting.remove(N-1); |
| 9109 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9110 | if (DEBUG_STARTING_WINDOW) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9111 | "Finished starting " + wtoken |
| 9112 | + ": startingWindow=" + wtoken.startingWindow |
| 9113 | + " startingView=" + wtoken.startingView); |
| 9114 | |
| 9115 | if (wtoken.startingWindow == null) { |
| 9116 | continue; |
| 9117 | } |
| 9118 | |
| 9119 | view = wtoken.startingView; |
| 9120 | token = wtoken.token; |
| 9121 | wtoken.startingData = null; |
| 9122 | wtoken.startingView = null; |
| 9123 | wtoken.startingWindow = null; |
| 9124 | } |
| 9125 | |
| 9126 | try { |
| 9127 | mPolicy.removeStartingWindow(token, view); |
| 9128 | } catch (Exception e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9129 | Slog.w(TAG, "Exception when removing starting window", e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9130 | } |
| 9131 | } |
| 9132 | } break; |
| 9133 | |
| 9134 | case REPORT_APPLICATION_TOKEN_WINDOWS: { |
| 9135 | final AppWindowToken wtoken = (AppWindowToken)msg.obj; |
| 9136 | |
| 9137 | boolean nowVisible = msg.arg1 != 0; |
| 9138 | boolean nowGone = msg.arg2 != 0; |
| 9139 | |
| 9140 | try { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9141 | if (DEBUG_VISIBILITY) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9142 | TAG, "Reporting visible in " + wtoken |
| 9143 | + " visible=" + nowVisible |
| 9144 | + " gone=" + nowGone); |
| 9145 | if (nowVisible) { |
| 9146 | wtoken.appToken.windowsVisible(); |
| 9147 | } else { |
| 9148 | wtoken.appToken.windowsGone(); |
| 9149 | } |
| 9150 | } catch (RemoteException ex) { |
| 9151 | } |
| 9152 | } break; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9153 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9154 | case WINDOW_FREEZE_TIMEOUT: { |
| 9155 | synchronized (mWindowMap) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9156 | Slog.w(TAG, "Window freeze timeout expired."); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9157 | int i = mWindows.size(); |
| 9158 | while (i > 0) { |
| 9159 | i--; |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 9160 | WindowState w = mWindows.get(i); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9161 | if (w.mOrientationChanging) { |
| 9162 | w.mOrientationChanging = false; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9163 | Slog.w(TAG, "Force clearing orientation change: " + w); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9164 | } |
| 9165 | } |
| 9166 | performLayoutAndPlaceSurfacesLocked(); |
| 9167 | } |
| 9168 | break; |
| 9169 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9170 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9171 | case HOLD_SCREEN_CHANGED: { |
| 9172 | Session oldHold; |
| 9173 | Session newHold; |
| 9174 | synchronized (mWindowMap) { |
| 9175 | oldHold = mLastReportedHold; |
| 9176 | newHold = (Session)msg.obj; |
| 9177 | mLastReportedHold = newHold; |
| 9178 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9179 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9180 | if (oldHold != newHold) { |
| 9181 | try { |
| 9182 | if (oldHold != null) { |
| Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 9183 | mBatteryStats.noteStopWakelock(oldHold.mUid, -1, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9184 | "window", |
| 9185 | BatteryStats.WAKE_TYPE_WINDOW); |
| 9186 | } |
| 9187 | if (newHold != null) { |
| Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 9188 | mBatteryStats.noteStartWakelock(newHold.mUid, -1, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9189 | "window", |
| 9190 | BatteryStats.WAKE_TYPE_WINDOW); |
| 9191 | } |
| 9192 | } catch (RemoteException e) { |
| 9193 | } |
| 9194 | } |
| 9195 | break; |
| 9196 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9197 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9198 | case APP_TRANSITION_TIMEOUT: { |
| 9199 | synchronized (mWindowMap) { |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 9200 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9201 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9202 | "*** APP TRANSITION TIMEOUT"); |
| 9203 | mAppTransitionReady = true; |
| 9204 | mAppTransitionTimeout = true; |
| 9205 | performLayoutAndPlaceSurfacesLocked(); |
| 9206 | } |
| 9207 | } |
| 9208 | break; |
| 9209 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9210 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9211 | case PERSIST_ANIMATION_SCALE: { |
| 9212 | Settings.System.putFloat(mContext.getContentResolver(), |
| 9213 | Settings.System.WINDOW_ANIMATION_SCALE, mWindowAnimationScale); |
| 9214 | Settings.System.putFloat(mContext.getContentResolver(), |
| 9215 | Settings.System.TRANSITION_ANIMATION_SCALE, mTransitionAnimationScale); |
| 9216 | break; |
| 9217 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9218 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9219 | case FORCE_GC: { |
| 9220 | synchronized(mWindowMap) { |
| 9221 | if (mAnimationPending) { |
| 9222 | // If we are animating, don't do the gc now but |
| 9223 | // delay a bit so we don't interrupt the animation. |
| 9224 | mH.sendMessageDelayed(mH.obtainMessage(H.FORCE_GC), |
| 9225 | 2000); |
| 9226 | return; |
| 9227 | } |
| 9228 | // If we are currently rotating the display, it will |
| 9229 | // schedule a new message when done. |
| 9230 | if (mDisplayFrozen) { |
| 9231 | return; |
| 9232 | } |
| 9233 | mFreezeGcPending = 0; |
| 9234 | } |
| 9235 | Runtime.getRuntime().gc(); |
| 9236 | break; |
| 9237 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9238 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9239 | case ENABLE_SCREEN: { |
| 9240 | performEnableScreen(); |
| 9241 | break; |
| 9242 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9243 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9244 | case APP_FREEZE_TIMEOUT: { |
| 9245 | synchronized (mWindowMap) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9246 | Slog.w(TAG, "App freeze timeout expired."); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9247 | int i = mAppTokens.size(); |
| 9248 | while (i > 0) { |
| 9249 | i--; |
| 9250 | AppWindowToken tok = mAppTokens.get(i); |
| 9251 | if (tok.freezingScreen) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9252 | Slog.w(TAG, "Force clearing freeze: " + tok); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9253 | unsetAppFreezingScreenLocked(tok, true, true); |
| 9254 | } |
| 9255 | } |
| 9256 | } |
| 9257 | break; |
| 9258 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9259 | |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 9260 | case SEND_NEW_CONFIGURATION: { |
| 9261 | removeMessages(SEND_NEW_CONFIGURATION); |
| 9262 | sendNewConfiguration(); |
| The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 9263 | break; |
| 9264 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9265 | |
| Konstantin Lopyrev | 6e0f65f | 2010-07-14 14:55:33 -0700 | [diff] [blame] | 9266 | case REPORT_WINDOWS_CHANGE: { |
| Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 9267 | if (mWindowsChanged) { |
| 9268 | synchronized (mWindowMap) { |
| 9269 | mWindowsChanged = false; |
| 9270 | } |
| 9271 | notifyWindowsChanged(); |
| 9272 | } |
| 9273 | break; |
| 9274 | } |
| 9275 | |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 9276 | case DRAG_START_TIMEOUT: { |
| 9277 | IBinder win = (IBinder)msg.obj; |
| 9278 | if (DEBUG_DRAG) { |
| 9279 | Slog.w(TAG, "Timeout starting drag by win " + win); |
| 9280 | } |
| 9281 | synchronized (mWindowMap) { |
| 9282 | // !!! TODO: ANR the app that has failed to start the drag in time |
| 9283 | if (mDragState != null) { |
| Chris Tate | d4533f14 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 9284 | mDragState.unregister(); |
| Jeff Brown | 2e44b07 | 2011-01-24 15:21:56 -0800 | [diff] [blame] | 9285 | mInputMonitor.updateInputWindowsLw(true /*force*/); |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 9286 | mDragState.reset(); |
| 9287 | mDragState = null; |
| 9288 | } |
| 9289 | } |
| Chris Tate | d4533f14 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 9290 | break; |
| Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 9291 | } |
| 9292 | |
| Chris Tate | d4533f14 | 2010-10-19 15:15:08 -0700 | [diff] [blame] | 9293 | case DRAG_END_TIMEOUT: { |
| 9294 | IBinder win = (IBinder)msg.obj; |
| 9295 | if (DEBUG_DRAG) { |
| 9296 | Slog.w(TAG, "Timeout ending drag to win " + win); |
| 9297 | } |
| 9298 | synchronized (mWindowMap) { |
| 9299 | // !!! TODO: ANR the drag-receiving app |
| 9300 | mDragState.mDragResult = false; |
| 9301 | mDragState.endDragLw(); |
| 9302 | } |
| 9303 | break; |
| 9304 | } |
| Jeff Brown | 2992ea7 | 2011-01-28 22:04:14 -0800 | [diff] [blame^] | 9305 | |
| 9306 | case REPORT_HARD_KEYBOARD_STATUS_CHANGE: { |
| 9307 | notifyHardKeyboardStatusChange(); |
| 9308 | break; |
| 9309 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9310 | } |
| 9311 | } |
| 9312 | } |
| 9313 | |
| 9314 | // ------------------------------------------------------------- |
| 9315 | // IWindowManager API |
| 9316 | // ------------------------------------------------------------- |
| 9317 | |
| 9318 | public IWindowSession openSession(IInputMethodClient client, |
| 9319 | IInputContext inputContext) { |
| 9320 | if (client == null) throw new IllegalArgumentException("null client"); |
| 9321 | if (inputContext == null) throw new IllegalArgumentException("null inputContext"); |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 9322 | Session session = new Session(client, inputContext); |
| 9323 | return session; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9324 | } |
| 9325 | |
| 9326 | public boolean inputMethodClientHasFocus(IInputMethodClient client) { |
| 9327 | synchronized (mWindowMap) { |
| 9328 | // The focus for the client is the window immediately below |
| 9329 | // where we would place the input method window. |
| 9330 | int idx = findDesiredInputMethodWindowIndexLocked(false); |
| 9331 | WindowState imFocus; |
| 9332 | if (idx > 0) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 9333 | imFocus = mWindows.get(idx-1); |
| Dianne Hackborn | e75d872 | 2011-01-27 19:37:40 -0800 | [diff] [blame] | 9334 | //Log.i(TAG, "Desired input method target: " + imFocus); |
| 9335 | //Log.i(TAG, "Current focus: " + this.mCurrentFocus); |
| 9336 | //Log.i(TAG, "Last focus: " + this.mLastFocus); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9337 | if (imFocus != null) { |
| Dianne Hackborn | e75d872 | 2011-01-27 19:37:40 -0800 | [diff] [blame] | 9338 | // This may be a starting window, in which case we still want |
| 9339 | // to count it as okay. |
| 9340 | if (imFocus.mAttrs.type == LayoutParams.TYPE_APPLICATION_STARTING |
| 9341 | && imFocus.mAppToken != null) { |
| 9342 | // The client has definitely started, so it really should |
| 9343 | // have a window in this app token. Let's look for it. |
| 9344 | for (int i=0; i<imFocus.mAppToken.windows.size(); i++) { |
| 9345 | WindowState w = imFocus.mAppToken.windows.get(i); |
| 9346 | if (w != imFocus) { |
| 9347 | //Log.i(TAG, "Switching to real app window: " + w); |
| 9348 | imFocus = w; |
| 9349 | break; |
| 9350 | } |
| 9351 | } |
| 9352 | } |
| 9353 | //Log.i(TAG, "IM target client: " + imFocus.mSession.mClient); |
| 9354 | //if (imFocus.mSession.mClient != null) { |
| 9355 | // Log.i(TAG, "IM target client binder: " + imFocus.mSession.mClient.asBinder()); |
| 9356 | // Log.i(TAG, "Requesting client binder: " + client.asBinder()); |
| 9357 | //} |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9358 | if (imFocus.mSession.mClient != null && |
| 9359 | imFocus.mSession.mClient.asBinder() == client.asBinder()) { |
| 9360 | return true; |
| 9361 | } |
| Dianne Hackborn | e75d872 | 2011-01-27 19:37:40 -0800 | [diff] [blame] | 9362 | |
| 9363 | // Okay, how about this... what is the current focus? |
| 9364 | // It seems in some cases we may not have moved the IM |
| 9365 | // target window, such as when it was in a pop-up window, |
| 9366 | // so let's also look at the current focus. (An example: |
| 9367 | // go to Gmail, start searching so the keyboard goes up, |
| 9368 | // press home. Sometimes the IME won't go down.) |
| 9369 | // Would be nice to fix this more correctly, but it's |
| 9370 | // way at the end of a release, and this should be good enough. |
| 9371 | if (mCurrentFocus != null && mCurrentFocus.mSession.mClient != null && |
| 9372 | mCurrentFocus.mSession.mClient.asBinder() == client.asBinder()) { |
| 9373 | return true; |
| 9374 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9375 | } |
| 9376 | } |
| 9377 | } |
| 9378 | return false; |
| 9379 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9380 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9381 | // ------------------------------------------------------------- |
| 9382 | // Internals |
| 9383 | // ------------------------------------------------------------- |
| 9384 | |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 9385 | final WindowState windowForClientLocked(Session session, IWindow client, |
| 9386 | boolean throwOnError) { |
| 9387 | return windowForClientLocked(session, client.asBinder(), throwOnError); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9388 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9389 | |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 9390 | final WindowState windowForClientLocked(Session session, IBinder client, |
| 9391 | boolean throwOnError) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9392 | WindowState win = mWindowMap.get(client); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9393 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9394 | TAG, "Looking up client " + client + ": " + win); |
| 9395 | if (win == null) { |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 9396 | RuntimeException ex = new IllegalArgumentException( |
| 9397 | "Requested window " + client + " does not exist"); |
| 9398 | if (throwOnError) { |
| 9399 | throw ex; |
| 9400 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9401 | Slog.w(TAG, "Failed looking up window", ex); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9402 | return null; |
| 9403 | } |
| 9404 | if (session != null && win.mSession != session) { |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 9405 | RuntimeException ex = new IllegalArgumentException( |
| 9406 | "Requested window " + client + " is in session " + |
| 9407 | win.mSession + ", not " + session); |
| 9408 | if (throwOnError) { |
| 9409 | throw ex; |
| 9410 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9411 | Slog.w(TAG, "Failed looking up window", ex); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9412 | return null; |
| 9413 | } |
| 9414 | |
| 9415 | return win; |
| 9416 | } |
| 9417 | |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9418 | final void rebuildAppWindowListLocked() { |
| 9419 | int NW = mWindows.size(); |
| 9420 | int i; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9421 | int lastWallpaper = -1; |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 9422 | int numRemoved = 0; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9423 | |
| Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 9424 | if (mRebuildTmp.length < NW) { |
| 9425 | mRebuildTmp = new WindowState[NW+10]; |
| 9426 | } |
| 9427 | |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9428 | // First remove all existing app windows. |
| 9429 | i=0; |
| 9430 | while (i < NW) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 9431 | WindowState w = mWindows.get(i); |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9432 | if (w.mAppToken != null) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 9433 | WindowState win = mWindows.remove(i); |
| Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 9434 | win.mRebuilding = true; |
| 9435 | mRebuildTmp[numRemoved] = win; |
| Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 9436 | mWindowsChanged = true; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9437 | if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, |
| Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 9438 | "Rebuild removing window: " + win); |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9439 | NW--; |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 9440 | numRemoved++; |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9441 | continue; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9442 | } else if (w.mAttrs.type == WindowManager.LayoutParams.TYPE_WALLPAPER |
| 9443 | && lastWallpaper == i-1) { |
| 9444 | lastWallpaper = i; |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9445 | } |
| 9446 | i++; |
| 9447 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9448 | |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9449 | // The wallpaper window(s) typically live at the bottom of the stack, |
| 9450 | // so skip them before adding app tokens. |
| 9451 | lastWallpaper++; |
| 9452 | i = lastWallpaper; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9453 | |
| Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 9454 | // First add all of the exiting app tokens... these are no longer |
| 9455 | // in the main app list, but still have windows shown. We put them |
| 9456 | // in the back because now that the animation is over we no longer |
| 9457 | // will care about them. |
| 9458 | int NT = mExitingAppTokens.size(); |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9459 | for (int j=0; j<NT; j++) { |
| Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 9460 | i = reAddAppWindowsLocked(i, mExitingAppTokens.get(j)); |
| 9461 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9462 | |
| Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 9463 | // And add in the still active app tokens in Z order. |
| 9464 | NT = mAppTokens.size(); |
| 9465 | for (int j=0; j<NT; j++) { |
| 9466 | i = reAddAppWindowsLocked(i, mAppTokens.get(j)); |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9467 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9468 | |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9469 | i -= lastWallpaper; |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 9470 | if (i != numRemoved) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9471 | Slog.w(TAG, "Rebuild removed " + numRemoved |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 9472 | + " windows but added " + i); |
| Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 9473 | for (i=0; i<numRemoved; i++) { |
| 9474 | WindowState ws = mRebuildTmp[i]; |
| 9475 | if (ws.mRebuilding) { |
| 9476 | StringWriter sw = new StringWriter(); |
| 9477 | PrintWriter pw = new PrintWriter(sw); |
| 9478 | ws.dump(pw, ""); |
| 9479 | pw.flush(); |
| 9480 | Slog.w(TAG, "This window was lost: " + ws); |
| 9481 | Slog.w(TAG, sw.toString()); |
| 9482 | } |
| 9483 | } |
| 9484 | Slog.w(TAG, "Current app token list:"); |
| 9485 | dumpAppTokensLocked(); |
| 9486 | Slog.w(TAG, "Final window list:"); |
| 9487 | dumpWindowsLocked(); |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 9488 | } |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 9489 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9490 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9491 | private final void assignLayersLocked() { |
| 9492 | int N = mWindows.size(); |
| 9493 | int curBaseLayer = 0; |
| 9494 | int curLayer = 0; |
| 9495 | int i; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9496 | |
| Dianne Hackborn | 6c8e20f | 2010-11-09 18:59:09 -0800 | [diff] [blame] | 9497 | if (DEBUG_LAYERS) { |
| 9498 | RuntimeException here = new RuntimeException("here"); |
| 9499 | here.fillInStackTrace(); |
| 9500 | Log.v(TAG, "Assigning layers", here); |
| 9501 | } |
| 9502 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9503 | for (i=0; i<N; i++) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 9504 | WindowState w = mWindows.get(i); |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 9505 | if (w.mBaseLayer == curBaseLayer || w.mIsImWindow |
| 9506 | || (i > 0 && w.mIsWallpaper)) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9507 | curLayer += WINDOW_LAYER_MULTIPLIER; |
| 9508 | w.mLayer = curLayer; |
| 9509 | } else { |
| 9510 | curBaseLayer = curLayer = w.mBaseLayer; |
| 9511 | w.mLayer = curLayer; |
| 9512 | } |
| 9513 | if (w.mTargetAppToken != null) { |
| 9514 | w.mAnimLayer = w.mLayer + w.mTargetAppToken.animLayerAdjustment; |
| 9515 | } else if (w.mAppToken != null) { |
| 9516 | w.mAnimLayer = w.mLayer + w.mAppToken.animLayerAdjustment; |
| 9517 | } else { |
| 9518 | w.mAnimLayer = w.mLayer; |
| 9519 | } |
| 9520 | if (w.mIsImWindow) { |
| 9521 | w.mAnimLayer += mInputMethodAnimLayerAdjustment; |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 9522 | } else if (w.mIsWallpaper) { |
| 9523 | w.mAnimLayer += mWallpaperAnimLayerAdjustment; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9524 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9525 | if (DEBUG_LAYERS) Slog.v(TAG, "Assign layer " + w + ": " |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9526 | + w.mAnimLayer); |
| 9527 | //System.out.println( |
| 9528 | // "Assigned layer " + curLayer + " to " + w.mClient.asBinder()); |
| 9529 | } |
| 9530 | } |
| 9531 | |
| 9532 | private boolean mInLayout = false; |
| 9533 | private final void performLayoutAndPlaceSurfacesLocked() { |
| 9534 | if (mInLayout) { |
| Dave Bort | cfe6524 | 2009-04-09 14:51:04 -0700 | [diff] [blame] | 9535 | if (DEBUG) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9536 | throw new RuntimeException("Recursive call!"); |
| 9537 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9538 | Slog.w(TAG, "performLayoutAndPlaceSurfacesLocked called while in layout"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9539 | return; |
| 9540 | } |
| 9541 | |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 9542 | if (mWaitingForConfig) { |
| 9543 | // Our configuration has changed (most likely rotation), but we |
| 9544 | // don't yet have the complete configuration to report to |
| 9545 | // applications. Don't do any window layout until we have it. |
| 9546 | return; |
| 9547 | } |
| 9548 | |
| Dianne Hackborn | ce2ef76 | 2010-09-20 11:39:14 -0700 | [diff] [blame] | 9549 | if (mDisplay == null) { |
| 9550 | // Not yet initialized, nothing to do. |
| 9551 | return; |
| 9552 | } |
| 9553 | |
| Dianne Hackborn | 2e7ffa5 | 2011-01-12 13:21:28 -0800 | [diff] [blame] | 9554 | mInLayout = true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9555 | boolean recoveringMemory = false; |
| Dianne Hackborn | 2e7ffa5 | 2011-01-12 13:21:28 -0800 | [diff] [blame] | 9556 | |
| 9557 | try { |
| 9558 | if (mForceRemoves != null) { |
| 9559 | recoveringMemory = true; |
| Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 9560 | // 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] | 9561 | for (int i=0; i<mForceRemoves.size(); i++) { |
| 9562 | WindowState ws = mForceRemoves.get(i); |
| 9563 | Slog.i(TAG, "Force removing: " + ws); |
| 9564 | removeWindowInnerLocked(ws.mSession, ws); |
| 9565 | } |
| 9566 | mForceRemoves = null; |
| 9567 | Slog.w(TAG, "Due to memory failure, waiting a bit for next layout"); |
| 9568 | Object tmp = new Object(); |
| 9569 | synchronized (tmp) { |
| 9570 | try { |
| 9571 | tmp.wait(250); |
| 9572 | } catch (InterruptedException e) { |
| 9573 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9574 | } |
| 9575 | } |
| Dianne Hackborn | 2e7ffa5 | 2011-01-12 13:21:28 -0800 | [diff] [blame] | 9576 | } catch (RuntimeException e) { |
| 9577 | 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] | 9578 | } |
| Dianne Hackborn | 2e7ffa5 | 2011-01-12 13:21:28 -0800 | [diff] [blame] | 9579 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9580 | try { |
| 9581 | performLayoutAndPlaceSurfacesLockedInner(recoveringMemory); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9582 | |
| Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 9583 | int N = mPendingRemove.size(); |
| 9584 | if (N > 0) { |
| 9585 | if (mPendingRemoveTmp.length < N) { |
| 9586 | mPendingRemoveTmp = new WindowState[N+10]; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9587 | } |
| Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 9588 | mPendingRemove.toArray(mPendingRemoveTmp); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9589 | mPendingRemove.clear(); |
| Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 9590 | for (int i=0; i<N; i++) { |
| 9591 | WindowState w = mPendingRemoveTmp[i]; |
| 9592 | removeWindowInnerLocked(w.mSession, w); |
| 9593 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9594 | |
| 9595 | mInLayout = false; |
| 9596 | assignLayersLocked(); |
| 9597 | mLayoutNeeded = true; |
| 9598 | performLayoutAndPlaceSurfacesLocked(); |
| 9599 | |
| 9600 | } else { |
| 9601 | mInLayout = false; |
| 9602 | if (mLayoutNeeded) { |
| 9603 | requestAnimationLocked(0); |
| 9604 | } |
| 9605 | } |
| Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 9606 | if (mWindowsChanged && !mWindowChangeListeners.isEmpty()) { |
| Konstantin Lopyrev | 6e0f65f | 2010-07-14 14:55:33 -0700 | [diff] [blame] | 9607 | mH.removeMessages(H.REPORT_WINDOWS_CHANGE); |
| 9608 | mH.sendMessage(mH.obtainMessage(H.REPORT_WINDOWS_CHANGE)); |
| Konstantin Lopyrev | dc30101 | 2010-07-08 17:55:51 -0700 | [diff] [blame] | 9609 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9610 | } catch (RuntimeException e) { |
| 9611 | mInLayout = false; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9612 | 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] | 9613 | } |
| 9614 | } |
| 9615 | |
| Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 9616 | private final int performLayoutLockedInner(boolean initial, boolean updateInputWindows) { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9617 | if (!mLayoutNeeded) { |
| 9618 | return 0; |
| 9619 | } |
| 9620 | |
| 9621 | mLayoutNeeded = false; |
| 9622 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9623 | final int dw = mDisplay.getWidth(); |
| 9624 | final int dh = mDisplay.getHeight(); |
| 9625 | |
| 9626 | final int N = mWindows.size(); |
| 9627 | int i; |
| 9628 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9629 | if (DEBUG_LAYOUT) Slog.v(TAG, "performLayout: needed=" |
| Dianne Hackborn | 9b52a21 | 2009-12-11 14:51:35 -0800 | [diff] [blame] | 9630 | + mLayoutNeeded + " dw=" + dw + " dh=" + dh); |
| 9631 | |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9632 | mPolicy.beginLayoutLw(dw, dh); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9633 | |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9634 | int seq = mLayoutSeq+1; |
| 9635 | if (seq < 0) seq = 0; |
| 9636 | mLayoutSeq = seq; |
| 9637 | |
| 9638 | // First perform layout of any root windows (not attached |
| 9639 | // to another window). |
| 9640 | int topAttached = -1; |
| 9641 | for (i = N-1; i >= 0; i--) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 9642 | WindowState win = mWindows.get(i); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9643 | |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9644 | // Don't do layout of a window if it is not visible, or |
| 9645 | // soon won't be visible, to avoid wasting time and funky |
| 9646 | // changes while a window is animating away. |
| 9647 | final AppWindowToken atoken = win.mAppToken; |
| 9648 | final boolean gone = win.mViewVisibility == View.GONE |
| 9649 | || !win.mRelayoutCalled |
| Dianne Hackborn | ff801ec | 2011-01-22 18:05:38 -0800 | [diff] [blame] | 9650 | || (atoken == null && win.mRootToken.hidden) |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9651 | || (atoken != null && atoken.hiddenRequested) |
| 9652 | || win.mAttachedHidden |
| 9653 | || win.mExiting || win.mDestroying; |
| 9654 | |
| Dianne Hackborn | 1c24e95 | 2010-11-23 00:34:30 -0800 | [diff] [blame] | 9655 | if (DEBUG_LAYOUT && !win.mLayoutAttached) { |
| 9656 | Slog.v(TAG, "First pass " + win |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9657 | + ": gone=" + gone + " mHaveFrame=" + win.mHaveFrame |
| 9658 | + " mLayoutAttached=" + win.mLayoutAttached); |
| Dianne Hackborn | 1c24e95 | 2010-11-23 00:34:30 -0800 | [diff] [blame] | 9659 | if (gone) Slog.v(TAG, " (mViewVisibility=" |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9660 | + win.mViewVisibility + " mRelayoutCalled=" |
| 9661 | + win.mRelayoutCalled + " hidden=" |
| 9662 | + win.mRootToken.hidden + " hiddenRequested=" |
| 9663 | + (atoken != null && atoken.hiddenRequested) |
| 9664 | + " mAttachedHidden=" + win.mAttachedHidden); |
| 9665 | } |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 9666 | |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9667 | // If this view is GONE, then skip it -- keep the current |
| 9668 | // frame, and let the caller know so they can ignore it |
| 9669 | // if they want. (We do the normal layout for INVISIBLE |
| 9670 | // windows, since that means "perform layout as normal, |
| 9671 | // just don't display"). |
| 9672 | if (!gone || !win.mHaveFrame) { |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 9673 | if (!win.mLayoutAttached) { |
| Dianne Hackborn | 8e11ef0 | 2010-11-18 19:47:42 -0800 | [diff] [blame] | 9674 | if (initial) { |
| Dianne Hackborn | 0f761d6 | 2010-11-30 22:06:10 -0800 | [diff] [blame] | 9675 | //Slog.i(TAG, "Window " + this + " clearing mContentChanged - initial"); |
| Dianne Hackborn | 8e11ef0 | 2010-11-18 19:47:42 -0800 | [diff] [blame] | 9676 | win.mContentChanged = false; |
| 9677 | } |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9678 | mPolicy.layoutWindowLw(win, win.mAttrs, null); |
| 9679 | win.mLayoutSeq = seq; |
| 9680 | if (DEBUG_LAYOUT) Slog.v(TAG, "-> mFrame=" |
| 9681 | + win.mFrame + " mContainingFrame=" |
| 9682 | + win.mContainingFrame + " mDisplayFrame=" |
| 9683 | + win.mDisplayFrame); |
| 9684 | } else { |
| 9685 | if (topAttached < 0) topAttached = i; |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 9686 | } |
| Dianne Hackborn | 958b9ad | 2009-03-31 18:00:36 -0700 | [diff] [blame] | 9687 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9688 | } |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9689 | |
| 9690 | // Now perform layout of attached windows, which usually |
| 9691 | // depend on the position of the window they are attached to. |
| 9692 | // XXX does not deal with windows that are attached to windows |
| 9693 | // that are themselves attached. |
| 9694 | for (i = topAttached; i >= 0; i--) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 9695 | WindowState win = mWindows.get(i); |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9696 | |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9697 | if (win.mLayoutAttached) { |
| 9698 | if (DEBUG_LAYOUT) Slog.v(TAG, "Second pass " + win |
| 9699 | + " mHaveFrame=" + win.mHaveFrame |
| 9700 | + " mViewVisibility=" + win.mViewVisibility |
| 9701 | + " mRelayoutCalled=" + win.mRelayoutCalled); |
| Dianne Hackborn | 1c24e95 | 2010-11-23 00:34:30 -0800 | [diff] [blame] | 9702 | // If this view is GONE, then skip it -- keep the current |
| 9703 | // frame, and let the caller know so they can ignore it |
| 9704 | // if they want. (We do the normal layout for INVISIBLE |
| 9705 | // windows, since that means "perform layout as normal, |
| 9706 | // just don't display"). |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9707 | if ((win.mViewVisibility != View.GONE && win.mRelayoutCalled) |
| 9708 | || !win.mHaveFrame) { |
| Dianne Hackborn | 8e11ef0 | 2010-11-18 19:47:42 -0800 | [diff] [blame] | 9709 | if (initial) { |
| Dianne Hackborn | 0f761d6 | 2010-11-30 22:06:10 -0800 | [diff] [blame] | 9710 | //Slog.i(TAG, "Window " + this + " clearing mContentChanged - initial"); |
| Dianne Hackborn | 8e11ef0 | 2010-11-18 19:47:42 -0800 | [diff] [blame] | 9711 | win.mContentChanged = false; |
| 9712 | } |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9713 | mPolicy.layoutWindowLw(win, win.mAttrs, win.mAttachedWindow); |
| 9714 | win.mLayoutSeq = seq; |
| 9715 | if (DEBUG_LAYOUT) Slog.v(TAG, "-> mFrame=" |
| 9716 | + win.mFrame + " mContainingFrame=" |
| 9717 | + win.mContainingFrame + " mDisplayFrame=" |
| 9718 | + win.mDisplayFrame); |
| 9719 | } |
| 9720 | } |
| 9721 | } |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 9722 | |
| 9723 | // Window frames may have changed. Tell the input dispatcher about it. |
| Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 9724 | mInputMonitor.setUpdateInputWindowsNeededLw(); |
| 9725 | if (updateInputWindows) { |
| Jeff Brown | 2e44b07 | 2011-01-24 15:21:56 -0800 | [diff] [blame] | 9726 | mInputMonitor.updateInputWindowsLw(false /*force*/); |
| Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 9727 | } |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9728 | |
| 9729 | return mPolicy.finishLayoutLw(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9730 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 9731 | |
| Brad Fitzpatrick | 6804433 | 2010-11-22 18:19:48 -0800 | [diff] [blame] | 9732 | // "Something has changed! Let's make it correct now." |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9733 | private final void performLayoutAndPlaceSurfacesLockedInner( |
| 9734 | boolean recoveringMemory) { |
| Joe Onorato | 34bcebc | 2010-07-07 18:05:01 -0400 | [diff] [blame] | 9735 | if (mDisplay == null) { |
| 9736 | Slog.i(TAG, "skipping performLayoutAndPlaceSurfacesLockedInner with no mDisplay"); |
| 9737 | return; |
| 9738 | } |
| 9739 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9740 | final long currentTime = SystemClock.uptimeMillis(); |
| 9741 | final int dw = mDisplay.getWidth(); |
| 9742 | final int dh = mDisplay.getHeight(); |
| 9743 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9744 | int i; |
| 9745 | |
| Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 9746 | if (mFocusMayChange) { |
| 9747 | mFocusMayChange = false; |
| Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 9748 | updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES, |
| 9749 | false /*updateInputWindows*/); |
| Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 9750 | } |
| 9751 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9752 | // Initialize state of exiting tokens. |
| 9753 | for (i=mExitingTokens.size()-1; i>=0; i--) { |
| 9754 | mExitingTokens.get(i).hasVisible = false; |
| 9755 | } |
| 9756 | |
| 9757 | // Initialize state of exiting applications. |
| 9758 | for (i=mExitingAppTokens.size()-1; i>=0; i--) { |
| 9759 | mExitingAppTokens.get(i).hasVisible = false; |
| 9760 | } |
| 9761 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9762 | boolean orientationChangeComplete = true; |
| 9763 | Session holdScreen = null; |
| 9764 | float screenBrightness = -1; |
| Mike Lockwood | fb73f79 | 2009-11-20 11:31:18 -0500 | [diff] [blame] | 9765 | float buttonBrightness = -1; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9766 | boolean focusDisplayed = false; |
| 9767 | boolean animating = false; |
| Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 9768 | boolean createWatermark = false; |
| Dianne Hackborn | 89ba675 | 2011-01-23 16:51:16 -0800 | [diff] [blame] | 9769 | boolean updateRotation = false; |
| Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 9770 | |
| 9771 | if (mFxSession == null) { |
| 9772 | mFxSession = new SurfaceSession(); |
| 9773 | createWatermark = true; |
| 9774 | } |
| 9775 | |
| Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 9776 | if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION performLayoutAndPlaceSurfaces"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9777 | |
| 9778 | Surface.openTransaction(); |
| Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 9779 | |
| 9780 | if (createWatermark) { |
| 9781 | createWatermark(); |
| 9782 | } |
| 9783 | if (mWatermark != null) { |
| 9784 | mWatermark.positionSurface(dw, dh); |
| 9785 | } |
| Brad Fitzpatrick | 6804433 | 2010-11-22 18:19:48 -0800 | [diff] [blame] | 9786 | if (mStrictModeFlash != null) { |
| 9787 | mStrictModeFlash.positionSurface(dw, dh); |
| 9788 | } |
| Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 9789 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9790 | try { |
| Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 9791 | boolean wallpaperForceHidingChanged = false; |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9792 | int repeats = 0; |
| 9793 | int changes = 0; |
| 9794 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9795 | do { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9796 | repeats++; |
| 9797 | if (repeats > 6) { |
| 9798 | Slog.w(TAG, "Animation repeat aborted after too many iterations"); |
| 9799 | mLayoutNeeded = false; |
| 9800 | break; |
| 9801 | } |
| 9802 | |
| 9803 | if ((changes&(WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER |
| 9804 | | WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG |
| 9805 | | WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT)) != 0) { |
| 9806 | if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER) != 0) { |
| 9807 | if ((adjustWallpaperWindowsLocked()&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) { |
| 9808 | assignLayersLocked(); |
| 9809 | mLayoutNeeded = true; |
| 9810 | } |
| 9811 | } |
| 9812 | if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG) != 0) { |
| 9813 | if (DEBUG_LAYOUT) Slog.v(TAG, "Computing new config from layout"); |
| Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 9814 | if (updateOrientationFromAppTokensLocked(true)) { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9815 | mLayoutNeeded = true; |
| 9816 | mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION); |
| 9817 | } |
| 9818 | } |
| 9819 | if ((changes&WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT) != 0) { |
| 9820 | mLayoutNeeded = true; |
| 9821 | } |
| 9822 | } |
| 9823 | |
| 9824 | // FIRST LOOP: Perform a layout, if needed. |
| 9825 | if (repeats < 4) { |
| Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 9826 | changes = performLayoutLockedInner(repeats == 0, false /*updateInputWindows*/); |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9827 | if (changes != 0) { |
| 9828 | continue; |
| 9829 | } |
| 9830 | } else { |
| 9831 | Slog.w(TAG, "Layout repeat skipped after too many iterations"); |
| 9832 | changes = 0; |
| 9833 | } |
| 9834 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9835 | final int transactionSequence = ++mTransactionSequence; |
| 9836 | |
| 9837 | // Update animations of all applications, including those |
| 9838 | // associated with exiting/removed apps |
| 9839 | boolean tokensAnimating = false; |
| 9840 | final int NAT = mAppTokens.size(); |
| 9841 | for (i=0; i<NAT; i++) { |
| 9842 | if (mAppTokens.get(i).stepAnimationLocked(currentTime, dw, dh)) { |
| 9843 | tokensAnimating = true; |
| 9844 | } |
| 9845 | } |
| 9846 | final int NEAT = mExitingAppTokens.size(); |
| 9847 | for (i=0; i<NEAT; i++) { |
| 9848 | if (mExitingAppTokens.get(i).stepAnimationLocked(currentTime, dw, dh)) { |
| 9849 | tokensAnimating = true; |
| 9850 | } |
| 9851 | } |
| 9852 | |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9853 | // SECOND LOOP: Execute animations and update visibility of windows. |
| 9854 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9855 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "*** ANIM STEP: seq=" |
| Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 9856 | + transactionSequence + " tokensAnimating=" |
| 9857 | + tokensAnimating); |
| 9858 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9859 | animating = tokensAnimating; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9860 | |
| Dianne Hackborn | f9d0be9 | 2010-11-24 12:35:25 -0800 | [diff] [blame] | 9861 | if (mScreenRotationAnimation != null) { |
| 9862 | if (mScreenRotationAnimation.isAnimating()) { |
| 9863 | if (mScreenRotationAnimation.stepAnimation(currentTime)) { |
| 9864 | animating = true; |
| 9865 | } else { |
| 9866 | mScreenRotationAnimation = null; |
| Dianne Hackborn | 89ba675 | 2011-01-23 16:51:16 -0800 | [diff] [blame] | 9867 | updateRotation = true; |
| Dianne Hackborn | f9d0be9 | 2010-11-24 12:35:25 -0800 | [diff] [blame] | 9868 | } |
| 9869 | } |
| 9870 | } |
| 9871 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9872 | boolean tokenMayBeDrawn = false; |
| Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 9873 | boolean wallpaperMayChange = false; |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9874 | boolean forceHiding = false; |
| Dianne Hackborn | 6c8e20f | 2010-11-09 18:59:09 -0800 | [diff] [blame] | 9875 | WindowState windowDetachedWallpaper = null; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9876 | |
| 9877 | mPolicy.beginAnimationLw(dw, dh); |
| 9878 | |
| Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 9879 | final int N = mWindows.size(); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9880 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9881 | for (i=N-1; i>=0; i--) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 9882 | WindowState w = mWindows.get(i); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9883 | |
| 9884 | final WindowManager.LayoutParams attrs = w.mAttrs; |
| 9885 | |
| 9886 | if (w.mSurface != null) { |
| Dianne Hackborn | 8e11ef0 | 2010-11-18 19:47:42 -0800 | [diff] [blame] | 9887 | // Take care of the window being ready to display. |
| Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 9888 | if (w.commitFinishDrawingLocked(currentTime)) { |
| 9889 | if ((w.mAttrs.flags |
| 9890 | & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER) != 0) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 9891 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 9892 | "First draw done in potential wallpaper target " + w); |
| Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 9893 | wallpaperMayChange = true; |
| 9894 | } |
| 9895 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9896 | |
| Dianne Hackborn | 6c8e20f | 2010-11-09 18:59:09 -0800 | [diff] [blame] | 9897 | final boolean wasAnimating = w.mAnimating; |
| Dianne Hackborn | 8e11ef0 | 2010-11-18 19:47:42 -0800 | [diff] [blame] | 9898 | |
| 9899 | int animDw = dw; |
| 9900 | int animDh = dh; |
| 9901 | |
| 9902 | // If the window has moved due to its containing |
| 9903 | // content frame changing, then we'd like to animate |
| 9904 | // it. The checks here are ordered by what is least |
| Joe Onorato | 3fe7f2f | 2010-11-20 13:48:58 -0800 | [diff] [blame] | 9905 | // likely to be true first. |
| Dianne Hackborn | 1c24e95 | 2010-11-23 00:34:30 -0800 | [diff] [blame] | 9906 | if (w.shouldAnimateMove()) { |
| Dianne Hackborn | 8e11ef0 | 2010-11-18 19:47:42 -0800 | [diff] [blame] | 9907 | // Frame has moved, containing content frame |
| 9908 | // has also moved, and we're not currently animating... |
| 9909 | // let's do something. |
| 9910 | Animation a = AnimationUtils.loadAnimation(mContext, |
| 9911 | com.android.internal.R.anim.window_move_from_decor); |
| 9912 | w.setAnimation(a); |
| 9913 | animDw = w.mLastFrame.left - w.mFrame.left; |
| 9914 | animDh = w.mLastFrame.top - w.mFrame.top; |
| 9915 | } |
| 9916 | |
| 9917 | // Execute animation. |
| 9918 | final boolean nowAnimating = w.stepAnimationLocked(currentTime, |
| 9919 | animDw, animDh); |
| Dianne Hackborn | 6c8e20f | 2010-11-09 18:59:09 -0800 | [diff] [blame] | 9920 | |
| 9921 | // If this window is animating, make a note that we have |
| 9922 | // an animating window and take care of a request to run |
| 9923 | // a detached wallpaper animation. |
| 9924 | if (nowAnimating) { |
| 9925 | if (w.mAnimation != null && w.mAnimation.getDetachWallpaper()) { |
| 9926 | windowDetachedWallpaper = w; |
| 9927 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9928 | animating = true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9929 | } |
| Dianne Hackborn | 6c8e20f | 2010-11-09 18:59:09 -0800 | [diff] [blame] | 9930 | |
| 9931 | // If this window's app token is running a detached wallpaper |
| 9932 | // animation, make a note so we can ensure the wallpaper is |
| 9933 | // displayed behind it. |
| 9934 | if (w.mAppToken != null && w.mAppToken.animation != null |
| 9935 | && w.mAppToken.animation.getDetachWallpaper()) { |
| 9936 | windowDetachedWallpaper = w; |
| 9937 | } |
| 9938 | |
| Dianne Hackborn | 6136b7e | 2009-09-18 01:53:49 -0700 | [diff] [blame] | 9939 | if (wasAnimating && !w.mAnimating && mWallpaperTarget == w) { |
| 9940 | wallpaperMayChange = true; |
| 9941 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9942 | |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9943 | if (mPolicy.doesForceHide(w, attrs)) { |
| Dianne Hackborn | 6c8e20f | 2010-11-09 18:59:09 -0800 | [diff] [blame] | 9944 | if (!wasAnimating && nowAnimating) { |
| Dianne Hackborn | 20cb56e | 2010-03-04 00:58:29 -0800 | [diff] [blame] | 9945 | if (DEBUG_VISIBILITY) Slog.v(TAG, |
| Dianne Hackborn | 6c8e20f | 2010-11-09 18:59:09 -0800 | [diff] [blame] | 9946 | "Animation started that could impact force hide: " |
| Dianne Hackborn | 20cb56e | 2010-03-04 00:58:29 -0800 | [diff] [blame] | 9947 | + w); |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9948 | wallpaperForceHidingChanged = true; |
| Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 9949 | mFocusMayChange = true; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9950 | } else if (w.isReadyForDisplay() && w.mAnimation == null) { |
| 9951 | forceHiding = true; |
| 9952 | } |
| 9953 | } else if (mPolicy.canBeForceHidden(w, attrs)) { |
| 9954 | boolean changed; |
| 9955 | if (forceHiding) { |
| 9956 | changed = w.hideLw(false, false); |
| Dianne Hackborn | 20cb56e | 2010-03-04 00:58:29 -0800 | [diff] [blame] | 9957 | if (DEBUG_VISIBILITY && changed) Slog.v(TAG, |
| 9958 | "Now policy hidden: " + w); |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9959 | } else { |
| 9960 | changed = w.showLw(false, false); |
| Dianne Hackborn | 20cb56e | 2010-03-04 00:58:29 -0800 | [diff] [blame] | 9961 | if (DEBUG_VISIBILITY && changed) Slog.v(TAG, |
| 9962 | "Now policy shown: " + w); |
| 9963 | if (changed) { |
| 9964 | if (wallpaperForceHidingChanged |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 9965 | && w.isVisibleNow() /*w.isReadyForDisplay()*/) { |
| Dianne Hackborn | 20cb56e | 2010-03-04 00:58:29 -0800 | [diff] [blame] | 9966 | // Assume we will need to animate. If |
| 9967 | // we don't (because the wallpaper will |
| 9968 | // stay with the lock screen), then we will |
| 9969 | // clean up later. |
| 9970 | Animation a = mPolicy.createForceHideEnterAnimation(); |
| 9971 | if (a != null) { |
| 9972 | w.setAnimation(a); |
| 9973 | } |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9974 | } |
| Dianne Hackborn | 20cb56e | 2010-03-04 00:58:29 -0800 | [diff] [blame] | 9975 | if (mCurrentFocus == null || |
| 9976 | mCurrentFocus.mLayer < w.mLayer) { |
| 9977 | // We are showing on to of the current |
| 9978 | // focus, so re-evaluate focus to make |
| 9979 | // sure it is correct. |
| 9980 | mFocusMayChange = true; |
| 9981 | } |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 9982 | } |
| 9983 | } |
| 9984 | if (changed && (attrs.flags |
| 9985 | & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER) != 0) { |
| 9986 | wallpaperMayChange = true; |
| 9987 | } |
| 9988 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9989 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9990 | mPolicy.animatingWindowLw(w, attrs); |
| 9991 | } |
| 9992 | |
| 9993 | final AppWindowToken atoken = w.mAppToken; |
| 9994 | if (atoken != null && (!atoken.allDrawn || atoken.freezingScreen)) { |
| 9995 | if (atoken.lastTransactionSequence != transactionSequence) { |
| 9996 | atoken.lastTransactionSequence = transactionSequence; |
| 9997 | atoken.numInterestingWindows = atoken.numDrawnWindows = 0; |
| 9998 | atoken.startingDisplayed = false; |
| 9999 | } |
| 10000 | if ((w.isOnScreen() || w.mAttrs.type |
| 10001 | == WindowManager.LayoutParams.TYPE_BASE_APPLICATION) |
| 10002 | && !w.mExiting && !w.mDestroying) { |
| 10003 | if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10004 | Slog.v(TAG, "Eval win " + w + ": isDrawn=" |
| Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 10005 | + w.isDrawnLw() |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10006 | + ", isAnimating=" + w.isAnimating()); |
| Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 10007 | if (!w.isDrawnLw()) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10008 | Slog.v(TAG, "Not displayed: s=" + w.mSurface |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10009 | + " pv=" + w.mPolicyVisibility |
| 10010 | + " dp=" + w.mDrawPending |
| 10011 | + " cdp=" + w.mCommitDrawPending |
| 10012 | + " ah=" + w.mAttachedHidden |
| 10013 | + " th=" + atoken.hiddenRequested |
| 10014 | + " a=" + w.mAnimating); |
| 10015 | } |
| 10016 | } |
| 10017 | if (w != atoken.startingWindow) { |
| 10018 | if (!atoken.freezingScreen || !w.mAppFreezing) { |
| 10019 | atoken.numInterestingWindows++; |
| Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 10020 | if (w.isDrawnLw()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10021 | atoken.numDrawnWindows++; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10022 | if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10023 | "tokenMayBeDrawn: " + atoken |
| 10024 | + " freezingScreen=" + atoken.freezingScreen |
| 10025 | + " mAppFreezing=" + w.mAppFreezing); |
| 10026 | tokenMayBeDrawn = true; |
| 10027 | } |
| 10028 | } |
| Dianne Hackborn | 7433e8a | 2009-09-27 13:21:20 -0700 | [diff] [blame] | 10029 | } else if (w.isDrawnLw()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10030 | atoken.startingDisplayed = true; |
| 10031 | } |
| 10032 | } |
| 10033 | } else if (w.mReadyToShow) { |
| 10034 | w.performShowLocked(); |
| 10035 | } |
| 10036 | } |
| 10037 | |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 10038 | changes |= mPolicy.finishAnimationLw(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10039 | |
| 10040 | if (tokenMayBeDrawn) { |
| 10041 | // See if any windows have been drawn, so they (and others |
| 10042 | // associated with them) can now be shown. |
| Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 10043 | final int NT = mAppTokens.size(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10044 | for (i=0; i<NT; i++) { |
| Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 10045 | AppWindowToken wtoken = mAppTokens.get(i); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10046 | if (wtoken.freezingScreen) { |
| 10047 | int numInteresting = wtoken.numInterestingWindows; |
| 10048 | if (numInteresting > 0 && wtoken.numDrawnWindows >= numInteresting) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10049 | if (DEBUG_VISIBILITY) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10050 | "allDrawn: " + wtoken |
| 10051 | + " interesting=" + numInteresting |
| 10052 | + " drawn=" + wtoken.numDrawnWindows); |
| 10053 | wtoken.showAllWindowsLocked(); |
| 10054 | unsetAppFreezingScreenLocked(wtoken, false, true); |
| 10055 | orientationChangeComplete = true; |
| 10056 | } |
| 10057 | } else if (!wtoken.allDrawn) { |
| 10058 | int numInteresting = wtoken.numInterestingWindows; |
| 10059 | if (numInteresting > 0 && wtoken.numDrawnWindows >= numInteresting) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10060 | if (DEBUG_VISIBILITY) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10061 | "allDrawn: " + wtoken |
| 10062 | + " interesting=" + numInteresting |
| 10063 | + " drawn=" + wtoken.numDrawnWindows); |
| 10064 | wtoken.allDrawn = true; |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 10065 | changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10066 | |
| 10067 | // We can now show all of the drawn windows! |
| 10068 | if (!mOpeningApps.contains(wtoken)) { |
| 10069 | wtoken.showAllWindowsLocked(); |
| 10070 | } |
| 10071 | } |
| 10072 | } |
| 10073 | } |
| 10074 | } |
| 10075 | |
| 10076 | // If we are ready to perform an app transition, check through |
| 10077 | // all of the app tokens to be shown and see if they are ready |
| 10078 | // to go. |
| 10079 | if (mAppTransitionReady) { |
| 10080 | int NN = mOpeningApps.size(); |
| 10081 | boolean goodToGo = true; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10082 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10083 | "Checking " + NN + " opening apps (frozen=" |
| 10084 | + mDisplayFrozen + " timeout=" |
| 10085 | + mAppTransitionTimeout + ")..."); |
| 10086 | if (!mDisplayFrozen && !mAppTransitionTimeout) { |
| 10087 | // If the display isn't frozen, wait to do anything until |
| 10088 | // all of the apps are ready. Otherwise just go because |
| 10089 | // we'll unfreeze the display when everyone is ready. |
| 10090 | for (i=0; i<NN && goodToGo; i++) { |
| 10091 | AppWindowToken wtoken = mOpeningApps.get(i); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10092 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10093 | "Check opening app" + wtoken + ": allDrawn=" |
| 10094 | + wtoken.allDrawn + " startingDisplayed=" |
| 10095 | + wtoken.startingDisplayed); |
| 10096 | if (!wtoken.allDrawn && !wtoken.startingDisplayed |
| 10097 | && !wtoken.startingMoved) { |
| 10098 | goodToGo = false; |
| 10099 | } |
| 10100 | } |
| 10101 | } |
| 10102 | if (goodToGo) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10103 | 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] | 10104 | int transit = mNextAppTransition; |
| 10105 | if (mSkipAppTransitionAnimation) { |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 10106 | transit = WindowManagerPolicy.TRANSIT_UNSET; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10107 | } |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 10108 | mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10109 | mAppTransitionReady = false; |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 10110 | mAppTransitionRunning = true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10111 | mAppTransitionTimeout = false; |
| 10112 | mStartingIconInTransition = false; |
| 10113 | mSkipAppTransitionAnimation = false; |
| 10114 | |
| 10115 | mH.removeMessages(H.APP_TRANSITION_TIMEOUT); |
| 10116 | |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 10117 | // If there are applications waiting to come to the |
| 10118 | // top of the stack, now is the time to move their windows. |
| 10119 | // (Note that we don't do apps going to the bottom |
| 10120 | // here -- we want to keep their windows in the old |
| 10121 | // Z-order until the animation completes.) |
| 10122 | if (mToTopApps.size() > 0) { |
| 10123 | NN = mAppTokens.size(); |
| 10124 | for (i=0; i<NN; i++) { |
| 10125 | AppWindowToken wtoken = mAppTokens.get(i); |
| 10126 | if (wtoken.sendingToTop) { |
| 10127 | wtoken.sendingToTop = false; |
| 10128 | moveAppWindowsLocked(wtoken, NN, false); |
| 10129 | } |
| 10130 | } |
| 10131 | mToTopApps.clear(); |
| 10132 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10133 | |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 10134 | WindowState oldWallpaper = mWallpaperTarget; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10135 | |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 10136 | adjustWallpaperWindowsLocked(); |
| Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 10137 | wallpaperMayChange = false; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10138 | |
| Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 10139 | // The top-most window will supply the layout params, |
| 10140 | // and we will determine it below. |
| 10141 | LayoutParams animLp = null; |
| 10142 | int bestAnimLayer = -1; |
| Dianne Hackborn | 08121bc | 2011-01-17 17:54:31 -0800 | [diff] [blame] | 10143 | boolean fullscreenAnim = false; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10144 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10145 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
| Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 10146 | "New wallpaper target=" + mWallpaperTarget |
| 10147 | + ", lower target=" + mLowerWallpaperTarget |
| 10148 | + ", upper target=" + mUpperWallpaperTarget); |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 10149 | int foundWallpapers = 0; |
| Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 10150 | // Do a first pass through the tokens for two |
| 10151 | // things: |
| 10152 | // (1) Determine if both the closing and opening |
| 10153 | // app token sets are wallpaper targets, in which |
| 10154 | // case special animations are needed |
| 10155 | // (since the wallpaper needs to stay static |
| 10156 | // behind them). |
| 10157 | // (2) Find the layout params of the top-most |
| 10158 | // application window in the tokens, which is |
| 10159 | // what will control the animation theme. |
| 10160 | final int NC = mClosingApps.size(); |
| 10161 | NN = NC + mOpeningApps.size(); |
| 10162 | for (i=0; i<NN; i++) { |
| 10163 | AppWindowToken wtoken; |
| 10164 | int mode; |
| 10165 | if (i < NC) { |
| 10166 | wtoken = mClosingApps.get(i); |
| 10167 | mode = 1; |
| 10168 | } else { |
| 10169 | wtoken = mOpeningApps.get(i-NC); |
| 10170 | mode = 2; |
| 10171 | } |
| 10172 | if (mLowerWallpaperTarget != null) { |
| 10173 | if (mLowerWallpaperTarget.mAppToken == wtoken |
| 10174 | || mUpperWallpaperTarget.mAppToken == wtoken) { |
| 10175 | foundWallpapers |= mode; |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 10176 | } |
| 10177 | } |
| Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 10178 | if (wtoken.appFullscreen) { |
| 10179 | WindowState ws = wtoken.findMainWindow(); |
| 10180 | if (ws != null) { |
| 10181 | // If this is a compatibility mode |
| 10182 | // window, we will always use its anim. |
| 10183 | if ((ws.mAttrs.flags&FLAG_COMPATIBLE_WINDOW) != 0) { |
| 10184 | animLp = ws.mAttrs; |
| 10185 | bestAnimLayer = Integer.MAX_VALUE; |
| Dianne Hackborn | 08121bc | 2011-01-17 17:54:31 -0800 | [diff] [blame] | 10186 | } else if (!fullscreenAnim || ws.mLayer > bestAnimLayer) { |
| Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 10187 | animLp = ws.mAttrs; |
| Dianne Hackborn | 08121bc | 2011-01-17 17:54:31 -0800 | [diff] [blame] | 10188 | bestAnimLayer = ws.mLayer; |
| 10189 | } |
| 10190 | fullscreenAnim = true; |
| 10191 | } |
| 10192 | } else if (!fullscreenAnim) { |
| 10193 | WindowState ws = wtoken.findMainWindow(); |
| 10194 | if (ws != null) { |
| 10195 | if (ws.mLayer > bestAnimLayer) { |
| 10196 | animLp = ws.mAttrs; |
| Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 10197 | bestAnimLayer = ws.mLayer; |
| 10198 | } |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 10199 | } |
| Dianne Hackborn | f8fbdb6 | 2009-08-19 12:39:43 -0700 | [diff] [blame] | 10200 | } |
| 10201 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10202 | |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 10203 | if (foundWallpapers == 3) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10204 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 10205 | "Wallpaper animation!"); |
| 10206 | switch (transit) { |
| 10207 | case WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN: |
| 10208 | case WindowManagerPolicy.TRANSIT_TASK_OPEN: |
| 10209 | case WindowManagerPolicy.TRANSIT_TASK_TO_FRONT: |
| 10210 | transit = WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_OPEN; |
| 10211 | break; |
| 10212 | case WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE: |
| 10213 | case WindowManagerPolicy.TRANSIT_TASK_CLOSE: |
| 10214 | case WindowManagerPolicy.TRANSIT_TASK_TO_BACK: |
| 10215 | transit = WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_CLOSE; |
| 10216 | break; |
| 10217 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10218 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 10219 | "New transit: " + transit); |
| 10220 | } else if (oldWallpaper != null) { |
| 10221 | // We are transitioning from an activity with |
| 10222 | // a wallpaper to one without. |
| 10223 | transit = WindowManagerPolicy.TRANSIT_WALLPAPER_CLOSE; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10224 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 10225 | "New transit away from wallpaper: " + transit); |
| 10226 | } else if (mWallpaperTarget != null) { |
| 10227 | // We are transitioning from an activity without |
| 10228 | // a wallpaper to now showing the wallpaper |
| 10229 | transit = WindowManagerPolicy.TRANSIT_WALLPAPER_OPEN; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10230 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 10231 | "New transit into wallpaper: " + transit); |
| 10232 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10233 | |
| Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 10234 | // If all closing windows are obscured, then there is |
| 10235 | // no need to do an animation. This is the case, for |
| 10236 | // example, when this transition is being done behind |
| 10237 | // the lock screen. |
| 10238 | if (!mPolicy.allowAppAnimationsLw()) { |
| 10239 | animLp = null; |
| 10240 | } |
| 10241 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10242 | NN = mOpeningApps.size(); |
| 10243 | for (i=0; i<NN; i++) { |
| 10244 | AppWindowToken wtoken = mOpeningApps.get(i); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10245 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10246 | "Now opening app" + wtoken); |
| 10247 | wtoken.reportedVisible = false; |
| 10248 | wtoken.inPendingTransaction = false; |
| Dianne Hackborn | 83360b3 | 2009-08-24 18:43:32 -0700 | [diff] [blame] | 10249 | wtoken.animation = null; |
| Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 10250 | setTokenVisibilityLocked(wtoken, animLp, true, transit, false); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10251 | wtoken.updateReportedVisibilityLocked(); |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 10252 | wtoken.waitingToShow = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10253 | wtoken.showAllWindowsLocked(); |
| 10254 | } |
| 10255 | NN = mClosingApps.size(); |
| 10256 | for (i=0; i<NN; i++) { |
| 10257 | AppWindowToken wtoken = mClosingApps.get(i); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10258 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10259 | "Now closing app" + wtoken); |
| 10260 | wtoken.inPendingTransaction = false; |
| Dianne Hackborn | 83360b3 | 2009-08-24 18:43:32 -0700 | [diff] [blame] | 10261 | wtoken.animation = null; |
| Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 10262 | setTokenVisibilityLocked(wtoken, animLp, false, transit, false); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10263 | wtoken.updateReportedVisibilityLocked(); |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 10264 | wtoken.waitingToHide = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10265 | // Force the allDrawn flag, because we want to start |
| 10266 | // this guy's animations regardless of whether it's |
| 10267 | // gotten drawn. |
| 10268 | wtoken.allDrawn = true; |
| 10269 | } |
| 10270 | |
| Dianne Hackborn | 8b571a8 | 2009-09-25 16:09:43 -0700 | [diff] [blame] | 10271 | mNextAppTransitionPackage = null; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10272 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10273 | mOpeningApps.clear(); |
| 10274 | mClosingApps.clear(); |
| 10275 | |
| 10276 | // This has changed the visibility of windows, so perform |
| 10277 | // a new layout to get them all up-to-date. |
| Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 10278 | changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT |
| 10279 | | WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10280 | mLayoutNeeded = true; |
| Dianne Hackborn | 20583ff | 2009-07-27 21:51:05 -0700 | [diff] [blame] | 10281 | if (!moveInputMethodWindowsIfNeededLocked(true)) { |
| 10282 | assignLayersLocked(); |
| 10283 | } |
| Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 10284 | updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES, |
| 10285 | false /*updateInputWindows*/); |
| Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 10286 | mFocusMayChange = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10287 | } |
| 10288 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10289 | |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 10290 | int adjResult = 0; |
| 10291 | |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 10292 | if (!animating && mAppTransitionRunning) { |
| 10293 | // We have finished the animation of an app transition. To do |
| 10294 | // this, we have delayed a lot of operations like showing and |
| 10295 | // hiding apps, moving apps in Z-order, etc. The app token list |
| 10296 | // reflects the correct Z-order, but the window list may now |
| 10297 | // be out of sync with it. So here we will just rebuild the |
| 10298 | // entire app window list. Fun! |
| 10299 | mAppTransitionRunning = false; |
| 10300 | // Clear information about apps that were moving. |
| 10301 | mToBottomApps.clear(); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10302 | |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 10303 | rebuildAppWindowListLocked(); |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 10304 | changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT; |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 10305 | adjResult |= ADJUST_WALLPAPER_LAYERS_CHANGED; |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 10306 | moveInputMethodWindowsIfNeededLocked(false); |
| 10307 | wallpaperMayChange = true; |
| Suchi Amalapurapu | c9568e3 | 2009-11-05 18:51:16 -0800 | [diff] [blame] | 10308 | // Since the window list has been rebuilt, focus might |
| 10309 | // have to be recomputed since the actual order of windows |
| 10310 | // might have changed again. |
| Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 10311 | mFocusMayChange = true; |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 10312 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10313 | |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 10314 | if (wallpaperForceHidingChanged && changes == 0 && !mAppTransitionReady) { |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10315 | // At this point, there was a window with a wallpaper that |
| 10316 | // was force hiding other windows behind it, but now it |
| 10317 | // is going away. This may be simple -- just animate |
| 10318 | // away the wallpaper and its window -- or it may be |
| 10319 | // hard -- the wallpaper now needs to be shown behind |
| 10320 | // something that was hidden. |
| 10321 | WindowState oldWallpaper = mWallpaperTarget; |
| Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 10322 | if (mLowerWallpaperTarget != null |
| 10323 | && mLowerWallpaperTarget.mAppToken != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10324 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
| Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 10325 | "wallpaperForceHiding changed with lower=" |
| 10326 | + mLowerWallpaperTarget); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10327 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
| Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 10328 | "hidden=" + mLowerWallpaperTarget.mAppToken.hidden + |
| 10329 | " hiddenRequested=" + mLowerWallpaperTarget.mAppToken.hiddenRequested); |
| 10330 | if (mLowerWallpaperTarget.mAppToken.hidden) { |
| 10331 | // The lower target has become hidden before we |
| 10332 | // actually started the animation... let's completely |
| 10333 | // re-evaluate everything. |
| 10334 | mLowerWallpaperTarget = mUpperWallpaperTarget = null; |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 10335 | changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM; |
| Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 10336 | } |
| 10337 | } |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 10338 | adjResult |= adjustWallpaperWindowsLocked(); |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10339 | wallpaperMayChange = false; |
| Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 10340 | wallpaperForceHidingChanged = false; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10341 | if (DEBUG_WALLPAPER) Slog.v(TAG, "****** OLD: " + oldWallpaper |
| Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 10342 | + " NEW: " + mWallpaperTarget |
| 10343 | + " LOWER: " + mLowerWallpaperTarget); |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10344 | if (mLowerWallpaperTarget == null) { |
| 10345 | // Whoops, we don't need a special wallpaper animation. |
| 10346 | // Clear them out. |
| 10347 | forceHiding = false; |
| 10348 | for (i=N-1; i>=0; i--) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 10349 | WindowState w = mWindows.get(i); |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10350 | if (w.mSurface != null) { |
| 10351 | final WindowManager.LayoutParams attrs = w.mAttrs; |
| Suchi Amalapurapu | c03d28b | 2009-10-28 14:32:05 -0700 | [diff] [blame] | 10352 | if (mPolicy.doesForceHide(w, attrs) && w.isVisibleLw()) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10353 | if (DEBUG_FOCUS) Slog.i(TAG, "win=" + w + " force hides other windows"); |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10354 | forceHiding = true; |
| 10355 | } else if (mPolicy.canBeForceHidden(w, attrs)) { |
| 10356 | if (!w.mAnimating) { |
| 10357 | // We set the animation above so it |
| 10358 | // is not yet running. |
| 10359 | w.clearAnimation(); |
| 10360 | } |
| 10361 | } |
| 10362 | } |
| 10363 | } |
| 10364 | } |
| 10365 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10366 | |
| Dianne Hackborn | 6c8e20f | 2010-11-09 18:59:09 -0800 | [diff] [blame] | 10367 | if (mWindowDetachedWallpaper != windowDetachedWallpaper) { |
| 10368 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
| 10369 | "Detached wallpaper changed from " + mWindowDetachedWallpaper |
| 10370 | + windowDetachedWallpaper); |
| 10371 | mWindowDetachedWallpaper = windowDetachedWallpaper; |
| 10372 | wallpaperMayChange = true; |
| 10373 | } |
| 10374 | |
| Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 10375 | if (wallpaperMayChange) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10376 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 10377 | "Wallpaper may change! Adjusting"); |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 10378 | adjResult |= adjustWallpaperWindowsLocked(); |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10379 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10380 | |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10381 | if ((adjResult&ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10382 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10383 | "Wallpaper layer changed: assigning layers + relayout"); |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 10384 | changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10385 | assignLayersLocked(); |
| 10386 | } else if ((adjResult&ADJUST_WALLPAPER_VISIBILITY_CHANGED) != 0) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10387 | if (DEBUG_WALLPAPER) Slog.v(TAG, |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10388 | "Wallpaper visibility changed: relayout"); |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 10389 | changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10390 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10391 | |
| Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 10392 | if (mFocusMayChange) { |
| 10393 | mFocusMayChange = false; |
| Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 10394 | if (updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES, |
| 10395 | false /*updateInputWindows*/)) { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 10396 | changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_ANIM; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10397 | adjResult = 0; |
| Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 10398 | } |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10399 | } |
| 10400 | |
| 10401 | if (mLayoutNeeded) { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 10402 | changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT; |
| Dianne Hackborn | 6c3f571 | 2009-08-25 18:42:59 -0700 | [diff] [blame] | 10403 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10404 | |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 10405 | if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "*** ANIM STEP: changes=0x" |
| 10406 | + Integer.toHexString(changes)); |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 10407 | } while (changes != 0); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10408 | |
| 10409 | // THIRD LOOP: Update the surfaces of all windows. |
| 10410 | |
| 10411 | final boolean someoneLosingFocus = mLosingFocus.size() != 0; |
| 10412 | |
| 10413 | boolean obscured = false; |
| 10414 | boolean blurring = false; |
| 10415 | boolean dimming = false; |
| 10416 | boolean covered = false; |
| Dianne Hackborn | 9ed4a4b | 2009-03-25 17:10:37 -0700 | [diff] [blame] | 10417 | boolean syswin = false; |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 10418 | boolean backgroundFillerShown = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10419 | |
| Dianne Hackborn | bdd52b2 | 2009-09-02 21:46:19 -0700 | [diff] [blame] | 10420 | final int N = mWindows.size(); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10421 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10422 | for (i=N-1; i>=0; i--) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 10423 | WindowState w = mWindows.get(i); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10424 | |
| 10425 | boolean displayed = false; |
| 10426 | final WindowManager.LayoutParams attrs = w.mAttrs; |
| 10427 | final int attrFlags = attrs.flags; |
| 10428 | |
| 10429 | if (w.mSurface != null) { |
| Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 10430 | // XXX NOTE: The logic here could be improved. We have |
| 10431 | // the decision about whether to resize a window separated |
| 10432 | // from whether to hide the surface. This can cause us to |
| 10433 | // resize a surface even if we are going to hide it. You |
| 10434 | // can see this by (1) holding device in landscape mode on |
| 10435 | // home screen; (2) tapping browser icon (device will rotate |
| 10436 | // to landscape; (3) tap home. The wallpaper will be resized |
| 10437 | // in step 2 but then immediately hidden, causing us to |
| 10438 | // have to resize and then redraw it again in step 3. It |
| 10439 | // would be nice to figure out how to avoid this, but it is |
| 10440 | // difficult because we do need to resize surfaces in some |
| 10441 | // cases while they are hidden such as when first showing a |
| 10442 | // window. |
| 10443 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10444 | w.computeShownFrameLocked(); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10445 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10446 | TAG, "Placing surface #" + i + " " + w.mSurface |
| 10447 | + ": new=" + w.mShownFrame + ", old=" |
| 10448 | + w.mLastShownFrame); |
| 10449 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10450 | int width, height; |
| 10451 | if ((w.mAttrs.flags & w.mAttrs.FLAG_SCALED) != 0) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10452 | // for a scaled surface, we just want to use |
| 10453 | // the requested size. |
| 10454 | width = w.mRequestedWidth; |
| 10455 | height = w.mRequestedHeight; |
| 10456 | w.mLastRequestedWidth = width; |
| 10457 | w.mLastRequestedHeight = height; |
| 10458 | w.mLastShownFrame.set(w.mShownFrame); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10459 | } else { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10460 | width = w.mShownFrame.width(); |
| 10461 | height = w.mShownFrame.height(); |
| 10462 | w.mLastShownFrame.set(w.mShownFrame); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10463 | } |
| 10464 | |
| Jeff Brown | fbae722 | 2011-01-23 13:07:25 -0800 | [diff] [blame] | 10465 | if (w.mSurface != null) { |
| 10466 | if (w.mSurfaceX != w.mShownFrame.left |
| 10467 | || w.mSurfaceY != w.mShownFrame.top) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10468 | try { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 10469 | if (SHOW_TRANSACTIONS) logSurface(w, |
| Jeff Brown | fbae722 | 2011-01-23 13:07:25 -0800 | [diff] [blame] | 10470 | "POS " + w.mShownFrame.left |
| 10471 | + ", " + w.mShownFrame.top, null); |
| 10472 | w.mSurfaceX = w.mShownFrame.left; |
| 10473 | w.mSurfaceY = w.mShownFrame.top; |
| 10474 | w.mSurface.setPosition(w.mShownFrame.left, w.mShownFrame.top); |
| 10475 | } catch (RuntimeException e) { |
| 10476 | Slog.w(TAG, "Error positioning surface of " + w |
| 10477 | + " pos=(" + w.mShownFrame.left |
| 10478 | + "," + w.mShownFrame.top + ")", e); |
| 10479 | if (!recoveringMemory) { |
| 10480 | reclaimSomeSurfaceMemoryLocked(w, "position"); |
| 10481 | } |
| 10482 | } |
| 10483 | } |
| 10484 | |
| 10485 | if (width < 1) { |
| 10486 | width = 1; |
| 10487 | } |
| 10488 | if (height < 1) { |
| 10489 | height = 1; |
| 10490 | } |
| 10491 | |
| 10492 | if (w.mSurfaceW != width || w.mSurfaceH != height) { |
| 10493 | try { |
| 10494 | if (SHOW_TRANSACTIONS) logSurface(w, |
| 10495 | "SIZE " + w.mShownFrame.width() + "x" |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 10496 | + w.mShownFrame.height(), null); |
| Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 10497 | w.mSurfaceResized = true; |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 10498 | w.mSurfaceW = width; |
| 10499 | w.mSurfaceH = height; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10500 | w.mSurface.setSize(width, height); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10501 | } catch (RuntimeException e) { |
| 10502 | // If something goes wrong with the surface (such |
| 10503 | // as running out of memory), don't take down the |
| 10504 | // entire system. |
| Jeff Brown | fbae722 | 2011-01-23 13:07:25 -0800 | [diff] [blame] | 10505 | Slog.e(TAG, "Error resizing surface of " + w |
| 10506 | + " size=(" + width + "x" + height + ")", e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10507 | if (!recoveringMemory) { |
| 10508 | reclaimSomeSurfaceMemoryLocked(w, "size"); |
| 10509 | } |
| 10510 | } |
| 10511 | } |
| 10512 | } |
| Jeff Brown | fbae722 | 2011-01-23 13:07:25 -0800 | [diff] [blame] | 10513 | |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 10514 | if (!w.mAppFreezing && w.mLayoutSeq == mLayoutSeq) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10515 | w.mContentInsetsChanged = |
| 10516 | !w.mLastContentInsets.equals(w.mContentInsets); |
| 10517 | w.mVisibleInsetsChanged = |
| 10518 | !w.mLastVisibleInsets.equals(w.mVisibleInsets); |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 10519 | boolean configChanged = |
| 10520 | w.mConfiguration != mCurConfiguration |
| 10521 | && (w.mConfiguration == null |
| 10522 | || mCurConfiguration.diff(w.mConfiguration) != 0); |
| Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 10523 | if (DEBUG_CONFIGURATION && configChanged) { |
| 10524 | Slog.v(TAG, "Win " + w + " config changed: " |
| 10525 | + mCurConfiguration); |
| 10526 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10527 | if (localLOGV) Slog.v(TAG, "Resizing " + w |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 10528 | + ": configChanged=" + configChanged |
| 10529 | + " last=" + w.mLastFrame + " frame=" + w.mFrame); |
| Jeff Brown | fbae722 | 2011-01-23 13:07:25 -0800 | [diff] [blame] | 10530 | boolean frameChanged = !w.mLastFrame.equals(w.mFrame); |
| 10531 | if (frameChanged |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10532 | || w.mContentInsetsChanged |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 10533 | || w.mVisibleInsetsChanged |
| Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 10534 | || w.mSurfaceResized |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 10535 | || configChanged) { |
| Jeff Brown | fbae722 | 2011-01-23 13:07:25 -0800 | [diff] [blame] | 10536 | if (DEBUG_RESIZE || DEBUG_ORIENTATION) { |
| 10537 | Slog.v(TAG, "Resize reasons: " |
| 10538 | + "frameChanged=" + frameChanged |
| 10539 | + " contentInsetsChanged=" + w.mContentInsetsChanged |
| 10540 | + " visibleInsetsChanged=" + w.mVisibleInsetsChanged |
| 10541 | + " surfaceResized=" + w.mSurfaceResized |
| 10542 | + " configChanged=" + configChanged); |
| 10543 | } |
| 10544 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10545 | w.mLastFrame.set(w.mFrame); |
| 10546 | w.mLastContentInsets.set(w.mContentInsets); |
| 10547 | w.mLastVisibleInsets.set(w.mVisibleInsets); |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 10548 | // If the screen is currently frozen, then keep |
| 10549 | // it frozen until this window draws at its new |
| 10550 | // orientation. |
| 10551 | if (mDisplayFrozen) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10552 | if (DEBUG_ORIENTATION) Slog.v(TAG, |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 10553 | "Resizing while display frozen: " + w); |
| 10554 | w.mOrientationChanging = true; |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 10555 | if (!mWindowsFreezingScreen) { |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 10556 | mWindowsFreezingScreen = true; |
| 10557 | // XXX should probably keep timeout from |
| 10558 | // when we first froze the display. |
| 10559 | mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT); |
| 10560 | mH.sendMessageDelayed(mH.obtainMessage( |
| 10561 | H.WINDOW_FREEZE_TIMEOUT), 2000); |
| 10562 | } |
| 10563 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10564 | // If the orientation is changing, then we need to |
| 10565 | // hold off on unfreezing the display until this |
| 10566 | // window has been redrawn; to do that, we need |
| 10567 | // to go through the process of getting informed |
| 10568 | // by the application when it has finished drawing. |
| 10569 | if (w.mOrientationChanging) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10570 | if (DEBUG_ORIENTATION) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10571 | "Orientation start waiting for draw in " |
| 10572 | + w + ", surface " + w.mSurface); |
| 10573 | w.mDrawPending = true; |
| 10574 | w.mCommitDrawPending = false; |
| 10575 | w.mReadyToShow = false; |
| 10576 | if (w.mAppToken != null) { |
| 10577 | w.mAppToken.allDrawn = false; |
| 10578 | } |
| 10579 | } |
| Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 10580 | if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10581 | "Resizing window " + w + " to " + w.mFrame); |
| 10582 | mResizingWindows.add(w); |
| 10583 | } else if (w.mOrientationChanging) { |
| 10584 | if (!w.mDrawPending && !w.mCommitDrawPending) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10585 | if (DEBUG_ORIENTATION) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10586 | "Orientation not waiting for draw in " |
| 10587 | + w + ", surface " + w.mSurface); |
| 10588 | w.mOrientationChanging = false; |
| 10589 | } |
| 10590 | } |
| 10591 | } |
| 10592 | |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10593 | if (w.mAttachedHidden || !w.isReadyForDisplay()) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10594 | if (!w.mLastHidden) { |
| 10595 | //dump(); |
| 10596 | w.mLastHidden = true; |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 10597 | if (SHOW_TRANSACTIONS) logSurface(w, |
| 10598 | "HIDE (performLayout)", null); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10599 | if (w.mSurface != null) { |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 10600 | w.mSurfaceShown = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10601 | try { |
| 10602 | w.mSurface.hide(); |
| 10603 | } catch (RuntimeException e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10604 | Slog.w(TAG, "Exception hiding surface in " + w); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10605 | } |
| 10606 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10607 | } |
| 10608 | // If we are waiting for this window to handle an |
| 10609 | // orientation change, well, it is hidden, so |
| 10610 | // doesn't really matter. Note that this does |
| 10611 | // introduce a potential glitch if the window |
| 10612 | // becomes unhidden before it has drawn for the |
| 10613 | // new orientation. |
| 10614 | if (w.mOrientationChanging) { |
| 10615 | w.mOrientationChanging = false; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10616 | if (DEBUG_ORIENTATION) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10617 | "Orientation change skips hidden " + w); |
| 10618 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10619 | } else if (w.mLastLayer != w.mAnimLayer |
| 10620 | || w.mLastAlpha != w.mShownAlpha |
| 10621 | || w.mLastDsDx != w.mDsDx |
| 10622 | || w.mLastDtDx != w.mDtDx |
| 10623 | || w.mLastDsDy != w.mDsDy |
| 10624 | || w.mLastDtDy != w.mDtDy |
| 10625 | || w.mLastHScale != w.mHScale |
| 10626 | || w.mLastVScale != w.mVScale |
| 10627 | || w.mLastHidden) { |
| 10628 | displayed = true; |
| 10629 | w.mLastAlpha = w.mShownAlpha; |
| 10630 | w.mLastLayer = w.mAnimLayer; |
| 10631 | w.mLastDsDx = w.mDsDx; |
| 10632 | w.mLastDtDx = w.mDtDx; |
| 10633 | w.mLastDsDy = w.mDsDy; |
| 10634 | w.mLastDtDy = w.mDtDy; |
| 10635 | w.mLastHScale = w.mHScale; |
| 10636 | w.mLastVScale = w.mVScale; |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 10637 | if (SHOW_TRANSACTIONS) logSurface(w, |
| 10638 | "alpha=" + w.mShownAlpha + " layer=" + w.mAnimLayer |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 10639 | + " matrix=[" + (w.mDsDx*w.mHScale) |
| 10640 | + "," + (w.mDtDx*w.mVScale) |
| 10641 | + "][" + (w.mDsDy*w.mHScale) |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 10642 | + "," + (w.mDtDy*w.mVScale) + "]", null); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10643 | if (w.mSurface != null) { |
| 10644 | try { |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 10645 | w.mSurfaceAlpha = w.mShownAlpha; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10646 | w.mSurface.setAlpha(w.mShownAlpha); |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 10647 | w.mSurfaceLayer = w.mAnimLayer; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10648 | w.mSurface.setLayer(w.mAnimLayer); |
| 10649 | w.mSurface.setMatrix( |
| 10650 | w.mDsDx*w.mHScale, w.mDtDx*w.mVScale, |
| 10651 | w.mDsDy*w.mHScale, w.mDtDy*w.mVScale); |
| 10652 | } catch (RuntimeException e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10653 | Slog.w(TAG, "Error updating surface in " + w, e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10654 | if (!recoveringMemory) { |
| 10655 | reclaimSomeSurfaceMemoryLocked(w, "update"); |
| 10656 | } |
| 10657 | } |
| 10658 | } |
| 10659 | |
| 10660 | if (w.mLastHidden && !w.mDrawPending |
| 10661 | && !w.mCommitDrawPending |
| 10662 | && !w.mReadyToShow) { |
| Dianne Hackborn | b8b11a0 | 2010-03-10 15:53:11 -0800 | [diff] [blame] | 10663 | if (SHOW_TRANSACTIONS) logSurface(w, |
| 10664 | "SHOW (performLayout)", null); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10665 | if (DEBUG_VISIBILITY) Slog.v(TAG, "Showing " + w |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10666 | + " during relayout"); |
| 10667 | if (showSurfaceRobustlyLocked(w)) { |
| 10668 | w.mHasDrawn = true; |
| 10669 | w.mLastHidden = false; |
| 10670 | } else { |
| 10671 | w.mOrientationChanging = false; |
| 10672 | } |
| 10673 | } |
| 10674 | if (w.mSurface != null) { |
| 10675 | w.mToken.hasVisible = true; |
| 10676 | } |
| 10677 | } else { |
| 10678 | displayed = true; |
| 10679 | } |
| 10680 | |
| 10681 | if (displayed) { |
| 10682 | if (!covered) { |
| Romain Guy | 980a938 | 2010-01-08 15:06:28 -0800 | [diff] [blame] | 10683 | if (attrs.width == LayoutParams.MATCH_PARENT |
| 10684 | && attrs.height == LayoutParams.MATCH_PARENT) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10685 | covered = true; |
| 10686 | } |
| 10687 | } |
| 10688 | if (w.mOrientationChanging) { |
| 10689 | if (w.mDrawPending || w.mCommitDrawPending) { |
| 10690 | orientationChangeComplete = false; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10691 | if (DEBUG_ORIENTATION) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10692 | "Orientation continue waiting for draw in " + w); |
| 10693 | } else { |
| 10694 | w.mOrientationChanging = false; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10695 | if (DEBUG_ORIENTATION) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10696 | "Orientation change complete in " + w); |
| 10697 | } |
| 10698 | } |
| 10699 | w.mToken.hasVisible = true; |
| 10700 | } |
| 10701 | } else if (w.mOrientationChanging) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10702 | if (DEBUG_ORIENTATION) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10703 | "Orientation change skips hidden " + w); |
| 10704 | w.mOrientationChanging = false; |
| 10705 | } |
| 10706 | |
| Dianne Hackborn | 0f761d6 | 2010-11-30 22:06:10 -0800 | [diff] [blame] | 10707 | if (w.mContentChanged) { |
| 10708 | //Slog.i(TAG, "Window " + this + " clearing mContentChanged - done placing"); |
| 10709 | w.mContentChanged = false; |
| 10710 | } |
| 10711 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10712 | final boolean canBeSeen = w.isDisplayedLw(); |
| 10713 | |
| 10714 | if (someoneLosingFocus && w == mCurrentFocus && canBeSeen) { |
| 10715 | focusDisplayed = true; |
| 10716 | } |
| 10717 | |
| Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 10718 | final boolean obscuredChanged = w.mObscured != obscured; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10719 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10720 | // Update effect. |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 10721 | if (!(w.mObscured=obscured)) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10722 | if (w.mSurface != null) { |
| 10723 | if ((attrFlags&FLAG_KEEP_SCREEN_ON) != 0) { |
| 10724 | holdScreen = w.mSession; |
| 10725 | } |
| Dianne Hackborn | 9ed4a4b | 2009-03-25 17:10:37 -0700 | [diff] [blame] | 10726 | if (!syswin && w.mAttrs.screenBrightness >= 0 |
| 10727 | && screenBrightness < 0) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10728 | screenBrightness = w.mAttrs.screenBrightness; |
| 10729 | } |
| Mike Lockwood | fb73f79 | 2009-11-20 11:31:18 -0500 | [diff] [blame] | 10730 | if (!syswin && w.mAttrs.buttonBrightness >= 0 |
| 10731 | && buttonBrightness < 0) { |
| 10732 | buttonBrightness = w.mAttrs.buttonBrightness; |
| 10733 | } |
| Mike Lockwood | 46af6a8 | 2010-03-09 08:28:22 -0500 | [diff] [blame] | 10734 | if (canBeSeen |
| 10735 | && (attrs.type == WindowManager.LayoutParams.TYPE_SYSTEM_DIALOG |
| 10736 | || attrs.type == WindowManager.LayoutParams.TYPE_KEYGUARD |
| 10737 | || attrs.type == WindowManager.LayoutParams.TYPE_SYSTEM_ERROR)) { |
| Dianne Hackborn | 9ed4a4b | 2009-03-25 17:10:37 -0700 | [diff] [blame] | 10738 | syswin = true; |
| 10739 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10740 | } |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 10741 | |
| Dianne Hackborn | 25994b4 | 2009-09-04 14:21:19 -0700 | [diff] [blame] | 10742 | boolean opaqueDrawn = canBeSeen && w.isOpaqueDrawn(); |
| 10743 | if (opaqueDrawn && w.isFullscreen(dw, dh)) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10744 | // This window completely covers everything behind it, |
| 10745 | // so we want to leave all of them as unblurred (for |
| 10746 | // performance reasons). |
| 10747 | obscured = true; |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 10748 | } else if (opaqueDrawn && w.needsBackgroundFiller(dw, dh)) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10749 | if (SHOW_TRANSACTIONS) Slog.d(TAG, "showing background filler"); |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 10750 | // This window is in compatibility mode, and needs background filler. |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 10751 | obscured = true; |
| 10752 | if (mBackgroundFillerSurface == null) { |
| 10753 | try { |
| 10754 | mBackgroundFillerSurface = new Surface(mFxSession, 0, |
| Mathias Agopian | 5d26c1e | 2010-03-01 16:09:43 -0800 | [diff] [blame] | 10755 | "BackGroundFiller", |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 10756 | 0, dw, dh, |
| 10757 | PixelFormat.OPAQUE, |
| 10758 | Surface.FX_SURFACE_NORMAL); |
| 10759 | } catch (Exception e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10760 | Slog.e(TAG, "Exception creating filler surface", e); |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 10761 | } |
| 10762 | } |
| 10763 | try { |
| 10764 | mBackgroundFillerSurface.setPosition(0, 0); |
| 10765 | mBackgroundFillerSurface.setSize(dw, dh); |
| 10766 | // Using the same layer as Dim because they will never be shown at the |
| 10767 | // same time. |
| 10768 | mBackgroundFillerSurface.setLayer(w.mAnimLayer - 1); |
| 10769 | mBackgroundFillerSurface.show(); |
| 10770 | } catch (RuntimeException e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10771 | Slog.e(TAG, "Exception showing filler surface"); |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 10772 | } |
| 10773 | backgroundFillerShown = true; |
| 10774 | mBackgroundFillerShown = true; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 10775 | } else if (canBeSeen && !obscured && |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10776 | (attrFlags&FLAG_BLUR_BEHIND|FLAG_DIM_BEHIND) != 0) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10777 | if (localLOGV) Slog.v(TAG, "Win " + w |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10778 | + ": blurring=" + blurring |
| 10779 | + " obscured=" + obscured |
| 10780 | + " displayed=" + displayed); |
| 10781 | if ((attrFlags&FLAG_DIM_BEHIND) != 0) { |
| 10782 | if (!dimming) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10783 | //Slog.i(TAG, "DIM BEHIND: " + w); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10784 | dimming = true; |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 10785 | if (mDimAnimator == null) { |
| 10786 | mDimAnimator = new DimAnimator(mFxSession); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10787 | } |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 10788 | mDimAnimator.show(dw, dh); |
| Dianne Hackborn | 1c24e95 | 2010-11-23 00:34:30 -0800 | [diff] [blame] | 10789 | mDimAnimator.updateParameters(mContext.getResources(), |
| 10790 | w, currentTime); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10791 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10792 | } |
| 10793 | if ((attrFlags&FLAG_BLUR_BEHIND) != 0) { |
| 10794 | if (!blurring) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10795 | //Slog.i(TAG, "BLUR BEHIND: " + w); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10796 | blurring = true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10797 | if (mBlurSurface == null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10798 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR " |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10799 | + mBlurSurface + ": CREATE"); |
| 10800 | try { |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10801 | mBlurSurface = new Surface(mFxSession, 0, |
| Mathias Agopian | 5d26c1e | 2010-03-01 16:09:43 -0800 | [diff] [blame] | 10802 | "BlurSurface", |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10803 | -1, 16, 16, |
| 10804 | PixelFormat.OPAQUE, |
| 10805 | Surface.FX_SURFACE_BLUR); |
| 10806 | } catch (Exception e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10807 | Slog.e(TAG, "Exception creating Blur surface", e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10808 | } |
| 10809 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10810 | if (mBlurSurface != null) { |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 10811 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR " |
| 10812 | + mBlurSurface + ": pos=(0,0) (" + |
| 10813 | dw + "x" + dh + "), layer=" + (w.mAnimLayer-1)); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10814 | mBlurSurface.setPosition(0, 0); |
| 10815 | mBlurSurface.setSize(dw, dh); |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 10816 | mBlurSurface.setLayer(w.mAnimLayer-2); |
| 10817 | if (!mBlurShown) { |
| 10818 | try { |
| 10819 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR " |
| 10820 | + mBlurSurface + ": SHOW"); |
| 10821 | mBlurSurface.show(); |
| 10822 | } catch (RuntimeException e) { |
| 10823 | Slog.w(TAG, "Failure showing blur surface", e); |
| 10824 | } |
| 10825 | mBlurShown = true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10826 | } |
| 10827 | } |
| 10828 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10829 | } |
| 10830 | } |
| 10831 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10832 | |
| Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 10833 | if (obscuredChanged && mWallpaperTarget == w) { |
| 10834 | // This is the wallpaper target and its obscured state |
| 10835 | // changed... make sure the current wallaper's visibility |
| 10836 | // has been updated accordingly. |
| 10837 | updateWallpaperVisibilityLocked(); |
| 10838 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10839 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10840 | |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 10841 | if (backgroundFillerShown == false && mBackgroundFillerShown) { |
| 10842 | mBackgroundFillerShown = false; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10843 | if (SHOW_TRANSACTIONS) Slog.d(TAG, "hiding background filler"); |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 10844 | try { |
| 10845 | mBackgroundFillerSurface.hide(); |
| 10846 | } catch (RuntimeException e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10847 | Slog.e(TAG, "Exception hiding filler surface", e); |
| Mitsuru Oshima | 1ecf5d2 | 2009-07-06 17:20:38 -0700 | [diff] [blame] | 10848 | } |
| 10849 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10850 | |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 10851 | if (mDimAnimator != null && mDimAnimator.mDimShown) { |
| Dianne Hackborn | de2606d | 2009-12-18 16:53:55 -0800 | [diff] [blame] | 10852 | animating |= mDimAnimator.updateSurface(dimming, currentTime, |
| 10853 | mDisplayFrozen || !mPolicy.isScreenOn()); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10854 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10855 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10856 | if (!blurring && mBlurShown) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10857 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " BLUR " + mBlurSurface |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10858 | + ": HIDE"); |
| 10859 | try { |
| 10860 | mBlurSurface.hide(); |
| 10861 | } catch (IllegalArgumentException e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10862 | Slog.w(TAG, "Illegal argument exception hiding blur surface"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10863 | } |
| 10864 | mBlurShown = false; |
| 10865 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10866 | } catch (RuntimeException e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10867 | Slog.e(TAG, "Unhandled exception in Window Manager", e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10868 | } |
| 10869 | |
| 10870 | Surface.closeTransaction(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10871 | |
| Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 10872 | if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION performLayoutAndPlaceSurfaces"); |
| 10873 | |
| Dianne Hackborn | b9fb170 | 2010-08-23 16:49:02 -0700 | [diff] [blame] | 10874 | if (mWatermark != null) { |
| 10875 | mWatermark.drawIfNeeded(); |
| 10876 | } |
| 10877 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10878 | if (DEBUG_ORIENTATION && mDisplayFrozen) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10879 | "With display frozen, orientationChangeComplete=" |
| 10880 | + orientationChangeComplete); |
| 10881 | if (orientationChangeComplete) { |
| 10882 | if (mWindowsFreezingScreen) { |
| 10883 | mWindowsFreezingScreen = false; |
| 10884 | mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT); |
| 10885 | } |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 10886 | stopFreezingDisplayLocked(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10887 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10888 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10889 | i = mResizingWindows.size(); |
| 10890 | if (i > 0) { |
| 10891 | do { |
| 10892 | i--; |
| 10893 | WindowState win = mResizingWindows.get(i); |
| 10894 | try { |
| Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 10895 | if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG, |
| 10896 | "Reporting new frame to " + win + ": " + win.mFrame); |
| Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 10897 | int diff = 0; |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 10898 | boolean configChanged = |
| 10899 | win.mConfiguration != mCurConfiguration |
| 10900 | && (win.mConfiguration == null |
| Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 10901 | || (diff=mCurConfiguration.diff(win.mConfiguration)) != 0); |
| 10902 | if ((DEBUG_RESIZE || DEBUG_ORIENTATION || DEBUG_CONFIGURATION) |
| 10903 | && configChanged) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 10904 | Slog.i(TAG, "Sending new config to window " + win + ": " |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 10905 | + win.mFrame.width() + "x" + win.mFrame.height() |
| Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 10906 | + " / " + mCurConfiguration + " / 0x" |
| 10907 | + Integer.toHexString(diff)); |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 10908 | } |
| Dianne Hackborn | 694f79b | 2010-03-17 19:44:59 -0700 | [diff] [blame] | 10909 | win.mConfiguration = mCurConfiguration; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10910 | win.mClient.resized(win.mFrame.width(), |
| 10911 | win.mFrame.height(), win.mLastContentInsets, |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 10912 | win.mLastVisibleInsets, win.mDrawPending, |
| 10913 | configChanged ? win.mConfiguration : null); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10914 | win.mContentInsetsChanged = false; |
| 10915 | win.mVisibleInsetsChanged = false; |
| Dianne Hackborn | ac3587d | 2010-03-11 11:12:11 -0800 | [diff] [blame] | 10916 | win.mSurfaceResized = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10917 | } catch (RemoteException e) { |
| 10918 | win.mOrientationChanging = false; |
| 10919 | } |
| 10920 | } while (i > 0); |
| 10921 | mResizingWindows.clear(); |
| 10922 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 10923 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10924 | // Destroy the surface of any windows that are no longer visible. |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 10925 | boolean wallpaperDestroyed = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10926 | i = mDestroySurface.size(); |
| 10927 | if (i > 0) { |
| 10928 | do { |
| 10929 | i--; |
| 10930 | WindowState win = mDestroySurface.get(i); |
| 10931 | win.mDestroying = false; |
| 10932 | if (mInputMethodWindow == win) { |
| 10933 | mInputMethodWindow = null; |
| 10934 | } |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 10935 | if (win == mWallpaperTarget) { |
| 10936 | wallpaperDestroyed = true; |
| 10937 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10938 | win.destroySurfaceLocked(); |
| 10939 | } while (i > 0); |
| 10940 | mDestroySurface.clear(); |
| 10941 | } |
| 10942 | |
| 10943 | // Time to remove any exiting tokens? |
| 10944 | for (i=mExitingTokens.size()-1; i>=0; i--) { |
| 10945 | WindowToken token = mExitingTokens.get(i); |
| 10946 | if (!token.hasVisible) { |
| 10947 | mExitingTokens.remove(i); |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 10948 | if (token.windowType == TYPE_WALLPAPER) { |
| 10949 | mWallpaperTokens.remove(token); |
| 10950 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10951 | } |
| 10952 | } |
| 10953 | |
| 10954 | // Time to remove any exiting applications? |
| 10955 | for (i=mExitingAppTokens.size()-1; i>=0; i--) { |
| 10956 | AppWindowToken token = mExitingAppTokens.get(i); |
| 10957 | if (!token.hasVisible && !mClosingApps.contains(token)) { |
| Dianne Hackborn | 9bfb707 | 2009-09-22 11:37:40 -0700 | [diff] [blame] | 10958 | // Make sure there is no animation running on this token, |
| 10959 | // so any windows associated with it will be removed as |
| 10960 | // soon as their animations are complete |
| 10961 | token.animation = null; |
| 10962 | token.animating = false; |
| Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 10963 | if (DEBUG_ADD_REMOVE || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG, |
| 10964 | "performLayout: App token exiting now removed" + token); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10965 | mAppTokens.remove(token); |
| 10966 | mExitingAppTokens.remove(i); |
| 10967 | } |
| 10968 | } |
| 10969 | |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 10970 | boolean needRelayout = false; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10971 | |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 10972 | if (!animating && mAppTransitionRunning) { |
| 10973 | // We have finished the animation of an app transition. To do |
| 10974 | // this, we have delayed a lot of operations like showing and |
| 10975 | // hiding apps, moving apps in Z-order, etc. The app token list |
| 10976 | // reflects the correct Z-order, but the window list may now |
| 10977 | // be out of sync with it. So here we will just rebuild the |
| 10978 | // entire app window list. Fun! |
| 10979 | mAppTransitionRunning = false; |
| 10980 | needRelayout = true; |
| 10981 | rebuildAppWindowListLocked(); |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 10982 | assignLayersLocked(); |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 10983 | // Clear information about apps that were moving. |
| 10984 | mToBottomApps.clear(); |
| 10985 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 10986 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10987 | if (focusDisplayed) { |
| 10988 | mH.sendEmptyMessage(H.REPORT_LOSING_FOCUS); |
| 10989 | } |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 10990 | if (wallpaperDestroyed) { |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 10991 | needRelayout = adjustWallpaperWindowsLocked() != 0; |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 10992 | } |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 10993 | if (needRelayout) { |
| Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 10994 | requestAnimationLocked(0); |
| 10995 | } else if (animating) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10996 | requestAnimationLocked(currentTime+(1000/60)-SystemClock.uptimeMillis()); |
| 10997 | } |
| Jeff Brown | eb857f1 | 2010-07-16 10:06:33 -0700 | [diff] [blame] | 10998 | |
| Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 10999 | // Finally update all input windows now that the window changes have stabilized. |
| Jeff Brown | 2e44b07 | 2011-01-24 15:21:56 -0800 | [diff] [blame] | 11000 | mInputMonitor.updateInputWindowsLw(true /*force*/); |
| Jeff Brown | eb857f1 | 2010-07-16 10:06:33 -0700 | [diff] [blame] | 11001 | |
| Jeff Brown | 8e03b75 | 2010-06-13 19:16:55 -0700 | [diff] [blame] | 11002 | setHoldScreenLocked(holdScreen != null); |
| Dianne Hackborn | 428ecb6 | 2011-01-26 14:53:23 -0800 | [diff] [blame] | 11003 | if (!mDisplayFrozen) { |
| 11004 | if (screenBrightness < 0 || screenBrightness > 1.0f) { |
| 11005 | mPowerManager.setScreenBrightnessOverride(-1); |
| 11006 | } else { |
| 11007 | mPowerManager.setScreenBrightnessOverride((int) |
| 11008 | (screenBrightness * Power.BRIGHTNESS_ON)); |
| 11009 | } |
| 11010 | if (buttonBrightness < 0 || buttonBrightness > 1.0f) { |
| 11011 | mPowerManager.setButtonBrightnessOverride(-1); |
| 11012 | } else { |
| 11013 | mPowerManager.setButtonBrightnessOverride((int) |
| 11014 | (buttonBrightness * Power.BRIGHTNESS_ON)); |
| 11015 | } |
| Mike Lockwood | fb73f79 | 2009-11-20 11:31:18 -0500 | [diff] [blame] | 11016 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11017 | if (holdScreen != mHoldingScreenOn) { |
| 11018 | mHoldingScreenOn = holdScreen; |
| 11019 | Message m = mH.obtainMessage(H.HOLD_SCREEN_CHANGED, holdScreen); |
| 11020 | mH.sendMessage(m); |
| 11021 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 11022 | |
| Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 11023 | if (mTurnOnScreen) { |
| Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 11024 | if (DEBUG_VISIBILITY) Slog.v(TAG, "Turning screen on after layout!"); |
| Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 11025 | mPowerManager.userActivity(SystemClock.uptimeMillis(), false, |
| 11026 | LocalPowerManager.BUTTON_EVENT, true); |
| 11027 | mTurnOnScreen = false; |
| 11028 | } |
| Dianne Hackborn | f3bea9c | 2009-12-09 18:26:21 -0800 | [diff] [blame] | 11029 | |
| Dianne Hackborn | 89ba675 | 2011-01-23 16:51:16 -0800 | [diff] [blame] | 11030 | if (updateRotation) { |
| 11031 | if (DEBUG_ORIENTATION) Slog.d(TAG, "Performing post-rotate rotation"); |
| 11032 | boolean changed = setRotationUncheckedLocked( |
| 11033 | WindowManagerPolicy.USE_LAST_ROTATION, 0, false); |
| 11034 | if (changed) { |
| 11035 | sendNewConfiguration(); |
| 11036 | } |
| 11037 | } |
| 11038 | |
| Dianne Hackborn | f3bea9c | 2009-12-09 18:26:21 -0800 | [diff] [blame] | 11039 | // Check to see if we are now in a state where the screen should |
| 11040 | // be enabled, because the window obscured flags have changed. |
| 11041 | enableScreenIfNeededLocked(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11042 | } |
| Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 11043 | |
| 11044 | /** |
| 11045 | * Must be called with the main window manager lock held. |
| 11046 | */ |
| 11047 | void setHoldScreenLocked(boolean holding) { |
| 11048 | boolean state = mHoldingScreenWakeLock.isHeld(); |
| 11049 | if (holding != state) { |
| 11050 | if (holding) { |
| 11051 | mHoldingScreenWakeLock.acquire(); |
| 11052 | } else { |
| 11053 | mPolicy.screenOnStoppedLw(); |
| 11054 | mHoldingScreenWakeLock.release(); |
| 11055 | } |
| 11056 | } |
| 11057 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11058 | |
| 11059 | void requestAnimationLocked(long delay) { |
| 11060 | if (!mAnimationPending) { |
| 11061 | mAnimationPending = true; |
| 11062 | mH.sendMessageDelayed(mH.obtainMessage(H.ANIMATE), delay); |
| 11063 | } |
| 11064 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 11065 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11066 | /** |
| 11067 | * Have the surface flinger show a surface, robustly dealing with |
| 11068 | * error conditions. In particular, if there is not enough memory |
| 11069 | * to show the surface, then we will try to get rid of other surfaces |
| 11070 | * in order to succeed. |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 11071 | * |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11072 | * @return Returns true if the surface was successfully shown. |
| 11073 | */ |
| 11074 | boolean showSurfaceRobustlyLocked(WindowState win) { |
| 11075 | try { |
| 11076 | if (win.mSurface != null) { |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 11077 | win.mSurfaceShown = true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11078 | win.mSurface.show(); |
| Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 11079 | if (win.mTurnOnScreen) { |
| Dianne Hackborn | b601ce1 | 2010-03-01 23:36:02 -0800 | [diff] [blame] | 11080 | if (DEBUG_VISIBILITY) Slog.v(TAG, |
| 11081 | "Show surface turning screen on: " + win); |
| Dianne Hackborn | 93e462b | 2009-09-15 22:50:40 -0700 | [diff] [blame] | 11082 | win.mTurnOnScreen = false; |
| 11083 | mTurnOnScreen = true; |
| 11084 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11085 | } |
| 11086 | return true; |
| 11087 | } catch (RuntimeException e) { |
| Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 11088 | 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] | 11089 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 11090 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11091 | reclaimSomeSurfaceMemoryLocked(win, "show"); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 11092 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11093 | return false; |
| 11094 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 11095 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11096 | void reclaimSomeSurfaceMemoryLocked(WindowState win, String operation) { |
| 11097 | final Surface surface = win.mSurface; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 11098 | |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 11099 | EventLog.writeEvent(EventLogTags.WM_NO_SURFACE_MEMORY, win.toString(), |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11100 | win.mSession.mPid, operation); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 11101 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11102 | if (mForceRemoves == null) { |
| 11103 | mForceRemoves = new ArrayList<WindowState>(); |
| 11104 | } |
| 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 | long callingIdentity = Binder.clearCallingIdentity(); |
| 11107 | try { |
| 11108 | // There was some problem... first, do a sanity check of the |
| 11109 | // window list to make sure we haven't left any dangling surfaces |
| 11110 | // around. |
| 11111 | int N = mWindows.size(); |
| 11112 | boolean leakedSurface = false; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 11113 | 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] | 11114 | for (int i=0; i<N; i++) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 11115 | WindowState ws = mWindows.get(i); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11116 | if (ws.mSurface != null) { |
| 11117 | if (!mSessions.contains(ws.mSession)) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 11118 | Slog.w(TAG, "LEAKED SURFACE (session doesn't exist): " |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11119 | + ws + " surface=" + ws.mSurface |
| 11120 | + " token=" + win.mToken |
| 11121 | + " pid=" + ws.mSession.mPid |
| 11122 | + " uid=" + ws.mSession.mUid); |
| Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 11123 | if (SHOW_TRANSACTIONS) logSurface(ws, "LEAK DESTROY", null); |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 11124 | ws.mSurface.destroy(); |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 11125 | ws.mSurfaceShown = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11126 | ws.mSurface = null; |
| 11127 | mForceRemoves.add(ws); |
| 11128 | i--; |
| 11129 | N--; |
| 11130 | leakedSurface = true; |
| Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 11131 | } else if (ws.mAppToken != null && ws.mAppToken.clientHidden) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 11132 | Slog.w(TAG, "LEAKED SURFACE (app token hidden): " |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11133 | + ws + " surface=" + ws.mSurface |
| 11134 | + " token=" + win.mAppToken); |
| Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 11135 | if (SHOW_TRANSACTIONS) logSurface(ws, "LEAK DESTROY", null); |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 11136 | ws.mSurface.destroy(); |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 11137 | ws.mSurfaceShown = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11138 | ws.mSurface = null; |
| 11139 | leakedSurface = true; |
| 11140 | } |
| 11141 | } |
| 11142 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 11143 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11144 | boolean killedApps = false; |
| 11145 | if (!leakedSurface) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 11146 | Slog.w(TAG, "No leaked surfaces; killing applicatons!"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11147 | SparseIntArray pidCandidates = new SparseIntArray(); |
| 11148 | for (int i=0; i<N; i++) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 11149 | WindowState ws = mWindows.get(i); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11150 | if (ws.mSurface != null) { |
| 11151 | pidCandidates.append(ws.mSession.mPid, ws.mSession.mPid); |
| 11152 | } |
| 11153 | } |
| 11154 | if (pidCandidates.size() > 0) { |
| 11155 | int[] pids = new int[pidCandidates.size()]; |
| 11156 | for (int i=0; i<pids.length; i++) { |
| 11157 | pids[i] = pidCandidates.keyAt(i); |
| 11158 | } |
| 11159 | try { |
| Suchi Amalapurapu | e99bb5f | 2010-03-19 14:36:49 -0700 | [diff] [blame] | 11160 | if (mActivityManager.killPids(pids, "Free memory")) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11161 | killedApps = true; |
| 11162 | } |
| 11163 | } catch (RemoteException e) { |
| 11164 | } |
| 11165 | } |
| 11166 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 11167 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11168 | if (leakedSurface || killedApps) { |
| 11169 | // We managed to reclaim some memory, so get rid of the trouble |
| 11170 | // surface and ask the app to request another one. |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 11171 | 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] | 11172 | if (surface != null) { |
| Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 11173 | if (SHOW_TRANSACTIONS) logSurface(win, "RECOVER DESTROY", null); |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 11174 | surface.destroy(); |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 11175 | win.mSurfaceShown = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11176 | win.mSurface = null; |
| 11177 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 11178 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11179 | try { |
| 11180 | win.mClient.dispatchGetNewSurface(); |
| 11181 | } catch (RemoteException e) { |
| 11182 | } |
| 11183 | } |
| 11184 | } finally { |
| 11185 | Binder.restoreCallingIdentity(callingIdentity); |
| 11186 | } |
| 11187 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 11188 | |
| Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 11189 | private boolean updateFocusedWindowLocked(int mode, boolean updateInputWindows) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11190 | WindowState newFocus = computeFocusedWindowLocked(); |
| 11191 | if (mCurrentFocus != newFocus) { |
| 11192 | // This check makes sure that we don't already have the focus |
| 11193 | // change message pending. |
| 11194 | mH.removeMessages(H.REPORT_FOCUS_CHANGE); |
| 11195 | mH.sendEmptyMessage(H.REPORT_FOCUS_CHANGE); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 11196 | if (localLOGV) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11197 | TAG, "Changing focus from " + mCurrentFocus + " to " + newFocus); |
| 11198 | final WindowState oldFocus = mCurrentFocus; |
| 11199 | mCurrentFocus = newFocus; |
| 11200 | mLosingFocus.remove(newFocus); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 11201 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11202 | final WindowState imWindow = mInputMethodWindow; |
| 11203 | if (newFocus != imWindow && oldFocus != imWindow) { |
| The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 11204 | if (moveInputMethodWindowsIfNeededLocked( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11205 | mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS && |
| The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 11206 | mode != UPDATE_FOCUS_WILL_PLACE_SURFACES)) { |
| 11207 | mLayoutNeeded = true; |
| 11208 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11209 | if (mode == UPDATE_FOCUS_PLACING_SURFACES) { |
| Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 11210 | performLayoutLockedInner(true /*initial*/, updateInputWindows); |
| The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 11211 | } else if (mode == UPDATE_FOCUS_WILL_PLACE_SURFACES) { |
| 11212 | // Client will do the layout, but we need to assign layers |
| 11213 | // for handleNewWindowLocked() below. |
| 11214 | assignLayersLocked(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11215 | } |
| 11216 | } |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 11217 | |
| 11218 | if (mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS) { |
| 11219 | // If we defer assigning layers, then the caller is responsible for |
| 11220 | // doing this part. |
| Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 11221 | finishUpdateFocusedWindowAfterAssignLayersLocked(updateInputWindows); |
| The Android Open Source Project | c474dec | 2009-03-04 09:49:09 -0800 | [diff] [blame] | 11222 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11223 | return true; |
| 11224 | } |
| 11225 | return false; |
| 11226 | } |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 11227 | |
| Jeff Brown | 3a22cd9 | 2011-01-21 13:59:04 -0800 | [diff] [blame] | 11228 | private void finishUpdateFocusedWindowAfterAssignLayersLocked(boolean updateInputWindows) { |
| 11229 | mInputMonitor.setInputFocusLw(mCurrentFocus, updateInputWindows); |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 11230 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11231 | |
| 11232 | private WindowState computeFocusedWindowLocked() { |
| 11233 | WindowState result = null; |
| 11234 | WindowState win; |
| 11235 | |
| 11236 | int i = mWindows.size() - 1; |
| 11237 | int nextAppIndex = mAppTokens.size()-1; |
| 11238 | WindowToken nextApp = nextAppIndex >= 0 |
| 11239 | ? mAppTokens.get(nextAppIndex) : null; |
| 11240 | |
| 11241 | while (i >= 0) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 11242 | win = mWindows.get(i); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11243 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 11244 | if (localLOGV || DEBUG_FOCUS) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11245 | TAG, "Looking for focus: " + i |
| 11246 | + " = " + win |
| 11247 | + ", flags=" + win.mAttrs.flags |
| 11248 | + ", canReceive=" + win.canReceiveKeys()); |
| 11249 | |
| 11250 | AppWindowToken thisApp = win.mAppToken; |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 11251 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11252 | // If this window's application has been removed, just skip it. |
| 11253 | if (thisApp != null && thisApp.removed) { |
| 11254 | i--; |
| 11255 | continue; |
| 11256 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 11257 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11258 | // If there is a focused app, don't allow focus to go to any |
| 11259 | // windows below it. If this is an application window, step |
| 11260 | // through the app tokens until we find its app. |
| 11261 | if (thisApp != null && nextApp != null && thisApp != nextApp |
| 11262 | && win.mAttrs.type != TYPE_APPLICATION_STARTING) { |
| 11263 | int origAppIndex = nextAppIndex; |
| 11264 | while (nextAppIndex > 0) { |
| 11265 | if (nextApp == mFocusedApp) { |
| 11266 | // Whoops, we are below the focused app... no focus |
| 11267 | // for you! |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 11268 | if (localLOGV || DEBUG_FOCUS) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11269 | TAG, "Reached focused app: " + mFocusedApp); |
| 11270 | return null; |
| 11271 | } |
| 11272 | nextAppIndex--; |
| 11273 | nextApp = mAppTokens.get(nextAppIndex); |
| 11274 | if (nextApp == thisApp) { |
| 11275 | break; |
| 11276 | } |
| 11277 | } |
| 11278 | if (thisApp != nextApp) { |
| 11279 | // Uh oh, the app token doesn't exist! This shouldn't |
| 11280 | // happen, but if it does we can get totally hosed... |
| 11281 | // so restart at the original app. |
| 11282 | nextAppIndex = origAppIndex; |
| 11283 | nextApp = mAppTokens.get(nextAppIndex); |
| 11284 | } |
| 11285 | } |
| 11286 | |
| 11287 | // Dispatch to this window if it is wants key events. |
| 11288 | if (win.canReceiveKeys()) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 11289 | if (DEBUG_FOCUS) Slog.v( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11290 | TAG, "Found focus @ " + i + " = " + win); |
| 11291 | result = win; |
| 11292 | break; |
| 11293 | } |
| 11294 | |
| 11295 | i--; |
| 11296 | } |
| 11297 | |
| 11298 | return result; |
| 11299 | } |
| 11300 | |
| Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 11301 | private void startFreezingDisplayLocked(boolean inTransaction) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11302 | if (mDisplayFrozen) { |
| 11303 | return; |
| 11304 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 11305 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11306 | mScreenFrozenLock.acquire(); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 11307 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11308 | long now = SystemClock.uptimeMillis(); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 11309 | //Slog.i(TAG, "Freezing, gc pending: " + mFreezeGcPending + ", now " + now); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11310 | if (mFreezeGcPending != 0) { |
| 11311 | if (now > (mFreezeGcPending+1000)) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 11312 | //Slog.i(TAG, "Gc! " + now + " > " + (mFreezeGcPending+1000)); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11313 | mH.removeMessages(H.FORCE_GC); |
| 11314 | Runtime.getRuntime().gc(); |
| 11315 | mFreezeGcPending = now; |
| 11316 | } |
| 11317 | } else { |
| 11318 | mFreezeGcPending = now; |
| 11319 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 11320 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11321 | mDisplayFrozen = true; |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 11322 | |
| Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 11323 | mInputMonitor.freezeInputDispatchingLw(); |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 11324 | |
| Dianne Hackborn | bfe319e | 2009-09-21 00:34:05 -0700 | [diff] [blame] | 11325 | if (mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) { |
| 11326 | mNextAppTransition = WindowManagerPolicy.TRANSIT_UNSET; |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 11327 | mNextAppTransitionPackage = null; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11328 | mAppTransitionReady = true; |
| 11329 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 11330 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11331 | if (PROFILE_ORIENTATION) { |
| 11332 | File file = new File("/data/system/frozen"); |
| 11333 | Debug.startMethodTracing(file.toString(), 8 * 1024 * 1024); |
| 11334 | } |
| Dianne Hackborn | a111187 | 2010-11-23 20:55:11 -0800 | [diff] [blame] | 11335 | |
| 11336 | if (CUSTOM_SCREEN_ROTATION) { |
| Dianne Hackborn | f9d0be9 | 2010-11-24 12:35:25 -0800 | [diff] [blame] | 11337 | if (mScreenRotationAnimation != null && mScreenRotationAnimation.isAnimating()) { |
| 11338 | mScreenRotationAnimation.kill(); |
| 11339 | mScreenRotationAnimation = null; |
| 11340 | } |
| Dianne Hackborn | a111187 | 2010-11-23 20:55:11 -0800 | [diff] [blame] | 11341 | if (mScreenRotationAnimation == null) { |
| Dianne Hackborn | f9d0be9 | 2010-11-24 12:35:25 -0800 | [diff] [blame] | 11342 | mScreenRotationAnimation = new ScreenRotationAnimation(mContext, |
| Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 11343 | mDisplay, mFxSession, inTransaction); |
| Dianne Hackborn | a111187 | 2010-11-23 20:55:11 -0800 | [diff] [blame] | 11344 | } |
| 11345 | } else { |
| 11346 | Surface.freezeDisplay(0); |
| 11347 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11348 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 11349 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11350 | private void stopFreezingDisplayLocked() { |
| 11351 | if (!mDisplayFrozen) { |
| 11352 | return; |
| 11353 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 11354 | |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 11355 | if (mWaitingForConfig || mAppsFreezingScreen > 0 || mWindowsFreezingScreen) { |
| 11356 | return; |
| 11357 | } |
| 11358 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11359 | mDisplayFrozen = false; |
| 11360 | mH.removeMessages(H.APP_FREEZE_TIMEOUT); |
| 11361 | if (PROFILE_ORIENTATION) { |
| 11362 | Debug.stopMethodTracing(); |
| 11363 | } |
| Dianne Hackborn | a111187 | 2010-11-23 20:55:11 -0800 | [diff] [blame] | 11364 | |
| Dianne Hackborn | 89ba675 | 2011-01-23 16:51:16 -0800 | [diff] [blame] | 11365 | boolean updateRotation = false; |
| 11366 | |
| Dianne Hackborn | a111187 | 2010-11-23 20:55:11 -0800 | [diff] [blame] | 11367 | if (CUSTOM_SCREEN_ROTATION) { |
| 11368 | if (mScreenRotationAnimation != null) { |
| Dianne Hackborn | f9d0be9 | 2010-11-24 12:35:25 -0800 | [diff] [blame] | 11369 | if (mScreenRotationAnimation.dismiss(MAX_ANIMATION_DURATION, |
| 11370 | mTransitionAnimationScale)) { |
| 11371 | requestAnimationLocked(0); |
| 11372 | } else { |
| 11373 | mScreenRotationAnimation = null; |
| Dianne Hackborn | 89ba675 | 2011-01-23 16:51:16 -0800 | [diff] [blame] | 11374 | updateRotation = true; |
| Dianne Hackborn | f9d0be9 | 2010-11-24 12:35:25 -0800 | [diff] [blame] | 11375 | } |
| Dianne Hackborn | a111187 | 2010-11-23 20:55:11 -0800 | [diff] [blame] | 11376 | } |
| 11377 | } else { |
| 11378 | Surface.unfreezeDisplay(0); |
| 11379 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 11380 | |
| Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 11381 | mInputMonitor.thawInputDispatchingLw(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11382 | |
| Dianne Hackborn | 420829e | 2011-01-28 11:30:35 -0800 | [diff] [blame] | 11383 | boolean configChanged; |
| 11384 | |
| Christopher Tate | b696aee | 2010-04-02 19:08:30 -0700 | [diff] [blame] | 11385 | // While the display is frozen we don't re-compute the orientation |
| 11386 | // to avoid inconsistent states. However, something interesting |
| 11387 | // could have actually changed during that time so re-evaluate it |
| 11388 | // now to catch that. |
| Dianne Hackborn | 420829e | 2011-01-28 11:30:35 -0800 | [diff] [blame] | 11389 | configChanged = updateOrientationFromAppTokensLocked(false); |
| Christopher Tate | b696aee | 2010-04-02 19:08:30 -0700 | [diff] [blame] | 11390 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11391 | // A little kludge: a lot could have happened while the |
| 11392 | // display was frozen, so now that we are coming back we |
| 11393 | // do a gc so that any remote references the system |
| 11394 | // processes holds on others can be released if they are |
| 11395 | // no longer needed. |
| 11396 | mH.removeMessages(H.FORCE_GC); |
| 11397 | mH.sendMessageDelayed(mH.obtainMessage(H.FORCE_GC), |
| 11398 | 2000); |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 11399 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11400 | mScreenFrozenLock.release(); |
| Dianne Hackborn | 89ba675 | 2011-01-23 16:51:16 -0800 | [diff] [blame] | 11401 | |
| 11402 | if (updateRotation) { |
| 11403 | if (DEBUG_ORIENTATION) Slog.d(TAG, "Performing post-rotate rotation"); |
| Dianne Hackborn | 420829e | 2011-01-28 11:30:35 -0800 | [diff] [blame] | 11404 | configChanged |= setRotationUncheckedLocked( |
| Dianne Hackborn | 89ba675 | 2011-01-23 16:51:16 -0800 | [diff] [blame] | 11405 | WindowManagerPolicy.USE_LAST_ROTATION, 0, false); |
| Dianne Hackborn | 420829e | 2011-01-28 11:30:35 -0800 | [diff] [blame] | 11406 | } |
| 11407 | |
| 11408 | if (configChanged) { |
| 11409 | mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION); |
| Dianne Hackborn | 89ba675 | 2011-01-23 16:51:16 -0800 | [diff] [blame] | 11410 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11411 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 11412 | |
| Dianne Hackborn | b9fb170 | 2010-08-23 16:49:02 -0700 | [diff] [blame] | 11413 | static int getPropertyInt(String[] tokens, int index, int defUnits, int defDps, |
| 11414 | DisplayMetrics dm) { |
| 11415 | if (index < tokens.length) { |
| 11416 | String str = tokens[index]; |
| 11417 | if (str != null && str.length() > 0) { |
| 11418 | try { |
| 11419 | int val = Integer.parseInt(str); |
| 11420 | return val; |
| 11421 | } catch (Exception e) { |
| 11422 | } |
| 11423 | } |
| Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 11424 | } |
| 11425 | if (defUnits == TypedValue.COMPLEX_UNIT_PX) { |
| 11426 | return defDps; |
| 11427 | } |
| 11428 | int val = (int)TypedValue.applyDimension(defUnits, defDps, dm); |
| 11429 | return val; |
| 11430 | } |
| 11431 | |
| Dianne Hackborn | ed7bfbf | 2010-11-05 13:08:35 -0700 | [diff] [blame] | 11432 | static class Watermark { |
| Dianne Hackborn | b9fb170 | 2010-08-23 16:49:02 -0700 | [diff] [blame] | 11433 | final String[] mTokens; |
| 11434 | final String mText; |
| 11435 | final Paint mTextPaint; |
| 11436 | final int mTextWidth; |
| 11437 | final int mTextHeight; |
| 11438 | final int mTextAscent; |
| 11439 | final int mTextDescent; |
| 11440 | final int mDeltaX; |
| 11441 | final int mDeltaY; |
| Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 11442 | |
| Dianne Hackborn | b9fb170 | 2010-08-23 16:49:02 -0700 | [diff] [blame] | 11443 | Surface mSurface; |
| 11444 | int mLastDW; |
| 11445 | int mLastDH; |
| 11446 | boolean mDrawNeeded; |
| 11447 | |
| Dianne Hackborn | ed7bfbf | 2010-11-05 13:08:35 -0700 | [diff] [blame] | 11448 | Watermark(Display display, SurfaceSession session, String[] tokens) { |
| Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 11449 | final DisplayMetrics dm = new DisplayMetrics(); |
| Dianne Hackborn | ed7bfbf | 2010-11-05 13:08:35 -0700 | [diff] [blame] | 11450 | display.getMetrics(dm); |
| Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 11451 | |
| Dianne Hackborn | b9fb170 | 2010-08-23 16:49:02 -0700 | [diff] [blame] | 11452 | if (false) { |
| 11453 | Log.i(TAG, "*********************** WATERMARK"); |
| 11454 | for (int i=0; i<tokens.length; i++) { |
| 11455 | Log.i(TAG, " TOKEN #" + i + ": " + tokens[i]); |
| 11456 | } |
| 11457 | } |
| Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 11458 | |
| Dianne Hackborn | b9fb170 | 2010-08-23 16:49:02 -0700 | [diff] [blame] | 11459 | mTokens = tokens; |
| Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 11460 | |
| Dianne Hackborn | b9fb170 | 2010-08-23 16:49:02 -0700 | [diff] [blame] | 11461 | StringBuilder builder = new StringBuilder(32); |
| 11462 | int len = mTokens[0].length(); |
| 11463 | len = len & ~1; |
| 11464 | for (int i=0; i<len; i+=2) { |
| 11465 | int c1 = mTokens[0].charAt(i); |
| 11466 | int c2 = mTokens[0].charAt(i+1); |
| 11467 | if (c1 >= 'a' && c1 <= 'f') c1 = c1 - 'a' + 10; |
| 11468 | else if (c1 >= 'A' && c1 <= 'F') c1 = c1 - 'A' + 10; |
| 11469 | else c1 -= '0'; |
| 11470 | if (c2 >= 'a' && c2 <= 'f') c2 = c2 - 'a' + 10; |
| 11471 | else if (c2 >= 'A' && c2 <= 'F') c2 = c2 - 'A' + 10; |
| 11472 | else c2 -= '0'; |
| 11473 | builder.append((char)(255-((c1*16)+c2))); |
| 11474 | } |
| 11475 | mText = builder.toString(); |
| 11476 | if (false) { |
| 11477 | Log.i(TAG, "Final text: " + mText); |
| 11478 | } |
| 11479 | |
| 11480 | int fontSize = getPropertyInt(tokens, 1, |
| 11481 | TypedValue.COMPLEX_UNIT_DIP, 20, dm); |
| 11482 | |
| 11483 | mTextPaint = new Paint(Paint.ANTI_ALIAS_FLAG); |
| 11484 | mTextPaint.setTextSize(fontSize); |
| 11485 | mTextPaint.setTypeface(Typeface.create(Typeface.SANS_SERIF, Typeface.BOLD)); |
| 11486 | |
| 11487 | FontMetricsInt fm = mTextPaint.getFontMetricsInt(); |
| 11488 | mTextWidth = (int)mTextPaint.measureText(mText); |
| 11489 | mTextAscent = fm.ascent; |
| 11490 | mTextDescent = fm.descent; |
| 11491 | mTextHeight = fm.descent - fm.ascent; |
| 11492 | |
| 11493 | mDeltaX = getPropertyInt(tokens, 2, |
| 11494 | TypedValue.COMPLEX_UNIT_PX, mTextWidth*2, dm); |
| 11495 | mDeltaY = getPropertyInt(tokens, 3, |
| 11496 | TypedValue.COMPLEX_UNIT_PX, mTextHeight*3, dm); |
| 11497 | int shadowColor = getPropertyInt(tokens, 4, |
| 11498 | TypedValue.COMPLEX_UNIT_PX, 0xb0000000, dm); |
| 11499 | int color = getPropertyInt(tokens, 5, |
| 11500 | TypedValue.COMPLEX_UNIT_PX, 0x60ffffff, dm); |
| 11501 | int shadowRadius = getPropertyInt(tokens, 6, |
| 11502 | TypedValue.COMPLEX_UNIT_PX, 7, dm); |
| 11503 | int shadowDx = getPropertyInt(tokens, 8, |
| 11504 | TypedValue.COMPLEX_UNIT_PX, 0, dm); |
| 11505 | int shadowDy = getPropertyInt(tokens, 9, |
| 11506 | TypedValue.COMPLEX_UNIT_PX, 0, dm); |
| 11507 | |
| 11508 | mTextPaint.setColor(color); |
| 11509 | mTextPaint.setShadowLayer(shadowRadius, shadowDx, shadowDy, shadowColor); |
| Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 11510 | |
| 11511 | try { |
| 11512 | mSurface = new Surface(session, 0, |
| Dianne Hackborn | b9fb170 | 2010-08-23 16:49:02 -0700 | [diff] [blame] | 11513 | "WatermarkSurface", -1, 1, 1, PixelFormat.TRANSLUCENT, 0); |
| Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 11514 | mSurface.setLayer(TYPE_LAYER_MULTIPLIER*100); |
| Dianne Hackborn | b9fb170 | 2010-08-23 16:49:02 -0700 | [diff] [blame] | 11515 | mSurface.setPosition(0, 0); |
| Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 11516 | mSurface.show(); |
| 11517 | } catch (OutOfResourcesException e) { |
| 11518 | } |
| 11519 | } |
| 11520 | |
| 11521 | void positionSurface(int dw, int dh) { |
| Dianne Hackborn | b9fb170 | 2010-08-23 16:49:02 -0700 | [diff] [blame] | 11522 | if (mLastDW != dw || mLastDH != dh) { |
| 11523 | mLastDW = dw; |
| 11524 | mLastDH = dh; |
| 11525 | mSurface.setSize(dw, dh); |
| 11526 | mDrawNeeded = true; |
| 11527 | } |
| 11528 | } |
| 11529 | |
| 11530 | void drawIfNeeded() { |
| 11531 | if (mDrawNeeded) { |
| 11532 | final int dw = mLastDW; |
| 11533 | final int dh = mLastDH; |
| 11534 | |
| 11535 | mDrawNeeded = false; |
| 11536 | Rect dirty = new Rect(0, 0, dw, dh); |
| 11537 | Canvas c = null; |
| 11538 | try { |
| 11539 | c = mSurface.lockCanvas(dirty); |
| 11540 | } catch (IllegalArgumentException e) { |
| 11541 | } catch (OutOfResourcesException e) { |
| 11542 | } |
| 11543 | if (c != null) { |
| Dianne Hackborn | ed7bfbf | 2010-11-05 13:08:35 -0700 | [diff] [blame] | 11544 | c.drawColor(0, PorterDuff.Mode.CLEAR); |
| 11545 | |
| Dianne Hackborn | b9fb170 | 2010-08-23 16:49:02 -0700 | [diff] [blame] | 11546 | int deltaX = mDeltaX; |
| 11547 | int deltaY = mDeltaY; |
| 11548 | |
| 11549 | // deltaX shouldn't be close to a round fraction of our |
| 11550 | // x step, or else things will line up too much. |
| 11551 | int div = (dw+mTextWidth)/deltaX; |
| 11552 | int rem = (dw+mTextWidth) - (div*deltaX); |
| 11553 | int qdelta = deltaX/4; |
| 11554 | if (rem < qdelta || rem > (deltaX-qdelta)) { |
| 11555 | deltaX += deltaX/3; |
| 11556 | } |
| 11557 | |
| 11558 | int y = -mTextHeight; |
| 11559 | int x = -mTextWidth; |
| 11560 | while (y < (dh+mTextHeight)) { |
| 11561 | c.drawText(mText, x, y, mTextPaint); |
| 11562 | x += deltaX; |
| 11563 | if (x >= dw) { |
| 11564 | x -= (dw+mTextWidth); |
| 11565 | y += deltaY; |
| 11566 | } |
| 11567 | } |
| 11568 | mSurface.unlockCanvasAndPost(c); |
| 11569 | } |
| 11570 | } |
| Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 11571 | } |
| 11572 | } |
| 11573 | |
| 11574 | void createWatermark() { |
| 11575 | if (mWatermark != null) { |
| 11576 | return; |
| 11577 | } |
| 11578 | |
| Dianne Hackborn | b9fb170 | 2010-08-23 16:49:02 -0700 | [diff] [blame] | 11579 | File file = new File("/system/etc/setup.conf"); |
| 11580 | FileInputStream in = null; |
| 11581 | try { |
| 11582 | in = new FileInputStream(file); |
| 11583 | DataInputStream ind = new DataInputStream(in); |
| 11584 | String line = ind.readLine(); |
| 11585 | if (line != null) { |
| 11586 | String[] toks = line.split("%"); |
| 11587 | if (toks != null && toks.length > 0) { |
| Dianne Hackborn | ed7bfbf | 2010-11-05 13:08:35 -0700 | [diff] [blame] | 11588 | mWatermark = new Watermark(mDisplay, mFxSession, toks); |
| Dianne Hackborn | b9fb170 | 2010-08-23 16:49:02 -0700 | [diff] [blame] | 11589 | } |
| 11590 | } |
| 11591 | } catch (FileNotFoundException e) { |
| 11592 | } catch (IOException e) { |
| 11593 | } finally { |
| 11594 | if (in != null) { |
| 11595 | try { |
| 11596 | in.close(); |
| 11597 | } catch (IOException e) { |
| 11598 | } |
| 11599 | } |
| Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 11600 | } |
| Dianne Hackborn | fb86ce9 | 2010-08-11 18:11:23 -0700 | [diff] [blame] | 11601 | } |
| 11602 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11603 | @Override |
| Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 11604 | public void statusBarVisibilityChanged(int visibility) { |
| 11605 | synchronized (mWindowMap) { |
| 11606 | final int N = mWindows.size(); |
| 11607 | for (int i = 0; i < N; i++) { |
| 11608 | WindowState ws = mWindows.get(i); |
| 11609 | try { |
| 11610 | if (ws.getAttrs().hasSystemUiListeners) { |
| 11611 | ws.mClient.dispatchSystemUiVisibilityChanged(visibility); |
| 11612 | } |
| 11613 | } catch (RemoteException e) { |
| 11614 | // so sorry |
| 11615 | } |
| 11616 | } |
| 11617 | } |
| 11618 | } |
| 11619 | |
| 11620 | @Override |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11621 | public void dump(FileDescriptor fd, PrintWriter pw, String[] args) { |
| 11622 | if (mContext.checkCallingOrSelfPermission("android.permission.DUMP") |
| 11623 | != PackageManager.PERMISSION_GRANTED) { |
| 11624 | pw.println("Permission Denial: can't dump WindowManager from from pid=" |
| 11625 | + Binder.getCallingPid() |
| 11626 | + ", uid=" + Binder.getCallingUid()); |
| 11627 | return; |
| 11628 | } |
| Romain Guy | 06882f8 | 2009-06-10 13:36:04 -0700 | [diff] [blame] | 11629 | |
| Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 11630 | mInputManager.dump(pw); |
| Dianne Hackborn | a2e9226 | 2010-03-02 17:19:29 -0800 | [diff] [blame] | 11631 | pw.println(" "); |
| 11632 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11633 | synchronized(mWindowMap) { |
| 11634 | pw.println("Current Window Manager state:"); |
| 11635 | for (int i=mWindows.size()-1; i>=0; i--) { |
| Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 11636 | WindowState w = mWindows.get(i); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11637 | pw.print(" Window #"); pw.print(i); pw.print(' '); |
| 11638 | pw.print(w); pw.println(":"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11639 | w.dump(pw, " "); |
| 11640 | } |
| 11641 | if (mInputMethodDialogs.size() > 0) { |
| 11642 | pw.println(" "); |
| 11643 | pw.println(" Input method dialogs:"); |
| 11644 | for (int i=mInputMethodDialogs.size()-1; i>=0; i--) { |
| 11645 | WindowState w = mInputMethodDialogs.get(i); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11646 | 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] | 11647 | } |
| 11648 | } |
| 11649 | if (mPendingRemove.size() > 0) { |
| 11650 | pw.println(" "); |
| 11651 | pw.println(" Remove pending for:"); |
| 11652 | for (int i=mPendingRemove.size()-1; i>=0; i--) { |
| 11653 | WindowState w = mPendingRemove.get(i); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11654 | pw.print(" Remove #"); pw.print(i); pw.print(' '); |
| 11655 | pw.print(w); pw.println(":"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11656 | w.dump(pw, " "); |
| 11657 | } |
| 11658 | } |
| 11659 | if (mForceRemoves != null && mForceRemoves.size() > 0) { |
| 11660 | pw.println(" "); |
| 11661 | pw.println(" Windows force removing:"); |
| 11662 | for (int i=mForceRemoves.size()-1; i>=0; i--) { |
| 11663 | WindowState w = mForceRemoves.get(i); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11664 | pw.print(" Removing #"); pw.print(i); pw.print(' '); |
| 11665 | pw.print(w); pw.println(":"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11666 | w.dump(pw, " "); |
| 11667 | } |
| 11668 | } |
| 11669 | if (mDestroySurface.size() > 0) { |
| 11670 | pw.println(" "); |
| 11671 | pw.println(" Windows waiting to destroy their surface:"); |
| 11672 | for (int i=mDestroySurface.size()-1; i>=0; i--) { |
| 11673 | WindowState w = mDestroySurface.get(i); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11674 | pw.print(" Destroy #"); pw.print(i); pw.print(' '); |
| 11675 | pw.print(w); pw.println(":"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11676 | w.dump(pw, " "); |
| 11677 | } |
| 11678 | } |
| 11679 | if (mLosingFocus.size() > 0) { |
| 11680 | pw.println(" "); |
| 11681 | pw.println(" Windows losing focus:"); |
| 11682 | for (int i=mLosingFocus.size()-1; i>=0; i--) { |
| 11683 | WindowState w = mLosingFocus.get(i); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11684 | pw.print(" Losing #"); pw.print(i); pw.print(' '); |
| 11685 | pw.print(w); pw.println(":"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11686 | w.dump(pw, " "); |
| 11687 | } |
| 11688 | } |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 11689 | if (mResizingWindows.size() > 0) { |
| 11690 | pw.println(" "); |
| 11691 | pw.println(" Windows waiting to resize:"); |
| 11692 | for (int i=mResizingWindows.size()-1; i>=0; i--) { |
| 11693 | WindowState w = mResizingWindows.get(i); |
| 11694 | pw.print(" Resizing #"); pw.print(i); pw.print(' '); |
| 11695 | pw.print(w); pw.println(":"); |
| 11696 | w.dump(pw, " "); |
| 11697 | } |
| 11698 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11699 | if (mSessions.size() > 0) { |
| 11700 | pw.println(" "); |
| 11701 | pw.println(" All active sessions:"); |
| 11702 | Iterator<Session> it = mSessions.iterator(); |
| 11703 | while (it.hasNext()) { |
| 11704 | Session s = it.next(); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11705 | pw.print(" Session "); pw.print(s); pw.println(':'); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11706 | s.dump(pw, " "); |
| 11707 | } |
| 11708 | } |
| 11709 | if (mTokenMap.size() > 0) { |
| 11710 | pw.println(" "); |
| 11711 | pw.println(" All tokens:"); |
| 11712 | Iterator<WindowToken> it = mTokenMap.values().iterator(); |
| 11713 | while (it.hasNext()) { |
| 11714 | WindowToken token = it.next(); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11715 | pw.print(" Token "); pw.print(token.token); pw.println(':'); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11716 | token.dump(pw, " "); |
| 11717 | } |
| 11718 | } |
| Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 11719 | if (mWallpaperTokens.size() > 0) { |
| 11720 | pw.println(" "); |
| 11721 | pw.println(" Wallpaper tokens:"); |
| 11722 | for (int i=mWallpaperTokens.size()-1; i>=0; i--) { |
| 11723 | WindowToken token = mWallpaperTokens.get(i); |
| 11724 | pw.print(" Wallpaper #"); pw.print(i); |
| 11725 | pw.print(' '); pw.print(token); pw.println(':'); |
| 11726 | token.dump(pw, " "); |
| 11727 | } |
| 11728 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11729 | if (mAppTokens.size() > 0) { |
| 11730 | pw.println(" "); |
| 11731 | pw.println(" Application tokens in Z order:"); |
| 11732 | for (int i=mAppTokens.size()-1; i>=0; i--) { |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11733 | pw.print(" App #"); pw.print(i); pw.print(": "); |
| 11734 | pw.println(mAppTokens.get(i)); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11735 | } |
| 11736 | } |
| 11737 | if (mFinishedStarting.size() > 0) { |
| 11738 | pw.println(" "); |
| 11739 | pw.println(" Finishing start of application tokens:"); |
| 11740 | for (int i=mFinishedStarting.size()-1; i>=0; i--) { |
| 11741 | WindowToken token = mFinishedStarting.get(i); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11742 | pw.print(" Finished Starting #"); pw.print(i); |
| 11743 | pw.print(' '); pw.print(token); pw.println(':'); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11744 | token.dump(pw, " "); |
| 11745 | } |
| 11746 | } |
| 11747 | if (mExitingTokens.size() > 0) { |
| 11748 | pw.println(" "); |
| 11749 | pw.println(" Exiting tokens:"); |
| 11750 | for (int i=mExitingTokens.size()-1; i>=0; i--) { |
| 11751 | WindowToken token = mExitingTokens.get(i); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11752 | pw.print(" Exiting #"); pw.print(i); |
| 11753 | pw.print(' '); pw.print(token); pw.println(':'); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11754 | token.dump(pw, " "); |
| 11755 | } |
| 11756 | } |
| 11757 | if (mExitingAppTokens.size() > 0) { |
| 11758 | pw.println(" "); |
| 11759 | pw.println(" Exiting application tokens:"); |
| 11760 | for (int i=mExitingAppTokens.size()-1; i>=0; i--) { |
| 11761 | WindowToken token = mExitingAppTokens.get(i); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11762 | pw.print(" Exiting App #"); pw.print(i); |
| 11763 | pw.print(' '); pw.print(token); pw.println(':'); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11764 | token.dump(pw, " "); |
| 11765 | } |
| 11766 | } |
| 11767 | pw.println(" "); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11768 | pw.print(" mCurrentFocus="); pw.println(mCurrentFocus); |
| 11769 | pw.print(" mLastFocus="); pw.println(mLastFocus); |
| 11770 | pw.print(" mFocusedApp="); pw.println(mFocusedApp); |
| 11771 | pw.print(" mInputMethodTarget="); pw.println(mInputMethodTarget); |
| 11772 | pw.print(" mInputMethodWindow="); pw.println(mInputMethodWindow); |
| Dianne Hackborn | f21adf6 | 2009-08-13 10:20:21 -0700 | [diff] [blame] | 11773 | pw.print(" mWallpaperTarget="); pw.println(mWallpaperTarget); |
| Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 11774 | if (mLowerWallpaperTarget != null && mUpperWallpaperTarget != null) { |
| 11775 | pw.print(" mLowerWallpaperTarget="); pw.println(mLowerWallpaperTarget); |
| 11776 | pw.print(" mUpperWallpaperTarget="); pw.println(mUpperWallpaperTarget); |
| 11777 | } |
| Dianne Hackborn | 6c8e20f | 2010-11-09 18:59:09 -0800 | [diff] [blame] | 11778 | if (mWindowDetachedWallpaper != null) { |
| 11779 | pw.print(" mWindowDetachedWallpaper="); pw.println(mWindowDetachedWallpaper); |
| 11780 | } |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 11781 | pw.print(" mCurConfiguration="); pw.println(this.mCurConfiguration); |
| 11782 | pw.print(" mInTouchMode="); pw.print(mInTouchMode); |
| 11783 | pw.print(" mLayoutSeq="); pw.println(mLayoutSeq); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11784 | pw.print(" mSystemBooted="); pw.print(mSystemBooted); |
| 11785 | pw.print(" mDisplayEnabled="); pw.println(mDisplayEnabled); |
| 11786 | pw.print(" mLayoutNeeded="); pw.print(mLayoutNeeded); |
| 11787 | pw.print(" mBlurShown="); pw.println(mBlurShown); |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11788 | if (mDimAnimator != null) { |
| 11789 | mDimAnimator.printTo(pw); |
| 11790 | } else { |
| Dianne Hackborn | a2e9226 | 2010-03-02 17:19:29 -0800 | [diff] [blame] | 11791 | pw.println( " no DimAnimator "); |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11792 | } |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11793 | pw.print(" mInputMethodAnimLayerAdjustment="); |
| Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 11794 | pw.print(mInputMethodAnimLayerAdjustment); |
| 11795 | pw.print(" mWallpaperAnimLayerAdjustment="); |
| 11796 | pw.println(mWallpaperAnimLayerAdjustment); |
| Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 11797 | pw.print(" mLastWallpaperX="); pw.print(mLastWallpaperX); |
| 11798 | pw.print(" mLastWallpaperY="); pw.println(mLastWallpaperY); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11799 | pw.print(" mDisplayFrozen="); pw.print(mDisplayFrozen); |
| 11800 | pw.print(" mWindowsFreezingScreen="); pw.print(mWindowsFreezingScreen); |
| Dianne Hackborn | e36d6e2 | 2010-02-17 19:46:25 -0800 | [diff] [blame] | 11801 | pw.print(" mAppsFreezingScreen="); pw.print(mAppsFreezingScreen); |
| 11802 | pw.print(" mWaitingForConfig="); pw.println(mWaitingForConfig); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11803 | pw.print(" mRotation="); pw.print(mRotation); |
| 11804 | pw.print(", mForcedAppOrientation="); pw.print(mForcedAppOrientation); |
| 11805 | pw.print(", mRequestedRotation="); pw.println(mRequestedRotation); |
| Dianne Hackborn | 89ba675 | 2011-01-23 16:51:16 -0800 | [diff] [blame] | 11806 | pw.print(" mDeferredRotation="); pw.print(mDeferredRotation); |
| 11807 | pw.print(", mDeferredRotationAnimFlags="); pw.print(mDeferredRotationAnimFlags); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11808 | pw.print(" mAnimationPending="); pw.print(mAnimationPending); |
| 11809 | pw.print(" mWindowAnimationScale="); pw.print(mWindowAnimationScale); |
| 11810 | pw.print(" mTransitionWindowAnimationScale="); pw.println(mTransitionAnimationScale); |
| 11811 | pw.print(" mNextAppTransition=0x"); |
| 11812 | pw.print(Integer.toHexString(mNextAppTransition)); |
| 11813 | pw.print(", mAppTransitionReady="); pw.print(mAppTransitionReady); |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 11814 | pw.print(", mAppTransitionRunning="); pw.print(mAppTransitionRunning); |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11815 | pw.print(", mAppTransitionTimeout="); pw.println( mAppTransitionTimeout); |
| Dianne Hackborn | 3b3e145 | 2009-09-24 19:22:12 -0700 | [diff] [blame] | 11816 | if (mNextAppTransitionPackage != null) { |
| 11817 | pw.print(" mNextAppTransitionPackage="); |
| 11818 | pw.print(mNextAppTransitionPackage); |
| 11819 | pw.print(", mNextAppTransitionEnter=0x"); |
| 11820 | pw.print(Integer.toHexString(mNextAppTransitionEnter)); |
| 11821 | pw.print(", mNextAppTransitionExit=0x"); |
| 11822 | pw.print(Integer.toHexString(mNextAppTransitionExit)); |
| 11823 | } |
| Dianne Hackborn | 1d442e0 | 2009-04-20 18:14:05 -0700 | [diff] [blame] | 11824 | pw.print(" mStartingIconInTransition="); pw.print(mStartingIconInTransition); |
| 11825 | pw.print(", mSkipAppTransitionAnimation="); pw.println(mSkipAppTransitionAnimation); |
| 11826 | if (mOpeningApps.size() > 0) { |
| 11827 | pw.print(" mOpeningApps="); pw.println(mOpeningApps); |
| 11828 | } |
| 11829 | if (mClosingApps.size() > 0) { |
| 11830 | pw.print(" mClosingApps="); pw.println(mClosingApps); |
| 11831 | } |
| Dianne Hackborn | a8f6018 | 2009-09-01 19:01:50 -0700 | [diff] [blame] | 11832 | if (mToTopApps.size() > 0) { |
| 11833 | pw.print(" mToTopApps="); pw.println(mToTopApps); |
| 11834 | } |
| 11835 | if (mToBottomApps.size() > 0) { |
| 11836 | pw.print(" mToBottomApps="); pw.println(mToBottomApps); |
| 11837 | } |
| Dianne Hackborn | 87fc308 | 2010-12-03 13:09:12 -0800 | [diff] [blame] | 11838 | if (mDisplay != null) { |
| 11839 | pw.print(" DisplayWidth="); pw.print(mDisplay.getWidth()); |
| 11840 | pw.print(" DisplayHeight="); pw.println(mDisplay.getHeight()); |
| 11841 | } else { |
| 11842 | pw.println(" NO DISPLAY"); |
| 11843 | } |
| Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 11844 | pw.println(" Policy:"); |
| 11845 | mPolicy.dump(" ", fd, pw, args); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 11846 | } |
| 11847 | } |
| 11848 | |
| Jeff Brown | 349703e | 2010-06-22 01:27:15 -0700 | [diff] [blame] | 11849 | // 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] | 11850 | public void monitor() { |
| 11851 | synchronized (mWindowMap) { } |
| Mike Lockwood | 983ee09 | 2009-11-22 01:42:24 -0500 | [diff] [blame] | 11852 | synchronized (mKeyguardTokenWatcher) { } |
| Dianne Hackborn | ddca3ee | 2009-07-23 19:01:31 -0700 | [diff] [blame] | 11853 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 11854 | |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11855 | /** |
| 11856 | * DimAnimator class that controls the dim animation. This holds the surface and |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 11857 | * all state used for dim animation. |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11858 | */ |
| 11859 | private static class DimAnimator { |
| 11860 | Surface mDimSurface; |
| 11861 | boolean mDimShown = false; |
| 11862 | float mDimCurrentAlpha; |
| 11863 | float mDimTargetAlpha; |
| 11864 | float mDimDeltaPerMs; |
| 11865 | long mLastDimAnimTime; |
| Dianne Hackborn | f83c555 | 2010-03-31 22:19:32 -0700 | [diff] [blame] | 11866 | |
| 11867 | int mLastDimWidth, mLastDimHeight; |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11868 | |
| 11869 | DimAnimator (SurfaceSession session) { |
| 11870 | if (mDimSurface == null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 11871 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11872 | + mDimSurface + ": CREATE"); |
| 11873 | try { |
| Mathias Agopian | 5d26c1e | 2010-03-01 16:09:43 -0800 | [diff] [blame] | 11874 | mDimSurface = new Surface(session, 0, |
| 11875 | "DimSurface", |
| 11876 | -1, 16, 16, PixelFormat.OPAQUE, |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11877 | Surface.FX_SURFACE_DIM); |
| Maciej Białka | 9ee5c22 | 2010-03-24 10:25:40 +0100 | [diff] [blame] | 11878 | mDimSurface.setAlpha(0.0f); |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11879 | } catch (Exception e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 11880 | Slog.e(TAG, "Exception creating Dim surface", e); |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11881 | } |
| 11882 | } |
| 11883 | } |
| 11884 | |
| 11885 | /** |
| 11886 | * Show the dim surface. |
| 11887 | */ |
| 11888 | void show(int dw, int dh) { |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 11889 | if (!mDimShown) { |
| 11890 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface + ": SHOW pos=(0,0) (" + |
| 11891 | dw + "x" + dh + ")"); |
| 11892 | mDimShown = true; |
| 11893 | try { |
| Dianne Hackborn | f83c555 | 2010-03-31 22:19:32 -0700 | [diff] [blame] | 11894 | mLastDimWidth = dw; |
| 11895 | mLastDimHeight = dh; |
| Dianne Hackborn | 16064f9 | 2010-03-25 00:47:24 -0700 | [diff] [blame] | 11896 | mDimSurface.setPosition(0, 0); |
| 11897 | mDimSurface.setSize(dw, dh); |
| 11898 | mDimSurface.show(); |
| 11899 | } catch (RuntimeException e) { |
| 11900 | Slog.w(TAG, "Failure showing dim surface", e); |
| 11901 | } |
| Dianne Hackborn | f83c555 | 2010-03-31 22:19:32 -0700 | [diff] [blame] | 11902 | } else if (mLastDimWidth != dw || mLastDimHeight != dh) { |
| 11903 | mLastDimWidth = dw; |
| 11904 | mLastDimHeight = dh; |
| 11905 | mDimSurface.setSize(dw, dh); |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11906 | } |
| 11907 | } |
| 11908 | |
| 11909 | /** |
| 11910 | * Set's the dim surface's layer and update dim parameters that will be used in |
| 11911 | * {@link updateSurface} after all windows are examined. |
| 11912 | */ |
| Dianne Hackborn | 1c24e95 | 2010-11-23 00:34:30 -0800 | [diff] [blame] | 11913 | void updateParameters(Resources res, WindowState w, long currentTime) { |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11914 | mDimSurface.setLayer(w.mAnimLayer-1); |
| 11915 | |
| 11916 | final float target = w.mExiting ? 0 : w.mAttrs.dimAmount; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 11917 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface |
| Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 11918 | + ": layer=" + (w.mAnimLayer-1) + " target=" + target); |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11919 | if (mDimTargetAlpha != target) { |
| 11920 | // If the desired dim level has changed, then |
| 11921 | // start an animation to it. |
| 11922 | mLastDimAnimTime = currentTime; |
| 11923 | long duration = (w.mAnimating && w.mAnimation != null) |
| 11924 | ? w.mAnimation.computeDurationHint() |
| 11925 | : DEFAULT_DIM_DURATION; |
| 11926 | if (target > mDimTargetAlpha) { |
| Dianne Hackborn | 1c24e95 | 2010-11-23 00:34:30 -0800 | [diff] [blame] | 11927 | TypedValue tv = new TypedValue(); |
| 11928 | res.getValue(com.android.internal.R.fraction.config_dimBehindFadeDuration, |
| 11929 | tv, true); |
| 11930 | if (tv.type == TypedValue.TYPE_FRACTION) { |
| 11931 | duration = (long)tv.getFraction((float)duration, (float)duration); |
| 11932 | } else if (tv.type >= TypedValue.TYPE_FIRST_INT |
| 11933 | && tv.type <= TypedValue.TYPE_LAST_INT) { |
| 11934 | duration = tv.data; |
| 11935 | } |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11936 | } |
| 11937 | if (duration < 1) { |
| 11938 | // Don't divide by zero |
| 11939 | duration = 1; |
| 11940 | } |
| 11941 | mDimTargetAlpha = target; |
| 11942 | mDimDeltaPerMs = (mDimTargetAlpha-mDimCurrentAlpha) / duration; |
| 11943 | } |
| 11944 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 11945 | |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11946 | /** |
| 11947 | * Updating the surface's alpha. Returns true if the animation continues, or returns |
| 11948 | * false when the animation is finished and the dim surface is hidden. |
| 11949 | */ |
| 11950 | boolean updateSurface(boolean dimming, long currentTime, boolean displayFrozen) { |
| 11951 | if (!dimming) { |
| 11952 | if (mDimTargetAlpha != 0) { |
| 11953 | mLastDimAnimTime = currentTime; |
| 11954 | mDimTargetAlpha = 0; |
| 11955 | mDimDeltaPerMs = (-mDimCurrentAlpha) / DEFAULT_DIM_DURATION; |
| 11956 | } |
| 11957 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 11958 | |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11959 | boolean animating = false; |
| 11960 | if (mLastDimAnimTime != 0) { |
| 11961 | mDimCurrentAlpha += mDimDeltaPerMs |
| 11962 | * (currentTime-mLastDimAnimTime); |
| 11963 | boolean more = true; |
| 11964 | if (displayFrozen) { |
| 11965 | // If the display is frozen, there is no reason to animate. |
| 11966 | more = false; |
| 11967 | } else if (mDimDeltaPerMs > 0) { |
| 11968 | if (mDimCurrentAlpha > mDimTargetAlpha) { |
| 11969 | more = false; |
| 11970 | } |
| 11971 | } else if (mDimDeltaPerMs < 0) { |
| 11972 | if (mDimCurrentAlpha < mDimTargetAlpha) { |
| 11973 | more = false; |
| 11974 | } |
| 11975 | } else { |
| 11976 | more = false; |
| 11977 | } |
| 11978 | |
| 11979 | // Do we need to continue animating? |
| 11980 | if (more) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 11981 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11982 | + mDimSurface + ": alpha=" + mDimCurrentAlpha); |
| 11983 | mLastDimAnimTime = currentTime; |
| 11984 | mDimSurface.setAlpha(mDimCurrentAlpha); |
| 11985 | animating = true; |
| 11986 | } else { |
| 11987 | mDimCurrentAlpha = mDimTargetAlpha; |
| 11988 | mLastDimAnimTime = 0; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 11989 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11990 | + mDimSurface + ": final alpha=" + mDimCurrentAlpha); |
| 11991 | mDimSurface.setAlpha(mDimCurrentAlpha); |
| 11992 | if (!dimming) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 11993 | if (SHOW_TRANSACTIONS) Slog.i(TAG, " DIM " + mDimSurface |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11994 | + ": HIDE"); |
| 11995 | try { |
| 11996 | mDimSurface.hide(); |
| 11997 | } catch (RuntimeException e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 11998 | Slog.w(TAG, "Illegal argument exception hiding dim surface"); |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 11999 | } |
| 12000 | mDimShown = false; |
| 12001 | } |
| 12002 | } |
| 12003 | } |
| 12004 | return animating; |
| 12005 | } |
| 12006 | |
| 12007 | public void printTo(PrintWriter pw) { |
| 12008 | pw.print(" mDimShown="); pw.print(mDimShown); |
| 12009 | pw.print(" current="); pw.print(mDimCurrentAlpha); |
| 12010 | pw.print(" target="); pw.print(mDimTargetAlpha); |
| 12011 | pw.print(" delta="); pw.print(mDimDeltaPerMs); |
| 12012 | pw.print(" lastAnimTime="); pw.println(mLastDimAnimTime); |
| 12013 | } |
| 12014 | } |
| 12015 | |
| 12016 | /** |
| 12017 | * Animation that fade in after 0.5 interpolate time, or fade out in reverse order. |
| 12018 | * This is used for opening/closing transition for apps in compatible mode. |
| 12019 | */ |
| 12020 | private static class FadeInOutAnimation extends Animation { |
| 12021 | int mWidth; |
| 12022 | boolean mFadeIn; |
| 12023 | |
| 12024 | public FadeInOutAnimation(boolean fadeIn) { |
| 12025 | setInterpolator(new AccelerateInterpolator()); |
| 12026 | setDuration(DEFAULT_FADE_IN_OUT_DURATION); |
| 12027 | mFadeIn = fadeIn; |
| 12028 | } |
| 12029 | |
| 12030 | @Override |
| 12031 | protected void applyTransformation(float interpolatedTime, Transformation t) { |
| 12032 | float x = interpolatedTime; |
| 12033 | if (!mFadeIn) { |
| 12034 | x = 1.0f - x; // reverse the interpolation for fade out |
| 12035 | } |
| 12036 | if (x < 0.5) { |
| 12037 | // move the window out of the screen. |
| 12038 | t.getMatrix().setTranslate(mWidth, 0); |
| 12039 | } else { |
| 12040 | t.getMatrix().setTranslate(0, 0);// show |
| 12041 | t.setAlpha((x - 0.5f) * 2); |
| 12042 | } |
| 12043 | } |
| 12044 | |
| 12045 | @Override |
| 12046 | public void initialize(int width, int height, int parentWidth, int parentHeight) { |
| 12047 | // width is the screen width {@see AppWindowToken#stepAnimatinoLocked} |
| 12048 | mWidth = width; |
| 12049 | } |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 12050 | |
| 12051 | @Override |
| Mitsuru Oshima | 5a2b91d | 2009-07-16 16:30:02 -0700 | [diff] [blame] | 12052 | public int getZAdjustment() { |
| 12053 | return Animation.ZORDER_TOP; |
| Mitsuru Oshima | 0a5d2c4 | 2009-07-14 14:10:30 -0700 | [diff] [blame] | 12054 | } |
| 12055 | } |
| Jeff Brown | 2992ea7 | 2011-01-28 22:04:14 -0800 | [diff] [blame^] | 12056 | |
| 12057 | public interface OnHardKeyboardStatusChangeListener { |
| 12058 | public void onHardKeyboardStatusChange(boolean available, boolean enabled); |
| 12059 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 12060 | } |